]> Creatis software - creaImageIO.git/blob - src2/creaImageIOGimmickView.h
Debugged the thread and added a deletion on exit
[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       ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
64       virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim) 
65           { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
66
67       virtual void GetSelectedFiles(std::vector<std::string>& s)
68       { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
69       virtual void OnSelectionChange(std::vector<tree::Node*>& s)
70       { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
71       
72       ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
73       bool ValidateSelected (std::vector<tree::Node*>& sel, int min_dim, int max_dim);
74       
75       ///Reads the vector of nodes, builds images in the dimension required and returns them in the supplied vector.
76       void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<tree::Node*> im, int dim);
77       ///Requests the reading of an image with priority and index in the 
78       /// current selection (-1 if not in selection)
79       void RequestReading(tree::Node* n, int prio, int selection_index);
80
81       ///Returns true if the ImageEventQueue is empty
82       bool IsQueueEmpty(){return mImageEventQueue.empty();}
83       ///Clears the queue
84       void ClearQueue(){mImageEventQueue.clear();}
85       ///Returns the next in line EventType's image
86       vtkImageData* GetNextImageQueued(){return mImageEventQueue.front().image;}
87       ///Returns the next in line EventType's node
88       tree::Node* GetNextNodeQueued(){return mImageEventQueue.front().node;}
89       ///Returns the next in line EventType's index in selection
90       int GetNextSelectionIndexQueued(){return mImageEventQueue.front().index;}
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       vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
116
117
118       //=============================================
119       typedef boost::signal<void (bool)>  ValidationSignalType;
120       typedef ValidationSignalType::slot_function_type ValidationCallbackType;
121       //=============================================
122
123      //==================================================================
124       /// Adds the function f to the list of functions to call 
125       /// when the addition progresses.
126       /// f is of type ProgressCallbackType which is:
127       /// void (*ProgressCallbackType)(Progress&)
128       /// To pass a member function 'f' of an instance 'c' of a class 'C' 
129       /// as callback you have to 'bind' it, i.e. call:
130       /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
131       void ConnectValidationObserver(ValidationCallbackType callback);
132      //==================================================================
133
134
135     private:
136       /// Controller which manages the interaction with the model
137       Gimmick* mGimmick;
138       /// The views 
139       TreeViewMapType mTreeViewMap;
140       /// The message that results from the validation
141       std::string mMess;
142
143       /// Multi-thread image reader
144       MultiThreadImageReader mReader;
145       /// Internal type of image reading event
146       /// If the image pointer is non null then the image is available (loaded)
147       /// else it has been unloaded
148       struct ImageEventType
149       {
150         ImageEventType( tree::Node* no = 0,  
151                         vtkImageData* im = 0, 
152                         int sel_index = -1)
153           : node(no), image(im), index(sel_index) {}
154         ImageEventType(vtkImageData* im )
155           : image(im) {}
156         tree::Node* node;
157         vtkImageData* image;
158         int index;
159       };
160       typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
161       /// Map of images' names to ImageEventType
162       /// Used to associated a filename to a the data of a request
163       ImageEventTypeMap mImageEventMap;
164       // queue of image event 
165       typedef std::deque<ImageEventType> ImageEventQueueType;
166       ImageEventQueueType mImageEventQueue;
167
168           ValidationSignalType mValidationSignal;
169       
170         };
171   // EO class GimmickView
172     //=====================================================================
173   
174
175   /*
176
177
178
179
180
181
182
183
184         //====================================================================
185         // General
186         //====================================================================
187
188     /// Returns the size of the current selection
189     virtual int GetSelectionSize() { return 0; } 
190     /// Returns true if there is a valid selection
191     virtual bool IsSelectionValid(){ return false; }
192     /// Returns the vector of full filenames of selected images
193     virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
194     /// Returns the vector of images corresponding to selection
195     virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
196     /// Returns the vector of DicomNode corresponding to selection
197     virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
198    /// Returns the DicomNode corresponding to the tree item
199     virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
200
201         
202         /// Type of list of DicomDatabase
203     typedef std::vector<DicomDatabase*> DicomDatabaseListType;
204     /// Returns the list of DicomDatabase open
205     virtual DicomDatabaseListType& GetDicomDatabaseList() 
206     { return null; }
207     /// Returns the list of DicomDatabase open (const)
208     virtual const DicomDatabaseListType& GetDicomDatabaseList() const 
209     { return null; }
210
211         protected:
212         ///Opens an existing database, or else, creates a local database.
213     virtual void OpenOrNewDatabase(bool open){ return; }
214         ///Shows the help
215         virtual void ShowHelp();
216
217         private:
218         ///Gets the extension of the database
219         const std::string& GetDatabaseExtension() { return null; }
220         ///Sets the extension of the database
221     virtual void SetDatabaseExtension(const std::string& ext){ return; }
222
223
224         //====================================================================
225     // Preview Display Related
226         //====================================================================
227
228
229     ///Shows the image sent as a parameter
230         private:
231          virtual void ShowImage(vtkImageData* image){ return; }
232
233         //====================================================================
234     // Favorites Related
235         //====================================================================
236
237
238         public:
239         ///Loads or creates a favorites database
240     virtual void LoadOrCreateFavoritesDatabase(){ return; }
241         private:
242         ///Creates the user settings directory
243     void CreateUserSettingsDirectory(){ return; }
244         ///Obtains the user settings directory
245         const std::string& GetUserSettingsDirectory(){ return null; }
246
247         //====================================================================  
248         // Attribute Display Related
249         //====================================================================
250
251
252         ///Shows the Information regarding the node sent as a parameter
253         private:
254      virtual void ShowInformation(DicomNode*){ return; }
255    
256         //====================================================================
257     // Tree Display Related
258     //====================================================================
259
260         protected:
261     /// Completely rebuilds the view with 
262     /// current DicomDatabaseList
263     virtual void RebuildView(){ return; }
264         /// Recursively updates the part of the view corresponding 
265     /// to the DicomDatabase passed
266     /// i.e. creates items for the DicomNode which do not have
267     ///      deletes obsolete items (whose DicomNode has been deleted)
268     virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
269     /// Recursively updates the part of the view corresponding 
270     /// to the DicomNode provided.
271     /// parent is its parent in the tree (where to insert / remove it)
272         virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
273     
274         private:
275         ///Type definition of the data regarding the tree
276     typedef WxGimmickTreeItemData TreeItemData;
277         ///Gets the item data of the tree item passed as a parameter
278     TreeItemData* GetItemData(const TreeItemId& id){ return null; }
279     ///Type definition of the data insid a node of the tree
280     typedef WxGimmickDicomNodeData NodeData;
281
282
283         //====================================================================
284     // Class Attributes
285     //====================================================================
286
287         
288         int mSelectionType;
289     int mSelectionMaxImageDimension;
290     int mCurrentSelectionImageSize[4];
291
292         ///Existent Database List
293     DicomDatabaseListType mDicomDatabaseList;
294         ///Favorites database
295     DicomDatabase* mFavoriteDatabase;
296
297         ///Path to the database list file
298     std::string mDatabaseListFile;
299         ///Extension of the database
300     std::string mDatabaseExtension;
301
302     bool mJustStarted;
303
304     int  mFirstDicomDatabaseIconIndex;
305
306    // Previewer
307     vtkImageViewer2* mViewer;
308     
309     int mx1,mx2,my1,my2,mz1,mz2;
310     double mspx,mspy,mspz;
311   
312     // Image preview :
313     // Multi-thread image reader
314     MultiThreadImageReader mReader;
315     // map of images name to node
316     std::map<std::string,DicomNode*> mImageFileNameToNode;
317   */
318  
319 } // EO namespace creaImageIO
320
321 // EOF
322 #endif