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