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 <QString> //TODO delete
24 #include <QMessageBox>
26 #include "vvLandmarks.h"
29 #include "vvMeshActor.h"
30 #include "vvClipPolyData.h"
32 #include <vtkSmartPointer.h>
33 #include <vtkImageViewer2.h>
34 #include <vtkImageReslice.h>
35 #include <vtkImageMapToColors.h>
36 #include <vtkCaptionActor2D.h>
41 class vtkPolyDataMapper2D;
43 class vtkClipPolyData;
45 class vvBlendImageActor;
47 class vtkCornerAnnotation;
49 class vtkPolyDataMapper2D;
50 class vtkPolyDataMapper;
56 class vtkAssignAttribute;
57 class vtkScalarBarActor;
59 class vtkImageReslice;
61 class vvSlicer: public vtkImageViewer2
64 static vvSlicer *New();
65 vtkTypeRevisionMacro(vvSlicer,vtkImageViewer2);
66 void PrintSelf(ostream& os, vtkIndent indent);
68 void SetImage(vvImage::Pointer inputImages);
69 vvImage::Pointer GetImage() {
73 void SetOverlay(vvImage::Pointer inputOverlay);
74 vvImage::Pointer GetOverlay() {
77 vtkImageMapToWindowLevelColors* GetOverlayMapper();
78 vvBlendImageActor* GetOverlayActor() ;
79 vtkImageMapToColors* GetFusionMapper() ;
80 vtkImageActor* GetFusionActor() ;
81 vtkActor* GetVFActor() ;
82 vtkCornerAnnotation* GetAnnotation();
84 void SetFusion(vvImage::Pointer inputFusion, int fusionSequenceCode = -1);
85 vvImage::Pointer GetFusion() {
88 void ShowFusionLegend(bool show) { showFusionLegend = show; }
90 /**Get/Set an actor's visibility ("overlay, fusion, vf, contour...")
91 Overlay index is the index of the overlay by type, eg. if there are
92 5 contours and we want to activate the 3rd one, pass 2 **/
93 bool GetActorVisibility(const std::string& actor_type, int overlay_index);
94 void SetActorVisibility(const std::string& actor_type, int overlay_index,bool vis);
95 void RemoveActor(const std::string& actor_type, int overlay_index);
97 void SetVF(vvImage::Pointer vf);
102 void SetLandmarks(vvLandmarks* landmarks);
103 void SetTSlice(int t, bool updateLinkedImages = true);
105 void SetFusionSequenceTSlice(int t);
107 void SetSliceOrientation(int orientation);
108 void AdjustResliceToSliceOrientation(vtkImageReslice *reslice);
110 int GetFusionTSlice();
111 int GetOverlayTSlice();
112 int GetMaxCurrentTSlice();
113 ///Reimplemented from vtkImageViewer2 to add polydata support
114 void SetSlice(int s);
117 void SetOpacity(double s);
118 void SetRenderWindow(int orientation, vtkRenderWindow * rw);
119 void SetDisplayMode(bool i);
120 void FlipHorizontalView();
121 void FlipVerticalView();
122 static double GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component=0);
124 ///Sets the camera to fit the image in the window
127 void SetVFSubSampling(int sub);
128 int GetVFSubSampling() {
131 void SetVFScale(int scale);
132 void SetVFWidth(int width);
136 void SetVFLog(int log);
141 void SetFileName(std::string filename) {
142 mFileName = filename;
144 std::string GetFileName() {
148 double* GetCursorPosition() {
152 vtkTransform * GetSlicingTransform() { return mSlicingTransform; }
153 vtkTransform * GetConcatenatedTransform() { return mConcatenatedTransform; }
154 vtkTransform * GetConcatenatedFusionTransform() { return mConcatenatedFusionTransform; }
155 vtkTransform * GetConcatenatedOverlayTransform() { return mConcatenatedOverlayTransform; }
157 void SetCurrentPosition(double x, double y, double z, int t);
158 double* GetCurrentPosition();
160 void UpdateCursorPosition();
161 void SetCursorVisibility(bool s);
163 bool GetCursorVisibility();
164 void SetCursorColor(int r,int g, int b);
166 void SetCornerAnnotationVisibility(bool s);
167 bool GetCornerAnnotationVisibility();
169 void GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform);
171 void UpdateLandmarks();
172 void ForceUpdateDisplayExtent();
174 int* GetDisplayExtent();
175 /**Add a polydata to be displayed as a contour over the image
176 ** the contour can be propagated to a time sequence using a motion field */
177 void AddContour(vvMesh::Pointer contours,bool propagate);
178 ///Toggle temporal superposition of contours
179 void ToggleContourSuperposition();
181 virtual void SetColorWindow(double s);
182 virtual void SetColorLevel(double s);
184 double GetOverlayColorWindow();
185 double GetOverlayColorLevel();
186 bool GetLinkOverlayWindowLevel() { return mLinkOverlayWindowLevel; }
188 void SetOverlayColorWindow(double s);
189 void SetOverlayColorLevel(double s);
190 void SetLinkOverlayWindowLevel(bool b) { mLinkOverlayWindowLevel = b; }
193 * When it is enabled, beware of a call to GetExtent.
194 * we must have setted mReducedExtent otherwhise random values
195 * are returned by GetExtent
197 void EnableReducedExtent(bool b);
198 void SetReducedExtent(int * ext);
200 bool ClipDisplayedExtent(int extent[6], int refExtent[6]);
201 int GetOrientation();
204 double* GetVFColor() {
207 void SetVFColor(double r, double g, double b);
209 //necessary to flag the secondary sequence
210 void SetFusionSequenceCode(int code) {mFusionSequenceCode=code;}
215 std::string mFileName;
216 vvImage::Pointer mImage;
217 vvImage::Pointer mOverlay;
218 vvImage::Pointer mFusion;
219 vvImage::Pointer mVF;
221 vvLandmarks* mLandmarks;
223 int mFusionSequenceCode; //-1: not involved in a fusion sequence, 0: main sequence (CT), 1: secondary sequence (US)
225 // __________ Image coordinates accounting for spacing and origin
227 // | | vvImage.GetTransform()
229 // GetConcatenatedTransform() | _|___ VV world coordinates (mm) (displayed in VV) mCurrentBeforeSlicingTransform
231 // | | GetSlicingTransform()
233 // ___|__|___ VTK world coordinates (mm) (never displayed) mCurrent
235 vtkSmartPointer<vtkTransform> mSlicingTransform;
236 vtkSmartPointer<vtkImageReslice> mImageReslice;
237 vtkSmartPointer<vtkTransform> mConcatenatedTransform;
238 vtkSmartPointer<vtkImageReslice> mOverlayReslice;
239 vtkSmartPointer<vtkTransform> mConcatenatedOverlayTransform;
240 vtkSmartPointer<vtkImageMapToWindowLevelColors> mOverlayMapper;
241 vtkSmartPointer<vvBlendImageActor> mOverlayActor;
242 vtkSmartPointer<vtkImageReslice> mFusionReslice;
243 vtkSmartPointer<vtkTransform> mConcatenatedFusionTransform;
244 vtkSmartPointer<vtkImageMapToColors> mFusionMapper;
245 vtkSmartPointer<vtkImageActor> mFusionActor;
246 vtkSmartPointer<vtkCornerAnnotation> ca;
247 vtkSmartPointer<vtkCursor2D> crossCursor;
248 vtkSmartPointer<vtkPolyDataMapper2D> pdm;
249 vtkSmartPointer<vtkActor2D> pdmA;
250 vtkSmartPointer<vvGlyphSource> mArrow;
251 vtkSmartPointer<vtkAssignAttribute> mAAFilter;
252 vtkSmartPointer<vtkExtractVOI> mVOIFilter;
253 vtkSmartPointer<vvGlyph2D> mGlyphFilter;
254 vtkSmartPointer<vtkPolyDataMapper> mVFMapper;
255 vtkSmartPointer<vtkLookupTable> mVFColorLUT;
256 vtkSmartPointer<vtkActor> mVFActor;
257 vtkSmartPointer<vtkGlyph3D> mLandGlyph;
258 vtkSmartPointer<vtkCursor3D> mCross;
259 vtkSmartPointer<vvClipPolyData> mLandClipper;
260 vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
261 vtkSmartPointer<vtkActor> mLandActor;
262 std::vector<vtkSmartPointer<vtkCaptionActor2D> > mLandLabelActors;
263 vtkSmartPointer<vtkBox> mClipBox;
264 vtkSmartPointer<vtkScalarBarActor> legend;
265 std::vector<vvMeshActor*> mSurfaceCutActors;
268 int mCurrentFusionTSlice;
269 int mCurrentOverlayTSlice;
271 double mCurrentBeforeSlicingTransform[3];
278 bool mUseReducedExtent;
279 int * mReducedExtent;
280 int * mInitialExtent;
281 bool mLinkOverlayWindowLevel;
282 bool showFusionLegend;
285 void UpdateOrientation();
286 void UpdateDisplayExtent();
287 void ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
288 vtkImageData *targetImage, int targetExtent[6]);
289 ///Sets the surfaces to be cut on the image slice: update the vtkCutter
290 void SetContourSlice();
292 // Visibility of the different elements that can be set from outside the object.
293 // Note that vvSlicer also check if the element is to be displayed according to
294 // the extent of the displayed object.
295 // These members have been introduced to fix Bug #1883.
296 bool mImageVisibility;
297 bool mOverlayVisibility;
298 bool mFusionVisibility;
300 bool mFirstSetSliceOrientation;