]> Creatis software - creaImageIO.git/blob - src2/creaImageIOGimmickView.h
move directory
[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           /// Display all Dicom Tags
98           virtual void DumpTags(const std::string filename)
99           {GimmickError("INTERNAL ERROR : DumpTags not implemented"); }
100           
101             ///Edits the fields of a given node
102           virtual void ExportToStorage(const std::vector<std::string> keys)
103           { GimmickError("INTERNAL ERROR : ExportToStorage not implemented"); }
104       
105            ///Copies selected files
106           virtual void SaveAs(const std::vector<std::string>& filenames)
107           { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
108
109           /// No selected image
110           bool NoValidateSelected();
111
112       ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
113       bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
114
115       ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
116           void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
117
118       ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
119           void ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
120
121 ///Requests the reading of an image with priority and index in the 
122       /// current selection (-1 if not in selection)
123       //void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
124           void RequestReading(tree::Node* n, int prio, int selection_index , boost::shared_ptr<ImagePointerHolder> p);
125
126       ///Obtains the message of the state
127       std::string GetMessage(){return mMess;}
128
129      ///Obtains the message of the state
130       void SetMessage(std::string mess){mMess=mess;}
131
132           ///Resets the data of the extent and begins a new selection
133           void ResetExtent();
134
135       /// Create the tree views 
136       void CreateTreeViews();
137
138           /// Create a tree view with a given name
139           void CreateSingleTreeView(std::string &i_name);
140
141       /// Create the tree view for TreeHandler provided
142       virtual void CreateTreeView( TreeHandler* ) 
143       { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
144
145       /// Updates the TreeView of given name from level l to bottom
146       /// (calls the virtual method TreeView::UpdateLevel(l))
147       virtual void UpdateTreeViewLevel(const std::string&, int l);
148
149           // Multi-thread image reader callback
150           void OnMultiThreadImageReaderEvent(const std::string& filename,
151                                        MultiThreadImageReaderUser::EventType t,
152                                        vtkImageData* image);
153
154       vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
155
156       //=============================================
157       typedef boost::signal<void (bool)>  ValidationSignalType;
158       typedef ValidationSignalType::slot_function_type ValidationCallbackType;
159       //=============================================
160
161      //==================================================================
162       /// Adds the function f to the list of functions to call 
163       /// when the addition progresses.
164       /// f is of type ProgressCallbackType which is:
165       /// void (*ProgressCallbackType)(Progress&)
166       /// To pass a member function 'f' of an instance 'c' of a class 'C' 
167       /// as callback you have to 'bind' it, i.e. call:
168       /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
169       void ConnectValidationObserver(ValidationCallbackType callback);
170      //==================================================================
171
172         void modifyValidationSignal(bool ivalid);
173
174     private:
175
176         double OrderTheFileNameVector(std::vector<std::string> &im);
177
178       /// Controller which manages the interaction with the model
179       boost::shared_ptr< Gimmick> mGimmick;
180
181       /// The views 
182       TreeViewMapType mTreeViewMap;
183
184       /// The message that results from the validation
185       std::string mMess;
186
187       /// Multi-thread image reader
188       MultiThreadImageReader mReader;
189
190       /// Internal type of image reading event
191       /// If the image pointer is non null then the image is available (loaded)
192       /// else it has been unloaded
193       struct ImageEventType
194       {
195         ImageEventType( tree::Node* no = 0,   
196                         int sel_index = -1)
197 //                      ImagePointerHolder* ph= 0)
198           : node(no), index(sel_index){}//,  pointerHolder(ph){}
199         ImageEventType(vtkImageData* im )
200           : image(im) {}
201         tree::Node* node;
202         vtkImageData* image;
203                 int index;
204                 boost::shared_ptr<ImagePointerHolder> pointerHolder;
205       };
206       typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
207       /// Map of images' names to ImageEventType
208       /// Used to associated a filename to a the data of a request
209       ImageEventTypeMap mImageEventMap;
210
211       // queue of image event 
212       typedef std::deque<ImageEventType> ImageEventQueueType;
213
214       //ImageEventQueueType mImageEventQueue;
215
216           ///The current image extent
217           boost::shared_ptr<ImageExtent> mImageExtent;
218
219           ///The validation signal
220           ValidationSignalType mValidationSignal;
221
222           ///Boolean that determines if the selection is valid
223           bool valid;
224
225           ///Boolean that determines if the reader has been started
226           bool mReaderStarted;
227
228         };
229   // EO class GimmickView
230     //=====================================================================
231
232  
233 } // EO namespace creaImageIO
234
235 // EOF
236 #endif