]> Creatis software - creaImageIO.git/blob - src/creaImageIOGimmickView.h
new Output format and structure for Gimmick. Based on creaImageIO Output document...
[creaImageIO.git] / src / creaImageIOGimmickView.h
1 #ifndef __creaImageIOGimmickView_h_INCLUDED__
2 #define __creaImageIOGimmickView_h_INCLUDED__
3
4 #include <creaImageIOGimmick.h>
5 #include <creaImageIOTreeView.h>
6 #include <creaImageIOSystem.h>
7 #include <creaImageIOImagePointerHolder.h>
8
9 //#include <map>
10 #include <vtkImageData.h>
11 #include <creaImageIOMultiThreadImageReader.h>
12
13 // Signal/slot mechanism for progress events
14 #include <boost/signal.hpp>
15 #include <boost/bind.hpp>
16
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
21
22 #define NATIVE 0
23 #define _2D    2
24 #define _3D    3
25
26 namespace creaImageIO
27 {
28
29         typedef struct 
30         { 
31                 vtkImageData *img;
32                 std::map<std::string, std::string> infos;
33         }OutStrGimmick;
34
35
36         /**
37         * \ingroup View
38         */
39          
40         class ImageExtent;
41     //=====================================================================
42     
43     //=====================================================================
44     ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
45         class GimmickView: public MultiThreadImageReaderUser
46     {
47     public:
48       /// Ctor
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
54       /// 
55       virtual void Initialize();
56
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;
60       
61       /// Returns the TreeViewMap (ref)
62       TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
63       /// Returns the TreeViewMap (const ref)
64       const TreeViewMapType& GetTreeViewMap() const
65       { return mTreeViewMap; }
66
67       /// Finalize 
68       virtual void Finalize();
69
70           ///Returns the maximal priority
71       int GetMaximalPriority(){return mReader.GetMaximalPriority();}
72
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"); }
76
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"); }
80
81       virtual void GetSelectedFiles(std::vector<std::string>& s)
82       { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
83
84           virtual void GetImages(int dim, std::vector<std::string> files, std::vector<vtkImageData*>& s) 
85           { GimmickError("INTERNAL ERROR : GetImages not implemented"); }
86
87       virtual void OnSelectionChange(const std::vector<tree::Node*>& s, bool isSelection, int selection, bool mProcess)
88       { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
89
90            virtual void ClearSelection()
91       { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
92
93           ///Adds a file to ignore
94           virtual void AddIgnoreFile(tree::Node* toRemove)
95           { GimmickError("INTERNAL ERROR : AddIgnoreFile not implemented"); }
96       
97           ///Copies selected files
98           virtual void CopyFiles(const std::vector<std::string>& filenames)
99           { GimmickError("INTERNAL ERROR : CopyFiles not implemented"); }
100
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"); }
104       
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"); }
108
109           /// Display all Dicom Tags
110           virtual void DumpTags(const std::string filename)
111           {GimmickError("INTERNAL ERROR : DumpTags not implemented"); }
112           
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"); }
116       
117            ///Copies selected files
118           virtual void SaveAs(const std::vector<std::string>& filenames)
119           { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
120
121           /// No selected image
122           bool NoValidateSelected();
123
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);
126
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);
129
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);
132
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);
137
138       ///Obtains the message of the state
139       std::string GetMessage(){return mMess;}
140
141      ///Obtains the message of the state
142       void SetMessage(std::string mess){mMess=mess;}
143
144           ///Resets the data of the extent and begins a new selection
145           void ResetExtent();
146
147       /// Create the tree views 
148       void CreateTreeViews();
149
150           /// Create a tree view with a given name
151           void CreateSingleTreeView(std::string &i_name);
152
153       /// Create the tree view for TreeHandler provided
154       virtual void CreateTreeView( TreeHandler* ) 
155       { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
156
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);
160
161           // Multi-thread image reader callback
162           void OnMultiThreadImageReaderEvent(const std::string& filename,
163                                        MultiThreadImageReaderUser::EventType t,
164                                        vtkImageData* image);
165
166       vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
167
168       //=============================================
169       typedef boost::signal<void (bool)>  ValidationSignalType;
170       typedef ValidationSignalType::slot_function_type ValidationCallbackType;
171       //=============================================
172
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      //==================================================================
183
184         void modifyValidationSignal(bool ivalid);
185
186         
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);
190     private:
191
192
193         typedef void (*readXD)(std::vector<OutStrGimmick>&,  std::vector<std::string>, OutputAttr, double);
194
195         void getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr);
196
197         virtual void readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
198                          OutputAttr i_attr, double i_zspc);
199
200         virtual void readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
201                          OutputAttr i_attr, double i_zspc);
202
203         virtual void readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
204                          OutputAttr i_attr);
205
206         virtual void readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
207                          OutputAttr i_attr);
208
209
210       /// Controller which manages the interaction with the model
211       boost::shared_ptr< Gimmick> mGimmick;
212
213       /// The views 
214       TreeViewMapType mTreeViewMap;
215
216       /// The message that results from the validation
217       std::string mMess;
218
219       /// Multi-thread image reader
220       MultiThreadImageReader mReader;
221
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
226       {
227         ImageEventType( tree::Node* no = 0,   
228                         int sel_index = -1)
229 //                      ImagePointerHolder* ph= 0)
230           : node(no), index(sel_index){}//,  pointerHolder(ph){}
231         ImageEventType(vtkImageData* im )
232           : image(im) {}
233         tree::Node* node;
234         vtkImageData* image;
235                 int index;
236                 boost::shared_ptr<ImagePointerHolder> pointerHolder;
237       };
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;
242
243       // queue of image event 
244       typedef std::deque<ImageEventType> ImageEventQueueType;
245
246       //ImageEventQueueType mImageEventQueue;
247
248           ///The current image extent
249           boost::shared_ptr<ImageExtent> mImageExtent;
250
251           ///The validation signal
252           ValidationSignalType mValidationSignal;
253
254           ///Boolean that determines if the selection is valid
255           bool valid;
256
257           ///Boolean that determines if the reader has been started
258           bool mReaderStarted;
259
260         };
261   // EO class GimmickView
262     //=====================================================================
263
264  
265 } // EO namespace creaImageIO
266
267 // EOF
268 #endif