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