]> Creatis software - cpPlugins.git/blobdiff - appli/ImageMPR/ImageMPR.cxx
Major refactoring: API-HCI bug corrected.
[cpPlugins.git] / appli / ImageMPR / ImageMPR.cxx
index 71b8e9d765096f9248858b28392ac50575af6198..931ff3ae7579e1a42bab0ed58e5cf3df80a44d0d 100644 (file)
@@ -8,9 +8,11 @@
 #include <QMessageBox>
 
 #ifdef _WIN32
+#  define PLUGIN_PREFIX ""
 #  define PLUGIN_EXT "dll"
 #  define PLUGIN_REGEX "Plugins file (*.dll);;All files (*)"
 #else
+#  define PLUGIN_PREFIX "lib"
 #  define PLUGIN_EXT "so"
 #  define PLUGIN_REGEX "Plugins file (*.so);;All files (*)"
 #endif // _WIN32
@@ -46,7 +48,11 @@ ImageMPR::ImageMPR( QWidget* parent )
     );
 
   // Start: load all disponible plugins
-  this->_triggered_actionOpenPlugins( );
+  this->_LoadPlugins(
+    std::string( PLUGIN_PREFIX ) +
+    std::string( "cpPlugins." ) +
+    std::string( PLUGIN_EXT )
+    );
 }
 
 // -------------------------------------------------------------------------
@@ -61,6 +67,22 @@ ImageMPR::
   delete this->m_MPR;
 }
 
+// -------------------------------------------------------------------------
+bool ImageMPR::
+_LoadPlugins( const std::string& filename )
+{
+  this->m_Plugins.UnloadAll( );
+  if( !( this->m_Plugins.Load( filename ) ) )
+  {
+    this->m_Plugins.UnloadAll( );
+    return( false );
+
+  } // fi
+  this->m_BaseClasses[ "ImageReader" ] = "cpPlugins::ImageReader";
+  this->m_BaseClasses[ "MeshReader" ] = "cpPlugins::MeshReader";
+  return( true );
+}
+
 // -------------------------------------------------------------------------
 void ImageMPR::
 _triggered_actionOpenPlugins( )
@@ -75,23 +97,12 @@ _triggered_actionOpenPlugins( )
     return;
   
   std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
-  this->m_Plugins.UnloadAll( );
-  if( !( this->m_Plugins.Load( fname ) ) )
-  {
+  if( !( _LoadPlugins( fname ) ) )
     QMessageBox::critical(
       this,
       tr( "Ignoring plugin" ),
       tr( fname.c_str( ) )
       );
-    this->m_Plugins.UnloadAll( );
-    return;
-
-  } // fi
-
-  this->m_BaseClasses[ "ImageReader" ] =
-    "cpPlugins::Plugins::ImageReader";
-  this->m_BaseClasses[ "PolyDataReader" ] =
-    "cpPlugins::Plugins::PolyDataReader";
 }
 
 // -------------------------------------------------------------------------
@@ -112,7 +123,7 @@ _triggered_actionOpenInputImage( )
   this->m_InputImage = NULL;
 
   // Get a reader from plugins
-  TPlugin::Pointer reader =
+  TPluginFilter::Pointer reader =
     this->m_Plugins.CreateProcessObject(
       this->m_BaseClasses[ "ImageReader" ]
       );
@@ -125,11 +136,6 @@ _triggered_actionOpenInputImage( )
   QStringList::const_iterator qIt = q_fnames.begin( );
   for( ; qIt != q_fnames.end( ); ++qIt )
     reader_params.AddValueToStringList( "FileNames", qIt->toStdString( ) );
-
-  // Other parameters
-  reader_params.SetValueAsString( "PixelType", "short" );
-  reader_params.SetValueAsUint( "ImageDimension", 3 );
-  reader_params.SetValueAsUint( "IsColorImage", 0 );
   reader->SetParameters( reader_params );
 
   // Execute and get error message, if any
@@ -167,12 +173,12 @@ _triggered_actionOpenInputPolyData( )
   
   std::string fname = dialog.selectedFiles( ).at( 0 ).toStdString( );
 
-  this->m_InputPolyData = NULL;
+  this->m_InputMesh = NULL;
 
   // Get a reader from plugins
-  TPlugin::Pointer reader =
+  TPluginFilter::Pointer reader =
     this->m_Plugins.CreateProcessObject(
-      this->m_BaseClasses[ "PolyDataReader" ]
+      this->m_BaseClasses[ "MeshReader" ]
       );
 
   // Configure plugin
@@ -186,13 +192,16 @@ _triggered_actionOpenInputPolyData( )
   // Assign fresh image, if any
   if( err == "" )
   {
-    this->m_InputPolyData =
-      dynamic_cast< TPluginPolyData* >( reader->GetOutput( 0 ) );
+    this->m_InputMesh =
+      dynamic_cast< TPluginMesh* >( reader->GetOutput( 0 ) );
     reader->DisconnectOutputs( );
-    if( this->m_InputPolyData.IsNotNull( ) )
+    if( this->m_InputMesh.IsNotNull( ) )
     {
-      this->m_InputPolyData->GetActor( )->GetProperty( )->SetColor( 1, 0, 1 );
-      this->m_MPR->Add3DActor( this->m_InputPolyData->GetActor( ) );
+      this->m_InputMeshMapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
+      this->m_InputMeshMapper->SetInputData( this->m_InputMesh->GetVTKPolyData( ) );
+      this->m_InputMeshActor = vtkSmartPointer< vtkActor >::New( );
+      this->m_InputMeshActor->SetMapper( this->m_InputMeshMapper );
+      this->m_MPR->Add3DActor( this->m_InputMeshActor );
 
     } // fi
   }