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 // Signal/slot mechanism for progress events
13 #include <boost/signal.hpp>
14 #include <boost/bind.hpp>
16 #define GIMMICK_NO_IMAGE_SELECTION 0
17 #define GIMMICK_2D_IMAGE_SELECTION 2
18 #define GIMMICK_3D_IMAGE_SELECTION 3
19 #define GIMMICK_4D_IMAGE_SELECTION 4
31 //=====================================================================
33 //=====================================================================
34 ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
35 class GimmickView: public MultiThreadImageReaderUser
39 GimmickView(Gimmick*, int number_of_threads = 0 );
40 /// Virtual destructor
41 virtual ~GimmickView();
42 /// Initializes the view :
43 /// Creates the TreeViews for all the TreeHandler of the Controller
45 virtual void Initialize();
47 /// Type of map from View name to TreeView*
48 /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
49 typedef std::map<std::string, TreeView*> TreeViewMapType;
51 /// Returns the TreeViewMap (ref)
52 TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
53 /// Returns the TreeViewMap (const ref)
54 const TreeViewMapType& GetTreeViewMap() const
55 { return mTreeViewMap; }
58 virtual void Finalize();
60 //Returns the maximal priority
61 int GetMaximalPriority(){return mReader.GetMaximalPriority();}
63 ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
64 virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
65 { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
67 virtual void GetSelectedFiles(std::vector<std::string>& s)
68 { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
69 virtual void OnSelectionChange(std::vector<tree::Node*>& s)
70 { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
71 virtual void ClearSelection()
72 { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
75 ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
76 bool ValidateSelected (std::vector<tree::Node*>& sel, int min_dim, int max_dim);
78 ///Reads the vector of nodes, builds images in the dimension required and returns them in the supplied vector.
79 void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<tree::Node*> im, int dim);
80 ///Requests the reading of an image with priority and index in the
81 /// current selection (-1 if not in selection)
82 void RequestReading(tree::Node* n, int prio, int selection_index);
84 ///Returns true if the ImageEventQueue is empty
85 bool IsQueueEmpty(){return mImageEventQueue.empty();}
87 void ClearQueue(){mImageEventQueue.clear();}
88 ///Returns the next in line EventType's image
89 vtkImageData* GetNextImageQueued(){return mImageEventQueue.front().image;}
90 ///Returns the next in line EventType's node
91 tree::Node* GetNextNodeQueued(){return mImageEventQueue.front().node;}
92 ///Returns the next in line EventType's index in selection
93 int GetNextSelectionIndexQueued(){return mImageEventQueue.front().index;}
94 ///Unqueus the next in line EventType
95 void UnqueueNext(){mImageEventQueue.pop_front();}
98 ///Obtains the message of the state
99 std::string GetMessage(){return mMess;}
100 ///Obtains the message of the state
101 void SetMessage(std::string mess){mMess=mess;}
103 /// Create the tree views
104 void CreateTreeViews();
106 /// Create the tree view for TreeHandler provided
107 virtual void CreateTreeView( TreeHandler*)
108 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
110 /// Updates the TreeView of given name from level l to bottom
111 /// (calls the virtual method TreeView::UpdateLevel(l))
112 virtual void UpdateTreeViewLevel(const std::string&, int l);
113 // Multi-thread image reader callback
114 void OnMultiThreadImageReaderEvent(const std::string& filename,
115 MultiThreadImageReaderUser::EventType t,
116 vtkImageData* image);
118 vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
121 //=============================================
122 typedef boost::signal<void (bool)> ValidationSignalType;
123 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
124 //=============================================
126 //==================================================================
127 /// Adds the function f to the list of functions to call
128 /// when the addition progresses.
129 /// f is of type ProgressCallbackType which is:
130 /// void (*ProgressCallbackType)(Progress&)
131 /// To pass a member function 'f' of an instance 'c' of a class 'C'
132 /// as callback you have to 'bind' it, i.e. call:
133 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
134 void ConnectValidationObserver(ValidationCallbackType callback);
135 //==================================================================
139 /// Controller which manages the interaction with the model
142 TreeViewMapType mTreeViewMap;
143 /// The message that results from the validation
146 /// Multi-thread image reader
147 MultiThreadImageReader mReader;
148 /// Internal type of image reading event
149 /// If the image pointer is non null then the image is available (loaded)
150 /// else it has been unloaded
151 struct ImageEventType
153 ImageEventType( tree::Node* no = 0,
154 vtkImageData* im = 0,
156 : node(no), image(im), index(sel_index) {}
157 ImageEventType(vtkImageData* im )
163 typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
164 /// Map of images' names to ImageEventType
165 /// Used to associated a filename to a the data of a request
166 ImageEventTypeMap mImageEventMap;
167 // queue of image event
168 typedef std::deque<ImageEventType> ImageEventQueueType;
169 ImageEventQueueType mImageEventQueue;
171 ValidationSignalType mValidationSignal;
174 // EO class GimmickView
175 //=====================================================================
187 //====================================================================
189 //====================================================================
191 /// Returns the size of the current selection
192 virtual int GetSelectionSize() { return 0; }
193 /// Returns true if there is a valid selection
194 virtual bool IsSelectionValid(){ return false; }
195 /// Returns the vector of full filenames of selected images
196 virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
197 /// Returns the vector of images corresponding to selection
198 virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
199 /// Returns the vector of DicomNode corresponding to selection
200 virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
201 /// Returns the DicomNode corresponding to the tree item
202 virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
205 /// Type of list of DicomDatabase
206 typedef std::vector<DicomDatabase*> DicomDatabaseListType;
207 /// Returns the list of DicomDatabase open
208 virtual DicomDatabaseListType& GetDicomDatabaseList()
210 /// Returns the list of DicomDatabase open (const)
211 virtual const DicomDatabaseListType& GetDicomDatabaseList() const
215 ///Opens an existing database, or else, creates a local database.
216 virtual void OpenOrNewDatabase(bool open){ return; }
218 virtual void ShowHelp();
221 ///Gets the extension of the database
222 const std::string& GetDatabaseExtension() { return null; }
223 ///Sets the extension of the database
224 virtual void SetDatabaseExtension(const std::string& ext){ return; }
227 //====================================================================
228 // Preview Display Related
229 //====================================================================
232 ///Shows the image sent as a parameter
234 virtual void ShowImage(vtkImageData* image){ return; }
236 //====================================================================
238 //====================================================================
242 ///Loads or creates a favorites database
243 virtual void LoadOrCreateFavoritesDatabase(){ return; }
245 ///Creates the user settings directory
246 void CreateUserSettingsDirectory(){ return; }
247 ///Obtains the user settings directory
248 const std::string& GetUserSettingsDirectory(){ return null; }
250 //====================================================================
251 // Attribute Display Related
252 //====================================================================
255 ///Shows the Information regarding the node sent as a parameter
257 virtual void ShowInformation(DicomNode*){ return; }
259 //====================================================================
260 // Tree Display Related
261 //====================================================================
264 /// Completely rebuilds the view with
265 /// current DicomDatabaseList
266 virtual void RebuildView(){ return; }
267 /// Recursively updates the part of the view corresponding
268 /// to the DicomDatabase passed
269 /// i.e. creates items for the DicomNode which do not have
270 /// deletes obsolete items (whose DicomNode has been deleted)
271 virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
272 /// Recursively updates the part of the view corresponding
273 /// to the DicomNode provided.
274 /// parent is its parent in the tree (where to insert / remove it)
275 virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
278 ///Type definition of the data regarding the tree
279 typedef WxGimmickTreeItemData TreeItemData;
280 ///Gets the item data of the tree item passed as a parameter
281 TreeItemData* GetItemData(const TreeItemId& id){ return null; }
282 ///Type definition of the data insid a node of the tree
283 typedef WxGimmickDicomNodeData NodeData;
286 //====================================================================
288 //====================================================================
292 int mSelectionMaxImageDimension;
293 int mCurrentSelectionImageSize[4];
295 ///Existent Database List
296 DicomDatabaseListType mDicomDatabaseList;
297 ///Favorites database
298 DicomDatabase* mFavoriteDatabase;
300 ///Path to the database list file
301 std::string mDatabaseListFile;
302 ///Extension of the database
303 std::string mDatabaseExtension;
307 int mFirstDicomDatabaseIconIndex;
310 vtkImageViewer2* mViewer;
312 int mx1,mx2,my1,my2,mz1,mz2;
313 double mspx,mspy,mspz;
316 // Multi-thread image reader
317 MultiThreadImageReader mReader;
318 // map of images name to node
319 std::map<std::string,DicomNode*> mImageFileNameToNode;
322 } // EO namespace creaImageIO