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