]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 9 Nov 2015 22:53:44 +0000 (17:53 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Mon, 9 Nov 2015 22:53:44 +0000 (17:53 -0500)
13 files changed:
appli/ImageMPR/ImageMPR.cxx
appli/ImageMPR/ImageMPR.h
appli/examples/CMakeLists.txt
appli/examples/example_MarchingCubes.cxx
appli/examples/example_View2DImage.cxx
lib/cpExtensions/Visualization/ImageBlender.cxx
lib/cpExtensions/Visualization/ImageBlender.h
lib/cpPlugins/Interface/BaseMPRWidget.cxx
lib/cpPlugins/Interface/BaseMPRWidget.h
lib/cpPlugins/Interface/Interface.cxx
lib/cpPlugins/Interface/Object.cxx
lib/cpPlugins/Interface/Plugins.cxx
lib/cpPlugins/Interface/ProcessObject.cxx

index 5754e3d9d120d866d1c72d0e62f94d18d8a1b22f..70124e9827df95a02366245b0a53f1683abb0ad7 100644 (file)
@@ -60,10 +60,25 @@ ImageMPR::
 void ImageMPR::
 UpdateActualFilter( )
 {
-  /* TODO
-     if( !( this->m_Plugins->HasActiveFilter( ) ) )
-     return;
+  if( !( this->m_Plugins.HasActiveFilter( ) ) )
+    return;
+
+  // Update filter
+  TPlugins::TStringContainer outputs;
+  if(
+    !(
+      this->m_Plugins.UpdateActiveFilter(
+        outputs, this->m_ActiveFilterMainInput
+        )
+      )
+    )
+    return;
+
+  // Show outputs
+  for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
+    std::cout << *oIt << std::endl;
   
+  /* TODO
      std::vector< std::string > outputs;
      std::string err = this->m_Plugins->UpdateActiveFilter( outputs );
      if( err == "" )
@@ -255,9 +270,8 @@ _execPlugin( )
     return;
 
   // Get IO names
-  TPlugins::TStringContainer inputs, outputs;
+  TPlugins::TStringContainer inputs;
   this->m_Plugins.GetActiveFilterInputsNames( inputs );
-  this->m_Plugins.GetActiveFilterOutputsNames( outputs );
 
   // Configure inputs
   if( inputs.size( ) > 1 )
@@ -265,80 +279,29 @@ _execPlugin( )
     // TODO
   }
   else if( inputs.size( ) == 1 )
+  {
+    this->m_ActiveFilterMainInput = this->m_UI->MPR->GetSelectedData( );
     this->m_Plugins.ConnectInputInActiveFilter(
-      this->m_UI->MPR->GetSelectedData( ), *( inputs.begin( ) )
+      this->m_ActiveFilterMainInput, *( inputs.begin( ) )
       );
 
-  // Configure outputs
-  for( auto oIt = outputs.begin( ); oIt != outputs.end( ); ++oIt )
-    this->m_Plugins.SetOutputNameInActiveFilter(
-      filter_name + "_" + *oIt, *oIt
-      );
+  } // fi
 
   // Configure paramereters
   auto dlg_res = this->m_Plugins.ConfigureActiveFilter( );
   if( dlg_res == TPlugins::TProcessObject::DialogResult_Cancel )
   {
+    // Just deactivate filter, since it was canceled
     this->m_Plugins.DeactivateFilter( );
-    // TODO
-  }
-
-
-  /*
-    QMenu* menu = dynamic_cast< QMenu* >( action->parentWidget( ) );
-    if( menu == NULL )
     return;
-    std::string filter_cate = menu->title( ).toStdString( );
-
-    // Activate filter
-    if( !( this->m_Plugins->ActivateFilter( filter_name ) ) )
-    return;
-
-    // Associate inputs
-    std::vector< std::string > inputs =
-    this->m_Plugins->GetActiveFilterInputsNames( );
-    if( inputs.size( ) == 1 )
-    {
-    std::string data_name = this->m_UI->MPR->GetSelectedData( );
-    this->m_Plugins->ConnectInputInActiveFilter( data_name, inputs[ 0 ] );
-    }
-    else if( inputs.size( ) > 1 )
-    {
-    QMessageBox::critical(
-    this,
-    tr( "Error executing" ),
-    tr( "Filter has multiple inputs: NOT YET IMPLEMENTED!!!" )
-    );
-    return;
-
-    } // fi
-
-    // 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
-    );
-
-    // Configure filter
-    TPlugins::TProcessObject::DialogResult dlg_res =
-    this->m_Plugins->ConfigureActiveFilter( );
-    if( dlg_res == TPlugins::TProcessObject::DialogResult_Cancel )
-    {
-    this->m_Plugins->DeactivateFilter( );
-    return;
-
-    } // fi
-
-    // Execute filter and associate outputs
-    if( dlg_res == TPlugins::TProcessObject::DialogResult_NoModal )
-    {
+  }
+  else if( dlg_res == TPlugins::TProcessObject::DialogResult_NoModal )
+  {
+    // Execute automatic filter and associate outputs
     this->UpdateActualFilter( );
-    this->m_Plugins->DeactivateFilter( );
+    this->m_Plugins.DeactivateFilter( );
 
-    } // fi
-  */
+  } // fi
 }
 
 // -------------------------------------------------------------------------
index 0a0199ec6dd75eb8a4941df7807b74a7bbad28e7..e11ec5ddc71ca6261548cbbd880f423f8c926bb5 100644 (file)
@@ -182,6 +182,7 @@ private slots:
 private:
   Ui::ImageMPR* m_UI;
   TPlugins      m_Plugins;
+  std::string   m_ActiveFilterMainInput;
 
   // Objects
   /*
index a389ddb70921e2e9db18ceb04e1ae68f42010430..023d3807d8ec6dd60d228459bb6aafa3735e8b58 100644 (file)
@@ -27,13 +27,13 @@ ENDFOREACH(prog)
 SET(
   EXAMPLES_PROGRAMS_WITH_PLUGINS
   example_ReadWriteImage
+  example_MarchingCubes
   #example_MPR
   example_View2DImage
   example_HandleWidget
   example_SeedWidget
   example_SphereWidget
   example_Test_Memento
-  ##example_MarchingCubes
   ##example_OtsuFilter
   ##example_RGBImageToHSVChannels
   ##example_RGBImageToYPbPrChannels
index fbd43bb4dc21c3f1fca02195d21a5c3beda4c7c0..a61a27825277fa893301bb3fa05cbc111602fbf1 100644 (file)
@@ -2,75 +2,89 @@
 #include <iostream>
 #include <string>
 
-#include <cpPlugins/Interface/Interface.h>
-#include <cpPlugins/Interface/ProcessObject.h>
+#include <cpPlugins/Interface/Plugins.h>
 
+// -------------------------------------------------------------------------
+typedef cpPlugins::Interface::Plugins TPlugins;
+
+// -------------------------------------------------------------------------
 int main( int argc, char* argv[] )
 {
-  if( argc < 5 )
+  if( argc < 4 )
   {
     std::cerr
       << "Usage: " << argv[ 0 ]
       << " plugins_file"
-      << " input_image value output_mesh" << std::endl;
+      << " input_image threshold output_image" << std::endl;
     return( 1 );
 
   } // fi
 
-  // Create interface
-  typedef cpPlugins::Interface::Interface TInterface;
-  typedef TInterface::TClasses            TClasses;
-  TInterface plugins;
-  if( !plugins.Load( argv[ 1 ] ) )
+  // Load plugins
+  cpPlugins::Interface::Plugins plugins;
+  if( !plugins.LoadPluginsPath( argv[ 1 ] ) )
   {
     std::cerr << "Failed to load plugins." << std::endl;
     return( 1 );
 
   } // fi
 
-  // Create objects
-  typedef cpPlugins::Interface::ProcessObject TProcessObject;
-  typedef cpPlugins::Interface::DataObject    TDataObject;
-  typedef cpPlugins::Interface::Parameters    TParameters;
-  cpPlugins::Interface::ProcessObject::Pointer reader, writer, mc;
-  reader = plugins.CreateProcessObject( "cpPlugins::ImageReader" );
-  writer = plugins.CreateProcessObject( "cpPlugins::MeshWriter" );
-  mc = plugins.CreateProcessObject( "cpPlugins::MarchingCubes" );
-  if( reader.IsNull( ) || writer.IsNull( ) || mc.IsNull( ) )
+  // Associate filenames
+  std::vector< std::string > fnames;
+  for( int i = 2; i < argc - 2; ++i )
+    fnames.push_back( argv[ i ] );
+  
+  // Read image
+  std::string filter = "cpPlugins::BasicFilters::MarchingCubes";
+  try
   {
-    std::cerr << "No suitable objects found in plugins." << std::endl;
-    return( 1 );
+    std::string name = plugins.ReadImage( fnames, "" );
 
-  } // fi
+    if( !( plugins.ActivateFilter( filter ) ) )
+    {
+      std::cerr << "Filter \"" << filter << "\" not found." << std::endl;
+      return( 1 );
 
-  // Configure reader
-  TParameters reader_params = reader->GetDefaultParameters( );
-  for( int i = 2; i < argc - 2; ++i )
-    reader_params.AddValueToStringList( "FileNames", argv[ i ] );
-  reader->SetParameters( reader_params );
-  // Configure marching cubes
-  TParameters mc_params = mc->GetDefaultParameters( );
-  mc_params.AddValueToRealList( "Thresholds", std::atof( argv[ argc - 2 ] ) );
-  mc->SetParameters( mc_params );
-
-  // Configure writer
-  TParameters writer_params = writer->GetDefaultParameters( );
-  writer_params.SetValueAsString( "FileName", argv[ argc - 1 ] );
-  writer->SetParameters( writer_params );
-
-  // Connect pipeline
-  mc->SetInput( 0, reader->GetOutput< TDataObject >( 0 ) );
-  writer->SetInput( 0, mc->GetOutput< TDataObject >( 0 ) );
-
-  // Execute pipeline
-  std::string err = writer->Update( );
-  if( err != "" )
+    } // fi
+
+    // Connect IO objects
+    TPlugins::TStringContainer inputs, outputs;
+    plugins.GetActiveFilterInputsNames( inputs );
+    plugins.GetActiveFilterOutputsNames( outputs );
+
+    plugins.ConnectInputInActiveFilter( name, *( inputs.begin( ) ) );
+    //plugins.SetOutputNameInActiveFilter( "output_mesh", *( outputs.begin( ) ) );
+
+    // Configure filter
+    TPlugins::TParameters* params = plugins.GetActiveFilterParameters( );
+    params->AddToRealList( "Thresholds", std::atof( argv[ argc - 2 ] ) );
+
+    // Execute filter
+    TPlugins::TStringContainer generated_outputs;
+    if( !( plugins.UpdateActiveFilter( generated_outputs, name ) ) )
+    {
+      std::cerr << "Error using filter \"" << filter << "\"." << std::endl;
+      return( 1 );
+
+    } // fi
+
+    // Save mesh
+    std::string outmesh_name = *( generated_outputs.begin( ) );
+    if( !( plugins.WriteDataObject( argv[ argc - 1 ], outmesh_name ) ) )
+    {
+      std::cerr
+        << "Error writing result into \"" << argv[ argc - 1 ]
+        << "\"" << std::endl;
+      return( 1 );
+
+    } // fi
+  }
+  catch( std::exception& err )
   {
-    std::cerr << "ERROR: " << err << std::endl;
+    std::cerr << err.what( ) << std::endl;
     return( 1 );
 
-  } // fi
+  } // yrt
   return( 0 );
 }
 
index 2778e8844a785901a6c1f374eb6b63a30d81468d..5e8327149a69c9e3a4bc6f1f3fab4d2f1db0ba4b 100644 (file)
@@ -1,25 +1,20 @@
 #include <cstdlib>
 #include <iostream>
 #include <string>
+#include <vector>
 
 #include <vtkRenderer.h>
 #include <vtkRenderWindow.h>
 #include <vtkRenderWindowInteractor.h>
 
-#include <cpPlugins/Interface/Interface.h>
-#include <cpPlugins/Interface/ProcessObject.h>
+#include <cpPlugins/Interface/Plugins.h>
 #include <cpPlugins/Interface/Image.h>
 
 #include <cpExtensions/Visualization/ImageSliceActors.h>
 
 // -------------------------------------------------------------------------
-typedef cpPlugins::Interface::Interface     TInterface;
-typedef cpPlugins::Interface::ProcessObject TProcessObject;
-typedef cpPlugins::Interface::DataObject    TDataObject;
-typedef cpPlugins::Interface::Image         TImage;
-typedef cpPlugins::Interface::Parameters    TParameters;
-typedef TInterface::TClasses                TClasses;
-
+typedef cpPlugins::Interface::Plugins                 TPlugins;
+typedef cpPlugins::Interface::Image                   TImage;
 typedef cpExtensions::Visualization::ImageSliceActors TSliceActors;
 
 // -------------------------------------------------------------------------
@@ -29,53 +24,39 @@ int main( int argc, char* argv[] )
   {
     std::cerr
       << "Usage: " << argv[ 0 ]
-      << " plugins_file input_image [widget]"
+      << " plugins_file input_image"
       << std::endl;
     return( 1 );
 
   } // fi
 
-  // Create interface
-  TInterface plugins;
-  if( !plugins.Load( argv[ 1 ] ) )
+  // Load plugins
+  cpPlugins::Interface::Plugins plugins;
+  if( !plugins.LoadPluginsPath( argv[ 1 ] ) )
   {
     std::cerr << "Failed to load plugins." << std::endl;
     return( 1 );
 
   } // fi
 
-  // Create objects
-  TProcessObject::Pointer reader;
-  reader = plugins.CreateObject( "cpPlugins::IO::ImageReader" );
-  if( reader.IsNull( ) )
-  {
-    std::cerr
-      << "No suitable reader found in plugins." << std::endl
-      << "Reader: " << reader.GetPointer( ) << std::endl
-      << std::endl;
-    return( 1 );
-
-  } // fi
-
-  // Configure reader
-  TParameters* reader_params = reader->GetParameters( );
-  if( argc > 4 )
+  // Associate filenames
+  std::vector< std::string > fnames;
+  for( int i = 2; i < argc; ++i )
+    fnames.push_back( argv[ i ] );
+  
+  // Read image
+  std::string name = "";
+  try
   {
-    for( int i = 2; i < argc; ++i )
-      reader_params->AddToStringList( "FileNames", argv[ i ] );
+    name = plugins.ReadImage( fnames, "" );
   }
-  else
-    reader_params->AddToStringList( "FileNames", argv[ 2 ] );
-
-  // Execute pipeline
-  std::string err = reader->Update( );
-  if( err != "" )
+  catch( std::exception& err )
   {
-    std::cerr << "ERROR: " << err << std::endl;
+    std::cerr << err.what( ) << std::endl;
     return( 1 );
 
-  } // fi
-  TImage* image = reader->GetOutput< TImage >( "Output" );
+  } // yrt
+  TImage* image = plugins.GetData< TImage >( name );
 
   // Configure visualization objects
   vtkSmartPointer< vtkRenderer > renderer =
index d5cbbd4b872326263d88ba1abaf9845b2dd7084f..49292c8dfaa61bc230ce2d1a8581ecd59b02652e 100644 (file)
@@ -25,8 +25,8 @@ PrintSelf( std::ostream& os, vtkIndent indent )
 
   // Objects
   os << indent << "Colors: " << std::endl;
-  auto i = this->m_Colors.begin( );
-  for( ; i != this->m_Colors.end( ); ++i )
+  auto i = this->Colors.begin( );
+  for( ; i != this->Colors.end( ); ++i )
     os
       << indent << indent << i->first << " : ["
       << i->second.R << ", "
@@ -39,73 +39,9 @@ PrintSelf( std::ostream& os, vtkIndent indent )
 unsigned int cpExtensions::Visualization::ImageBlender::
 GetNumberOfImages( ) const
 {
-  return( ( const_cast< Self* >( this ) )->GetNumberOfInputConnections( 0 ) );
-}
-
-// -------------------------------------------------------------------------
-const double& cpExtensions::Visualization::ImageBlender::
-GetMaxWindow( ) const
-{
-  return( this->m_MaxWindow );
-}
-
-// -------------------------------------------------------------------------
-const double& cpExtensions::Visualization::ImageBlender::
-GetMaxLevel( ) const
-{
-  return( this->m_MaxLevel );
-}
-
-// -------------------------------------------------------------------------
-const double& cpExtensions::Visualization::ImageBlender::
-GetMinWindow( ) const
-{
-  return( this->m_MinWindow );
-}
-
-// -------------------------------------------------------------------------
-const double& cpExtensions::Visualization::ImageBlender::
-GetMinLevel( ) const
-{
-  return( this->m_MinLevel );
-}
-
-// -------------------------------------------------------------------------
-const double& cpExtensions::Visualization::ImageBlender::
-GetWindow( ) const
-{
-  return( this->m_Window );
-}
-
-// -------------------------------------------------------------------------
-const double& cpExtensions::Visualization::ImageBlender::
-GetLevel( ) const
-{
-  return( this->m_Level );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageBlender::
-SetWindow( const double& w )
-{
-  if( this->m_Window != w )
-  {
-    this->m_Window = w;
-    this->Modified( );
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageBlender::
-SetLevel( const double& l )
-{
-  if( this->m_Level != l )
-  {
-    this->m_Level = l;
-    this->Modified( );
-
-  } // fi
+  return(
+    ( const_cast< Self* >( this ) )->GetNumberOfInputConnections( 0 )
+    );
 }
 
 // -------------------------------------------------------------------------
@@ -125,8 +61,8 @@ GetColor(
   double& b
   ) const
 {
-  auto c = this->m_Colors.find( i );
-  if( c != this->m_Colors.end( ) )
+  auto c = this->Colors.find( i );
+  if( c != this->Colors.end( ) )
   {
     r = c->second.R;
     g = c->second.G;
@@ -151,7 +87,7 @@ SetColor(
   const double& b
   )
 {
-  this->m_Colors[ i ] = TColor( r, g, b );
+  this->Colors[ i ] = TColor( r, g, b );
   this->Modified( );
 }
 
@@ -159,12 +95,12 @@ SetColor(
 cpExtensions::Visualization::ImageBlender::
 ImageBlender( )
   : Superclass( ),
-    m_MaxWindow( double( 0 ) ),
-    m_MaxLevel( double( 0 ) ),
-    m_MinWindow( double( 0 ) ),
-    m_MinLevel( double( 0 ) ),
-    m_Window( double( 0 ) ),
-    m_Level( double( 0 ) )
+    MaxWindow( double( 1 ) ),
+    MaxLevel( double( 1 ) ),
+    MinWindow( double( 0 ) ),
+    MinLevel( double( 0 ) ),
+    Window( double( 1 ) ),
+    Level( double( 0.5 ) )
 {
   this->SetNumberOfInputPorts( 1 );
 }
@@ -208,27 +144,13 @@ RequestInformation(
   this->m_Extent[ 5 ] += 1;
 
   // Configure window/level
-  double range[ 2 ];
-  inData->GetScalarRange( range );
-  this->m_MaxWindow = range[ 1 ] - range[ 0 ];
-  this->m_MinWindow = this->m_MaxWindow * double( 1e-2 );
-  this->m_MinLevel = range[ 0 ];
-  this->m_MaxLevel = range[ 1 ];
-  if( this->m_Window < this->m_MinWindow )
-    this->m_Window = this->m_MinWindow;
-  if( this->m_Window > this->m_MaxWindow )
-    this->m_Window = this->m_MaxWindow;
-  if( this->m_Level < this->m_MinLevel )
-    this->m_Level = this->m_MinLevel;
-  if( this->m_Level > this->m_MaxLevel )
-    this->m_Level = this->m_MaxLevel;
-  this->m_WLSlope = double( 1 ) / this->m_Window;
-  this->m_WLOffset = double( 0.5 ) - ( this->m_Level / this->m_Window );
+  this->m_WLSlope = double( 1 ) / this->Window;
+  this->m_WLOffset = double( 0.5 ) - ( this->Level / this->Window );
 
   // Configure output type
   vtkDataObject::SetPointDataActiveScalarInfo(
     outputVector->GetInformationObject( 0 ),
-    VTK_UNSIGNED_CHAR, 4
+    VTK_UNSIGNED_CHAR, 3
     );
   return( 1 );
 }
@@ -337,7 +259,7 @@ _GenerateData(
   vtkImageData** inDatas,
   int numInputs,
   vtkImageData* outData,
-  int outExt[6],
+  int outExt[ 6 ],
   int id
   )
 {
@@ -352,7 +274,7 @@ _GenerateData(
   int mType = inDatas[ 0 ]->GetScalarType( );
   int mSize = inDatas[ 0 ]->GetScalarSize( );
 
-  double r, g, b, a;
+  double r, g, b;
   int e13 = this->m_Extent[ 1 ] * this->m_Extent[ 3 ];
   for( int k = outExt[ 4 ]; k <= outExt[ 5 ]; ++k )
   {
@@ -375,7 +297,6 @@ _GenerateData(
 
         // Prepare color
         r = g = b = v;
-        a = _1;
 
         // Blend colors
         for( int i = 1; i < numInputs; ++i )
@@ -391,22 +312,20 @@ _GenerateData(
             );
           if( c > double( 0 ) )
           {
-            TColor rgb = this->m_Colors[ i ];
+            TColor rgb = this->Colors[ i ];
             r *= rgb.R * rgb.N;
             g *= rgb.G * rgb.N;
             b *= rgb.B * rgb.N;
-            a = _1;
 
           } // fi
 
         } // rof
 
         // Update color
-        int di4 = di << 2;
-        oBuffer[ di4 + 0 ] = static_cast< unsigned char >( r * _255 );
-        oBuffer[ di4 + 1 ] = static_cast< unsigned char >( g * _255 );
-        oBuffer[ di4 + 2 ] = static_cast< unsigned char >( b * _255 );
-        oBuffer[ di4 + 3 ] = static_cast< unsigned char >( a * _255 );
+        int di3 = di * 3;
+        oBuffer[ di3 + 0 ] = static_cast< unsigned char >( r * _255 );
+        oBuffer[ di3 + 1 ] = static_cast< unsigned char >( g * _255 );
+        oBuffer[ di3 + 2 ] = static_cast< unsigned char >( b * _255 );
 
       } // rof
 
index f12282295da44d6ac107d962d3cd8b1648a207b8..7ccc86494c09d093dac237e5300bf0f4d0c18ba4 100644 (file)
@@ -21,21 +21,25 @@ namespace cpExtensions
       typedef ImageBlender Self;
       vtkTypeMacro( ImageBlender, vtkThreadedImageAlgorithm );
 
+      vtkGetMacro( MaxWindow, double );
+      vtkGetMacro( MaxLevel, double );
+      vtkGetMacro( MinWindow, double );
+      vtkGetMacro( MinLevel, double );
+      vtkGetMacro( Window, double );
+      vtkGetMacro( Level, double );
+
+      vtkSetMacro( MaxWindow, double );
+      vtkSetMacro( MaxLevel, double );
+      vtkSetMacro( MinWindow, double );
+      vtkSetMacro( MinLevel, double );
+      vtkSetMacro( Window, double );
+      vtkSetMacro( Level, double );
+
     public:
       static Self* New( );
       void PrintSelf( std::ostream& os, vtkIndent indent );
 
       unsigned int GetNumberOfImages( ) const;
-
-      const double& GetMaxWindow( ) const;
-      const double& GetMaxLevel( ) const;
-      const double& GetMinWindow( ) const;
-      const double& GetMinLevel( ) const;
-      const double& GetWindow( ) const;
-      const double& GetLevel( ) const;
-
-      void SetWindow( const double& w );
-      void SetLevel( const double& l );
       void SetWindowLevel( const double& w, const double& l );
 
       void GetColor(
@@ -74,7 +78,7 @@ namespace cpExtensions
         vtkImageData** inDatas,
         int numInputs,
         vtkImageData* outData,
-        int outExt[6],
+        int outExt[ 6 ],
         int id
         );
 
@@ -99,14 +103,14 @@ namespace cpExtensions
             this->N = std::sqrt( ( r * r ) + ( g * g ) + ( b * b ) );
           }
       };
-      mutable std::map< unsigned int, TColor > m_Colors;
-
-      double m_MaxWindow;
-      double m_MaxLevel;
-      double m_MinWindow;
-      double m_MinLevel;
-      double m_Window;
-      double m_Level;
+      mutable std::map< unsigned int, TColor > Colors;
+
+      double MaxWindow;
+      double MaxLevel;
+      double MinWindow;
+      double MinLevel;
+      double Window;
+      double Level;
 
       int    m_Extent[ 6 ];
       double m_WLSlope;
index e7f270ce7700de29c530d35d531570b840bb976e..4a03cd95365f1e934c95629b41c662eacb9677cc 100644 (file)
@@ -3,6 +3,9 @@
 #ifdef cpPlugins_Interface_QT4
 
 #include <cpPlugins/Interface/ui_BaseMPRWidget.h>
+#include <cpPlugins/Interface/DataObject.h>
+#include <cpPlugins/Interface/Image.h>
+#include <cpPlugins/Interface/Mesh.h>
 #include <QTreeWidgetItem>
 #include <vtkRendererCollection.h>
 
@@ -49,39 +52,30 @@ cpPlugins::Interface::BaseMPRWidget::
 
 // -------------------------------------------------------------------------
 bool cpPlugins::Interface::BaseMPRWidget::
-AddImage(
-  vtkImageData* image, const std::string& name, const std::string& parent
+AddData(
+  cpPlugins::Interface::DataObject* data, const std::string& name,
+  const std::string& parent
   )
 {
   if( name == "" )
     return( false );
 
-  if( parent == "" )
-    this->DeleteAllData( );
-  
   auto iIt = this->m_Data.find( name );
   if( iIt == this->m_Data.end( ) )
   {
-    // Update tree
     if( parent != "" )
     {
       auto pIt = this->m_Data.find( parent );
-      if( pIt != this->m_Data.end( ) )
-        this->m_Tree[ name ] = parent;
-      else
+      if( pIt == this->m_Data.end( ) )
         return( false );
-    }
-    else
-      this->m_MainImage = name;
-    
+
+    } // fi
+
     // Add new data
-    Data nd;
-    nd.Tag = Data::IMAGE;
-    nd.Image = image;
-    this->m_Data[ name ] = nd;
+    this->m_Data[ name ].SetSourceDataObject( data );
 
     // Add to tree view
-    this->_UpdateItem( name, parent );
+    this->_UpdateTreeItem( name, parent );
     return( true );
   }
   else
@@ -90,32 +84,18 @@ AddImage(
 
 // -------------------------------------------------------------------------
 bool cpPlugins::Interface::BaseMPRWidget::
-AddMesh(
-  vtkPolyData* mesh, const std::string& name, const std::string& parent
-  )
+SetMainImage( const std::string& name )
 {
-  if( name == "" || parent == "" )
-    return( false );
-  
   auto iIt = this->m_Data.find( name );
-  if( iIt == this->m_Data.end( ) )
+  if( iIt != this->m_Data.end( ) )
   {
-    // Add new data
-    Data nd;
-    nd.Tag = Data::MESH;
-    nd.Mesh.Configure( mesh );
-    this->m_Data[ name ] = nd;
-
-    // Update tree
-    auto pIt = this->m_Data.find( parent );
-    if( pIt != this->m_Data.end( ) )
-      this->m_Tree[ name ] = parent;
+    if( iIt->second.Tag == Data::IMAGE )
+    {
+      this->m_MainImage = name;
+      return( true );
+    }
     else
       return( false );
-    
-    // Add to tree view
-    this->_UpdateItem( name, parent );
-    return( true );
   }
   else
     return( false );
@@ -148,14 +128,14 @@ DeleteData( const std::string& name )
       this->DeleteData( *dIt );
 
     // Delete from tree widget
-    QTreeWidgetItem* item = this->_FindItem( name );
+    QTreeWidgetItem* item = this->_FindItemInTree( name );
     if( item != NULL )
       this->m_UI->LoadedData->removeItemWidget( item, 0 );
 
     // Reset main image, just in case
     if( this->m_Data.size( ) == 0 )
       this->m_MainImage = "";
-    
+
   } // fi
 }
 
@@ -176,16 +156,18 @@ SetDataColor(
   const std::string& name, const double& r, const double& g, const double& b
   )
 {
-  auto iIt = this->m_Data.find( name );
-  if( iIt == this->m_Data.end( ) )
+  /*
+    auto iIt = this->m_Data.find( name );
+    if( iIt == this->m_Data.end( ) )
     return;
 
-  if( iIt->second.Tag == Data::IMAGE )
-  {
-  }
-  else if( iIt->second.Tag == Data::MESH )
-  {
-  } // fi
+    if( iIt->second.Tag == Data::IMAGE )
+    {
+    }
+    else if( iIt->second.Tag == Data::MESH )
+    {
+    } // fi
+  */
 }
 
 // -------------------------------------------------------------------------
@@ -196,20 +178,27 @@ ShowData( const std::string& name )
   if( iIt == this->m_Data.end( ) )
     return;
 
-  if( iIt->second.Tag == Data::IMAGE )
-  {
+  /*
+    if( iIt->second.Tag == Data::IMAGE )
+    {
     this->m_MPRObjects->AddImage( iIt->second.Image );
-  }
-  else if( iIt->second.Tag == Data::MESH )
-  {
+    }
+    else if( iIt->second.Tag == Data::MESH )
+    {
     vtkRenderer* ren =
-      this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
+    this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
     if( ren == NULL )
-      return;
+    return;
     ren->AddActor( iIt->second.GetMeshActor( ) );
     this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
+    } // fi
+  */
+}
 
-  } // fi
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::BaseMPRWidget::
+HideData( const std::string& name )
+{
 }
 
 // -------------------------------------------------------------------------
@@ -237,7 +226,7 @@ GetInteractor( unsigned int i )
   )
   {
   // Update tree view
-  QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
+  QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent );
   if( new_item == NULL )
   return( false );
 
@@ -260,7 +249,7 @@ GetInteractor( unsigned int i )
   )
   {
   // Update tree view
-  QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
+  QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent );
   if( new_item == NULL )
   return( false );
 
@@ -282,7 +271,7 @@ GetInteractor( unsigned int i )
   )
   {
   // Update tree view
-  QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
+  QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent );
   if( new_item == NULL )
   return( false );
 
@@ -331,7 +320,7 @@ GetSelectedData( ) const
 
 // -------------------------------------------------------------------------
 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
-_FindItem( const std::string& name ) const
+_FindItemInTree( const std::string& name ) const
 {
   QList< QTreeWidgetItem* > items =
     this->m_UI->LoadedData->findItems( name.c_str( ), Qt::MatchExactly );
@@ -343,16 +332,16 @@ _FindItem( const std::string& name ) const
 
 // -------------------------------------------------------------------------
 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
-_UpdateItem( const std::string& name, const std::string& parent )
+_UpdateTreeItem( const std::string& name, const std::string& parent )
 {
   // Update tree view
   QTreeWidgetItem* new_item = NULL;
   if( parent != "" )
   {
-    QTreeWidgetItem* parent_item = this->_FindItem( parent );
+    QTreeWidgetItem* parent_item = this->_FindItemInTree( parent );
     if( parent_item != NULL )
     {
-      QTreeWidgetItem* old_item = this->_FindItem( name );
+      QTreeWidgetItem* old_item = this->_FindItemInTree( name );
       if( old_item == NULL )
       {
         new_item =
@@ -451,6 +440,107 @@ Configure( vtkPolyData* pd )
   this->Actor->DeferLODConstructionOff( );
 }
 
+// -------------------------------------------------------------------------
+cpPlugins::Interface::BaseMPRWidget::Data::
+Data( )
+{
+  this->Tag = Data::IMAGE;
+  this->Source = NULL;
+  this->Image = NULL;
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::BaseMPRWidget::Data::
+~Data( )
+{
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::BaseMPRWidget::
+Data& cpPlugins::Interface::BaseMPRWidget::Data::
+operator=( const Data& data )
+{
+  this->Tag = data.Tag;
+  this->Source = data.Source;
+  if( this->Tag == Data::IMAGE )
+    this->Image = data.Image;
+  else if( this->Tag == Data::MESH )
+    this->Mesh = data.Mesh;
+  return( *this );
+}
+
+// -------------------------------------------------------------------------
+cpPlugins::Interface::
+DataObject* cpPlugins::Interface::BaseMPRWidget::Data::
+GetSourceDataObject( )
+{
+  return( this->Source );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::
+DataObject* cpPlugins::Interface::BaseMPRWidget::Data::
+GetSourceDataObject( ) const
+{
+  return( this->Source );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::Interface::BaseMPRWidget::Data::
+SetSourceDataObject( cpPlugins::Interface::DataObject* dobj )
+{
+  typedef cpPlugins::Interface::Image _TImage;
+  typedef cpPlugins::Interface::Mesh  _TMesh;
+
+  this->Source = dobj;
+  _TImage* image = dynamic_cast< _TImage* >( dobj );
+  if( image != NULL )
+  {
+    this->Tag = Data::IMAGE;
+    this->Image = image->GetVTK< vtkImageData >( );
+  }
+  else
+  {
+    _TMesh* mesh = dynamic_cast< _TMesh* >( dobj );
+    if( mesh == NULL )
+      return;
+
+    this->Tag = Data::MESH;
+    this->Mesh.Configure( mesh->GetVTK< vtkPolyData >( ) );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+vtkImageData* cpPlugins::Interface::BaseMPRWidget::Data::
+GetImage( )
+{
+  if( this->Tag == Data::IMAGE )
+    return( this->Image );
+  else
+    return( NULL );
+}
+
+// -------------------------------------------------------------------------
+vtkPolyData* cpPlugins::Interface::BaseMPRWidget::Data::
+GetMesh( )
+{
+  if( this->Tag == Data::MESH )
+    return( this->Mesh.Mesh );
+  else
+    return( NULL );
+}
+
+// -------------------------------------------------------------------------
+vtkProp* cpPlugins::Interface::BaseMPRWidget::Data::
+GetMeshActor( )
+{
+  if( this->Tag == Data::MESH )
+    return( this->Mesh.Actor );
+  else
+    return( NULL );
+}
+
 #endif // cpPlugins_Interface_QT4
 
 // eof - $RCSfile$
index 6cb89f305816a6c83270df8659d00a3fcef50736..cd269f41e58f0560569d31f8ec4c585e825543c7 100644 (file)
@@ -34,6 +34,9 @@ namespace cpPlugins
 {
   namespace Interface
   {
+    // Some forward declarations
+    class DataObject;
+
     /**
      */
     class cpPlugins_Interface_EXPORT BaseMPRWidget
@@ -62,70 +65,34 @@ namespace cpPlugins
       virtual ~BaseMPRWidget( );
 
       // Data management
-      bool AddImage(
-        vtkImageData* image,
-        const std::string& name,
-        const std::string& parent = ""
-        );
-      bool AddMesh(
-        vtkPolyData* mesh,
-        const std::string& name,
+      bool AddData(
+        DataObject* data, const std::string& name,
         const std::string& parent
         );
+      bool SetMainImage( const std::string& name );
       void DeleteData( const std::string& name );
       void DeleteAllData( );
 
       // Some visualization accessors
       void SetDataColor(
         const std::string& name,
-        const double& r,
-        const double& g,
-        const double& b
+        const double& r, const double& g, const double& b
         );
       void ShowData( const std::string& name );
+      void HideData( const std::string& name );
 
       vtkRenderWindowInteractor* GetInteractor( unsigned int i );
 
-      /*
-        bool ShowImage(
-        vtkImageData* image,
-        const std::string& name,
-        const std::string& parent = ""
-        );
-        bool ShowImage(
-        vtkImageData* image,
-        const std::string& name,
-        const std::string& parent,
-        const double& r, const double& g, const double& b
-        );
-        bool ShowMesh(
-        vtkPolyData* mesh,
-        const std::string& name,
-        const std::string& parent
-        );
-        bool ShowMesh(
-        vtkPolyData* mesh,
-        const std::string& name,
-        const std::string& parent,
-        const double& r, const double& g, const double& b
-        );
-        void ClearAll( );
-      */
-
       // Visual objects accessors
       std::string GetSelectedData( ) const;
 
     protected:
-      QTreeWidgetItem* _FindItem( const std::string& name ) const;
-      QTreeWidgetItem* _UpdateItem(
+      QTreeWidgetItem* _FindItemInTree( const std::string& name ) const;
+      QTreeWidgetItem* _UpdateTreeItem(
         const std::string& name,
         const std::string& parent
         );
 
-      /* TODO
-         void _Add3DActor( vtkProp3D* prop );
-      */
-
     private slots:
       void _SyncBottom( int a, int b );
       void _SyncTop( int a, int b );
@@ -151,46 +118,25 @@ namespace cpPlugins
       struct Data
       {
         enum { IMAGE, MESH } Tag;
+        DataObject*          Source;
         union
         {
           vtkImageData* Image;
           PolyDataActor Mesh;
         };
 
-        Data( ) { }
-        virtual ~Data( ) { }
-
-        inline Data& operator=( const Data& data )
-          {
-            this->Tag = data.Tag;
-            if( this->Tag == Data::IMAGE )
-              this->Image = data.Image;
-            else if( this->Tag == Data::MESH )
-              this->Mesh = data.Mesh;
-            return( *this );
-          }
-
-        inline vtkImageData* GetImage( )
-          {
-            if( this->Tag == Data::IMAGE )
-              return( this->Image );
-            else
-              return( NULL );
-          }
-        inline vtkPolyData* GetMesh( )
-          {
-            if( this->Tag == Data::MESH )
-              return( this->Mesh.Mesh );
-            else
-              return( NULL );
-          }
-        inline vtkProp* GetMeshActor( )
-          {
-            if( this->Tag == Data::MESH )
-              return( this->Mesh.Actor );
-            else
-              return( NULL );
-          }
+        Data( );
+        virtual ~Data( );
+
+        Data& operator=( const Data& data );
+
+        DataObject* GetSourceDataObject( );
+        const DataObject* GetSourceDataObject( ) const;
+        void SetSourceDataObject( DataObject* dobj );
+
+        vtkImageData* GetImage( );
+        vtkPolyData* GetMesh( );
+        vtkProp* GetMeshActor( );
       };
 
       std::string m_MainImage;
index bb5b35c92ac32a7f85cfaefbd9432ed01bc3b884..494f1893bfab3fd2010b1aeea892d48f18f55c53 100644 (file)
@@ -43,7 +43,12 @@ CreateObject( const std::string& name ) const
         this->m_Providers[ cIt->second ]
         );
     if( provider != NULL )
-      return( provider->create( ) );
+    {
+      cpPlugins::Interface::ProcessObject::Pointer po = provider->create( );
+      po->SetName( name );
+      return( po );
+
+    } // fi
 
   } // fi
   return( NULL );
index 474e031f04565b552b84f2c86d1d32312d4d88e8..85ef6a123f332d99ff8093906333cebe9fce8c3d 100644 (file)
@@ -3,7 +3,8 @@
 // -------------------------------------------------------------------------
 cpPlugins::Interface::Object::
 Object( )
-  : Superclass( )
+  : Superclass( ),
+    m_Name( "" )
 {
 }
 
index a5092ccaeee07f2a014d3fe02029f41dd1b645bb..614fddbda124a315d7e2ddb93fd3e51e84a915e5 100644 (file)
@@ -676,6 +676,11 @@ UpdateActiveFilter( TStringContainer& outputs, const std::string& parent )
     {
       TDataObject* dobj =
         this->m_ActiveFilter->GetOutput< TDataObject >( *oIt );
+
+      if( std::string( dobj->GetName( ) ) == std::string( "" ) )
+        dobj->SetName(
+          this->m_ActiveFilter->GetName( ) + std::string( "_" ) + *oIt
+          );
       this->_InsertNewData( dobj, parent );
       outputs.insert( dobj->GetName( ) );
 
index 7d2a19257fe1340b2dfa9d30934bf6a04d178837..1e89c859aafdb52bebce3aa40a680694bf7c79e9 100644 (file)
@@ -117,6 +117,8 @@ void cpPlugins::Interface::ProcessObject::
 AddInteractor( vtkRenderWindowInteractor* interactor )
 {
 #ifdef cpPlugins_Interface_QT4
+  if( this->m_ParametersDialog == NULL )
+    this->m_ParametersDialog = new ParametersQtDialog( );
   this->m_ParametersDialog->addInteractor( interactor );
 #endif // cpPlugins_Interface_QT4
 }