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