]> Creatis software - cpMesh.git/blob - appli/InteractiveDeformableMeshSegmentation/VolumeActors.h
First commit
[cpMesh.git] / appli / InteractiveDeformableMeshSegmentation / VolumeActors.h
1 #ifndef __IDMS__VOLUMEACTORS__H__
2 #define __IDMS__VOLUMEACTORS__H__
3
4 #include <set>
5
6 #include <vtkActor.h>
7 #include <vtkCutter.h>
8 #include <vtkImageActor.h>
9 #include <vtkImageMapToColors.h>
10 #include <vtkImageMapToWindowLevelColors.h>
11 #include <vtkImageSliceMapper.h>
12 #include <vtkOutlineSource.h>
13 #include <vtkPlane.h>
14 #include <vtkPlaneSource.h>
15 #include <vtkPolyDataMapper.h>
16 #include <vtkProp3D.h>
17 #include <vtkPropCollection.h>
18 #include <vtkSmartPointer.h>
19 #include <vtkSphereSource.h>
20 #include <vtkTextActor.h>
21 #include <vtkTransform.h>
22
23 class vtkImageData;
24 class vtkPlane;
25 class vtkRenderWindowInteractor;
26
27 // -------------------------------------------------------------------------
28 #define IDMS_VOLUMEACTORS( name, type )                                 \
29   inline type* Get##name##Actor( ) const                                \
30   {                                                                     \
31     return(                                                             \
32       dynamic_cast< type* >(                                            \
33         const_cast< Self* >( this )->                                   \
34         GetItemAsObject( this->name##Index )                            \
35         )                                                               \
36       );                                                                \
37   }
38
39 namespace idms
40 {
41   /**
42    */
43   class VolumeActors
44     : public vtkPropCollection
45   {
46   public:
47     typedef VolumeActors Self;
48
49   protected:
50     struct SliceActor
51     {
52       vtkSmartPointer< vtkImageSliceMapper > SliceMapper;
53       vtkSmartPointer< vtkImageSliceMapper > SegmentationSliceMapper;
54       vtkSmartPointer< vtkPlaneSource >      PlaneSource;
55       vtkSmartPointer< vtkPolyDataMapper >   PlaneMapper;
56       vtkSmartPointer< vtkActor >            PlaneActor;
57       vtkSmartPointer< vtkImageActor >       ImageActor;
58       vtkSmartPointer< vtkImageActor >       SegmentationActor;
59       vtkSmartPointer< vtkTextActor >        TextActor;
60       vtkSmartPointer< vtkPlane >            RegionCutterPlane;
61       vtkSmartPointer< vtkCutter >           RegionCutter;
62       vtkSmartPointer< vtkPolyDataMapper >   RegionCutterMapper;
63       vtkSmartPointer< vtkActor >            RegionCutterActor;
64       char TextBuffer[ 128 ];
65
66       SliceActor( );
67       void Configure( vtkAlgorithmOutput* aout, int axis );
68       void ConfigureRegion( vtkAlgorithmOutput* aout );
69       void SetSegmentation( vtkAlgorithmOutput* aout );
70       void SetSliceNumber( const int& slice );
71       void UpdateText( const double& w, const double& l );
72     };
73     typedef std::set< vtkRenderWindowInteractor* > TInteractors;
74
75   public:
76     vtkTypeMacro( VolumeActors, vtkPropCollection );
77
78     IDMS_VOLUMEACTORS( ImageOutline, vtkActor );
79     IDMS_VOLUMEACTORS( XPlane, vtkImageActor );
80     IDMS_VOLUMEACTORS( YPlane, vtkImageActor );
81     IDMS_VOLUMEACTORS( ZPlane, vtkImageActor );
82     IDMS_VOLUMEACTORS( XText, vtkTextActor );
83     IDMS_VOLUMEACTORS( YText, vtkTextActor );
84     IDMS_VOLUMEACTORS( ZText, vtkTextActor );
85     IDMS_VOLUMEACTORS( XBounds, vtkActor );
86     IDMS_VOLUMEACTORS( YBounds, vtkActor );
87     IDMS_VOLUMEACTORS( ZBounds, vtkActor );
88     IDMS_VOLUMEACTORS( Cursor, vtkActor );
89     IDMS_VOLUMEACTORS( Region, vtkActor );
90
91   public:
92     // Creation
93     static VolumeActors* New( );
94     void Configure(
95       vtkImageData* image,
96       vtkRenderWindowInteractor* xi,
97       vtkRenderWindowInteractor* yi,
98       vtkRenderWindowInteractor* zi
99       );
100     void SetSegmentation( vtkImageData* segmentation );
101     void AddAuxiliaryInteractor( vtkRenderWindowInteractor* i );
102
103     inline vtkImageData* GetImage( )
104       { return( this->Image ); }
105     inline vtkImageData* GetSegmentation( )
106       { return( this->Segmentation ); }
107     inline const vtkImageData* GetImage( ) const
108       { return( this->Image ); }
109     inline const vtkImageData* GetSegmentation( ) const
110       { return( this->Segmentation ); }
111
112     // Window/Level
113     double GetMinWindow( ) const;
114     double GetMaxWindow( ) const;
115     double GetMinLevel( ) const;
116     double GetMaxLevel( ) const;
117     double GetWindow( ) const;
118     double GetLevel( ) const;
119     void SetWindow( const double& w );
120     void SetLevel( const double& l );
121     void SetWindowLevel( const double& w, const double& l );
122     void ResetWindowLevel( );
123
124     // Slice access
125     vtkPlane* GetSlicePlane( const int& axis ) const;
126     int GetSliceNumberMinValue( const int& axis ) const;
127     int GetSliceNumberMaxValue( const int& axis ) const;
128     int GetSlice( const int& axis ) const;
129     void SetSlice( const int& axis, const int& slice );
130     void SetSlice( const int& axis, const double& slice );
131     void ResetSlices( );
132
133     // Seeds
134     void AddSeed( int idx[ 3 ] );
135     void AddSeed( double pos[ 3 ] );
136     unsigned int GetNumberOfSeeds( ) const;
137     void GetSeed( unsigned int i, int idx[ 3 ] ) const;
138
139     // 3D cursor and region
140     void SetCursorPosition( double pos[ 3 ] );
141     void ShowRegion( int a );
142     void HideRegion( int a );
143     void SetRegionPosition( double pos[ 3 ] );
144     void SetRegionRadius( double pos[ 3 ] );
145
146     // General accessors 
147     void GetImageBounds( double bounds[ 6 ] ) const;
148
149     // Rendering synch
150     void Render( );
151     void RenderAuxiliaryInteractors( );
152     void ResetCameras( );
153
154   protected:
155     VolumeActors( );
156     virtual ~VolumeActors( );
157
158   private:
159     // Purposely not implemented
160     VolumeActors( const Self& );
161     Self& operator=( const Self& );
162
163   protected:
164     vtkImageData* Image;
165     vtkImageData* Segmentation;
166     vtkRenderWindowInteractor* Interactors[ 3 ];
167     TInteractors AuxiliaryInteractors;
168
169     vtkSmartPointer< vtkImageMapToWindowLevelColors > ImageToWindowLevel;
170     vtkSmartPointer< vtkImageMapToColors >            SegmentationToColors;
171
172     vtkSmartPointer< vtkOutlineSource > ImageOutlineSource;
173     SliceActor Planes[ 3 ];
174
175     std::vector< std::vector< int > > Seeds;
176
177     vtkSmartPointer< vtkSphereSource >   Cursor;
178     vtkSmartPointer< vtkPolyDataMapper > CursorMapper;
179     vtkSmartPointer< vtkActor >          CursorActor;
180
181     vtkSmartPointer< vtkSphereSource >   Region;
182     vtkSmartPointer< vtkPolyDataMapper > RegionMapper;
183     vtkSmartPointer< vtkActor >          RegionActor;
184
185     unsigned int ImageOutlineIndex;
186     unsigned int XPlaneIndex;
187     unsigned int YPlaneIndex;
188     unsigned int ZPlaneIndex;
189     unsigned int XTextIndex;
190     unsigned int YTextIndex;
191     unsigned int ZTextIndex;
192     unsigned int XBoundsIndex;
193     unsigned int YBoundsIndex;
194     unsigned int ZBoundsIndex;
195     unsigned int CursorIndex;
196     unsigned int RegionIndex;
197   };
198
199 } // ecapseman
200
201 #endif // __IDMS__VOLUMEACTORS__H__
202
203 // eof - $RCSfile$