1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================**/
23 #include "vvLandmarks.h"
26 #include "vvMeshActor.h"
27 #include "vvClipPolyData.h"
29 #include <vtkSmartPointer.h>
30 #include <vtkImageViewer2.h>
31 #include <vtkImageReslice.h>
32 #include <vtkImageMapToColors.h>
33 #include <vtkCaptionActor2D.h>
38 class vtkPolyDataMapper2D;
40 class vtkClipPolyData;
42 class vvBlendImageActor;
44 class vtkCornerAnnotation;
46 class vtkPolyDataMapper2D;
47 class vtkPolyDataMapper;
53 class vtkAssignAttribute;
54 class vtkScalarBarActor;
56 class vtkImageReslice;
58 class vvSlicer: public vtkImageViewer2
61 static vvSlicer *New();
62 vtkTypeRevisionMacro(vvSlicer,vtkImageViewer2);
63 void PrintSelf(ostream& os, vtkIndent indent);
65 void SetImage(vvImage::Pointer inputImages);
66 vvImage::Pointer GetImage() {
70 void SetOverlay(vvImage::Pointer inputOverlay);
71 vvImage::Pointer GetOverlay() {
74 vtkImageMapToWindowLevelColors* GetOverlayMapper();
75 vvBlendImageActor* GetOverlayActor() ;
76 vtkImageMapToColors* GetFusionMapper() ;
77 vtkImageActor* GetFusionActor() ;
78 vtkActor* GetVFActor() ;
79 vtkCornerAnnotation* GetAnnotation();
81 void SetFusion(vvImage::Pointer inputFusion);
82 vvImage::Pointer GetFusion() {
85 void ShowFusionLegend(bool show) { showFusionLegend = show; }
87 /**Get/Set an actor's visibility ("overlay, fusion, vf, contour...")
88 Overlay index is the index of the overlay by type, eg. if there are
89 5 contours and we want to activate the 3rd one, pass 2 **/
90 bool GetActorVisibility(const std::string& actor_type, int overlay_index);
91 void SetActorVisibility(const std::string& actor_type, int overlay_index,bool vis);
92 void RemoveActor(const std::string& actor_type, int overlay_index);
94 void SetVF(vvImage::Pointer vf);
99 void SetLandmarks(vvLandmarks* landmarks);
100 void SetTSlice(int t);
101 void SetSliceOrientation(int orientation);
102 void AdjustResliceToSliceOrientation(vtkImageReslice *reslice);
104 int GetFusionTSlice();
105 int GetOverlayTSlice();
106 int GetMaxCurrentTSlice();
107 ///Reimplemented from vtkImageViewer2 to add polydata support
108 void SetSlice(int s);
111 void SetOpacity(double s);
112 void SetRenderWindow(int orientation, vtkRenderWindow * rw);
113 void SetDisplayMode(bool i);
114 void FlipHorizontalView();
115 void FlipVerticalView();
116 static double GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component=0);
118 ///Sets the camera to fit the image in the window
121 void SetVFSubSampling(int sub);
122 int GetVFSubSampling() {
125 void SetVFScale(int scale);
126 void SetVFWidth(int width);
130 void SetVFLog(int log);
135 void SetFileName(std::string filename) {
136 mFileName = filename;
138 std::string GetFileName() {
142 double* GetCursorPosition() {
146 vtkTransform * GetSlicingTransform() { return mSlicingTransform; }
147 vtkTransform * GetConcatenatedTransform() { return mConcatenatedTransform; }
148 vtkTransform * GetConcatenatedFusionTransform() { return mConcatenatedFusionTransform; }
149 vtkTransform * GetConcatenatedOverlayTransform() { return mConcatenatedOverlayTransform; }
151 void SetCurrentPosition(double x, double y, double z, int t);
152 double* GetCurrentPosition();
154 void UpdateCursorPosition();
155 void SetCursorVisibility(bool s);
157 bool GetCursorVisibility();
158 void SetCursorColor(int r,int g, int b);
160 void SetCornerAnnotationVisibility(bool s);
161 bool GetCornerAnnotationVisibility();
163 void GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform);
165 void UpdateLandmarks();
166 void ForceUpdateDisplayExtent();
168 int* GetDisplayExtent();
169 /**Add a polydata to be displayed as a contour over the image
170 ** the contour can be propagated to a time sequence using a motion field */
171 void AddContour(vvMesh::Pointer contours,bool propagate);
172 ///Toggle temporal superposition of contours
173 void ToggleContourSuperposition();
175 virtual void SetColorWindow(double s);
176 virtual void SetColorLevel(double s);
178 double GetOverlayColorWindow();
179 double GetOverlayColorLevel();
180 bool GetLinkOverlayWindowLevel() { return mLinkOverlayWindowLevel; }
182 void SetOverlayColorWindow(double s);
183 void SetOverlayColorLevel(double s);
184 void SetLinkOverlayWindowLevel(bool b) { mLinkOverlayWindowLevel = b; }
187 * When it is enabled, beware of a call to GetExtent.
188 * we must have setted mReducedExtent otherwhise random values
189 * are returned by GetExtent
191 void EnableReducedExtent(bool b);
192 void SetReducedExtent(int * ext);
194 void ClipDisplayedExtent(int extent[6], int refExtent[6]);
195 int GetOrientation();
198 double* GetVFColor() {
201 void SetVFColor(double r, double g, double b);
207 std::string mFileName;
208 vvImage::Pointer mImage;
209 vvImage::Pointer mOverlay;
210 vvImage::Pointer mFusion;
211 vvImage::Pointer mVF;
213 vvLandmarks* mLandmarks;
215 // __________ Image coordinates accounting for spacing and origin
217 // | | vvImage.GetTransform()
219 // GetConcatenatedTransform() | _|___ VV world coordinates (mm) (displayed in VV) mCurrentBeforeSlicingTransform
221 // | | GetSlicingTransform()
223 // ___|__|___ VTK world coordinates (mm) (never displayed) mCurrent
225 vtkSmartPointer<vtkTransform> mSlicingTransform;
226 vtkSmartPointer<vtkImageReslice> mImageReslice;
227 vtkSmartPointer<vtkTransform> mConcatenatedTransform;
228 vtkSmartPointer<vtkImageReslice> mOverlayReslice;
229 vtkSmartPointer<vtkTransform> mConcatenatedOverlayTransform;
230 vtkSmartPointer<vtkImageMapToWindowLevelColors> mOverlayMapper;
231 vtkSmartPointer<vvBlendImageActor> mOverlayActor;
232 vtkSmartPointer<vtkImageReslice> mFusionReslice;
233 vtkSmartPointer<vtkTransform> mConcatenatedFusionTransform;
234 vtkSmartPointer<vtkImageMapToColors> mFusionMapper;
235 vtkSmartPointer<vtkImageActor> mFusionActor;
236 vtkSmartPointer<vtkCornerAnnotation> ca;
237 vtkSmartPointer<vtkCursor2D> crossCursor;
238 vtkSmartPointer<vtkPolyDataMapper2D> pdm;
239 vtkSmartPointer<vtkActor2D> pdmA;
240 vtkSmartPointer<vvGlyphSource> mArrow;
241 vtkSmartPointer<vtkAssignAttribute> mAAFilter;
242 vtkSmartPointer<vtkExtractVOI> mVOIFilter;
243 vtkSmartPointer<vvGlyph2D> mGlyphFilter;
244 vtkSmartPointer<vtkPolyDataMapper> mVFMapper;
245 vtkSmartPointer<vtkLookupTable> mVFColorLUT;
246 vtkSmartPointer<vtkActor> mVFActor;
247 vtkSmartPointer<vtkGlyph3D> mLandGlyph;
248 vtkSmartPointer<vtkCursor3D> mCross;
249 vtkSmartPointer<vvClipPolyData> mLandClipper;
250 vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
251 vtkSmartPointer<vtkActor> mLandActor;
252 std::vector<vtkSmartPointer<vtkCaptionActor2D> > mLandLabelActors;
253 vtkSmartPointer<vtkBox> mClipBox;
254 vtkSmartPointer<vtkScalarBarActor> legend;
255 std::vector<vvMeshActor*> mSurfaceCutActors;
258 int mCurrentFusionTSlice;
259 int mCurrentOverlayTSlice;
261 double mCurrentBeforeSlicingTransform[3];
268 bool mUseReducedExtent;
269 int * mReducedExtent;
270 int * mInitialExtent;
271 bool mLinkOverlayWindowLevel;
272 bool showFusionLegend;
275 void UpdateOrientation();
276 void UpdateDisplayExtent();
277 void ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
278 vtkImageData *targetImage, int targetExtent[6]);
279 ///Sets the surfaces to be cut on the image slice: update the vtkCutter
280 void SetContourSlice();