]> Creatis software - creaImageIO.git/blob - src2/creaImageIOGimmickView.h
Linux compat
[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
8 //#include <map>
9 #include <vtkImageData.h>
10 #include <creaImageIOMultiThreadImageReader.h>
11
12 #define GIMMICK_NO_IMAGE_SELECTION 0
13 #define GIMMICK_2D_IMAGE_SELECTION 2
14 #define GIMMICK_3D_IMAGE_SELECTION 3
15 #define GIMMICK_4D_IMAGE_SELECTION 4
16
17 #define NATIVE 0
18 #define _2D 2
19 #define _3D 3
20
21
22 namespace creaImageIO
23 {
24         /**
25         * \ingroup View
26         */
27     //=====================================================================
28     
29     //=====================================================================
30     ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
31         class GimmickView: public MultiThreadImageReaderUser
32     {
33     public:
34       /// Ctor
35       GimmickView(Gimmick*, int number_of_threads = 0 );
36       /// Virtual destructor
37       virtual ~GimmickView();
38       /// Initializes the view : 
39       /// Creates the TreeViews for all the TreeHandler of the Controller
40       /// 
41       virtual void Initialize();
42
43       /// Type of map from View name to TreeView* 
44       /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
45       typedef std::map<std::string, TreeView*> TreeViewMapType;
46       
47       /// Returns the TreeViewMap (ref)
48       TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
49       /// Returns the TreeViewMap (const ref)
50       const TreeViewMapType& GetTreeViewMap() const
51       { return mTreeViewMap; }
52
53       /// Finalize 
54       virtual void Finalize();
55
56           //Returns the maximal priority
57           int GetMaximalPriority(){return mReader.GetMaximalPriority();}
58
59           ///Returns the selected Images and validates to see if they comply with the given parameter(<4D)
60           vtkImageData* GetSelectedImage(int dim);
61       ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
62       virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim) 
63           { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
64
65           virtual void GetSelectedFiles(std::vector<std::string>& s)
66           { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
67           virtual void OnSelectionChange(std::vector<tree::Node*>& s)
68           { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
69
70           ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
71           bool ValidateSelected (std::vector<tree::Node*>& sel, int min_dim, int max_dim);
72
73           ///Reads the vector of nodes, builds images in the dimension required and returns them in the supplied vector.
74           void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<tree::Node*> im, int dim);
75           ///Requests the reading of an image
76           void RequestReading(tree::Node* n, int prio){mReader.Request(this,n->GetAttribute("FullFileName"),prio);}
77           ///Adds an entry to the filename to node map
78           void AddEntryToMap(tree::Node* node){mImageFileNameToNode[node->GetAttribute("FullFileName")] = node;}
79           ///Returns true if the ImageEventQueue is empty
80           bool IsQueueEmpty(){return mImageEventQueue.empty();}
81           ///Clears the queue
82           void ClearQueue(){mImageEventQueue.clear();}
83           ///Returns the next in line EventType's image
84           vtkImageData* GetNextImageQueued(){return mImageEventQueue.front().image;}
85           ///Returns the next in line EventType's node
86           tree::Node* GetNextNodeQueued(){return mImageEventQueue.front().node;}
87           ///Unqueus the next in line EventType
88           void UnqueueNext(){mImageEventQueue.pop_front();}
89   
90
91           ///Obtains the message of the state
92           std::string GetMessage(){return mMess;}
93           ///Obtains the message of the state
94           void SetMessage(std::string mess){mMess=mess;}
95
96       /// Create the tree views 
97       void CreateTreeViews();
98
99       /// Create the tree view for TreeHandler provided
100       virtual void CreateTreeView( TreeHandler*) 
101       { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
102
103       /// Updates the TreeView of given name from level l to bottom
104       /// (calls the virtual method TreeView::UpdateLevel(l))
105       virtual void UpdateTreeViewLevel(const std::string&, int l);
106           // Multi-thread image reader callback
107           void OnMultiThreadImageReaderEvent(const std::string& filename,
108                                        MultiThreadImageReaderUser::EventType t,
109                                        vtkImageData* image);
110
111     private:
112       /// Controller which manages the interaction with the model
113       Gimmick* mGimmick;
114       /// The views 
115       TreeViewMapType mTreeViewMap;
116           /// The message that results from the validation
117           std::string mMess;
118           /// Multi-thread image reader
119           MultiThreadImageReader mReader;
120           /// Map of images' names to nodes
121           std::map<std::string,tree::Node*> mImageFileNameToNode;
122           /// type of image event
123           /// If the image pointer is non null then the image is available (loaded)
124       /// else it has been unloaded
125       struct ImageEventType
126       {
127                   ImageEventType( tree::Node* no,  vtkImageData* im )
128           : node(no), image(im) {}
129         ImageEventType(vtkImageData* im )
130           : image(im) {}
131         tree::Node* node;
132         vtkImageData* image;
133       };
134       // queue of image event 
135       typedef std::deque<ImageEventType> ImageEventQueueType;
136       ImageEventQueueType mImageEventQueue;
137       
138     };
139     // EO class GimmickView
140     //=====================================================================
141   
142
143   /*
144
145
146
147
148
149
150
151
152         //====================================================================
153         // General
154         //====================================================================
155
156     /// Returns the size of the current selection
157     virtual int GetSelectionSize() { return 0; } 
158     /// Returns true if there is a valid selection
159     virtual bool IsSelectionValid(){ return false; }
160     /// Returns the vector of full filenames of selected images
161     virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
162     /// Returns the vector of images corresponding to selection
163     virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
164     /// Returns the vector of DicomNode corresponding to selection
165     virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
166    /// Returns the DicomNode corresponding to the tree item
167     virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
168
169         
170         /// Type of list of DicomDatabase
171     typedef std::vector<DicomDatabase*> DicomDatabaseListType;
172     /// Returns the list of DicomDatabase open
173     virtual DicomDatabaseListType& GetDicomDatabaseList() 
174     { return null; }
175     /// Returns the list of DicomDatabase open (const)
176     virtual const DicomDatabaseListType& GetDicomDatabaseList() const 
177     { return null; }
178
179         protected:
180         ///Opens an existing database, or else, creates a local database.
181     virtual void OpenOrNewDatabase(bool open){ return; }
182         ///Shows the help
183         virtual void ShowHelp();
184
185         private:
186         ///Gets the extension of the database
187         const std::string& GetDatabaseExtension() { return null; }
188         ///Sets the extension of the database
189     virtual void SetDatabaseExtension(const std::string& ext){ return; }
190
191
192         //====================================================================
193     // Preview Display Related
194         //====================================================================
195
196
197     ///Shows the image sent as a parameter
198         private:
199          virtual void ShowImage(vtkImageData* image){ return; }
200
201         //====================================================================
202     // Favorites Related
203         //====================================================================
204
205
206         public:
207         ///Loads or creates a favorites database
208     virtual void LoadOrCreateFavoritesDatabase(){ return; }
209         private:
210         ///Creates the user settings directory
211     void CreateUserSettingsDirectory(){ return; }
212         ///Obtains the user settings directory
213         const std::string& GetUserSettingsDirectory(){ return null; }
214
215         //====================================================================  
216         // Attribute Display Related
217         //====================================================================
218
219
220         ///Shows the Information regarding the node sent as a parameter
221         private:
222      virtual void ShowInformation(DicomNode*){ return; }
223    
224         //====================================================================
225     // Tree Display Related
226     //====================================================================
227
228         protected:
229     /// Completely rebuilds the view with 
230     /// current DicomDatabaseList
231     virtual void RebuildView(){ return; }
232         /// Recursively updates the part of the view corresponding 
233     /// to the DicomDatabase passed
234     /// i.e. creates items for the DicomNode which do not have
235     ///      deletes obsolete items (whose DicomNode has been deleted)
236     virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
237     /// Recursively updates the part of the view corresponding 
238     /// to the DicomNode provided.
239     /// parent is its parent in the tree (where to insert / remove it)
240         virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
241     
242         private:
243         ///Type definition of the data regarding the tree
244     typedef WxGimmickTreeItemData TreeItemData;
245         ///Gets the item data of the tree item passed as a parameter
246     TreeItemData* GetItemData(const TreeItemId& id){ return null; }
247     ///Type definition of the data insid a node of the tree
248     typedef WxGimmickDicomNodeData NodeData;
249
250
251         //====================================================================
252     // Class Attributes
253     //====================================================================
254
255         
256         int mSelectionType;
257     int mSelectionMaxImageDimension;
258     int mCurrentSelectionImageSize[4];
259
260         ///Existent Database List
261     DicomDatabaseListType mDicomDatabaseList;
262         ///Favorites database
263     DicomDatabase* mFavoriteDatabase;
264
265         ///Path to the database list file
266     std::string mDatabaseListFile;
267         ///Extension of the database
268     std::string mDatabaseExtension;
269
270     bool mJustStarted;
271
272     int  mFirstDicomDatabaseIconIndex;
273
274    // Previewer
275     vtkImageViewer2* mViewer;
276     
277     int mx1,mx2,my1,my2,mz1,mz2;
278     double mspx,mspy,mspz;
279   
280     // Image preview :
281     // Multi-thread image reader
282     MultiThreadImageReader mReader;
283     // map of images name to node
284     std::map<std::string,DicomNode*> mImageFileNameToNode;
285   */
286  
287 } // EO namespace creaImageIO
288
289 // EOF
290 #endif