]> Creatis software - clitk.git/blob - vv/vvSlicer.h
Account for reslicing transform in overlay and fusion (contours and vf
[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   ///Reimplemented from vtkImageViewer2 to add polydata support
105   void SetSlice(int s);
106   int GetTMax() {
107     return (unsigned int)mImage->GetVTKImages().size() - 1;
108   }
109
110   void SetOpacity(double s);
111   void SetRenderWindow(int orientation, vtkRenderWindow * rw);
112   void SetDisplayMode(bool i);
113   void FlipHorizontalView();
114   void FlipVerticalView();
115   static double GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component=0);
116   void Render();
117   ///Sets the camera to fit the image in the window
118   void ResetCamera();
119
120   void SetVFSubSampling(int sub);
121   int GetVFSubSampling() {
122     return mSubSampling;
123   }
124   void SetVFScale(int scale);
125   void SetVFWidth(int width);
126   int GetVFScale() {
127     return mScale;
128   }
129   void SetVFLog(int log);
130   int GetVFLog() {
131     return mVFLog;
132   }
133
134   void SetFileName(std::string filename) {
135     mFileName = filename;
136   }
137   std::string GetFileName() {
138     return mFileName;
139   }
140
141   double* GetCursorPosition() {
142     return mCursor;
143   }
144
145   vtkTransform * GetSlicingTransform() { return mSlicingTransform; }
146   vtkTransform * GetConcatenatedTransform() { return mConcatenatedTransform; }
147   vtkTransform * GetConcatenatedFusionTransform() { return mConcatenatedFusionTransform; }
148   vtkTransform * GetConcatenatedOverlayTransform() { return mConcatenatedOverlayTransform; }
149
150   void SetCurrentPosition(double x, double y, double z, int t);
151   double* GetCurrentPosition();
152
153   void UpdateCursorPosition();
154   void SetCursorVisibility(bool s);
155
156   bool GetCursorVisibility();
157   void SetCursorColor(int r,int g, int b);
158
159   void SetCornerAnnotationVisibility(bool s);
160   bool GetCornerAnnotationVisibility();
161
162   void GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform);
163
164   void UpdateLandmarks();
165   void ForceUpdateDisplayExtent();
166
167   int* GetDisplayExtent();
168   /**Add a polydata to be displayed as a contour over the image
169    ** the contour can be propagated to a time sequence using a motion field */
170   void AddContour(vvMesh::Pointer contours,bool propagate);
171   ///Toggle temporal superposition of contours
172   void ToggleContourSuperposition();
173
174   virtual void SetColorWindow(double s);
175   virtual void SetColorLevel(double s);
176
177   double GetOverlayColorWindow();
178   double GetOverlayColorLevel();
179   bool GetLinkOverlayWindowLevel() { return mLinkOverlayWindowLevel; }
180
181   void SetOverlayColorWindow(double s);
182   void SetOverlayColorLevel(double s);
183   void SetLinkOverlayWindowLevel(bool b) { mLinkOverlayWindowLevel = b; }
184
185   /**
186    * When it is enabled, beware of a call to GetExtent.
187    * we must have setted mReducedExtent otherwhise random values
188    * are returned by GetExtent
189    * */
190   void EnableReducedExtent(bool b);
191   void SetReducedExtent(int * ext);
192
193   void ClipDisplayedExtent(int extent[6], int refExtent[6]);
194   int GetOrientation();
195   int * GetExtent();
196
197   double* GetVFColor() {
198     return mVFColor;
199   }
200   void SetVFColor(double r, double g, double b);
201
202 protected:
203   vvSlicer();
204   ~vvSlicer();
205
206   std::string mFileName;
207   vvImage::Pointer mImage;
208   vvImage::Pointer mOverlay;
209   vvImage::Pointer mFusion;
210   vvImage::Pointer mVF;
211
212   vvLandmarks* mLandmarks;
213
214   //                         __________ Image coordinates accounting for spacing and origin
215   //                            Λ  Λ
216   //                            |  | vvImage.GetTransform()
217   //                            |  |
218   // GetConcatenatedTransform() | _|___ VV world coordinates (mm) (displayed in VV)             mCurrentBeforeSlicingTransform
219   //                            |  Λ
220   //                            |  | GetSlicingTransform()
221   //                            |  |
222   //                         ___|__|___ VTK world coordinates (mm) (never displayed)            mCurrent
223
224   vtkSmartPointer<vtkTransform> mSlicingTransform;
225   vtkSmartPointer<vtkImageReslice> mImageReslice;
226   vtkSmartPointer<vtkTransform> mConcatenatedTransform;
227   vtkSmartPointer<vtkImageReslice> mOverlayReslice;
228   vtkSmartPointer<vtkTransform> mConcatenatedOverlayTransform;
229   vtkSmartPointer<vtkImageMapToWindowLevelColors> mOverlayMapper;
230   vtkSmartPointer<vvBlendImageActor> mOverlayActor;
231   vtkSmartPointer<vtkImageReslice> mFusionReslice;
232   vtkSmartPointer<vtkTransform> mConcatenatedFusionTransform;
233   vtkSmartPointer<vtkImageMapToColors> mFusionMapper;
234   vtkSmartPointer<vtkImageActor> mFusionActor;
235   vtkSmartPointer<vtkCornerAnnotation> ca;
236   vtkSmartPointer<vtkCursor2D> crossCursor;
237   vtkSmartPointer<vtkPolyDataMapper2D> pdm;
238   vtkSmartPointer<vtkActor2D> pdmA;
239   vtkSmartPointer<vvGlyphSource> mArrow;
240   vtkSmartPointer<vtkAssignAttribute> mAAFilter;
241   vtkSmartPointer<vtkExtractVOI> mVOIFilter;
242   vtkSmartPointer<vvGlyph2D> mGlyphFilter;
243   vtkSmartPointer<vtkPolyDataMapper> mVFMapper;
244   vtkSmartPointer<vtkLookupTable> mVFColorLUT;
245   vtkSmartPointer<vtkActor> mVFActor;
246   vtkSmartPointer<vtkGlyph3D> mLandGlyph;
247   vtkSmartPointer<vtkCursor3D> mCross;
248   vtkSmartPointer<vtkClipPolyData> mLandClipper;
249   vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
250   vtkSmartPointer<vtkActor> mLandActor;
251   vtkSmartPointer<vtkBox> mClipBox;
252   vtkSmartPointer<vtkScalarBarActor> legend;
253   std::vector<vvMeshActor*> mSurfaceCutActors;
254
255   int mCurrentTSlice;
256   int mCurrentFusionTSlice;
257   int mCurrentOverlayTSlice;
258   double mCurrent[3];
259   double mCurrentBeforeSlicingTransform[3];
260   double mCursor[4];
261   int mSubSampling;
262   int mScale;
263   int mVFLog;
264   int mVFWidth;
265   double mVFColor[3];
266   bool mUseReducedExtent;
267   int * mReducedExtent;
268   int * mInitialExtent;
269   bool mLinkOverlayWindowLevel;
270   bool showFusionLegend;
271
272 private:
273   void UpdateOrientation();
274   void UpdateDisplayExtent();
275   void ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
276                                         vtkImageData *targetImage, int targetExtent[6]);
277   ///Sets the surfaces to be cut on the image slice: update the vtkCutter
278   void SetContourSlice();
279
280
281 };
282 #endif