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
33 //=====================================================================
35 //=====================================================================
36 ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
37 class GimmickView: public MultiThreadImageReaderUser
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
47 virtual void Initialize();
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;
53 /// Returns the TreeViewMap (ref)
54 TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
55 /// Returns the TreeViewMap (const ref)
56 const TreeViewMapType& GetTreeViewMap() const
57 { return mTreeViewMap; }
60 virtual void Finalize();
62 ///Returns the maximal priority
63 int GetMaximalPriority(){return mReader.GetMaximalPriority();}
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"); }
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"); }
73 virtual void GetSelectedFiles(std::vector<std::string>& s)
74 { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
76 virtual void GetImages(int dim, std::vector<std::string> files, std::vector<vtkImageData*>& s)
77 { GimmickError("INTERNAL ERROR : GetImages not implemented"); }
79 virtual void OnSelectionChange(const std::vector<tree::Node*>& s, bool isSelection, int selection, bool mProcess)
80 { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
82 virtual void ClearSelection()
83 { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
85 ///Adds a file to ignore
86 virtual void AddIgnoreFile(tree::Node* toRemove)
87 { GimmickError("INTERNAL ERROR : AddIgnoreFile not implemented"); }
89 ///Copies selected files
90 virtual void CopyFiles(const std::vector<std::string>& filenames)
91 { GimmickError("INTERNAL ERROR : CopyFiles not implemented"); }
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"); }
97 /// Display all Dicom Tags
98 virtual void DumpTags(const std::string filename)
99 {GimmickError("INTERNAL ERROR : DumpTags not implemented"); }
101 ///Copies selected files
102 virtual void SaveAs(const std::vector<std::string>& filenames)
103 { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
105 /// No selected image
106 bool NoValidateSelected();
108 ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
109 bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
111 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
112 void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
114 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
115 void ReadImagesNotThreadedInVector(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
117 ///Requests the reading of an image with priority and index in the
118 /// current selection (-1 if not in selection)
119 //void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
120 void RequestReading(tree::Node* n, int prio, int selection_index , boost::shared_ptr<ImagePointerHolder> p);
122 ///Obtains the message of the state
123 std::string GetMessage(){return mMess;}
125 ///Obtains the message of the state
126 void SetMessage(std::string mess){mMess=mess;}
128 ///Resets the data of the extent and begins a new selection
131 /// Create the tree views
132 void CreateTreeViews();
134 /// Create a tree view with a given name
135 void CreateSingleTreeView(std::string &i_name);
137 /// Create the tree view for TreeHandler provided
138 virtual void CreateTreeView( TreeHandler* )
139 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
141 /// Updates the TreeView of given name from level l to bottom
142 /// (calls the virtual method TreeView::UpdateLevel(l))
143 virtual void UpdateTreeViewLevel(const std::string&, int l);
145 // Multi-thread image reader callback
146 void OnMultiThreadImageReaderEvent(const std::string& filename,
147 MultiThreadImageReaderUser::EventType t,
148 vtkImageData* image);
150 vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
152 //=============================================
153 typedef boost::signal<void (bool)> ValidationSignalType;
154 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
155 //=============================================
157 //==================================================================
158 /// Adds the function f to the list of functions to call
159 /// when the addition progresses.
160 /// f is of type ProgressCallbackType which is:
161 /// void (*ProgressCallbackType)(Progress&)
162 /// To pass a member function 'f' of an instance 'c' of a class 'C'
163 /// as callback you have to 'bind' it, i.e. call:
164 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
165 void ConnectValidationObserver(ValidationCallbackType callback);
166 //==================================================================
168 void modifyValidationSignal(bool ivalid);
172 double OrderTheFileNameVector(std::vector<std::string> &im);
174 /// Controller which manages the interaction with the model
175 boost::shared_ptr< Gimmick> mGimmick;
178 TreeViewMapType mTreeViewMap;
180 /// The message that results from the validation
183 /// Multi-thread image reader
184 MultiThreadImageReader mReader;
186 /// Internal type of image reading event
187 /// If the image pointer is non null then the image is available (loaded)
188 /// else it has been unloaded
189 struct ImageEventType
191 ImageEventType( tree::Node* no = 0,
193 // ImagePointerHolder* ph= 0)
194 : node(no), index(sel_index){}//, pointerHolder(ph){}
195 ImageEventType(vtkImageData* im )
200 boost::shared_ptr<ImagePointerHolder> pointerHolder;
202 typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
203 /// Map of images' names to ImageEventType
204 /// Used to associated a filename to a the data of a request
205 ImageEventTypeMap mImageEventMap;
207 // queue of image event
208 typedef std::deque<ImageEventType> ImageEventQueueType;
210 //ImageEventQueueType mImageEventQueue;
212 ///The current image extent
213 boost::shared_ptr<ImageExtent> mImageExtent;
215 ///The validation signal
216 ValidationSignalType mValidationSignal;
218 ///Boolean that determines if the selection is valid
221 ///Boolean that determines if the reader has been started
225 // EO class GimmickView
226 //=====================================================================
229 } // EO namespace creaImageIO