]> Creatis software - clitk.git/blob - vv/vvSlicerManager.h
Modify Nearest Neighbor interpolation
[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);
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
289 signals :
290   void callAddLandmark(float x,float y,float z,float t);
291   void currentImageChanged(std::string id);
292   void currentPickedImageChanged(std::string id);
293   void UpdatePosition(int visibility,double x, double y, double z, double X, double Y, double Z, double value);
294   void UpdateVector(int display, double x, double y, double z, double value);
295   void UpdateOverlay(int display, double valueOver, double valueRef);
296   void UpdateFusion(int display, double valueFus);
297   void UpdateFusionSequence(int fusionSequenceFrameIndex, bool fusionSequenceSpatialSyncFlag, unsigned int fusionSequenceNbFrames);
298   void MousePositionUpdatedSignal(int slicer);
299   void KeyPressedSignal(std::string KeyPressed);
300   void UpdateOrientation(int slicer, int orientation);
301   void UpdateSlice(int slicer, int slice);
302   void UpdateTSlice(int slicer, int slice, int code);
303   void UpdateSliceRange(int slice, int min, int max, int tmin, int tmax);
304   void WindowLevelChanged();
305   void UpdateLinkManager(std::string, int slicer, double x, double y, double z, int temps);
306   void UpdateLinkedNavigation(std::string, vvSlicerManager*, vvSlicer*);
307   void LandmarkAdded();
308   void ChangeImageWithIndexOffset(vvSlicerManager *sm, int slicer, int offset);
309   void LeftButtonReleaseSignal(int slicer);
310   void AVerticalSliderHasChanged(int slicer, int slice);
311
312 protected:
313   std::vector< vtkSmartPointer<vvSlicer> > mSlicers;
314   int mSelectedSlicer;
315   vvImageReader::Pointer mReader;
316   vvImageReader::Pointer mOverlayReader;
317   vvImageReader::Pointer mFusionReader;
318   vvImageReader::Pointer mFusionSequenceReader;
319   vvImageReader::Pointer mVectorReader;
320   vvImage::Pointer mImage;
321   vvImage::Pointer mVF;
322   int mColorMap;
323   int mOverlayColor;
324
325   int mFusionOpacity;
326   int mFusionThresOpacity;
327   int mFusionColorMap;
328   double mFusionWindow;
329   double mFusionLevel;
330   bool mFusionShowLegend;
331
332   //Fusion of sequences related data
333   int mFusionSequenceInvolvementCode; //-1: not involved, 0: main sequence(CT), 1: secondary sequence (US)
334   int mFusionSequenceIndexLinkedManager; //index of the other sequence involved in the visualization
335   int mFusionSequenceFrameIndex; //temporal index of the current image in the sequence (<->TSlice)
336   unsigned int mFusionSequenceNbFrames; //number of frames in the temporal sequence
337   bool mFusionSequenceSpatialSyncFlag, mFusionSequenceTemporalSyncFlag; //flags indicating whether the spatial/temporal synchronization are actives
338   vtkSmartPointer<vtkMatrix4x4> mFusionSequenceMainTransform;
339   std::vector< vtkSmartPointer<vtkMatrix4x4> > mFusionSequenceListInitialTransformMatrices;
340   std::vector<unsigned> mFusionSequenceCorrespondances;
341   
342   int mPreset;
343   SlicingPresetType mSlicingPreset;
344   vvImageReader::LoadedImageType mType;
345   std::string mVFComponent;
346   std::string mOverlayComponent;
347   std::string mFusionComponent;
348   std::string mFileName;
349   std::string mBaseFileName;
350   int mBaseFileNameNumber;
351   std::string mId;
352   std::string mVFName;
353   std::string mOverlayName;
354   std::string mFusionName;
355   std::string mVFId;
356   std::string mLastError;
357   std::list<std::string> mLinkedId;
358
359   vvLandmarks* mLandmarks;
360   
361   std::vector<int> mPreviousSlice;
362   std::vector<int> mPreviousTSlice;
363 };
364
365 #endif