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 RemoveLandmarks();
174 void DisplayLandmarks();
175 void ForceUpdateDisplayExtent();
177 int* GetDisplayExtent();
178 /**Add a polydata to be displayed as a contour over the image
179 ** the contour can be propagated to a time sequence using a motion field */
180 void AddContour(vvMesh::Pointer contours,bool propagate);
181 ///Toggle temporal superposition of contours
182 void ToggleContourSuperposition();
184 virtual void SetColorWindow(double s);
185 virtual void SetColorLevel(double s);
187 double GetOverlayColorWindow();
188 double GetOverlayColorLevel();
189 bool GetLinkOverlayWindowLevel() { return mLinkOverlayWindowLevel; }
191 void SetOverlayColorWindow(double s);
192 void SetOverlayColorLevel(double s);
193 void SetLinkOverlayWindowLevel(bool b) { mLinkOverlayWindowLevel = b; }
196 * When it is enabled, beware of a call to GetExtent.
197 * we must have setted mReducedExtent otherwhise random values
198 * are returned by GetExtent
200 void EnableReducedExtent(bool b);
201 void SetReducedExtent(int * ext);
203 bool ClipDisplayedExtent(int extent[6], int refExtent[6]);
204 int GetOrientation();
207 double* GetVFColor() {
210 void SetVFColor(double r, double g, double b);
212 //necessary to flag the secondary sequence
213 void SetFusionSequenceCode(int code) {mFusionSequenceCode=code;}
214 void SetRegisterExtent(int [6]);
215 void GetRegisterExtent(int [6]);
217 void SetSlicerNumber(const int nbSlicer) {mSlicerNumber = nbSlicer;}
218 int GetSlicerNumber() const {return mSlicerNumber;}
221 void UpdateDisplayExtentBegin(int);
222 void UpdateDisplayExtentEnd(int);
228 std::string mFileName;
229 vvImage::Pointer mImage;
230 vvImage::Pointer mOverlay;
231 vvImage::Pointer mFusion;
232 vvImage::Pointer mVF;
234 vvLandmarks* mLandmarks;
236 int mFusionSequenceCode; //-1: not involved in a fusion sequence, 0: main sequence (CT), 1: secondary sequence (US)
238 // __________ Image coordinates accounting for spacing and origin
240 // | | vvImage.GetTransform()
242 // GetConcatenatedTransform() | _|___ VV world coordinates (mm) (displayed in VV) mCurrentBeforeSlicingTransform
244 // | | GetSlicingTransform()
246 // ___|__|___ VTK world coordinates (mm) (never displayed) mCurrent
248 vtkSmartPointer<vtkTransform> mSlicingTransform;
249 vtkSmartPointer<vtkImageReslice> mImageReslice;
250 vtkSmartPointer<vtkTransform> mConcatenatedTransform;
251 vtkSmartPointer<vtkImageReslice> mOverlayReslice;
252 vtkSmartPointer<vtkTransform> mConcatenatedOverlayTransform;
253 vtkSmartPointer<vtkImageMapToWindowLevelColors> mOverlayMapper;
254 vtkSmartPointer<vvBlendImageActor> mOverlayActor;
255 vtkSmartPointer<vtkImageReslice> mFusionReslice;
256 vtkSmartPointer<vtkTransform> mConcatenatedFusionTransform;
257 vtkSmartPointer<vtkImageMapToColors> mFusionMapper;
258 vtkSmartPointer<vtkImageActor> mFusionActor;
259 vtkSmartPointer<vtkCornerAnnotation> ca;
260 vtkSmartPointer<vtkCursor2D> crossCursor;
261 vtkSmartPointer<vtkPolyDataMapper2D> pdm;
262 vtkSmartPointer<vtkActor2D> pdmA;
263 vtkSmartPointer<vvGlyphSource> mArrow;
264 vtkSmartPointer<vtkAssignAttribute> mAAFilter;
265 vtkSmartPointer<vtkExtractVOI> mVOIFilter;
266 vtkSmartPointer<vvGlyph2D> mGlyphFilter;
267 vtkSmartPointer<vtkPolyDataMapper> mVFMapper;
268 vtkSmartPointer<vtkLookupTable> mVFColorLUT;
269 vtkSmartPointer<vtkActor> mVFActor;
270 vtkSmartPointer<vtkGlyph3D> mLandGlyph;
271 vtkSmartPointer<vtkCursor3D> mCross;
272 vtkSmartPointer<vvClipPolyData> mLandClipper;
273 vtkSmartPointer<vtkPolyDataMapper> mLandMapper;
274 vtkSmartPointer<vtkActor> mLandActor;
275 std::vector<vtkSmartPointer<vtkCaptionActor2D> > mLandLabelActors;
276 vtkSmartPointer<vtkBox> mClipBox;
277 vtkSmartPointer<vtkScalarBarActor> legend;
278 std::vector<vvMeshActor*> mSurfaceCutActors;
282 int mCurrentFusionTSlice;
283 int mCurrentOverlayTSlice;
285 double mCurrentBeforeSlicingTransform[3];
292 bool mUseReducedExtent;
293 int * mReducedExtent;
294 int * mRegisterExtent;
295 bool mLinkOverlayWindowLevel;
296 bool showFusionLegend;
299 void UpdateOrientation();
300 void UpdateDisplayExtent();
301 void ConvertImageToImageDisplayExtent(vtkInformation *sourceImage, const int sourceExtent[6],
302 vtkImageData *targetImage, int targetExtent[6]);
303 void ConvertImageToImageDisplayExtent(vtkImageData *sourceImage, const int sourceExtent[6],
304 vtkImageData *targetImage, int targetExtent[6]);
305 ///Sets the surfaces to be cut on the image slice: update the vtkCutter
306 void SetContourSlice();
308 // Visibility of the different elements that can be set from outside the object.
309 // Note that vvSlicer also check if the element is to be displayed according to
310 // the extent of the displayed object.
311 // These members have been introduced to fix Bug #1883.
312 bool mImageVisibility;
313 bool mOverlayVisibility;
314 bool mFusionVisibility;
316 bool mFirstSetSliceOrientation;