]> Creatis software - cpPlugins.git/blob - plugins/ImageGenericFilters/MinimumMaximumCalculator.cxx
6bb519003ab0278be4f34ae56bc9e1b248625982
[cpPlugins.git] / plugins / ImageGenericFilters / MinimumMaximumCalculator.cxx
1 #include <plugins/ImageGenericFilters/MinimumMaximumCalculator.h>
2 #include <cpPlugins/DataObjects/Image.h>
3 #include <cpPlugins/DataObjects/Mesh.h>
4
5 #include <itkMinimumMaximumImageCalculator.h>
6 #include <itkMinimumMaximumImageCalculator.hxx>
7
8 // -------------------------------------------------------------------------
9 cpPluginsImageGenericFilters::MinimumMaximumCalculator::
10 MinimumMaximumCalculator( )
11   : Superclass( )
12 {
13   this->_ConfigureInput< cpPlugins::DataObjects::Image >( "Input", true, false );
14   this->_ConfigureOutput< cpPlugins::DataObjects::Mesh >( "Maximum" );
15   this->_ConfigureOutput< cpPlugins::DataObjects::Mesh >( "Minimum" );
16 }
17
18 // -------------------------------------------------------------------------
19 cpPluginsImageGenericFilters::MinimumMaximumCalculator::
20 ~MinimumMaximumCalculator( )
21 {
22 }
23
24 // -------------------------------------------------------------------------
25 void cpPluginsImageGenericFilters::MinimumMaximumCalculator::
26 _GenerateData( )
27 {
28   auto o = this->GetInputData( "Input" );
29   cpPlugins_Demangle_ImageScalars_Dims( o, _GD0 );
30   else this->_Error( "Invalid input image." );
31 }
32
33 // -------------------------------------------------------------------------
34 template< class _TImage >
35 void cpPluginsImageGenericFilters::MinimumMaximumCalculator::
36 _GD0( _TImage* input )
37 {
38   typedef itk::MinimumMaximumImageCalculator< _TImage > _TFilter;
39   typedef typename _TImage::IndexType _TIndex;
40   typedef typename _TImage::PointType _TPoint;
41
42   auto filter = this->_CreateITK< _TFilter >( );
43   filter->SetImage( input );
44   filter->Compute( );
45
46   _TIndex min_idx = filter->GetIndexOfMinimum( );
47   _TIndex max_idx = filter->GetIndexOfMaximum( );
48
49   _TPoint min_pnt, max_pnt;
50   input->TransformIndexToPhysicalPoint( min_idx, min_pnt );
51   input->TransformIndexToPhysicalPoint( max_idx, max_pnt );
52
53   auto min_pd = this->GetOutputData< vtkPolyData >( "Minimum" );
54   if( min_pd == NULL )
55   {
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 );
67
68     points->InsertNextPoint( 0, 0, 0 );
69     verts->InsertNextCell( 1 );
70     verts->InsertCellPoint( 0 );
71
72     this->GetOutput( "Minimum" )->SetVTK( pd );
73     min_pd = this->GetOutputData< vtkPolyData >( "Minimum" );
74
75   } // fi
76
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 ] );
83
84   auto max_pd = this->GetOutputData< vtkPolyData >( "Maximum" );
85   if( max_pd == NULL )
86   {
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 );
98
99     points->InsertNextPoint( 0, 0, 0 );
100     verts->InsertNextCell( 1 );
101     verts->InsertCellPoint( 0 );
102
103     this->GetOutput( "Maximum" )->SetVTK( pd );
104     max_pd = this->GetOutputData< vtkPolyData >( "Maximum" );
105
106   } // fi
107
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 ] );
114 }
115
116 // eof - $RCSfile$