2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
29 #ifndef __creaImageIOGimmickView_h_INCLUDED__
30 #define __creaImageIOGimmickView_h_INCLUDED__
32 #include <creaImageIOGimmick.h>
33 #include <creaImageIOTreeView.h>
34 #include <creaImageIOSystem.h>
35 #include <creaImageIOImagePointerHolder.h>
38 #include <vtkImageData.h>
39 #if defined (USE_WXWIDGETS)
40 #include <creaImageIOMultiThreadImageReader.h>
44 #include "Qt/creaImageIOQMultiThreadImageReader.h"
48 // Signal/slot mechanism for progress events
49 #include <boost/signals2/signal.hpp>
50 #include <boost/bind.hpp>
52 #define GIMMICK_NO_IMAGE_SELECTION 0
53 #define GIMMICK_2D_IMAGE_SELECTION 2
54 #define GIMMICK_3D_IMAGE_SELECTION 3
55 #define GIMMICK_4D_IMAGE_SELECTION 4
63 typedef std::map<std::string, std::string> mapInfoDicom;
68 //std::map<std::string, std::string> infos;
78 //=====================================================================
80 //=====================================================================
81 ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
82 class CREAIMAGEIO_EXPORT GimmickView: public MultiThreadImageReaderUser
86 GimmickView(boost::shared_ptr<Gimmick>, int number_of_threads = 0 );
87 /// Virtual destructor
88 virtual ~GimmickView();
89 /// Initializes the view :
90 /// Creates the TreeViews for all the TreeHandler of the Controller
92 virtual void Initialize();
94 /// Type of map from View name to TreeView*
95 /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
96 typedef std::map<std::string, TreeView*> TreeViewMapType;
98 /// Returns the TreeViewMap (ref)
99 TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
100 /// Returns the TreeViewMap (const ref)
101 const TreeViewMapType& GetTreeViewMap() const
102 { return mTreeViewMap; }
105 virtual void Finalize();
107 ///Returns the maximal priority
108 int GetMaximalPriority(){return mReader.GetMaximalPriority();}
110 ///Adds the selected Images to the given vector
111 virtual void GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
112 { GimmickError("INTERNAL ERROR : GetSelectedImagesInVector not implemented"); }
114 ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
115 virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
116 { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
118 virtual void GetSelectedFiles(std::vector<std::string>& s)
119 { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
121 virtual void GetImages(int dim, std::vector<std::string> files, std::vector<vtkImageData*>& s)
122 { GimmickError("INTERNAL ERROR : GetImages not implemented"); }
124 virtual void OnSelectionChange(const std::vector<tree::Node*>& s, bool isSelection, int selection, bool mProcess)
125 { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
127 virtual void ClearSelection()
128 { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
130 ///Adds a file to ignore
131 virtual void AddIgnoreFile(tree::Node* toRemove)
132 { GimmickError("INTERNAL ERROR : AddIgnoreFile not implemented"); }
134 ///Copies selected files
135 virtual void CopyFiles(const std::vector<std::string>& filenames)
136 { GimmickError("INTERNAL ERROR : CopyFiles not implemented"); }
138 ///Edits the fields of a given node
139 virtual void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
140 { GimmickError("INTERNAL ERROR : EditFields not implemented"); }
142 /// Anonymize or de-anonymize data
143 void Anonymize(std::vector<std::string> i_filenames, int type);
145 /// Display all Dicom Tags
146 virtual void DumpTags(const std::string filename)
147 {GimmickError("INTERNAL ERROR : DumpTags not implemented"); }
149 ///Edits the fields of a given node
150 virtual void ExportToStorage(const std::vector<std::string> keys)
151 { GimmickError("INTERNAL ERROR : ExportToStorage not implemented"); }
153 ///Copies selected files
154 virtual void SaveAs(const std::vector<std::string>& filenames)
155 { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
157 /// No selected image
158 bool NoValidateSelected();
160 ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
161 bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
163 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
164 void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
166 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
167 void ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
169 ///Requests the reading of an image with priority and index in the
170 /// current selection (-1 if not in selection)
171 //void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
172 void RequestReading(tree::Node* n, int prio, int selection_index , boost::shared_ptr<ImagePointerHolder> p);
174 ///Obtains the message of the state
175 std::string GetMessage(){return mMess;}
177 ///Obtains the message of the state
178 void SetMessage(std::string mess){mMess=mess;}
180 ///Resets the data of the extent and begins a new selection
183 /// Create the tree views
184 void CreateTreeViews();
186 /// Create a tree view with a given name
187 void CreateSingleTreeView(std::string &i_name);
189 /// Create the tree view for TreeHandler provided
190 virtual void CreateTreeView( TreeHandler* )
191 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
193 /// Updates the TreeView of given name from level l to bottom
194 /// (calls the virtual method TreeView::UpdateLevel(l))
195 virtual void UpdateTreeViewLevel(const std::string&, int l);
197 // Multi-thread image reader callback
198 void OnMultiThreadImageReaderEvent(const std::string& filename,
199 MultiThreadImageReaderUser::EventType t,
200 vtkImageData* image);
202 vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
204 //=============================================
205 typedef boost::signals2::signal<void (bool)> ValidationSignalType;
206 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
207 //=============================================
209 //==================================================================
210 /// Adds the function f to the list of functions to call
211 /// when the addition progresses.
212 /// f is of type ProgressCallbackType which is:
213 /// void (*ProgressCallbackType)(Progress&)
214 /// To pass a member function 'f' of an instance 'c' of a class 'C'
215 /// as callback you have to 'bind' it, i.e. call:
216 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
217 void ConnectValidationObserver(ValidationCallbackType callback);
218 //==================================================================
220 void modifyValidationSignal(bool ivalid);
223 void readImages(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
224 OutputAttr i_attr, int i_dim, double i_zspc);
225 bool isSingle(const std::string i_file);
231 typedef void (*readXD)(std::vector<OutStrGimmick>&, std::vector<std::string>, OutputAttr, double);
233 void getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr);
235 virtual void readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
236 OutputAttr i_attr, double i_zspc);
238 virtual void readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
239 OutputAttr i_attr, double i_zspc);
241 virtual void readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
244 virtual void readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
248 /// Controller which manages the interaction with the model
249 boost::shared_ptr< Gimmick> mGimmick;
252 TreeViewMapType mTreeViewMap;
254 /// The message that results from the validation
257 /// Multi-thread image reader
258 MultiThreadImageReader mReader;
260 /// Internal type of image reading event
261 /// If the image pointer is non null then the image is available (loaded)
262 /// else it has been unloaded
263 struct ImageEventType
265 ImageEventType( tree::Node* no = 0,
267 // ImagePointerHolder* ph= 0)
268 : node(no), index(sel_index){}//, pointerHolder(ph){}
269 ImageEventType(vtkImageData* im )
274 boost::shared_ptr<ImagePointerHolder> pointerHolder;
276 typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
277 /// Map of images' names to ImageEventType
278 /// Used to associated a filename to a the data of a request
279 ImageEventTypeMap mImageEventMap;
281 // queue of image event
282 typedef std::deque<ImageEventType> ImageEventQueueType;
284 //ImageEventQueueType mImageEventQueue;
286 ///The current image extent
287 boost::shared_ptr<ImageExtent> mImageExtent;
289 ///The validation signal
290 ValidationSignalType mValidationSignal;
292 ///Boolean that determines if the selection is valid
295 ///Boolean that determines if the reader has been started
299 // EO class GimmickView
300 //=====================================================================
303 } // EO namespace creaImageIO