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 ===========================================================================**/
24 #include <QString> //TODO delete
25 #include <QMessageBox>
27 #include "vvLandmarks.h"
30 #include "vvMeshActor.h"
31 #include "vvClipPolyData.h"
33 #include <vtkSmartPointer.h>
34 #include <vtkImageViewer2.h>
35 #include <vtkImageReslice.h>
36 #include <vtkImageMapToColors.h>
37 #include <vtkCaptionActor2D.h>
38 #include <vtkTransformPolyDataFilter.h>
43 class vtkPolyDataMapper2D;
45 class vtkClipPolyData;
47 class vvBlendImageActor;
49 class vtkCornerAnnotation;
51 class vtkPolyDataMapper2D;
52 class vtkPolyDataMapper;
58 class vtkAssignAttribute;
59 class vtkScalarBarActor;
61 class vtkImageReslice;
63 class vvSlicer: public QObject, public vtkImageViewer2 {
68 static vvSlicer *New();
69 vtkTypeMacro(vvSlicer,vtkImageViewer2);
70 void PrintSelf(ostream& os, vtkIndent indent);
72 void SetImage(vvImage::Pointer inputImages);
73 vvImage::Pointer GetImage() {
77 void SetOverlay(vvImage::Pointer inputOverlay);
78 vvImage::Pointer GetOverlay() {
81 vtkImageMapToWindowLevelColors* GetOverlayMapper();
82 vvBlendImageActor* GetOverlayActor() ;
83 vtkImageMapToColors* GetFusionMapper() ;
84 vtkImageActor* GetFusionActor() ;
85 vtkActor* GetVFActor() ;
86 vtkCornerAnnotation* GetAnnotation();
88 void SetFusion(vvImage::Pointer inputFusion, int fusionSequenceCode = -1);
89 vvImage::Pointer GetFusion() {
92 void ShowFusionLegend(bool show) { showFusionLegend = show; }
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);
101 void SetVF(vvImage::Pointer vf);
106 void SetLandmarks(vvLandmarks* landmarks);
107 void SetTSlice(int t, bool updateLinkedImages = true);
109 void SetFusionSequenceTSlice(int t);
111 void SetSliceOrientation(int orientation);
112 void AdjustResliceToSliceOrientation(vtkImageReslice *reslice);
114 int GetFusionTSlice();
115 int GetOverlayTSlice();
116 int GetMaxCurrentTSlice();
117 ///Reimplemented from vtkImageViewer2 to add polydata support
118 void SetSlice(int s);
121 void SetOpacity(double s);
122 void SetRenderWindow(int orientation, vtkRenderWindow * rw);
123 void SetDisplayMode(bool i);
124 void FlipHorizontalView();
125 void FlipVerticalView();
126 double GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component=0);
128 ///Sets the camera to fit the image in the window
131 void SetVFSubSampling(int sub);
132 int GetVFSubSampling() {
135 void SetVFScale(int scale);
136 void SetVFWidth(int width);
140 void SetVFLog(int log);
145 void SetFileName(std::string filename) {
146 mFileName = filename;
148 std::string GetFileName() {
152 double* GetCursorPosition() {
155 vtkTransform * GetSlicingTransform() { return mSlicingTransform; }
156 vtkTransform * GetConcatenatedTransform() { return mConcatenatedTransform; }
157 vtkTransform * GetConcatenatedFusionTransform() { return mConcatenatedFusionTransform; }
158 vtkTransform * GetConcatenatedOverlayTransform() { return mConcatenatedOverlayTransform; }
160 void SetCurrentPosition(double x, double y, double z, int t);
161 double* GetCurrentPosition();
163 void UpdateCursorPosition();
164 void SetCursorVisibility(bool s);
166 bool GetCursorVisibility();
167 void SetCursorColor(int r,int g, int b);
169 void SetCornerAnnotationVisibility(bool s);
170 bool GetCornerAnnotationVisibility();
172 void GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform);
174 void RemoveLandmarks();
175 void DisplayLandmarks();
176 void ForceUpdateDisplayExtent();
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 void SetInterpolationImageReslice(int interpolation);
186 virtual void SetColorWindow(double s);
187 virtual void SetColorLevel(double s);
189 double GetOverlayColorWindow();
190 double GetOverlayColorLevel();
191 bool GetLinkOverlayWindowLevel() { return mLinkOverlayWindowLevel; }
193 void SetOverlayColorWindow(double s);
194 void SetOverlayColorLevel(double s);
195 void SetLinkOverlayWindowLevel(bool b) { mLinkOverlayWindowLevel = b; }
198 * When it is enabled, beware of a call to GetExtent.
199 * we must have setted mReducedExtent otherwhise random values
200 * are returned by GetExtent
202 void EnableReducedExtent(bool b);
203 void SetReducedExtent(int * ext);
205 bool ClipDisplayedExtent(int extent[6], int refExtent[6]);
206 int GetOrientation();
209 double* GetVFColor() {
212 void SetVFColor(double r, double g, double b);
214 //necessary to flag the secondary sequence
215 void SetFusionSequenceCode(int code) {mFusionSequenceCode=code;}
216 void SetRegisterExtent(int [6]);
217 void GetRegisterExtent(int [6]);
219 void SetSlicerNumber(const int nbSlicer) {mSlicerNumber = nbSlicer;}
220 int GetSlicerNumber() const {return mSlicerNumber;}
223 void UpdateDisplayExtentBegin(int);
224 void UpdateDisplayExtentEnd(int);
230 std::string mFileName;
231 vvImage::Pointer mImage;
232 vvImage::Pointer mOverlay;
233 vvImage::Pointer mFusion;
234 vvImage::Pointer mVF;
236 vvLandmarks* mLandmarks;
238 int mFusionSequenceCode; //-1: not involved in a fusion sequence, 0: main sequence (CT), 1: secondary sequence (US)
240 // __________ Image coordinates accounting for spacing and origin
242 // | | vvImage.GetTransform()
244 // GetConcatenatedTransform() | _|___ VV world coordinates (mm) (displayed in VV) mCurrentBeforeSlicingTransform
246 // | | GetSlicingTransform()
248 // ___|__|___ VTK world coordinates (mm) (never displayed) mCurrent
250 vtkSmartPointer<vtkTransform> mSlicingTransform;
251 vtkSmartPointer<vtkTransformPolyDataFilter> mLandmarkTransform;
252 vtkSmartPointer<vtkImageReslice> mImageReslice;
253 vtkSmartPointer<vtkTransform> mConcatenatedTransform;
254 vtkSmartPointer<vtkImageReslice> mOverlayReslice;
255 vtkSmartPointer<vtkTransform> mConcatenatedOverlayTransform;
256 vtkSmartPointer<vtkImageMapToWindowLevelColors> mOverlayMapper;
257 vtkSmartPointer<vvBlendImageActor> mOverlayActor;
258 vtkSmartPointer<vtkImageReslice> mFusionReslice;
259 vtkSmartPointer<vtkTransform> mConcatenatedFusionTransform;
260 vtkSmartPointer<vtkImageMapToColors> mFusionMapper;
261 vtkSmartPointer<vtkImageActor> mFusionActor;
262 vtkSmartPointer<vtkCornerAnnotation> ca;
263 vtkSmartPointer<vtkCursor2D> crossCursor;
264 vtkSmartPointer<vtkPolyDataMapper2D> pdm;
265 vtkSmartPointer<vtkActor2D> pdmA;
266 vtkSmartPointer<vvGlyphSource> mArrow;
267 vtkSmartPointer<vtkAssignAttribute> mAAFilter;
268 vtkSmartPointer<vtkExtractVOI> mVOIFilter;
269 vtkSmartPointer<vvGlyph2D> mGlyphFilter;
270 vtkSmartPointer<vtkPolyDataMapper> mVFMapper;
271 vtkSmartPointer<vtkLookupTable> mVFColorLUT;
272 vtkSmartPointer<vtkActor> mVFActor;
273 vtkSmartPointer<vtkImageReslice> mVFReslice;
274 vtkSmartPointer<vtkTransform> mConcatenatedVFTransform;
275 vtkSmartPointer<vtkGlyph3D> mLandGlyph;
276 vtkSmartPointer<vtkCursor3D> mCross;
277 vtkSmartPointer<vvClipPolyData> mLandClipper;
278 vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
279 vtkSmartPointer<vtkActor> mLandActor;
280 std::vector<vtkSmartPointer<vtkCaptionActor2D> > mLandLabelActors;
281 vtkSmartPointer<vtkBox> mClipBox;
282 vtkSmartPointer<vtkScalarBarActor> legend;
283 std::vector<vvMeshActor*> mSurfaceCutActors;
287 int mCurrentFusionTSlice;
288 int mCurrentOverlayTSlice;
290 double mCurrentBeforeSlicingTransform[3];
297 bool mUseReducedExtent;
298 int * mReducedExtent;
299 int * mRegisterExtent;
300 bool mLinkOverlayWindowLevel;
301 bool showFusionLegend;
304 void UpdateOrientation();
305 void UpdateDisplayExtent();
306 void ConvertImageToImageDisplayExtent(vtkInformation *sourceImage, const int sourceExtent[6],
307 vtkImageData *targetImage, int targetExtent[6]);
308 void ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
309 vtkImageData *targetImage, int targetExtent[6]);
310 ///Sets the surfaces to be cut on the image slice: update the vtkCutter
311 void SetContourSlice();
313 // Visibility of the different elements that can be set from outside the object.
314 // Note that vvSlicer also check if the element is to be displayed according to
315 // the extent of the displayed object.
316 // These members have been introduced to fix Bug #1883.
317 bool mImageVisibility;
318 bool mOverlayVisibility;
319 bool mFusionVisibility;
321 bool mFirstSetSliceOrientation;