]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 21 Apr 2016 16:47:34 +0000 (11:47 -0500)
committerLeonardo Florez-Valencia <florez-l@javeriana.edu.co>
Thu, 21 Apr 2016 16:47:34 +0000 (11:47 -0500)
lib/cpExtensions/QT/SimpleMPRWidget.cxx
lib/cpExtensions/QT/SimpleMPRWidget.h
plugins/cpPluginsWidgets/SeedWidget.cxx
plugins/cpPluginsWidgets/SeedWidget.h

index d335f538456d2439f6da9ff5e50cfe22963aec7d..911921b005c1140bca4031cd6ef426787084a8d9 100644 (file)
@@ -169,6 +169,16 @@ AddMesh( vtkPolyData* mesh )
   this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
 }
 
+// -------------------------------------------------------------------------
+vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
+GetInteractor( unsigned int i )
+{
+  if( i < 4 )
+    return( this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( ) );
+  else
+    return( NULL );
+}
+
 // -------------------------------------------------------------------------
 void cpExtensions::QT::SimpleMPRWidget::
 _SyncBottom( int a, int b )
index 42a09f667a2f02abe30f6353c75a00ed8c7d4209..5aed9ec08f8548e403902a2d1e0e6479d5e0c88e 100644 (file)
@@ -110,7 +110,11 @@ namespace cpExtensions
       void Clear( );
       void SetMainImage( vtkImageData* image );
       void AddMesh( vtkPolyData* mesh );
-      
+
+      // Visual objects
+      vtkRenderWindowInteractor* GetInteractor( unsigned int i );
+
+
       /* TODO
          unsigned int GetNumberOfData( ) const;
          bool AddData(
@@ -136,8 +140,6 @@ namespace cpExtensions
          double GetWindow( ) const;
          double GetLevel( ) const;
 
-         vtkRenderWindowInteractor* GetInteractor( unsigned int i );
-
          // Visual objects accessors
          std::string GetSelectedData( ) const;
          vtkProp* GetProp( const std::string& name );
index 9e7a408b33d0d559622991c825438cea27bb1fff..64069e4ce4602c971cde376a7600b3a23b5c411f 100644 (file)
@@ -1,19 +1,47 @@
 #include "SeedWidget.h"
 
-#include <cpPlugins/Image.h>
-#include <cpExtensions/DataStructures/ImageIndexesContainer.h>
-#include <cpExtensions/QT/SimpleMPRWidget.h>
-#include <cpExtensions/Interaction/ImageInteractorStyle.h>
+#include <vtkProperty.h>
 #include <vtkRenderWindowInteractor.h>
-#include <itkSimpleDataObjectDecorator.h>
-#include <itkSimpleDataObjectDecorator.hxx>
+#include <cpExtensions/QT/SimpleMPRWidget.h>
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::SeedWidget::WidgetData::
+Configure( vtkRenderWindowInteractor* interactor, vtkImageActor* actor )
+{
+  this->Placer = vtkSmartPointer< vtkImageActorPointPlacer >::New( );
+  this->Handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
+  this->Seed = vtkSmartPointer< vtkSeedRepresentation >::New( );
+  this->Widget =
+    vtkSmartPointer< cpExtensions::Interaction::SeedWidget >::New( );
+
+  this->Placer->SetImageActor( actor );
+  this->Handle->GetProperty( )->SetColor( 1, 0, 0 );
+  this->Handle->SetPointPlacer( this->Placer );
+  this->Seed->SetHandleRepresentation( this->Handle );
+  this->Widget->SetRepresentation( this->Seed );
+  this->Widget->SetInteractor( interactor );
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::SeedWidget::WidgetData::
+On( )
+{
+  this->Widget->On( );
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::SeedWidget::WidgetData::
+Off( )
+{
+  this->Widget->Off( );
+}
 
 // -------------------------------------------------------------------------
 itk::ModifiedTimeType cpPluginsWidgets::SeedWidget::
 GetMTime( ) const
 {
-  // std::cout << "Seed GetMTime" << std::endl;
-  return( 0 /*this->Superclass::GetMTime( )*/ );
+  this->Modified( );
+  return( this->Superclass::GetMTime( ) );
 }
 
 // -------------------------------------------------------------------------
@@ -22,7 +50,6 @@ SeedWidget( )
   : Superclass( ),
     m_Configured( false )
 {
-  this->_AddInput( "ReferenceImage" );
   this->_AddOutput< cpPlugins::DataObject >( "Output" );
 }
 
@@ -36,94 +63,75 @@ cpPluginsWidgets::SeedWidget::
 void cpPluginsWidgets::SeedWidget::
 _GenerateData( )
 {
-  auto image = this->GetInputData< itk::DataObject >( "ReferenceImage" );
-  cpPlugins_Image_Demangle_Dim     ( _GD0, image, 2 );
-  else cpPlugins_Image_Demangle_Dim( _GD0, image, 3 );
-  else this->_Error( "No valid input image." );
-}
-
-// -------------------------------------------------------------------------
-template< class _TImage >
-void cpPluginsWidgets::SeedWidget::
-_GD0( _TImage* image )
-{
-
-  /*
-    typedef
-    cpExtensions::DataStructures::ImageIndexesContainer< _TImage::ImageDimension >
-    _TContainer;
-    typedef cpExtensions::Interaction::ImageInteractorStyle _S;
-
-    if( image != NULL )
-    {
-    auto container = this->_CreateITK< _TContainer >( );
-    double aux_pnt[ 3 ];
-    unsigned int dim = ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3;
-    container->Get( ).clear( );
-
-    // MPR
-    if( this->m_MPRViewer != NULL )
-    {
-    for( unsigned int i = 0; i < 4; ++i )
-    {
-    _S* s =
-    dynamic_cast< _S* >(
-    this->m_MPRViewer->GetInteractor( i )->GetInteractorStyle( )
-    );
-    if( s != NULL )
-    {
-    if( this->m_Configured )
+  if( this->m_Configured )
+  {
+    auto points = this->_CreateVTK< vtkPoints >( );
+    for(
+      auto wIt = this->m_Widgets.begin( );
+      wIt != this->m_Widgets.end( );
+      ++wIt
+      )
     {
-    for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
-    {
-    s->GetSeedAsPoint( i, aux_pnt );
-    typename _TImage::PointType seed;
-    for( unsigned int d = 0; d < dim; ++d )
-    seed[ d ] = aux_pnt[ d ];
-    typename _TImage::IndexType idx;
-    if( image->TransformPhysicalPointToIndex( seed, idx ) )
-    container->Get( ).push_back( idx );
+      double pos[ 3 ];
+      for( unsigned int i = 0; i < wIt->Seed->GetNumberOfSeeds( ); ++i )
+      {
+        wIt->Seed->GetSeedWorldPosition( i, pos );
+        points->InsertNextPoint( pos );
 
-    } // rof
-    }
-    else
-    s->SeedWidgetOn( );
-
-    } // fi
+      } // rof
 
     } // rof
+    this->GetOutput( "Output" )->SetVTK( points );
+  }
+  else
+  {
+    std::vector< vtkRenderWindowInteractor* > ints;
+    if( this->m_MPRViewer != NULL )
+    {
+      ints.push_back( this->m_MPRViewer->GetInteractor( 0 ) );
+      ints.push_back( this->m_MPRViewer->GetInteractor( 1 ) );
+      ints.push_back( this->m_MPRViewer->GetInteractor( 2 ) );
 
     } // fi
+    if( this->m_SingleInteractor != NULL )
+      ints.push_back( this->m_SingleInteractor );
 
-    // Single interactor
-    _S* s = dynamic_cast< _S* >( this->m_SingleInteractor );
-    if( s != NULL )
-    {
-    if( this->m_Configured )
+    for( auto iIt = ints.begin( ); iIt !=  ints.end( ); ++iIt )
     {
-    for( unsigned int i = 0; i < s->GetNumberOfSeeds( ); ++i )
-    {
-    s->GetSeedAsPoint( i, aux_pnt );
-    typename _TImage::PointType seed;
-    for( unsigned int d = 0; d < dim; ++d )
-    seed[ d ] = aux_pnt[ d ];
-    typename _TImage::IndexType idx;
-    if( image->TransformPhysicalPointToIndex( seed, idx ) )
-    container->Get( ).push_back( idx );
+      auto ren = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( );
+      if( ren != NULL )
+      {
+        auto props = ren->GetViewProps( );
+        if( props != NULL )
+        {
+          props->InitTraversal( );
+          vtkProp* prop;
+          while( ( prop = props->GetNextProp( ) ) != NULL )
+          {
+            auto actor = dynamic_cast< vtkImageActor* >( prop );
+            if( actor != NULL )
+            {
+              WidgetData d;
+              d.Configure( *iIt, actor );
+              d.On( );
+              this->m_Widgets.push_back( d );
+              this->m_Configured = true;
+
+            } // fi
+
+          } // elihw
+
+        } // fi
+
+      } // fi
 
     } // rof
-    }
-    else
-    s->SeedWidgetOn( );
 
-    } // fi
-    this->m_Configured = true;
-    container->SetReferenceImage( image );
-    this->GetOutputData( "Output" )->SetITK( container );
-    }
-    else
-    this->_Error( "Input image dimension not supported." );
-  */
+  } // fi
+  if( !( this->m_Configured ) )
+    this->_Error(
+      "Could not create valid widget: are there any valid actors?"
+      );
 }
 
 // eof - $RCSfile$
index b53b346281972d1413c9e00bc6dcfe7bcfc9bf4a..74dfc0b40b476a05e6ad463a5184adbeca31cbcc 100644 (file)
@@ -4,6 +4,12 @@
 #include <plugins/cpPluginsWidgets/cpPluginsWidgets_Export.h>
 #include <cpPlugins/BaseWidget.h>
 
+#include <cpExtensions/Interaction/SeedWidget.h>
+#include <vtkImageActorPointPlacer.h>
+#include <vtkPointHandleRepresentation3D.h>
+#include <vtkSeedRepresentation.h>
+#include <vtkSmartPointer.h>
+
 namespace cpPluginsWidgets
 {
   /**
@@ -22,6 +28,20 @@ namespace cpPluginsWidgets
     itkTypeMacro( SeedWidget, cpPlugins::BaseWidget );
     cpPlugins_Id_Macro( SeedWidget, Widgets );
 
+    struct WidgetData
+    {
+      vtkSmartPointer< cpExtensions::Interaction::SeedWidget > Widget;
+      vtkSmartPointer< vtkImageActorPointPlacer >              Placer;
+      vtkSmartPointer< vtkPointHandleRepresentation3D >        Handle;
+      vtkSmartPointer< vtkSeedRepresentation >                 Seed;
+
+      void Configure(
+        vtkRenderWindowInteractor* interactor, vtkImageActor* actor
+        );
+      void On( );
+      void Off( );
+    };
+
   public:
     virtual itk::ModifiedTimeType GetMTime( ) const ITK_OVERRIDE;
 
@@ -31,8 +51,10 @@ namespace cpPluginsWidgets
 
     virtual void _GenerateData( ) ITK_OVERRIDE;
 
-    template< class _TImage >
-      inline void _GD0( _TImage* image );
+    /* TODO
+       template< class _TImage >
+       inline void _GD0( _TImage* image );
+    */
 
   private:
     // Purposely not implemented
@@ -41,6 +63,7 @@ namespace cpPluginsWidgets
 
   protected:
     bool m_Configured;
+    std::vector< WidgetData > m_Widgets;
   };
 
 } // ecapseman