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 ///Returns the selected Images and validates to see if they comply with the given parameter(<4D)
64 vtkImageData* GetSelectedImage(int dim);
65 ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
66 virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
67 { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
69 virtual void GetSelectedFiles(std::vector<std::string>& s)
70 { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
71 virtual void OnSelectionChange(std::vector<tree::Node*>& s)
72 { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
74 ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
75 bool ValidateSelected (std::vector<tree::Node*>& sel, int min_dim, int max_dim);
77 ///Reads the vector of nodes, builds images in the dimension required and returns them in the supplied vector.
78 void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<tree::Node*> im, int dim);
79 ///Requests the reading of an image
80 void RequestReading(tree::Node* n, int prio){mReader.Request(this,n->GetAttribute("FullFileName"),prio);}
81 ///Adds an entry to the filename to node map
82 void AddEntryToMap(tree::Node* node){mImageFileNameToNode[node->GetAttribute("FullFileName")] = node;}
83 ///Returns true if the ImageEventQueue is empty
84 bool IsQueueEmpty(){return mImageEventQueue.empty();}
86 void ClearQueue(){mImageEventQueue.clear();}
87 ///Returns the next in line EventType's image
88 vtkImageData* GetNextImageQueued(){return mImageEventQueue.front().image;}
89 ///Returns the next in line EventType's node
90 tree::Node* GetNextNodeQueued(){return mImageEventQueue.front().node;}
91 ///Unqueus the next in line EventType
92 void UnqueueNext(){mImageEventQueue.pop_front();}
95 ///Obtains the message of the state
96 std::string GetMessage(){return mMess;}
97 ///Obtains the message of the state
98 void SetMessage(std::string mess){mMess=mess;}
100 /// Create the tree views
101 void CreateTreeViews();
103 /// Create the tree view for TreeHandler provided
104 virtual void CreateTreeView( TreeHandler*)
105 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
107 /// Updates the TreeView of given name from level l to bottom
108 /// (calls the virtual method TreeView::UpdateLevel(l))
109 virtual void UpdateTreeViewLevel(const std::string&, int l);
110 // Multi-thread image reader callback
111 void OnMultiThreadImageReaderEvent(const std::string& filename,
112 MultiThreadImageReaderUser::EventType t,
113 vtkImageData* image);
115 //=============================================
116 typedef boost::signal<void (bool)> ValidationSignalType;
117 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
118 //=============================================
120 //==================================================================
121 /// Adds the function f to the list of functions to call
122 /// when the addition progresses.
123 /// f is of type ProgressCallbackType which is:
124 /// void (*ProgressCallbackType)(Progress&)
125 /// To pass a member function 'f' of an instance 'c' of a class 'C'
126 /// as callback you have to 'bind' it, i.e. call:
127 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
128 void ConnectValidationObserver(ValidationCallbackType callback);
129 //==================================================================
132 /// Controller which manages the interaction with the model
135 TreeViewMapType mTreeViewMap;
136 /// The message that results from the validation
138 /// Multi-thread image reader
139 MultiThreadImageReader mReader;
140 /// Map of images' names to nodes
141 std::map<std::string,tree::Node*> mImageFileNameToNode;
142 /// type of image event
143 /// If the image pointer is non null then the image is available (loaded)
144 /// else it has been unloaded
145 struct ImageEventType
147 ImageEventType( tree::Node* no, vtkImageData* im )
148 : node(no), image(im) {}
149 ImageEventType(vtkImageData* im )
154 // queue of image event
155 typedef std::deque<ImageEventType> ImageEventQueueType;
156 ImageEventQueueType mImageEventQueue;
158 ValidationSignalType mValidationSignal;
161 // EO class GimmickView
162 //=====================================================================
174 //====================================================================
176 //====================================================================
178 /// Returns the size of the current selection
179 virtual int GetSelectionSize() { return 0; }
180 /// Returns true if there is a valid selection
181 virtual bool IsSelectionValid(){ return false; }
182 /// Returns the vector of full filenames of selected images
183 virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
184 /// Returns the vector of images corresponding to selection
185 virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
186 /// Returns the vector of DicomNode corresponding to selection
187 virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
188 /// Returns the DicomNode corresponding to the tree item
189 virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
192 /// Type of list of DicomDatabase
193 typedef std::vector<DicomDatabase*> DicomDatabaseListType;
194 /// Returns the list of DicomDatabase open
195 virtual DicomDatabaseListType& GetDicomDatabaseList()
197 /// Returns the list of DicomDatabase open (const)
198 virtual const DicomDatabaseListType& GetDicomDatabaseList() const
202 ///Opens an existing database, or else, creates a local database.
203 virtual void OpenOrNewDatabase(bool open){ return; }
205 virtual void ShowHelp();
208 ///Gets the extension of the database
209 const std::string& GetDatabaseExtension() { return null; }
210 ///Sets the extension of the database
211 virtual void SetDatabaseExtension(const std::string& ext){ return; }
214 //====================================================================
215 // Preview Display Related
216 //====================================================================
219 ///Shows the image sent as a parameter
221 virtual void ShowImage(vtkImageData* image){ return; }
223 //====================================================================
225 //====================================================================
229 ///Loads or creates a favorites database
230 virtual void LoadOrCreateFavoritesDatabase(){ return; }
232 ///Creates the user settings directory
233 void CreateUserSettingsDirectory(){ return; }
234 ///Obtains the user settings directory
235 const std::string& GetUserSettingsDirectory(){ return null; }
237 //====================================================================
238 // Attribute Display Related
239 //====================================================================
242 ///Shows the Information regarding the node sent as a parameter
244 virtual void ShowInformation(DicomNode*){ return; }
246 //====================================================================
247 // Tree Display Related
248 //====================================================================
251 /// Completely rebuilds the view with
252 /// current DicomDatabaseList
253 virtual void RebuildView(){ return; }
254 /// Recursively updates the part of the view corresponding
255 /// to the DicomDatabase passed
256 /// i.e. creates items for the DicomNode which do not have
257 /// deletes obsolete items (whose DicomNode has been deleted)
258 virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
259 /// Recursively updates the part of the view corresponding
260 /// to the DicomNode provided.
261 /// parent is its parent in the tree (where to insert / remove it)
262 virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
265 ///Type definition of the data regarding the tree
266 typedef WxGimmickTreeItemData TreeItemData;
267 ///Gets the item data of the tree item passed as a parameter
268 TreeItemData* GetItemData(const TreeItemId& id){ return null; }
269 ///Type definition of the data insid a node of the tree
270 typedef WxGimmickDicomNodeData NodeData;
273 //====================================================================
275 //====================================================================
279 int mSelectionMaxImageDimension;
280 int mCurrentSelectionImageSize[4];
282 ///Existent Database List
283 DicomDatabaseListType mDicomDatabaseList;
284 ///Favorites database
285 DicomDatabase* mFavoriteDatabase;
287 ///Path to the database list file
288 std::string mDatabaseListFile;
289 ///Extension of the database
290 std::string mDatabaseExtension;
294 int mFirstDicomDatabaseIconIndex;
297 vtkImageViewer2* mViewer;
299 int mx1,mx2,my1,my2,mz1,mz2;
300 double mspx,mspy,mspz;
303 // Multi-thread image reader
304 MultiThreadImageReader mReader;
305 // map of images name to node
306 std::map<std::string,DicomNode*> mImageFileNameToNode;
309 } // EO namespace creaImageIO