]> Creatis software - cpPlugins.git/blob - plugins/cpPluginsVisualization/IndexesToPolyData.cxx
9e4b65cd92d8bcdd294866b522a668a20a854c25
[cpPlugins.git] / plugins / cpPluginsVisualization / IndexesToPolyData.cxx
1 #include <cpPluginsVisualization/IndexesToPolyData.h>
2 #include <cpPlugins/Image.h>
3 #include <cpPlugins/Mesh.h>
4
5 #include <cpExtensions/Visualization/IndexesToPolyData.h>
6 #include <cpExtensions/Visualization/IndexesToPolyData.hxx>
7
8 // -------------------------------------------------------------------------
9 cpPluginsVisualization::IndexesToPolyData::
10 IndexesToPolyData( )
11   : Superclass( )
12 {
13   this->_AddInput( "Input" );
14   this->_AddInput( "ReferenceImage", false );
15   this->_AddOutput< cpPlugins::Mesh >( "Output" );
16 }
17
18 // -------------------------------------------------------------------------
19 cpPluginsVisualization::IndexesToPolyData::
20 ~IndexesToPolyData( )
21 {
22 }
23
24 // -------------------------------------------------------------------------
25 std::string cpPluginsVisualization::IndexesToPolyData::
26 _GenerateData( )
27 {
28   typedef itk::SimpleDataObjectDecorator< std::vector< itk::Index< 2 > > > _2D;
29   typedef itk::SimpleDataObjectDecorator< std::vector< itk::Index< 3 > > > _3D;
30
31   auto indexes = this->GetInputData( "Input" )->GetITK< itk::DataObject >( );
32   auto indexes2D = dynamic_cast< _2D* >( indexes );
33   auto indexes3D = dynamic_cast< _3D* >( indexes );
34   if( indexes2D != NULL )
35     return( this->_GD0( indexes2D ) );
36   else if( indexes3D != NULL )
37     return( this->_GD0( indexes3D ) );
38   else
39     return( "cpPluginsVisualization::IndexesToPolyData: no valid input." );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class _TIndexes >
44 std::string cpPluginsVisualization::IndexesToPolyData::
45 _GD0( _TIndexes* indexes )
46 {
47   typedef
48     cpExtensions::Visualization::IndexesToPolyData< _TIndexes >
49     _TFilter;
50   typedef typename _TFilter::TImage _TImage;
51
52   // Configure filter
53   _TFilter* filter = this->_CreateVTK< _TFilter >( );
54   filter->SetInput( indexes );
55   filter->SetReferenceImage(
56     this->GetInputData( "Input" )->GetITK< _TImage >( )
57     );
58   filter->Update( );
59
60   // Connect output
61   this->GetOutputData( "Output" )->SetVTK( filter->GetOutput( ) );
62   return( "" );
63 }
64
65 // eof - $RCSfile$