1 #ifndef __creaImageIOGimmickView_h_INCLUDED__
2 #define __creaImageIOGimmickView_h_INCLUDED__
4 #include <creaImageIOGimmick.h>
5 #include <creaImageIOTreeView.h>
6 #include <creaImageIOSystem.h>
7 #include <creaImageIOImagePointerHolder.h>
10 #include <vtkImageData.h>
11 #include <creaImageIOMultiThreadImageReader.h>
13 // Signal/slot mechanism for progress events
14 #include <boost/signal.hpp>
15 #include <boost/bind.hpp>
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
34 //=====================================================================
36 //=====================================================================
37 ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
38 class GimmickView: public MultiThreadImageReaderUser
43 GimmickView(Gimmick*, int number_of_threads = 0 );
44 /// Virtual destructor
45 virtual ~GimmickView();
46 /// Initializes the view :
47 /// Creates the TreeViews for all the TreeHandler of the Controller
49 virtual void Initialize();
51 /// Type of map from View name to TreeView*
52 /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
53 typedef std::map<std::string, TreeView*> TreeViewMapType;
55 /// Returns the TreeViewMap (ref)
56 TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
57 /// Returns the TreeViewMap (const ref)
58 const TreeViewMapType& GetTreeViewMap() const
59 { return mTreeViewMap; }
62 virtual void Finalize();
64 //Returns the maximal priority
65 int GetMaximalPriority(){return mReader.GetMaximalPriority();}
67 ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
68 virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
69 { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
71 virtual void GetSelectedFiles(std::vector<std::string>& s)
72 { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
73 virtual void OnSelectionChange(std::vector<tree::Node*>& s)
74 { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
75 virtual void ClearSelection()
76 { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
79 ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
80 bool ValidateSelected (std::vector<tree::Node*>& sel, int min_dim, int max_dim);
82 ///Reads the vector of nodes, builds images in the dimension required and returns them in the supplied vector.
83 void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<tree::Node*> im, int dim);
84 ///Requests the reading of an image with priority and index in the
85 /// current selection (-1 if not in selection)
86 void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
88 ///Returns true if the ImageEventQueue is empty
89 bool IsQueueEmpty(){return mImageEventQueue.empty();}
91 void ClearQueue(){mImageEventQueue.clear();}
92 ///Returns the next in line EventType's image
93 vtkImageData* GetNextImageQueued(){return mImageEventQueue.front().image;}
94 ///Returns the next in line EventType's node
95 tree::Node* GetNextNodeQueued(){return mImageEventQueue.front().node;}
96 ///Returns the next in line EventType's index in selection
97 int GetNextSelectionIndexQueued(){return mImageEventQueue.front().index;}
98 ///Unqueus the next in line EventType
99 void UnqueueNext(){mImageEventQueue.pop_front();}
102 ///Obtains the message of the state
103 std::string GetMessage(){return mMess;}
104 ///Obtains the message of the state
105 void SetMessage(std::string mess){mMess=mess;}
107 /// Create the tree views
108 void CreateTreeViews();
110 /// Create the tree view for TreeHandler provided
111 virtual void CreateTreeView( TreeHandler*)
112 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
114 /// Updates the TreeView of given name from level l to bottom
115 /// (calls the virtual method TreeView::UpdateLevel(l))
116 virtual void UpdateTreeViewLevel(const std::string&, int l);
117 // Multi-thread image reader callback
118 void OnMultiThreadImageReaderEvent(const std::string& filename,
119 MultiThreadImageReaderUser::EventType t,
120 vtkImageData* image);
122 vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
125 //=============================================
126 typedef boost::signal<void (bool)> ValidationSignalType;
127 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
128 //=============================================
130 //==================================================================
131 /// Adds the function f to the list of functions to call
132 /// when the addition progresses.
133 /// f is of type ProgressCallbackType which is:
134 /// void (*ProgressCallbackType)(Progress&)
135 /// To pass a member function 'f' of an instance 'c' of a class 'C'
136 /// as callback you have to 'bind' it, i.e. call:
137 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
138 void ConnectValidationObserver(ValidationCallbackType callback);
139 //==================================================================
143 /// Controller which manages the interaction with the model
146 TreeViewMapType mTreeViewMap;
147 /// The message that results from the validation
150 /// Multi-thread image reader
151 MultiThreadImageReader mReader;
152 /// Internal type of image reading event
153 /// If the image pointer is non null then the image is available (loaded)
154 /// else it has been unloaded
155 struct ImageEventType
157 ImageEventType( tree::Node* no = 0,
159 ImagePointerHolder* ph= 0)
160 : node(no), index(sel_index), pointerHolder(ph){}
161 ImageEventType(vtkImageData* im )
166 ImagePointerHolder* pointerHolder;
168 typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
169 /// Map of images' names to ImageEventType
170 /// Used to associated a filename to a the data of a request
171 ImageEventTypeMap mImageEventMap;
172 // queue of image event
173 typedef std::deque<ImageEventType> ImageEventQueueType;
174 ImageEventQueueType mImageEventQueue;
176 ValidationSignalType mValidationSignal;
179 // EO class GimmickView
180 //=====================================================================
192 //====================================================================
194 //====================================================================
196 /// Returns the size of the current selection
197 virtual int GetSelectionSize() { return 0; }
198 /// Returns true if there is a valid selection
199 virtual bool IsSelectionValid(){ return false; }
200 /// Returns the vector of full filenames of selected images
201 virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
202 /// Returns the vector of images corresponding to selection
203 virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
204 /// Returns the vector of DicomNode corresponding to selection
205 virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
206 /// Returns the DicomNode corresponding to the tree item
207 virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
210 /// Type of list of DicomDatabase
211 typedef std::vector<DicomDatabase*> DicomDatabaseListType;
212 /// Returns the list of DicomDatabase open
213 virtual DicomDatabaseListType& GetDicomDatabaseList()
215 /// Returns the list of DicomDatabase open (const)
216 virtual const DicomDatabaseListType& GetDicomDatabaseList() const
220 ///Opens an existing database, or else, creates a local database.
221 virtual void OpenOrNewDatabase(bool open){ return; }
223 virtual void ShowHelp();
226 ///Gets the extension of the database
227 const std::string& GetDatabaseExtension() { return null; }
228 ///Sets the extension of the database
229 virtual void SetDatabaseExtension(const std::string& ext){ return; }
232 //====================================================================
233 // Preview Display Related
234 //====================================================================
237 ///Shows the image sent as a parameter
239 virtual void ShowImage(vtkImageData* image){ return; }
241 //====================================================================
243 //====================================================================
247 ///Loads or creates a favorites database
248 virtual void LoadOrCreateFavoritesDatabase(){ return; }
250 ///Creates the user settings directory
251 void CreateUserSettingsDirectory(){ return; }
252 ///Obtains the user settings directory
253 const std::string& GetUserSettingsDirectory(){ return null; }
255 //====================================================================
256 // Attribute Display Related
257 //====================================================================
260 ///Shows the Information regarding the node sent as a parameter
262 virtual void ShowInformation(DicomNode*){ return; }
264 //====================================================================
265 // Tree Display Related
266 //====================================================================
269 /// Completely rebuilds the view with
270 /// current DicomDatabaseList
271 virtual void RebuildView(){ return; }
272 /// Recursively updates the part of the view corresponding
273 /// to the DicomDatabase passed
274 /// i.e. creates items for the DicomNode which do not have
275 /// deletes obsolete items (whose DicomNode has been deleted)
276 virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
277 /// Recursively updates the part of the view corresponding
278 /// to the DicomNode provided.
279 /// parent is its parent in the tree (where to insert / remove it)
280 virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
283 ///Type definition of the data regarding the tree
284 typedef WxGimmickTreeItemData TreeItemData;
285 ///Gets the item data of the tree item passed as a parameter
286 TreeItemData* GetItemData(const TreeItemId& id){ return null; }
287 ///Type definition of the data insid a node of the tree
288 typedef WxGimmickDicomNodeData NodeData;
291 //====================================================================
293 //====================================================================
297 int mSelectionMaxImageDimension;
298 int mCurrentSelectionImageSize[4];
300 ///Existent Database List
301 DicomDatabaseListType mDicomDatabaseList;
302 ///Favorites database
303 DicomDatabase* mFavoriteDatabase;
305 ///Path to the database list file
306 std::string mDatabaseListFile;
307 ///Extension of the database
308 std::string mDatabaseExtension;
312 int mFirstDicomDatabaseIconIndex;
315 vtkImageViewer2* mViewer;
317 int mx1,mx2,my1,my2,mz1,mz2;
318 double mspx,mspy,mspz;
321 // Multi-thread image reader
322 MultiThreadImageReader mReader;
323 // map of images name to node
324 std::map<std::string,DicomNode*> mImageFileNameToNode;
327 } // EO namespace creaImageIO