]> Creatis software - clitk.git/blob - vv/vvSlicer.h
Merge branch 'master' of tux.creatis.insa-lyon.fr:clitk
[clitk.git] / vv / vvSlicer.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ===========================================================================**/
18 #ifndef __vvSlicer_h
19 #define __vvSlicer_h
20 #include <iostream>
21 #include <vector>
22
23 #include "vvLandmarks.h"
24 #include "vvImage.h"
25 #include "vvMesh.h"
26 #include "vvMeshActor.h"
27
28 #include <vtkSmartPointer.h>
29 #include <vtkImageViewer2.h>
30 #include <vtkImageReslice.h>
31 #include <vtkImageMapToColors.h>
32
33 class vtkActor;
34 class vtkActor2D;
35 class vtkCursor2D;
36 class vtkPolyDataMapper2D;
37 class vtkProperty2D;
38 class vtkClipPolyData;
39 class vtkImageActor;
40 class vvBlendImageActor;
41 class vtkBox;
42 class vtkCornerAnnotation;
43 class vtkExtractVOI;
44 class vtkPolyDataMapper2D;
45 class vtkPolyDataMapper;
46 class vtkGlyph3D;
47 class vvGlyph2D;
48 class vvGlyphSource;
49 class vtkCursor3D;
50 class vtkCutter;
51 class vtkAssignAttribute;
52 class vtkScalarBarActor;
53 class vtkTransform;
54 class vtkImageReslice;
55
56 class vvSlicer: public vtkImageViewer2
57 {
58 public:
59   static vvSlicer *New();
60   vtkTypeRevisionMacro(vvSlicer,vtkImageViewer2);
61   void PrintSelf(ostream& os, vtkIndent indent);
62
63   void SetImage(vvImage::Pointer inputImages);
64   vvImage::Pointer GetImage() {
65     return mImage;
66   }
67
68   void SetOverlay(vvImage::Pointer inputOverlay);
69   vvImage::Pointer GetOverlay() {
70     return mOverlay;
71   }
72   vtkImageMapToWindowLevelColors* GetOverlayMapper(); 
73   vvBlendImageActor* GetOverlayActor() ;
74   vtkImageMapToColors* GetFusionMapper() ;
75   vtkImageActor* GetFusionActor() ;
76   vtkActor* GetVFActor() ;
77   vtkCornerAnnotation* GetAnnotation();
78     
79   void SetFusion(vvImage::Pointer inputFusion);
80   vvImage::Pointer GetFusion() {
81     return mFusion;
82   }
83   void ShowFusionLegend(bool show) { showFusionLegend = show; }
84
85   /**Get/Set an actor's visibility ("overlay, fusion, vf, contour...")
86      Overlay index is the index of the overlay by type, eg. if there are
87      5 contours and we want to activate the 3rd one, pass 2 **/
88   bool GetActorVisibility(const std::string& actor_type, int overlay_index);
89   void SetActorVisibility(const std::string& actor_type, int overlay_index,bool vis);
90   void RemoveActor(const std::string& actor_type, int overlay_index);
91
92   void SetVF(vvImage::Pointer vf);
93   vvImage *GetVF() {
94     return mVF;
95   }
96
97   void SetLandmarks(vvLandmarks* landmarks);
98   void SetTSlice(int t);
99   void SetSliceOrientation(int orientation);
100   void AdjustResliceToSliceOrientation(vtkImageReslice *reslice);
101   int GetTSlice();
102   int GetFusionTSlice();
103   int GetOverlayTSlice();
104   int GetMaxCurrentTSlice();
105   ///Reimplemented from vtkImageViewer2 to add polydata support
106   void SetSlice(int s);
107   int GetTMax();
108
109   void SetOpacity(double s);
110   void SetRenderWindow(int orientation, vtkRenderWindow * rw);
111   void SetDisplayMode(bool i);
112   void FlipHorizontalView();
113   void FlipVerticalView();
114   static double GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component=0);
115   void Render();
116   ///Sets the camera to fit the image in the window
117   void ResetCamera();
118
119   void SetVFSubSampling(int sub);
120   int GetVFSubSampling() {
121     return mSubSampling;
122   }
123   void SetVFScale(int scale);
124   void SetVFWidth(int width);
125   int GetVFScale() {
126     return mScale;
127   }
128   void SetVFLog(int log);
129   int GetVFLog() {
130     return mVFLog;
131   }
132
133   void SetFileName(std::string filename) {
134     mFileName = filename;
135   }
136   std::string GetFileName() {
137     return mFileName;
138   }
139
140   double* GetCursorPosition() {
141     return mCursor;
142   }
143
144   vtkTransform * GetSlicingTransform() { return mSlicingTransform; }
145   vtkTransform * GetConcatenatedTransform() { return mConcatenatedTransform; }
146   vtkTransform * GetConcatenatedFusionTransform() { return mConcatenatedFusionTransform; }
147   vtkTransform * GetConcatenatedOverlayTransform() { return mConcatenatedOverlayTransform; }
148
149   void SetCurrentPosition(double x, double y, double z, int t);
150   double* GetCurrentPosition();
151
152   void UpdateCursorPosition();
153   void SetCursorVisibility(bool s);
154
155   bool GetCursorVisibility();
156   void SetCursorColor(int r,int g, int b);
157
158   void SetCornerAnnotationVisibility(bool s);
159   bool GetCornerAnnotationVisibility();
160
161   void GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform);
162
163   void UpdateLandmarks();
164   void ForceUpdateDisplayExtent();
165
166   int* GetDisplayExtent();
167   /**Add a polydata to be displayed as a contour over the image
168    ** the contour can be propagated to a time sequence using a motion field */
169   void AddContour(vvMesh::Pointer contours,bool propagate);
170   ///Toggle temporal superposition of contours
171   void ToggleContourSuperposition();
172
173   virtual void SetColorWindow(double s);
174   virtual void SetColorLevel(double s);
175
176   double GetOverlayColorWindow();
177   double GetOverlayColorLevel();
178   bool GetLinkOverlayWindowLevel() { return mLinkOverlayWindowLevel; }
179
180   void SetOverlayColorWindow(double s);
181   void SetOverlayColorLevel(double s);
182   void SetLinkOverlayWindowLevel(bool b) { mLinkOverlayWindowLevel = b; }
183
184   /**
185    * When it is enabled, beware of a call to GetExtent.
186    * we must have setted mReducedExtent otherwhise random values
187    * are returned by GetExtent
188    * */
189   void EnableReducedExtent(bool b);
190   void SetReducedExtent(int * ext);
191
192   void ClipDisplayedExtent(int extent[6], int refExtent[6]);
193   int GetOrientation();
194   int * GetExtent();
195
196   double* GetVFColor() {
197     return mVFColor;
198   }
199   void SetVFColor(double r, double g, double b);
200
201 protected:
202   vvSlicer();
203   ~vvSlicer();
204
205   std::string mFileName;
206   vvImage::Pointer mImage;
207   vvImage::Pointer mOverlay;
208   vvImage::Pointer mFusion;
209   vvImage::Pointer mVF;
210
211   vvLandmarks* mLandmarks;
212
213   //                         __________ Image coordinates accounting for spacing and origin
214   //                            Λ  Λ
215   //                            |  | vvImage.GetTransform()
216   //                            |  |
217   // GetConcatenatedTransform() | _|___ VV world coordinates (mm) (displayed in VV)             mCurrentBeforeSlicingTransform
218   //                            |  Λ
219   //                            |  | GetSlicingTransform()
220   //                            |  |
221   //                         ___|__|___ VTK world coordinates (mm) (never displayed)            mCurrent
222
223   vtkSmartPointer<vtkTransform> mSlicingTransform;
224   vtkSmartPointer<vtkImageReslice> mImageReslice;
225   vtkSmartPointer<vtkTransform> mConcatenatedTransform;
226   vtkSmartPointer<vtkImageReslice> mOverlayReslice;
227   vtkSmartPointer<vtkTransform> mConcatenatedOverlayTransform;
228   vtkSmartPointer<vtkImageMapToWindowLevelColors> mOverlayMapper;
229   vtkSmartPointer<vvBlendImageActor> mOverlayActor;
230   vtkSmartPointer<vtkImageReslice> mFusionReslice;
231   vtkSmartPointer<vtkTransform> mConcatenatedFusionTransform;
232   vtkSmartPointer<vtkImageMapToColors> mFusionMapper;
233   vtkSmartPointer<vtkImageActor> mFusionActor;
234   vtkSmartPointer<vtkCornerAnnotation> ca;
235   vtkSmartPointer<vtkCursor2D> crossCursor;
236   vtkSmartPointer<vtkPolyDataMapper2D> pdm;
237   vtkSmartPointer<vtkActor2D> pdmA;
238   vtkSmartPointer<vvGlyphSource> mArrow;
239   vtkSmartPointer<vtkAssignAttribute> mAAFilter;
240   vtkSmartPointer<vtkExtractVOI> mVOIFilter;
241   vtkSmartPointer<vvGlyph2D> mGlyphFilter;
242   vtkSmartPointer<vtkPolyDataMapper> mVFMapper;
243   vtkSmartPointer<vtkLookupTable> mVFColorLUT;
244   vtkSmartPointer<vtkActor> mVFActor;
245   vtkSmartPointer<vtkGlyph3D> mLandGlyph;
246   vtkSmartPointer<vtkCursor3D> mCross;
247   vtkSmartPointer<vtkClipPolyData> mLandClipper;
248   vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
249   vtkSmartPointer<vtkActor> mLandActor;
250   vtkSmartPointer<vtkBox> mClipBox;
251   vtkSmartPointer<vtkScalarBarActor> legend;
252   std::vector<vvMeshActor*> mSurfaceCutActors;
253
254   int mCurrentTSlice;
255   int mCurrentFusionTSlice;
256   int mCurrentOverlayTSlice;
257   double mCurrent[3];
258   double mCurrentBeforeSlicingTransform[3];
259   double mCursor[4];
260   int mSubSampling;
261   int mScale;
262   int mVFLog;
263   int mVFWidth;
264   double mVFColor[3];
265   bool mUseReducedExtent;
266   int * mReducedExtent;
267   int * mInitialExtent;
268   bool mLinkOverlayWindowLevel;
269   bool showFusionLegend;
270
271 private:
272   void UpdateOrientation();
273   void UpdateDisplayExtent();
274   void ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
275                                         vtkImageData *targetImage, int targetExtent[6]);
276   ///Sets the surfaces to be cut on the image slice: update the vtkCutter
277   void SetContourSlice();
278
279
280 };
281 #endif