]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 23 Nov 2016 13:40:56 +0000 (08:40 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 23 Nov 2016 13:40:56 +0000 (08:40 -0500)
appli/CMakeLists.txt
appli/plugins/CMakeLists.txt [new file with mode: 0644]
appli/plugins/ExecutePipeline.cxx [new file with mode: 0644]
lib/cpInstances/UnaryFunctorFilters.i
plugins/ITKUnaryFunctorFilters/AbsImageFilter.cxx [new file with mode: 0644]
plugins/ITKUnaryFunctorFilters/AbsImageFilter.h [new file with mode: 0644]
plugins/VTKFilters/MarchingCubes.cxx [new file with mode: 0644]
plugins/VTKFilters/MarchingCubes.h [new file with mode: 0644]

index b1e3af3bbc55a4d5d83bbd068b60cb563f9ff005..7daf31923ad5fd4bb8af0418a93bb25c3992e6ff 100644 (file)
@@ -1,4 +1,4 @@
 
-SUBDIRS(bash examples PipelineEditor)
+SUBDIRS(bash plugins examples PipelineEditor)
 
 ## eof - $RCSfile$
diff --git a/appli/plugins/CMakeLists.txt b/appli/plugins/CMakeLists.txt
new file mode 100644 (file)
index 0000000..d9f331f
--- /dev/null
@@ -0,0 +1,19 @@
+INCLUDE_DIRECTORIES(
+  ${PROJECT_SOURCE_DIR}/lib
+  ${PROJECT_BINARY_DIR}/lib
+  )
+SET(
+  _plugins_APPS
+  ExecutePipeline
+  )
+FOREACH(_app ${_plugins_APPS})
+  ADD_EXECUTABLE(cpPlugins_plugins_${_app} ${_app})
+  TARGET_LINK_LIBRARIES(cpPlugins_plugins_${_app} cpPlugins)
+  SET(
+    cpPlugins_plugins_${_app}_APP cpPlugins_plugins_${_app}
+    CACHE INTERNAL "bash program cpPlugins_plugins_${_app}"
+    )
+ENDFOREACH(_app)
+
+
+## eof - $RCSfile$
diff --git a/appli/plugins/ExecutePipeline.cxx b/appli/plugins/ExecutePipeline.cxx
new file mode 100644 (file)
index 0000000..128583d
--- /dev/null
@@ -0,0 +1,84 @@
+#include <iostream>
+#include <cpPlugins/Utility.h>
+#include <cpPlugins/Interface/Plugins.h>
+#include <cpPlugins/Interface/Workspace.h>
+
+int main( int argc, char* argv[] )
+{
+  // Manage inputs
+  if( argc < 2 )
+  {
+    std::cerr
+      << "Usage: " << argv[ 0 ]
+      << " workspace [parameters]" << std::endl;
+    return( 1 );
+
+  } // fi
+
+  // Create interface and load library
+  cpPlugins::Interface::Plugins::Pointer interface =
+    cpPlugins::Interface::Plugins::New( );
+  try
+  {
+    interface->GuessPlugins( );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << "Error caught: " << err.what( ) << std::endl;
+    return( 1 );
+
+  } // yrt
+
+  // Workspace
+  cpPlugins::Interface::Workspace::Pointer workspace =
+    cpPlugins::Interface::Workspace::New( );
+  try
+  {
+    workspace->Load( argv[ 1 ] );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr
+      << "Error loading workspace \"" << argv[ 1 ]
+      << "\": " << err.what( ) << std::endl;
+    return( 1 );
+
+  } // yrt
+    
+  // Read parameters
+  for( int i = 2; i < argc; ++i )
+  {
+    std::vector< std::string > tokens;
+    cpPlugins::Tokenize( tokens, argv[ i ], "@=" );
+    if( tokens.size( ) == 3 )
+    {
+      auto filter = workspace->GetFilter( tokens[ 1 ] );
+      if( filter != NULL )
+      {
+        auto params = filter->GetParameters( );
+        params->SetString( tokens[ 0 ], tokens[ 2 ], true );
+
+      } // fi
+
+    } // fi
+
+  } // rof
+
+  // Execute filter
+  workspace->PrintExecutionOn( );
+  try
+  {
+    workspace->Update( );
+  }
+  catch( std::exception& err )
+  {
+    std::cerr << std::endl << "********************************" << std::endl;
+    std::cerr << "Error caught: " << err.what( ) << std::endl;
+    std::cerr << "********************************" << std::endl;
+    return( 1 );
+
+  } // yrt
+  return( 0 );
+}
+
+// eof - $RCSfile$
index 7ae9eb3059a59c9a5e8a2f3f7e44bac579d43e2c..55e0a696336f951618da83ae5163e37050462e2a 100644 (file)
@@ -3,15 +3,17 @@ header #define ITK_MANUAL_INSTANTIATION
 define all_ints=#int_types#;#uint_types#
 define in_scalars=#scalar_pixels#
 define out_scalars=#scalar_pixels#
+define filters=AbsImageFilter;NotImageFilter
 
 tinclude itkUnaryFunctorImageFilter:h|hxx
 tinclude itkInvertIntensityImageFilter:h|hxx
 tinclude itkBinaryThresholdImageFilter:h|hxx
 tinclude itkCastImageFilter:h|hxx
 
-cinclude itkNotImageFilter.h
+cinclude itk#filters#.h
 
 instances itk::UnaryFunctorImageFilter< itk::Image< #all_ints#, #process_dims# >, itk::Image< #all_ints#, #process_dims# >, itk::Functor::NOT< #all_ints#, #all_ints# > >
+instances itk::UnaryFunctorImageFilter< itk::Image< #scalar_pixels#, #process_dims# >, itk::Image< #scalar_pixels#, #process_dims# >, itk::Functor::Abs< #scalar_pixels#, #scalar_pixels# > >
 
 instances itk::CastImageFilter< itk::Image< #in_scalars#, #process_dims# >, itk::Image< #out_scalars#, #process_dims# > >
 
diff --git a/plugins/ITKUnaryFunctorFilters/AbsImageFilter.cxx b/plugins/ITKUnaryFunctorFilters/AbsImageFilter.cxx
new file mode 100644 (file)
index 0000000..1249a4f
--- /dev/null
@@ -0,0 +1,46 @@
+#include <ITKUnaryFunctorFilters/AbsImageFilter.h>
+#include <cpInstances/Image.h>
+
+#include <itkAbsImageFilter.h>
+
+// -------------------------------------------------------------------------
+cpPluginsITKUnaryFunctorFilters::AbsImageFilter::
+AbsImageFilter( )
+  : Superclass( )
+{
+  typedef cpInstances::Image _TImage;
+
+  this->_ConfigureInput< _TImage >( "Input", true, false );
+  this->_ConfigureOutput< _TImage >( "Output" );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsITKUnaryFunctorFilters::AbsImageFilter::
+~AbsImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsITKUnaryFunctorFilters::AbsImageFilter::
+_GenerateData( )
+{
+  auto o = this->GetInputData( "Input" );
+  cpPlugins_Demangle_Image_ScalarPixels_AllDims_1( o, _GD0 )
+    this->_Error( "Invalid input image." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpPluginsITKUnaryFunctorFilters::AbsImageFilter::
+_GD0( _TImage* image )
+{
+  typedef itk::AbsImageFilter< _TImage, _TImage > _TFilter;
+
+  // Configure filter
+  auto filter = this->_CreateITK< _TFilter >( );
+  filter->SetInput( image );
+  filter->Update( );
+  this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/ITKUnaryFunctorFilters/AbsImageFilter.h b/plugins/ITKUnaryFunctorFilters/AbsImageFilter.h
new file mode 100644 (file)
index 0000000..8d03b10
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __cpPluginsITKUnaryFunctorFilters__AbsImageFilter__h__
+#define __cpPluginsITKUnaryFunctorFilters__AbsImageFilter__h__
+
+#include <cpPluginsITKUnaryFunctorFilters_Export.h>
+#include <cpPlugins/BaseObjects/ProcessObject.h>
+
+namespace cpPluginsITKUnaryFunctorFilters
+{
+  /**
+   */
+  class cpPluginsITKUnaryFunctorFilters_EXPORT AbsImageFilter
+    : public cpPlugins::BaseObjects::ProcessObject
+  {
+    cpPluginsObject(
+      AbsImageFilter,
+      cpPlugins::BaseObjects::ProcessObject,
+      ImageFilters
+      );
+
+  protected:
+    template< class _TImage >
+    inline void _GD0( _TImage* image );
+  };
+
+} // ecapseman
+
+#endif // __cpPluginsITKUnaryFunctorFilters__AbsImageFilter__h__
+
+// eof - $RCSfile$
diff --git a/plugins/VTKFilters/MarchingCubes.cxx b/plugins/VTKFilters/MarchingCubes.cxx
new file mode 100644 (file)
index 0000000..b8a7866
--- /dev/null
@@ -0,0 +1,64 @@
+#include <VTKFilters/MarchingCubes.h>
+#include <cpInstances/Image.h>
+#include <cpInstances/Mesh.h>
+
+#include <vtkImageData.h>
+#include <vtkMarchingCubes.h>
+#include <vtkMarchingSquares.h>
+
+// -------------------------------------------------------------------------
+cpPluginsVTKFilters::MarchingCubes::
+MarchingCubes( )
+  : Superclass( )
+{
+  this->_ConfigureInput< cpInstances::Image >( "Input", true, false );
+  this->_ConfigureOutput< cpInstances::Mesh >( "Output" );
+  this->m_Parameters.ConfigureAsRealList( "Thresholds" );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsVTKFilters::MarchingCubes::
+~MarchingCubes( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsVTKFilters::MarchingCubes::
+_GenerateData( )
+{
+  // Get input
+  auto image = this->GetInput( "Input" );
+  vtkImageData* vtk_image = image->GetVTK< vtkImageData >( );
+  if( vtk_image == NULL )
+    this->_Error( "Input does not have a valid VTK conversion." );
+
+  std::vector< double > values =
+    this->m_Parameters.GetRealList( "Thresholds" );
+  vtkPolyData* pd = NULL;
+  if( vtk_image->GetDataDimension( ) == 2 )
+  {
+    vtkMarchingSquares* ms = this->_CreateVTK< vtkMarchingSquares >( );
+    ms->SetInputData( vtk_image );
+    for( unsigned int i = 0; i < values.size( ); ++i )
+      ms->SetValue( i, values[ i ] );
+    ms->Update( );
+    pd = ms->GetOutput( );
+  }
+  else if( vtk_image->GetDataDimension( ) == 3 )
+  {
+    vtkMarchingCubes* mc = this->_CreateVTK< vtkMarchingCubes >( );
+    mc->ComputeNormalsOff( );
+    mc->SetInputData( vtk_image );
+    for( unsigned int i = 0; i < values.size( ); ++i )
+      mc->SetValue( i, values[ i ] );
+    mc->Update( );
+    pd = mc->GetOutput( );
+  }
+  else
+    this->_Error( "Input data does not have a valid dimension." );
+
+  // Connect output
+  this->GetOutput( "Output" )->SetVTK( pd );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/VTKFilters/MarchingCubes.h b/plugins/VTKFilters/MarchingCubes.h
new file mode 100644 (file)
index 0000000..fe29362
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef __cpPluginsVTKFilters__MarchingCubes__h__
+#define __cpPluginsVTKFilters__MarchingCubes__h__
+
+#include <cpPluginsVTKFilters_Export.h>
+#include <cpPlugins/BaseObjects/ProcessObject.h>
+
+namespace cpPluginsVTKFilters
+{
+  /**
+   */
+  class cpPluginsVTKFilters_EXPORT MarchingCubes
+    : public cpPlugins::BaseObjects::ProcessObject
+  {
+    cpPluginsObject(
+      MarchingCubes,
+      cpPlugins::BaseObjects::ProcessObject,
+      ImageToMeshFilters
+      );
+  };
+
+} // ecapseman
+
+#endif // __cpPluginsVTKFilters__MarchingCubes__h__
+
+// eof - $RCSfile$