]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Algorithms/RegionOfInterestImageCalculator.hxx
yet another refactoring
[cpPlugins.git] / lib / cpExtensions / Algorithms / RegionOfInterestImageCalculator.hxx
diff --git a/lib/cpExtensions/Algorithms/RegionOfInterestImageCalculator.hxx b/lib/cpExtensions/Algorithms/RegionOfInterestImageCalculator.hxx
new file mode 100644 (file)
index 0000000..fd7867f
--- /dev/null
@@ -0,0 +1,92 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __CPEXTENSIONS__ALGORITHMS__REGIONOFINTERESTIMAGECALCULATOR__HXX__
+#define __CPEXTENSIONS__ALGORITHMS__REGIONOFINTERESTIMAGECALCULATOR__HXX__
+
+#include <itkImageRegionConstIteratorWithIndex.h>
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpExtensions::Algorithms::RegionOfInterestImageCalculator< _TImage >::
+Compute( )
+{
+  typedef itk::ImageRegionConstIteratorWithIndex< _TImage > _TIterator;
+  typedef typename _TImage::RegionType _TRegion;
+
+  if( this->m_Image.IsNotNull( ) )
+  {
+    _TRegion region = this->m_Image->GetRequestedRegion( );
+    TIndex minidx = region.GetIndex( );
+    TIndex maxidx = minidx + region.GetSize( );
+    for( unsigned int d = 0; d < _TImage::ImageDimension; ++d )
+      maxidx[ d ] -= 1;
+
+    bool first = true;
+    _TIterator i( this->m_Image, region );
+    for( i.GoToBegin( ); !i.IsAtEnd( ); ++i )
+    {
+      if( i.Get( ) != this->m_BackgroundValue )
+      {
+        TIndex idx = i.GetIndex( );
+        if( !first )
+        {
+          for( unsigned int d = 0; d < _TImage::ImageDimension; ++d )
+          {
+            minidx[ d ] = ( idx[ d ] < minidx[ d ] )? idx[ d ]: minidx[ d ];
+            maxidx[ d ] = ( idx[ d ] > maxidx[ d ] )? idx[ d ]: maxidx[ d ];
+
+          } // rof
+        }
+        else
+        {
+          minidx = maxidx = idx;
+          first = false;
+
+        } // fi
+
+      } // fi
+
+    } // rof
+    this->m_Minimum = minidx;
+    this->m_Maximum = maxidx;
+  }
+  else
+  {
+    this->m_Minimum.Fill( 0 );
+    this->m_Maximum.Fill( 0 );
+
+  } // fi
+}
+      
+// -------------------------------------------------------------------------
+template< class _TImage >
+cpExtensions::Algorithms::RegionOfInterestImageCalculator< _TImage >::
+RegionOfInterestImageCalculator( )
+  : Superclass( ),
+    m_BackgroundValue( TPixel( 0 ) )
+{
+  this->m_Minimum.Fill( 0 );
+  this->m_Maximum.Fill( 0 );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+cpExtensions::Algorithms::RegionOfInterestImageCalculator< _TImage >::
+~RegionOfInterestImageCalculator( )
+{
+}
+
+
+/* TODO
+   typename _TImage::ConstPointer m_Image;
+   TPixel m_BackgroundValue;
+   TIndex m_Minimum;
+   TIndex m_Maximum;
+   };
+*/
+
+#endif // __CPEXTENSIONS__ALGORITHMS__REGIONOFINTERESTIMAGECALCULATOR__HXX__
+
+// eof - $RCSfile$