]> Creatis software - cpPlugins.git/blobdiff - plugins/ImageSources/RandomImageSource.cxx
...
[cpPlugins.git] / plugins / ImageSources / RandomImageSource.cxx
index b0ef6c4b8f1fdc378d9cf8db2abe3dbbfb3589d0..d726feda2f81dcec37ed80065dc011b7b12ddc0f 100644 (file)
@@ -1,8 +1,7 @@
-#include <plugins/ImageSources/RandomImageSource.h>
+#include <ImageSources/RandomImageSource.h>
 #include <cpPlugins/DataObjects/Image.h>
 
 #include <itkRandomImageSource.h>
-#include <itkRandomImageSource.hxx>
 
 // -------------------------------------------------------------------------
 cpPluginsImageSources::RandomImageSource::
@@ -15,26 +14,44 @@ RandomImageSource( )
   this->m_Parameters.ConfigureAsRealList( "Spacing" );
 
   std::vector< std::string > pixels;
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
   pixels.push_back( "char" );
-  pixels.push_back( "short" );
-  pixels.push_back( "int" );
-  pixels.push_back( "long" );
   pixels.push_back( "uchar" );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_char
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
+  pixels.push_back( "short" );
   pixels.push_back( "ushort" );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_short
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
+  pixels.push_back( "int" );
   pixels.push_back( "uint" );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_int
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
+  pixels.push_back( "long" );
   pixels.push_back( "ulong" );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_long
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_float
   pixels.push_back( "float" );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_float
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_double
   pixels.push_back( "double" );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_double
   this->m_Parameters.ConfigureAsChoices( "PixelType", pixels );
-  this->m_Parameters.SetSelectedChoice( "PixelType", "uchar" );
 
   std::vector< std::string > dims;
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
   dims.push_back( "1" );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
   dims.push_back( "2" );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
   dims.push_back( "3" );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
   dims.push_back( "4" );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
   this->m_Parameters.ConfigureAsChoices( "Dimension", dims );
-  this->m_Parameters.SetSelectedChoice( "Dimension", "2" );
 }
 
 // -------------------------------------------------------------------------
@@ -47,36 +64,61 @@ cpPluginsImageSources::RandomImageSource::
 void cpPluginsImageSources::RandomImageSource::
 _GenerateData( )
 {
+  bool success = false;
   auto pixel = this->m_Parameters.GetSelectedChoice( "PixelType" );
-  if     ( pixel == "char"   ) this->_GD0< char >( );
-  else if( pixel == "short"  ) this->_GD0< short >( );
-  else if( pixel == "int"    ) this->_GD0< int >( );
-  else if( pixel == "long"   ) this->_GD0< long >( );
-  else if( pixel == "uchar"  ) this->_GD0< unsigned char >( );
-  else if( pixel == "ushort" ) this->_GD0< unsigned short >( );
-  else if( pixel == "uint"   ) this->_GD0< unsigned int >( );
-  else if( pixel == "ulong"  ) this->_GD0< unsigned long >( );
-  else if( pixel == "float"  ) this->_GD0< float >( );
-  else if( pixel == "double" ) this->_GD0< double >( );
-  else this->_Error( "Invalid pixel type." );
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_char
+  if( pixel == "char"   ) success = this->_GD0< char >( );
+  if( pixel == "uchar"  ) success = this->_GD0< unsigned char >( );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_char
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_short
+  if( pixel == "short"  ) success = this->_GD0< short >( );
+  if( pixel == "ushort" ) success = this->_GD0< unsigned short >( );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_short
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_int
+  if( pixel == "int"    ) success = this->_GD0< int >( );
+  if( pixel == "uint"   ) success = this->_GD0< unsigned int >( );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_int
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_long
+  if( pixel == "long"   ) success = this->_GD0< long >( );
+  if( pixel == "ulong"  ) success = this->_GD0< unsigned long >( );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_long
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_float
+  if( pixel == "float"  ) success = this->_GD0< float >( );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_float
+#ifdef cpPlugins_CONFIG_INTEGER_TYPES_double
+  if( pixel == "double" ) success = this->_GD0< double >( );
+#endif // cpPlugins_CONFIG_INTEGER_TYPES_double
+  if( !success )
+    this->_Error( "Invalid pixel type." );
 }
 
 // -------------------------------------------------------------------------
 template< class _TPixel >
-void cpPluginsImageSources::RandomImageSource::
+bool cpPluginsImageSources::RandomImageSource::
 _GD0( )
 {
+  bool success = false;
   auto dim = this->m_Parameters.GetSelectedChoice( "Dimension" );
-  if     ( dim == "1" ) this->_GD1< _TPixel, 1 >( );
-  else if( dim == "2" ) this->_GD1< _TPixel, 2 >( );
-  else if( dim == "3" ) this->_GD1< _TPixel, 3 >( );
-  else if( dim == "4" ) this->_GD1< _TPixel, 4 >( );
-  else this->_Error( "Invalid dimension." );
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
+  if( dim == "1" ) success = this->_GD1< _TPixel, 1 >( );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
+  if( dim == "2" ) success = this->_GD1< _TPixel, 2 >( );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
+  if( dim == "3" ) success = this->_GD1< _TPixel, 3 >( );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
+  if( dim == "4" ) success = this->_GD1< _TPixel, 4 >( );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
+  if( !success )
+    this->_Error( "Invalid dimension." );
+  return( success );
 }
 
 // -------------------------------------------------------------------------
 template< class _TPixel, unsigned int _VDim >
-void cpPluginsImageSources::RandomImageSource::
+bool cpPluginsImageSources::RandomImageSource::
 _GD1( )
 {
   typedef itk::Image< _TPixel, _VDim >      _TImage;
@@ -103,6 +145,7 @@ _GD1( )
   filter->SetSpacing( out_spac );
   filter->Update( );
   this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
+  return( true );
 }
 
 // eof - $RCSfile$