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