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
34 //=====================================================================
36 //=====================================================================
37 ///Abstract class that handles views, attributes and previews (GUI) for Gimmick.
38 class GimmickView: public MultiThreadImageReaderUser
42 GimmickView(boost::shared_ptr<Gimmick>, int number_of_threads = 0 );
43 /// Virtual destructor
44 virtual ~GimmickView();
45 /// Initializes the view :
46 /// Creates the TreeViews for all the TreeHandler of the Controller
48 virtual void Initialize();
50 /// Type of map from View name to TreeView*
51 /// (This map is equivalent for Views of the TreeHandlerMap of Gimmick)
52 typedef std::map<std::string, TreeView*> TreeViewMapType;
54 /// Returns the TreeViewMap (ref)
55 TreeViewMapType& GetTreeViewMap() { return mTreeViewMap; }
56 /// Returns the TreeViewMap (const ref)
57 const TreeViewMapType& GetTreeViewMap() const
58 { return mTreeViewMap; }
61 virtual void Finalize();
63 //Returns the maximal priority
64 int GetMaximalPriority(){return mReader.GetMaximalPriority();}
66 ///Adds the selected Images to the given vector and validates to see if they comply with the given parameter (4D)
67 virtual void GetSelectedImages(std::vector<vtkImageData*>& s, int dim)
68 { GimmickError("INTERNAL ERROR : GetSelectedImages not implemented"); }
70 virtual void GetSelectedFiles(std::vector<std::string>& s)
71 { GimmickError("INTERNAL ERROR : GetSelectedFiles not implemented"); }
73 virtual void GetImages(int dim, std::vector<std::string> files, std::vector<vtkImageData*>& s)
74 { GimmickError("INTERNAL ERROR : GetImages not implemented"); }
76 virtual void OnSelectionChange(const std::vector<tree::Node*>& s, bool isSelection, int selection, bool mProcess)
77 { GimmickError("INTERNAL ERROR : OnSelectionChange not implemented"); }
79 virtual void ClearSelection()
80 { GimmickError("INTERNAL ERROR : ClearSelection not implemented"); }
82 ///Adds a file to ignore
83 virtual void AddIgnoreFile(tree::Node* toRemove)
84 { GimmickError("INTERNAL ERROR : AddIgnoreFile not implemented"); }
86 ///Copies selected files
87 virtual void CopyFiles(const std::vector<std::string>& filenames)
88 { GimmickError("INTERNAL ERROR : CopyFiles not implemented"); }
90 ///Edits the fields of a given node
91 virtual void CreateEditFieldsDialog(tree::Node* node, std::vector<std::string> names, std::vector<std::string> keys)
92 { GimmickError("INTERNAL ERROR : EditFields not implemented"); }
94 ///Copies selected files
95 virtual void SaveAs(const std::vector<std::string>& filenames)
96 { GimmickError("INTERNAL ERROR : SaveAs not implemented"); }
100 bool NoValidateSelected();
101 ///Validates the dimension compliance of the images with the maximum and minimum given, and between their sizes
102 bool ValidateSelected (tree::Node* sel, int min_dim, int max_dim);
104 ///Reads the vector of images, builds it in the dimension required and returns them in the supplied vector.
105 void ReadImagesNotThreaded(std::vector<vtkImageData*>& s,std::vector<std::string> files, int dim);
106 ///Requests the reading of an image with priority and index in the
107 /// current selection (-1 if not in selection)
108 //void RequestReading(tree::Node* n, int prio, int selection_index , ImagePointerHolder *p);
109 void RequestReading(tree::Node* n, int prio, int selection_index , boost::shared_ptr<ImagePointerHolder> p);
112 ///Obtains the message of the state
113 std::string GetMessage(){return mMess;}
114 ///Obtains the message of the state
115 void SetMessage(std::string mess){mMess=mess;}
116 ///Resets the data of the extent and begins a new selection
119 /// Create the tree views
120 void CreateTreeViews();
122 /// Create a tree view with a given name
123 void CreateSingleTreeView(std::string &i_name);
125 /// Create the tree view for TreeHandler provided
126 virtual void CreateTreeView( TreeHandler* )
127 { GimmickError("INTERNAL ERROR : CreateTreeView not implemented"); }
129 /// Updates the TreeView of given name from level l to bottom
130 /// (calls the virtual method TreeView::UpdateLevel(l))
131 virtual void UpdateTreeViewLevel(const std::string&, int l);
132 // Multi-thread image reader callback
133 void OnMultiThreadImageReaderEvent(const std::string& filename,
134 MultiThreadImageReaderUser::EventType t,
135 vtkImageData* image);
137 vtkImageData* GetDefaultImage() { return mReader.GetImage(""); }
140 //=============================================
141 typedef boost::signal<void (bool)> ValidationSignalType;
142 typedef ValidationSignalType::slot_function_type ValidationCallbackType;
143 //=============================================
145 //==================================================================
146 /// Adds the function f to the list of functions to call
147 /// when the addition progresses.
148 /// f is of type ProgressCallbackType which is:
149 /// void (*ProgressCallbackType)(Progress&)
150 /// To pass a member function 'f' of an instance 'c' of a class 'C'
151 /// as callback you have to 'bind' it, i.e. call:
152 /// ConnectValidationObserver ( boost::bind( &C::f , c, _1 ) );
153 void ConnectValidationObserver(ValidationCallbackType callback);
154 //==================================================================
158 void modifyValidationSignal(bool ivalid);
162 /// Controller which manages the interaction with the model
163 boost::shared_ptr< Gimmick> mGimmick;
165 TreeViewMapType mTreeViewMap;
166 /// The message that results from the validation
169 /// Multi-thread image reader
170 MultiThreadImageReader mReader;
171 /// Internal type of image reading event
172 /// If the image pointer is non null then the image is available (loaded)
173 /// else it has been unloaded
174 struct ImageEventType
176 ImageEventType( tree::Node* no = 0,
178 // ImagePointerHolder* ph= 0)
179 : node(no), index(sel_index){}//, pointerHolder(ph){}
180 ImageEventType(vtkImageData* im )
185 boost::shared_ptr<ImagePointerHolder> pointerHolder;
187 typedef std::map<std::string,ImageEventType> ImageEventTypeMap;
188 /// Map of images' names to ImageEventType
189 /// Used to associated a filename to a the data of a request
190 ImageEventTypeMap mImageEventMap;
191 // queue of image event
192 typedef std::deque<ImageEventType> ImageEventQueueType;
193 //ImageEventQueueType mImageEventQueue;
195 ///The current image extent
196 boost::shared_ptr<ImageExtent> mImageExtent;
197 ///The validation signal
198 ValidationSignalType mValidationSignal;
199 ///Boolean that determines if the selection is valid
201 ///Boolean that determines if the reader has been started
205 // EO class GimmickView
206 //=====================================================================
211 } // EO namespace creaImageIO