]> Creatis software - clitk.git/blob - vv/vvSlicer.h
Merge branch 'master' of /home/dsarrut/clitk3.server
[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 "vvLandmarks.h"
24 #include "vvImage.h"
25 #include "vvMesh.h"
26 #include "vvMeshActor.h"
27
28 #include <vtkSmartPointer.h>
29 #include <vtkImageViewer2.h>
30 #include <vtkImageReslice.h>
31 #include <vtkImageMapToColors.h>
32
33 class vtkActor;
34 class vtkActor2D;
35 class vtkCursor2D;
36 class vtkPolyDataMapper2D;
37 class vtkProperty2D;
38 class vtkClipPolyData;
39 class vtkImageActor;
40 class vvBlendImageActor;
41 class vtkBox;
42 class vtkCornerAnnotation;
43 class vtkExtractVOI;
44 class vtkPolyDataMapper2D;
45 class vtkPolyDataMapper;
46 class vtkGlyph3D;
47 class vvGlyph2D;
48 class vvGlyphSource;
49 class vtkCursor3D;
50 class vtkCutter;
51 class vtkAssignAttribute;
52 class vtkScalarBarActor;
53 class vtkTransform;
54 class vtkImageReslice;
55
56 class vvSlicer: public vtkImageViewer2
57 {
58 public:
59   static vvSlicer *New();
60   vtkTypeRevisionMacro(vvSlicer,vtkImageViewer2);
61   void PrintSelf(ostream& os, vtkIndent indent);
62
63   void SetImage(vvImage::Pointer inputImages);
64   vvImage::Pointer GetImage() {
65     return mImage;
66   }
67
68   void SetOverlay(vvImage::Pointer inputOverlay);
69   vvImage::Pointer GetOverlay() {
70     return mOverlay;
71   }
72   vtkImageMapToWindowLevelColors* GetOverlayMapper(); 
73   vvBlendImageActor* GetOverlayActor() ;
74   vtkImageMapToColors* GetFusionMapper() ;
75   vtkImageActor* GetFusionActor() ;
76   vtkActor* GetVFActor() ;
77   vtkCornerAnnotation* GetAnnotation();
78     
79   void SetFusion(vvImage::Pointer inputFusion);
80   vvImage::Pointer GetFusion() {
81     return mFusion;
82   }
83
84   /**Get/Set an actor's visibility ("overlay, fusion, vf, contour...")
85      Overlay index is the index of the overlay by type, eg. if there are
86      5 contours and we want to activate the 3rd one, pass 2 **/
87   bool GetActorVisibility(const std::string& actor_type, int overlay_index);
88   void SetActorVisibility(const std::string& actor_type, int overlay_index,bool vis);
89   void RemoveActor(const std::string& actor_type, int overlay_index);
90
91   void SetVF(vvImage::Pointer vf);
92   vvImage *GetVF() {
93     return mVF;
94   }
95
96   void SetLandmarks(vvLandmarks* landmarks);
97   void SetTSlice(int t);
98   void SetSliceOrientation(int orientation);
99   void AdjustResliceToSliceOrientation(vtkImageReslice *reslice);
100   int GetTSlice();
101   ///Reimplemented from vtkImageViewer2 to add polydata support
102   void SetSlice(int s);
103   int GetTMax() {
104     return (unsigned int)mImage->GetVTKImages().size() - 1;
105   }
106
107   void SetOpacity(double s);
108   void SetRenderWindow(int orientation, vtkRenderWindow * rw);
109   void SetDisplayMode(bool i);
110   void FlipHorizontalView();
111   void FlipVerticalView();
112   static double GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component=0);
113   void Render();
114   ///Sets the camera to fit the image in the window
115   void ResetCamera();
116
117   void SetVFSubSampling(int sub);
118   int GetVFSubSampling() {
119     return mSubSampling;
120   }
121   void SetVFScale(int scale);
122   void SetVFWidth(int width);
123   int GetVFScale() {
124     return mScale;
125   }
126   void SetVFLog(int log);
127   int GetVFLog() {
128     return mVFLog;
129   }
130
131   void SetFileName(std::string filename) {
132     mFileName = filename;
133   }
134   std::string GetFileName() {
135     return mFileName;
136   }
137
138   double* GetCursorPosition() {
139     return mCursor;
140   }
141
142   void SetCurrentPosition(double x, double y, double z, int t);
143   double* GetCurrentPosition() {
144     return mCurrent;
145   }
146
147   void UpdateCursorPosition();
148   void SetCursorVisibility(bool s);
149
150   bool GetCursorVisibility();
151   void SetCursorColor(int r,int g, int b);
152
153   void SetCornerAnnotationVisibility(bool s);
154   bool GetCornerAnnotationVisibility();
155
156   void GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image);
157
158   void UpdateLandmarks();
159   void ForceUpdateDisplayExtent();
160
161   int* GetDisplayExtent();
162   /**Add a polydata to be displayed as a contour over the image
163    ** the contour can be propagated to a time sequence using a motion field */
164   void AddContour(vvMesh::Pointer contours,bool propagate);
165   ///Toggle temporal superposition of contours
166   void ToggleContourSuperposition();
167
168   virtual void SetColorWindow(double s);
169   virtual void SetColorLevel(double s);
170
171   double GetOverlayColorWindow();
172   double GetOverlayColorLevel();
173   bool GetLinkOverlayWindowLevel() { return mLinkOverlayWindowLevel; }
174
175   void SetOverlayColorWindow(double s);
176   void SetOverlayColorLevel(double s);
177   void SetLinkOverlayWindowLevel(bool b) { mLinkOverlayWindowLevel = b; }
178
179   /**
180    * When it is enabled, beware of a call to GetExtent.
181    * we must have setted mReducedExtent otherwhise random values
182    * are returned by GetExtent
183    * */
184   void EnableReducedExtent(bool b);
185   void SetReducedExtent(int * ext);
186
187   void ClipDisplayedExtent(int extent[6], int refExtent[6]);
188   int GetOrientation();
189   int * GetExtent();
190
191   double* GetVFColor() {
192     return mVFColor;
193   }
194   void SetVFColor(double r, double g, double b);
195
196 protected:
197   vvSlicer();
198   ~vvSlicer();
199
200   std::string mFileName;
201   vvImage::Pointer mImage;
202   vvImage::Pointer mOverlay;
203   vvImage::Pointer mFusion;
204   vvImage::Pointer mVF;
205
206   vvLandmarks* mLandmarks;
207
208   vtkSmartPointer<vtkImageReslice> mImageReslice;
209   vtkSmartPointer<vtkImageReslice> mOverlayReslice;
210   vtkSmartPointer<vtkImageMapToWindowLevelColors> mOverlayMapper;
211   vtkSmartPointer<vvBlendImageActor> mOverlayActor;
212   vtkSmartPointer<vtkImageReslice> mFusionReslice;
213   vtkSmartPointer<vtkImageMapToColors> mFusionMapper;
214   vtkSmartPointer<vtkImageActor> mFusionActor;
215   vtkSmartPointer<vtkCornerAnnotation> ca;
216   vtkSmartPointer<vtkCursor2D> crossCursor;
217   vtkSmartPointer<vtkPolyDataMapper2D> pdm;
218   vtkSmartPointer<vtkActor2D> pdmA;
219   vtkSmartPointer<vvGlyphSource> mArrow;
220   vtkSmartPointer<vtkAssignAttribute> mAAFilter;
221   vtkSmartPointer<vtkExtractVOI> mVOIFilter;
222   vtkSmartPointer<vvGlyph2D> mGlyphFilter;
223   vtkSmartPointer<vtkPolyDataMapper> mVFMapper;
224   vtkSmartPointer<vtkLookupTable> mVFColorLUT;
225   vtkSmartPointer<vtkActor> mVFActor;
226   vtkSmartPointer<vtkGlyph3D> mLandGlyph;
227   vtkSmartPointer<vtkCursor3D> mCross;
228   vtkSmartPointer<vtkClipPolyData> mLandClipper;
229   vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
230   vtkSmartPointer<vtkActor> mLandActor;
231   vtkSmartPointer<vtkBox> mClipBox;
232   vtkSmartPointer<vtkScalarBarActor> legend;
233   std::vector<vvMeshActor*> mSurfaceCutActors;
234
235   int mCurrentTSlice;
236   double mCurrent[3];
237   double mCursor[4];
238   int mSubSampling;
239   int mScale;
240   int mVFLog;
241   int mVFWidth;
242   double mVFColor[3];
243   bool mUseReducedExtent;
244   int * mReducedExtent;
245   int * mInitialExtent;
246   bool mLinkOverlayWindowLevel;
247
248 private:
249   void UpdateOrientation();
250   void UpdateDisplayExtent();
251   void ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
252                                         vtkImageData *targetImage, int targetExtent[6]);
253   ///Sets the surfaces to be cut on the image slice: update the vtkCutter
254   void SetContourSlice();
255
256
257 };
258 #endif