]> Creatis software - clitk.git/blob - vv/vvSlicer.h
Landmarks move with the image during registration
[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   static 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(int r,int g, int 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
185   virtual void SetColorWindow(double s);
186   virtual void SetColorLevel(double s);
187
188   double GetOverlayColorWindow();
189   double GetOverlayColorLevel();
190   bool GetLinkOverlayWindowLevel() { return mLinkOverlayWindowLevel; }
191
192   void SetOverlayColorWindow(double s);
193   void SetOverlayColorLevel(double s);
194   void SetLinkOverlayWindowLevel(bool b) { mLinkOverlayWindowLevel = b; }
195
196   /**
197    * When it is enabled, beware of a call to GetExtent.
198    * we must have setted mReducedExtent otherwhise random values
199    * are returned by GetExtent
200    * */
201   void EnableReducedExtent(bool b);
202   void SetReducedExtent(int * ext);
203
204   bool ClipDisplayedExtent(int extent[6], int refExtent[6]);
205   int GetOrientation();
206   int * GetExtent();
207
208   double* GetVFColor() {
209     return mVFColor;
210   }
211   void SetVFColor(double r, double g, double b);
212   
213   //necessary to flag the secondary sequence
214   void SetFusionSequenceCode(int code) {mFusionSequenceCode=code;}
215   void SetRegisterExtent(int [6]);
216   void GetRegisterExtent(int [6]);
217   
218   void SetSlicerNumber(const int nbSlicer) {mSlicerNumber = nbSlicer;}
219   int GetSlicerNumber() const {return mSlicerNumber;}
220   
221 signals:
222   void UpdateDisplayExtentBegin(int);
223   void UpdateDisplayExtentEnd(int);
224   
225 protected:
226   vvSlicer();
227   ~vvSlicer();
228
229   std::string mFileName;
230   vvImage::Pointer mImage;
231   vvImage::Pointer mOverlay;
232   vvImage::Pointer mFusion;
233   vvImage::Pointer mVF;
234
235   vvLandmarks* mLandmarks;
236
237   int mFusionSequenceCode; //-1: not involved in a fusion sequence, 0: main sequence (CT), 1: secondary sequence (US)
238
239   //                         __________ Image coordinates accounting for spacing and origin
240   //                            Λ  Λ
241   //                            |  | vvImage.GetTransform()
242   //                            |  |
243   // GetConcatenatedTransform() | _|___ VV world coordinates (mm) (displayed in VV)             mCurrentBeforeSlicingTransform
244   //                            |  Λ
245   //                            |  | GetSlicingTransform()
246   //                            |  |
247   //                         ___|__|___ VTK world coordinates (mm) (never displayed)            mCurrent
248
249   vtkSmartPointer<vtkTransform> mSlicingTransform;
250   vtkSmartPointer<vtkTransformPolyDataFilter> mLandmarkTransform;
251   vtkSmartPointer<vtkImageReslice> mImageReslice;
252   vtkSmartPointer<vtkTransform> mConcatenatedTransform;
253   vtkSmartPointer<vtkImageReslice> mOverlayReslice;
254   vtkSmartPointer<vtkTransform> mConcatenatedOverlayTransform;
255   vtkSmartPointer<vtkImageMapToWindowLevelColors> mOverlayMapper;
256   vtkSmartPointer<vvBlendImageActor> mOverlayActor;
257   vtkSmartPointer<vtkImageReslice> mFusionReslice;
258   vtkSmartPointer<vtkTransform> mConcatenatedFusionTransform;
259   vtkSmartPointer<vtkImageMapToColors> mFusionMapper;
260   vtkSmartPointer<vtkImageActor> mFusionActor;
261   vtkSmartPointer<vtkCornerAnnotation> ca;
262   vtkSmartPointer<vtkCursor2D> crossCursor;
263   vtkSmartPointer<vtkPolyDataMapper2D> pdm;
264   vtkSmartPointer<vtkActor2D> pdmA;
265   vtkSmartPointer<vvGlyphSource> mArrow;
266   vtkSmartPointer<vtkAssignAttribute> mAAFilter;
267   vtkSmartPointer<vtkExtractVOI> mVOIFilter;
268   vtkSmartPointer<vvGlyph2D> mGlyphFilter;
269   vtkSmartPointer<vtkPolyDataMapper> mVFMapper;
270   vtkSmartPointer<vtkLookupTable> mVFColorLUT;
271   vtkSmartPointer<vtkActor> mVFActor;
272   vtkSmartPointer<vtkGlyph3D> mLandGlyph;
273   vtkSmartPointer<vtkCursor3D> mCross;
274   vtkSmartPointer<vvClipPolyData> mLandClipper;
275   vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
276   vtkSmartPointer<vtkActor> mLandActor;
277   std::vector<vtkSmartPointer<vtkCaptionActor2D> > mLandLabelActors;
278   vtkSmartPointer<vtkBox> mClipBox;
279   vtkSmartPointer<vtkScalarBarActor> legend;
280   std::vector<vvMeshActor*> mSurfaceCutActors;
281
282   int mSlicerNumber;
283   int mCurrentTSlice;
284   int mCurrentFusionTSlice;
285   int mCurrentOverlayTSlice;
286   double mCurrent[3];
287   double mCurrentBeforeSlicingTransform[3];
288   double mCursor[4];
289   int mSubSampling;
290   int mScale;
291   int mVFLog;
292   int mVFWidth;
293   double mVFColor[3];
294   bool mUseReducedExtent;
295   int * mReducedExtent;
296   int * mRegisterExtent;
297   bool mLinkOverlayWindowLevel;
298   bool showFusionLegend;
299
300 private:
301   void UpdateOrientation();
302   void UpdateDisplayExtent();
303   void ConvertImageToImageDisplayExtent(vtkInformation *sourceImage, const int sourceExtent[6],
304                                         vtkImageData *targetImage, int targetExtent[6]);
305   void ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
306                                         vtkImageData *targetImage, int targetExtent[6]);
307   ///Sets the surfaces to be cut on the image slice: update the vtkCutter
308   void SetContourSlice();
309
310   // Visibility of the different elements that can be set from outside the object.
311   // Note that vvSlicer also check if the element is to be displayed according to
312   // the extent of the displayed object.
313   // These members have been introduced to fix Bug #1883.
314   bool mImageVisibility;
315   bool mOverlayVisibility;
316   bool mFusionVisibility;
317   bool mVFVisibility;
318   bool mFirstSetSliceOrientation;
319 };
320 #endif