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>
42 class vtkPolyDataMapper2D;
44 class vtkClipPolyData;
46 class vvBlendImageActor;
48 class vtkCornerAnnotation;
50 class vtkPolyDataMapper2D;
51 class vtkPolyDataMapper;
57 class vtkAssignAttribute;
58 class vtkScalarBarActor;
60 class vtkImageReslice;
62 class vvSlicer: public QObject, public vtkImageViewer2 {
67 static vvSlicer *New();
68 vtkTypeMacro(vvSlicer,vtkImageViewer2);
69 void PrintSelf(ostream& os, vtkIndent indent);
71 void SetImage(vvImage::Pointer inputImages);
72 vvImage::Pointer GetImage() {
76 void SetOverlay(vvImage::Pointer inputOverlay);
77 vvImage::Pointer GetOverlay() {
80 vtkImageMapToWindowLevelColors* GetOverlayMapper();
81 vvBlendImageActor* GetOverlayActor() ;
82 vtkImageMapToColors* GetFusionMapper() ;
83 vtkImageActor* GetFusionActor() ;
84 vtkActor* GetVFActor() ;
85 vtkCornerAnnotation* GetAnnotation();
87 void SetFusion(vvImage::Pointer inputFusion, int fusionSequenceCode = -1);
88 vvImage::Pointer GetFusion() {
91 void ShowFusionLegend(bool show) { showFusionLegend = show; }
93 /**Get/Set an actor's visibility ("overlay, fusion, vf, contour...")
94 Overlay index is the index of the overlay by type, eg. if there are
95 5 contours and we want to activate the 3rd one, pass 2 **/
96 bool GetActorVisibility(const std::string& actor_type, int overlay_index);
97 void SetActorVisibility(const std::string& actor_type, int overlay_index,bool vis);
98 void RemoveActor(const std::string& actor_type, int overlay_index);
100 void SetVF(vvImage::Pointer vf);
105 void SetLandmarks(vvLandmarks* landmarks);
106 void SetTSlice(int t, bool updateLinkedImages = true);
108 void SetFusionSequenceTSlice(int t);
110 void SetSliceOrientation(int orientation);
111 void AdjustResliceToSliceOrientation(vtkImageReslice *reslice);
113 int GetFusionTSlice();
114 int GetOverlayTSlice();
115 int GetMaxCurrentTSlice();
116 ///Reimplemented from vtkImageViewer2 to add polydata support
117 void SetSlice(int s);
120 void SetOpacity(double s);
121 void SetRenderWindow(int orientation, vtkRenderWindow * rw);
122 void SetDisplayMode(bool i);
123 void FlipHorizontalView();
124 void FlipVerticalView();
125 static double GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int &ix, int &iy, int &iz, int component=0);
127 ///Sets the camera to fit the image in the window
130 void SetVFSubSampling(int sub);
131 int GetVFSubSampling() {
134 void SetVFScale(int scale);
135 void SetVFWidth(int width);
139 void SetVFLog(int log);
144 void SetFileName(std::string filename) {
145 mFileName = filename;
147 std::string GetFileName() {
151 double* GetCursorPosition() {
154 vtkTransform * GetSlicingTransform() { return mSlicingTransform; }
155 vtkTransform * GetConcatenatedTransform() { return mConcatenatedTransform; }
156 vtkTransform * GetConcatenatedFusionTransform() { return mConcatenatedFusionTransform; }
157 vtkTransform * GetConcatenatedOverlayTransform() { return mConcatenatedOverlayTransform; }
159 void SetCurrentPosition(double x, double y, double z, int t);
160 double* GetCurrentPosition();
162 void UpdateCursorPosition();
163 void SetCursorVisibility(bool s);
165 bool GetCursorVisibility();
166 void SetCursorColor(int r,int g, int b);
168 void SetCornerAnnotationVisibility(bool s);
169 bool GetCornerAnnotationVisibility();
171 void GetExtremasAroundMousePointer(double & min, double & max, vtkImageData *image, vtkTransform *transform);
173 void UpdateLandmarks();
174 void ForceUpdateDisplayExtent();
176 int* GetDisplayExtent();
177 /**Add a polydata to be displayed as a contour over the image
178 ** the contour can be propagated to a time sequence using a motion field */
179 void AddContour(vvMesh::Pointer contours,bool propagate);
180 ///Toggle temporal superposition of contours
181 void ToggleContourSuperposition();
183 virtual void SetColorWindow(double s);
184 virtual void SetColorLevel(double s);
186 double GetOverlayColorWindow();
187 double GetOverlayColorLevel();
188 bool GetLinkOverlayWindowLevel() { return mLinkOverlayWindowLevel; }
190 void SetOverlayColorWindow(double s);
191 void SetOverlayColorLevel(double s);
192 void SetLinkOverlayWindowLevel(bool b) { mLinkOverlayWindowLevel = b; }
195 * When it is enabled, beware of a call to GetExtent.
196 * we must have setted mReducedExtent otherwhise random values
197 * are returned by GetExtent
199 void EnableReducedExtent(bool b);
200 void SetReducedExtent(int * ext);
202 bool ClipDisplayedExtent(int extent[6], int refExtent[6]);
203 int GetOrientation();
206 double* GetVFColor() {
209 void SetVFColor(double r, double g, double b);
211 //necessary to flag the secondary sequence
212 void SetFusionSequenceCode(int code) {mFusionSequenceCode=code;}
213 void SetRegisterExtent(int [6]);
214 void GetRegisterExtent(int [6]);
216 void SetSlicerNumber(const int nbSlicer) {mSlicerNumber = nbSlicer;}
217 int GetSlicerNumber() const {return mSlicerNumber;}
220 void UpdateDisplayExtentBegin(int);
221 void UpdateDisplayExtentEnd(int);
227 std::string mFileName;
228 vvImage::Pointer mImage;
229 vvImage::Pointer mOverlay;
230 vvImage::Pointer mFusion;
231 vvImage::Pointer mVF;
233 vvLandmarks* mLandmarks;
235 int mFusionSequenceCode; //-1: not involved in a fusion sequence, 0: main sequence (CT), 1: secondary sequence (US)
237 // __________ Image coordinates accounting for spacing and origin
239 // | | vvImage.GetTransform()
241 // GetConcatenatedTransform() | _|___ VV world coordinates (mm) (displayed in VV) mCurrentBeforeSlicingTransform
243 // | | GetSlicingTransform()
245 // ___|__|___ VTK world coordinates (mm) (never displayed) mCurrent
247 vtkSmartPointer<vtkTransform> mSlicingTransform;
248 vtkSmartPointer<vtkImageReslice> mImageReslice;
249 vtkSmartPointer<vtkTransform> mConcatenatedTransform;
250 vtkSmartPointer<vtkImageReslice> mOverlayReslice;
251 vtkSmartPointer<vtkTransform> mConcatenatedOverlayTransform;
252 vtkSmartPointer<vtkImageMapToWindowLevelColors> mOverlayMapper;
253 vtkSmartPointer<vvBlendImageActor> mOverlayActor;
254 vtkSmartPointer<vtkImageReslice> mFusionReslice;
255 vtkSmartPointer<vtkTransform> mConcatenatedFusionTransform;
256 vtkSmartPointer<vtkImageMapToColors> mFusionMapper;
257 vtkSmartPointer<vtkImageActor> mFusionActor;
258 vtkSmartPointer<vtkCornerAnnotation> ca;
259 vtkSmartPointer<vtkCursor2D> crossCursor;
260 vtkSmartPointer<vtkPolyDataMapper2D> pdm;
261 vtkSmartPointer<vtkActor2D> pdmA;
262 vtkSmartPointer<vvGlyphSource> mArrow;
263 vtkSmartPointer<vtkAssignAttribute> mAAFilter;
264 vtkSmartPointer<vtkExtractVOI> mVOIFilter;
265 vtkSmartPointer<vvGlyph2D> mGlyphFilter;
266 vtkSmartPointer<vtkPolyDataMapper> mVFMapper;
267 vtkSmartPointer<vtkLookupTable> mVFColorLUT;
268 vtkSmartPointer<vtkActor> mVFActor;
269 vtkSmartPointer<vtkGlyph3D> mLandGlyph;
270 vtkSmartPointer<vtkCursor3D> mCross;
271 vtkSmartPointer<vvClipPolyData> mLandClipper;
272 vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
273 vtkSmartPointer<vtkActor> mLandActor;
274 std::vector<vtkSmartPointer<vtkCaptionActor2D> > mLandLabelActors;
275 vtkSmartPointer<vtkBox> mClipBox;
276 vtkSmartPointer<vtkScalarBarActor> legend;
277 std::vector<vvMeshActor*> mSurfaceCutActors;
281 int mCurrentFusionTSlice;
282 int mCurrentOverlayTSlice;
284 double mCurrentBeforeSlicingTransform[3];
291 bool mUseReducedExtent;
292 int * mReducedExtent;
293 int * mRegisterExtent;
294 bool mLinkOverlayWindowLevel;
295 bool showFusionLegend;
298 void UpdateOrientation();
299 void UpdateDisplayExtent();
300 void ConvertImageToImageDisplayExtent(vtkInformation *sourceImage, const int sourceExtent[6],
301 vtkImageData *targetImage, int targetExtent[6]);
302 ///Sets the surfaces to be cut on the image slice: update the vtkCutter
303 void SetContourSlice();
305 // Visibility of the different elements that can be set from outside the object.
306 // Note that vvSlicer also check if the element is to be displayed according to
307 // the extent of the displayed object.
308 // These members have been introduced to fix Bug #1883.
309 bool mImageVisibility;
310 bool mOverlayVisibility;
311 bool mFusionVisibility;
313 bool mFirstSetSliceOrientation;