]> Creatis software - creaImageIO.git/blob - src2/creaImageIOGimmickView.h
8ab1c68b88ba60022c3d2fd61d793ab10c9b8c21
[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 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         
137       /// Controller which manages the interaction with the model
138       Gimmick* mGimmick;
139       /// The views 
140       TreeViewMapType mTreeViewMap;
141       /// The message that results from the validation
142       std::string mMess;
143
144       /// Multi-thread image reader
145       MultiThreadImageReader mReader;
146       /// Internal type of image reading event
147       /// If the image pointer is non null then the image is available (loaded)
148       /// else it has been unloaded
149       struct ImageEventType
150       {
151         ImageEventType( tree::Node* no = 0,   
152                         int sel_index = -1,
153                         ImagePointerHolder* ph= 0)
154           : node(no), index(sel_index),  pointerHolder(ph){}
155         ImageEventType(vtkImageData* im )
156           : image(im) {}
157         tree::Node* node;
158         vtkImageData* image;
159                 int index;
160                 ImagePointerHolder* pointerHolder;
161       };
162       typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
163       /// Map of images' names to ImageEventType
164       /// Used to associated a filename to a the data of a request
165       ImageEventTypeMap mImageEventMap;
166       // queue of image event 
167       typedef std::deque<ImageEventType> ImageEventQueueType;
168       //ImageEventQueueType mImageEventQueue;
169
170           ///The current image extent
171           ImageExtent* mImageExtent;
172           ///The validation signal
173           ValidationSignalType mValidationSignal;
174           ///Boolean that determines if the selection is valid
175           bool valid;
176           ///Boolean that determines if the reader has been started
177           bool mReaderStarted;
178       
179         };
180   // EO class GimmickView
181     //=====================================================================
182   
183
184   /*
185
186
187
188
189
190
191
192
193         //====================================================================
194         // General
195         //====================================================================
196
197     /// Returns the size of the current selection
198     virtual int GetSelectionSize() { return 0; } 
199     /// Returns true if there is a valid selection
200     virtual bool IsSelectionValid(){ return false; }
201     /// Returns the vector of full filenames of selected images
202     virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
203     /// Returns the vector of images corresponding to selection
204     virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
205     /// Returns the vector of DicomNode corresponding to selection
206     virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
207    /// Returns the DicomNode corresponding to the tree item
208     virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
209
210         
211         /// Type of list of DicomDatabase
212     typedef std::vector<DicomDatabase*> DicomDatabaseListType;
213     /// Returns the list of DicomDatabase open
214     virtual DicomDatabaseListType& GetDicomDatabaseList() 
215     { return null; }
216     /// Returns the list of DicomDatabase open (const)
217     virtual const DicomDatabaseListType& GetDicomDatabaseList() const 
218     { return null; }
219
220         protected:
221         ///Opens an existing database, or else, creates a local database.
222     virtual void OpenOrNewDatabase(bool open){ return; }
223         ///Shows the help
224         virtual void ShowHelp();
225
226         private:
227         ///Gets the extension of the database
228         const std::string& GetDatabaseExtension() { return null; }
229         ///Sets the extension of the database
230     virtual void SetDatabaseExtension(const std::string& ext){ return; }
231
232
233         //====================================================================
234     // Preview Display Related
235         //====================================================================
236
237
238     ///Shows the image sent as a parameter
239         private:
240          virtual void ShowImage(vtkImageData* image){ return; }
241
242         //====================================================================
243     // Favorites Related
244         //====================================================================
245
246
247         public:
248         ///Loads or creates a favorites database
249     virtual void LoadOrCreateFavoritesDatabase(){ return; }
250         private:
251         ///Creates the user settings directory
252     void CreateUserSettingsDirectory(){ return; }
253         ///Obtains the user settings directory
254         const std::string& GetUserSettingsDirectory(){ return null; }
255
256         //====================================================================  
257         // Attribute Display Related
258         //====================================================================
259
260
261         ///Shows the Information regarding the node sent as a parameter
262         private:
263      virtual void ShowInformation(DicomNode*){ return; }
264    
265         //====================================================================
266     // Tree Display Related
267     //====================================================================
268
269         protected:
270     /// Completely rebuilds the view with 
271     /// current DicomDatabaseList
272     virtual void RebuildView(){ return; }
273         /// Recursively updates the part of the view corresponding 
274     /// to the DicomDatabase passed
275     /// i.e. creates items for the DicomNode which do not have
276     ///      deletes obsolete items (whose DicomNode has been deleted)
277     virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
278     /// Recursively updates the part of the view corresponding 
279     /// to the DicomNode provided.
280     /// parent is its parent in the tree (where to insert / remove it)
281         virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
282     
283         private:
284         ///Type definition of the data regarding the tree
285     typedef WxGimmickTreeItemData TreeItemData;
286         ///Gets the item data of the tree item passed as a parameter
287     TreeItemData* GetItemData(const TreeItemId& id){ return null; }
288     ///Type definition of the data insid a node of the tree
289     typedef WxGimmickDicomNodeData NodeData;
290
291
292         //====================================================================
293     // Class Attributes
294     //====================================================================
295
296         
297         int mSelectionType;
298     int mSelectionMaxImageDimension;
299     int mCurrentSelectionImageSize[4];
300
301         ///Existent Database List
302     DicomDatabaseListType mDicomDatabaseList;
303         ///Favorites database
304     DicomDatabase* mFavoriteDatabase;
305
306         ///Path to the database list file
307     std::string mDatabaseListFile;
308         ///Extension of the database
309     std::string mDatabaseExtension;
310
311     bool mJustStarted;
312
313     int  mFirstDicomDatabaseIconIndex;
314
315    // Previewer
316     vtkImageViewer2* mViewer;
317     
318     int mx1,mx2,my1,my2,mz1,mz2;
319     double mspx,mspy,mspz;
320   
321     // Image preview :
322     // Multi-thread image reader
323     MultiThreadImageReader mReader;
324     // map of images name to node
325     std::map<std::string,DicomNode*> mImageFileNameToNode;
326   */
327  
328 } // EO namespace creaImageIO
329
330 // EOF
331 #endif