#include <cstdlib>
#include <iostream>
+#include <sstream>
#include <string>
#include <vector>
// -------------------------------------------------------------------------
int main( int argc, char* argv[] )
{
- if( argc < 5 )
+ if( argc < 9 )
{
std::cerr
<< "Usage: " << argv[ 0 ]
- << " plugins_file input_image lower upper"
+ << " plugins_file input_image"
+ << " lower1 upper1 lower2 upper2 lower3 upper3"
<< std::endl;
return( 1 );
} // fi
std::string plugins_file = argv[ 1 ];
- double lower = std::atof( argv[ argc - 2 ] );
- double upper = std::atof( argv[ argc - 1 ] );
+ std::string input_image_file = argv[ 2 ];
+ double lower[ 3 ], upper[ 3 ];
+ lower[ 0 ] = std::atof( argv[ 3 ] );
+ upper[ 0 ] = std::atof( argv[ 4 ] );
+ lower[ 1 ] = std::atof( argv[ 5 ] );
+ upper[ 1 ] = std::atof( argv[ 6 ] );
+ lower[ 2 ] = std::atof( argv[ 7 ] );
+ upper[ 2 ] = std::atof( argv[ 8 ] );
// Load plugins
cpPlugins::Interface::Plugins plugins;
} // fi
- // Associate filenames
- std::vector< std::string > fnames;
- for( int i = 2; i < argc - 2; ++i )
- fnames.push_back( argv[ i ] );
-
// Read image
std::string image_name = "";
try
{
- image_name = plugins.ReadImage( fnames, "" );
+ image_name = plugins.ReadImage( input_image_file, "" );
}
catch( std::exception& err )
{
} // yrt
- // Apply a two-level threshold
+ // Apply three a two-level threshold
+ std::vector< std::string > thresholds_names;
std::string filter_name =
"cpPlugins::BasicFilters::BinaryThresholdImageFilter";
-
- if( !( plugins.ActivateFilter( filter_name ) ) )
+ for( int i = 0; i < 3; ++i )
{
- std::cerr << "No filter found" << std::endl;
- return( 1 );
+ if( !( plugins.ActivateFilter( filter_name ) ) )
+ {
+ std::cerr << "No filter found" << std::endl;
+ return( 1 );
- } // fi
+ } // fi
- // Connect inputs
- TPlugins::TStringContainer input_names;
- plugins.GetActiveFilterInputsNames( input_names );
- for( auto iIt = input_names.begin( ); iIt != input_names.end( ); ++iIt )
- plugins.ConnectInputInActiveFilter( image_name, *iIt );
-
- // Configure
- TPlugins::TParameters* filter_params = plugins.GetActiveFilterParameters( );
- filter_params->SetReal( "LowerThresholdValue", lower );
- filter_params->SetReal( "UpperThresholdValue", upper );
- filter_params->SetUint( "InsideValue", 1 );
- filter_params->SetUint( "OutsideValue", 0 );
-
- // Execute
- TPlugins::TStringContainer output_names;
- try
- {
- if( !( plugins.UpdateActiveFilter( output_names, image_name ) ) )
+ // Connect inputs
+ TPlugins::TStringContainer input_names;
+ plugins.GetActiveFilterInputsNames( input_names );
+ for( auto iIt = input_names.begin( ); iIt != input_names.end( ); ++iIt )
+ plugins.ConnectInputInActiveFilter( image_name, *iIt );
+
+ // Configure
+ TPlugins::TParameters* filter_params = plugins.GetActiveFilterParameters( );
+ filter_params->SetReal( "LowerThresholdValue", lower[ i ] );
+ filter_params->SetReal( "UpperThresholdValue", upper[ i ] );
+ filter_params->SetUint( "InsideValue", i + 10 );
+ filter_params->SetUint( "OutsideValue", 0 );
+
+ // Configure outputs
+ TPlugins::TStringContainer output_names;
+ plugins.GetActiveFilterOutputsNames( output_names );
+
+ std::stringstream obj_name_str;
+ obj_name_str << "output_" << i;
+ plugins.SetOutputNameInActiveFilter(
+ obj_name_str.str( ),
+ *( output_names.begin( ) )
+ );
+
+ // Execute
+ output_names.clear( );
+ try
{
- std::cerr << "Error executing filter." << std::endl;
+ if( !( plugins.UpdateActiveFilter( output_names, image_name ) ) )
+ {
+ std::cerr << "Error executing filter." << std::endl;
+ return( 1 );
+
+ } // fi
+ }
+ catch( std::exception& err )
+ {
+ std::cerr << err.what( ) << std::endl;
return( 1 );
- } // fi
- }
- catch( std::exception& err )
- {
- std::cerr << err.what( ) << std::endl;
- return( 1 );
+ } // yrt
+ thresholds_names.push_back( *( output_names.begin( ) ) );
- } // yrt
- std::string threshold_name = *( output_names.begin( ) );
+ plugins.DeactivateFilter( );
+
+ } // rof
// Get both images
TImage* image = plugins.GetData< TImage >( image_name );
- TImage* threshold = plugins.GetData< TImage >( threshold_name );
+ TImage* thr0 = plugins.GetData< TImage >( thresholds_names[ 0 ] );
+ TImage* thr1 = plugins.GetData< TImage >( thresholds_names[ 1 ] );
+ TImage* thr2 = plugins.GetData< TImage >( thresholds_names[ 2 ] );
// Configure visualization objects
vtkSmartPointer< vtkRenderer > renderer =
vtkSmartPointer< vtkRenderer >::New( );
- renderer->SetBackground( 0.1, 0.3, 0.5 );
+ renderer->SetBackground( 0.3, 0.3, 0.3 );
vtkSmartPointer< vtkRenderWindow > window =
vtkSmartPointer< vtkRenderWindow >::New( );
vtkSmartPointer< TSliceActors > image_actors =
vtkSmartPointer< TSliceActors >::New( );
image_actors->SetInputImage( image->GetVTK< vtkImageData >( ) );
- image_actors->AddBinaryImage( threshold->GetVTK< vtkImageData >( ), 1, 0, 1 );
+ image_actors->AddBinaryImage( thr0->GetVTK< vtkImageData >( ), 1, 0, 0 );
+ image_actors->AddBinaryImage( thr1->GetVTK< vtkImageData >( ), 0, 1, 0 );
+ image_actors->AddBinaryImage( thr2->GetVTK< vtkImageData >( ), 0, 0, 1 );
image_actors->SetAxis( 2 );
image_actors->PushActorsInto( window );
// Begin interaction
- image_actors->ResetCamera( );
+ renderer->ResetCamera( );
window->Render( );
interactor->Start( );