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
32 std::map<std::string, std::string> infos;
41 //=====================================================================
43 //=====================================================================
44 ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
45 class GimmickView: public MultiThreadImageReaderUser
49 GimmickView(boost::shared_ptr<Gimmick>, int number_of_threads = 0 );
50 /// Virtual destructor
51 virtual ~GimmickView();
52 /// Initializes the view :
53 /// Creates the TreeViews for all the TreeHandler of the Controller
55 virtual void Initialize();
57 /// Type of map from View name to TreeView*
58 /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
59 typedef std::map<std::string, TreeView*> TreeViewMapType;
61 /// Returns the TreeViewMap (ref)
62 TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
63 /// Returns the TreeViewMap (const ref)
64 const TreeViewMapType& GetTreeViewMap() const
65 { return mTreeViewMap; }
68 virtual void Finalize();
70 ///Returns the maximal priority
71 int GetMaximalPriority(){return mReader.GetMaximalPriority();}
73 ///Adds the selected Images to the given vector
74 virtual void GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
75 { GimmickError("INTERNAL ERROR : GetSelectedImagesInVector not implemented"); }
77 ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
78 virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
79 { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
81 virtual void GetSelectedFiles(std::vector<std::string>& s)
82 { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
84 virtual void GetImages(int dim, std::vector<std::string> files, std::vector<vtkImageData*>& s)
85 { GimmickError("INTERNAL ERROR : GetImages not implemented"); }
87 virtual void OnSelectionChange(const std::vector<tree::Node*>& s, bool isSelection, int selection, bool mProcess)
88 { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
90 virtual void ClearSelection()
91 { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
93 ///Adds a file to ignore
94 virtual void AddIgnoreFile(tree::Node* toRemove)
95 { GimmickError("INTERNAL ERROR : AddIgnoreFile not implemented"); }
97 ///Copies selected files
98 virtual void CopyFiles(const std::vector<std::string>& filenames)
99 { GimmickError("INTERNAL ERROR : CopyFiles not implemented"); }
101 ///Edits the fields of a given node
102 virtual void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
103 { GimmickError("INTERNAL ERROR : EditFields not implemented"); }
105 /// Anonymize or de-anonymize data
106 virtual void Anonymize(std::vector<std::string> i_filenames, int type)
107 { GimmickError("INTERNAL ERROR : Anonymize not implemented"); }
109 /// Display all Dicom Tags
110 virtual void DumpTags(const std::string filename)
111 {GimmickError("INTERNAL ERROR : DumpTags not implemented"); }
113 ///Edits the fields of a given node
114 virtual void ExportToStorage(const std::vector<std::string> keys)
115 { GimmickError("INTERNAL ERROR : ExportToStorage not implemented"); }
117 ///Copies selected files
118 virtual void SaveAs(const std::vector<std::string>& filenames)
119 { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
121 /// No selected image
122 bool NoValidateSelected();
124 ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
125 bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
127 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
128 void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
130 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
131 void ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
133 ///Requests the reading of an image with priority and index in the
134 /// current selection (-1 if not in selection)
135 //void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
136 void RequestReading(tree::Node* n, int prio, int selection_index , boost::shared_ptr<ImagePointerHolder> p);
138 ///Obtains the message of the state
139 std::string GetMessage(){return mMess;}
141 ///Obtains the message of the state
142 void SetMessage(std::string mess){mMess=mess;}
144 ///Resets the data of the extent and begins a new selection
147 /// Create the tree views
148 void CreateTreeViews();
150 /// Create a tree view with a given name
151 void CreateSingleTreeView(std::string &i_name);
153 /// Create the tree view for TreeHandler provided
154 virtual void CreateTreeView( TreeHandler* )
155 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
157 /// Updates the TreeView of given name from level l to bottom
158 /// (calls the virtual method TreeView::UpdateLevel(l))
159 virtual void UpdateTreeViewLevel(const std::string&, int l);
161 // Multi-thread image reader callback
162 void OnMultiThreadImageReaderEvent(const std::string& filename,
163 MultiThreadImageReaderUser::EventType t,
164 vtkImageData* image);
166 vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
168 //=============================================
169 typedef boost::signal<void (bool)> ValidationSignalType;
170 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
171 //=============================================
173 //==================================================================
174 /// Adds the function f to the list of functions to call
175 /// when the addition progresses.
176 /// f is of type ProgressCallbackType which is:
177 /// void (*ProgressCallbackType)(Progress&)
178 /// To pass a member function 'f' of an instance 'c' of a class 'C'
179 /// as callback you have to 'bind' it, i.e. call:
180 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
181 void ConnectValidationObserver(ValidationCallbackType callback);
182 //==================================================================
184 void modifyValidationSignal(bool ivalid);
187 void readImages(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
188 OutputAttr i_attr, int i_dim, double i_zspc);
189 bool isSingle(const std::string i_file);
193 typedef void (*readXD)(std::vector<OutStrGimmick>&, std::vector<std::string>, OutputAttr, double);
195 void getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr);
197 virtual void readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
198 OutputAttr i_attr, double i_zspc);
200 virtual void readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
201 OutputAttr i_attr, double i_zspc);
203 virtual void readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
206 virtual void readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
210 /// Controller which manages the interaction with the model
211 boost::shared_ptr< Gimmick> mGimmick;
214 TreeViewMapType mTreeViewMap;
216 /// The message that results from the validation
219 /// Multi-thread image reader
220 MultiThreadImageReader mReader;
222 /// Internal type of image reading event
223 /// If the image pointer is non null then the image is available (loaded)
224 /// else it has been unloaded
225 struct ImageEventType
227 ImageEventType( tree::Node* no = 0,
229 // ImagePointerHolder* ph= 0)
230 : node(no), index(sel_index){}//, pointerHolder(ph){}
231 ImageEventType(vtkImageData* im )
236 boost::shared_ptr<ImagePointerHolder> pointerHolder;
238 typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
239 /// Map of images' names to ImageEventType
240 /// Used to associated a filename to a the data of a request
241 ImageEventTypeMap mImageEventMap;
243 // queue of image event
244 typedef std::deque<ImageEventType> ImageEventQueueType;
246 //ImageEventQueueType mImageEventQueue;
248 ///The current image extent
249 boost::shared_ptr<ImageExtent> mImageExtent;
251 ///The validation signal
252 ValidationSignalType mValidationSignal;
254 ///Boolean that determines if the selection is valid
257 ///Boolean that determines if the reader has been started
261 // EO class GimmickView
262 //=====================================================================
265 } // EO namespace creaImageIO