]> Creatis software - clitk.git/blob - vv/vvSlicerManager.h
Debug RTStruct conversion with empty struc
[clitk.git] / vv / vvSlicerManager.h
1
2 /*=========================================================================
3   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
4
5   Authors belong to: 
6   - University of LYON              http://www.universite-lyon.fr/
7   - Léon Bérard cancer center       http://www.centreleonberard.fr
8   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
9
10   This software is distributed WITHOUT ANY WARRANTY; without even
11   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12   PURPOSE.  See the copyright notices for more information.
13
14   It is distributed under dual licence
15
16   - BSD        See included LICENSE.txt file
17   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
18   ===========================================================================**/
19
20 #ifndef VVSLICERMANAGER_H
21 #define VVSLICERMANAGER_H
22
23 // std
24 #include <iostream>
25 #include <vector>
26 #include <string>
27
28 // QT
29 #include <QObject>
30
31 // VTK
32 #include <vtksys/SystemTools.hxx>
33 class vtkImageData;
34 class vtkInteractorStyle;
35 class vtkRenderWindow;
36 class vtkPolyData;
37
38 // VV
39 #include "clitkCommon.h"
40 #include "vvImage.h"
41 #include "vvMesh.h"
42 #include "vvImageReader.h"
43
44 class vvSlicer;
45 class vvInteractorStyleNavigator;
46 class vvImageReader;
47 class vvImageReader;
48 class vvLandmarks;
49
50 enum WindowLevelPreset {
51   WL_AUTO,
52   WL_HOUNSFIELD,
53   WL_SOFTTISSUE,
54   WL_LUNGS,
55   WL_BONES,
56   WL_HEAD,
57   WL_BINARY,
58   WL_USER,
59   WL_VENTILATION
60 };
61
62 //------------------------------------------------------------------------------
63 class vvSlicerManager : public QObject {
64   Q_OBJECT
65
66   public:
67   typedef enum {WORLD_SLICING, VOXELS_SLICING} SlicingPresetType;
68   vvSlicerManager(int numberOfSlicers);
69   ~vvSlicerManager();
70
71   std::string GetLastError() {
72     return mLastError;
73   }
74
75   bool SetImage(std::string filename, vvImageReader::LoadedImageType type, int n=0, unsigned int slice=0);
76   void SetImage(vvImage::Pointer image);
77   bool SetImages(std::vector<std::string> filenames, vvImageReader::LoadedImageType type, int n=0, bool patientCoordinateSystem=0);
78
79   bool SetOverlay(std::vector<std::string> filenames, int dim, std::string component, vvImageReader::LoadedImageType type);
80   bool SetFusion(std::vector<std::string> filenames,int dim, std::string component, vvImageReader::LoadedImageType type);
81   bool SetFusionSequence(std::vector<std::string> filenames, int dim, std::string component, vvImageReader::LoadedImageType type);
82   ///Set a VF by loading it from the disk
83   bool SetVF(std::string filename);
84   ///Set a VF from memory
85   bool SetVF(vvImage::Pointer vf,std::string filename);
86   ///Add a mesh to the slicers, with optional propagation using a vector field
87   void AddContour(vvMesh::Pointer ,bool propagate=false);
88   ///Toggle temporal superposition of contours
89   void ToggleContourSuperposition();
90
91   std::string GetFileName()      { return mFileName; }
92   std::string GetBaseFileName()  { return mBaseFileName; }
93   int GetBaseFileNameNumber()    { return mBaseFileNameNumber; }
94   std::string GetVFName()        { return mVFName; }
95   std::string GetOverlayName()   { return mOverlayName; }
96   std::string GetFusionName()    { return mFusionName; }
97   std::string GetListOfAbsoluteFilePathInOneString(const std::string &actorType);
98
99   ///Switch between nearest neighbor and linear interpolation
100   void ToggleInterpolation();
101   vvSlicer* GetSlicer(int i);
102   int GetSelectedSlicer() {
103     return mSelectedSlicer;
104   }
105   
106   void UpdateSlicer(int num, bool state);
107   void SetSlicerWindow(int i, vtkRenderWindow* RW);
108   void SetInteractorStyleNavigator(int i,vtkInteractorStyle* style);
109
110   int GetNumberOfSlicers()        { return mSlicers.size(); }
111   vvImage::Pointer GetImage()  { return mImage; }
112   vvImage::Pointer GetVF()     { return mVF; }
113   int GetType()                { return mType; }
114   void SetId(std::string id)   { mId = id; }
115   std::string GetId()  const        { return mId; }
116   int GetDimension() {
117     if (mImage) return mImage->GetNumberOfDimensions();
118     else return -1;
119   }
120
121   void SetFilename(std::string f, int number=0);
122
123   void SetSliceOrientation(int slicer, int orientation);
124   int GetTSlice();
125   void SetTSlice(int slice, bool updateLinkedImages = true);
126   void SetNextTSlice(int originating_slicer);
127   void SetPreviousTSlice(int originating_slicer);
128   void SetTSliceInSlicer(int tslice, int slicer);
129
130   void SetFusionSequenceTSlice(int slice);
131
132   void GenerateDefaultLookupTable();
133   void SetColorWindow(double s);
134   void SetColorLevel(double s);
135   void SetOverlayColorWindow(double s);
136   void SetOverlayColorLevel(double s);
137   void SetLinkOverlayWindowLevel(bool b);
138   void SetLocalColorWindowing(const int slicer, const bool bCtrlKey);
139   void SetOpacity(int i, double factor);
140   void SetColorMap(int colormap);
141   void SetPreset(int preset);
142   void SetOverlayColor(int color) {
143     mOverlayColor = (color/60)*60; //SR: new vvBlendImageActor needs 0 or 255 per component
144   }
145   void SetFusionOpacity(int opacity) {
146     mFusionOpacity = opacity;
147   }
148   void SetFusionThresholdOpacity(int thresOpacity) {
149     mFusionThresOpacity = thresOpacity;
150   }
151   void SetFusionColorMap(int colorMap) {
152     mFusionColorMap = colorMap;
153   }
154   void SetFusionWindow(double window) {
155     mFusionWindow = window;
156   }
157   void SetFusionLevel(double level) {
158     mFusionLevel = level;
159   }
160   void SetFusionShowLegend(int show) {
161     mFusionShowLegend = show;
162   }
163
164
165   //set/get fusionSequence related data
166   void SetFusionSequenceFrameIndex(int sequenceFrameIndex) { mFusionSequenceFrameIndex = sequenceFrameIndex; }
167   void SetFusionSequenceSpatialSyncFlag(bool spatialSync) { mFusionSequenceSpatialSyncFlag = spatialSync; }
168   void SetFusionSequenceTemporalSyncFlag(bool temporalSync) { mFusionSequenceTemporalSyncFlag = temporalSync; }
169   void SetFusionSequenceLength(unsigned int fusionSequenceNbFrames) { mFusionSequenceNbFrames = fusionSequenceNbFrames; }
170   void SetFusionSequenceMainTransformMatrix(vtkSmartPointer<vtkMatrix4x4> mat) { 
171           mFusionSequenceMainTransform = vtkSmartPointer<vtkMatrix4x4>::New();
172           mFusionSequenceMainTransform->DeepCopy(mat);
173   }
174   void AddFusionSequenceInitialTransformMatrices(vtkSmartPointer<vtkMatrix4x4> mat) { 
175                 vtkSmartPointer<vtkMatrix4x4> tmpMat = vtkSmartPointer<vtkMatrix4x4>::New();
176                 tmpMat->DeepCopy(mat);
177                 mFusionSequenceListInitialTransformMatrices.push_back( tmpMat );
178   }
179   void SetFusionSequenceIndexOfLinkedManager(int index) { mFusionSequenceIndexLinkedManager = index; }
180   void SetFusionSequenceCorrespondances(std::vector<unsigned> s) { mFusionSequenceCorrespondances = s; }
181   
182   void SetFusionSequenceInvolvmentCode(int code) { mFusionSequenceInvolvementCode=code; }
183   int GetFusionSequenceInvolvmentCode() { return mFusionSequenceInvolvementCode;}
184   bool IsInvolvedInFusionSequence() {return (!(mFusionSequenceInvolvementCode==-1));}
185   bool IsMainSequenceOfFusionSequence() {return (mFusionSequenceInvolvementCode==0);}
186   bool IsSecondarySequenceOfFusionSequence() {return (mFusionSequenceInvolvementCode==1);}
187
188   int GetFusionSequenceIndexOfLinkedManager() { return mFusionSequenceIndexLinkedManager; }
189   int GetFusionSequenceFrameIndex() { return mFusionSequenceFrameIndex; }
190   bool GetFusionSequenceSpatialSyncFlag() { return mFusionSequenceSpatialSyncFlag; }
191   bool GetFusionSequenceTemporalSyncFlag() { return mFusionSequenceTemporalSyncFlag; }
192   unsigned int GetFusionSequenceNbFrames() { return mFusionSequenceNbFrames; }
193   const vtkSmartPointer<vtkMatrix4x4>& GetFusionSequenceMainTransformMatrix() {return mFusionSequenceMainTransform;}
194   const std::vector< vtkSmartPointer<vtkMatrix4x4> >& GetFusionSequenceInitialTransformMatrices() {return mFusionSequenceListInitialTransformMatrices;}
195   const vtkSmartPointer<vtkMatrix4x4>& GetFusionSequenceInitialTransformMatrixAtFrame(unsigned i) {
196           return mFusionSequenceListInitialTransformMatrices[i];
197   }
198   const std::vector<unsigned>& GetFusionSequenceCorrespondances() {return mFusionSequenceCorrespondances;}
199
200   double GetColorWindow() const;
201   double GetColorLevel() const;
202   double GetOverlayColorWindow() const;
203   double GetOverlayColorLevel() const;
204   bool GetLinkOverlayWindowLevel() const;
205   int GetColorMap() {
206     return mColorMap;
207   }
208   int GetPreset() const {
209     return mPreset;
210   }
211   SlicingPresetType GetSlicingPreset() {
212     return mSlicingPreset;
213   }
214   int GetOverlayColor() const {
215     return mOverlayColor;
216   }
217   int GetFusionOpacity() const {
218     return mFusionOpacity;
219   }
220   int GetFusionThresholdOpacity() const {
221     return mFusionThresOpacity;
222   }
223   int GetFusionColorMap() const {
224     return mFusionColorMap;
225   }
226   double GetFusionWindow() const {
227     return mFusionWindow;
228   }
229   double GetFusionLevel() const {
230     return mFusionLevel;
231   }
232
233
234   void SetCursorAndCornerAnnotationVisibility(int s);
235   void UpdateViews(int current, int slicer);
236   void UpdateLinked(int slicer);
237   void UpdateLinkedNavigation(vvSlicer *slicer, bool bPropagate=false);
238   void ResetTransformationToIdentity(const std::string actorType);
239   void Render();
240
241   void AddLink(std::string newId) {
242     mLinkedId.push_back(newId);
243   }
244   void RemoveLink(std::string oldId) {
245     mLinkedId.remove(oldId); 
246   }
247   
248   std::list<std::string> GetLinks() const {
249     return mLinkedId;
250   }
251   
252   bool IsLinked() {
253     return mLinkedId.size() > 0;
254   }
255
256   ///Remove the actor defined by its type and index (example: 3rd contour)
257   void RemoveActor(const std::string& actor_type, int overlay_index);
258   void RemoveActors();
259   void Reload();
260   void ReloadOverlay();
261   void ReloadFusion();
262   void ReloadFusionSequence();
263   void ReloadVF();
264
265   void Activated();
266   void Picked();
267   void UpdateInfoOnCursorPosition(int slicer);
268   void EmitMousePositionUpdated(int slicer);
269   void EmitKeyPressed(std::string keyPress);
270   void UpdateWindowLevel();
271   void UpdateSlice(int slicer);
272   void UpdateTSlice(int slicer);
273   void UpdateSliceRange(int slicer);
274   void SetSlicingPreset(SlicingPresetType preset);
275
276   vvLandmarks *GetLandmarks();
277   void AddNewLandmark(float x,float y,float z,float t);
278   void AddLandmarkProfile(float x,float y,float z,float t);
279   
280   void NextImage(int slicer);
281   void PrevImage(int slicer);
282   void LeftButtonReleaseEvent(int slicer);
283   void VerticalSliderHasChanged(int slicer, int slice);
284   double GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int component=0);
285
286 public slots:
287   void AddLandmark(float x,float y,float z,float t);
288   void UpdateLandmark();
289
290 signals :
291   void callAddLandmark(float x,float y,float z,float t);
292   void currentImageChanged(std::string id);
293   void currentPickedImageChanged(std::string id);
294   void UpdatePosition(int visibility,double x, double y, double z, double X, double Y, double Z, double value);
295   void UpdateVector(int display, double x, double y, double z, double value);
296   void UpdateOverlay(int display, double valueOver, double valueRef);
297   void UpdateFusion(int display, double valueFus);
298   void UpdateFusionSequence(int fusionSequenceFrameIndex, bool fusionSequenceSpatialSyncFlag, unsigned int fusionSequenceNbFrames);
299   void MousePositionUpdatedSignal(int slicer);
300   void KeyPressedSignal(std::string KeyPressed);
301   void UpdateOrientation(int slicer, int orientation);
302   void UpdateSlice(int slicer, int slice);
303   void UpdateTSlice(int slicer, int slice, int code);
304   void UpdateSliceRange(int slice, int min, int max, int tmin, int tmax);
305   void WindowLevelChanged();
306   void UpdateLinkManager(std::string, int slicer, double x, double y, double z, int temps);
307   void UpdateLinkedNavigation(std::string, vvSlicerManager*, vvSlicer*);
308   void LandmarkAdded();
309   void ChangeImageWithIndexOffset(vvSlicerManager *sm, int slicer, int offset);
310   void LeftButtonReleaseSignal(int slicer);
311   void AVerticalSliderHasChanged(int slicer, int slice);
312
313 protected:
314   std::vector< vtkSmartPointer<vvSlicer> > mSlicers;
315   int mSelectedSlicer;
316   vvImageReader::Pointer mReader;
317   vvImageReader::Pointer mOverlayReader;
318   vvImageReader::Pointer mFusionReader;
319   vvImageReader::Pointer mFusionSequenceReader;
320   vvImageReader::Pointer mVectorReader;
321   vvImage::Pointer mImage;
322   vvImage::Pointer mVF;
323   int mColorMap;
324   int mOverlayColor;
325
326   int mFusionOpacity;
327   int mFusionThresOpacity;
328   int mFusionColorMap;
329   double mFusionWindow;
330   double mFusionLevel;
331   bool mFusionShowLegend;
332
333   //Fusion of sequences related data
334   int mFusionSequenceInvolvementCode; //-1: not involved, 0: main sequence(CT), 1: secondary sequence (US)
335   int mFusionSequenceIndexLinkedManager; //index of the other sequence involved in the visualization
336   int mFusionSequenceFrameIndex; //temporal index of the current image in the sequence (<->TSlice)
337   unsigned int mFusionSequenceNbFrames; //number of frames in the temporal sequence
338   bool mFusionSequenceSpatialSyncFlag, mFusionSequenceTemporalSyncFlag; //flags indicating whether the spatial/temporal synchronization are actives
339   vtkSmartPointer<vtkMatrix4x4> mFusionSequenceMainTransform;
340   std::vector< vtkSmartPointer<vtkMatrix4x4> > mFusionSequenceListInitialTransformMatrices;
341   std::vector<unsigned> mFusionSequenceCorrespondances;
342   
343   int mPreset;
344   SlicingPresetType mSlicingPreset;
345   vvImageReader::LoadedImageType mType;
346   std::string mVFComponent;
347   std::string mOverlayComponent;
348   std::string mFusionComponent;
349   std::string mFileName;
350   std::string mBaseFileName;
351   int mBaseFileNameNumber;
352   std::string mId;
353   std::string mVFName;
354   std::string mOverlayName;
355   std::string mFusionName;
356   std::string mVFId;
357   std::string mLastError;
358   std::list<std::string> mLinkedId;
359
360   vvLandmarks* mLandmarks;
361   
362   std::vector<int> mPreviousSlice;
363   std::vector<int> mPreviousTSlice;
364 };
365
366 #endif