]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/ImageSliceActors.h
Widget integration (step 5/6): generic widget controller finished and tested on linux...
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageSliceActors.h
index 3991ab39419309ec5f7399ea3e3a7381128cf2a7..f940a90a6ff6f93a6af1dce2fda93df14c4c575e 100644 (file)
@@ -3,26 +3,20 @@
 
 #include <cpExtensions/cpExtensions_Export.h>
 
+#include <utility>
+#include <vector>
+
 #include <vtkActor.h>
 #include <vtkImageActor.h>
 #include <vtkImageSliceMapper.h>
+#include <vtkPlane.h>
 #include <vtkPolyData.h>
 #include <vtkPolyDataMapper.h>
 #include <vtkPropCollection.h>
 #include <vtkSmartPointer.h>
 #include <vtkTextActor.h>
 
-// -------------------------------------------------------------------------
-#define cpPlugins_ImageSliceActors( name, type )                        \
-  inline type* Get##name##Actor( ) const                                \
-  {                                                                     \
-    return(                                                             \
-      dynamic_cast< type* >(                                            \
-        const_cast< Self* >( this )->                                   \
-        GetItemAsObject( this->name##ActorIndex )                       \
-        )                                                               \
-      );                                                                \
-  }
+#include <cpExtensions/Visualization/ImageInteractorStyle.h>
 
 // -------------------------------------------------------------------------
 class vtkAlgorithmOutput;
@@ -30,66 +24,121 @@ class vtkImageData;
 
 // -------------------------------------------------------------------------
 namespace cpExtensions
+{
+  namespace Visualization
   {
-    namespace Visualization
+    /**
+     */
+    class cpExtensions_EXPORT ImageSliceActors
+      : public vtkPropCollection
     {
-      /**
-       */
-      class cpExtensions_EXPORT ImageSliceActors
-        : public vtkPropCollection
-      {
-      public:
-        typedef ImageSliceActors Self;
-
-      public:
-        vtkTypeMacro( ImageSliceActors, vtkPropCollection );
-
-        cpPlugins_ImageSliceActors( Image, vtkImageActor );
-        cpPlugins_ImageSliceActors( Text, vtkTextActor );
-        cpPlugins_ImageSliceActors( Plane, vtkActor );
-
-      public:
-        // Creation
-        static ImageSliceActors* New( );
-
-        void SetInputConnection( vtkAlgorithmOutput* aout, int axis );
-        void SetInputData( vtkImageData* data, int axis );
-
-        double* GetDisplayBounds( ) const;
-        void GetDisplayBounds( double bounds[ 6 ] ) const;
-
-        int GetAxis( ) const;
-        int GetSliceNumber( ) const;
-        int GetSliceNumberMinValue( ) const;
-        int GetSliceNumberMaxValue( ) const;
-        void SetSliceNumber( const int& slice );
-        void UpdateText( );
-
-      protected:
-        ImageSliceActors( );
-        virtual ~ImageSliceActors( );
-
-      private:
-        // Purposely not implemented
-        ImageSliceActors( const Self& );
-        Self& operator=( const Self& );
-
-      protected:
-        vtkSmartPointer< vtkImageSliceMapper > SliceMapper;
-        vtkSmartPointer< vtkPolyData >         PlaneSource;
-        vtkSmartPointer< vtkPolyDataMapper >   PlaneMapper;
-        char                                   TextBuffer[ 1024 ];
-
-        vtkSmartPointer< vtkImageActor > ImageActor;
-        vtkSmartPointer< vtkTextActor >  TextActor;
-        vtkSmartPointer< vtkActor >      PlaneActor;
-
-        unsigned int ImageActorIndex;
-        unsigned int TextActorIndex;
-        unsigned int PlaneActorIndex;
-      };
-
-    } // ecapseman
+    public:
+      typedef ImageSliceActors Self;
+
+    public:
+      vtkTypeMacro( ImageSliceActors, vtkPropCollection );
+
+    public:
+      // Creation
+      static ImageSliceActors* New( );
+
+      void AddInputConnection( vtkAlgorithmOutput* aout, int axis = 2 );
+      void AddInputData( vtkImageData* data, int axis = 2 );
+      void Clear( );
+
+      vtkInteractorStyle* GetStyle( );
+      const vtkInteractorStyle* GetStyle( ) const;
+
+      void PushActorsInto( vtkRenderer* renderer );
+      void PopActorsFrom( vtkRenderer* renderer );
+      unsigned int GetNumberOfImageActors( ) const;
+      vtkImageActor* GetImageActor( unsigned int id );
+      const vtkImageActor* GetImageActor( unsigned int id ) const;
+      vtkTextActor* GetTextActor( );
+      const vtkTextActor* GetTextActor( ) const;
+      vtkActor* GetPlaneActor( );
+      const vtkActor* GetPlaneActor( ) const;
+      vtkPlane* GetPlaneFunction( );
+      const vtkPlane* GetPlaneFunction( ) const;
+
+      void AddActor( vtkAlgorithm* algorithm, vtkActor* actor );
+      void AddActor( vtkActor* actor );
+
+      void SetInterpolate( bool v );
+      void InterpolateOn( );
+      void InterpolateOff( );
+
+      double* GetDisplayBounds( ) const;
+      void GetDisplayBounds( double bounds[ 6 ] ) const;
+
+      int GetAxis( ) const;
+      int GetSliceNumber( ) const;
+      int GetSliceNumberMinValue( ) const;
+      int GetSliceNumberMaxValue( ) const;
+      void SetSliceNumber( const int& slice );
+      void UpdateText( );
+      void UpdateText( double pos[ 3 ] );
+      void UpdateText( const double& w, const double& l );
+
+    protected:
+      ImageSliceActors( );
+      virtual ~ImageSliceActors( );
+
+      void _ConfigureNewInput( int axis );
+
+      // Events
+      static void _MouseMoveCommand(
+        void* data,
+        const ImageInteractorStyle::ButtonID& btn, double* pos,
+        bool alt, bool ctr, bool sft
+        );
+      static void _MouseClickCommand(
+        void* data,
+        const ImageInteractorStyle::ButtonID& btn, double* pos,
+        bool alt, bool ctr, bool sft
+        );
+      static void _MouseDoubleClickCommand(
+        void* data,
+        const ImageInteractorStyle::ButtonID& btn, double* pos,
+        bool alt, bool ctr, bool sft
+        );
+      static void _MouseWheelCommand(
+        void* data,
+        const int& dir, bool alt, bool ctr, bool sft
+        );
+      static void _KeyCommand(
+        void* data,
+        const char& key
+        );
+
+    private:
+      // Purposely not implemented
+      ImageSliceActors( const Self& );
+      Self& operator=( const Self& );
+
+    protected:
+      vtkSmartPointer< ImageInteractorStyle > Style;
+
+      // Multiple actors
+      std::vector< vtkSmartPointer< vtkImageSliceMapper > > SliceMappers;
+      std::vector< vtkSmartPointer< vtkImageActor > >       ImageActors;
+      bool Interpolate;
+
+      // Other associated actors
+      typedef std::pair< vtkAlgorithm*, vtkActor* > TAssociatedActor;
+      typedef std::vector< TAssociatedActor >       TAssociatedActors;
+      TAssociatedActors AssociatedActors;
+
+      // Unique objects
+      vtkSmartPointer< vtkPlane >          PlaneFunction;
+      vtkSmartPointer< vtkPolyData >       PlaneSource;
+      vtkSmartPointer< vtkPolyDataMapper > PlaneMapper;
+      char                                 TextBuffer[ 1024 ];
+      vtkSmartPointer< vtkTextActor >      TextActor;
+      vtkSmartPointer< vtkActor >          PlaneActor;
+    };
+
+  } // ecapseman
 
 } // ecapseman