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