]> Creatis software - clitk.git/blob - vv/vvSlicerManager.h
Memory leak hunt: vvBinaryImageOverlayActor vvImageContour vVImageReader are now...
[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://oncora1.lyon.fnclcc.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 "vvConstants.h"
40 #include "clitkCommon.h"
41 #include "vvImage.h"
42 #include "vvMesh.h"
43 #include "vvImageReader.h"
44
45 class vvSlicer;
46 class vvInteractorStyleNavigator;
47 class vvImageReader;
48 class vvImageReader;
49 class vvLandmarks;
50
51 //------------------------------------------------------------------------------
52 class vvSlicerManager : public QObject {
53   Q_OBJECT
54
55   public:
56   vvSlicerManager(int numberOfSlicers);
57   ~vvSlicerManager();
58
59   std::string GetLastError() {
60     return mLastError;
61   }
62
63   bool SetImage(std::string filename,LoadedImageType type, int n=0, unsigned int slice=0);
64   void SetImage(vvImage::Pointer image);
65   bool SetImages(std::vector<std::string> filenames, LoadedImageType type, int n=0);
66
67   bool SetOverlay(std::string filename, int dim, std::string component);
68   bool SetFusion(std::string filename, int dim, std::string component);
69   ///Set a VF by loading it from the disk
70   bool SetVF(std::string filename);
71   ///Set a VF from memory
72   bool SetVF(vvImage::Pointer vf,std::string filename);
73   ///Add a mesh to the slicers, with optional propagation using a vector field
74   void AddContour(vvMesh::Pointer ,bool propagate=false);
75   ///Toggle temporal superposition of contours
76   void ToggleContourSuperposition();
77
78   std::string GetFileName()      { return mFileName; }
79   std::string GetBaseFileName()  { return mBaseFileName; }
80   int GetBaseFileNameNumber()    { return mBaseFileNameNumber; }
81   std::string GetVFName()        { return mVFName; }
82   std::string GetOverlayName()   { return mOverlayName; }
83   std::string GetFusionName()    { return mFusionName; }
84
85   ///Switch between nearest neighbor and linear interpolation
86   void ToggleInterpolation();
87   vvSlicer* GetSlicer(int i);
88   void UpdateSlicer(int num, bool state);
89   void SetSlicerWindow(int i, vtkRenderWindow* RW);
90   void SetInteractorStyleNavigator(int i,vtkInteractorStyle* style);
91
92   int GetNumberOfSlicers()        { return mSlicers.size(); }
93   vvImage::Pointer GetImage()  { return mImage; }
94   vvImage::Pointer GetVF()     { return mVF; }
95   int GetType()                { return mType; }
96   void SetId(std::string id)   { mId = id; }
97   std::string GetId()          { return mId; }
98   int GetDimension() {
99     if (mImage) return mImage->GetNumberOfDimensions();
100     else return -1;
101   }
102
103   void SetFilename(std::string f, int number=0);
104
105   void SetTSlice(int slice);
106   void SetNextTSlice(int originating_slicer);
107   void SetPreviousTSlice(int originating_slicer);
108   void SetTSliceInSlicer(int tslice, int slicer);
109
110   void GenerateDefaultLookupTable();
111   void SetColorWindow(double s);
112   void SetColorLevel(double s);
113   void SetLocalColorWindowing(const int slicer);
114   void SetOpacity(int i, double factor);
115   void SetColorMap();
116   void SetColorMap(int colormap);
117   void SetPreset(int preset);
118   void SetOverlayColor(int color) {
119     mOverlayColor = (color/60)*60; //SR: new vvBlendImageActor needs 0 or 255 per component
120   }
121   void SetFusionOpacity(int opacity) {
122     mFusionOpacity = opacity;
123   }
124   void SetFusionColorMap(int colorMap) {
125     mFusionColorMap = colorMap;
126   }
127   void SetFusionWindow(double window) {
128     mFusionWindow = window;
129   }
130   void SetFusionLevel(double level) {
131     mFusionLevel = level;
132   }
133
134   double GetColorWindow();
135   double GetColorLevel();
136   int GetColorMap() {
137     return mColorMap;
138   }
139   int GetPreset() {
140     return mPreset;
141   }
142   int GetOverlayColor() {
143     return mOverlayColor;
144   }
145
146   int GetFusionOpacity() {
147     return mFusionOpacity;
148   }
149   int GetFusionColorMap() {
150     return mFusionColorMap;
151   }
152   double GetFusionWindow() {
153     return mFusionWindow;
154   }
155   double GetFusionLevel() {
156     return mFusionLevel;
157   }
158
159   void SetCursorAndCornerAnnotationVisibility(int s);
160   void UpdateViews(int current, int slicer);
161   void UpdateLinked(int slicer);
162   void UpdateLinkedNavigation(vvSlicer *slicer, bool bPropagate=false);
163   void Render();
164
165   void AddLink(std::string newId) {
166     mLinkedId.push_back(newId);
167   }
168   void RemoveLink(std::string oldId) {
169     mLinkedId.remove(oldId); 
170   }
171
172   ///Remove the actor defined by its type and index (example: 3rd contour)
173   void RemoveActor(const std::string& actor_type, int overlay_index);
174   void RemoveActors();
175   void Reload();
176   void ReloadOverlay();
177   void ReloadFusion();
178   void ReloadVF();
179
180   void Activated();
181   void Picked();
182   void UpdateInfoOnCursorPosition(int slicer);
183   void UpdateWindowLevel();
184   void UpdateSlice(int slicer);
185   void UpdateTSlice(int slicer);
186   void UpdateSliceRange(int slicer);
187
188   vvLandmarks *GetLandmarks();
189   void AddLandmark(float x,float y,float z,float t);
190   
191   void NextImage(int slicer);
192   void PrevImage(int slicer);
193   void LeftButtonReleaseEvent(int slicer);
194   void VerticalSliderHasChanged(int slicer, int slice);
195   double GetScalarComponentAsDouble(vtkImageData *image, double X, double Y, double Z, int component=0);
196
197 signals :
198   void currentImageChanged(std::string id);
199   void currentPickedImageChanged(std::string id);
200   void UpdatePosition(int visibility,double x, double y, double z, double X, double Y, double Z, double value);
201   void UpdateVector(int display, double x, double y, double z, double value);
202   void UpdateOverlay(int display, double valueOver, double valueRef);
203   void UpdateFusion(int display, double valueFus);
204   void UpdateWindows(int slicer, int view, int slice);
205   void UpdateSlice(int slicer, int slice);
206   void UpdateTSlice(int slicer, int slice);
207   void UpdateSliceRange(int slice, int min, int max, int tmin, int tmax);
208   void WindowLevelChanged(double window, double level, int preset, int colormap);
209   void UpdateLinkManager(std::string, int slicer, double x, double y, double z, int temps);
210   void UpdateLinkedNavigation(std::string, vvSlicerManager*);
211   void LandmarkAdded();
212   void ChangeImageWithIndexOffset(vvSlicerManager *sm, int slicer, int offset);
213   void LeftButtonReleaseSignal(int slicer);
214   void AVerticalSliderHasChanged(int slicer, int slice);
215
216 protected:
217   std::vector<vvSlicer*> mSlicers;
218   vvImageReader::Pointer mReader;
219   vvImageReader::Pointer mOverlayReader;
220   vvImageReader::Pointer mFusionReader;
221   vvImageReader::Pointer mVectorReader;
222   vvImage::Pointer mImage;
223   vvImage::Pointer mVF;
224   int mColorMap;
225   int mOverlayColor;
226
227   int mFusionOpacity;
228   int mFusionColorMap;
229   double mFusionWindow;
230   double mFusionLevel;
231
232   int mPreset;
233   LoadedImageType mType;
234   std::string mVFComponent;
235   std::string mOverlayComponent;
236   std::string mFusionComponent;
237   std::string mFileName;
238   std::string mBaseFileName;
239   int mBaseFileNameNumber;
240   std::string mId;
241   std::string mVFName;
242   std::string mOverlayName;
243   std::string mFusionName;
244   std::string mVFId;
245   std::string mLastError;
246   std::list<std::string> mLinkedId;
247
248   vvLandmarks* mLandmarks;
249   
250   std::vector<int> mPreviousSlice;
251   std::vector<int> mPreviousTSlice;
252 };
253
254 #endif