From a13f931723180e65d7dfdef297c465956952eb7a Mon Sep 17 00:00:00 2001 From: Leonardo Florez-Valencia Date: Tue, 2 Jun 2015 19:35:44 -0500 Subject: [PATCH] ITK-VTK-Qt4-CMake coordination/factory problem finally solvedgit status! --- CMakeLists.txt | 64 +--- appli/examples/CMakeLists.txt | 6 + appli/examples/example_1DImageGradient.cxx | 84 +++++ .../example_2DGulsunTekMedialness.cxx | 220 ++++++++++++ appli/examples/example_2DImageGradient.cxx | 84 +++++ .../example_3DGulsunTekMedialness.cxx | 118 +++++++ appli/examples/example_3DImageGradient.cxx | 84 +++++ .../Algorithms/GradientFunctionBase.h | 86 +++++ .../Algorithms/GradientFunctionBase.hxx | 82 +++++ .../Algorithms/GulsunTekMedialness.h | 87 +++++ .../Algorithms/GulsunTekMedialness.hxx | 197 +++++++++++ .../Algorithms/ImageFunctionFilter.h | 108 ++++++ .../Extensions/Algorithms/InertiaMedialness.h | 217 ++++++++++++ .../Algorithms/InertiaTensorFunction.h | 182 ++++++++++ .../MultiScaleGaussianImageFilter.h | 104 ++++++ .../MultiScaleGaussianImageFilter.hxx | 315 ++++++++++++++++++ .../Algorithms/RGBExtractFunction.h | 58 ++++ lib/cpPlugins/Extensions/CMakeLists.txt | 12 +- .../Visualization/MPRWithDifferentWindows.cxx | 10 + .../Visualization/MPRWithDifferentWindows.h | 2 + lib/cpPlugins/Plugins/CMakeLists.txt | 3 - .../ItkVtkGlue/itkImageToVTKImageFilter.h | 108 ++++++ .../ItkVtkGlue/itkImageToVTKImageFilter.hxx | 129 +++++++ .../ItkVtkGlue/itkVTKImageToImageFilter.h | 100 ++++++ .../ItkVtkGlue/itkVTKImageToImageFilter.hxx | 107 ++++++ 25 files changed, 2514 insertions(+), 53 deletions(-) create mode 100644 appli/examples/example_1DImageGradient.cxx create mode 100644 appli/examples/example_2DGulsunTekMedialness.cxx create mode 100644 appli/examples/example_2DImageGradient.cxx create mode 100644 appli/examples/example_3DGulsunTekMedialness.cxx create mode 100644 appli/examples/example_3DImageGradient.cxx create mode 100644 lib/cpPlugins/Extensions/Algorithms/GradientFunctionBase.h create mode 100644 lib/cpPlugins/Extensions/Algorithms/GradientFunctionBase.hxx create mode 100644 lib/cpPlugins/Extensions/Algorithms/GulsunTekMedialness.h create mode 100644 lib/cpPlugins/Extensions/Algorithms/GulsunTekMedialness.hxx create mode 100644 lib/cpPlugins/Extensions/Algorithms/ImageFunctionFilter.h create mode 100644 lib/cpPlugins/Extensions/Algorithms/InertiaMedialness.h create mode 100644 lib/cpPlugins/Extensions/Algorithms/InertiaTensorFunction.h create mode 100644 lib/cpPlugins/Extensions/Algorithms/MultiScaleGaussianImageFilter.h create mode 100644 lib/cpPlugins/Extensions/Algorithms/MultiScaleGaussianImageFilter.hxx create mode 100644 lib/cpPlugins/Extensions/Algorithms/RGBExtractFunction.h create mode 100644 lib/third_party/ItkVtkGlue/itkImageToVTKImageFilter.h create mode 100644 lib/third_party/ItkVtkGlue/itkImageToVTKImageFilter.hxx create mode 100644 lib/third_party/ItkVtkGlue/itkVTKImageToImageFilter.h create mode 100644 lib/third_party/ItkVtkGlue/itkVTKImageToImageFilter.hxx diff --git a/CMakeLists.txt b/CMakeLists.txt index 61a150b..c64dad9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,20 +1,8 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) -# for CMake 2.6 corrected behaviour (see "cmake --help-policy CMP0003") -IF( - COMMAND cmake_policy AND - ${CMAKE_MAJOR_VERSION} EQUAL 2 AND - ${CMAKE_MINOR_VERSION} GREATER 4 - ) - CMAKE_POLICY(SET CMP0003 NEW) - CMAKE_POLICY(SET CMP0005 NEW) - CMAKE_POLICY(SET CMP0011 NEW) - CMAKE_POLICY(SET CMP0012 NEW) -ENDIF( - COMMAND cmake_policy AND - ${CMAKE_MAJOR_VERSION} EQUAL 2 AND - ${CMAKE_MINOR_VERSION} GREATER 4 - ) +IF(POLICY CMP0020) + CMAKE_POLICY(SET CMP0020 NEW) +ENDIF(POLICY CMP0020) ## ================ ## = Project name = @@ -42,38 +30,16 @@ OPTION(BUILD_EXAMPLES "Build examples" OFF) INCLUDE(GenerateExportHeader) -## ------------------------------------------------------------------------- -## If compiling on UNIX-like OS, an error could arise when using ITKVtkGlue: -## -## :0:0: warning: "vtkRenderingCore_AUTOINIT" redefined -## :0:0: note: this is the location of the previous definition -## -## This is avoided by not including the VTK_USE_FILE. Nevertheless, this fails -## on MS-Win OS. -## -## This is due to object factories. To avoid this, and let the project be -## usable on UNIX-like and MS-Win, the way to find ITK and VTK differs -## ------------------------------------------------------------------------- - -IF(UNIX) - FIND_PACKAGE(ITK REQUIRED) - FIND_PACKAGE(VTK REQUIRED) - INCLUDE(${ITK_USE_FILE}) - IF(NOT ITKVtkGlue_LOADED) - MESSAGE(FATAL_ERROR "ITKVtkGlue module is required but not available.") - ENDIF(NOT ITKVtkGlue_LOADED) -ELSE(UNIX) - FIND_PACKAGE(ITK REQUIRED) - INCLUDE(${ITK_USE_FILE}) - IF(ITKVtkGlue_LOADED) - FIND_PACKAGE(VTK REQUIRED) - INCLUDE(${VTK_USE_FILE}) - ELSE(ITKVtkGlue_LOADED) - FIND_PACKAGE(ItkVtkGlue REQUIRED) - INCLUDE(${ItkVtkGlue_USE_FILE}) - SET(Glue ItkVtkGlue) - ENDIF(ITKVtkGlue_LOADED) -ENDIF(UNIX) +FIND_PACKAGE(ITK REQUIRED) +INCLUDE(${ITK_USE_FILE}) + +FIND_PACKAGE(VTK REQUIRED) +INCLUDE(${VTK_USE_FILE}) + +IF(ITKVtkGlue_LOADED) + MESSAGE(FATAL_ERROR "ITKVtkGlue module is available. Please re-compile your ITK without it. It could lead to nasty compilation problems... Just waiting for Kitware to solve it.") +ENDIF(ITKVtkGlue_LOADED) + IF(USE_QT4) FIND_PACKAGE(Qt4 REQUIRED) @@ -121,8 +87,10 @@ MARK_AS_ADVANCED( INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR}/lib ${PROJECT_SOURCE_DIR}/lib/third_party + ${PROJECT_SOURCE_DIR}/lib/third_party/ItkVtkGlue ${PROJECT_BINARY_DIR}/lib ${PROJECT_BINARY_DIR}/lib/third_party + ${PROJECT_BINARY_DIR}/lib/third_party/ItkVtkGlue ) IF(WIN32) INCLUDE_DIRECTORIES( diff --git a/appli/examples/CMakeLists.txt b/appli/examples/CMakeLists.txt index 93bc0d8..70ea3ee 100644 --- a/appli/examples/CMakeLists.txt +++ b/appli/examples/CMakeLists.txt @@ -34,6 +34,11 @@ SET( example_RenderQuadEdgeMeshWithoutPlugins example_ParallelImageMean example_LightCompensation + example_1DImageGradient + example_2DImageGradient + example_3DImageGradient + example_2DGulsunTekMedialness + example_3DGulsunTekMedialness ) FOREACH(prog ${NOPLUGINS_EXAMPLES_PROGRAMS}) ADD_EXECUTABLE( @@ -43,6 +48,7 @@ FOREACH(prog ${NOPLUGINS_EXAMPLES_PROGRAMS}) TARGET_LINK_LIBRARIES( ${prog} ${ITK_LIBRARIES} + cpPlugins_Extensions ) ENDFOREACH(prog) diff --git a/appli/examples/example_1DImageGradient.cxx b/appli/examples/example_1DImageGradient.cxx new file mode 100644 index 0000000..29a19b4 --- /dev/null +++ b/appli/examples/example_1DImageGradient.cxx @@ -0,0 +1,84 @@ +#include +#include +#include + +#include +#include +#include +#include + +#include + +// ------------------------------------------------------------------------- +typedef short TPixel; +typedef float TScalar; +const unsigned int Dimension = 2; + +typedef itk::CovariantVector< TScalar, Dimension > TVector; +typedef itk::Image< TPixel, Dimension > TImage; +typedef itk::Image< TVector, Dimension > TGradient; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + if( argc < 4 ) + { + std::cout + << "Usage: " << argv[ 0 ] + << " input_image output_gradient s0 s1 ..." + << std::endl; + return( 1 ); + + } // fi + std::string image_fn = argv[ 1 ]; + std::string gradient_fn = argv[ 2 ]; + + // Read image + itk::ImageFileReader< TImage >::Pointer image_reader = + itk::ImageFileReader< TImage >::New( ); + image_reader->SetFileName( image_fn ); + try + { + image_reader->Update( ); + } + catch( itk::ExceptionObject& err ) + { + std::cerr << err << std::endl; + return( 1 ); + + } // yrt + + // Prepare filter + typedef cpPlugins::Extensions::Algorithms:: + MultiScaleGaussianImageFilter< TImage, TGradient > TFilter; + + TFilter::Pointer filter = TFilter::New( ); + filter->SetFilterToGradient( ); + filter->SetInput( image_reader->GetOutput( ) ); + for( int i = 3; i < argc; ++i ) + filter->AddScale( std::atof( argv[ i ] ) ); + + // Execute filter + itk::SimpleFilterWatcher filter_watcher( filter, "Gradient" ); + filter->Update( ); + + // Read image + itk::ImageFileWriter< TGradient >::Pointer gradient_writer = + itk::ImageFileWriter< TGradient >::New( ); + gradient_writer->SetInput( filter->GetOutput( ) ); + gradient_writer->SetFileName( gradient_fn ); + try + { + gradient_writer->Update( ); + } + catch( itk::ExceptionObject& err ) + { + std::cerr << err << std::endl; + return( 1 ); + + } // yrt + + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/appli/examples/example_2DGulsunTekMedialness.cxx b/appli/examples/example_2DGulsunTekMedialness.cxx new file mode 100644 index 0000000..d7aa0d0 --- /dev/null +++ b/appli/examples/example_2DGulsunTekMedialness.cxx @@ -0,0 +1,220 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + + +// ------------------------------------------------------------------------- +typedef short TPixel; +typedef float TScalar; +const unsigned int Dimension = 2; + +typedef itk::Vector< TScalar, Dimension > TVector; +typedef itk::Image< TPixel, Dimension > TImage; +typedef itk::Image< TVector, Dimension > TGradient; +typedef itk::Image< TScalar, Dimension > TScalarImage; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + if( argc < 8 ) + { + std::cout + << "Usage: " << argv[ 0 ] + << " input_image output_medialness" + << " min_radius max_radius profile_sampling radial_sampling" + << " s0 s1 ..." + << std::endl; + return( 1 ); + + } // fi + std::string image_fn = argv[ 1 ]; + std::string medialness_fn = argv[ 2 ]; + double min_radius = std::atof( argv[ 3 ] ); + double max_radius = std::atof( argv[ 4 ] ); + unsigned int profile_sampling = std::atoi( argv[ 5 ] ); + unsigned int radial_sampling = std::atoi( argv[ 6 ] ); + + // Read image + itk::ImageFileReader< TImage >::Pointer image_reader = + itk::ImageFileReader< TImage >::New( ); + image_reader->SetFileName( image_fn ); + try + { + image_reader->Update( ); + } + catch( itk::ExceptionObject& err ) + { + std::cerr << err << std::endl; + return( 1 ); + + } // yrt + + // Inertia tensor + /* TODO + typedef cpPlugins::Extensions::Algorithms:: + InertiaTensorFunction< TScalar, Dimension > + TInertiaFunction; + TInertiaFunction::Pointer inertia = TInertiaFunction::New( ); + + itk::ImageRegionConstIteratorWithIndex< TImage > it( + image_reader->GetOutput( ), + image_reader->GetOutput( )->GetRequestedRegion( ) + ); + for( it.GoToBegin( ); !it.IsAtEnd( ); ++it ) + { + TInertiaFunction::TPoint pnt; + image_reader->GetOutput( )-> + TransformIndexToPhysicalPoint( it.GetIndex( ), pnt ); + inertia->AddMass( pnt, TScalar( it.Get( ) ) ); + + } // rof + + TInertiaFunction::TMatrix I = inertia->GetInertia( ); + TInertiaFunction::TVector m = inertia->GetCenterOfGravity( ); + + TInertiaFunction::TVector pv; + TInertiaFunction::TVector r; + TInertiaFunction::TMatrix pm; + inertia->GetEigenAnalysis( pm, pv, r ); + + vtkSmartPointer< vtkMatrix4x4 > matrix = + vtkSmartPointer< vtkMatrix4x4 >::New( ); + matrix->Identity( ); + matrix->SetElement( 0, 0, pm[ 0 ][ 0 ] * r[ 0 ] ); + matrix->SetElement( 0, 1, pm[ 0 ][ 1 ] * r[ 1 ] ); + matrix->SetElement( 1, 0, pm[ 1 ][ 0 ] * r[ 0 ] ); + matrix->SetElement( 1, 1, pm[ 1 ][ 1 ] * r[ 1 ] ); + matrix->SetElement( 0, 3, m[ 0 ] ); + matrix->SetElement( 1, 3, m[ 1 ] ); + + vtkSmartPointer< vtkAxesActor > axes = + vtkSmartPointer< vtkAxesActor >::New( ); + axes->SetUserMatrix( matrix ); + + std::cout << "---------------------------------" << std::endl; + std::cout << I << std::endl; + std::cout << m << std::endl; + std::cout << "---------------------------------" << std::endl; + std::cout << pm << std::endl; + std::cout << pv << std::endl; + std::cout << "---------------------------------" << std::endl; + + typedef itk::ImageToVTKImageFilter< TImage > TVTKImage; + TVTKImage::Pointer vtk_input_image = TVTKImage::New( ); + vtk_input_image->SetInput( image_reader->GetOutput( ) ); + vtk_input_image->Update( ); + + // Visualization window and interactor + vtkSmartPointer< vtkRenderWindowInteractor > interactor = + vtkSmartPointer< vtkRenderWindowInteractor >::New( ); + vtkSmartPointer< vtkRenderWindow > window = + vtkSmartPointer< vtkRenderWindow >::New( ); + window->SetSize( 500, 500 ); + window->SetInteractor( interactor ); + + // Viewer + cpPlugins::Extensions::Visualization::MPRWithDifferentWindows + view( NULL, NULL, window, NULL ); + view.SetImage( vtk_input_image->GetOutput( ) ); + view.GetRenderer( 2 )->AddActor( axes ); + view.ResetCamera( 2 ); + view.Render( 2 ); + + // Start + interactor->Initialize( ); + interactor->Start( ); + + */ + + /* + // Prepare filter + typedef cpPlugins::Extensions::Algorithms:: + MultiScaleGaussianImageFilter< TImage, TGradient > TGradientFilter; + + TGradientFilter::Pointer gradientFilter = TGradientFilter::New( ); + gradientFilter->SetFilterToGradient( ); + gradientFilter->SetInput( image_reader->GetOutput( ) ); + for( int i = 7; i < argc; ++i ) + gradientFilter->AddScale( std::atof( argv[ i ] ) ); + + // Execute filter + itk::SimpleFilterWatcher gradientFilter_watcher( gradientFilter, "Gradient" ); + gradientFilter->Update( ); + */ + + // Prepare medialness function + typedef cpPlugins::Extensions::Algorithms:: + InertiaMedialness< TImage, TScalar > TMedialness; + TMedialness::Pointer medialness = TMedialness::New( ); + medialness->SetInputImage( image_reader->GetOutput( ) ); + medialness->SetMaxRadius( max_radius ); + /* + medialness->SetMinRadius( min_radius ); + medialness->SetProfileSampling( profile_sampling ); + medialness->SetRadialSampling( radial_sampling ); + + TGradient::IndexType idx; + idx[ 0 ] = 288; + idx[ 1 ] = 690; + + std::cout << "Medialness = " << medialness->EvaluateAtIndex( idx ) << std::endl; + // return( 0 ); + */ + + // Prepare output filter + typedef cpPlugins::Extensions::Algorithms:: + ImageFunctionFilter< TImage, TScalarImage, TMedialness > + TFunctionApplier; + TFunctionApplier::Pointer medialnessFilter = TFunctionApplier::New( ); + medialnessFilter->SetInput( image_reader->GetOutput( ) ); + medialnessFilter->SetFunction( medialness ); + + // Execute filter + itk::SimpleFilterWatcher medialnessFilter_watcher( + medialnessFilter, "Medialness" + ); + medialnessFilter->Update( ); + + // Write image + itk::ImageFileWriter< TScalarImage >::Pointer medialness_writer = + itk::ImageFileWriter< TScalarImage >::New( ); + medialness_writer->SetInput( medialnessFilter->GetOutput( ) ); + medialness_writer->SetFileName( medialness_fn ); + try + { + medialness_writer->Update( ); + } + catch( itk::ExceptionObject& err ) + { + std::cerr << err << std::endl; + return( 1 ); + + } // yrt + + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/appli/examples/example_2DImageGradient.cxx b/appli/examples/example_2DImageGradient.cxx new file mode 100644 index 0000000..c0ef19f --- /dev/null +++ b/appli/examples/example_2DImageGradient.cxx @@ -0,0 +1,84 @@ +#include +#include +#include + +#include +#include +#include +#include + +#include + +// ------------------------------------------------------------------------- +typedef short TPixel; +typedef float TScalar; +const unsigned int Dimension = 2; + +typedef itk::CovariantVector< TScalar, Dimension > TVector; +typedef itk::Image< TPixel, Dimension > TImage; +typedef itk::Image< TVector, Dimension > TGradient; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + if( argc < 4 ) + { + std::cout + << "Usage: " << argv[ 0 ] + << " input_image output_gradient s0 s1 ..." + << std::endl; + return( 1 ); + + } // fi + std::string image_fn = argv[ 1 ]; + std::string gradient_fn = argv[ 2 ]; + + // Read image + itk::ImageFileReader< TImage >::Pointer image_reader = + itk::ImageFileReader< TImage >::New( ); + image_reader->SetFileName( image_fn ); + try + { + image_reader->Update( ); + } + catch( itk::ExceptionObject& err ) + { + std::cerr << err << std::endl; + return( 1 ); + + } // yrt + + // Prepare filter + typedef cpPlugins::Extensions::Algorithms:: + MultiScaleGaussianImageFilter< TImage, TGradient > TFilter; + + TFilter::Pointer filter = TFilter::New( ); + filter->SetFilterToGradient( ); + filter->SetInput( image_reader->GetOutput( ) ); + for( int i = 3; i < argc; ++i ) + filter->AddScale( std::atof( argv[ i ] ) ); + + // Execute filter + itk::SimpleFilterWatcher filter_watcher( filter, "Gradient" ); + filter->Update( ); + + // Write image + itk::ImageFileWriter< TGradient >::Pointer gradient_writer = + itk::ImageFileWriter< TGradient >::New( ); + gradient_writer->SetInput( filter->GetOutput( ) ); + gradient_writer->SetFileName( gradient_fn ); + try + { + gradient_writer->Update( ); + } + catch( itk::ExceptionObject& err ) + { + std::cerr << err << std::endl; + return( 1 ); + + } // yrt + + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/appli/examples/example_3DGulsunTekMedialness.cxx b/appli/examples/example_3DGulsunTekMedialness.cxx new file mode 100644 index 0000000..796cf05 --- /dev/null +++ b/appli/examples/example_3DGulsunTekMedialness.cxx @@ -0,0 +1,118 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +// ------------------------------------------------------------------------- +typedef short TPixel; +typedef float TScalar; +const unsigned int Dimension = 3; + +typedef itk::Vector< TScalar, Dimension > TVector; +typedef itk::Image< TPixel, Dimension > TImage; +typedef itk::Image< TVector, Dimension > TGradient; +typedef itk::Image< TScalar, Dimension > TScalarImage; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + if( argc < 8 ) + { + std::cout + << "Usage: " << argv[ 0 ] + << " input_image output_medialness" + << " min_radius max_radius profile_sampling radial_sampling" + << " s0 s1 ..." + << std::endl; + return( 1 ); + + } // fi + std::string image_fn = argv[ 1 ]; + std::string medialness_fn = argv[ 2 ]; + double min_radius = std::atof( argv[ 3 ] ); + double max_radius = std::atof( argv[ 4 ] ); + unsigned int profile_sampling = std::atoi( argv[ 5 ] ); + unsigned int radial_sampling = std::atoi( argv[ 6 ] ); + + // Read image + itk::ImageFileReader< TImage >::Pointer image_reader = + itk::ImageFileReader< TImage >::New( ); + image_reader->SetFileName( image_fn ); + try + { + image_reader->Update( ); + } + catch( itk::ExceptionObject& err ) + { + std::cerr << err << std::endl; + return( 1 ); + + } // yrt + + // Prepare filter + typedef cpPlugins::Extensions::Algorithms:: + MultiScaleGaussianImageFilter< TImage, TGradient > TGradientFilter; + + TGradientFilter::Pointer gradientFilter = TGradientFilter::New( ); + gradientFilter->SetFilterToGradient( ); + gradientFilter->SetInput( image_reader->GetOutput( ) ); + for( int i = 7; i < argc; ++i ) + gradientFilter->AddScale( std::atof( argv[ i ] ) ); + + // Execute filter + itk::SimpleFilterWatcher gradientFilter_watcher( gradientFilter, "Gradient" ); + gradientFilter->Update( ); + + // Prepare medialness function + typedef cpPlugins::Extensions::Algorithms:: + GulsunTekMedialness< TGradient > TMedialness; + TMedialness::Pointer medialness = TMedialness::New( ); + medialness->SetInputImage( gradientFilter->GetOutput( ) ); + medialness->SetMinRadius( min_radius ); + medialness->SetMaxRadius( max_radius ); + medialness->SetProfileSampling( profile_sampling ); + medialness->SetRadialSampling( radial_sampling ); + + // Prepare output filter + typedef cpPlugins::Extensions::Algorithms:: + ImageFunctionFilter< TGradient, TScalarImage, TMedialness > + TFunctionApplier; + TFunctionApplier::Pointer medialnessFilter = TFunctionApplier::New( ); + medialnessFilter->SetInput( gradientFilter->GetOutput( ) ); + medialnessFilter->SetFunction( medialness ); + + // Execute filter + itk::SimpleFilterWatcher medialnessFilter_watcher( + medialnessFilter, "Medialness" + ); + medialnessFilter->Update( ); + + // Write image + itk::ImageFileWriter< TScalarImage >::Pointer medialness_writer = + itk::ImageFileWriter< TScalarImage >::New( ); + medialness_writer->SetInput( medialnessFilter->GetOutput( ) ); + medialness_writer->SetFileName( medialness_fn ); + try + { + medialness_writer->Update( ); + } + catch( itk::ExceptionObject& err ) + { + std::cerr << err << std::endl; + return( 1 ); + + } // yrt + + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/appli/examples/example_3DImageGradient.cxx b/appli/examples/example_3DImageGradient.cxx new file mode 100644 index 0000000..c35a085 --- /dev/null +++ b/appli/examples/example_3DImageGradient.cxx @@ -0,0 +1,84 @@ +#include +#include +#include + +#include +#include +#include +#include + +#include + +// ------------------------------------------------------------------------- +typedef short TPixel; +typedef float TScalar; +const unsigned int Dimension = 3; + +typedef itk::CovariantVector< TScalar, Dimension > TVector; +typedef itk::Image< TPixel, Dimension > TImage; +typedef itk::Image< TVector, Dimension > TGradient; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ + if( argc < 4 ) + { + std::cout + << "Usage: " << argv[ 0 ] + << " input_image output_gradient s0 s1 ..." + << std::endl; + return( 1 ); + + } // fi + std::string image_fn = argv[ 1 ]; + std::string gradient_fn = argv[ 2 ]; + + // Read image + itk::ImageFileReader< TImage >::Pointer image_reader = + itk::ImageFileReader< TImage >::New( ); + image_reader->SetFileName( image_fn ); + try + { + image_reader->Update( ); + } + catch( itk::ExceptionObject& err ) + { + std::cerr << err << std::endl; + return( 1 ); + + } // yrt + + // Prepare filter + typedef cpPlugins::Extensions::Algorithms:: + MultiScaleGaussianImageFilter< TImage, TGradient > TFilter; + + TFilter::Pointer filter = TFilter::New( ); + filter->SetFilterToGradient( ); + filter->SetInput( image_reader->GetOutput( ) ); + for( int i = 3; i < argc; ++i ) + filter->AddScale( std::atof( argv[ i ] ) ); + + // Execute filter + itk::SimpleFilterWatcher filter_watcher( filter, "Gradient" ); + filter->Update( ); + + // Write image + itk::ImageFileWriter< TGradient >::Pointer gradient_writer = + itk::ImageFileWriter< TGradient >::New( ); + gradient_writer->SetInput( filter->GetOutput( ) ); + gradient_writer->SetFileName( gradient_fn ); + try + { + gradient_writer->Update( ); + } + catch( itk::ExceptionObject& err ) + { + std::cerr << err << std::endl; + return( 1 ); + + } // yrt + + return( 0 ); +} + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Extensions/Algorithms/GradientFunctionBase.h b/lib/cpPlugins/Extensions/Algorithms/GradientFunctionBase.h new file mode 100644 index 0000000..0310783 --- /dev/null +++ b/lib/cpPlugins/Extensions/Algorithms/GradientFunctionBase.h @@ -0,0 +1,86 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__H__ +#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__H__ + +#include +#include + +namespace cpPlugins +{ + namespace Extensions + { + namespace Algorithms + { + /** + */ + template< class G > + class GradientFunctionBase + : public itk::ImageFunction< G, typename G::PixelType::ValueType, typename G::PixelType::ValueType > + { + public: + // Types from input arguments + typedef G TGradient; + typedef typename G::PixelType TVector; + typedef typename TVector::ValueType TScalar; + itkStaticConstMacro( Dimension, unsigned int, G::ImageDimension ); + + // Standard itk types + typedef GradientFunctionBase Self; + typedef itk::ImageFunction< G, TScalar, TScalar > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + // Types from base itk::ImageFunction + typedef typename Superclass::InputType TInput; + typedef typename Superclass::OutputType TOutput; + typedef typename Superclass::PointType TPoint; + typedef typename Superclass::ContinuousIndexType TContIndex; + typedef typename Superclass::IndexType TIndex; + + // Sparse buffer + typedef std::map< TIndex, TOutput, typename TIndex::LexicographicCompare > TBuffer; + + public: + itkTypeMacro( GradientFunctionBase, itkImageFunction ); + + itkBooleanMacro( BufferResults ); + itkGetConstMacro( BufferResults, bool ); + itkSetMacro( BufferResults, bool ); + + public: + virtual void ResetBuffer( ); + + virtual TOutput Evaluate( const TPoint& p ) const; + virtual TOutput EvaluateAtIndex( const TIndex& i ) const; + virtual TOutput EvaluateAtContinuousIndex( const TContIndex& i ) const; + + protected: + GradientFunctionBase( ); + virtual ~GradientFunctionBase( ); + + virtual TOutput _Evaluate( const TIndex& i ) const = 0; + + private: + // Purposely not implemented. + GradientFunctionBase( const Self& ); + void operator=( const Self& ); + + protected: + mutable TBuffer m_Buffer; + bool m_BufferResults; + }; + + } // ecapseman + + } // ecapseman + +} // ecapseman + +#include + +#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Extensions/Algorithms/GradientFunctionBase.hxx b/lib/cpPlugins/Extensions/Algorithms/GradientFunctionBase.hxx new file mode 100644 index 0000000..eaf9cf9 --- /dev/null +++ b/lib/cpPlugins/Extensions/Algorithms/GradientFunctionBase.hxx @@ -0,0 +1,82 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__HXX__ +#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__HXX__ + +// ------------------------------------------------------------------------- +template< class G > +void cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >:: +ResetBuffer( ) +{ + this->m_Buffer.clear( ); +} + +// ------------------------------------------------------------------------- +template< class G > +typename cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >:: +TOutput cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >:: +Evaluate( const TPoint& p ) const +{ + TIndex i; + this->GetInputImage( )->TransformPhysicalPointToIndex( p, i ); + return( this->EvaluateAtIndex( i ) ); +} + +// ------------------------------------------------------------------------- +template< class G > +typename cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >:: +TOutput cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >:: +EvaluateAtIndex( const TIndex& i ) const +{ + TOutput res = TOutput( 0 ); + bool computed = false; + if( this->m_BufferResults ) + { + typename TBuffer::const_iterator bIt = this->m_Buffer.find( i ); + computed = ( bIt != this->m_Buffer.end( ) ); + res = ( computed )? bIt->second: res; + + } // fi + + if( !computed ) + res = this->_Evaluate( i ); + + if( this->m_BufferResults ) + this->m_Buffer[ i ] = res; + return( res ); +} + +// ------------------------------------------------------------------------- +template< class G > +typename cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >:: +TOutput cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >:: +EvaluateAtContinuousIndex( const TContIndex& i ) const +{ + TPoint p; + this->GetInputImage( )->TransformContinuousIndexToPhysicalPoint( i, p ); + return( this->Evaluate( p ) ); +} + +// ------------------------------------------------------------------------- +template< class G > +cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >:: +GradientFunctionBase( ) + : Superclass( ), + m_BufferResults( false ) +{ + this->m_Buffer.clear( ); +} + +// ------------------------------------------------------------------------- +template< class G > +cpPlugins::Extensions::Algorithms::GradientFunctionBase< G >:: +~GradientFunctionBase( ) +{ + this->m_Buffer.clear( ); +} + +#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__GRADIENTFUNCTIONBASE__HXX__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Extensions/Algorithms/GulsunTekMedialness.h b/lib/cpPlugins/Extensions/Algorithms/GulsunTekMedialness.h new file mode 100644 index 0000000..9f942e8 --- /dev/null +++ b/lib/cpPlugins/Extensions/Algorithms/GulsunTekMedialness.h @@ -0,0 +1,87 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__GULSUNTEKMEDIALNESS__H__ +#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__GULSUNTEKMEDIALNESS__H__ + +#include +#include + +namespace cpPlugins +{ + namespace Extensions + { + namespace Algorithms + { + /** + */ + template< class G > + class GulsunTekMedialness + : public GradientFunctionBase< G > + { + public: + // Standard itk types + typedef GulsunTekMedialness Self; + typedef GradientFunctionBase< G > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + // Types from superclass + typedef typename Superclass::TGradient TGradient; + typedef typename Superclass::TVector TVector; + typedef typename Superclass::TScalar TScalar; + typedef typename Superclass::TInput TInput; + typedef typename Superclass::TOutput TOutput; + typedef typename Superclass::TPoint TPoint; + typedef typename Superclass::TContIndex TContIndex; + typedef typename Superclass::TIndex TIndex; + typedef typename Superclass::TBuffer TBuffer; + + typedef typename TIndex::OffsetType TOffset; + typedef std::vector< double > TProfile; + typedef std::vector< TOffset > TOffsets; + + public: + itkNewMacro( Self ); + itkTypeMacro( GulsunTekMedialness, GradientFunctionBase ); + + itkGetConstMacro( MinRadius, double ); + itkGetConstMacro( MaxRadius, double ); + itkGetConstMacro( ProfileSampling, unsigned int ); + itkGetConstMacro( RadialSampling, unsigned int ); + + itkSetMacro( MinRadius, double ); + itkSetMacro( MaxRadius, double ); + itkSetMacro( ProfileSampling, unsigned int ); + itkSetMacro( RadialSampling, unsigned int ); + + protected: + GulsunTekMedialness( ); + virtual ~GulsunTekMedialness( ); + + virtual TOutput _Evaluate( const TIndex& i ) const; + + private: + // Purposely not implemented. + GulsunTekMedialness( const Self& ); + void operator=( const Self& ); + + protected: + double m_MinRadius; + double m_MaxRadius; + unsigned int m_ProfileSampling; + unsigned int m_RadialSampling; + }; + + } // ecapseman + + } // ecapseman + +} // ecapseman + +#include + +#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__GULSUNTEKMEDIALNESS__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Extensions/Algorithms/GulsunTekMedialness.hxx b/lib/cpPlugins/Extensions/Algorithms/GulsunTekMedialness.hxx new file mode 100644 index 0000000..af30c74 --- /dev/null +++ b/lib/cpPlugins/Extensions/Algorithms/GulsunTekMedialness.hxx @@ -0,0 +1,197 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__GULSUNTEKMEDIALNESS__HXX__ +#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__GULSUNTEKMEDIALNESS__HXX__ + +#include +#include + + +#include +#include +#include + + + + +// ------------------------------------------------------------------------- +template< class G > +cpPlugins::Extensions::Algorithms::GulsunTekMedialness< G >:: +GulsunTekMedialness( ) + : Superclass( ), + m_MinRadius( double( 0 ) ), + m_MaxRadius( double( 1 ) ), + m_ProfileSampling( 4 ), + m_RadialSampling( 10 ) +{ +} + +// ------------------------------------------------------------------------- +template< class G > +cpPlugins::Extensions::Algorithms::GulsunTekMedialness< G >:: +~GulsunTekMedialness( ) +{ +} + +// ------------------------------------------------------------------------- +template< class G > +typename cpPlugins::Extensions::Algorithms::GulsunTekMedialness< G >:: +TOutput cpPlugins::Extensions::Algorithms::GulsunTekMedialness< G >:: +_Evaluate( const TIndex& i ) const +{ + const G* gradient = this->GetInputImage( ); + typename G::RegionType region = gradient->GetRequestedRegion( ); + typename G::PointType i_P; + gradient->TransformIndexToPhysicalPoint( i, i_P ); + + std::queue< TIndex > q; + std::set< TIndex, typename TIndex::LexicographicCompare > m; + std::map< TOffset, std::vector< TIndex >, typename TOffset::LexicographicCompare > profiles; + q.push( i ); + + while( !q.empty( ) ) + { + // Get next node + TIndex node = q.front( ); + q.pop( ); + if( m.find( node ) != m.end( ) ) + continue; + m.insert( node ); + + // Get neighborhood + for( unsigned int d = 0; d < Self::Dimension; d++ ) + { + for( int off = -1; off <= 1; off += 2 ) + { + TIndex neighbor = node; + neighbor[ d ] += off; + if( region.IsInside( neighbor ) ) + { + typename G::PointType neighbor_P; + gradient->TransformIndexToPhysicalPoint( neighbor, neighbor_P ); + if( double( i_P.EuclideanDistanceTo( neighbor_P ) ) > this->m_MaxRadius ) + continue; + + // Normalize offset in terms of a l1 (manhattan) distance + TOffset offset = neighbor - i; + // std::cout << "Offset: " << offset << std::endl; + + /* + int max_off = 0; + for( unsigned int o = 0; o < Self::Dimension; ++o ) + max_off += std::abs( offset[ o ] ); + if( max_off == 0 ) + continue; + bool normalized = true; + TOffset normalized_offset; + for( unsigned int o = 0; o < Self::Dimension && normalized; ++o ) + { + if( offset[ o ] % max_off == 0 ) + normalized_offset[ o ] = offset[ o ] / max_off; + else + normalized = false; + + } // rof + if( !normalized ) + normalized_offset = offset; + std::cout << "offset: " << normalized_offset << std::endl; + + // Update profiles + profiles[ normalized_offset ].push_back( neighbor ); + */ + + // Update queue + q.push( neighbor ); + + } // fi + + } // rof + + } // rof + + } // elihw + // std::cout << "HOLA: " << profiles.size( ) << std::endl; + + + return( TOutput( 0 ) ); + /* TODO + const G* in = this->GetInputImage( ); + double pi2n = + double( 2 ) * double( vnl_math::pi ) / + double( this->m_ProfileSampling ); + double rOff = this->m_MaxRadius / double( this->m_RadialSampling - 1 ); + double optR = double( 0 ); + TPoint pnt; + in->TransformIndexToPhysicalPoint( i, pnt ); + + // Main loop + for( unsigned int cx = 0; cx < Self::Dimension - 1; cx++ ) + { + for( unsigned int cy = cx + 1; cy < Self::Dimension; cy++ ) + { + TProfile maxProfile( this->m_RadialSampling, double( 0 ) ); + for( unsigned int p = 0; p < this->m_ProfileSampling; p++ ) + { + double a = pi2n * double( p ); + + // Direction of this profile + TVector dir; + dir.Fill( TScalar( 0 ) ); + dir[ cx ] = TScalar( std::cos( a ) ); + dir[ cy ] = TScalar( std::sin( a ) ); + + double maxrise = double( 0 ); + double maxfall = double( -1 ); + TProfile profile; + for( unsigned int r = 0; r < this->m_RadialSampling; r++ ) + { + double radius = double( r ) * rOff; + TIndex idx; + if( + in->TransformPhysicalPointToIndex( pnt + ( dir * radius ), idx ) + ) + { + TVector g = in->GetPixel( idx ); + double b = double( g.GetNorm( ) ); + if( double( g * dir ) < double( 0 ) ) + b *= double( -1 ); + maxrise = ( b > maxrise )? b: maxrise; + if( radius >= this->m_MinRadius ) + maxfall = ( b < maxfall )? b: maxfall; + profile.push_back( -b - maxrise ); + } + else + profile.push_back( double( 0 ) ); + + } // rof + + for( unsigned int r = 0; r < this->m_RadialSampling; r++ ) + { + double E = profile[ r ] / -maxfall; + E = ( E < double( 0 ) )? double( 0 ): E; + E = ( E > double( 1 ) )? double( 1 ): E; + maxProfile[ r ] += E; + + } // rof + + } // rof + + for( unsigned int r = 0; r < this->m_RadialSampling; r++ ) + { + double E = maxProfile[ r ] / double( this->m_RadialSampling ); + optR = ( E > optR )? E: optR; + + } // rof + + } // rof + + } // rof + return( TScalar( optR ) ); + */ +} + +#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__GULSUNTEKMEDIALNESS__HXX__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Extensions/Algorithms/ImageFunctionFilter.h b/lib/cpPlugins/Extensions/Algorithms/ImageFunctionFilter.h new file mode 100644 index 0000000..4a938af --- /dev/null +++ b/lib/cpPlugins/Extensions/Algorithms/ImageFunctionFilter.h @@ -0,0 +1,108 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__H__ +#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__H__ + +#include +#include +#include +#include + +namespace cpPlugins +{ + namespace Extensions + { + namespace Algorithms + { + /** + */ + template< class I, class O, class F > + class ImageFunctionFilter + : public itk::ImageToImageFilter< I, O > + { + public: + typedef ImageFunctionFilter Self; + typedef itk::ImageToImageFilter< I, O > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef I TInputImage; + typedef O TOutputImage; + typedef F TFunction; + + typedef typename O::RegionType TRegion; + + public: + itkNewMacro( Self ); + itkTypeMacro( ImageFunctionFilter, itkImageToImageFilter ); + + itkGetObjectMacro( Function, F ); + itkSetObjectMacro( Function, F ); + + protected: + ImageFunctionFilter( ) + : Superclass( ) + { + } + virtual ~ImageFunctionFilter( ) + { + } + + virtual void ThreadedGenerateData( + const TRegion& region, + itk::ThreadIdType threadId + ) + { + const typename TRegion::SizeType& regionSize = region.GetSize( ); + if( regionSize[ 0 ] == 0 ) + return; + const I* in = this->GetInput( ); + O* out = this->GetOutput( 0 ); + + const size_t nLines = region.GetNumberOfPixels( ) / regionSize[ 0 ]; + itk::ProgressReporter progress( this, threadId, nLines ); + + // Define the iterators + itk::ImageScanlineConstIterator< I > inIt( in, region ); + itk::ImageScanlineIterator< O > outIt( out, region ); + + inIt.GoToBegin( ); + outIt.GoToBegin( ); + while( !inIt.IsAtEnd( ) ) + { + while( !inIt.IsAtEndOfLine( ) ) + { + outIt.Set( this->m_Function->EvaluateAtIndex( inIt.GetIndex( ) ) ); + ++inIt; + ++outIt; + + } // elihw + inIt.NextLine( ); + outIt.NextLine( ); + progress.CompletedPixel( ); + + } // elihw + } + + private: + // Purposely not implemented. + ImageFunctionFilter( const Self& ); + void operator=( const Self& ); + + protected: + typename F::Pointer m_Function; + }; + + } // ecapseman + + } // ecapseman + +} // ecapseman + +// TODO: #include + +#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__IMAGEFUNCTIONFILTER__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Extensions/Algorithms/InertiaMedialness.h b/lib/cpPlugins/Extensions/Algorithms/InertiaMedialness.h new file mode 100644 index 0000000..478432a --- /dev/null +++ b/lib/cpPlugins/Extensions/Algorithms/InertiaMedialness.h @@ -0,0 +1,217 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__INERTIAMEDIALNESS__H__ +#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__INERTIAMEDIALNESS__H__ + +#include +#include + +#include +#include + +namespace cpPlugins +{ + namespace Extensions + { + namespace Algorithms + { + /** + */ + template< class I, class S = float > + class InertiaMedialness + : public itk::ImageFunction< I, S, S > + { + public: + // Standard itk types + typedef InertiaMedialness Self; + typedef itk::ImageFunction< I, S, S > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + // Types from base itk::ImageFunction + typedef typename Superclass::InputType TInput; + typedef typename Superclass::OutputType TOutput; + typedef typename Superclass::PointType TPoint; + typedef typename Superclass::ContinuousIndexType TContIndex; + typedef typename Superclass::IndexType TIndex; + typedef typename TIndex::OffsetType TOffset; + + // Sparse buffer + typedef std::map< TIndex, TOutput, typename TIndex::LexicographicCompare > TBuffer; + + typedef InertiaTensorFunction< S, I::ImageDimension > TInertia; + + public: + itkNewMacro( Self ); + itkTypeMacro( InertiaMedialness, itkImageFunction ); + + itkBooleanMacro( BufferResults ); + itkGetConstMacro( BufferResults, bool ); + itkGetConstMacro( MaxRadius, double ); + + itkSetMacro( BufferResults, bool ); + itkSetMacro( MaxRadius, double ); + + public: + virtual void ResetBuffer( ) + { + this->m_Buffer.clear( ); + } + + virtual TOutput Evaluate( const TPoint& p ) const + { + TIndex i; + this->GetInputImage( )->TransformPhysicalPointToIndex( p, i ); + return( this->EvaluateAtIndex( i ) ); + } + + virtual TOutput EvaluateAtIndex( const TIndex& i ) const + { + TOutput res = TOutput( 0 ); + bool computed = false; + if( this->m_BufferResults ) + { + typename TBuffer::const_iterator bIt = this->m_Buffer.find( i ); + computed = ( bIt != this->m_Buffer.end( ) ); + res = ( computed )? bIt->second: res; + + } // fi + + if( !computed ) + res = this->_Evaluate( i ); + + if( this->m_BufferResults ) + this->m_Buffer[ i ] = res; + return( res ); + } + + virtual TOutput EvaluateAtContinuousIndex( const TContIndex& i ) const + { + TPoint p; + this->GetInputImage( )->TransformContinuousIndexToPhysicalPoint( i, p ); + return( this->Evaluate( p ) ); + } + + protected: + InertiaMedialness( ) + : Superclass( ), + m_BufferResults( false ), + m_MaxRadius( double( 1 ) ) + { + this->m_Buffer.clear( ); + } + + virtual ~InertiaMedialness( ) + { + this->m_Buffer.clear( ); + } + + virtual TOutput _Evaluate( const TIndex& idx ) const + { + const I* image = this->GetInputImage( ); + + typename I::PointType p_i; + image->TransformIndexToPhysicalPoint( idx, p_i ); + + typename I::PointType max_p, min_p; + for( unsigned int d = 0; d < I::ImageDimension; ++d ) + { + max_p[ d ] = p_i[ d ] + this->m_MaxRadius; + min_p[ d ] = p_i[ d ] - this->m_MaxRadius; + + } // rof + TIndex max_i, min_i; + image->TransformPhysicalPointToIndex( max_p, max_i ); + image->TransformPhysicalPointToIndex( min_p, min_i ); + + typename I::RegionType in_region = image->GetRequestedRegion( ); + TIndex in_index = in_region.GetIndex( ); + TIndex in_last = in_index + in_region.GetSize( ); + typename I::SizeType size; + for( unsigned int d = 0; d < I::ImageDimension; ++d ) + { + if( min_i[ d ] < in_index[ d ] ) min_i[ d ] = in_index[ d ]; + if( max_i[ d ] < in_index[ d ] ) max_i[ d ] = in_index[ d ]; + if( min_i[ d ] >= in_last[ d ] ) min_i[ d ] = in_last[ d ]; + if( max_i[ d ] >= in_last[ d ] ) max_i[ d ] = in_last[ d ]; + + size[ d ] = max_i[ d ] - min_i[ d ]; + + } // rof + + typename I::RegionType region; + region.SetIndex( min_i ); + region.SetSize( size ); + + std::vector< typename TInertia::Pointer > inertias; + itk::ImageRegionConstIteratorWithIndex< I > it( image, region ); + for( it.GoToBegin( ); !it.IsAtEnd( ); ++it ) + { + TOffset off = it.GetIndex( ) - idx; + unsigned long l1dist = std::abs( off[ 0 ] ); + for( unsigned int d = 1; d < I::ImageDimension; ++d ) + l1dist = ( std::abs( off[ d ] ) > l1dist )? std::abs( off[ d ] ): l1dist; + + typename TInertia::TPoint i_pnt; + image->TransformIndexToPhysicalPoint( it.GetIndex( ), i_pnt ); + + for( unsigned long l = 0; l < l1dist; ++l ) + { + if( inertias.size( ) <= l ) + inertias.push_back( TInertia::New( ) ); + inertias[ l ]->AddMass( i_pnt.GetVectorFromOrigin( ), S( it.Get( ) ) ); + + /* TODO + typename TInertias::iterator inIt = inertias.find( l ); + if( inIt == inertias.end( ) ) + inIt = inertias.insert( std::pair< unsigned long, typename TInertia::Pointer >( l, TInertia::New( ) ) ).first; + */ + + } // rof + + } // rof + + if( inertias.size( ) > 0 ) + { + S res = S( 0 ); + for( unsigned int l = 0; l < inertias.size( ); ++l ) + { + typename TInertia::TVector pv, r; + typename TInertia::TMatrix pm; + inertias[ l ]->GetEigenAnalysis( pm, pv, r ); + S v = pv.GetNorm( ); + if( l == 0 || v > res ) + res = v; + + } // rof + return( res ); + } + else + return( TOutput( 0 ) ); + } + + private: + // Purposely not implemented. + InertiaMedialness( const Self& ); + void operator=( const Self& ); + + protected: + mutable TBuffer m_Buffer; + bool m_BufferResults; + + double m_MaxRadius; + }; + + } // ecapseman + + } // ecapseman + +} // ecapseman + +// TODO: #include + +#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__INERTIAMEDIALNESS__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Extensions/Algorithms/InertiaTensorFunction.h b/lib/cpPlugins/Extensions/Algorithms/InertiaTensorFunction.h new file mode 100644 index 0000000..515d560 --- /dev/null +++ b/lib/cpPlugins/Extensions/Algorithms/InertiaTensorFunction.h @@ -0,0 +1,182 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__INERTIATENSORFUNCTION__H__ +#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__INERTIATENSORFUNCTION__H__ + +#include + +#include +#include +#include +#include + + +#include +#include + + +namespace cpPlugins +{ + namespace Extensions + { + namespace Algorithms + { + /** + */ + template< class S, unsigned int D > + class InertiaTensorFunction + : public itk::Object + { + public: + // Standard itk types + typedef InertiaTensorFunction Self; + typedef itk::Object Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef S TScalar; + typedef itk::Matrix< S, D, D > TMatrix; + typedef itk::Point< S, D > TPoint; + typedef typename TPoint::VectorType TVector; + + protected: + typedef TMatrix _TInternalMatrix; + typedef itk::Matrix< S, D, 1 > _TInternalVector; + + public: + itkNewMacro( Self ); + itkTypeMacro( InertiaTensorFunction, itkObject ); + + public: + inline void Reset( ) + { + this->m_M = S( 0 ); + this->m_MPP = S( 0 ); + this->m_MP.Fill( S( 0 ) ); + this->m_MPPT.Fill( S( 0 ) ); + this->Modified( ); + } + inline void AddMass( const TPoint& pnt, const S& mass = S( 1 ) ) + { + this->AddMass( pnt.GetVectorFromOrigin( ), mass ); + } + inline void AddMass( const S* data, const S& mass = S( 1 ) ) + { + this->AddMass( TVector( data ), mass ); + } + inline void AddMass( const TVector& vec, const S& mass = S( 1 ) ) + { + this->m_M += mass; + this->m_MPP += mass * ( vec * vec ); + + _TInternalVector mp; + for( unsigned int d = 0; d < D; ++d ) + { + this->m_MP[ d ][ 0 ] += mass * vec[ d ]; + mp[ d ][ 0 ] = vec[ d ]; + + } // rof + this->m_MPPT += + _TInternalMatrix( mp.GetVnlMatrix( ) * mp.GetTranspose( ) ) * + mass; + } + + inline S GetMass( ) const + { + return( this->m_M ); + } + + inline TMatrix GetInertia( ) const + { + TMatrix I; + if( S( 0 ) < this->m_M ) + { + I.SetIdentity( ); + I *= this->m_MPP - ( ( this->m_MP.GetTranspose( ) * this->m_MP.GetVnlMatrix( ) )[ 0 ][ 0 ] / this->m_M ); + I -= this->m_MPPT; + I += TMatrix( this->m_MP.GetVnlMatrix( ) * this->m_MP.GetTranspose( ) ) / this->m_M; + } + else + I.Fill( S( 0 ) ); + return( I ); + } + + inline TVector GetCenterOfGravity( ) const + { + TVector cog; + if( S( 0 ) < this->m_M ) + { + for( unsigned int d = 0; d < D; ++d ) + cog[ d ] = this->m_MP[ d ][ 0 ] / this->m_M; + } + else + cog.Fill( S( 0 ) ); + return( cog ); + } + + inline void GetEigenAnalysis( TMatrix& pm, TVector& pv, TVector& r ) const + { + TMatrix I = this->GetInertia( ); + + itk::SymmetricEigenAnalysis< TMatrix, TVector, TMatrix > eigen; + eigen.SetDimension( D ); + eigen.SetOrderEigenMagnitudes( true ); + eigen.SetOrderEigenValues( 1 ); + eigen.ComputeEigenValuesAndVectors( I, pv, pm ); + pm = TMatrix( pm.GetTranspose( ) ); + S det = vnl_determinant( pm.GetVnlMatrix( ) ); + for( unsigned int d = 0; d < D; ++d ) + pm[ d ][ D - 1 ] *= det; + + if( D == 2 ) + { + S coeff = S( 4 ) / this->m_M; + r[ 0 ] = std::sqrt( std::fabs( coeff * pv[ 1 ] ) ); + r[ 1 ] = std::sqrt( std::fabs( coeff * pv[ 0 ] ) ); + } + else if( D == 3 ) + { + S coeff = S( 2.5 ) / this->m_M; + r[ 0 ] = std::sqrt( std::fabs( coeff * ( pv[ 1 ] + pv[ 2 ] - pv[ 0 ] ) ) ); + r[ 1 ] = std::sqrt( std::fabs( coeff * ( pv[ 0 ] + pv[ 2 ] - pv[ 1 ] ) ) ); + r[ 2 ] = std::sqrt( std::fabs( coeff * ( pv[ 0 ] + pv[ 1 ] - pv[ 2 ] ) ) ); + } + else + r.Fill( S( 0 ) ); + } + + protected: + InertiaTensorFunction( ) + : Superclass( ) + { + this->Reset( ); + } + virtual ~InertiaTensorFunction( ) + { + } + + private: + // Purposely not implemented. + InertiaTensorFunction( const Self& ); + void operator=( const Self& ); + + protected: + S m_M; + S m_MPP; + _TInternalVector m_MP; + _TInternalMatrix m_MPPT; + }; + + } // ecapseman + + } // ecapseman + +} // ecapseman + +// #include + +#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__INERTIATENSORFUNCTION__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Extensions/Algorithms/MultiScaleGaussianImageFilter.h b/lib/cpPlugins/Extensions/Algorithms/MultiScaleGaussianImageFilter.h new file mode 100644 index 0000000..e906512 --- /dev/null +++ b/lib/cpPlugins/Extensions/Algorithms/MultiScaleGaussianImageFilter.h @@ -0,0 +1,104 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__MULTISCALEGAUSSIANIMAGEFILTER__H__ +#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__MULTISCALEGAUSSIANIMAGEFILTER__H__ + +#include +#include + +namespace cpPlugins +{ + namespace Extensions + { + namespace Algorithms + { + /** + */ + template< class I, class O > + class MultiScaleGaussianImageFilter + : public itk::ImageToImageFilter< I, O > + { + public: + typedef MultiScaleGaussianImageFilter Self; + typedef itk::ImageToImageFilter< I, O > Superclass; + typedef itk::SmartPointer< Self > Pointer; + typedef itk::SmartPointer< const Self > ConstPointer; + + typedef I TInputImage; + typedef O TOutputImage; + + typedef std::set< double > TScalesContainer; + + enum FilterId + { + Gradient = 0, + GradientMagnitude, + Hessian, + None + }; + + protected: + /** + */ + class _Greater + { + public: + typedef typename O::PixelType _T; + + public: + _Greater( ); + virtual ~_Greater( ); + bool operator!=( const _Greater& b ) const; + bool operator==( const _Greater& b ) const; + inline _T operator()( const _T& a ) const; + inline _T operator()( const _T& a, const _T& b ) const; + }; + + public: + itkNewMacro( Self ); + itkTypeMacro( MultiScaleGaussianImageFilter, itkImageToImageFilter ); + + public: + void SetFilterToGradient( ); + void SetFilterToGradientMagnitude( ); + void SetFilterToHessian( ); + + bool IsGradientFilter( ) const; + bool IsGradientMagnitudeFilter( ) const; + bool IsHessianFilter( ) const; + + void AddScale( const double& s ); + unsigned long GetNumberOfScales( ) const; + + protected: + MultiScaleGaussianImageFilter( ); + virtual ~MultiScaleGaussianImageFilter( ); + + virtual void GenerateData( ); + + template< class F > + void _GenerateData( ); + + private: + // Purposely not implemented. + MultiScaleGaussianImageFilter( const Self& ); + void operator=( const Self& ); + + protected: + TScalesContainer m_Scales; + FilterId m_FilterId; + }; + + } // ecapseman + + } // ecapseman + +} // ecapseman + +#include + +#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__MULTISCALEGAUSSIANIMAGEFILTER__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Extensions/Algorithms/MultiScaleGaussianImageFilter.hxx b/lib/cpPlugins/Extensions/Algorithms/MultiScaleGaussianImageFilter.hxx new file mode 100644 index 0000000..0ec5156 --- /dev/null +++ b/lib/cpPlugins/Extensions/Algorithms/MultiScaleGaussianImageFilter.hxx @@ -0,0 +1,315 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__MULTISCALEGAUSSIANIMAGEFILTER__HXX__ +#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__MULTISCALEGAUSSIANIMAGEFILTER__HXX__ + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +// ------------------------------------------------------------------------- +template< class I, class O > +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >::_Greater:: +_Greater( ) +{ +} + +// ------------------------------------------------------------------------- +template< class I, class O > +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >::_Greater:: +~_Greater( ) +{ +} + +// ------------------------------------------------------------------------- +template< class I, class O > +bool cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >::_Greater:: +operator!=( const _Greater& b ) const +{ + return( false ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +bool cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >::_Greater:: +operator==( const _Greater& b ) const +{ + return !( *this != b ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +typename cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >::_Greater:: +_T cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >::_Greater:: +operator()( const _T& a ) const +{ + return( a ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +typename cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >::_Greater:: +_T cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >::_Greater:: +operator()( const _T& a, const _T& b ) const +{ + typedef itk::NumericTraits< _T > _TTraits; + typedef typename _TTraits::ValueType _TValue; + typedef vnl_vector< _TValue > _TVector; + + _TVector va( _TTraits::GetLength( ) ); + _TVector vb( _TTraits::GetLength( ) ); + + _TTraits::AssignToArray( a, va ); + _TTraits::AssignToArray( b, vb ); + return( ( vb.magnitude( ) < va.magnitude( ) )? a: b ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +void +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >:: +SetFilterToGradient( ) +{ + if( + itk::NumericTraits< typename O::PixelType >::GetLength( ) == + I::ImageDimension + ) + this->m_FilterId = Self::Gradient; + else + this->m_FilterId = Self::None; + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +void +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >:: +SetFilterToGradientMagnitude( ) +{ + if( itk::NumericTraits< typename O::PixelType >::GetLength( ) == 1 ) + this->m_FilterId = Self::GradientMagnitude; + else + this->m_FilterId = Self::None; + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +void +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >:: +SetFilterToHessian( ) +{ + itkExceptionMacro( << "Check for hessian definition." ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +bool +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >:: +IsGradientFilter( ) const +{ + return( this->m_FilterId == Self::Gradient ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +bool +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >:: +IsGradientMagnitudeFilter( ) const +{ + return( this->m_FilterId == Self::GradientMagnitude ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +bool +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >:: +IsHessianFilter( ) const +{ + return( this->m_FilterId == Self::Hessian ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +void +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >:: +AddScale( const double& s ) +{ + if( this->m_Scales.insert( s ).second ) + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +unsigned long +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >:: +GetNumberOfScales( ) const +{ + return( this->m_Scales.size( ) ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >:: +MultiScaleGaussianImageFilter( ) + : Superclass( ) +{ + this->SetFilterToGradientMagnitude( ); + if( !this->IsGradientMagnitudeFilter( ) ) + { + this->SetFilterToGradient( ); + if( !this->IsGradientFilter( ) ) + this->SetFilterToHessian( ); + + } // fi +} + +// ------------------------------------------------------------------------- +template< class I, class O > +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >:: +~MultiScaleGaussianImageFilter( ) +{ +} + +// ------------------------------------------------------------------------- +template< class I, class O > +void +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >:: +GenerateData( ) +{ + typedef itk::GradientRecursiveGaussianImageFilter< I, O > _TGF; + typedef itk::GradientMagnitudeRecursiveGaussianImageFilter< I, O > _TGMF; + typedef itk::HessianRecursiveGaussianImageFilter< I, O > _THF; + + if( this->IsGradientFilter( ) ) + this->_GenerateData< _TGF >( ); + else if( this->IsGradientMagnitudeFilter( ) ) + this->_GenerateData< _TGMF >( ); + else if( this->IsHessianFilter( ) ) + this->_GenerateData< _THF >( ); +} + +// ------------------------------------------------------------------------- +template< class I, class O > +template< class F > +void +cpPlugins::Extensions::Algorithms:: +MultiScaleGaussianImageFilter< I, O >:: +_GenerateData( ) +{ + // Some types + typedef itk::BinaryFunctorImageFilter< O, O, O, _Greater > _TMaxFilter; + typedef itk::UnaryFunctorImageFilter< O, O, _Greater > _TCopyFilter; + typedef itk::ImageRegionConstIterator< O > _TConstIt; + typedef itk::ImageRegionIterator< O > _TIt; + typedef itk::ProgressAccumulator _TProgress; + + // Some values + typename I::ConstPointer input = this->GetInput( ); + typename O::Pointer output = this->GetOutput( ); + unsigned int nThreads = this->GetNumberOfThreads( ); + float fw = float( 1 ) / float( this->m_Scales.size( ) << 1 ); + + // Progress accumulator + _TProgress::Pointer pg = _TProgress::New( ); + pg->SetMiniPipelineFilter( this ); + + // Copy image information + output->SetLargestPossibleRegion( input->GetLargestPossibleRegion( ) ); + output->SetRequestedRegion( input->GetRequestedRegion( ) ); + output->SetBufferedRegion( input->GetBufferedRegion( ) ); + output->SetSpacing( input->GetSpacing( ) ); + output->SetOrigin( input->GetOrigin( ) ); + output->SetDirection( input->GetDirection( ) ); + output->Allocate( ); + + // Intermediary buffer + typename O::Pointer buffer = O::New( ); + buffer->SetLargestPossibleRegion( input->GetLargestPossibleRegion( ) ); + buffer->SetRequestedRegion( input->GetRequestedRegion( ) ); + buffer->SetBufferedRegion( input->GetBufferedRegion( ) ); + buffer->SetSpacing( input->GetSpacing( ) ); + buffer->SetOrigin( input->GetOrigin( ) ); + buffer->SetDirection( input->GetDirection( ) ); + buffer->Allocate( ); + + // Perform all scales + _TIt gIt( output, output->GetRequestedRegion( ) ); + TScalesContainer::const_iterator sIt = this->m_Scales.begin( ); + for( ; sIt != this->m_Scales.end( ); sIt++ ) + { + // Single scale filter + typename F::Pointer filter = F::New( ); + filter->SetInput( input ); + filter->SetNormalizeAcrossScale( true ); + filter->SetNumberOfThreads( nThreads ); + filter->SetSigma( *sIt ); + pg->RegisterInternalFilter( filter, fw ); + filter->GraftOutput( buffer ); + filter->Update( ); + buffer->Graft( filter->GetOutput( ) ); + + // Get maximum response + if( sIt == this->m_Scales.begin( ) ) + { + // Copy first result + typename _TCopyFilter::Pointer copy = _TCopyFilter::New( ); + copy->SetInput( buffer ); + copy->InPlaceOff( ); + copy->SetNumberOfThreads( nThreads ); + pg->RegisterInternalFilter( copy, fw ); + copy->GraftOutput( output ); + copy->Update( ); + output->Graft( copy->GetOutput( ) ); + } + else + { + // Maximize results + typename _TMaxFilter::Pointer max = _TMaxFilter::New( ); + max->SetInput1( output ); + max->SetInput2( buffer ); + max->InPlaceOn( ); + max->SetNumberOfThreads( nThreads ); + pg->RegisterInternalFilter( max, fw ); + max->GraftOutput( output ); + max->Update( ); + output->Graft( max->GetOutput( ) ); + + } // fi + + } // rof +} + +#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__MULTISCALEGAUSSIANIMAGEFILTER__HXX__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Extensions/Algorithms/RGBExtractFunction.h b/lib/cpPlugins/Extensions/Algorithms/RGBExtractFunction.h new file mode 100644 index 0000000..d9d21be --- /dev/null +++ b/lib/cpPlugins/Extensions/Algorithms/RGBExtractFunction.h @@ -0,0 +1,58 @@ +// ------------------------------------------------------------------------- +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ------------------------------------------------------------------------- + +#ifndef __CPPLUGINS__EXTENSIONS__ALGORITHMS__RGBEXTRACTFUNCTION__H__ +#define __CPPLUGINS__EXTENSIONS__ALGORITHMS__RGBEXTRACTFUNCTION__H__ + +#include +#include +#include + +#include +#include + +namespace cpPlugins +{ + namespace Extensions + { + namespace Algorithms + { + /** + */ + template< class O > + struct RGBExtractFunction + { + typedef RGBExtractFunction Self; + typedef itk::Vector< O, 3 > TOutPixel; + + template< class Tr, class Tg, class Tb > + TOutPixel operator()( const Tr& r, const Tg& g, const Tb& b ) const + { + TOutPixel rgb; + rgb[ 0 ] = O( r ); + rgb[ 1 ] = O( g ); + rgb[ 2 ] = O( b ); + return( rgb ); + } + + template< class C > + TOutPixel operator()( const itk::RGBPixel< C >& rgb ) const + { + return( + this->operator()( + rgb.GetRed( ), rgb.GetGreen( ), rgb.GetBlue( ) + ) + ); + } + }; + + } // ecapseman + + } // ecapseman + +} // ecapseman + +#endif // __CPPLUGINS__EXTENSIONS__ALGORITHMS__RGBEXTRACTFUNCTION__H__ + +// eof - $RCSfile$ diff --git a/lib/cpPlugins/Extensions/CMakeLists.txt b/lib/cpPlugins/Extensions/CMakeLists.txt index f9d6d98..c669f39 100644 --- a/lib/cpPlugins/Extensions/CMakeLists.txt +++ b/lib/cpPlugins/Extensions/CMakeLists.txt @@ -71,9 +71,17 @@ GENERATE_EXPORT_HEADER( ) TARGET_LINK_LIBRARIES( ${LIBRARY_NAME} - ITKCommon - ITKVtkGlue + vtkCommonCore + vtkRenderingCore + vtkRenderingOpenGL + vtkRenderingAnnotation + vtkRenderingVolumeOpenGL + vtkRenderingFreeTypeOpenGL + vtkInteractionStyle vtkInteractionWidgets + vtkIOMPIImage + ITKCommon + ITKVTK ) ## eof - $RCSfile$ diff --git a/lib/cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.cxx b/lib/cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.cxx index e870051..1bf8ea9 100644 --- a/lib/cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.cxx +++ b/lib/cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.cxx @@ -156,6 +156,16 @@ RenderAll( ) this->m_Windows[ i ]->Render( ); } +// ------------------------------------------------------------------------- +vtkRenderer* cpPlugins::Extensions::Visualization::MPRWithDifferentWindows:: +GetRenderer( const int& id ) const +{ + if( id < 4 ) + return( this->m_Renderers[ id ] ); + else + return( NULL ); +} + // ------------------------------------------------------------------------- void cpPlugins::Extensions::Visualization::MPRWithDifferentWindows:: Add3DActor( vtkProp3D* prop ) diff --git a/lib/cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.h b/lib/cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.h index aef8ebd..addfad7 100644 --- a/lib/cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.h +++ b/lib/cpPlugins/Extensions/Visualization/MPRWithDifferentWindows.h @@ -70,6 +70,8 @@ namespace cpPlugins void Render( const int& id ); void RenderAll( ); + vtkRenderer* GetRenderer( const int& id ) const; + void Add3DActor( vtkProp3D* prop ); protected: diff --git a/lib/cpPlugins/Plugins/CMakeLists.txt b/lib/cpPlugins/Plugins/CMakeLists.txt index 7bf21b5..372b150 100644 --- a/lib/cpPlugins/Plugins/CMakeLists.txt +++ b/lib/cpPlugins/Plugins/CMakeLists.txt @@ -33,9 +33,6 @@ TARGET_LINK_LIBRARIES( ${LIBRARY_NAME} cpPlugins_Interface ${ITK_LIBRARIES} - ${VTK_LIBRARIES} - vtkIOLegacy - ITKIOImageBase ) ## eof - $RCSfile$ diff --git a/lib/third_party/ItkVtkGlue/itkImageToVTKImageFilter.h b/lib/third_party/ItkVtkGlue/itkImageToVTKImageFilter.h new file mode 100644 index 0000000..34975da --- /dev/null +++ b/lib/third_party/ItkVtkGlue/itkImageToVTKImageFilter.h @@ -0,0 +1,108 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ +#ifndef __itkImageToVTKImageFilter_h +#define __itkImageToVTKImageFilter_h + +#include "itkVTKImageExport.h" +#include "vtkImageImport.h" +#include "vtkImageData.h" + +namespace itk +{ + +/** \class ImageToVTKImageFilter + * \brief Converts an ITK image into a VTK image and plugs a + * itk data pipeline to a VTK datapipeline. + * + * This class puts together an itkVTKImageExporter and a vtkImageImporter. + * It takes care of the details related to the connection of ITK and VTK + * pipelines. The User will perceive this filter as an adaptor to which + * an itk::Image can be plugged as input and a vtkImage is produced as + * output. + * + * \ingroup ITKVtkGlue + * + * \wiki + * \wikiexample{IO/ImageToVTKImageFilter,Display an ITK image} + * \wikiexample{IO/itkVtkImageConvertDICOM,Uses a custom user matrix to align the image with DICOM physical space} + * \endwiki + */ +template +class ImageToVTKImageFilter : public ProcessObject +{ +public: + /** Standard class typedefs. */ + typedef ImageToVTKImageFilter Self; + typedef ProcessObject Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(ImageToVTKImageFilter, ProcessObject); + + /** Some typedefs. */ + typedef TInputImage InputImageType; + typedef typename InputImageType::ConstPointer InputImagePointer; + + typedef VTKImageExport< InputImageType> ExporterFilterType; + typedef typename ExporterFilterType::Pointer ExporterFilterPointer; + + /** Get the output in the form of a vtkImage. + This call is delegated to the internal vtkImageImporter filter */ + vtkImageData * GetOutput() const; + + /** Set the input in the form of an itk::Image */ + using Superclass::SetInput; + void SetInput( const InputImageType * ); + InputImageType * GetInput(); + + /** Return the internal VTK image importer filter. + This is intended to facilitate users the access + to methods in the importer */ + vtkImageImport * GetImporter() const; + + /** Return the internal ITK image exporter filter. + This is intended to facilitate users the access + to methods in the exporter */ + ExporterFilterType * GetExporter() const; + + /** This call delegates the update to the importer */ + void Update(); + +protected: + ImageToVTKImageFilter(); + virtual ~ImageToVTKImageFilter(); + +private: + ImageToVTKImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + ExporterFilterPointer m_Exporter; + vtkImageImport * m_Importer; +}; + +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itkImageToVTKImageFilter.hxx" +#endif + +#endif diff --git a/lib/third_party/ItkVtkGlue/itkImageToVTKImageFilter.hxx b/lib/third_party/ItkVtkGlue/itkImageToVTKImageFilter.hxx new file mode 100644 index 0000000..1febaf0 --- /dev/null +++ b/lib/third_party/ItkVtkGlue/itkImageToVTKImageFilter.hxx @@ -0,0 +1,129 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ +#ifndef __itkImageToVTKImageFilter_hxx +#define __itkImageToVTKImageFilter_hxx + +#include "itkImageToVTKImageFilter.h" + +namespace itk +{ + +/** + * Constructor + */ +template +ImageToVTKImageFilter +::ImageToVTKImageFilter() +{ + m_Importer = vtkImageImport::New(); + m_Exporter = ExporterFilterType::New(); + + m_Importer->SetUpdateInformationCallback(m_Exporter->GetUpdateInformationCallback()); + m_Importer->SetPipelineModifiedCallback(m_Exporter->GetPipelineModifiedCallback()); + m_Importer->SetWholeExtentCallback(m_Exporter->GetWholeExtentCallback()); + m_Importer->SetSpacingCallback(m_Exporter->GetSpacingCallback()); + m_Importer->SetOriginCallback(m_Exporter->GetOriginCallback()); + m_Importer->SetScalarTypeCallback(m_Exporter->GetScalarTypeCallback()); + m_Importer->SetNumberOfComponentsCallback(m_Exporter->GetNumberOfComponentsCallback()); + m_Importer->SetPropagateUpdateExtentCallback(m_Exporter->GetPropagateUpdateExtentCallback()); + m_Importer->SetUpdateDataCallback(m_Exporter->GetUpdateDataCallback()); + m_Importer->SetDataExtentCallback(m_Exporter->GetDataExtentCallback()); + m_Importer->SetBufferPointerCallback(m_Exporter->GetBufferPointerCallback()); + m_Importer->SetCallbackUserData(m_Exporter->GetCallbackUserData()); + +} + +/** + * Destructor + */ +template +ImageToVTKImageFilter +::~ImageToVTKImageFilter() +{ + if( m_Importer ) + { + m_Importer->Delete(); + m_Importer = 0; + } +} + +/** + * Set an itk::Image as input + */ +template +void +ImageToVTKImageFilter +::SetInput( const InputImageType * inputImage ) +{ + m_Exporter->SetInput( inputImage ); +} + +template +typename ImageToVTKImageFilter::InputImageType * +ImageToVTKImageFilter +::GetInput() +{ + return m_Exporter->GetInput(); +} + +/** + * Get a vtkImage as output + */ +template +vtkImageData * +ImageToVTKImageFilter +::GetOutput() const +{ + return m_Importer->GetOutput(); +} + +/** + * Get the importer filter + */ +template +vtkImageImport * +ImageToVTKImageFilter +::GetImporter() const +{ + return m_Importer; +} + +/** + * Get the exporter filter + */ +template +typename ImageToVTKImageFilter::ExporterFilterType * +ImageToVTKImageFilter +::GetExporter() const +{ + return m_Exporter.GetPointer(); +} + +/** + * Delegate the Update to the importer + */ +template +void +ImageToVTKImageFilter +::Update() +{ + m_Importer->Update(); +} +} // end namespace itk + +#endif diff --git a/lib/third_party/ItkVtkGlue/itkVTKImageToImageFilter.h b/lib/third_party/ItkVtkGlue/itkVTKImageToImageFilter.h new file mode 100644 index 0000000..6ba43fb --- /dev/null +++ b/lib/third_party/ItkVtkGlue/itkVTKImageToImageFilter.h @@ -0,0 +1,100 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ + +#ifndef __itkVTKImageToImageFilter_h +#define __itkVTKImageToImageFilter_h + +#include "itkVTKImageImport.h" +#include "vtkImageExport.h" +#include "vtkImageData.h" +#include "vtkSmartPointer.h" + +#ifndef vtkFloatingPointType +#define vtkFloatingPointType float +#endif + +namespace itk +{ + +/** \class VTKImageToImageFilter + * \brief Converts a VTK image into an ITK image and plugs a + * VTK data pipeline to an ITK datapipeline. + * + * This class puts together an itk::VTKImageImport and a vtk::ImageExport. + * It takes care of the details related to the connection of ITK and VTK + * pipelines. The User will perceive this filter as an adaptor to which + * a vtkImageData can be plugged as input and an itk::Image is produced as + * output. + * + * \ingroup ITKVtkGlue + */ +template +class VTKImageToImageFilter : public VTKImageImport< TOutputImage > +{ +public: + /** Standard class typedefs. */ + typedef VTKImageToImageFilter Self; + typedef VTKImageImport< TOutputImage > Superclass; + typedef SmartPointer Pointer; + typedef SmartPointer ConstPointer; + + /** Method for creation through the object factory. */ + itkNewMacro(Self); + + /** Run-time type information (and related methods). */ + itkTypeMacro(VTKImageToImageFilter, VTKImageImport); + + /** Some typedefs. */ + typedef TOutputImage OutputImageType; + typedef typename OutputImageType::ConstPointer OutputImagePointer; + + /** Set the input in the form of a vtkImageData */ + void SetInput( vtkImageData * ); + using Superclass::SetInput; + + /** Return the internal VTK image exporter filter. + This is intended to facilitate users the access + to methods in the exporter */ + vtkImageExport * GetExporter() const; + + /** Return the internal ITK image importer filter. + This is intended to facilitate users the access + to methods in the importer. + */ + const Superclass * GetImporter() const; + +protected: + VTKImageToImageFilter(); + virtual ~VTKImageToImageFilter(); + +private: + VTKImageToImageFilter(const Self&); //purposely not implemented + void operator=(const Self&); //purposely not implemented + + typedef vtkSmartPointer ImageExportPointer; + ImageExportPointer m_Exporter; + +}; + +} // end namespace itk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "itkVTKImageToImageFilter.hxx" +#endif + +#endif diff --git a/lib/third_party/ItkVtkGlue/itkVTKImageToImageFilter.hxx b/lib/third_party/ItkVtkGlue/itkVTKImageToImageFilter.hxx new file mode 100644 index 0000000..c17538b --- /dev/null +++ b/lib/third_party/ItkVtkGlue/itkVTKImageToImageFilter.hxx @@ -0,0 +1,107 @@ +/*========================================================================= + * + * Copyright Insight Software Consortium + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *=========================================================================*/ + +#ifndef __itkVTKImageToImageFilter_hxx +#define __itkVTKImageToImageFilter_hxx + +#include "itkVTKImageToImageFilter.h" + +#include "vtkVersion.h" + +namespace itk +{ + +/** + * Constructor + */ +template +VTKImageToImageFilter +::VTKImageToImageFilter() +{ + + m_Exporter = vtkImageExport::New(); + + this->SetUpdateInformationCallback( m_Exporter->GetUpdateInformationCallback()); + this->SetPipelineModifiedCallback( m_Exporter->GetPipelineModifiedCallback()); + this->SetWholeExtentCallback( m_Exporter->GetWholeExtentCallback()); + this->SetSpacingCallback( m_Exporter->GetSpacingCallback()); + this->SetOriginCallback( m_Exporter->GetOriginCallback()); + this->SetScalarTypeCallback( m_Exporter->GetScalarTypeCallback()); + this->SetNumberOfComponentsCallback( m_Exporter->GetNumberOfComponentsCallback()); + this->SetPropagateUpdateExtentCallback( m_Exporter->GetPropagateUpdateExtentCallback()); + this->SetUpdateDataCallback( m_Exporter->GetUpdateDataCallback()); + this->SetDataExtentCallback( m_Exporter->GetDataExtentCallback()); + this->SetBufferPointerCallback( m_Exporter->GetBufferPointerCallback()); + this->SetCallbackUserData( m_Exporter->GetCallbackUserData()); + +} + +/** + * Destructor + */ +template +VTKImageToImageFilter +::~VTKImageToImageFilter() +{ + if( m_Exporter ) + { + m_Exporter->Delete(); + m_Exporter = 0; + } +} + +/** + * Set a vtkImageData as input + */ +template +void +VTKImageToImageFilter +::SetInput( vtkImageData * inputImage ) +{ +#if VTK_MAJOR_VERSION <= 5 + m_Exporter->SetInput( inputImage ); +#else + m_Exporter->SetInputData( inputImage ); +#endif +} + +/** + * Get the exporter filter + */ +template +vtkImageExport * +VTKImageToImageFilter +::GetExporter() const +{ + return m_Exporter; +} + +/** + * Get the importer filter + */ +template +const typename VTKImageToImageFilter::Superclass * +VTKImageToImageFilter +::GetImporter() const +{ + return this; +} + +} // end namespace itk + +#endif -- 2.47.1