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() {
151 vtkTransform * GetSlicingTransform() { return mSlicingTransform; }
152 vtkTransform * GetConcatenatedTransform() { return mConcatenatedTransform; }
153 vtkTransform * GetConcatenatedFusionTransform() { return mConcatenatedFusionTransform; }
154 vtkTransform * GetConcatenatedOverlayTransform() { return mConcatenatedOverlayTransform; }
156 void SetCurrentPosition(double x, double y, double z, int t);
157 double* GetCurrentPosition();
159 void UpdateCursorPosition();
160 void SetCursorVisibility(bool s);
162 bool GetCursorVisibility();
163 void SetCursorColor(int r,int g, int b);
165 void SetCornerAnnotationVisibility(bool s);
166 bool GetCornerAnnotationVisibility();
168 void GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform);
170 void UpdateLandmarks();
171 void ForceUpdateDisplayExtent();
173 int* GetDisplayExtent();
174 /**Add a polydata to be displayed as a contour over the image
175 ** the contour can be propagated to a time sequence using a motion field */
176 void AddContour(vvMesh::Pointer contours,bool propagate);
177 ///Toggle temporal superposition of contours
178 void ToggleContourSuperposition();
180 virtual void SetColorWindow(double s);
181 virtual void SetColorLevel(double s);
183 double GetOverlayColorWindow();
184 double GetOverlayColorLevel();
185 bool GetLinkOverlayWindowLevel() { return mLinkOverlayWindowLevel; }
187 void SetOverlayColorWindow(double s);
188 void SetOverlayColorLevel(double s);
189 void SetLinkOverlayWindowLevel(bool b) { mLinkOverlayWindowLevel = b; }
192 * When it is enabled, beware of a call to GetExtent.
193 * we must have setted mReducedExtent otherwhise random values
194 * are returned by GetExtent
196 void EnableReducedExtent(bool b);
197 void SetReducedExtent(int * ext);
199 bool ClipDisplayedExtent(int extent[6], int refExtent[6]);
200 int GetOrientation();
203 double* GetVFColor() {
206 void SetVFColor(double r, double g, double b);
208 //necessary to flag the secondary sequence
209 void SetFusionSequenceCode(int code) {mFusionSequenceCode=code;}
210 void SetRegisterExtent(int [6]);
211 void GetRegisterExtent(int [6]);
217 std::string mFileName;
218 vvImage::Pointer mImage;
219 vvImage::Pointer mOverlay;
220 vvImage::Pointer mFusion;
221 vvImage::Pointer mVF;
223 vvLandmarks* mLandmarks;
225 int mFusionSequenceCode; //-1: not involved in a fusion sequence, 0: main sequence (CT), 1: secondary sequence (US)
227 // __________ Image coordinates accounting for spacing and origin
229 // | | vvImage.GetTransform()
231 // GetConcatenatedTransform() | _|___ VV world coordinates (mm) (displayed in VV) mCurrentBeforeSlicingTransform
233 // | | GetSlicingTransform()
235 // ___|__|___ VTK world coordinates (mm) (never displayed) mCurrent
237 vtkSmartPointer<vtkTransform> mSlicingTransform;
238 vtkSmartPointer<vtkImageReslice> mImageReslice;
239 vtkSmartPointer<vtkTransform> mConcatenatedTransform;
240 vtkSmartPointer<vtkImageReslice> mOverlayReslice;
241 vtkSmartPointer<vtkTransform> mConcatenatedOverlayTransform;
242 vtkSmartPointer<vtkImageMapToWindowLevelColors> mOverlayMapper;
243 vtkSmartPointer<vvBlendImageActor> mOverlayActor;
244 vtkSmartPointer<vtkImageReslice> mFusionReslice;
245 vtkSmartPointer<vtkTransform> mConcatenatedFusionTransform;
246 vtkSmartPointer<vtkImageMapToColors> mFusionMapper;
247 vtkSmartPointer<vtkImageActor> mFusionActor;
248 vtkSmartPointer<vtkCornerAnnotation> ca;
249 vtkSmartPointer<vtkCursor2D> crossCursor;
250 vtkSmartPointer<vtkPolyDataMapper2D> pdm;
251 vtkSmartPointer<vtkActor2D> pdmA;
252 vtkSmartPointer<vvGlyphSource> mArrow;
253 vtkSmartPointer<vtkAssignAttribute> mAAFilter;
254 vtkSmartPointer<vtkExtractVOI> mVOIFilter;
255 vtkSmartPointer<vvGlyph2D> mGlyphFilter;
256 vtkSmartPointer<vtkPolyDataMapper> mVFMapper;
257 vtkSmartPointer<vtkLookupTable> mVFColorLUT;
258 vtkSmartPointer<vtkActor> mVFActor;
259 vtkSmartPointer<vtkGlyph3D> mLandGlyph;
260 vtkSmartPointer<vtkCursor3D> mCross;
261 vtkSmartPointer<vvClipPolyData> mLandClipper;
262 vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
263 vtkSmartPointer<vtkActor> mLandActor;
264 std::vector<vtkSmartPointer<vtkCaptionActor2D> > mLandLabelActors;
265 vtkSmartPointer<vtkBox> mClipBox;
266 vtkSmartPointer<vtkScalarBarActor> legend;
267 std::vector<vvMeshActor*> mSurfaceCutActors;
270 int mCurrentFusionTSlice;
271 int mCurrentOverlayTSlice;
273 double mCurrentBeforeSlicingTransform[3];
280 bool mUseReducedExtent;
281 int * mReducedExtent;
282 int * mRegisterExtent;
283 bool mLinkOverlayWindowLevel;
284 bool showFusionLegend;
287 void UpdateOrientation();
288 void UpdateDisplayExtent();
289 void ConvertImageToImageDisplayExtent(vtkInformation *sourceImage, const int sourceExtent[6],
290 vtkImageData *targetImage, int targetExtent[6]);
291 ///Sets the surfaces to be cut on the image slice: update the vtkCutter
292 void SetContourSlice();
294 // Visibility of the different elements that can be set from outside the object.
295 // Note that vvSlicer also check if the element is to be displayed according to
296 // the extent of the displayed object.
297 // These members have been introduced to fix Bug #1883.
298 bool mImageVisibility;
299 bool mOverlayVisibility;
300 bool mFusionVisibility;
302 bool mFirstSetSliceOrientation;