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"); }
82 ///Adds a file to ignore
83 virtual void AddIgnoreFile(tree::Node* toRemove)
84 { GimmickError("INTERNAL ERROR : AddIgnoreFile not implemented"); }
86 ///Copies selected files
87 virtual void CopyFiles(const std::vector<std::string>& filenames)
88 { GimmickError("INTERNAL ERROR : CopyFiles not implemented"); }
90 ///Edits the fields of a given node
91 virtual void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
92 { GimmickError("INTERNAL ERROR : EditFields not implemented"); }
94 ///Copies selected files
95 virtual void SaveAs(const std::vector<std::string>& filenames)
96 { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
99 ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
100 bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
102 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
103 void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
104 ///Requests the reading of an image with priority and index in the
105 /// current selection (-1 if not in selection)
106 void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
109 ///Obtains the message of the state
110 std::string GetMessage(){return mMess;}
111 ///Obtains the message of the state
112 void SetMessage(std::string mess){mMess=mess;}
113 ///Resets the data of the extent and begins a new selection
116 /// Create the tree views
117 void CreateTreeViews();
119 /// Create a tree view with a given name
120 void CreateSingleTreeView(std::string &i_name);
122 /// Create the tree view for TreeHandler provided
123 virtual void CreateTreeView( TreeHandler* )
124 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
126 /// Updates the TreeView of given name from level l to bottom
127 /// (calls the virtual method TreeView::UpdateLevel(l))
128 virtual void UpdateTreeViewLevel(const std::string&, int l);
129 // Multi-thread image reader callback
130 void OnMultiThreadImageReaderEvent(const std::string& filename,
131 MultiThreadImageReaderUser::EventType t,
132 vtkImageData* image);
134 vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
137 //=============================================
138 typedef boost::signal<void (bool)> ValidationSignalType;
139 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
140 //=============================================
142 //==================================================================
143 /// Adds the function f to the list of functions to call
144 /// when the addition progresses.
145 /// f is of type ProgressCallbackType which is:
146 /// void (*ProgressCallbackType)(Progress&)
147 /// To pass a member function 'f' of an instance 'c' of a class 'C'
148 /// as callback you have to 'bind' it, i.e. call:
149 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
150 void ConnectValidationObserver(ValidationCallbackType callback);
151 //==================================================================
155 void modifyValidationSignal(bool ivalid);
159 /// Controller which manages the interaction with the model
162 TreeViewMapType mTreeViewMap;
163 /// The message that results from the validation
166 /// Multi-thread image reader
167 MultiThreadImageReader mReader;
168 /// Internal type of image reading event
169 /// If the image pointer is non null then the image is available (loaded)
170 /// else it has been unloaded
171 struct ImageEventType
173 ImageEventType( tree::Node* no = 0,
175 ImagePointerHolder* ph= 0)
176 : node(no), index(sel_index), pointerHolder(ph){}
177 ImageEventType(vtkImageData* im )
182 ImagePointerHolder* pointerHolder;
184 typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
185 /// Map of images' names to ImageEventType
186 /// Used to associated a filename to a the data of a request
187 ImageEventTypeMap mImageEventMap;
188 // queue of image event
189 typedef std::deque<ImageEventType> ImageEventQueueType;
190 //ImageEventQueueType mImageEventQueue;
192 ///The current image extent
193 ImageExtent* mImageExtent;
194 ///The validation signal
195 ValidationSignalType mValidationSignal;
196 ///Boolean that determines if the selection is valid
198 ///Boolean that determines if the reader has been started
202 // EO class GimmickView
203 //=====================================================================
215 //====================================================================
217 //====================================================================
219 /// Returns the size of the current selection
220 virtual int GetSelectionSize() { return 0; }
221 /// Returns true if there is a valid selection
222 virtual bool IsSelectionValid(){ return false; }
223 /// Returns the vector of full filenames of selected images
224 virtual void GetSelectedFiles(std::vector<std::string>&){ return; }
225 /// Returns the vector of images corresponding to selection
226 virtual void GetSelectedImages(std::vector<vtkImageData*>&){ return; }
227 /// Returns the vector of DicomNode corresponding to selection
228 virtual void GetSelectedDicomNodes(std::vector<DicomNode*>&){ return; }
229 /// Returns the DicomNode corresponding to the tree item
230 virtual DicomNode* GetDicomNodeOfItem(const TreeItemId& i);
233 /// Type of list of DicomDatabase
234 typedef std::vector<DicomDatabase*> DicomDatabaseListType;
235 /// Returns the list of DicomDatabase open
236 virtual DicomDatabaseListType& GetDicomDatabaseList()
238 /// Returns the list of DicomDatabase open (const)
239 virtual const DicomDatabaseListType& GetDicomDatabaseList() const
243 ///Opens an existing database, or else, creates a local database.
244 virtual void OpenOrNewDatabase(bool open){ return; }
246 virtual void ShowHelp();
249 ///Gets the extension of the database
250 const std::string& GetDatabaseExtension() { return null; }
251 ///Sets the extension of the database
252 virtual void SetDatabaseExtension(const std::string& ext){ return; }
255 //====================================================================
256 // Preview Display Related
257 //====================================================================
260 ///Shows the image sent as a parameter
262 virtual void ShowImage(vtkImageData* image){ return; }
264 //====================================================================
266 //====================================================================
270 ///Loads or creates a favorites database
271 virtual void LoadOrCreateFavoritesDatabase(){ return; }
273 ///Creates the user settings directory
274 void CreateUserSettingsDirectory(){ return; }
275 ///Obtains the user settings directory
276 const std::string& GetUserSettingsDirectory(){ return null; }
278 //====================================================================
279 // Attribute Display Related
280 //====================================================================
283 ///Shows the Information regarding the node sent as a parameter
285 virtual void ShowInformation(DicomNode*){ return; }
287 //====================================================================
288 // Tree Display Related
289 //====================================================================
292 /// Completely rebuilds the view with
293 /// current DicomDatabaseList
294 virtual void RebuildView(){ return; }
295 /// Recursively updates the part of the view corresponding
296 /// to the DicomDatabase passed
297 /// i.e. creates items for the DicomNode which do not have
298 /// deletes obsolete items (whose DicomNode has been deleted)
299 virtual void UpdateDicomDatabaseView(DicomDatabase*){ return; }
300 /// Recursively updates the part of the view corresponding
301 /// to the DicomNode provided.
302 /// parent is its parent in the tree (where to insert / remove it)
303 virtual void UpdateDicomNodeView(DicomNode* n, const TreeItemId& parent){ return; }
306 ///Type definition of the data regarding the tree
307 typedef WxGimmickTreeItemData TreeItemData;
308 ///Gets the item data of the tree item passed as a parameter
309 TreeItemData* GetItemData(const TreeItemId& id){ return null; }
310 ///Type definition of the data insid a node of the tree
311 typedef WxGimmickDicomNodeData NodeData;
314 //====================================================================
316 //====================================================================
320 int mSelectionMaxImageDimension;
321 int mCurrentSelectionImageSize[4];
323 ///Existent Database List
324 DicomDatabaseListType mDicomDatabaseList;
325 ///Favorites database
326 DicomDatabase* mFavoriteDatabase;
328 ///Path to the database list file
329 std::string mDatabaseListFile;
330 ///Extension of the database
331 std::string mDatabaseExtension;
335 int mFirstDicomDatabaseIconIndex;
338 vtkImageViewer2* mViewer;
340 int mx1,mx2,my1,my2,mz1,mz2;
341 double mspx,mspy,mspz;
344 // Multi-thread image reader
345 MultiThreadImageReader mReader;
346 // map of images name to node
347 std::map<std::string,DicomNode*> mImageFileNameToNode;
350 } // EO namespace creaImageIO