1 #include <ImageGenericFilters/MinimumMaximumCalculator.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Mesh.h>
4 #include <cpPlugins/DataObjects/Image_Demanglers.h>
7 #include <itkMinimumMaximumImageCalculator.h>
8 #include <vtkPolyData.h>
10 // -------------------------------------------------------------------------
11 cpPluginsImageGenericFilters::MinimumMaximumCalculator::
12 MinimumMaximumCalculator( )
15 typedef cpPlugins::DataObjects::Image _TImage;
16 typedef cpPlugins::DataObjects::Mesh _TMesh;
18 this->_ConfigureInput< _TImage >( "Input", true, false );
19 this->_ConfigureOutput< _TMesh >( "Maximum" );
20 this->_ConfigureOutput< _TMesh >( "Minimum" );
23 // -------------------------------------------------------------------------
24 cpPluginsImageGenericFilters::MinimumMaximumCalculator::
25 ~MinimumMaximumCalculator( )
29 // -------------------------------------------------------------------------
30 void cpPluginsImageGenericFilters::MinimumMaximumCalculator::
33 auto o = this->GetInputData( "Input" );
34 cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
35 this->_Error( "Invalid input image." );
38 // -------------------------------------------------------------------------
39 template< class _TImage >
40 void cpPluginsImageGenericFilters::MinimumMaximumCalculator::
41 _GD0( _TImage* input )
43 typedef itk::MinimumMaximumImageCalculator< _TImage > _TFilter;
44 typedef typename _TImage::IndexType _TIndex;
45 typedef typename _TImage::PointType _TPoint;
47 auto filter = this->_CreateITK< _TFilter >( );
48 filter->SetImage( input );
51 _TIndex min_idx = filter->GetIndexOfMinimum( );
52 _TIndex max_idx = filter->GetIndexOfMaximum( );
54 _TPoint min_pnt, max_pnt;
55 input->TransformIndexToPhysicalPoint( min_idx, min_pnt );
56 input->TransformIndexToPhysicalPoint( max_idx, max_pnt );
58 auto min_pd = this->GetOutputData< vtkPolyData >( "Minimum" );
61 auto points = vtkSmartPointer< vtkPoints >::New( );
62 auto verts = vtkSmartPointer< vtkCellArray >::New( );
63 auto lines = vtkSmartPointer< vtkCellArray >::New( );
64 auto polys = vtkSmartPointer< vtkCellArray >::New( );
65 auto strips = vtkSmartPointer< vtkCellArray >::New( );
66 auto pd = vtkSmartPointer< vtkPolyData >::New( );
67 pd->SetPoints( points );
68 pd->SetVerts( verts );
69 pd->SetLines( lines );
70 pd->SetPolys( polys );
71 pd->SetStrips( strips );
73 points->InsertNextPoint( 0, 0, 0 );
74 verts->InsertNextCell( 1 );
75 verts->InsertCellPoint( 0 );
77 this->GetOutput( "Minimum" )->SetVTK( pd );
78 min_pd = this->GetOutputData< vtkPolyData >( "Minimum" );
82 if( _TImage::ImageDimension == 1 )
83 min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], 0, 0 );
84 else if( _TImage::ImageDimension == 2 )
85 min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], min_pnt[ 1 ], 0 );
86 else if( _TImage::ImageDimension > 2 )
87 min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], min_pnt[ 1 ], min_pnt[ 2 ] );
89 auto max_pd = this->GetOutputData< vtkPolyData >( "Maximum" );
92 auto points = vtkSmartPointer< vtkPoints >::New( );
93 auto verts = vtkSmartPointer< vtkCellArray >::New( );
94 auto lines = vtkSmartPointer< vtkCellArray >::New( );
95 auto polys = vtkSmartPointer< vtkCellArray >::New( );
96 auto strips = vtkSmartPointer< vtkCellArray >::New( );
97 auto pd = vtkSmartPointer< vtkPolyData >::New( );
98 pd->SetPoints( points );
99 pd->SetVerts( verts );
100 pd->SetLines( lines );
101 pd->SetPolys( polys );
102 pd->SetStrips( strips );
104 points->InsertNextPoint( 0, 0, 0 );
105 verts->InsertNextCell( 1 );
106 verts->InsertCellPoint( 0 );
108 this->GetOutput( "Maximum" )->SetVTK( pd );
109 max_pd = this->GetOutputData< vtkPolyData >( "Maximum" );
113 if( _TImage::ImageDimension == 1 )
114 max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], 0, 0 );
115 else if( _TImage::ImageDimension == 2 )
116 max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], max_pnt[ 1 ], 0 );
117 else if( _TImage::ImageDimension > 2 )
118 max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], max_pnt[ 1 ], max_pnt[ 2 ] );