]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/Interface/BaseMPRWindow.cxx
Widget integration (step 6/6): Interactive architecture finished. Needs to be tested...
[cpPlugins.git] / lib / cpPlugins / Interface / BaseMPRWindow.cxx
index b43975547a21ccaca3bf3efcfd693dafceda39c8..d55632c6d1dde34e34e813d27b5d520e0b1d6324 100644 (file)
@@ -158,17 +158,13 @@ LoadPlugins( )
 }
 
 // -------------------------------------------------------------------------
-bool cpPlugins::Interface::BaseMPRWindow::
+std::string cpPlugins::Interface::BaseMPRWindow::
 LoadImage( )
 {
   std::string msg = "";
-  bool ret = true;
+  std::string ret = "";
   if( this->m_ImageReader.IsNull( ) )
-  {
     msg = "No valid image reader. Please load a valid plugin file.";
-    ret = false;
-
-  } // fi
 
   if( this->m_ImageReader->ExecConfigurationDialog( this ) )
   {
@@ -176,13 +172,16 @@ LoadImage( )
     msg = this->m_ImageReader->Update( );
     if( msg == "" )
     {
-      this->m_Images.push_back(
-        this->m_ImageReader->GetOutput< TImage >( 0 )
-        );
+      TImage::Pointer image =
+        this->m_ImageReader->GetOutput< TImage >( "Output" );
+      if( this->m_Images.size( ) == 0 )
+        ret = image->GetName( );
+      else
+        ret = "Segmentation";
+      this->m_Images[ ret ] = image;
       this->m_ImageReader->DisconnectOutputs( );
       this->m_ImageReader->GetParameters( )->ClearStringList( "FileNames" );
-      vtkImageData* vtk_id =
-        this->m_Images.rbegin( )->GetPointer( )->GetVTK< vtkImageData >( );
+      vtkImageData* vtk_id = image->GetVTK< vtkImageData >( );
       if( vtk_id != NULL )
       {
         this->m_MPRObjects->AddImage( vtk_id );
@@ -195,7 +194,7 @@ LoadImage( )
         msg = "Read image does not have a valid VTK converter.";
     }
     else
-      ret = false;
+      ret = "";
 
   } // fi
 
@@ -209,33 +208,67 @@ LoadImage( )
 }
 
 // -------------------------------------------------------------------------
-bool cpPlugins::Interface::BaseMPRWindow::
+std::string cpPlugins::Interface::BaseMPRWindow::
 LoadMesh( )
 {
-  return( false );
+  return( "" );
 }
 
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::BaseMPRWindow::
-ExecuteFilter( const std::string& name, int input_id, int output_id )
+ExecuteFilter(
+  const std::string& name,
+  const std::string& input_id,
+  const std::string& output_id
+  )
 {
   TProcessObject::Pointer filter =
     this->m_Interface.CreateProcessObject( name );
   std::string category = filter->GetClassCategory( );
   if( category == "ImageToBinaryImageFilter" )
   {
-    if( input_id < this->m_Images.size( ) )
+    TImages::iterator iIt = this->m_Images.find( input_id );
+    if( iIt != this->m_Images.end( ) )
     {
-      filter->SetInput( 0, this->m_Images[ input_id ] );
+      filter->SetInput( "Input", this->m_Images[ input_id ] );
       bool dlg_ok = filter->ExecConfigurationDialog( NULL );
       if( !dlg_ok )
         return;
 
+      std::string err = filter->Update( );
+      std::cout << "ERR: " << err << std::endl;
+      if( err == "" )
+      {
+        this->m_Images[ "Segmentation" ] =
+          filter->GetOutput< TImage >( "Output" );
+        filter->DisconnectOutputs( );
+
+        vtkImageData* vtk_id =
+          this->m_Images[ "Segmentation" ]->GetVTK< vtkImageData >( );
+        if( vtk_id != NULL )
+          this->m_MPRObjects->AddImage( vtk_id );
+      }
+      else
+        QMessageBox::critical(
+          this, tr( "Error with plugin" ), tr( err.c_str( ) )
+          );
+
     } // fi
 
   } // fi
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::BaseMPRWindow::
+AddImage( const std::string& name, TImage* image )
+{
+  this->m_Images[ name ] = image;
+  vtkImageData* vtk_id =
+    this->m_Images[ name ]->GetVTK< vtkImageData >( );
+  if( vtk_id != NULL )
+    this->m_MPRObjects->AddImage( vtk_id );
+}
+
 // -------------------------------------------------------------------------
 void cpPlugins::Interface::BaseMPRWindow::
 ClearAll( )