]> Creatis software - cpPlugins.git/blobdiff - appli/ImageMPR/ImageMPR.cxx
Tree data updated.
[cpPlugins.git] / appli / ImageMPR / ImageMPR.cxx
index a83a5d6b7898c3651f289ccd03eaa3aeb98ec877..47c3622e4e7430af2663940ea6a32de22d1e7de2 100644 (file)
@@ -15,8 +15,7 @@ ImageMPR::
 ImageMPR( QWidget* parent )
   : QMainWindow( parent ),
     m_UI( new Ui::ImageMPR ),
-    m_Plugins( new TPlugins ),
-    m_MainImage( NULL )
+    m_Plugins( new TPlugins )
 {
   this->m_UI->setupUi( this );
   this->m_Plugins->SetWidget( this );
@@ -53,11 +52,19 @@ ImageMPR::
 void ImageMPR::
 _aOpenImage( )
 {
-  if( this->m_MainImage.IsNotNull( ) )
+  // Clear all, since we are loading the main image
+  if( this->m_Objects.size( ) > 0 )
+  {
     this->m_UI->MPR->ClearAll( );
-  if( this->m_Plugins->ReadImage( this->m_MainImage, true ) )
+    this->m_Objects.clear( );
+
+  } // fi
+
+  // Read and show image, if possible
+  TPlugins::TImage::Pointer image;
+  if( this->m_Plugins->ReadImage( image, true ) )
   {
-    vtkImageData* vimage = this->m_MainImage->GetVTK< vtkImageData >( );
+    vtkImageData* vimage = image->GetVTK< vtkImageData >( );
     if( vimage == NULL )
       QMessageBox::critical(
         this,
@@ -67,7 +74,11 @@ _aOpenImage( )
           )
         );
     else
-      this->m_UI->MPR->ShowImage( vimage );
+      this->m_UI->MPR->ShowImage( vimage, image->GetName( ) );
+
+    // Keep a track on a local data tree
+    this->m_Objects[ image->GetName( ) ] =
+      TTreeNode( "", image.GetPointer( ) );
 
   } // fi
 }
@@ -76,11 +87,19 @@ _aOpenImage( )
 void ImageMPR::
 _aOpenDICOMSeries( )
 {
-  if( this->m_MainImage.IsNotNull( ) )
+  // Clear all, since we are loading the main image
+  if( this->m_Objects.size( ) > 0 )
+  {
     this->m_UI->MPR->ClearAll( );
-  if( this->m_Plugins->ReadDicomSeries( this->m_MainImage ) )
+    this->m_Objects.clear( );
+
+  } // fi
+
+  // Read and show image, if possible
+  TPlugins::TImage::Pointer image;
+  if( this->m_Plugins->ReadDicomSeries( image ) )
   {
-    vtkImageData* vimage = this->m_MainImage->GetVTK< vtkImageData >( );
+    vtkImageData* vimage = image->GetVTK< vtkImageData >( );
     if( vimage == NULL )
       QMessageBox::critical(
         this,
@@ -90,7 +109,11 @@ _aOpenDICOMSeries( )
           )
         );
     else
-      this->m_UI->MPR->ShowImage( vimage );
+      this->m_UI->MPR->ShowImage( vimage, image->GetName( ) );
+
+    // Keep a track on a local data tree
+    this->m_Objects[ image->GetName( ) ] =
+      TTreeNode( "", image.GetPointer( ) );
 
   } // fi
 }
@@ -115,8 +138,10 @@ _aOpenPolyData( )
 void ImageMPR::
 _aSaveImage( )
 {
-  if( this->m_MainImage.IsNotNull( ) )
+  /*
+    if( this->m_MainImage.IsNotNull( ) )
     this->m_Plugins->WriteImage( this->m_MainImage, true );
+  */
 }
 
 // -------------------------------------------------------------------------
@@ -163,6 +188,13 @@ _aShowPlugins( )
 void ImageMPR::
 _execPlugin( )
 {
+  /*
+  typedef std::map< std::string, TPlugins::TImage::Pointer > _TImages;
+  typedef std::map< std::string, TPlugins::TMesh::Pointer >  _TMeshes;
+
+  // Get selected data
+  // std::string data_name = this->m_UI->MPR->GetSelectedData( );
+
   // Get filter name
   QAction* action = dynamic_cast< QAction* >( this->sender( ) );
   if( action == NULL )
@@ -170,40 +202,124 @@ _execPlugin( )
   QMenu* menu = dynamic_cast< QMenu* >( action->parentWidget( ) );
   if( menu == NULL )
     return;
-  std::string cate = menu->title( ).toStdString( );
-  std::string name = action->text( ).toStdString( );
-  std::string err = "";
+  std::string filter_cate = menu->title( ).toStdString( );
+  std::string filter_name = action->text( ).toStdString( );
 
+  // Create filter
   TPlugins::TProcessObject::Pointer filter;
-  if( this->m_Plugins->CreateFilter( filter, name ) )
+  if( !( this->m_Plugins->CreateFilter( filter, filter_name ) ) )
+  {
+    QMessageBox::critical(
+      this,
+      tr( "Error creating filter" ),
+      tr( (
+            std::string( "No valid filter \"" ) +
+            filter_name +
+            std::string( "\"defined." )
+            ).c_str( ) )
+      );
+    return;
+
+  } // fi
+
+  // Assign inputs
+  std::vector< std::string > inputs_names = filter->GetInputsNames( );
+  if( inputs_names.size( ) == 1 )
+  {
+       std::string data_name = this->m_UI->MPR->GetSelectedData( );
+       _TImages::iterator iIt = this->m_Images.find( data_name );
+       _TImages::iterator mIt = this->m_Meshes.find( data_name );
+       filter->SetInput( inputs_names[ 0 ]);
+  }
+  else if( inputs_names.size( ) > 1 )
+  {
+  } // fi
+
+  // Get outputs
+  std::vector< std::string > outputs_names = filter->GetOutputsNames( );
+  */
+
+  /*
+
+  // Choose inputs
+  if( filter_cate == "ImageToMeshFilter" )
   {
-    if( cate == "ImageToMeshFilter" )
+    // Check inputs
+    _TImages::iterator iIt = this->m_Images.find( data_name );
+    if( iIt == this->m_Images.end( ) )
     {
-      if( filter->ExecConfigurationDialog( this ) )
-      {
-        filter->SetInput( "Input", this->m_MainImage );
-        this->_Block( );
-        err = filter->Update( );
-        this->_Unblock( );
-        TPlugins::TMesh::Pointer mesh =
-          filter->GetOutput< TPlugins::TMesh >( "Output" );
-        this->m_Meshes.push_back( mesh );
-        mesh->CreateVTKActor( );
-        vtkActor* actor = mesh->GetVTKActor( );
-        if( actor != NULL )
-          this->m_UI->MPR->Add3DActor( actor );
+      QMessageBox::critical(
+        this,
+        tr( "Error creating filter" ),
+        tr( "No valid input selected." )
+        );
+      return;
 
-      } // fi
+    } // fi
+
+    // Execute configuration dialog
+    if( !( filter->ExecConfigurationDialog( this ) ) )
+      return;
+
+    // Execute filter
+    filter->SetInput( "Input", iIt->second );
+    this->_Block( );
+    std::string filter_err = filter->Update( );
+    this->_Unblock( );
+    if( filter_err != "" )
+    {
+      QMessageBox::critical(
+        this,
+        tr( "Error executing" ),
+        tr( filter_err.c_str( ) )
+        );
+      return;
 
     } // fi
-  }
-  else
-    QMessageBox::critical(
-      this,
-      tr( "Error creating filter" ),
-      tr( "No valid filter defined." )
+
+    // Keep and show results
+    TPlugins::TMesh::Pointer mesh =
+      filter->GetOutput< TPlugins::TMesh >( "Output" );
+    this->m_Meshes[ filter_name ] = mesh;
+    this->_Block( );
+    this->m_UI->MPR->ShowMesh(
+      mesh->GetVTK< vtkPolyData >( ),
+      filter_name,
+      data_name
       );
+    this->_Unblock( );
 
+  } // fi
+  */
+
+  /*
+    if( this->m_Plugins->CreateFilter( filter, name ) )
+    {
+    if( filter->ExecConfigurationDialog( this ) )
+    {
+    filter->SetInput( "Input", this->m_MainImage );
+    this->_Block( );
+    err = filter->Update( );
+    this->_Unblock( );
+    TPlugins::TMesh::Pointer mesh =
+    filter->GetOutput< TPlugins::TMesh >( "Output" );
+    this->m_Meshes.push_back( mesh );
+    mesh->CreateVTKActor( );
+    vtkActor* actor = mesh->GetVTKActor( );
+    if( actor != NULL )
+    this->m_UI->MPR->Add3DActor( actor );
+
+    } // fi
+    
+    } // fi
+    }
+    else
+    QMessageBox::critical(
+    this,
+    tr( "Error creating filter" ),
+    tr( "No valid filter defined." )
+    );
+  */
   /*
     if( name == "cpPlugins::BasicFilters::FloodFillImageFilter" )
     {