]> Creatis software - creaImageIO.git/blob - src/creaImageIOGimmickView.h
02b35d8d26c4d80b9d9aad795accf2ff4f4adae4
[creaImageIO.git] / src / creaImageIOGimmickView.h
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image 
5 #                        pour la Santé)
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9 #
10 #  This software is governed by the CeCILL-B license under French law and 
11 #  abiding by the rules of distribution of free software. You can  use, 
12 #  modify and/ or redistribute the software under the terms of the CeCILL-B 
13 #  license as circulated by CEA, CNRS and INRIA at the following URL 
14 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
15 #  or in the file LICENSE.txt.
16 #
17 #  As a counterpart to the access to the source code and  rights to copy,
18 #  modify and redistribute granted by the license, users are provided only
19 #  with a limited warranty  and the software's author,  the holder of the
20 #  economic rights,  and the successive licensors  have only  limited
21 #  liability. 
22 #
23 #  The fact that you are presently reading this means that you have had
24 #  knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
26 */
27
28
29 #ifndef __creaImageIOGimmickView_h_INCLUDED__
30 #define __creaImageIOGimmickView_h_INCLUDED__
31
32 #include <creaImageIOGimmick.h>
33 #include <creaImageIOTreeView.h>
34 #include <creaImageIOSystem.h>
35 #include <creaImageIOImagePointerHolder.h>
36
37 //#include <map>
38 #include <vtkImageData.h>
39 #if defined (USE_WXWIDGETS)
40 #include <creaImageIOMultiThreadImageReader.h>
41 #endif
42
43 #if defined(USE_QT)
44 #include "Qt/creaImageIOQMultiThreadImageReader.h"
45 #endif
46
47
48 // Signal/slot mechanism for progress events
49 #include <boost/signal.hpp>
50 #include <boost/bind.hpp>
51
52 #define GIMMICK_NO_IMAGE_SELECTION 0
53 #define GIMMICK_2D_IMAGE_SELECTION 2
54 #define GIMMICK_3D_IMAGE_SELECTION 3
55 #define GIMMICK_4D_IMAGE_SELECTION 4
56
57 #define NATIVE 0
58 #define _2D    2
59 #define _3D    3
60
61 namespace creaImageIO
62 {
63         typedef std::map<std::string, std::string> mapInfoDicom;
64
65         typedef struct 
66         { 
67                 vtkImageData *img;
68                 //std::map<std::string, std::string> infos;
69                 mapInfoDicom infos; 
70         } OutStrGimmick;
71
72
73         /**
74         * \ingroup View
75         */
76          
77         class ImageExtent;
78     //=====================================================================
79     
80     //=====================================================================
81     ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
82         class GimmickView: public MultiThreadImageReaderUser
83     {
84     public:
85       /// Ctor
86       GimmickView(boost::shared_ptr<Gimmick>, int number_of_threads = 0 );
87       /// Virtual destructor
88       virtual ~GimmickView();
89       /// Initializes the view : 
90       /// Creates the TreeViews for all the TreeHandler of the Controller
91       /// 
92       virtual void Initialize();
93
94       /// Type of map from View name to TreeView* 
95       /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
96       typedef std::map<std::string, TreeView*> TreeViewMapType;
97       
98       /// Returns the TreeViewMap (ref)
99       TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
100       /// Returns the TreeViewMap (const ref)
101       const TreeViewMapType& GetTreeViewMap() const
102       { return mTreeViewMap; }
103
104       /// Finalize 
105       virtual void Finalize();
106
107           ///Returns the maximal priority
108       int GetMaximalPriority(){return mReader.GetMaximalPriority();}
109
110       ///Adds the selected Images to the given vector
111       virtual void GetSelectedImagesInVector(std::vector<vtkImageData*>& s, int dim)
112         { GimmickError("INTERNAL ERROR : GetSelectedImagesInVector not implemented"); }
113
114       ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
115       virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim) 
116           { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
117
118       virtual void GetSelectedFiles(std::vector<std::string>& s)
119       { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
120
121       virtual void GetImages(int dim, std::vector<std::string> files, std::vector<vtkImageData*>& s) 
122       { GimmickError("INTERNAL ERROR : GetImages not implemented"); }
123
124       virtual void OnSelectionChange(const std::vector<tree::Node*>& s, bool isSelection, int selection, bool mProcess)
125       { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
126
127            virtual void ClearSelection()
128       { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
129
130           ///Adds a file to ignore
131           virtual void AddIgnoreFile(tree::Node* toRemove)
132           { GimmickError("INTERNAL ERROR : AddIgnoreFile not implemented"); }
133       
134           ///Copies selected files
135           virtual void CopyFiles(const std::vector<std::string>& filenames)
136           { GimmickError("INTERNAL ERROR : CopyFiles not implemented"); }
137
138           ///Edits the fields of a given node
139           virtual void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
140           { GimmickError("INTERNAL ERROR : EditFields not implemented"); }
141       
142           /// Anonymize or de-anonymize data
143           void Anonymize(std::vector<std::string> i_filenames, int type);
144
145           /// Display all Dicom Tags
146           virtual void DumpTags(const std::string filename)
147           {GimmickError("INTERNAL ERROR : DumpTags not implemented"); }
148           
149             ///Edits the fields of a given node
150           virtual void ExportToStorage(const std::vector<std::string> keys)
151           { GimmickError("INTERNAL ERROR : ExportToStorage not implemented"); }
152       
153            ///Copies selected files
154           virtual void SaveAs(const std::vector<std::string>& filenames)
155           { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
156
157           /// No selected image
158           bool NoValidateSelected();
159
160       ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
161       bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
162
163       ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
164           void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
165
166       ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
167           void ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
168
169 ///Requests the reading of an image with priority and index in the 
170       /// current selection (-1 if not in selection)
171       //void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
172           void RequestReading(tree::Node* n, int prio, int selection_index , boost::shared_ptr<ImagePointerHolder> p);
173
174       ///Obtains the message of the state
175       std::string GetMessage(){return mMess;}
176
177      ///Obtains the message of the state
178       void SetMessage(std::string mess){mMess=mess;}
179
180           ///Resets the data of the extent and begins a new selection
181           void ResetExtent();
182
183       /// Create the tree views 
184       void CreateTreeViews();
185
186           /// Create a tree view with a given name
187           void CreateSingleTreeView(std::string &i_name);
188
189       /// Create the tree view for TreeHandler provided
190       virtual void CreateTreeView( TreeHandler* ) 
191       { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
192
193       /// Updates the TreeView of given name from level l to bottom
194       /// (calls the virtual method TreeView::UpdateLevel(l))
195       virtual void UpdateTreeViewLevel(const std::string&, int l);
196
197           // Multi-thread image reader callback
198           void OnMultiThreadImageReaderEvent(const std::string& filename,
199                                        MultiThreadImageReaderUser::EventType t,
200                                        vtkImageData* image);
201
202       vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
203
204       //=============================================
205       typedef boost::signal<void (bool)>  ValidationSignalType;
206       typedef ValidationSignalType::slot_function_type ValidationCallbackType;
207       //=============================================
208
209      //==================================================================
210       /// Adds the function f to the list of functions to call 
211       /// when the addition progresses.
212       /// f is of type ProgressCallbackType which is:
213       /// void (*ProgressCallbackType)(Progress&)
214       /// To pass a member function 'f' of an instance 'c' of a class 'C' 
215       /// as callback you have to 'bind' it, i.e. call:
216       /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
217       void ConnectValidationObserver(ValidationCallbackType callback);
218      //==================================================================
219
220         void modifyValidationSignal(bool ivalid);
221
222         
223         void readImages(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
224                          OutputAttr i_attr, int i_dim, double i_zspc);
225                         bool isSingle(const std::string i_file);
226
227         void stopReader();
228     private:
229
230
231         typedef void (*readXD)(std::vector<OutStrGimmick>&,  std::vector<std::string>, OutputAttr, double);
232
233         void getAttributes(const std::string i_file, std::map<std::string, std::string> &o_infos, OutputAttr i_attr);
234
235         virtual void readImages2(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
236                          OutputAttr i_attr, double i_zspc);
237
238         virtual void readImages3(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
239                          OutputAttr i_attr, double i_zspc);
240
241         virtual void readImages4(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
242                          OutputAttr i_attr);
243
244         virtual void readImages1(std::vector<OutStrGimmick>& o_output, std::vector<std::string> im,
245                          OutputAttr i_attr);
246
247
248       /// Controller which manages the interaction with the model
249       boost::shared_ptr< Gimmick> mGimmick;
250
251       /// The views 
252       TreeViewMapType mTreeViewMap;
253
254       /// The message that results from the validation
255       std::string mMess;
256
257       /// Multi-thread image reader
258       MultiThreadImageReader mReader;
259
260       /// Internal type of image reading event
261       /// If the image pointer is non null then the image is available (loaded)
262       /// else it has been unloaded
263       struct ImageEventType
264       {
265         ImageEventType( tree::Node* no = 0,   
266                         int sel_index = -1)
267 //                      ImagePointerHolder* ph= 0)
268           : node(no), index(sel_index){}//,  pointerHolder(ph){}
269         ImageEventType(vtkImageData* im )
270           : image(im) {}
271         tree::Node* node;
272         vtkImageData* image;
273                 int index;
274                 boost::shared_ptr<ImagePointerHolder> pointerHolder;
275       };
276       typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
277       /// Map of images' names to ImageEventType
278       /// Used to associated a filename to a the data of a request
279       ImageEventTypeMap mImageEventMap;
280
281       // queue of image event 
282       typedef std::deque<ImageEventType> ImageEventQueueType;
283
284       //ImageEventQueueType mImageEventQueue;
285
286           ///The current image extent
287           boost::shared_ptr<ImageExtent> mImageExtent;
288
289           ///The validation signal
290           ValidationSignalType mValidationSignal;
291
292           ///Boolean that determines if the selection is valid
293           bool valid;
294
295           ///Boolean that determines if the reader has been started
296           bool mReaderStarted;
297
298         };
299   // EO class GimmickView
300     //=====================================================================
301
302  
303 } // EO namespace creaImageIO
304
305 // EOF
306 #endif