+#include <plugins/ImageGenericFilters/MinimumMaximumCalculator.h>
+#include <cpPlugins/DataObjects/Image.h>
+#include <cpPlugins/DataObjects/Mesh.h>
+
+#include <itkMinimumMaximumImageCalculator.h>
+
+// -------------------------------------------------------------------------
+cpPluginsImageGenericFilters::MinimumMaximumCalculator::
+MinimumMaximumCalculator( )
+ : Superclass( )
+{
+ this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
+ this->_ConfigureOutput< cpPlugins::DataObjects::Mesh >( "Maximum" );
+ this->_ConfigureOutput< cpPlugins::DataObjects::Mesh >( "Minimum" );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsImageGenericFilters::MinimumMaximumCalculator::
+~MinimumMaximumCalculator( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsImageGenericFilters::MinimumMaximumCalculator::
+_GenerateData( )
+{
+ auto o = this->GetInputData( "Input" );
+ cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
+ else this->_Error( "Invalid input image." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpPluginsImageGenericFilters::MinimumMaximumCalculator::
+_GD0( _TImage* input )
+{
+ typedef itk::MinimumMaximumImageCalculator< _TImage > _TFilter;
+ typedef typename _TImage::IndexType _TIndex;
+ typedef typename _TImage::PointType _TPoint;
+
+ auto filter = this->_CreateITK< _TFilter >( );
+ filter->SetImage( input );
+ filter->Compute( );
+
+ _TIndex min_idx = filter->GetIndexOfMinimum( );
+ _TIndex max_idx = filter->GetIndexOfMaximum( );
+
+ _TPoint min_pnt, max_pnt;
+ input->TransformIndexToPhysicalPoint( min_idx, min_pnt );
+ input->TransformIndexToPhysicalPoint( max_idx, max_pnt );
+
+ auto min_pd = this->GetOutputData< vtkPolyData >( "Minimum" );
+ if( min_pd == NULL )
+ {
+ auto points = vtkSmartPointer< vtkPoints >::New( );
+ auto verts = vtkSmartPointer< vtkCellArray >::New( );
+ auto lines = vtkSmartPointer< vtkCellArray >::New( );
+ auto polys = vtkSmartPointer< vtkCellArray >::New( );
+ auto strips = vtkSmartPointer< vtkCellArray >::New( );
+ auto pd = vtkSmartPointer< vtkPolyData >::New( );
+ pd->SetPoints( points );
+ pd->SetVerts( verts );
+ pd->SetLines( lines );
+ pd->SetPolys( polys );
+ pd->SetStrips( strips );
+
+ points->InsertNextPoint( 0, 0, 0 );
+ verts->InsertNextCell( 1 );
+ verts->InsertCellPoint( 0 );
+
+ this->GetOutput( "Minimum" )->SetVTK( pd );
+ min_pd = this->GetOutputData< vtkPolyData >( "Minimum" );
+
+ } // fi
+
+ if( _TImage::ImageDimension == 1 )
+ min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], 0, 0 );
+ else if( _TImage::ImageDimension == 2 )
+ min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], min_pnt[ 1 ], 0 );
+ else if( _TImage::ImageDimension > 2 )
+ min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], min_pnt[ 1 ], min_pnt[ 2 ] );
+
+ auto max_pd = this->GetOutputData< vtkPolyData >( "Maximum" );
+ if( max_pd == NULL )
+ {
+ auto points = vtkSmartPointer< vtkPoints >::New( );
+ auto verts = vtkSmartPointer< vtkCellArray >::New( );
+ auto lines = vtkSmartPointer< vtkCellArray >::New( );
+ auto polys = vtkSmartPointer< vtkCellArray >::New( );
+ auto strips = vtkSmartPointer< vtkCellArray >::New( );
+ auto pd = vtkSmartPointer< vtkPolyData >::New( );
+ pd->SetPoints( points );
+ pd->SetVerts( verts );
+ pd->SetLines( lines );
+ pd->SetPolys( polys );
+ pd->SetStrips( strips );
+
+ points->InsertNextPoint( 0, 0, 0 );
+ verts->InsertNextCell( 1 );
+ verts->InsertCellPoint( 0 );
+
+ this->GetOutput( "Maximum" )->SetVTK( pd );
+ max_pd = this->GetOutputData< vtkPolyData >( "Maximum" );
+
+ } // fi
+
+ if( _TImage::ImageDimension == 1 )
+ max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], 0, 0 );
+ else if( _TImage::ImageDimension == 2 )
+ max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], max_pnt[ 1 ], 0 );
+ else if( _TImage::ImageDimension > 2 )
+ max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], max_pnt[ 1 ], max_pnt[ 2 ] );
+}
+
+// eof - $RCSfile$