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
42 GimmickView(Gimmick*, int number_of_threads = 0 );
43 /// Virtual destructor
44 virtual ~GimmickView();
45 /// Initializes the view :
46 /// Creates the TreeViews for all the TreeHandler of the Controller
48 virtual void Initialize();
50 /// Type of map from View name to TreeView*
51 /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
52 typedef std::map<std::string, TreeView*> TreeViewMapType;
54 /// Returns the TreeViewMap (ref)
55 TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
56 /// Returns the TreeViewMap (const ref)
57 const TreeViewMapType& GetTreeViewMap() const
58 { return mTreeViewMap; }
61 virtual void Finalize();
63 //Returns the maximal priority
64 int GetMaximalPriority(){return mReader.GetMaximalPriority();}
66 ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
67 virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
68 { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
70 virtual void GetSelectedFiles(std::vector<std::string>& s)
71 { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
73 virtual void GetImages(int dim, std::vector<std::string> files, std::vector<vtkImageData*>& s)
74 { GimmickError("INTERNAL ERROR : GetImages not implemented"); }
76 virtual void OnSelectionChange(const std::vector<tree::Node*>& s, bool isSelection, int selection, bool mProcess)
77 { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
79 virtual void ClearSelection()
80 { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
83 ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
84 bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
86 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
87 void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
88 ///Requests the reading of an image with priority and index in the
89 /// current selection (-1 if not in selection)
90 void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
93 ///Obtains the message of the state
94 std::string GetMessage(){return mMess;}
95 ///Obtains the message of the state
96 void SetMessage(std::string mess){mMess=mess;}
97 ///Resets the data of the extent and begins a new selection
100 /// Create the tree views
101 void CreateTreeViews();
103 /// Create the tree view for TreeHandler provided
104 virtual void CreateTreeView( TreeHandler*, TimestampDatabaseHandler* )
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 vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
118 //=============================================
119 typedef boost::signal<void (bool)> ValidationSignalType;
120 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
121 //=============================================
123 //==================================================================
124 /// Adds the function f to the list of functions to call
125 /// when the addition progresses.
126 /// f is of type ProgressCallbackType which is:
127 /// void (*ProgressCallbackType)(Progress&)
128 /// To pass a member function 'f' of an instance 'c' of a class 'C'
129 /// as callback you have to 'bind' it, i.e. call:
130 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
131 void ConnectValidationObserver(ValidationCallbackType callback);
132 //==================================================================
134 void modifyValidationSignal(bool ivalid);
138 /// Controller which manages the interaction with the model
141 TreeViewMapType mTreeViewMap;
142 /// The message that results from the validation
145 /// Multi-thread image reader
146 MultiThreadImageReader mReader;
147 /// Internal type of image reading event
148 /// If the image pointer is non null then the image is available (loaded)
149 /// else it has been unloaded
150 struct ImageEventType
152 ImageEventType( tree::Node* no = 0,
154 ImagePointerHolder* ph= 0)
155 : node(no), index(sel_index), pointerHolder(ph){}
156 ImageEventType(vtkImageData* im )
161 ImagePointerHolder* pointerHolder;
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 ///The current image extent
172 ImageExtent* mImageExtent;
173 ///The validation signal
174 ValidationSignalType mValidationSignal;
175 ///Boolean that determines if the selection is valid
177 ///Boolean that determines if the reader has been started
181 // EO class GimmickView
182 //=====================================================================
194 //====================================================================
196 //====================================================================
198 /// Returns the size of the current selection
199 virtual int GetSelectionSize() { return 0; }
200 /// Returns true if there is a valid selection
201 virtual bool IsSelectionValid(){ return false; }
202 /// Returns the vector of full filenames of selected images
203 virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
204 /// Returns the vector of images corresponding to selection
205 virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
206 /// Returns the vector of DicomNode corresponding to selection
207 virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
208 /// Returns the DicomNode corresponding to the tree item
209 virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
212 /// Type of list of DicomDatabase
213 typedef std::vector<DicomDatabase*> DicomDatabaseListType;
214 /// Returns the list of DicomDatabase open
215 virtual DicomDatabaseListType& GetDicomDatabaseList()
217 /// Returns the list of DicomDatabase open (const)
218 virtual const DicomDatabaseListType& GetDicomDatabaseList() const
222 ///Opens an existing database, or else, creates a local database.
223 virtual void OpenOrNewDatabase(bool open){ return; }
225 virtual void ShowHelp();
228 ///Gets the extension of the database
229 const std::string& GetDatabaseExtension() { return null; }
230 ///Sets the extension of the database
231 virtual void SetDatabaseExtension(const std::string& ext){ return; }
234 //====================================================================
235 // Preview Display Related
236 //====================================================================
239 ///Shows the image sent as a parameter
241 virtual void ShowImage(vtkImageData* image){ return; }
243 //====================================================================
245 //====================================================================
249 ///Loads or creates a favorites database
250 virtual void LoadOrCreateFavoritesDatabase(){ return; }
252 ///Creates the user settings directory
253 void CreateUserSettingsDirectory(){ return; }
254 ///Obtains the user settings directory
255 const std::string& GetUserSettingsDirectory(){ return null; }
257 //====================================================================
258 // Attribute Display Related
259 //====================================================================
262 ///Shows the Information regarding the node sent as a parameter
264 virtual void ShowInformation(DicomNode*){ return; }
266 //====================================================================
267 // Tree Display Related
268 //====================================================================
271 /// Completely rebuilds the view with
272 /// current DicomDatabaseList
273 virtual void RebuildView(){ return; }
274 /// Recursively updates the part of the view corresponding
275 /// to the DicomDatabase passed
276 /// i.e. creates items for the DicomNode which do not have
277 /// deletes obsolete items (whose DicomNode has been deleted)
278 virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
279 /// Recursively updates the part of the view corresponding
280 /// to the DicomNode provided.
281 /// parent is its parent in the tree (where to insert / remove it)
282 virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
285 ///Type definition of the data regarding the tree
286 typedef WxGimmickTreeItemData TreeItemData;
287 ///Gets the item data of the tree item passed as a parameter
288 TreeItemData* GetItemData(const TreeItemId& id){ return null; }
289 ///Type definition of the data insid a node of the tree
290 typedef WxGimmickDicomNodeData NodeData;
293 //====================================================================
295 //====================================================================
299 int mSelectionMaxImageDimension;
300 int mCurrentSelectionImageSize[4];
302 ///Existent Database List
303 DicomDatabaseListType mDicomDatabaseList;
304 ///Favorites database
305 DicomDatabase* mFavoriteDatabase;
307 ///Path to the database list file
308 std::string mDatabaseListFile;
309 ///Extension of the database
310 std::string mDatabaseExtension;
314 int mFirstDicomDatabaseIconIndex;
317 vtkImageViewer2* mViewer;
319 int mx1,mx2,my1,my2,mz1,mz2;
320 double mspx,mspy,mspz;
323 // Multi-thread image reader
324 MultiThreadImageReader mReader;
325 // map of images name to node
326 std::map<std::string,DicomNode*> mImageFileNameToNode;
329 } // EO namespace creaImageIO