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