1 #include <plugins/ImageGenericFilters/MinimumMaximumCalculator.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Mesh.h>
5 #include <itkMinimumMaximumImageCalculator.h>
6 #include <itkMinimumMaximumImageCalculator.hxx>
8 // -------------------------------------------------------------------------
9 cpPluginsImageGenericFilters::MinimumMaximumCalculator::
10 MinimumMaximumCalculator( )
13 this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
14 this->_ConfigureOutput< cpPlugins::DataObjects::Mesh >( "Maximum" );
15 this->_ConfigureOutput< cpPlugins::DataObjects::Mesh >( "Minimum" );
18 // -------------------------------------------------------------------------
19 cpPluginsImageGenericFilters::MinimumMaximumCalculator::
20 ~MinimumMaximumCalculator( )
24 // -------------------------------------------------------------------------
25 void cpPluginsImageGenericFilters::MinimumMaximumCalculator::
28 auto o = this->GetInputData( "Input" );
29 cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
30 else this->_Error( "Invalid input image." );
33 // -------------------------------------------------------------------------
34 template< class _TImage >
35 void cpPluginsImageGenericFilters::MinimumMaximumCalculator::
36 _GD0( _TImage* input )
38 typedef itk::MinimumMaximumImageCalculator< _TImage > _TFilter;
39 typedef typename _TImage::IndexType _TIndex;
40 typedef typename _TImage::PointType _TPoint;
42 auto filter = this->_CreateITK< _TFilter >( );
43 filter->SetImage( input );
46 _TIndex min_idx = filter->GetIndexOfMinimum( );
47 _TIndex max_idx = filter->GetIndexOfMaximum( );
49 _TPoint min_pnt, max_pnt;
50 input->TransformIndexToPhysicalPoint( min_idx, min_pnt );
51 input->TransformIndexToPhysicalPoint( max_idx, max_pnt );
53 auto min_pd = this->GetOutputData< vtkPolyData >( "Minimum" );
56 auto points = vtkSmartPointer< vtkPoints >::New( );
57 auto verts = vtkSmartPointer< vtkCellArray >::New( );
58 auto lines = vtkSmartPointer< vtkCellArray >::New( );
59 auto polys = vtkSmartPointer< vtkCellArray >::New( );
60 auto strips = vtkSmartPointer< vtkCellArray >::New( );
61 auto pd = vtkSmartPointer< vtkPolyData >::New( );
62 pd->SetPoints( points );
63 pd->SetVerts( verts );
64 pd->SetLines( lines );
65 pd->SetPolys( polys );
66 pd->SetStrips( strips );
68 points->InsertNextPoint( 0, 0, 0 );
69 verts->InsertNextCell( 1 );
70 verts->InsertCellPoint( 0 );
72 this->GetOutput( "Minimum" )->SetVTK( pd );
73 min_pd = this->GetOutputData< vtkPolyData >( "Minimum" );
77 if( _TImage::ImageDimension == 1 )
78 min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], 0, 0 );
79 else if( _TImage::ImageDimension == 2 )
80 min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], min_pnt[ 1 ], 0 );
81 else if( _TImage::ImageDimension > 2 )
82 min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], min_pnt[ 1 ], min_pnt[ 2 ] );
84 auto max_pd = this->GetOutputData< vtkPolyData >( "Maximum" );
87 auto points = vtkSmartPointer< vtkPoints >::New( );
88 auto verts = vtkSmartPointer< vtkCellArray >::New( );
89 auto lines = vtkSmartPointer< vtkCellArray >::New( );
90 auto polys = vtkSmartPointer< vtkCellArray >::New( );
91 auto strips = vtkSmartPointer< vtkCellArray >::New( );
92 auto pd = vtkSmartPointer< vtkPolyData >::New( );
93 pd->SetPoints( points );
94 pd->SetVerts( verts );
95 pd->SetLines( lines );
96 pd->SetPolys( polys );
97 pd->SetStrips( strips );
99 points->InsertNextPoint( 0, 0, 0 );
100 verts->InsertNextCell( 1 );
101 verts->InsertCellPoint( 0 );
103 this->GetOutput( "Maximum" )->SetVTK( pd );
104 max_pd = this->GetOutputData< vtkPolyData >( "Maximum" );
108 if( _TImage::ImageDimension == 1 )
109 max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], 0, 0 );
110 else if( _TImage::ImageDimension == 2 )
111 max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], max_pnt[ 1 ], 0 );
112 else if( _TImage::ImageDimension > 2 )
113 max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], max_pnt[ 1 ], max_pnt[ 2 ] );