{
this->m_UI->setupUi( this );
this->m_Plugins->SetWidget( this );
+ this->m_Plugins->SetApplication( this );
// Connect actions
ImageMPR_ConnectAction( OpenImage );
ImageMPR_ConnectAction( LoadPlugins );
ImageMPR_ConnectAction( ShowPlugins );
+ // Associate model with view
+ for( unsigned int i = 0; i < 4; ++i )
+ this->m_Plugins->AddInteractor( this->m_UI->MPR->GetInteractor( i ) );
+
// Try to load default plugins
#ifdef WIN32
- this->m_Plugins->LoadPlugins("cpPluginsIO.dll");
- this->m_Plugins->LoadPlugins("cpPluginsBasicFilters.dll");
+ this->m_Plugins->LoadPlugins( "cpPluginsIO.dll" );
+ this->m_Plugins->LoadPlugins( "cpPluginsBasicFilters.dll" );
#else
- this->m_Plugins->LoadPluginsConfigurationFile("Plugins.cfg");
+ this->m_Plugins->LoadPluginsConfigurationFile( "Plugins.cfg" );
#endif
this->m_Plugins->AssociatePluginsToMenu(
this->m_UI->MenuFilters, this, SLOT( _execPlugin( ) )
delete this->m_Plugins;
}
+// -------------------------------------------------------------------------
+void ImageMPR::
+UpdateActualFilter( )
+{
+ if( !( this->m_Plugins->HasActiveFilter( ) ) )
+ return;
+
+ std::vector< std::string > outputs;
+ std::string err = this->m_Plugins->UpdateActiveFilter( outputs );
+ if( err == "" )
+ {
+ for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
+ {
+ TPlugins::TImage* image = this->m_Plugins->GetImage( *oIt );
+ if( image != NULL )
+ {
+ vtkImageData* vimage = image->GetVTK< vtkImageData >( );
+ if( vimage != NULL )
+ {
+ this->m_UI->MPR->AddImage(
+ vimage, *oIt, this->m_Plugins->GetParent( *oIt )
+ );
+ this->m_UI->MPR->ShowData( *oIt );
+
+ } // fi
+ continue;
+
+ } // fi
+
+ TPlugins::TMesh* mesh = this->m_Plugins->GetMesh( *oIt );
+ if( mesh != NULL )
+ {
+ this->m_Plugins->BlockWidget( );
+ this->m_UI->MPR->AddMesh(
+ mesh->GetVTK< vtkPolyData >( ),
+ *oIt,
+ this->m_Plugins->GetParent( *oIt )
+ );
+ this->m_UI->MPR->ShowData( *oIt );
+ this->m_Plugins->UnblockWidget( );
+
+ } // fi
+
+ } // rof
+ }
+ else
+ {
+ QMessageBox::critical(
+ this,
+ tr( "Error executing filter" ),
+ tr( ( std::string( "Error caught: " ) + err ).c_str( ) )
+ );
+ return;
+
+ } // fi
+}
+
// -------------------------------------------------------------------------
void ImageMPR::
_aOpenImage( )
{
- // Read and show image, if possible
- TPlugins::TImage::Pointer image;
- if( this->m_Plugins->ReadImage( image, true ) )
+ std::string name = this->m_Plugins->ReadImage( "" );
+ if( name != "" )
{
+ // Since we are opening an image, clear view
+ this->m_UI->MPR->DeleteAllData( );
+
+ // Prepare visualization
+ TPlugins::TImage* image = this->m_Plugins->GetImage( name );
vtkImageData* vimage = image->GetVTK< vtkImageData >( );
- if( vimage == NULL )
+ if( vimage != NULL )
{
+ this->m_UI->MPR->AddImage( vimage, name );
+ this->m_UI->MPR->ShowData( name );
+ }
+ else
QMessageBox::critical(
this,
QMessageBox::tr( "Error showing image." ),
"Image was read, but no valid VTK conversion was found."
)
);
- return;
- }
- else
- {
- // Since we are opening an image, clear all
- this->m_UI->MPR->DeleteAllData( );
- this->m_Objects.clear( );
-
- // Update references
- std::string name = image->GetName( );
- this->m_Objects[ name ] = TTreeNode( "", image.GetPointer( ) );
- this->m_UI->MPR->AddImage( vimage, name );
- this->m_UI->MPR->ShowData( name );
-
- } // fi
} // fi
}
void ImageMPR::
_aOpenDICOMSeries( )
{
- // Read and show image, if possible
- TPlugins::TImage::Pointer image;
- if( this->m_Plugins->ReadDicomSeries( image ) )
+ std::string name = this->m_Plugins->ReadDicomSeries( "" );
+ if( name != "" )
{
+ // Since we are opening an image, clear view
+ this->m_UI->MPR->DeleteAllData( );
+
+ // Prepare visualization
+ TPlugins::TImage* image = this->m_Plugins->GetImage( name );
vtkImageData* vimage = image->GetVTK< vtkImageData >( );
- if( vimage == NULL )
+ if( vimage != NULL )
{
+ this->m_UI->MPR->AddImage( vimage, name );
+ this->m_UI->MPR->ShowData( name );
+ }
+ else
QMessageBox::critical(
this,
QMessageBox::tr( "Error showing image." ),
"Image was read, but no valid VTK conversion was found."
)
);
- return;
- }
- else
- {
- // Since we are opening an image, clear all
- this->m_UI->MPR->DeleteAllData( );
- this->m_Objects.clear( );
-
- // Update references
- std::string name = image->GetName( );
- this->m_Objects[ name ] = TTreeNode( "", image.GetPointer( ) );
- this->m_UI->MPR->AddImage( vimage, name );
- this->m_UI->MPR->ShowData( name );
-
- } // fi
} // fi
}
_aSaveImage( )
{
std::string data_name = this->m_UI->MPR->GetSelectedData( );
- TPlugins::TImage* image = dynamic_cast< TPlugins::TImage* >(
- this->m_Objects[ data_name ].second.GetPointer( )
- );
- if( image == NULL )
- return;
- this->m_Plugins->WriteImage( image, true );
+ this->m_Plugins->WriteImage( data_name );
}
// -------------------------------------------------------------------------
void ImageMPR::
_aSavePolyData( )
{
- std::string data_name = this->m_UI->MPR->GetSelectedData( );
- TPlugins::TMesh* mesh = dynamic_cast< TPlugins::TMesh* >(
- this->m_Objects[ data_name ].second.GetPointer( )
- );
- if( mesh == NULL )
- return;
- this->m_Plugins->WriteMesh( mesh, true );
}
// -------------------------------------------------------------------------
std::string filter_cate = menu->title( ).toStdString( );
std::string filter_name = action->text( ).toStdString( );
- // Create filter
- if( !( this->m_Plugins->CreateFilter( this->m_ActiveFilter, filter_name ) ) )
- {
- QMessageBox::critical(
- this,
- tr( "Error creating filter" ),
- tr( (
- std::string( "No valid filter \"" ) +
- filter_name +
- std::string( "\"defined." )
- ).c_str( ) )
- );
- this->m_ActiveFilter = NULL;
- return;
-
- } // fi
-
- // Configure filter
- this->m_ActiveFilter->AddInteractor( this->m_UI->MPR->GetInteractor( 0 ) );
- this->m_ActiveFilter->AddInteractor( this->m_UI->MPR->GetInteractor( 1 ) );
- this->m_ActiveFilter->AddInteractor( this->m_UI->MPR->GetInteractor( 2 ) );
- this->m_ActiveFilter->AddInteractor( this->m_UI->MPR->GetInteractor( 3 ) );
-
- TPlugins::TProcessObject::DialogResult res =
- this->m_ActiveFilter->ExecConfigurationDialog( this );
- if( res == TPlugins::TProcessObject::DialogResult_Cancel )
- {
- this->m_ActiveFilter = NULL;
+ // Activate filter
+ if( !( this->m_Plugins->ActivateFilter( filter_name ) ) )
return;
- } // fi
-
- // Assign inputs
- std::string data_name = this->m_UI->MPR->GetSelectedData( );
- std::vector< std::string > inputs_names =
- this->m_ActiveFilter->GetInputsNames( );
- if( inputs_names.size( ) == 1 )
+ // Associate inputs
+ std::vector< std::string > inputs =
+ this->m_Plugins->GetActiveFilterInputsNames( );
+ if( inputs.size( ) == 1 )
{
- TTree::iterator iIt = this->m_Objects.find( data_name );
- if( iIt == this->m_Objects.end( ) )
- {
- QMessageBox::critical(
- this,
- tr( "Error configuring filter" ),
- tr( "No valid input found. Please select a valid input." )
- );
- this->m_ActiveFilter = NULL;
- return;
-
- } //fi
- this->m_ActiveFilter->SetInput( inputs_names[ 0 ], iIt->second.second );
+ std::string data_name = this->m_UI->MPR->GetSelectedData( );
+ this->m_Plugins->ConnectInputInActiveFilter( data_name, inputs[ 0 ] );
}
- else if( inputs_names.size( ) > 1 )
+ else if( inputs.size( ) > 1 )
{
QMessageBox::critical(
this,
} // fi
- // Execute filter
- /*
- if( res == TPlugins::TProcessObject::DialogResult_NoModal )
- {
- this->_Block( );
- std::string filter_err = this->m_ActiveFilter->Update( );
- this->_Unblock( );
- if( filter_err != "" )
- {
- QMessageBox::critical(
- this,
- tr( "Error executing" ),
- tr( filter_err.c_str( ) )
- );
- this->m_ActiveFilter = NULL;
- return;
-
- } // fi
-
- // Get outputs
- std::vector< std::string > outputs_names = filter->GetOutputsNames( );
- for(
- auto oIt = outputs_names.begin( );
- oIt != outputs_names.end( );
- ++oIt
- )
- {
- std::string out_name = filter_name + "_" + *oIt;
-
- TPlugins::TImage* image =
- this->m_ActiveFilter->GetOutput< TPlugins::TImage >( *oIt );
- if( image != NULL )
- {
- if( filter_cate == "ImageToBinaryImageFilter" )
- {
- this->m_UI->MPR->ShowImage(
- image->GetVTK< vtkImageData >( ),
- out_name,
- data_name, 1, 0, 0
- );
- }
- else if( filter_cate == "ImageToImageFilter" )
- {
- } // fi
-
- // Keep a track on a local data tree and go to next output
- this->m_Objects[ out_name ] = TTreeNode( data_name, image );
- continue;
-
- } // fi
-
- TPlugins::TMesh* mesh = filter->GetOutput< TPlugins::TMesh >( *oIt );
- if( mesh != NULL )
- {
- // Show mesh
- this->_Block( );
- this->m_UI->MPR->ShowMesh(
- mesh->GetVTK< vtkPolyData >( ),
- out_name,
- data_name
- );
- this->_Unblock( );
-
- // Keep a track on a local data tree and go to next output
- this->m_Objects[ out_name ] = TTreeNode( data_name, mesh );
- continue;
+ // Associate outputs
+ std::vector< std::string > outputs =
+ this->m_Plugins->GetActiveFilterOutputsNames( );
+ for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
+ this->m_Plugins->SetOutputNameInActiveFilter(
+ filter_name + "_" + *oIt, *oIt
+ );
- } // fi
+ // Configure filter
+ TPlugins::TProcessObject::DialogResult dlg_res =
+ this->m_Plugins->ConfigureActiveFilter( );
+ if( dlg_res == TPlugins::TProcessObject::DialogResult_Cancel )
+ {
+ this->m_Plugins->DeactivateFilter( );
+ return;
- } // rof
+ } // fi
- // No-modal filters just exists for one usage
- this->m_ActiveFilter = NULL;
+ // Execute filter and associate outputs
+ if( dlg_res == TPlugins::TProcessObject::DialogResult_NoModal )
+ {
+ this->UpdateActualFilter( );
+ this->m_Plugins->DeactivateFilter( );
} // fi
- */
}
// -------------------------------------------------------------------------
cpPlugins::Interface::Plugins::
Plugins( QWidget* widget )
: m_Widget( widget ),
+ m_Application( NULL ),
m_LastLoadedPlugin( "." )
{
}
#endif // cpPlugins_Interface_QT4
}
+// -------------------------------------------------------------------------
+cpPlugins::Interface::
+BasePluginsApplication* cpPlugins::Interface::Plugins::
+GetApplication( )
+{
+ return( this->m_Application );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::
+BasePluginsApplication* cpPlugins::Interface::Plugins::
+GetApplication( ) const
+{
+ return( this->m_Application );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+SetApplication( cpPlugins::Interface::BasePluginsApplication* a )
+{
+ this->m_Application = a;
+}
+
// -------------------------------------------------------------------------
bool cpPlugins::Interface::Plugins::
LoadPlugins( const std::string& fname )
{
this->m_LoadedPlugins.insert( fname );
this->m_LastLoadedPlugin = fname;
- this->_Update( );
+ this->_UpdateLoadedPluginsInformation( );
} // fi
}
// -------------------------------------------------------------------------
-cpPlugins::Interface::Plugins::
-TParameters* cpPlugins::Interface::Plugins::
-GetImageReaderParameters( )
+void cpPlugins::Interface::Plugins::
+AddInteractor( vtkRenderWindowInteractor* interactor )
{
- return( this->m_ImageReader->GetParameters( ) );
+ this->m_Interactors.insert( interactor );
}
// -------------------------------------------------------------------------
-cpPlugins::Interface::Plugins::
-TParameters* cpPlugins::Interface::Plugins::
-GetMeshReaderParameters( )
+void cpPlugins::Interface::Plugins::
+RemoveInteractor( vtkRenderWindowInteractor* interactor )
{
- return( this->m_MeshReader->GetParameters( ) );
+ this->m_Interactors.erase( interactor );
}
// -------------------------------------------------------------------------
-cpPlugins::Interface::Plugins::
-TParameters* cpPlugins::Interface::Plugins::
-GetImageWriterParameters( )
+void cpPlugins::Interface::Plugins::
+ClearInteractors( )
{
- return( this->m_ImageWriter->GetParameters( ) );
+ this->m_Interactors.clear( );
}
// -------------------------------------------------------------------------
-cpPlugins::Interface::Plugins::
-TParameters* cpPlugins::Interface::Plugins::
-GetMeshWriterParameters( )
+bool cpPlugins::Interface::Plugins::
+HasImageReader( ) const
{
- return( this->m_MeshWriter->GetParameters( ) );
+ return( this->m_ImageReader.IsNotNull( ) );
}
// -------------------------------------------------------------------------
-const cpPlugins::Interface::Plugins::
-TParameters* cpPlugins::Interface::Plugins::
-GetImageReaderParameters( ) const
+bool cpPlugins::Interface::Plugins::
+HasDicomSeriesReader( ) const
{
- return( this->m_ImageReader->GetParameters( ) );
+ return( this->m_DicomSeriesReader.IsNotNull( ) );
}
// -------------------------------------------------------------------------
-const cpPlugins::Interface::Plugins::
-TParameters* cpPlugins::Interface::Plugins::
-GetMeshReaderParameters( ) const
+bool cpPlugins::Interface::Plugins::
+HasMeshReader( ) const
{
- return( this->m_MeshReader->GetParameters( ) );
+ return( this->m_MeshReader.IsNotNull( ) );
}
// -------------------------------------------------------------------------
-const cpPlugins::Interface::Plugins::
-TParameters* cpPlugins::Interface::Plugins::
-GetImageWriterParameters( ) const
+bool cpPlugins::Interface::Plugins::
+HasImageWriter( ) const
{
- return( this->m_ImageWriter->GetParameters( ) );
+ return( this->m_ImageWriter.IsNotNull( ) );
}
// -------------------------------------------------------------------------
-const cpPlugins::Interface::Plugins::
-TParameters* cpPlugins::Interface::Plugins::
-GetMeshWriterParameters( ) const
+bool cpPlugins::Interface::Plugins::
+HasMeshWriter( ) const
{
- return( this->m_MeshWriter->GetParameters( ) );
+ return( this->m_MeshWriter.IsNotNull( ) );
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-ReadImage( TImage::Pointer& image, bool exec_qt )
+std::string cpPlugins::Interface::Plugins::
+ReadImage( const std::string& fname, const std::string& parent )
{
- std::string ret = "";
+ std::vector< std::string > fnames;
+ fnames.push_back( fname );
+ return( this->ReadImage( fnames, parent ) );
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::Plugins::
+ReadImage(
+ const std::vector< std::string >& fnames, const std::string& parent
+ )
+{
+ // Check if object exists
if( this->m_ImageReader.IsNull( ) )
- ret = "Plugins: No valid image reader. Please load a valid plugin.";
+ return( "" );
- if( ret == "" )
- {
- TProcessObject::DialogResult dret = TProcessObject::DialogResult_NoModal;
- if( exec_qt )
- dret = this->m_ImageReader->ExecConfigurationDialog( this->m_Widget );
- if( dret != TProcessObject::DialogResult_Cancel )
- {
- this->BlockWidget( );
- ret = this->m_ImageReader->Update( );
- this->UnblockWidget( );
- if( ret == "" )
- {
- image = this->m_ImageReader->GetOutput< TImage >( "Output" );
- this->m_ImageReader->DisconnectOutputs( );
- this->m_ImageReader->GetParameters( )->ClearStringList( "FileNames" );
- }
- else
- image = NULL;
+ // Configure object
+ TParameters* params = this->m_ImageReader->GetParameters( );
+ params->ClearStringList( "FileNames" );
+ auto i = fnames.begin( );
+ for( ; i != fnames.end( ); ++i )
+ params->AddToStringList( "FileNames", *i );
- } // fi
+ // Execute filter
+ this->BlockWidget( );
+ std::string err = this->m_ImageReader->Update( );
+ this->UnblockWidget( );
- } // fi
+ // Get result, if any
+ if( err == "" )
+ {
+ TImage* image = this->m_ImageReader->GetOutput< TImage >( "Output" );
+ this->m_ImageReader->DisconnectOutputs( );
- // Show an error message and return
- if( ret != "" )
+ // Add newly added data
+ if( this->_InsertNewData( image, parent ) )
+ return( image->GetName( ) );
+ else
+ return( "" );
+ }
+ else
{
#ifdef cpPlugins_Interface_QT4
if( this->m_Widget != NULL )
QMessageBox::critical(
this->m_Widget,
QMessageBox::tr( "Error reading image." ),
- QMessageBox::tr( ret.c_str( ) )
+ QMessageBox::tr( err.c_str( ) )
);
+#else // cpPlugins_Interface_QT4
+ std::cerr << "Error reading image: " << err << std::endl;
#endif // cpPlugins_Interface_QT4
- return( false );
+ return( "" );
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::Plugins::
+ReadImage( const std::string& parent )
+{
+ // Check if object exists
+ if( this->m_ImageReader.IsNull( ) )
+ return( "" );
+
+ // Configure object
+ TProcessObject::DialogResult dret =
+ this->m_ImageReader->ExecConfigurationDialog( this->m_Widget );
+ if( dret == TProcessObject::DialogResult_Cancel )
+ return( "" );
+
+ // Execute filter
+ this->BlockWidget( );
+ std::string err = this->m_ImageReader->Update( );
+ this->UnblockWidget( );
+
+ // Get result, if any
+ if( err == "" )
+ {
+ TImage* image = this->m_ImageReader->GetOutput< TImage >( "Output" );
+ this->m_ImageReader->DisconnectOutputs( );
+
+ // Add newly added data
+ if( this->_InsertNewData( image, parent ) )
+ return( image->GetName( ) );
+ else
+ return( "" );
}
else
- return( true );
+ {
+#ifdef cpPlugins_Interface_QT4
+ if( this->m_Widget != NULL )
+ QMessageBox::critical(
+ this->m_Widget,
+ QMessageBox::tr( "Error reading image." ),
+ QMessageBox::tr( err.c_str( ) )
+ );
+#else // cpPlugins_Interface_QT4
+ std::cerr << "Error reading image: " << err << std::endl;
+#endif // cpPlugins_Interface_QT4
+ return( "" );
+
+ } // fi
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-ReadDicomSeries( TImage::Pointer& image )
+std::string cpPlugins::Interface::Plugins::
+ReadDicomSeries( const std::string& parent )
{
- std::string ret = "";
+ // Check if object exists
if( this->m_DicomSeriesReader.IsNull( ) )
- ret = "Plugins: No valid dicom series reader. Please load a valid plugin.";
+ return( "" );
- if( ret == "" )
- {
- TProcessObject::DialogResult dret =
- this->m_DicomSeriesReader->ExecConfigurationDialog( this->m_Widget );
- if( dret != TProcessObject::DialogResult_Cancel )
- {
- this->BlockWidget( );
- ret = this->m_DicomSeriesReader->Update( );
- this->UnblockWidget( );
- if( ret == "" )
- {
- image = this->m_DicomSeriesReader->GetOutput< TImage >( "Output" );
- this->m_DicomSeriesReader->DisconnectOutputs( );
- this->m_DicomSeriesReader->GetParameters( )->
- ClearStringList( "FileNames" );
- }
- else
- image = NULL;
+ // Configure object
+ TProcessObject::DialogResult dret =
+ this->m_DicomSeriesReader->ExecConfigurationDialog( this->m_Widget );
+ if( dret == TProcessObject::DialogResult_Cancel )
+ return( "" );
- } // fi
+ // Execute filter
+ this->BlockWidget( );
+ std::string err = this->m_DicomSeriesReader->Update( );
+ this->UnblockWidget( );
- } // fi
+ // Get result, if any
+ if( err == "" )
+ {
+ TImage* image =
+ this->m_DicomSeriesReader->GetOutput< TImage >( "Output" );
+ this->m_DicomSeriesReader->DisconnectOutputs( );
- // Show an error message and return
- if( ret != "" )
+ // Add newly added data
+ if( this->_InsertNewData( image, parent ) )
+ return( image->GetName( ) );
+ else
+ return( "" );
+ }
+ else
{
#ifdef cpPlugins_Interface_QT4
if( this->m_Widget != NULL )
QMessageBox::critical(
this->m_Widget,
- QMessageBox::tr( "Error reading dicom series." ),
- QMessageBox::tr( ret.c_str( ) )
+ QMessageBox::tr( "Error reading image." ),
+ QMessageBox::tr( err.c_str( ) )
);
+#else // cpPlugins_Interface_QT4
+ std::cerr << "Error reading image: " << err << std::endl;
#endif // cpPlugins_Interface_QT4
- return( false );
+ return( "" );
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::Plugins::
+ReadMesh( const std::string& fname, const std::string& parent )
+{
+ // Check if object exists
+ if( this->m_MeshReader.IsNull( ) )
+ return( "" );
+
+ // Configure object
+ TParameters* params = this->m_MeshReader->GetParameters( );
+ params->SetString( "FileName", fname );
+
+ // Execute filter
+ this->BlockWidget( );
+ std::string err = this->m_MeshReader->Update( );
+ this->UnblockWidget( );
+
+ // Get result, if any
+ if( err == "" )
+ {
+ TMesh* mesh = this->m_MeshReader->GetOutput< TMesh >( "Output" );
+ this->m_MeshReader->DisconnectOutputs( );
+
+ // Add newly added data
+ if( this->_InsertNewData( mesh, parent ) )
+ return( mesh->GetName( ) );
+ else
+ return( "" );
}
else
- return( true );
+ {
+#ifdef cpPlugins_Interface_QT4
+ if( this->m_Widget != NULL )
+ QMessageBox::critical(
+ this->m_Widget,
+ QMessageBox::tr( "Error reading mesh." ),
+ QMessageBox::tr( err.c_str( ) )
+ );
+#else // cpPlugins_Interface_QT4
+ std::cerr << "Error reading mesh: " << err << std::endl;
+#endif // cpPlugins_Interface_QT4
+ return( "" );
+
+ } // fi
}
// -------------------------------------------------------------------------
-bool cpPlugins::Interface::Plugins::
-ReadMesh( TMesh::Pointer& mesh, bool exec_qt )
+std::string cpPlugins::Interface::Plugins::
+ReadMesh( const std::string& parent )
{
- std::string ret = "";
+ // Check if object exists
if( this->m_MeshReader.IsNull( ) )
- ret = "Plugins: No valid mesh reader. Please load a valid plugin.";
+ return( "" );
- if( ret == "" )
+ // Configure object
+ TProcessObject::DialogResult dret =
+ this->m_MeshReader->ExecConfigurationDialog( this->m_Widget );
+ if( dret == TProcessObject::DialogResult_Cancel )
+ return( "" );
+
+ // Execute filter
+ this->BlockWidget( );
+ std::string err = this->m_MeshReader->Update( );
+ this->UnblockWidget( );
+
+ // Get result, if any
+ if( err == "" )
{
- TProcessObject::DialogResult dret = TProcessObject::DialogResult_NoModal;
- if( exec_qt )
- dret = this->m_MeshReader->ExecConfigurationDialog( this->m_Widget );
- if( dret != TProcessObject::DialogResult_Cancel )
- {
- this->BlockWidget( );
- ret = this->m_MeshReader->Update( );
- this->UnblockWidget( );
- if( ret == "" )
- {
- mesh = this->m_MeshReader->GetOutput< TMesh >( "Output" );
- this->m_MeshReader->DisconnectOutputs( );
- }
- else
- mesh = NULL;
+ TMesh* mesh = this->m_MeshReader->GetOutput< TMesh >( "Output" );
+ this->m_MeshReader->DisconnectOutputs( );
- } // fi
+ // Add newly added data
+ if( this->_InsertNewData( mesh, parent ) )
+ return( mesh->GetName( ) );
+ else
+ return( "" );
+ }
+ else
+ {
+#ifdef cpPlugins_Interface_QT4
+ if( this->m_Widget != NULL )
+ QMessageBox::critical(
+ this->m_Widget,
+ QMessageBox::tr( "Error reading mesh." ),
+ QMessageBox::tr( err.c_str( ) )
+ );
+#else // cpPlugins_Interface_QT4
+ std::cerr << "Error reading mesh: " << err << std::endl;
+#endif // cpPlugins_Interface_QT4
+ return( "" );
} // fi
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+WriteImage( const std::string& fname, const std::string& name )
+{
+ // Check if objects exist
+ if( this->m_ImageWriter.IsNull( ) )
+ return( false );
+ TImage* image = this->GetImage( name );
+ if( image == NULL )
+ return( false );
- // Show an error message and return
- if( ret != "" )
+ // Configure writer
+ this->m_ImageWriter->GetParameters( )->SetString( "FileName", fname );
+ this->m_ImageWriter->SetInput( "Input", image );
+
+ // Execute filter
+ this->BlockWidget( );
+ std::string err = this->m_ImageWriter->Update( );
+ this->UnblockWidget( );
+
+ // Get result, if any
+ if( err != "" )
{
#ifdef cpPlugins_Interface_QT4
if( this->m_Widget != NULL )
QMessageBox::critical(
this->m_Widget,
- QMessageBox::tr( "Error reading image." ),
- QMessageBox::tr( ret.c_str( ) )
+ QMessageBox::tr( "Error reading mesh." ),
+ QMessageBox::tr( err.c_str( ) )
);
+#else // cpPlugins_Interface_QT4
+ std::cerr << "Error reading mesh: " << err << std::endl;
#endif // cpPlugins_Interface_QT4
return( false );
}
// -------------------------------------------------------------------------
bool cpPlugins::Interface::Plugins::
-WriteImage( TImage* image, bool exec_qt )
+WriteImage( const std::string& name )
{
- std::string ret = "";
+ // Check if objects exist
if( this->m_ImageWriter.IsNull( ) )
- ret = "Plugins: No valid image writer. Please load a valid plugin.";
-
- if( ret == "" )
- {
- TProcessObject::DialogResult dret = TProcessObject::DialogResult_NoModal;
- if( exec_qt )
- dret = this->m_ImageWriter->ExecConfigurationDialog( this->m_Widget );
- if( dret != TProcessObject::DialogResult_Cancel )
- {
- this->m_ImageWriter->SetInput( "Input", image );
- this->BlockWidget( );
- ret = this->m_ImageWriter->Update( );
- this->UnblockWidget( );
+ return( false );
+ TImage* image = this->GetImage( name );
+ if( image == NULL )
+ return( false );
- } // fi
+ // Configure writer
+ TProcessObject::DialogResult dret =
+ this->m_ImageWriter->ExecConfigurationDialog( this->m_Widget );
+ if( dret == TProcessObject::DialogResult_Cancel )
+ return( "" );
+ this->m_ImageWriter->SetInput( "Input", image );
- } // fi
+ // Execute filter
+ this->BlockWidget( );
+ std::string err = this->m_ImageWriter->Update( );
+ this->UnblockWidget( );
- // Show an error message and return
- if( ret != "" )
+ // Get result, if any
+ if( err != "" )
{
#ifdef cpPlugins_Interface_QT4
if( this->m_Widget != NULL )
QMessageBox::critical(
this->m_Widget,
- QMessageBox::tr( "Error reading image." ),
- QMessageBox::tr( ret.c_str( ) )
+ QMessageBox::tr( "Error reading mesh." ),
+ QMessageBox::tr( err.c_str( ) )
);
+#else // cpPlugins_Interface_QT4
+ std::cerr << "Error reading mesh: " << err << std::endl;
#endif // cpPlugins_Interface_QT4
return( false );
}
// -------------------------------------------------------------------------
bool cpPlugins::Interface::Plugins::
-WriteMesh( TMesh* mesh, bool exec_qt )
+WriteMesh( const std::string& fname, const std::string& name )
{
- std::string ret = "";
+ // Check if objects exist
if( this->m_MeshWriter.IsNull( ) )
- ret = "Plugins: No valid mesh writer. Please load a valid plugin.";
+ return( false );
+ TMesh* mesh = this->GetMesh( name );
+ if( mesh == NULL )
+ return( false );
- if( ret == "" )
+ // Configure writer
+ this->m_MeshWriter->GetParameters( )->SetString( "FileName", fname );
+ this->m_MeshWriter->SetInput( "Input", mesh );
+
+ // Execute filter
+ this->BlockWidget( );
+ std::string err = this->m_MeshWriter->Update( );
+ this->UnblockWidget( );
+
+ // Get result, if any
+ if( err != "" )
{
- TProcessObject::DialogResult dret = TProcessObject::DialogResult_NoModal;
- if( exec_qt )
- dret = this->m_MeshWriter->ExecConfigurationDialog( this->m_Widget );
- if( dret != TProcessObject::DialogResult_Cancel )
- {
- this->m_MeshWriter->SetInput( "Input", mesh );
- this->BlockWidget( );
- ret = this->m_MeshWriter->Update( );
- this->UnblockWidget( );
+#ifdef cpPlugins_Interface_QT4
+ if( this->m_Widget != NULL )
+ QMessageBox::critical(
+ this->m_Widget,
+ QMessageBox::tr( "Error reading mesh." ),
+ QMessageBox::tr( err.c_str( ) )
+ );
+#else // cpPlugins_Interface_QT4
+ std::cerr << "Error reading mesh: " << err << std::endl;
+#endif // cpPlugins_Interface_QT4
+ return( false );
+ }
+ else
+ return( true );
+}
- } // fi
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+WriteMesh( const std::string& name )
+{
+ // Check if objects exist
+ if( this->m_MeshWriter.IsNull( ) )
+ return( false );
+ TMesh* mesh = this->GetMesh( name );
+ if( mesh == NULL )
+ return( false );
- } // fi
+ // Configure writer
+ TProcessObject::DialogResult dret =
+ this->m_MeshWriter->ExecConfigurationDialog( this->m_Widget );
+ if( dret == TProcessObject::DialogResult_Cancel )
+ return( "" );
+ this->m_MeshWriter->SetInput( "Input", mesh );
+
+ // Execute filter
+ this->BlockWidget( );
+ std::string err = this->m_MeshWriter->Update( );
+ this->UnblockWidget( );
- // Show an error message and return
- if( ret != "" )
+ // Get result, if any
+ if( err != "" )
{
#ifdef cpPlugins_Interface_QT4
if( this->m_Widget != NULL )
QMessageBox::critical(
this->m_Widget,
- QMessageBox::tr( "Error reading image." ),
- QMessageBox::tr( ret.c_str( ) )
+ QMessageBox::tr( "Error reading mesh." ),
+ QMessageBox::tr( err.c_str( ) )
);
+#else // cpPlugins_Interface_QT4
+ std::cerr << "Error reading mesh: " << err << std::endl;
#endif // cpPlugins_Interface_QT4
return( false );
}
return( true );
}
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+ClearDataObjects( )
+{
+ this->m_Objects.clear( );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+DeleteDataObject( const std::string& name )
+{
+ auto i = this->m_Objects.find( name );
+ if( i != this->m_Objects.end( ) )
+ {
+ this->m_Objects.erase( i );
+
+ // Get children
+ std::vector< std::string > children;
+ for( i = this->m_Objects.begin( ); i != this->m_Objects.end( ); ++i )
+ if( i->second.first == name )
+ children.push_back( i->first );
+
+ // Erase children
+ auto c = children.begin( );
+ for( ; c != children.end( ); ++c )
+ this->DeleteDataObject( *c );
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::Plugins::
+GetParent( const std::string& name ) const
+{
+ auto i = this->m_Objects.find( name );
+ if( i != this->m_Objects.end( ) )
+ return( i->second.first );
+ else
+ return( "" );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Plugins::
+TTree& cpPlugins::Interface::Plugins::
+GetDataObjects( ) const
+{
+ return( this->m_Objects );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Plugins::
+TDataObject* cpPlugins::Interface::Plugins::
+GetDataObject( const std::string& name )
+{
+ auto i = this->m_Objects.find( name );
+ if( i != this->m_Objects.end( ) )
+ return( dynamic_cast< TDataObject* >( i->second.second.GetPointer( ) ) );
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Plugins::
+TDataObject* cpPlugins::Interface::Plugins::
+GetDataObject( const std::string& name ) const
+{
+ auto i = this->m_Objects.find( name );
+ if( i != this->m_Objects.end( ) )
+ return(
+ dynamic_cast< const TDataObject* >( i->second.second.GetPointer( ) )
+ );
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Plugins::
+TImage* cpPlugins::Interface::Plugins::
+GetImage( const std::string& name )
+{
+ auto i = this->m_Objects.find( name );
+ if( i != this->m_Objects.end( ) )
+ return( dynamic_cast< TImage* >( i->second.second.GetPointer( ) ) );
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Plugins::
+TImage* cpPlugins::Interface::Plugins::
+GetImage( const std::string& name ) const
+{
+ auto i = this->m_Objects.find( name );
+ if( i != this->m_Objects.end( ) )
+ return( dynamic_cast< const TImage* >( i->second.second.GetPointer( ) ) );
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Plugins::
+TMesh* cpPlugins::Interface::Plugins::
+GetMesh( const std::string& name )
+{
+ auto i = this->m_Objects.find( name );
+ if( i != this->m_Objects.end( ) )
+ return( dynamic_cast< TMesh* >( i->second.second.GetPointer( ) ) );
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Plugins::
+TMesh* cpPlugins::Interface::Plugins::
+GetMesh( const std::string& name ) const
+{
+ auto i = this->m_Objects.find( name );
+ if( i != this->m_Objects.end( ) )
+ return( dynamic_cast< const TMesh* >( i->second.second.GetPointer( ) ) );
+ else
+ return( NULL );
+}
+
// -------------------------------------------------------------------------
bool cpPlugins::Interface::Plugins::
-CreateFilter( TProcessObject::Pointer& filter, const std::string& name )
+ActivateFilter( const std::string& name )
{
- filter = this->m_Interface.CreateProcessObject( name );
- return( filter.IsNotNull( ) );
+ this->m_ActiveFilter = this->m_Interface.CreateProcessObject( name );
+ if( this->m_ActiveFilter.IsNotNull( ) )
+ {
+ this->m_ActiveFilter->SetPlugins( this );
+ this->m_ActiveFilterOutputs.clear( );
+ auto i = this->m_Interactors.begin( );
+ for( ; i != this->m_Interactors.end( ); ++i )
+ this->m_ActiveFilter->AddInteractor( *i );
+ return( true );
+ }
+ else
+ return( false );
}
// -------------------------------------------------------------------------
void cpPlugins::Interface::Plugins::
-_Update( )
+DeactivateFilter( )
+{
+ this->m_ActiveFilter = NULL;
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+HasActiveFilter( ) const
+{
+ return( this->m_ActiveFilter.IsNotNull( ) );
+}
+
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+IsActiveFilterInteractive( ) const
+{
+ if( this->m_ActiveFilter.IsNotNull( ) )
+ return( this->m_ActiveFilter->IsInteractive( ) );
+ else
+ return( false );
+}
+
+// -------------------------------------------------------------------------
+unsigned int cpPlugins::Interface::Plugins::
+GetNumberOfInputsInActiveFilter( ) const
+{
+ if( this->m_ActiveFilter.IsNotNull( ) )
+ return( this->m_ActiveFilter->GetNumberOfInputs( ) );
+ else
+ return( 0 );
+}
+
+// -------------------------------------------------------------------------
+unsigned int cpPlugins::Interface::Plugins::
+GetNumberOfOutputsInActiveFilter( ) const
+{
+ if( this->m_ActiveFilter.IsNotNull( ) )
+ return( this->m_ActiveFilter->GetNumberOfOutputs( ) );
+ else
+ return( 0 );
+}
+
+// -------------------------------------------------------------------------
+std::vector< std::string > cpPlugins::Interface::Plugins::
+GetActiveFilterInputsNames( ) const
+{
+ if( this->m_ActiveFilter.IsNotNull( ) )
+ return( this->m_ActiveFilter->GetInputsNames( ) );
+ else
+ return( std::vector< std::string >( ) );
+}
+
+// -------------------------------------------------------------------------
+std::vector< std::string > cpPlugins::Interface::Plugins::
+GetActiveFilterOutputsNames( ) const
+{
+ if( this->m_ActiveFilter.IsNotNull( ) )
+ return( this->m_ActiveFilter->GetOutputsNames( ) );
+ else
+ return( std::vector< std::string >( ) );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+ConnectInputInActiveFilter(
+ const std::string& object_name, const std::string& input
+ )
+{
+ if( this->m_ActiveFilter.IsNotNull( ) )
+ {
+ TDataObject* dobj = this->GetDataObject( object_name );
+ if( dobj != NULL )
+ this->m_ActiveFilter->SetInput( input, dobj );
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+SetOutputNameInActiveFilter(
+ const std::string& new_name, const std::string& output
+ )
+{
+ this->m_ActiveFilterOutputs[ output ] = new_name;
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Plugins::
+TParameters* cpPlugins::Interface::Plugins::
+GetActiveFilterParameters( )
+{
+ if( this->m_ActiveFilter.IsNotNull( ) )
+ return( this->m_ActiveFilter->GetParameters( ) );
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Plugins::
+TParameters* cpPlugins::Interface::Plugins::
+GetActiveFilterParameters( ) const
+{
+ if( this->m_ActiveFilter.IsNotNull( ) )
+ return( this->m_ActiveFilter->GetParameters( ) );
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Plugins::
+TProcessObject::DialogResult cpPlugins::Interface::Plugins::
+ConfigureActiveFilter( )
+{
+ if( this->m_ActiveFilter.IsNotNull( ) )
+ return( this->m_ActiveFilter->ExecConfigurationDialog( this->m_Widget ) );
+ else
+ return( TProcessObject::DialogResult_Cancel );
+}
+
+// -------------------------------------------------------------------------
+std::string cpPlugins::Interface::Plugins::
+UpdateActiveFilter( std::vector< std::string >& outputs )
+{
+ // Execute filter
+ this->BlockWidget( );
+ std::string err = this->m_ActiveFilter->Update( );
+ this->UnblockWidget( );
+
+ // Associate outputs
+ outputs.clear( );
+ if( err == "" )
+ {
+ std::string parent = "";
+ if( this->GetNumberOfInputsInActiveFilter( ) > 0 )
+ {
+ std::string input = this->m_ActiveFilter->GetInputsNames( )[ 0 ];
+ parent =
+ this->m_ActiveFilter->GetInput< TDataObject >( input )->GetName( );
+
+ } // fi
+
+ auto i = this->m_ActiveFilterOutputs.begin( );
+ for( ; i != this->m_ActiveFilterOutputs.end( ); ++i )
+ {
+ TDataObject* out =
+ this->m_ActiveFilter->GetOutput< TDataObject >( i->first );
+ out->SetName( i->second );
+ outputs.push_back( out->GetName( ) );
+ this->_InsertNewData( out, parent );
+
+ } // rof
+
+ } // fi
+ return( err );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::Plugins::
+_UpdateLoadedPluginsInformation( )
{
typedef TInterface::TClasses _C;
} // rof
}
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Plugins::
+_InsertNewData( TDataObject* dobj, const std::string& parent )
+{
+ std::string name = dobj->GetName( );
+ auto i = this->m_Objects.find( name );
+ bool ret = true;
+ if( i == this->m_Objects.end( ) )
+ {
+ if( parent != "" )
+ {
+ auto j = this->m_Objects.find( parent );
+ if( j != this->m_Objects.end( ) )
+ this->m_Objects[ name ] = TTreeNode( parent, dobj );
+ else
+ ret = false;
+ }
+ else
+ this->m_Objects[ name ] = TTreeNode( "", dobj );
+ }
+ else
+ i->second.second = dobj;
+
+ if( !ret )
+ {
+#ifdef cpPlugins_Interface_QT4
+ if( this->m_Widget != NULL )
+ QMessageBox::critical(
+ this->m_Widget,
+ QMessageBox::tr( "Error inserting data." ),
+ QMessageBox::tr( "Given parent does not exists." )
+ );
+#else // cpPlugins_Interface_QT4
+ std::cerr
+ << "Error inserting data: Given parent does not exists."
+ << std::endl;
+#endif // cpPlugins_Interface_QT4
+ } // fi
+ return( ret );
+}
+
// eof - $RCSfile$