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 "Qt/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 void Anonymize(std::vector<std::string> i_filenames, int type);
117 /// Display all Dicom Tags
118 virtual void DumpTags(const std::string filename)
119 {GimmickError("INTERNAL ERROR : DumpTags not implemented"); }
121 ///Edits the fields of a given node
122 virtual void ExportToStorage(const std::vector<std::string> keys)
123 { GimmickError("INTERNAL ERROR : ExportToStorage not implemented"); }
125 ///Copies selected files
126 virtual void SaveAs(const std::vector<std::string>& filenames)
127 { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
129 /// No selected image
130 bool NoValidateSelected();
132 ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
133 bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
135 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
136 void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
138 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
139 void ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
141 ///Requests the reading of an image with priority and index in the
142 /// current selection (-1 if not in selection)
143 //void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
144 void RequestReading(tree::Node* n, int prio, int selection_index , boost::shared_ptr<ImagePointerHolder> p);
146 ///Obtains the message of the state
147 std::string GetMessage(){return mMess;}
149 ///Obtains the message of the state
150 void SetMessage(std::string mess){mMess=mess;}
152 ///Resets the data of the extent and begins a new selection
155 /// Create the tree views
156 void CreateTreeViews();
158 /// Create a tree view with a given name
159 void CreateSingleTreeView(std::string &i_name);
161 /// Create the tree view for TreeHandler provided
162 virtual void CreateTreeView( TreeHandler* )
163 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
165 /// Updates the TreeView of given name from level l to bottom
166 /// (calls the virtual method TreeView::UpdateLevel(l))
167 virtual void UpdateTreeViewLevel(const std::string&, int l);
169 // Multi-thread image reader callback
170 void OnMultiThreadImageReaderEvent(const std::string& filename,
171 MultiThreadImageReaderUser::EventType t,
172 vtkImageData* image);
174 vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
176 //=============================================
177 typedef boost::signal<void (bool)> ValidationSignalType;
178 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
179 //=============================================
181 //==================================================================
182 /// Adds the function f to the list of functions to call
183 /// when the addition progresses.
184 /// f is of type ProgressCallbackType which is:
185 /// void (*ProgressCallbackType)(Progress&)
186 /// To pass a member function 'f' of an instance 'c' of a class 'C'
187 /// as callback you have to 'bind' it, i.e. call:
188 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
189 void ConnectValidationObserver(ValidationCallbackType callback);
190 //==================================================================
192 void modifyValidationSignal(bool ivalid);
195 void readImages(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
196 OutputAttr i_attr, int i_dim, double i_zspc);
197 bool isSingle(const std::string i_file);
203 typedef void (*readXD)(std::vector<OutStrGimmick>&, std::vector<std::string>, OutputAttr, double);
205 void getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr);
207 virtual void readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
208 OutputAttr i_attr, double i_zspc);
210 virtual void readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
211 OutputAttr i_attr, double i_zspc);
213 virtual void readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
216 virtual void readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
220 /// Controller which manages the interaction with the model
221 boost::shared_ptr< Gimmick> mGimmick;
224 TreeViewMapType mTreeViewMap;
226 /// The message that results from the validation
229 /// Multi-thread image reader
230 MultiThreadImageReader mReader;
232 /// Internal type of image reading event
233 /// If the image pointer is non null then the image is available (loaded)
234 /// else it has been unloaded
235 struct ImageEventType
237 ImageEventType( tree::Node* no = 0,
239 // ImagePointerHolder* ph= 0)
240 : node(no), index(sel_index){}//, pointerHolder(ph){}
241 ImageEventType(vtkImageData* im )
246 boost::shared_ptr<ImagePointerHolder> pointerHolder;
248 typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
249 /// Map of images' names to ImageEventType
250 /// Used to associated a filename to a the data of a request
251 ImageEventTypeMap mImageEventMap;
253 // queue of image event
254 typedef std::deque<ImageEventType> ImageEventQueueType;
256 //ImageEventQueueType mImageEventQueue;
258 ///The current image extent
259 boost::shared_ptr<ImageExtent> mImageExtent;
261 ///The validation signal
262 ValidationSignalType mValidationSignal;
264 ///Boolean that determines if the selection is valid
267 ///Boolean that determines if the reader has been started
271 // EO class GimmickView
272 //=====================================================================
275 } // EO namespace creaImageIO