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, bool isSelection, int selection, bool mProcess)
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 (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);
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;}
93 ///Clears status and begins a new selection
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);
111 vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
114 //=============================================
115 typedef boost::signal<void (bool)> ValidationSignalType;
116 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
117 //=============================================
119 //==================================================================
120 /// Adds the function f to the list of functions to call
121 /// when the addition progresses.
122 /// f is of type ProgressCallbackType which is:
123 /// void (*ProgressCallbackType)(Progress&)
124 /// To pass a member function 'f' of an instance 'c' of a class 'C'
125 /// as callback you have to 'bind' it, i.e. call:
126 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
127 void ConnectValidationObserver(ValidationCallbackType callback);
128 //==================================================================
132 /// Controller which manages the interaction with the model
135 TreeViewMapType mTreeViewMap;
136 /// The message that results from the validation
139 /// Multi-thread image reader
140 MultiThreadImageReader mReader;
141 /// Internal type of image reading event
142 /// If the image pointer is non null then the image is available (loaded)
143 /// else it has been unloaded
144 struct ImageEventType
146 ImageEventType( tree::Node* no = 0,
148 ImagePointerHolder* ph= 0)
149 : node(no), index(sel_index), pointerHolder(ph){}
150 ImageEventType(vtkImageData* im )
155 ImagePointerHolder* pointerHolder;
157 typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
158 /// Map of images' names to ImageEventType
159 /// Used to associated a filename to a the data of a request
160 ImageEventTypeMap mImageEventMap;
161 // queue of image event
162 typedef std::deque<ImageEventType> ImageEventQueueType;
163 //ImageEventQueueType mImageEventQueue;
165 ValidationSignalType mValidationSignal;
173 // EO class GimmickView
174 //=====================================================================
186 //====================================================================
188 //====================================================================
190 /// Returns the size of the current selection
191 virtual int GetSelectionSize() { return 0; }
192 /// Returns true if there is a valid selection
193 virtual bool IsSelectionValid(){ return false; }
194 /// Returns the vector of full filenames of selected images
195 virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
196 /// Returns the vector of images corresponding to selection
197 virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
198 /// Returns the vector of DicomNode corresponding to selection
199 virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
200 /// Returns the DicomNode corresponding to the tree item
201 virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
204 /// Type of list of DicomDatabase
205 typedef std::vector<DicomDatabase*> DicomDatabaseListType;
206 /// Returns the list of DicomDatabase open
207 virtual DicomDatabaseListType& GetDicomDatabaseList()
209 /// Returns the list of DicomDatabase open (const)
210 virtual const DicomDatabaseListType& GetDicomDatabaseList() const
214 ///Opens an existing database, or else, creates a local database.
215 virtual void OpenOrNewDatabase(bool open){ return; }
217 virtual void ShowHelp();
220 ///Gets the extension of the database
221 const std::string& GetDatabaseExtension() { return null; }
222 ///Sets the extension of the database
223 virtual void SetDatabaseExtension(const std::string& ext){ return; }
226 //====================================================================
227 // Preview Display Related
228 //====================================================================
231 ///Shows the image sent as a parameter
233 virtual void ShowImage(vtkImageData* image){ return; }
235 //====================================================================
237 //====================================================================
241 ///Loads or creates a favorites database
242 virtual void LoadOrCreateFavoritesDatabase(){ return; }
244 ///Creates the user settings directory
245 void CreateUserSettingsDirectory(){ return; }
246 ///Obtains the user settings directory
247 const std::string& GetUserSettingsDirectory(){ return null; }
249 //====================================================================
250 // Attribute Display Related
251 //====================================================================
254 ///Shows the Information regarding the node sent as a parameter
256 virtual void ShowInformation(DicomNode*){ return; }
258 //====================================================================
259 // Tree Display Related
260 //====================================================================
263 /// Completely rebuilds the view with
264 /// current DicomDatabaseList
265 virtual void RebuildView(){ return; }
266 /// Recursively updates the part of the view corresponding
267 /// to the DicomDatabase passed
268 /// i.e. creates items for the DicomNode which do not have
269 /// deletes obsolete items (whose DicomNode has been deleted)
270 virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
271 /// Recursively updates the part of the view corresponding
272 /// to the DicomNode provided.
273 /// parent is its parent in the tree (where to insert / remove it)
274 virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
277 ///Type definition of the data regarding the tree
278 typedef WxGimmickTreeItemData TreeItemData;
279 ///Gets the item data of the tree item passed as a parameter
280 TreeItemData* GetItemData(const TreeItemId& id){ return null; }
281 ///Type definition of the data insid a node of the tree
282 typedef WxGimmickDicomNodeData NodeData;
285 //====================================================================
287 //====================================================================
291 int mSelectionMaxImageDimension;
292 int mCurrentSelectionImageSize[4];
294 ///Existent Database List
295 DicomDatabaseListType mDicomDatabaseList;
296 ///Favorites database
297 DicomDatabase* mFavoriteDatabase;
299 ///Path to the database list file
300 std::string mDatabaseListFile;
301 ///Extension of the database
302 std::string mDatabaseExtension;
306 int mFirstDicomDatabaseIconIndex;
309 vtkImageViewer2* mViewer;
311 int mx1,mx2,my1,my2,mz1,mz2;
312 double mspx,mspy,mspz;
315 // Multi-thread image reader
316 MultiThreadImageReader mReader;
317 // map of images name to node
318 std::map<std::string,DicomNode*> mImageFileNameToNode;
321 } // EO namespace creaImageIO