]> Creatis software - cpPlugins.git/commitdiff
Line widget added.
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 5 Oct 2016 23:08:41 +0000 (18:08 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 5 Oct 2016 23:08:41 +0000 (18:08 -0500)
appli/bash/BuildInstances.cxx.in
lib/cpPlugins/BaseObjects/Widget.cxx
lib/cpPlugins/BaseObjects/Widget.h
lib/cpPlugins/Interface/Workspace.cxx
lib/cpPlugins/Interface/Workspace.h
plugins/Widgets/LineWidget.cxx [new file with mode: 0644]
plugins/Widgets/LineWidget.h [new file with mode: 0644]
plugins/Widgets/SeedWidget.cxx
plugins/Widgets/SeedWidget.h
plugins/Widgets/SplineWidget.cxx
plugins/Widgets/SplineWidget.h

index 79cbcf26873f3d34f31eb7408726c16f140063db..084ee1c3dc1d36262ff61c569dabb14c28f4b5e9 100644 (file)
@@ -218,7 +218,7 @@ void Lines( TCommands& commands, const std::deque< std::string >& lines )
   for( auto l = lines.begin( ); l != lines.end( ); ++l )
   {
     auto pos = l->find_first_not_of( " " );
-    char cmd = std::tolower( ( *l )[ pos ] );
+    char cmd = tolower( ( *l )[ pos ] );
     commands[ cmd ].push_back(
       l->substr( l->find_first_not_of( " ", pos + 1 ) )
       );
index 35bf57aaaab421b76b89f6a7619408f844abe812..93bf1b93b9757957d35aacf41ddcb6638d24141d 100644 (file)
@@ -16,6 +16,20 @@ IsInteractive( )
   return( true );
 }
 
+// -------------------------------------------------------------------------
+void cpPlugins::BaseObjects::Widget::
+EnabledOn( )
+{
+  this->SetEnabled( true );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::BaseObjects::Widget::
+EnabledOff( )
+{
+  this->SetEnabled( false );
+}
+
 // -------------------------------------------------------------------------
 cpPlugins::BaseObjects::Widget::
 Widget( )
index daa5de730a7096902b337c4a80cab1deb3c336f3..1451b7b0f1ae16aa2dee0456cb7e31ed3f8e1faf 100644 (file)
@@ -28,6 +28,11 @@ namespace cpPlugins
 
       virtual bool IsInteractive( ) cpPlugins_OVERRIDE;
 
+      virtual void EnabledOn( );
+      virtual void EnabledOff( );
+      virtual void Clear( ) = 0;
+      virtual void SetEnabled( bool v ) = 0;
+
     protected:
       Widget( );
       virtual ~Widget( );
index d1d2c0daa7b412935ce6c4909b1ccdfc4b879c2d..90c26d5415ca430af81d910a7187f0274eb08cb2 100644 (file)
@@ -44,6 +44,24 @@ GetFilter( const std::string& name ) const
     return( NULL );
 }
 
+// -------------------------------------------------------------------------
+cpPlugins::Interface::Workspace::
+TWidget* cpPlugins::Interface::Workspace::
+GetWidget( const std::string& name )
+{
+  TProcess* process = this->GetFilter( name );
+  return( dynamic_cast< TWidget* >( process ) );
+}
+
+// -------------------------------------------------------------------------
+const cpPlugins::Interface::Workspace::
+TWidget* cpPlugins::Interface::Workspace::
+GetWidget( const std::string& name ) const
+{
+  const TProcess* process = this->GetFilter( name );
+  return( dynamic_cast< const TWidget* >( process ) );
+}
+
 // -------------------------------------------------------------------------
 bool cpPlugins::Interface::Workspace::
 HasFilter( const std::string& name ) const
@@ -51,6 +69,14 @@ HasFilter( const std::string& name ) const
   return( this->m_Filters.find( name ) != this->m_Filters.end( ) );
 }
 
+// -------------------------------------------------------------------------
+bool cpPlugins::Interface::Workspace::
+HasWidget( const std::string& name ) const
+{
+  const TWidget* wdg = this->GetWidget( name );
+  return( wdg != NULL );
+}
+
 // -------------------------------------------------------------------------
 cpPlugins::Interface::Workspace::
 TProcess* cpPlugins::Interface::Workspace::
index 6282f697f6ee7784e835fdac11f06037b16cf277..428f13a72148727478c2cb4f1f0e156e142b94fd 100644 (file)
@@ -4,6 +4,7 @@
 #include <cpPlugins/Interface/Plugins.h>
 #include <cpPlugins/BaseObjects/DataObject.h>
 #include <cpPlugins/BaseObjects/ProcessObject.h>
+#include <cpPlugins/BaseObjects/Widget.h>
 #include <itkObject.h>
 
 class vtkRenderWindowInteractor;
@@ -24,6 +25,7 @@ namespace cpPlugins
       typedef itk::SmartPointer< const Self > ConstPointer;
 
       typedef cpPlugins::BaseObjects::ProcessObject TProcess;
+      typedef cpPlugins::BaseObjects::Widget        TWidget;
       typedef cpPlugins::Interface::Plugins         TInterface;
 
       typedef std::map< std::string, TProcess::Pointer > TFilters;
@@ -51,7 +53,14 @@ namespace cpPlugins
       const TProcess* GetFilter(
         const std::string& name
         ) const;
+      TWidget* GetWidget(
+        const std::string& name
+        );
+      const TWidget* GetWidget(
+        const std::string& name
+        ) const;
       bool HasFilter( const std::string& name ) const;
+      bool HasWidget( const std::string& name ) const;
       TProcess* CreateFilter(
         const std::string& category,
         const std::string& filter,
diff --git a/plugins/Widgets/LineWidget.cxx b/plugins/Widgets/LineWidget.cxx
new file mode 100644 (file)
index 0000000..f73e100
--- /dev/null
@@ -0,0 +1,143 @@
+#include <plugins/Widgets/LineWidget.h>
+#include <cpPlugins/DataObjects/Image.h>
+#include <cpPlugins/DataObjects/Mesh.h>
+#include <cpExtensions/Visualization/WindowLevelImageActor.h>
+
+#include <vtkLineWidget2.h>
+#include <vtkImageData.h>
+#include <vtkImageMapper3D.h>
+#include <vtkInteractorObserver.h>
+#include <vtkLineRepresentation.h>
+#include <vtkMapper.h>
+#include <vtkRenderer.h>
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::LineWidget::
+Clear( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::LineWidget::
+SetEnabled( bool v )
+{
+}
+
+// -------------------------------------------------------------------------
+cpPluginsWidgets::LineWidget::
+LineWidget( )
+  : Superclass( )
+{
+  typedef cpPlugins::BaseObjects::DataObject _TData;
+  typedef cpPlugins::DataObjects::Mesh       _TMesh;
+
+  this->_ConfigureInput< _TData >( "Input", false, false );
+  this->_ConfigureOutput< _TMesh >( "Output" );
+  auto line = vtkSmartPointer< vtkPolyData >::New( );
+  line->SetPoints( vtkSmartPointer< vtkPoints >::New( ) );
+  line->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) );
+  line->SetLines( vtkSmartPointer< vtkCellArray >::New( ) );
+  line->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) );
+  line->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) );
+  this->GetOutput( "Output" )->SetVTK( line );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsWidgets::LineWidget::
+~LineWidget( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::LineWidget::
+_GenerateData( )
+{
+  if( this->m_Interactors.size( ) == 0 )
+    this->_Error( "Give at least one valid interactor." );
+
+  auto image = this->GetInputData< vtkImageData >( "Input" );
+  if( image != NULL ) this->_GD_Image( image );
+  else this->_Error( "Do not know how to create this widget." );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsWidgets::LineWidget::
+TValidProps cpPluginsWidgets::LineWidget::
+_GetValidActors( vtkObject* source )
+{
+  TValidProps valid_props;
+  auto iIt = this->m_Interactors.begin( );
+  for( ; iIt != this->m_Interactors.end( ); ++iIt )
+  {
+    auto r = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( );
+    if( r != NULL )
+    {
+      auto props = r->GetViewProps( );
+      if( props != NULL )
+      {
+        props->InitTraversal( );
+        while( vtkProp* prop = props->GetNextProp( ) )
+        {
+          auto image_actor = dynamic_cast< vtkImageSlice* >( prop );
+          auto mesh_actor = dynamic_cast< vtkActor* >( prop );
+          vtkObject* input = NULL;
+          if( image_actor != NULL )
+          {
+            auto mapper = image_actor->GetMapper( );
+            if( mapper != NULL )
+              input = mapper->GetInput( );
+          }
+          else if( mesh_actor != NULL )
+          {
+            auto mapper = mesh_actor->GetMapper( );
+            if( mapper != NULL )
+              input = mapper->GetInput( );
+
+          } // fi
+          if( input != NULL )
+            valid_props[ *iIt ].insert( prop );
+
+        } // elihw
+
+      } // fi
+
+    } // fi
+
+  } // rof
+  return( valid_props );
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::LineWidget::
+_GD_Image( vtkImageData* image )
+{
+  auto valid_props = this->_GetValidActors( image );
+  if( valid_props.size( ) == 0 )
+    this->_Error( "Given image does not have a valid associated actor." );
+
+  vtkSmartPointer< vtkLineWidget2 > wdg = this->GetVTK< vtkLineWidget2 >( );
+  if( wdg.GetPointer( ) == NULL )
+  {
+    auto rep = vtkSmartPointer< vtkLineRepresentation >::New( );
+
+    /* TODO
+       p[ 0 ] = 0.0; p[ 1 ] = -1.0; p[ 2 ] = 0.0;
+       rep->SetPoint1WorldPosition( p );
+       p[ 0 ] = 0.0; p[ 1 ] =  1.0; p[ 2 ] = 0.0;
+       rep->SetPoint2WorldPosition( p );
+       rep->PlaceWidget( pl3d_block0->GetBounds( ) );
+       rep->GetPolyData( seeds );
+       rep->DistanceAnnotationVisibilityOn( );
+    */
+
+    wdg = this->_CreateVTK< vtkLineWidget2 >( );
+    wdg->SetInteractor( valid_props.begin( )->first );
+    wdg->SetRepresentation( rep );
+    wdg->EnabledOn( );
+  }
+  else
+    dynamic_cast< vtkLineRepresentation* >( wdg->GetRepresentation( ) )->
+      GetPolyData( this->GetOutputData< vtkPolyData >( "Output" ) );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/Widgets/LineWidget.h b/plugins/Widgets/LineWidget.h
new file mode 100644 (file)
index 0000000..281cacd
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef __cpPluginsWidgets__LineWidget__h__
+#define __cpPluginsWidgets__LineWidget__h__
+
+#include <plugins/cpPluginsWidgets_Export.h>
+#include <cpPlugins/BaseObjects/Widget.h>
+#include <set>
+
+// -------------------------------------------------------------------------
+class vtkImageData;
+class vtkProp;
+
+// -------------------------------------------------------------------------
+namespace cpPluginsWidgets
+{
+  /**
+   */
+  class cpPluginsWidgets_EXPORT LineWidget
+    : public cpPlugins::BaseObjects::Widget
+  {
+    cpPluginsObject( LineWidget, cpPlugins::BaseObjects::Widget, Widgets );
+
+  public:
+    virtual void Clear( ) cpPlugins_OVERRIDE;
+    virtual void SetEnabled( bool v ) cpPlugins_OVERRIDE;
+
+  protected:
+    typedef std::set< vtkProp* > TProps;
+    typedef std::map< vtkRenderWindowInteractor*, TProps > TValidProps;
+
+  protected:
+    TValidProps _GetValidActors( vtkObject* source );
+    void _GD_Image( vtkImageData* image );
+  };
+
+} // ecapseman
+
+#endif // __cpPluginsWidgets__LineWidget__h__
+
+// eof - $RCSfile$
index 440005622c82bdb01b7be79868c6f31442320e75..dc5b6a56ad596abb5927fa8d75a444e309a6a14e 100644 (file)
 #include <vtkRenderWindow.h>
 #include <vtkSeedRepresentation.h>
 
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::SeedWidget::
+Clear( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::SeedWidget::
+SetEnabled( bool v )
+{
+}
+
 // -------------------------------------------------------------------------
 cpPluginsWidgets::SeedWidget::
 SeedWidget( )
index b119bb950e9eff1bba11b2e30855c42f7c4bc4ed..7449b948def012cd689370628dc9b586398bfd57 100644 (file)
@@ -38,6 +38,10 @@ namespace cpPluginsWidgets
     typedef cpExtensions::Interaction::ImageSlicePointPlacer   TPlacer;
     typedef cpExtensions::Visualization::WindowLevelImageActor TImageActor;
 
+  public:
+    virtual void Clear( ) cpPlugins_OVERRIDE;
+    virtual void SetEnabled( bool v ) cpPlugins_OVERRIDE;
+
   protected:
     /**
      */
index 1bba488aaa070f470e74a8148d017332f1b4bdbf..057d4e783d10e7407d6ec8ae5a62cc24b997242d 100644 (file)
@@ -7,6 +7,25 @@
 #include <vtkRenderer.h>
 #include <vtkSplineWidget.h>
 
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::SplineWidget::
+Clear( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsWidgets::SplineWidget::
+SetEnabled( bool v )
+{
+  auto wdg = this->GetVTK< vtkSplineWidget >( );
+  if( wdg != NULL )
+  {
+    wdg->SetEnabled( v );
+    wdg->GetInteractor( )->Render( );
+
+  } // fi
+}
+
 // -------------------------------------------------------------------------
 cpPluginsWidgets::SplineWidget::
 SplineWidget( )
@@ -49,7 +68,6 @@ _GenerateData( )
   if( this->m_Configured )
   {
     wdg->GetPolyData( this->m_Contour.GetPointer( ) );
-    wdg->Off( );
   }
   else
   {
@@ -111,7 +129,6 @@ _GenerateData( )
       );
     wdg->SetHandleSize( 0.005 );
     wdg->SetNumberOfHandles( 3 );
-    wdg->On( );
     this->m_Configured = true;
 
   } // fi
index 83b57b2c93c8d50eb83440a15a6ce802eac92f07..7eaeccdabeefcf1e6ff4698f827beed43a503e14 100644 (file)
@@ -29,6 +29,10 @@ namespace cpPluginsWidgets
   {
     cpPluginsObject( SplineWidget, cpPlugins::BaseObjects::Widget, Widgets );
 
+  public:
+    virtual void Clear( ) cpPlugins_OVERRIDE;
+    virtual void SetEnabled( bool v ) cpPlugins_OVERRIDE;
+
   protected:
     bool m_Configured;
     vtkSmartPointer< vtkPolyData > m_Contour;