]> Creatis software - clitk.git/blob - vv/vvSlicer.h
Ensure the compilation with Qt4 and Qt5
[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   vtkTypeMacro(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   vtkTransform * GetSlicingTransform() { return mSlicingTransform; }
152   vtkTransform * GetConcatenatedTransform() { return mConcatenatedTransform; }
153   vtkTransform * GetConcatenatedFusionTransform() { return mConcatenatedFusionTransform; }
154   vtkTransform * GetConcatenatedOverlayTransform() { return mConcatenatedOverlayTransform; }
155
156   void SetCurrentPosition(double x, double y, double z, int t);
157   double* GetCurrentPosition();
158
159   void UpdateCursorPosition();
160   void SetCursorVisibility(bool s);
161
162   bool GetCursorVisibility();
163   void SetCursorColor(int r,int g, int b);
164
165   void SetCornerAnnotationVisibility(bool s);
166   bool GetCornerAnnotationVisibility();
167
168   void GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform);
169
170   void UpdateLandmarks();
171   void ForceUpdateDisplayExtent();
172
173   int* GetDisplayExtent();
174   /**Add a polydata to be displayed as a contour over the image
175    ** the contour can be propagated to a time sequence using a motion field */
176   void AddContour(vvMesh::Pointer contours,bool propagate);
177   ///Toggle temporal superposition of contours
178   void ToggleContourSuperposition();
179
180   virtual void SetColorWindow(double s);
181   virtual void SetColorLevel(double s);
182
183   double GetOverlayColorWindow();
184   double GetOverlayColorLevel();
185   bool GetLinkOverlayWindowLevel() { return mLinkOverlayWindowLevel; }
186
187   void SetOverlayColorWindow(double s);
188   void SetOverlayColorLevel(double s);
189   void SetLinkOverlayWindowLevel(bool b) { mLinkOverlayWindowLevel = b; }
190
191   /**
192    * When it is enabled, beware of a call to GetExtent.
193    * we must have setted mReducedExtent otherwhise random values
194    * are returned by GetExtent
195    * */
196   void EnableReducedExtent(bool b);
197   void SetReducedExtent(int * ext);
198
199   bool ClipDisplayedExtent(int extent[6], int refExtent[6]);
200   int GetOrientation();
201   int * GetExtent();
202
203   double* GetVFColor() {
204     return mVFColor;
205   }
206   void SetVFColor(double r, double g, double b);
207   
208   //necessary to flag the secondary sequence
209   void SetFusionSequenceCode(int code) {mFusionSequenceCode=code;}
210   void SetRegisterExtent(int [6]);
211   void GetRegisterExtent(int [6]);
212   
213 protected:
214   vvSlicer();
215   ~vvSlicer();
216
217   std::string mFileName;
218   vvImage::Pointer mImage;
219   vvImage::Pointer mOverlay;
220   vvImage::Pointer mFusion;
221   vvImage::Pointer mVF;
222
223   vvLandmarks* mLandmarks;
224
225   int mFusionSequenceCode; //-1: not involved in a fusion sequence, 0: main sequence (CT), 1: secondary sequence (US)
226
227   //                         __________ Image coordinates accounting for spacing and origin
228   //                            Λ  Λ
229   //                            |  | vvImage.GetTransform()
230   //                            |  |
231   // GetConcatenatedTransform() | _|___ VV world coordinates (mm) (displayed in VV)             mCurrentBeforeSlicingTransform
232   //                            |  Λ
233   //                            |  | GetSlicingTransform()
234   //                            |  |
235   //                         ___|__|___ VTK world coordinates (mm) (never displayed)            mCurrent
236
237   vtkSmartPointer<vtkTransform> mSlicingTransform;
238   vtkSmartPointer<vtkImageReslice> mImageReslice;
239   vtkSmartPointer<vtkTransform> mConcatenatedTransform;
240   vtkSmartPointer<vtkImageReslice> mOverlayReslice;
241   vtkSmartPointer<vtkTransform> mConcatenatedOverlayTransform;
242   vtkSmartPointer<vtkImageMapToWindowLevelColors> mOverlayMapper;
243   vtkSmartPointer<vvBlendImageActor> mOverlayActor;
244   vtkSmartPointer<vtkImageReslice> mFusionReslice;
245   vtkSmartPointer<vtkTransform> mConcatenatedFusionTransform;
246   vtkSmartPointer<vtkImageMapToColors> mFusionMapper;
247   vtkSmartPointer<vtkImageActor> mFusionActor;
248   vtkSmartPointer<vtkCornerAnnotation> ca;
249   vtkSmartPointer<vtkCursor2D> crossCursor;
250   vtkSmartPointer<vtkPolyDataMapper2D> pdm;
251   vtkSmartPointer<vtkActor2D> pdmA;
252   vtkSmartPointer<vvGlyphSource> mArrow;
253   vtkSmartPointer<vtkAssignAttribute> mAAFilter;
254   vtkSmartPointer<vtkExtractVOI> mVOIFilter;
255   vtkSmartPointer<vvGlyph2D> mGlyphFilter;
256   vtkSmartPointer<vtkPolyDataMapper> mVFMapper;
257   vtkSmartPointer<vtkLookupTable> mVFColorLUT;
258   vtkSmartPointer<vtkActor> mVFActor;
259   vtkSmartPointer<vtkGlyph3D> mLandGlyph;
260   vtkSmartPointer<vtkCursor3D> mCross;
261   vtkSmartPointer<vvClipPolyData> mLandClipper;
262   vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
263   vtkSmartPointer<vtkActor> mLandActor;
264   std::vector<vtkSmartPointer<vtkCaptionActor2D> > mLandLabelActors;
265   vtkSmartPointer<vtkBox> mClipBox;
266   vtkSmartPointer<vtkScalarBarActor> legend;
267   std::vector<vvMeshActor*> mSurfaceCutActors;
268
269   int mCurrentTSlice;
270   int mCurrentFusionTSlice;
271   int mCurrentOverlayTSlice;
272   double mCurrent[3];
273   double mCurrentBeforeSlicingTransform[3];
274   double mCursor[4];
275   int mSubSampling;
276   int mScale;
277   int mVFLog;
278   int mVFWidth;
279   double mVFColor[3];
280   bool mUseReducedExtent;
281   int * mReducedExtent;
282   int * mRegisterExtent;
283   bool mLinkOverlayWindowLevel;
284   bool showFusionLegend;
285
286 private:
287   void UpdateOrientation();
288   void UpdateDisplayExtent();
289   void ConvertImageToImageDisplayExtent(vtkInformation *sourceImage, const int sourceExtent[6],
290                                         vtkImageData *targetImage, int targetExtent[6]);
291   void ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
292                                         vtkImageData *targetImage, int targetExtent[6]);
293   ///Sets the surfaces to be cut on the image slice: update the vtkCutter
294   void SetContourSlice();
295
296   // Visibility of the different elements that can be set from outside the object.
297   // Note that vvSlicer also check if the element is to be displayed according to
298   // the extent of the displayed object.
299   // These members have been introduced to fix Bug #1883.
300   bool mImageVisibility;
301   bool mOverlayVisibility;
302   bool mFusionVisibility;
303   bool mVFVisibility;
304   bool mFirstSetSliceOrientation;
305 };
306 #endif