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