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"); }
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);
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();}
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();}
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;}
94 /// Create the tree views
95 void CreateTreeViews();
97 /// Create the tree view for TreeHandler provided
98 virtual void CreateTreeView( TreeHandler*)
99 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
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);
110 /// Controller which manages the interaction with the model
113 TreeViewMapType mTreeViewMap;
114 /// The message that results from the validation
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
125 ImageEventType( tree::Node* no, vtkImageData* im )
126 : node(no), image(im) {}
127 ImageEventType(vtkImageData* im )
132 // queue of image event
133 typedef std::deque<ImageEventType> ImageEventQueueType;
134 ImageEventQueueType mImageEventQueue;
137 // EO class GimmickView
138 //=====================================================================
150 //====================================================================
152 //====================================================================
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);
168 /// Type of list of DicomDatabase
169 typedef std::vector<DicomDatabase*> DicomDatabaseListType;
170 /// Returns the list of DicomDatabase open
171 virtual DicomDatabaseListType& GetDicomDatabaseList()
173 /// Returns the list of DicomDatabase open (const)
174 virtual const DicomDatabaseListType& GetDicomDatabaseList() const
178 ///Opens an existing database, or else, creates a local database.
179 virtual void OpenOrNewDatabase(bool open){ return; }
181 virtual void ShowHelp();
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; }
190 //====================================================================
191 // Preview Display Related
192 //====================================================================
195 ///Shows the image sent as a parameter
197 virtual void ShowImage(vtkImageData* image){ return; }
199 //====================================================================
201 //====================================================================
205 ///Loads or creates a favorites database
206 virtual void LoadOrCreateFavoritesDatabase(){ return; }
208 ///Creates the user settings directory
209 void CreateUserSettingsDirectory(){ return; }
210 ///Obtains the user settings directory
211 const std::string& GetUserSettingsDirectory(){ return null; }
213 //====================================================================
214 // Attribute Display Related
215 //====================================================================
218 ///Shows the Information regarding the node sent as a parameter
220 virtual void ShowInformation(DicomNode*){ return; }
222 //====================================================================
223 // Tree Display Related
224 //====================================================================
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; }
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;
249 //====================================================================
251 //====================================================================
255 int mSelectionMaxImageDimension;
256 int mCurrentSelectionImageSize[4];
258 ///Existent Database List
259 DicomDatabaseListType mDicomDatabaseList;
260 ///Favorites database
261 DicomDatabase* mFavoriteDatabase;
263 ///Path to the database list file
264 std::string mDatabaseListFile;
265 ///Extension of the database
266 std::string mDatabaseExtension;
270 int mFirstDicomDatabaseIconIndex;
273 vtkImageViewer2* mViewer;
275 int mx1,mx2,my1,my2,mz1,mz2;
276 double mspx,mspy,mspz;
279 // Multi-thread image reader
280 MultiThreadImageReader mReader;
281 // map of images name to node
282 std::map<std::string,DicomNode*> mImageFileNameToNode;
285 } // EO namespace creaImageIO