]> Creatis software - creaImageIO.git/blob - src2/creaImageIOGimmickView.h
Added boost signal to validate
[creaImageIO.git] / src2 / 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
8 //#include <map>
9 #include <vtkImageData.h>
10 #include <creaImageIOMultiThreadImageReader.h>
11
12 // Signal/slot mechanism for progress events
13 #include <boost/signal.hpp>
14 #include <boost/bind.hpp>
15
16 #define GIMMICK_NO_IMAGE_SELECTION 0
17 #define GIMMICK_2D_IMAGE_SELECTION 2
18 #define GIMMICK_3D_IMAGE_SELECTION 3
19 #define GIMMICK_4D_IMAGE_SELECTION 4
20
21 #define NATIVE 0
22 #define _2D 2
23 #define _3D 3
24
25
26 namespace creaImageIO
27 {
28         /**
29         * \ingroup View
30         */
31     //=====================================================================
32     
33     //=====================================================================
34     ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
35         class GimmickView: public MultiThreadImageReaderUser
36     {
37     public:
38       /// Ctor
39       GimmickView(Gimmick*, int number_of_threads = 0 );
40       /// Virtual destructor
41       virtual ~GimmickView();
42       /// Initializes the view : 
43       /// Creates the TreeViews for all the TreeHandler of the Controller
44       /// 
45       virtual void Initialize();
46
47       /// Type of map from View name to TreeView* 
48       /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
49       typedef std::map<std::string, TreeView*> TreeViewMapType;
50       
51       /// Returns the TreeViewMap (ref)
52       TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
53       /// Returns the TreeViewMap (const ref)
54       const TreeViewMapType& GetTreeViewMap() const
55       { return mTreeViewMap; }
56
57       /// Finalize 
58       virtual void Finalize();
59
60           //Returns the maximal priority
61           int GetMaximalPriority(){return mReader.GetMaximalPriority();}
62
63           ///Returns the selected Images and validates to see if they comply with the given parameter(<4D)
64           vtkImageData* GetSelectedImage(int dim);
65       ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
66       virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim) 
67           { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
68
69           virtual void GetSelectedFiles(std::vector<std::string>& s)
70           { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
71           virtual void OnSelectionChange(std::vector<tree::Node*>& s)
72           { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
73
74           ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
75           bool ValidateSelected (std::vector<tree::Node*>& sel, int min_dim, int max_dim);
76
77           ///Reads the vector of nodes, builds images in the dimension required and returns them in the supplied vector.
78           void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<tree::Node*> im, int dim);
79           ///Requests the reading of an image
80           void RequestReading(tree::Node* n, int prio){mReader.Request(this,n->GetAttribute("FullFileName"),prio);}
81           ///Adds an entry to the filename to node map
82           void AddEntryToMap(tree::Node* node){mImageFileNameToNode[node->GetAttribute("FullFileName")] = node;}
83           ///Returns true if the ImageEventQueue is empty
84           bool IsQueueEmpty(){return mImageEventQueue.empty();}
85           ///Clears the queue
86           void ClearQueue(){mImageEventQueue.clear();}
87           ///Returns the next in line EventType's image
88           vtkImageData* GetNextImageQueued(){return mImageEventQueue.front().image;}
89           ///Returns the next in line EventType's node
90           tree::Node* GetNextNodeQueued(){return mImageEventQueue.front().node;}
91           ///Unqueus the next in line EventType
92           void UnqueueNext(){mImageEventQueue.pop_front();}
93   
94
95           ///Obtains the message of the state
96           std::string GetMessage(){return mMess;}
97           ///Obtains the message of the state
98           void SetMessage(std::string mess){mMess=mess;}
99
100       /// Create the tree views 
101       void CreateTreeViews();
102
103       /// Create the tree view for TreeHandler provided
104       virtual void CreateTreeView( TreeHandler*) 
105       { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
106
107       /// Updates the TreeView of given name from level l to bottom
108       /// (calls the virtual method TreeView::UpdateLevel(l))
109       virtual void UpdateTreeViewLevel(const std::string&, int l);
110           // Multi-thread image reader callback
111           void OnMultiThreadImageReaderEvent(const std::string& filename,
112                                        MultiThreadImageReaderUser::EventType t,
113                                        vtkImageData* image);
114
115           //=============================================
116       typedef boost::signal<void (bool)>  ValidationSignalType;
117       typedef ValidationSignalType::slot_function_type ValidationCallbackType;
118       //=============================================
119
120      //==================================================================
121       /// Adds the function f to the list of functions to call 
122       /// when the addition progresses.
123       /// f is of type ProgressCallbackType which is:
124       /// void (*ProgressCallbackType)(Progress&)
125       /// To pass a member function 'f' of an instance 'c' of a class 'C' 
126       /// as callback you have to 'bind' it, i.e. call:
127       /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
128       void ConnectValidationObserver(ValidationCallbackType callback);
129      //==================================================================
130
131     private:
132       /// Controller which manages the interaction with the model
133       Gimmick* mGimmick;
134       /// The views 
135       TreeViewMapType mTreeViewMap;
136           /// The message that results from the validation
137           std::string mMess;
138           /// Multi-thread image reader
139           MultiThreadImageReader mReader;
140           /// Map of images' names to nodes
141           std::map<std::string,tree::Node*> mImageFileNameToNode;
142           /// type of image event
143           /// If the image pointer is non null then the image is available (loaded)
144       /// else it has been unloaded
145       struct ImageEventType
146       {
147                   ImageEventType( tree::Node* no,  vtkImageData* im )
148           : node(no), image(im) {}
149         ImageEventType(vtkImageData* im )
150           : image(im) {}
151         tree::Node* node;
152         vtkImageData* image;
153       };
154       // queue of image event 
155       typedef std::deque<ImageEventType> ImageEventQueueType;
156       ImageEventQueueType mImageEventQueue;
157
158           ValidationSignalType mValidationSignal;
159       
160     };
161     // EO class GimmickView
162     //=====================================================================
163   
164
165   /*
166
167
168
169
170
171
172
173
174         //====================================================================
175         // General
176         //====================================================================
177
178     /// Returns the size of the current selection
179     virtual int GetSelectionSize() { return 0; } 
180     /// Returns true if there is a valid selection
181     virtual bool IsSelectionValid(){ return false; }
182     /// Returns the vector of full filenames of selected images
183     virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
184     /// Returns the vector of images corresponding to selection
185     virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
186     /// Returns the vector of DicomNode corresponding to selection
187     virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
188    /// Returns the DicomNode corresponding to the tree item
189     virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
190
191         
192         /// Type of list of DicomDatabase
193     typedef std::vector<DicomDatabase*> DicomDatabaseListType;
194     /// Returns the list of DicomDatabase open
195     virtual DicomDatabaseListType& GetDicomDatabaseList() 
196     { return null; }
197     /// Returns the list of DicomDatabase open (const)
198     virtual const DicomDatabaseListType& GetDicomDatabaseList() const 
199     { return null; }
200
201         protected:
202         ///Opens an existing database, or else, creates a local database.
203     virtual void OpenOrNewDatabase(bool open){ return; }
204         ///Shows the help
205         virtual void ShowHelp();
206
207         private:
208         ///Gets the extension of the database
209         const std::string& GetDatabaseExtension() { return null; }
210         ///Sets the extension of the database
211     virtual void SetDatabaseExtension(const std::string& ext){ return; }
212
213
214         //====================================================================
215     // Preview Display Related
216         //====================================================================
217
218
219     ///Shows the image sent as a parameter
220         private:
221          virtual void ShowImage(vtkImageData* image){ return; }
222
223         //====================================================================
224     // Favorites Related
225         //====================================================================
226
227
228         public:
229         ///Loads or creates a favorites database
230     virtual void LoadOrCreateFavoritesDatabase(){ return; }
231         private:
232         ///Creates the user settings directory
233     void CreateUserSettingsDirectory(){ return; }
234         ///Obtains the user settings directory
235         const std::string& GetUserSettingsDirectory(){ return null; }
236
237         //====================================================================  
238         // Attribute Display Related
239         //====================================================================
240
241
242         ///Shows the Information regarding the node sent as a parameter
243         private:
244      virtual void ShowInformation(DicomNode*){ return; }
245    
246         //====================================================================
247     // Tree Display Related
248     //====================================================================
249
250         protected:
251     /// Completely rebuilds the view with 
252     /// current DicomDatabaseList
253     virtual void RebuildView(){ return; }
254         /// Recursively updates the part of the view corresponding 
255     /// to the DicomDatabase passed
256     /// i.e. creates items for the DicomNode which do not have
257     ///      deletes obsolete items (whose DicomNode has been deleted)
258     virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
259     /// Recursively updates the part of the view corresponding 
260     /// to the DicomNode provided.
261     /// parent is its parent in the tree (where to insert / remove it)
262         virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
263     
264         private:
265         ///Type definition of the data regarding the tree
266     typedef WxGimmickTreeItemData TreeItemData;
267         ///Gets the item data of the tree item passed as a parameter
268     TreeItemData* GetItemData(const TreeItemId& id){ return null; }
269     ///Type definition of the data insid a node of the tree
270     typedef WxGimmickDicomNodeData NodeData;
271
272
273         //====================================================================
274     // Class Attributes
275     //====================================================================
276
277         
278         int mSelectionType;
279     int mSelectionMaxImageDimension;
280     int mCurrentSelectionImageSize[4];
281
282         ///Existent Database List
283     DicomDatabaseListType mDicomDatabaseList;
284         ///Favorites database
285     DicomDatabase* mFavoriteDatabase;
286
287         ///Path to the database list file
288     std::string mDatabaseListFile;
289         ///Extension of the database
290     std::string mDatabaseExtension;
291
292     bool mJustStarted;
293
294     int  mFirstDicomDatabaseIconIndex;
295
296    // Previewer
297     vtkImageViewer2* mViewer;
298     
299     int mx1,mx2,my1,my2,mz1,mz2;
300     double mspx,mspy,mspz;
301   
302     // Image preview :
303     // Multi-thread image reader
304     MultiThreadImageReader mReader;
305     // map of images name to node
306     std::map<std::string,DicomNode*> mImageFileNameToNode;
307   */
308  
309 } // EO namespace creaImageIO
310
311 // EOF
312 #endif