]> Creatis software - creaImageIO.git/blob - src2/creaImageIOGimmickView.h
ed6d31f734750280d6409f7e3608165419676351
[creaImageIO.git] / src2 / 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         * \ingroup View
30         */
31          
32         class ImageExtent;
33     //=====================================================================
34     
35     //=====================================================================
36     ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
37         class GimmickView: public MultiThreadImageReaderUser
38     {
39     public:
40       /// Ctor
41       GimmickView(boost::shared_ptr<Gimmick>, int number_of_threads = 0 );
42       /// Virtual destructor
43       virtual ~GimmickView();
44       /// Initializes the view : 
45       /// Creates the TreeViews for all the TreeHandler of the Controller
46       /// 
47       virtual void Initialize();
48
49       /// Type of map from View name to TreeView* 
50       /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
51       typedef std::map<std::string, TreeView*> TreeViewMapType;
52       
53       /// Returns the TreeViewMap (ref)
54       TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
55       /// Returns the TreeViewMap (const ref)
56       const TreeViewMapType& GetTreeViewMap() const
57       { return mTreeViewMap; }
58
59       /// Finalize 
60       virtual void Finalize();
61
62           ///Returns the maximal priority
63       int GetMaximalPriority(){return mReader.GetMaximalPriority();}
64
65       ///Adds the selected Images to the given vector
66       virtual void GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
67         { GimmickError("INTERNAL ERROR : GetSelectedImagesInVector not implemented"); }
68
69       ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
70       virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim) 
71           { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
72
73       virtual void GetSelectedFiles(std::vector<std::string>& s)
74       { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
75
76           virtual void GetImages(int dim, std::vector<std::string> files, std::vector<vtkImageData*>& s) 
77           { GimmickError("INTERNAL ERROR : GetImages not implemented"); }
78
79       virtual void OnSelectionChange(const std::vector<tree::Node*>& s, bool isSelection, int selection, bool mProcess)
80       { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
81
82            virtual void ClearSelection()
83       { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
84
85           ///Adds a file to ignore
86           virtual void AddIgnoreFile(tree::Node* toRemove)
87           { GimmickError("INTERNAL ERROR : AddIgnoreFile not implemented"); }
88       
89           ///Copies selected files
90           virtual void CopyFiles(const std::vector<std::string>& filenames)
91           { GimmickError("INTERNAL ERROR : CopyFiles not implemented"); }
92
93           ///Edits the fields of a given node
94           virtual void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
95           { GimmickError("INTERNAL ERROR : EditFields not implemented"); }
96       
97            ///Copies selected files
98           virtual void SaveAs(const std::vector<std::string>& filenames)
99           { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
100
101           /// No selected image
102           bool NoValidateSelected();
103
104       ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
105       bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
106
107       ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
108           void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
109
110       ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
111           void ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
112
113 ///Requests the reading of an image with priority and index in the 
114       /// current selection (-1 if not in selection)
115       //void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
116           void RequestReading(tree::Node* n, int prio, int selection_index , boost::shared_ptr<ImagePointerHolder> p);
117
118       ///Obtains the message of the state
119       std::string GetMessage(){return mMess;}
120
121      ///Obtains the message of the state
122       void SetMessage(std::string mess){mMess=mess;}
123
124           ///Resets the data of the extent and begins a new selection
125           void ResetExtent();
126
127       /// Create the tree views 
128       void CreateTreeViews();
129
130           /// Create a tree view with a given name
131           void CreateSingleTreeView(std::string &i_name);
132
133       /// Create the tree view for TreeHandler provided
134       virtual void CreateTreeView( TreeHandler* ) 
135       { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
136
137       /// Updates the TreeView of given name from level l to bottom
138       /// (calls the virtual method TreeView::UpdateLevel(l))
139       virtual void UpdateTreeViewLevel(const std::string&, int l);
140
141           // Multi-thread image reader callback
142           void OnMultiThreadImageReaderEvent(const std::string& filename,
143                                        MultiThreadImageReaderUser::EventType t,
144                                        vtkImageData* image);
145
146       vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
147
148       //=============================================
149       typedef boost::signal<void (bool)>  ValidationSignalType;
150       typedef ValidationSignalType::slot_function_type ValidationCallbackType;
151       //=============================================
152
153      //==================================================================
154       /// Adds the function f to the list of functions to call 
155       /// when the addition progresses.
156       /// f is of type ProgressCallbackType which is:
157       /// void (*ProgressCallbackType)(Progress&)
158       /// To pass a member function 'f' of an instance 'c' of a class 'C' 
159       /// as callback you have to 'bind' it, i.e. call:
160       /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
161       void ConnectValidationObserver(ValidationCallbackType callback);
162      //==================================================================
163
164         void modifyValidationSignal(bool ivalid);
165
166     private:
167
168         double OrderTheFileNameVector(std::vector<std::string> &im);
169
170       /// Controller which manages the interaction with the model
171       boost::shared_ptr< Gimmick> mGimmick;
172
173       /// The views 
174       TreeViewMapType mTreeViewMap;
175
176       /// The message that results from the validation
177       std::string mMess;
178
179       /// Multi-thread image reader
180       MultiThreadImageReader mReader;
181
182       /// Internal type of image reading event
183       /// If the image pointer is non null then the image is available (loaded)
184       /// else it has been unloaded
185       struct ImageEventType
186       {
187         ImageEventType( tree::Node* no = 0,   
188                         int sel_index = -1)
189 //                      ImagePointerHolder* ph= 0)
190           : node(no), index(sel_index){}//,  pointerHolder(ph){}
191         ImageEventType(vtkImageData* im )
192           : image(im) {}
193         tree::Node* node;
194         vtkImageData* image;
195                 int index;
196                 boost::shared_ptr<ImagePointerHolder> pointerHolder;
197       };
198       typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
199       /// Map of images' names to ImageEventType
200       /// Used to associated a filename to a the data of a request
201       ImageEventTypeMap mImageEventMap;
202
203       // queue of image event 
204       typedef std::deque<ImageEventType> ImageEventQueueType;
205
206       //ImageEventQueueType mImageEventQueue;
207
208           ///The current image extent
209           boost::shared_ptr<ImageExtent> mImageExtent;
210
211           ///The validation signal
212           ValidationSignalType mValidationSignal;
213
214           ///Boolean that determines if the selection is valid
215           bool valid;
216
217           ///Boolean that determines if the reader has been started
218           bool mReaderStarted;
219
220         };
221   // EO class GimmickView
222     //=====================================================================
223
224  
225 } // EO namespace creaImageIO
226
227 // EOF
228 #endif