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
28 typedef std::map<std::string, std::string> mapInfoDicom;
33 //std::map<std::string, std::string> infos;
43 //=====================================================================
45 //=====================================================================
46 ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
47 class GimmickView: public MultiThreadImageReaderUser
51 GimmickView(boost::shared_ptr<Gimmick>, int number_of_threads = 0 );
52 /// Virtual destructor
53 virtual ~GimmickView();
54 /// Initializes the view :
55 /// Creates the TreeViews for all the TreeHandler of the Controller
57 virtual void Initialize();
59 /// Type of map from View name to TreeView*
60 /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
61 typedef std::map<std::string, TreeView*> TreeViewMapType;
63 /// Returns the TreeViewMap (ref)
64 TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
65 /// Returns the TreeViewMap (const ref)
66 const TreeViewMapType& GetTreeViewMap() const
67 { return mTreeViewMap; }
70 virtual void Finalize();
72 ///Returns the maximal priority
73 int GetMaximalPriority(){return mReader.GetMaximalPriority();}
75 ///Adds the selected Images to the given vector
76 virtual void GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
77 { GimmickError("INTERNAL ERROR : GetSelectedImagesInVector not implemented"); }
79 ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
80 virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
81 { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
83 virtual void GetSelectedFiles(std::vector<std::string>& s)
84 { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
86 virtual void GetImages(int dim, std::vector<std::string> files, std::vector<vtkImageData*>& s)
87 { GimmickError("INTERNAL ERROR : GetImages not implemented"); }
89 virtual void OnSelectionChange(const std::vector<tree::Node*>& s, bool isSelection, int selection, bool mProcess)
90 { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
92 virtual void ClearSelection()
93 { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
95 ///Adds a file to ignore
96 virtual void AddIgnoreFile(tree::Node* toRemove)
97 { GimmickError("INTERNAL ERROR : AddIgnoreFile not implemented"); }
99 ///Copies selected files
100 virtual void CopyFiles(const std::vector<std::string>& filenames)
101 { GimmickError("INTERNAL ERROR : CopyFiles not implemented"); }
103 ///Edits the fields of a given node
104 virtual void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
105 { GimmickError("INTERNAL ERROR : EditFields not implemented"); }
107 /// Anonymize or de-anonymize data
108 virtual void Anonymize(std::vector<std::string> i_filenames, int type)
109 { GimmickError("INTERNAL ERROR : Anonymize not implemented"); }
111 /// Display all Dicom Tags
112 virtual void DumpTags(const std::string filename)
113 {GimmickError("INTERNAL ERROR : DumpTags not implemented"); }
115 ///Edits the fields of a given node
116 virtual void ExportToStorage(const std::vector<std::string> keys)
117 { GimmickError("INTERNAL ERROR : ExportToStorage not implemented"); }
119 ///Copies selected files
120 virtual void SaveAs(const std::vector<std::string>& filenames)
121 { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
123 /// No selected image
124 bool NoValidateSelected();
126 ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
127 bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
129 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
130 void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
132 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
133 void ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
135 ///Requests the reading of an image with priority and index in the
136 /// current selection (-1 if not in selection)
137 //void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
138 void RequestReading(tree::Node* n, int prio, int selection_index , boost::shared_ptr<ImagePointerHolder> p);
140 ///Obtains the message of the state
141 std::string GetMessage(){return mMess;}
143 ///Obtains the message of the state
144 void SetMessage(std::string mess){mMess=mess;}
146 ///Resets the data of the extent and begins a new selection
149 /// Create the tree views
150 void CreateTreeViews();
152 /// Create a tree view with a given name
153 void CreateSingleTreeView(std::string &i_name);
155 /// Create the tree view for TreeHandler provided
156 virtual void CreateTreeView( TreeHandler* )
157 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
159 /// Updates the TreeView of given name from level l to bottom
160 /// (calls the virtual method TreeView::UpdateLevel(l))
161 virtual void UpdateTreeViewLevel(const std::string&, int l);
163 // Multi-thread image reader callback
164 void OnMultiThreadImageReaderEvent(const std::string& filename,
165 MultiThreadImageReaderUser::EventType t,
166 vtkImageData* image);
168 vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
170 //=============================================
171 typedef boost::signal<void (bool)> ValidationSignalType;
172 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
173 //=============================================
175 //==================================================================
176 /// Adds the function f to the list of functions to call
177 /// when the addition progresses.
178 /// f is of type ProgressCallbackType which is:
179 /// void (*ProgressCallbackType)(Progress&)
180 /// To pass a member function 'f' of an instance 'c' of a class 'C'
181 /// as callback you have to 'bind' it, i.e. call:
182 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
183 void ConnectValidationObserver(ValidationCallbackType callback);
184 //==================================================================
186 void modifyValidationSignal(bool ivalid);
189 void readImages(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
190 OutputAttr i_attr, int i_dim, double i_zspc);
191 bool isSingle(const std::string i_file);
195 typedef void (*readXD)(std::vector<OutStrGimmick>&, std::vector<std::string>, OutputAttr, double);
197 void getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr);
199 virtual void readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
200 OutputAttr i_attr, double i_zspc);
202 virtual void readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
203 OutputAttr i_attr, double i_zspc);
205 virtual void readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
208 virtual void readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
212 /// Controller which manages the interaction with the model
213 boost::shared_ptr< Gimmick> mGimmick;
216 TreeViewMapType mTreeViewMap;
218 /// The message that results from the validation
221 /// Multi-thread image reader
222 MultiThreadImageReader mReader;
224 /// Internal type of image reading event
225 /// If the image pointer is non null then the image is available (loaded)
226 /// else it has been unloaded
227 struct ImageEventType
229 ImageEventType( tree::Node* no = 0,
231 // ImagePointerHolder* ph= 0)
232 : node(no), index(sel_index){}//, pointerHolder(ph){}
233 ImageEventType(vtkImageData* im )
238 boost::shared_ptr<ImagePointerHolder> pointerHolder;
240 typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
241 /// Map of images' names to ImageEventType
242 /// Used to associated a filename to a the data of a request
243 ImageEventTypeMap mImageEventMap;
245 // queue of image event
246 typedef std::deque<ImageEventType> ImageEventQueueType;
248 //ImageEventQueueType mImageEventQueue;
250 ///The current image extent
251 boost::shared_ptr<ImageExtent> mImageExtent;
253 ///The validation signal
254 ValidationSignalType mValidationSignal;
256 ///Boolean that determines if the selection is valid
259 ///Boolean that determines if the reader has been started
263 // EO class GimmickView
264 //=====================================================================
267 } // EO namespace creaImageIO