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 #if defined (USE_WXWIDGETS)
12 #include <creaImageIOMultiThreadImageReader.h>
16 #include <creaImageIOQMultiThreadImageReader.h>
20 // Signal/slot mechanism for progress events
21 #include <boost/signal.hpp>
22 #include <boost/bind.hpp>
24 #define GIMMICK_NO_IMAGE_SELECTION 0
25 #define GIMMICK_2D_IMAGE_SELECTION 2
26 #define GIMMICK_3D_IMAGE_SELECTION 3
27 #define GIMMICK_4D_IMAGE_SELECTION 4
35 typedef std::map<std::string, std::string> mapInfoDicom;
40 //std::map<std::string, std::string> infos;
50 //=====================================================================
52 //=====================================================================
53 ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
54 class GimmickView: public MultiThreadImageReaderUser
58 GimmickView(boost::shared_ptr<Gimmick>, int number_of_threads = 0 );
59 /// Virtual destructor
60 virtual ~GimmickView();
61 /// Initializes the view :
62 /// Creates the TreeViews for all the TreeHandler of the Controller
64 virtual void Initialize();
66 /// Type of map from View name to TreeView*
67 /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
68 typedef std::map<std::string, TreeView*> TreeViewMapType;
70 /// Returns the TreeViewMap (ref)
71 TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
72 /// Returns the TreeViewMap (const ref)
73 const TreeViewMapType& GetTreeViewMap() const
74 { return mTreeViewMap; }
77 virtual void Finalize();
79 ///Returns the maximal priority
80 int GetMaximalPriority(){return mReader.GetMaximalPriority();}
82 ///Adds the selected Images to the given vector
83 virtual void GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
84 { GimmickError("INTERNAL ERROR : GetSelectedImagesInVector not implemented"); }
86 ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
87 virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
88 { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
90 virtual void GetSelectedFiles(std::vector<std::string>& s)
91 { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
93 virtual void GetImages(int dim, std::vector<std::string> files, std::vector<vtkImageData*>& s)
94 { GimmickError("INTERNAL ERROR : GetImages not implemented"); }
96 virtual void OnSelectionChange(const std::vector<tree::Node*>& s, bool isSelection, int selection, bool mProcess)
97 { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
99 virtual void ClearSelection()
100 { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
102 ///Adds a file to ignore
103 virtual void AddIgnoreFile(tree::Node* toRemove)
104 { GimmickError("INTERNAL ERROR : AddIgnoreFile not implemented"); }
106 ///Copies selected files
107 virtual void CopyFiles(const std::vector<std::string>& filenames)
108 { GimmickError("INTERNAL ERROR : CopyFiles not implemented"); }
110 ///Edits the fields of a given node
111 virtual void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
112 { GimmickError("INTERNAL ERROR : EditFields not implemented"); }
114 /// Anonymize or de-anonymize data
115 virtual void Anonymize(std::vector<std::string> i_filenames, int type)
116 { GimmickError("INTERNAL ERROR : Anonymize not implemented"); }
118 /// Display all Dicom Tags
119 virtual void DumpTags(const std::string filename)
120 {GimmickError("INTERNAL ERROR : DumpTags not implemented"); }
122 ///Edits the fields of a given node
123 virtual void ExportToStorage(const std::vector<std::string> keys)
124 { GimmickError("INTERNAL ERROR : ExportToStorage not implemented"); }
126 ///Copies selected files
127 virtual void SaveAs(const std::vector<std::string>& filenames)
128 { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
130 /// No selected image
131 bool NoValidateSelected();
133 ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
134 bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
136 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
137 void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
139 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
140 void ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
142 ///Requests the reading of an image with priority and index in the
143 /// current selection (-1 if not in selection)
144 //void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
145 void RequestReading(tree::Node* n, int prio, int selection_index , boost::shared_ptr<ImagePointerHolder> p);
147 ///Obtains the message of the state
148 std::string GetMessage(){return mMess;}
150 ///Obtains the message of the state
151 void SetMessage(std::string mess){mMess=mess;}
153 ///Resets the data of the extent and begins a new selection
156 /// Create the tree views
157 void CreateTreeViews();
159 /// Create a tree view with a given name
160 void CreateSingleTreeView(std::string &i_name);
162 /// Create the tree view for TreeHandler provided
163 virtual void CreateTreeView( TreeHandler* )
164 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
166 /// Updates the TreeView of given name from level l to bottom
167 /// (calls the virtual method TreeView::UpdateLevel(l))
168 virtual void UpdateTreeViewLevel(const std::string&, int l);
170 // Multi-thread image reader callback
171 void OnMultiThreadImageReaderEvent(const std::string& filename,
172 MultiThreadImageReaderUser::EventType t,
173 vtkImageData* image);
175 vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
177 //=============================================
178 typedef boost::signal<void (bool)> ValidationSignalType;
179 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
180 //=============================================
182 //==================================================================
183 /// Adds the function f to the list of functions to call
184 /// when the addition progresses.
185 /// f is of type ProgressCallbackType which is:
186 /// void (*ProgressCallbackType)(Progress&)
187 /// To pass a member function 'f' of an instance 'c' of a class 'C'
188 /// as callback you have to 'bind' it, i.e. call:
189 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
190 void ConnectValidationObserver(ValidationCallbackType callback);
191 //==================================================================
193 void modifyValidationSignal(bool ivalid);
196 void readImages(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
197 OutputAttr i_attr, int i_dim, double i_zspc);
198 bool isSingle(const std::string i_file);
204 typedef void (*readXD)(std::vector<OutStrGimmick>&, std::vector<std::string>, OutputAttr, double);
206 void getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr);
208 virtual void readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
209 OutputAttr i_attr, double i_zspc);
211 virtual void readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
212 OutputAttr i_attr, double i_zspc);
214 virtual void readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
217 virtual void readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
221 /// Controller which manages the interaction with the model
222 boost::shared_ptr< Gimmick> mGimmick;
225 TreeViewMapType mTreeViewMap;
227 /// The message that results from the validation
230 /// Multi-thread image reader
231 MultiThreadImageReader mReader;
233 /// Internal type of image reading event
234 /// If the image pointer is non null then the image is available (loaded)
235 /// else it has been unloaded
236 struct ImageEventType
238 ImageEventType( tree::Node* no = 0,
240 // ImagePointerHolder* ph= 0)
241 : node(no), index(sel_index){}//, pointerHolder(ph){}
242 ImageEventType(vtkImageData* im )
247 boost::shared_ptr<ImagePointerHolder> pointerHolder;
249 typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
250 /// Map of images' names to ImageEventType
251 /// Used to associated a filename to a the data of a request
252 ImageEventTypeMap mImageEventMap;
254 // queue of image event
255 typedef std::deque<ImageEventType> ImageEventQueueType;
257 //ImageEventQueueType mImageEventQueue;
259 ///The current image extent
260 boost::shared_ptr<ImageExtent> mImageExtent;
262 ///The validation signal
263 ValidationSignalType mValidationSignal;
265 ///Boolean that determines if the selection is valid
268 ///Boolean that determines if the reader has been started
272 // EO class GimmickView
273 //=====================================================================
276 } // EO namespace creaImageIO