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