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