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