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