1 #include <ImageGenericFilters/MinimumMaximumCalculator.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Mesh.h>
5 #include <itkMinimumMaximumImageCalculator.h>
7 // -------------------------------------------------------------------------
8 cpPluginsImageGenericFilters::MinimumMaximumCalculator::
9 MinimumMaximumCalculator( )
12 this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
13 this->_ConfigureOutput< cpPlugins::DataObjects::Mesh >( "Maximum" );
14 this->_ConfigureOutput< cpPlugins::DataObjects::Mesh >( "Minimum" );
17 // -------------------------------------------------------------------------
18 cpPluginsImageGenericFilters::MinimumMaximumCalculator::
19 ~MinimumMaximumCalculator( )
23 // -------------------------------------------------------------------------
24 void cpPluginsImageGenericFilters::MinimumMaximumCalculator::
27 auto o = this->GetInputData( "Input" );
28 cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
29 else this->_Error( "Invalid input image." );
32 // -------------------------------------------------------------------------
33 template< class _TImage >
34 void cpPluginsImageGenericFilters::MinimumMaximumCalculator::
35 _GD0( _TImage* input )
37 typedef itk::MinimumMaximumImageCalculator< _TImage > _TFilter;
38 typedef typename _TImage::IndexType _TIndex;
39 typedef typename _TImage::PointType _TPoint;
41 auto filter = this->_CreateITK< _TFilter >( );
42 filter->SetImage( input );
45 _TIndex min_idx = filter->GetIndexOfMinimum( );
46 _TIndex max_idx = filter->GetIndexOfMaximum( );
48 _TPoint min_pnt, max_pnt;
49 input->TransformIndexToPhysicalPoint( min_idx, min_pnt );
50 input->TransformIndexToPhysicalPoint( max_idx, max_pnt );
52 auto min_pd = this->GetOutputData< vtkPolyData >( "Minimum" );
55 auto points = vtkSmartPointer< vtkPoints >::New( );
56 auto verts = vtkSmartPointer< vtkCellArray >::New( );
57 auto lines = vtkSmartPointer< vtkCellArray >::New( );
58 auto polys = vtkSmartPointer< vtkCellArray >::New( );
59 auto strips = vtkSmartPointer< vtkCellArray >::New( );
60 auto pd = vtkSmartPointer< vtkPolyData >::New( );
61 pd->SetPoints( points );
62 pd->SetVerts( verts );
63 pd->SetLines( lines );
64 pd->SetPolys( polys );
65 pd->SetStrips( strips );
67 points->InsertNextPoint( 0, 0, 0 );
68 verts->InsertNextCell( 1 );
69 verts->InsertCellPoint( 0 );
71 this->GetOutput( "Minimum" )->SetVTK( pd );
72 min_pd = this->GetOutputData< vtkPolyData >( "Minimum" );
76 if( _TImage::ImageDimension == 1 )
77 min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], 0, 0 );
78 else if( _TImage::ImageDimension == 2 )
79 min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], min_pnt[ 1 ], 0 );
80 else if( _TImage::ImageDimension > 2 )
81 min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], min_pnt[ 1 ], min_pnt[ 2 ] );
83 auto max_pd = this->GetOutputData< vtkPolyData >( "Maximum" );
86 auto points = vtkSmartPointer< vtkPoints >::New( );
87 auto verts = vtkSmartPointer< vtkCellArray >::New( );
88 auto lines = vtkSmartPointer< vtkCellArray >::New( );
89 auto polys = vtkSmartPointer< vtkCellArray >::New( );
90 auto strips = vtkSmartPointer< vtkCellArray >::New( );
91 auto pd = vtkSmartPointer< vtkPolyData >::New( );
92 pd->SetPoints( points );
93 pd->SetVerts( verts );
94 pd->SetLines( lines );
95 pd->SetPolys( polys );
96 pd->SetStrips( strips );
98 points->InsertNextPoint( 0, 0, 0 );
99 verts->InsertNextCell( 1 );
100 verts->InsertCellPoint( 0 );
102 this->GetOutput( "Maximum" )->SetVTK( pd );
103 max_pd = this->GetOutputData< vtkPolyData >( "Maximum" );
107 if( _TImage::ImageDimension == 1 )
108 max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], 0, 0 );
109 else if( _TImage::ImageDimension == 2 )
110 max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], max_pnt[ 1 ], 0 );
111 else if( _TImage::ImageDimension > 2 )
112 max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], max_pnt[ 1 ], max_pnt[ 2 ] );