]> Creatis software - cpPlugins.git/blobdiff - plugins/ITKImageGenericFilters_1/ImageToBoundingBoxFromThreshold.cxx
...
[cpPlugins.git] / plugins / ITKImageGenericFilters_1 / ImageToBoundingBoxFromThreshold.cxx
diff --git a/plugins/ITKImageGenericFilters_1/ImageToBoundingBoxFromThreshold.cxx b/plugins/ITKImageGenericFilters_1/ImageToBoundingBoxFromThreshold.cxx
new file mode 100644 (file)
index 0000000..a93ba35
--- /dev/null
@@ -0,0 +1,61 @@
+#include <ITKImageGenericFilters_1/ImageToBoundingBoxFromThreshold.h>
+#include <cpInstances/Image.h>
+#include <cpInstances/BoundingBox.h>
+
+#include <itkImage.h>
+#include <cpExtensions/Algorithms/ImageToBoundingBoxFromThreshold.h>
+
+// -------------------------------------------------------------------------
+cpPluginsITKImageGenericFilters_1::ImageToBoundingBoxFromThreshold::
+ImageToBoundingBoxFromThreshold( )
+  : Superclass( )
+{
+  this->_ConfigureInput< cpInstances::Image >( "Input", true, false );
+  this->_ConfigureOutput< cpInstances::BoundingBox >( "Output" );
+
+  this->m_Parameters.ConfigureAsReal( "LowerThreshold", 0 );
+  this->m_Parameters.ConfigureAsReal( "UpperThreshold", 1 );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsITKImageGenericFilters_1::ImageToBoundingBoxFromThreshold::
+~ImageToBoundingBoxFromThreshold( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsITKImageGenericFilters_1::ImageToBoundingBoxFromThreshold::
+_GenerateData( )
+{
+  auto o = this->GetInputData( "Input" );
+  cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
+    this->_Error( "Invalid input image." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpPluginsITKImageGenericFilters_1::ImageToBoundingBoxFromThreshold::
+_GD0( _TImage* image )
+{
+  typedef
+    cpExtensions::Algorithms::ImageToBoundingBoxFromThreshold< _TImage >
+    _TFilter;
+
+  // Configure filter
+  _TFilter* filter = this->_CreateITK< _TFilter >( );
+  filter->SetImage( image );
+  filter->SetLowerThreshold( this->m_Parameters.GetReal( "LowerThreshold" ) );
+  filter->SetUpperThreshold( this->m_Parameters.GetReal( "UpperThreshold" ) );
+  filter->Compute( );
+
+  // Create output
+  auto reg = filter->GetRegion( );
+  auto bb = this->GetOutput< cpInstances::BoundingBox >( "Output" );
+  typename _TImage::PointType p0, p1;
+  image->TransformIndexToPhysicalPoint( reg.GetIndex( ), p0 );
+  image->TransformIndexToPhysicalPoint( reg.GetIndex( ) + reg.GetSize( ), p1 );
+  bb->SetMinimum( p0 );
+  bb->SetMaximum( p1 );
+}
+
+// eof - $RCSfile$