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