1 #include <cpPlugins/Plugins/MarchingCubes.h>
2 #include <cpPlugins/Interface/Image.h>
3 #include <cpPlugins/Interface/Mesh.h>
5 #include <itkImageFileReader.h>
7 #define ITK_MANUAL_INSTANTIATION
9 #include <itkRGBPixel.h>
11 // -------------------------------------------------------------------------
12 std::string cpPlugins::Plugins::MarchingCubes::
15 return( "cpPlugins::Plugins::MarchingCubes" );
18 // -------------------------------------------------------------------------
19 cpPlugins::Plugins::MarchingCubes::
23 this->SetNumberOfInputs( 1 );
24 this->SetNumberOfOutputs( 1 );
25 this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
28 this->m_DefaultParameters[ "FileName" ] =
29 TParameter( "string", "no_file_name" );
30 this->m_DefaultParameters[ "PixelType" ] = TParameter( "type", "uchar" );
31 this->m_DefaultParameters[ "ImageDimension" ] = TParameter( "int", "2" );
32 this->m_DefaultParameters[ "IsColorImage" ] = TParameter( "bool", "0" );
36 // -------------------------------------------------------------------------
37 cpPlugins::Plugins::MarchingCubes::
42 // -------------------------------------------------------------------------
43 std::string cpPlugins::Plugins::MarchingCubes::
48 TParameters::const_iterator dIt;
50 // Get image dimension
51 dIt = this->m_Parameters.find( "ImageDimension" );
52 if( dIt == this->m_Parameters.end( ) )
53 dIt = this->m_DefaultParameters.find( "ImageDimension" );
55 std::string r = "cpPlugins::Plugins::MarchingCubes: itk::Image dimension not supported.";
56 if ( dIt->second.second == "1" ) r = this->_GD0< 1 >( );
57 else if( dIt->second.second == "2" ) r = this->_GD0< 2 >( );
58 else if( dIt->second.second == "3" ) r = this->_GD0< 3 >( );
59 else if( dIt->second.second == "4" ) r = this->_GD0< 4 >( );
65 // -------------------------------------------------------------------------
66 template< unsigned int D >
67 std::string cpPlugins::Plugins::MarchingCubes::
72 TParameters::const_iterator tIt, cIt;
74 // Get image pixel type
75 tIt = this->m_Parameters.find( "PixelType" );
76 if( tIt == this->m_Parameters.end( ) )
77 tIt = this->m_DefaultParameters.find( "PixelType" );
78 cIt = this->m_Parameters.find( "IsColorImage" );
79 if( cIt == this->m_Parameters.end( ) )
80 cIt = this->m_DefaultParameters.find( "IsColorImage" );
82 std::string r = "cpPlugins::Plugins::MarchingCubes: itk::Image pixel type not supported";
83 if( cIt->second.second == "0" )
85 if( tIt->second.second == "char" )
86 r = this->_GD1< char, D >( );
87 else if( tIt->second.second == "short" )
88 r = this->_GD1< short, D >( );
89 else if( tIt->second.second == "int" )
90 r = this->_GD1< int, D >( );
91 else if( tIt->second.second == "long" )
92 r = this->_GD1< long, D >( );
93 else if( tIt->second.second == "uchar" )
94 r = this->_GD1< unsigned char, D >( );
95 else if( tIt->second.second == "ushort" )
96 r = this->_GD1< unsigned short, D >( );
97 else if( tIt->second.second == "uint" )
98 r = this->_GD1< unsigned int, D >( );
99 else if( tIt->second.second == "ulong" )
100 r = this->_GD1< unsigned long, D >( );
101 else if( tIt->second.second == "float" )
102 r = this->_GD1< float, D >( );
103 else if( tIt->second.second == "double" )
104 r = this->_GD1< double, D >( );
106 else if( cIt->second.second == "1" )
108 if( tIt->second.second == "char" )
109 r = this->_GD1< itk::RGBPixel< char >, D >( );
110 else if( tIt->second.second == "short" )
111 r = this->_GD1< itk::RGBPixel< short >, D >( );
112 else if( tIt->second.second == "int" )
113 r = this->_GD1< itk::RGBPixel< int >, D >( );
114 else if( tIt->second.second == "long" )
115 r = this->_GD1< itk::RGBPixel< long >, D >( );
116 else if( tIt->second.second == "uchar" )
117 r = this->_GD1< itk::RGBPixel< unsigned char >, D >( );
118 else if( tIt->second.second == "ushort" )
119 r = this->_GD1< itk::RGBPixel< unsigned short >, D >( );
120 else if( tIt->second.second == "uint" )
121 r = this->_GD1< itk::RGBPixel< unsigned int >, D >( );
122 else if( tIt->second.second == "ulong" )
123 r = this->_GD1< itk::RGBPixel< unsigned long >, D >( );
124 else if( tIt->second.second == "float" )
125 r = this->_GD1< itk::RGBPixel< float >, D >( );
126 else if( tIt->second.second == "double" )
127 r = this->_GD1< itk::RGBPixel< double >, D >( );
133 // -------------------------------------------------------------------------
134 template< class P, unsigned int D >
135 std::string cpPlugins::Plugins::MarchingCubes::
140 TParameters::const_iterator fIt;
143 fIt = this->m_Parameters.find( "FileName" );
144 if( fIt == this->m_Parameters.end( ) )
145 fIt = this->m_DefaultParameters.find( "FileName" );
147 typedef itk::Image< P, D > _TImage;
148 typedef itk::ImageFileReader< _TImage > _TReader;
151 dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) );
154 this->m_Reader = _TReader::New( );
155 reader = dynamic_cast< _TReader* >( this->m_Reader.GetPointer( ) );
158 reader->SetFileName( fIt->second.second );
163 catch( itk::ExceptionObject& err )
165 return( err.GetDescription( ) );
168 this->_SetOutput( 0, reader->GetOutput( ) );