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 vtkTypeMacro(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;}
211 void SetRegisterExtent(int [6]);
212 void GetRegisterExtent(int [6]);
218 std::string mFileName;
219 vvImage::Pointer mImage;
220 vvImage::Pointer mOverlay;
221 vvImage::Pointer mFusion;
222 vvImage::Pointer mVF;
224 vvLandmarks* mLandmarks;
226 int mFusionSequenceCode; //-1: not involved in a fusion sequence, 0: main sequence (CT), 1: secondary sequence (US)
228 // __________ Image coordinates accounting for spacing and origin
230 // | | vvImage.GetTransform()
232 // GetConcatenatedTransform() | _|___ VV world coordinates (mm) (displayed in VV) mCurrentBeforeSlicingTransform
234 // | | GetSlicingTransform()
236 // ___|__|___ VTK world coordinates (mm) (never displayed) mCurrent
238 vtkSmartPointer<vtkTransform> mSlicingTransform;
239 vtkSmartPointer<vtkImageReslice> mImageReslice;
240 vtkSmartPointer<vtkTransform> mConcatenatedTransform;
241 vtkSmartPointer<vtkImageReslice> mOverlayReslice;
242 vtkSmartPointer<vtkTransform> mConcatenatedOverlayTransform;
243 vtkSmartPointer<vtkImageMapToWindowLevelColors> mOverlayMapper;
244 vtkSmartPointer<vvBlendImageActor> mOverlayActor;
245 vtkSmartPointer<vtkImageReslice> mFusionReslice;
246 vtkSmartPointer<vtkTransform> mConcatenatedFusionTransform;
247 vtkSmartPointer<vtkImageMapToColors> mFusionMapper;
248 vtkSmartPointer<vtkImageActor> mFusionActor;
249 vtkSmartPointer<vtkCornerAnnotation> ca;
250 vtkSmartPointer<vtkCursor2D> crossCursor;
251 vtkSmartPointer<vtkPolyDataMapper2D> pdm;
252 vtkSmartPointer<vtkActor2D> pdmA;
253 vtkSmartPointer<vvGlyphSource> mArrow;
254 vtkSmartPointer<vtkAssignAttribute> mAAFilter;
255 vtkSmartPointer<vtkExtractVOI> mVOIFilter;
256 vtkSmartPointer<vvGlyph2D> mGlyphFilter;
257 vtkSmartPointer<vtkPolyDataMapper> mVFMapper;
258 vtkSmartPointer<vtkLookupTable> mVFColorLUT;
259 vtkSmartPointer<vtkActor> mVFActor;
260 vtkSmartPointer<vtkGlyph3D> mLandGlyph;
261 vtkSmartPointer<vtkCursor3D> mCross;
262 vtkSmartPointer<vvClipPolyData> mLandClipper;
263 vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
264 vtkSmartPointer<vtkActor> mLandActor;
265 std::vector<vtkSmartPointer<vtkCaptionActor2D> > mLandLabelActors;
266 vtkSmartPointer<vtkBox> mClipBox;
267 vtkSmartPointer<vtkScalarBarActor> legend;
268 std::vector<vvMeshActor*> mSurfaceCutActors;
271 int mCurrentFusionTSlice;
272 int mCurrentOverlayTSlice;
274 double mCurrentBeforeSlicingTransform[3];
281 bool mUseReducedExtent;
282 int * mReducedExtent;
283 int * mRegisterExtent;
284 bool mLinkOverlayWindowLevel;
285 bool showFusionLegend;
288 void UpdateOrientation();
289 void UpdateDisplayExtent();
290 void ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
291 vtkImageData *targetImage, int targetExtent[6]);
292 ///Sets the surfaces to be cut on the image slice: update the vtkCutter
293 void SetContourSlice();
295 // Visibility of the different elements that can be set from outside the object.
296 // Note that vvSlicer also check if the element is to be displayed according to
297 // the extent of the displayed object.
298 // These members have been introduced to fix Bug #1883.
299 bool mImageVisibility;
300 bool mOverlayVisibility;
301 bool mFusionVisibility;
303 bool mFirstSetSliceOrientation;