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