1 #include <ITKImageGenericFilters_1/MinimumMaximumImageCalculator.h>
2 #include <cpInstances/DataObjects/Image.h>
3 #include <cpInstances/DataObjects/Mesh.h>
6 #include <itkMinimumMaximumImageCalculator.h>
7 #include <vtkPolyData.h>
9 // -------------------------------------------------------------------------
10 cpPluginsITKImageGenericFilters_1::MinimumMaximumImageCalculator::
11 MinimumMaximumImageCalculator( )
14 typedef cpInstances::DataObjects::Image _TImage;
15 typedef cpInstances::DataObjects::Mesh _TMesh;
17 this->_ConfigureInput< _TImage >( "Input", true, false );
18 this->_ConfigureOutput< _TMesh >( "Maximum" );
19 this->_ConfigureOutput< _TMesh >( "Minimum" );
22 // -------------------------------------------------------------------------
23 cpPluginsITKImageGenericFilters_1::MinimumMaximumImageCalculator::
24 ~MinimumMaximumImageCalculator( )
28 // -------------------------------------------------------------------------
29 void cpPluginsITKImageGenericFilters_1::MinimumMaximumImageCalculator::
32 auto o = this->GetInputData( "Input" );
33 cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
34 this->_Error( "Invalid input image." );
37 // -------------------------------------------------------------------------
38 template< class _TImage >
39 void cpPluginsITKImageGenericFilters_1::MinimumMaximumImageCalculator::
40 _GD0( _TImage* input )
42 typedef itk::MinimumMaximumImageCalculator< _TImage > _TFilter;
43 typedef typename _TImage::IndexType _TIndex;
44 typedef typename _TImage::PointType _TPoint;
46 auto filter = this->_CreateITK< _TFilter >( );
47 filter->SetImage( input );
50 _TIndex min_idx = filter->GetIndexOfMinimum( );
51 _TIndex max_idx = filter->GetIndexOfMaximum( );
53 _TPoint min_pnt, max_pnt;
54 input->TransformIndexToPhysicalPoint( min_idx, min_pnt );
55 input->TransformIndexToPhysicalPoint( max_idx, max_pnt );
57 auto min_pd = this->GetOutputData< vtkPolyData >( "Minimum" );
60 auto points = vtkSmartPointer< vtkPoints >::New( );
61 auto verts = vtkSmartPointer< vtkCellArray >::New( );
62 auto lines = vtkSmartPointer< vtkCellArray >::New( );
63 auto polys = vtkSmartPointer< vtkCellArray >::New( );
64 auto strips = vtkSmartPointer< vtkCellArray >::New( );
65 auto pd = vtkSmartPointer< vtkPolyData >::New( );
66 pd->SetPoints( points );
67 pd->SetVerts( verts );
68 pd->SetLines( lines );
69 pd->SetPolys( polys );
70 pd->SetStrips( strips );
72 points->InsertNextPoint( 0, 0, 0 );
73 verts->InsertNextCell( 1 );
74 verts->InsertCellPoint( 0 );
76 this->GetOutput( "Minimum" )->SetVTK( pd );
77 min_pd = this->GetOutputData< vtkPolyData >( "Minimum" );
81 if( _TImage::ImageDimension == 1 )
82 min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], 0, 0 );
83 else if( _TImage::ImageDimension == 2 )
84 min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], min_pnt[ 1 ], 0 );
85 else if( _TImage::ImageDimension > 2 )
86 min_pd->GetPoints( )->SetPoint( 0, min_pnt[ 0 ], min_pnt[ 1 ], min_pnt[ 2 ] );
88 auto max_pd = this->GetOutputData< vtkPolyData >( "Maximum" );
91 auto points = vtkSmartPointer< vtkPoints >::New( );
92 auto verts = vtkSmartPointer< vtkCellArray >::New( );
93 auto lines = vtkSmartPointer< vtkCellArray >::New( );
94 auto polys = vtkSmartPointer< vtkCellArray >::New( );
95 auto strips = vtkSmartPointer< vtkCellArray >::New( );
96 auto pd = vtkSmartPointer< vtkPolyData >::New( );
97 pd->SetPoints( points );
98 pd->SetVerts( verts );
99 pd->SetLines( lines );
100 pd->SetPolys( polys );
101 pd->SetStrips( strips );
103 points->InsertNextPoint( 0, 0, 0 );
104 verts->InsertNextCell( 1 );
105 verts->InsertCellPoint( 0 );
107 this->GetOutput( "Maximum" )->SetVTK( pd );
108 max_pd = this->GetOutputData< vtkPolyData >( "Maximum" );
112 if( _TImage::ImageDimension == 1 )
113 max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], 0, 0 );
114 else if( _TImage::ImageDimension == 2 )
115 max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], max_pnt[ 1 ], 0 );
116 else if( _TImage::ImageDimension > 2 )
117 max_pd->GetPoints( )->SetPoint( 0, max_pnt[ 0 ], max_pnt[ 1 ], max_pnt[ 2 ] );