]> Creatis software - creaImageIO.git/blob - src/creaImageIOGimmickView.h
allow data anonymization
[creaImageIO.git] / src / creaImageIOGimmickView.h
1 #ifndef __creaImageIOGimmickView_h_INCLUDED__
2 #define __creaImageIOGimmickView_h_INCLUDED__
3
4 #include <creaImageIOGimmick.h>
5 #include <creaImageIOTreeView.h>
6 #include <creaImageIOSystem.h>
7 #include <creaImageIOImagePointerHolder.h>
8
9 //#include <map>
10 #include <vtkImageData.h>
11 #if defined (USE_WXWIDGETS)
12 #include <creaImageIOMultiThreadImageReader.h>
13 #endif
14
15 #if defined(USE_QT)
16 #include "Qt/creaImageIOQMultiThreadImageReader.h"
17 #endif
18
19
20 // Signal/slot mechanism for progress events
21 #include <boost/signal.hpp>
22 #include <boost/bind.hpp>
23
24 #define GIMMICK_NO_IMAGE_SELECTION 0
25 #define GIMMICK_2D_IMAGE_SELECTION 2
26 #define GIMMICK_3D_IMAGE_SELECTION 3
27 #define GIMMICK_4D_IMAGE_SELECTION 4
28
29 #define NATIVE 0
30 #define _2D    2
31 #define _3D    3
32
33 namespace creaImageIO
34 {
35         typedef std::map<std::string, std::string> mapInfoDicom;
36
37         typedef struct 
38         { 
39                 vtkImageData *img;
40                 //std::map<std::string, std::string> infos;
41                 mapInfoDicom infos; 
42         } OutStrGimmick;
43
44
45         /**
46         * \ingroup View
47         */
48          
49         class ImageExtent;
50     //=====================================================================
51     
52     //=====================================================================
53     ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
54         class GimmickView: public MultiThreadImageReaderUser
55     {
56     public:
57       /// Ctor
58       GimmickView(boost::shared_ptr<Gimmick>, int number_of_threads = 0 );
59       /// Virtual destructor
60       virtual ~GimmickView();
61       /// Initializes the view : 
62       /// Creates the TreeViews for all the TreeHandler of the Controller
63       /// 
64       virtual void Initialize();
65
66       /// Type of map from View name to TreeView* 
67       /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
68       typedef std::map<std::string, TreeView*> TreeViewMapType;
69       
70       /// Returns the TreeViewMap (ref)
71       TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
72       /// Returns the TreeViewMap (const ref)
73       const TreeViewMapType& GetTreeViewMap() const
74       { return mTreeViewMap; }
75
76       /// Finalize 
77       virtual void Finalize();
78
79           ///Returns the maximal priority
80       int GetMaximalPriority(){return mReader.GetMaximalPriority();}
81
82       ///Adds the selected Images to the given vector
83       virtual void GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
84         { GimmickError("INTERNAL ERROR : GetSelectedImagesInVector not implemented"); }
85
86       ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
87       virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim) 
88           { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
89
90       virtual void GetSelectedFiles(std::vector<std::string>& s)
91       { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
92
93       virtual void GetImages(int dim, std::vector<std::string> files, std::vector<vtkImageData*>& s) 
94       { GimmickError("INTERNAL ERROR : GetImages not implemented"); }
95
96       virtual void OnSelectionChange(const std::vector<tree::Node*>& s, bool isSelection, int selection, bool mProcess)
97       { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
98
99            virtual void ClearSelection()
100       { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
101
102           ///Adds a file to ignore
103           virtual void AddIgnoreFile(tree::Node* toRemove)
104           { GimmickError("INTERNAL ERROR : AddIgnoreFile not implemented"); }
105       
106           ///Copies selected files
107           virtual void CopyFiles(const std::vector<std::string>& filenames)
108           { GimmickError("INTERNAL ERROR : CopyFiles not implemented"); }
109
110           ///Edits the fields of a given node
111           virtual void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
112           { GimmickError("INTERNAL ERROR : EditFields not implemented"); }
113       
114           /// Anonymize or de-anonymize data
115           void Anonymize(std::vector<std::string> i_filenames, int type);
116
117           /// Display all Dicom Tags
118           virtual void DumpTags(const std::string filename)
119           {GimmickError("INTERNAL ERROR : DumpTags not implemented"); }
120           
121             ///Edits the fields of a given node
122           virtual void ExportToStorage(const std::vector<std::string> keys)
123           { GimmickError("INTERNAL ERROR : ExportToStorage not implemented"); }
124       
125            ///Copies selected files
126           virtual void SaveAs(const std::vector<std::string>& filenames)
127           { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
128
129           /// No selected image
130           bool NoValidateSelected();
131
132       ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
133       bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
134
135       ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
136           void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
137
138       ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
139           void ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
140
141 ///Requests the reading of an image with priority and index in the 
142       /// current selection (-1 if not in selection)
143       //void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
144           void RequestReading(tree::Node* n, int prio, int selection_index , boost::shared_ptr<ImagePointerHolder> p);
145
146       ///Obtains the message of the state
147       std::string GetMessage(){return mMess;}
148
149      ///Obtains the message of the state
150       void SetMessage(std::string mess){mMess=mess;}
151
152           ///Resets the data of the extent and begins a new selection
153           void ResetExtent();
154
155       /// Create the tree views 
156       void CreateTreeViews();
157
158           /// Create a tree view with a given name
159           void CreateSingleTreeView(std::string &i_name);
160
161       /// Create the tree view for TreeHandler provided
162       virtual void CreateTreeView( TreeHandler* ) 
163       { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
164
165       /// Updates the TreeView of given name from level l to bottom
166       /// (calls the virtual method TreeView::UpdateLevel(l))
167       virtual void UpdateTreeViewLevel(const std::string&, int l);
168
169           // Multi-thread image reader callback
170           void OnMultiThreadImageReaderEvent(const std::string& filename,
171                                        MultiThreadImageReaderUser::EventType t,
172                                        vtkImageData* image);
173
174       vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
175
176       //=============================================
177       typedef boost::signal<void (bool)>  ValidationSignalType;
178       typedef ValidationSignalType::slot_function_type ValidationCallbackType;
179       //=============================================
180
181      //==================================================================
182       /// Adds the function f to the list of functions to call 
183       /// when the addition progresses.
184       /// f is of type ProgressCallbackType which is:
185       /// void (*ProgressCallbackType)(Progress&)
186       /// To pass a member function 'f' of an instance 'c' of a class 'C' 
187       /// as callback you have to 'bind' it, i.e. call:
188       /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
189       void ConnectValidationObserver(ValidationCallbackType callback);
190      //==================================================================
191
192         void modifyValidationSignal(bool ivalid);
193
194         
195         void readImages(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
196                          OutputAttr i_attr, int i_dim, double i_zspc);
197                         bool isSingle(const std::string i_file);
198
199         void stopReader();
200     private:
201
202
203         typedef void (*readXD)(std::vector<OutStrGimmick>&,  std::vector<std::string>, OutputAttr, double);
204
205         void getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr);
206
207         virtual void readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
208                          OutputAttr i_attr, double i_zspc);
209
210         virtual void readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
211                          OutputAttr i_attr, double i_zspc);
212
213         virtual void readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
214                          OutputAttr i_attr);
215
216         virtual void readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
217                          OutputAttr i_attr);
218
219
220       /// Controller which manages the interaction with the model
221       boost::shared_ptr< Gimmick> mGimmick;
222
223       /// The views 
224       TreeViewMapType mTreeViewMap;
225
226       /// The message that results from the validation
227       std::string mMess;
228
229       /// Multi-thread image reader
230       MultiThreadImageReader mReader;
231
232       /// Internal type of image reading event
233       /// If the image pointer is non null then the image is available (loaded)
234       /// else it has been unloaded
235       struct ImageEventType
236       {
237         ImageEventType( tree::Node* no = 0,   
238                         int sel_index = -1)
239 //                      ImagePointerHolder* ph= 0)
240           : node(no), index(sel_index){}//,  pointerHolder(ph){}
241         ImageEventType(vtkImageData* im )
242           : image(im) {}
243         tree::Node* node;
244         vtkImageData* image;
245                 int index;
246                 boost::shared_ptr<ImagePointerHolder> pointerHolder;
247       };
248       typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
249       /// Map of images' names to ImageEventType
250       /// Used to associated a filename to a the data of a request
251       ImageEventTypeMap mImageEventMap;
252
253       // queue of image event 
254       typedef std::deque<ImageEventType> ImageEventQueueType;
255
256       //ImageEventQueueType mImageEventQueue;
257
258           ///The current image extent
259           boost::shared_ptr<ImageExtent> mImageExtent;
260
261           ///The validation signal
262           ValidationSignalType mValidationSignal;
263
264           ///Boolean that determines if the selection is valid
265           bool valid;
266
267           ///Boolean that determines if the reader has been started
268           bool mReaderStarted;
269
270         };
271   // EO class GimmickView
272     //=====================================================================
273
274  
275 } // EO namespace creaImageIO
276
277 // EOF
278 #endif