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