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