1 #ifndef __creaImageIOGimmickView_h_INCLUDED__
2 #define __creaImageIOGimmickView_h_INCLUDED__
4 #include <creaImageIOGimmick.h>
5 #include <creaImageIOTreeView.h>
6 #include <creaImageIOSystem.h>
9 #include <vtkImageData.h>
10 #include <creaImageIOMultiThreadImageReader.h>
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
27 //=====================================================================
29 //=====================================================================
30 ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
31 class GimmickView: public MultiThreadImageReaderUser
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
41 virtual void Initialize();
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;
47 /// Returns the TreeViewMap (ref)
48 TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
49 /// Returns the TreeViewMap (const ref)
50 const TreeViewMapType& GetTreeViewMap() const
51 { return mTreeViewMap; }
54 virtual void Finalize();
56 //Returns the maximal priority
57 int GetMaximalPriority(){return mReader.GetMaximalPriority();}
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"); }
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"); }
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);
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();}
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();}
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;}
96 /// Create the tree views
97 void CreateTreeViews();
99 /// Create the tree view for TreeHandler provided
100 virtual void CreateTreeView( TreeHandler*)
101 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
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);
112 /// Controller which manages the interaction with the model
115 TreeViewMapType mTreeViewMap;
116 /// The message that results from the validation
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
127 ImageEventType( tree::Node* no, vtkImageData* im )
128 : node(no), image(im) {}
129 ImageEventType(vtkImageData* im )
134 // queue of image event
135 typedef std::deque<ImageEventType> ImageEventQueueType;
136 ImageEventQueueType mImageEventQueue;
139 // EO class GimmickView
140 //=====================================================================
152 //====================================================================
154 //====================================================================
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);
170 /// Type of list of DicomDatabase
171 typedef std::vector<DicomDatabase*> DicomDatabaseListType;
172 /// Returns the list of DicomDatabase open
173 virtual DicomDatabaseListType& GetDicomDatabaseList()
175 /// Returns the list of DicomDatabase open (const)
176 virtual const DicomDatabaseListType& GetDicomDatabaseList() const
180 ///Opens an existing database, or else, creates a local database.
181 virtual void OpenOrNewDatabase(bool open){ return; }
183 virtual void ShowHelp();
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; }
192 //====================================================================
193 // Preview Display Related
194 //====================================================================
197 ///Shows the image sent as a parameter
199 virtual void ShowImage(vtkImageData* image){ return; }
201 //====================================================================
203 //====================================================================
207 ///Loads or creates a favorites database
208 virtual void LoadOrCreateFavoritesDatabase(){ return; }
210 ///Creates the user settings directory
211 void CreateUserSettingsDirectory(){ return; }
212 ///Obtains the user settings directory
213 const std::string& GetUserSettingsDirectory(){ return null; }
215 //====================================================================
216 // Attribute Display Related
217 //====================================================================
220 ///Shows the Information regarding the node sent as a parameter
222 virtual void ShowInformation(DicomNode*){ return; }
224 //====================================================================
225 // Tree Display Related
226 //====================================================================
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; }
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;
251 //====================================================================
253 //====================================================================
257 int mSelectionMaxImageDimension;
258 int mCurrentSelectionImageSize[4];
260 ///Existent Database List
261 DicomDatabaseListType mDicomDatabaseList;
262 ///Favorites database
263 DicomDatabase* mFavoriteDatabase;
265 ///Path to the database list file
266 std::string mDatabaseListFile;
267 ///Extension of the database
268 std::string mDatabaseExtension;
272 int mFirstDicomDatabaseIconIndex;
275 vtkImageViewer2* mViewer;
277 int mx1,mx2,my1,my2,mz1,mz2;
278 double mspx,mspy,mspz;
281 // Multi-thread image reader
282 MultiThreadImageReader mReader;
283 // map of images name to node
284 std::map<std::string,DicomNode*> mImageFileNameToNode;
287 } // EO namespace creaImageIO