Hugin trunk 0.1
Loading...
Searching...
No Matches
ViewState.h
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
2
24/* A ViewState or VisualizationState holds information about what is visible, the state of the
25 * various bits of the panorama as it is shown in a preview, and the scaling of
26 * the preview. The state of the panorama options and images are stored so
27 * that we can continuously change properties interactively without bothering
28 * the real panorama object and therefore the undo / redo history. The classes
29 * also manages what needs to be recalculated to update the view.
30 *
31 * When a change occurs, we examine any differences with our stored state that
32 * we care about. It doesn't matter if the change is caused by an interactive
33 * tool or an update to the panorama object.
34 * If we find a change that makes our preview out of sync, we record what needs
35 * to be done to bring it up to date. Note some changes do not create any
36 * difference to the preview, so we don't even want to redraw sometimes.
37 * After the changes have been made, we can state what needs redoing when asked.
38 * The texture manager and mesh manager will ask what they need to do.
39 * After that, any changes we suggested should have been made, and FinishDraw()
40 * is called. At this point we declare everything is clean and up to date again.
41 *
42 * We don't intitiate the calculations ourself when doing things interactively
43 * so we can group several changes together, e.g. when dragging a group of
44 * images together SetSrcImage is called for each image but we only want to
45 * redraw after they have all been moved. However, when the panorama changes
46 * we want to initiate an update the preview ourself, so all the main GUI
47 * interactions work.
48 *
49 * The information is divided into two classes:
50 * - The first class is the ViewState class which holds information that is
51 * relevant for all Visualizations like the preview, panosphere or plane.
52 * This is mainly dominated by the manipulation of the Textures related stuff
53 * which are the same for all visualizations.
54 * The ViewState also encapsulates all the VisualizationState in itself so that
55 * it can properly inform them when any change occurs
56 *
57 * - The second class is the VisualizationState class which is subclassed for each
58 * type of visualization. The VisualizationState class holds information specific
59 * to each visualization. This includes the state of the meshes, state of the viewport, etc.
60 *
61 */
62
63#ifndef __VIEWSTATE_H
64#define __VIEWSTATE_H
65
66#include "base_wx/wxutils.h"
68#include <panodata/Panorama.h>
70#include <vigra/diff2d.hxx>
71#include "TextureManager.h"
72#include "MeshManager.h"
73
75
76class GLViewer;
78
79
81{
82public:
83 // constructor: we need to know what panorama we deal with.
85 ~ViewState();
86 // when the real panorama changes, we want to update ourself to reflect it.
87 // we will force a redraw if anything worthwhile changes.
90
91 // For interactive control, the real panorama does not change. Instead one
92 // of the following functions will be called:
96 // someone else decides we need to redraw next time around.
97 void ForceRequireRedraw();
98 // then we compare with the stored state and set dirty flags as neceassry.
99
103
105
106 bool GetSupportMultiTexture() const { return m_multiTexture; };
107 // These functions are used to identify what needs to be redone on the next
108 // redraw.
109 // return true if we should update a texture's photometric correction
111 // return true if we should check the generated mip levels of the textures
113 // return true if we should update a mask
114 bool RequireRecalculateMasks(unsigned int image_nr);
115 // return true if images have been removed
116 bool ImagesRemoved();
117
118 // this is called when a draw has been performed, so we can assume the
119 // drawing state (textures, meshes) are now all up to date.
120 void FinishedDraw();
121
122 // update the meshes and textures as necessary before drawing.
123 void DoUpdates();
124
125 void Redraw();
126
127 std::map<VisualizationState*, bool> vis_states;
128
129protected:
130
132 std::map<unsigned int, HuginBase::SrcPanoImage> img_states;
135 // std::map<unsigned int, HuginBase::Lens> lens_states;
136 unsigned int number_of_images;
137 class fbool // a bool that initialises to false.
138 {
139 public:
141 {
142 val = false;
143 }
144 bool val;
145 };
146 // what needs redoing?
148 std::map<unsigned int, bool> active;
149 std::map<unsigned int, fbool> dirty_mask;
151 // reset all the dirty flags.
152 void Clean();
153
154 // this stores all the textures we need.
157};
158
160{
161public:
162
163 template <class M>
165 {
166 m_pano = pano;
167 m_view_state = view_state;
169 refreshArg = arg;
170 dirty_draw = true;
171 dirty_viewport = true;
172 unsigned int number_of_images = m_pano->getNrOfImages();
173 for (unsigned int img = 0; img < number_of_images; img++)
174 {
175 dirty_mesh[img].val = true;
176 }
177 genscale = 0.0;
178 m_mesh_manager = new M(m_pano, this);
179 m_view_state->vis_states[this] = true;
181 m_zoom = 1.0;
182 m_lookAt = hugin_utils::FDiff2D(0.5, 0.5);
183 }
184
185 virtual ~VisualizationState();
186
189 virtual HuginBase::SrcPanoImage *GetSrcImage(unsigned int image_nr);
190
192 virtual void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage * new_img) {}
193
194 // return true if we need to recalculate the mesh
195 bool RequireRecalculateMesh (unsigned int image_nr);
196 // return true if we need to redraw at all
197 bool RequireDraw();
198 // return true if we should check the renderers' viewport
200
201 // the scale is the number of screen pixels per panorama pixel.
202 float GetScale();
203 void SetScale(float scale);
204
205 // stuff used directly for drawing the preview, made accessible for tools.
206 unsigned int GetMeshDisplayList(unsigned int image_nr);
208
209 void FinishedDraw();
210
211 // The visible area is the part of the panarama visible in the view. The
212 // coordinates are in panorama pixels.
213 void SetVisibleArea(vigra::Rect2D area)
214 {
215 /* TODO with zooming, update meshes that were generated with this area
216 * in mind. Zooming changes the scale, which updates the meshes.
217 * Panning on the other hand needs to recalculate meshes as they can
218 * ignore the stuff off-screen
219 */
221 }
222 vigra::Rect2D GetVisibleArea()
223 {
224 return visible_area;
225 }
226
227 double GetZoomLevel() const
228 {
229 return m_zoom;
230 };
231 void SetZoomLevel(const float new_zoom);
233 {
234 return m_lookAt;
235 };
236 void SetViewingCenter(const hugin_utils::FDiff2D& center);
237 void SetCanvasSize(const vigra::Size2D& canvasSize);
238
240
241 // redraw the preview, but only if something has changed.
242 void Redraw();
243
244 // update the meshes and textures as necessary before drawing.
245 void DoUpdates();
246
247 void SetDirtyMesh(int image_nr) {dirty_mesh[image_nr].val = true;}
248 void ForceRequireRedraw();
250
252
253protected:
254
256
257 class fbool // a bool that initialises to false.
258 {
259 public:
261 {
262 val = false;
263 }
264 bool val;
265 };
266 // redoing specific only for a certain visualization
267 std::map<unsigned int, fbool> dirty_mesh;
269
271 vigra::Rect2D visible_area;
273 float m_zoom;
274 vigra::Size2D m_canvasSize;
275 void (*RefreshFunc)(void *);
277
278 // this stores all the meshes we need.
281
283private:
284 // don't copy this class
287};
288
290{
291public:
292 template <class M>
295
296};
297
299{
300public:
301
304
307
308// HuginBase::SrcPanoImage *GetSrcImage(unsigned int image_nr);
309// void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage * new_img );
310
312
313 //camera properties
314 double getAngY() {return angy;}
315 double getAngX() {return angx;}
316 double getR() {return R;}
317 double getFOV() {return fov;}
318 bool isInsideView() { return m_insideView; };
319
321
322 void setAngX(double angx_in);
323 void setAngY(double angy_in);
324 void setR(double r) { R = r; };
325 void setFOV(double newFOV);
326 void setInsideView(bool insideView);
327
328
329protected:
330
331 double angy;
332 double angx;
333 double R;
334 double fov;
336
338
339// std::map<unsigned int, HuginBase::SrcPanoImage> img_states;
342
343
344};
345
347{
348public:
349
352
355
357
358 //camera properties
359 double getR() {return R;}
360 double getFOV() {return fov;}
361 double getX() {return X;}
362 double getY() {return Y;}
363
364 void setR(double r) {R = r;}
365 void setX(double x) {X = x;}
366 void setY(double y) {Y = y;}
367
368protected:
369
370 double X;
371 double Y;
372 double R;
373 double fov;
374
377
378};
379
380#endif
381
A wxWidget to display the fast preview.
Definition GLViewer.h:52
this handler class will receive change events from the Panorama.
Panorama image options.
Model for a panorama.
Definition Panorama.h:153
std::size_t getNrOfImages() const
number of images.
Definition Panorama.h:205
All variables of a source image.
A MeshManager handles the graphics system representation of a remapping, by creating OpenGL display l...
Definition MeshManager.h:38
OverviewVisualizationState(HuginBase::Panorama *pano, ViewState *view_state, GLViewer *viewer, void(*RefreshFunction)(void *), void *arg, M *classArg)
Definition ViewState.h:293
HuginBase::PanoramaOptions opts
Definition ViewState.h:340
HuginBase::PanoramaOptions * GetOptions()
OutputProjectionInfo * GetProjectionInfo()
OutputProjectionInfo * projection_info
Definition ViewState.h:341
void SetOptions(const HuginBase::PanoramaOptions *new_opts)
void setInsideView(bool insideView)
OutputProjectionInfo * projection_info
Definition ViewState.h:376
OutputProjectionInfo * GetProjectionInfo()
HuginBase::PanoramaOptions * GetOptions()
void SetOptions(const HuginBase::PanoramaOptions *new_opts)
HuginBase::PanoramaOptions opts
Definition ViewState.h:375
std::map< unsigned int, fbool > dirty_mask
Definition ViewState.h:149
HuginBase::Panorama * m_pano
Definition ViewState.h:131
void DoUpdates()
TextureManager * m_tex_manager
Definition ViewState.h:155
bool RequireRecalculateMasks(unsigned int image_nr)
bool GetSupportMultiTexture() const
Definition ViewState.h:106
void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage *new_img)
std::map< unsigned int, bool > active
Definition ViewState.h:148
void SetOptions(const HuginBase::PanoramaOptions *new_opts)
bool images_removed
Definition ViewState.h:150
OutputProjectionInfo * GetProjectionInfo()
bool dirty_image_sizes
Definition ViewState.h:150
void panoramaImagesChanged(HuginBase::Panorama &, const HuginBase::UIntSet &)
notifies about changes to images
void ForceRequireRedraw()
HuginBase::PanoramaOptions * GetOptions()
void Clean()
void SetLens(unsigned int lens_nr, HuginBase::Lens *new_lens)
void panoramaChanged(HuginBase::Panorama &pano)
Notification about a Panorama change.
Definition ViewState.cpp:63
HuginBase::PanoramaOptions opts
Definition ViewState.h:133
bool m_multiTexture
Definition ViewState.h:156
HuginBase::SrcPanoImage * GetSrcImage(unsigned int image_nr)
void FinishedDraw()
unsigned int number_of_images
Definition ViewState.h:136
std::map< unsigned int, HuginBase::SrcPanoImage > img_states
Definition ViewState.h:132
bool dirty_photometrics
Definition ViewState.h:147
OutputProjectionInfo * projection_info
Definition ViewState.h:134
std::map< VisualizationState *, bool > vis_states
Definition ViewState.h:127
TextureManager * GetTextureManager()
Definition ViewState.h:104
bool RequireRecalculatePhotometric()
bool RequireRecalculateImageSizes()
bool ImagesRemoved()
void Redraw()
void SetZoomLevel(const float new_zoom)
void SetViewingCenter(const hugin_utils::FDiff2D &center)
HuginBase::Panorama * m_pano
Definition ViewState.h:255
virtual void SetOptions(const HuginBase::PanoramaOptions *new_opts)
Definition ViewState.h:191
MeshManager * GetMeshManager()
Definition ViewState.h:207
vigra::Rect2D GetVisibleArea()
Definition ViewState.h:222
hugin_utils::FDiff2D m_lookAt
Definition ViewState.h:272
virtual void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage *new_img)
Definition ViewState.h:192
void SetScale(float scale)
std::map< unsigned int, fbool > dirty_mesh
Definition ViewState.h:267
ViewState * m_view_state
Definition ViewState.h:280
virtual HuginBase::PanoramaOptions * GetOptions()
vigra::Rect2D visible_area
Definition ViewState.h:271
void(* RefreshFunc)(void *)
Definition ViewState.h:275
vigra::Size2D m_canvasSize
Definition ViewState.h:274
GLViewer * m_viewer
Definition ViewState.h:282
virtual OutputProjectionInfo * GetProjectionInfo()
GLViewer * GetViewer()
Definition ViewState.h:251
bool RequireRecalculateViewport()
void SetDirtyMesh(int image_nr)
Definition ViewState.h:247
unsigned int GetMeshDisplayList(unsigned int image_nr)
virtual HuginBase::SrcPanoImage * GetSrcImage(unsigned int image_nr)
virtual ~VisualizationState()
ViewState * getViewState()
Definition ViewState.h:239
double GetZoomLevel() const
Definition ViewState.h:227
void SetDirtyViewport()
Definition ViewState.h:249
VisualizationState & operator=(const VisualizationState &other)
MeshManager * m_mesh_manager
Definition ViewState.h:279
void SetVisibleArea(vigra::Rect2D area)
Definition ViewState.h:213
void SetCanvasSize(const vigra::Size2D &canvasSize)
hugin_utils::FDiff2D GetViewingCenter() const
Definition ViewState.h:232
VisualizationState(HuginBase::Panorama *pano, ViewState *view_state, GLViewer *viewer, void(*RefreshFunction)(void *), void *arg, M *classArg)
Definition ViewState.h:164
bool RequireRecalculateMesh(unsigned int image_nr)
VisualizationState(const VisualizationState &other)
std::set< unsigned int > UIntSet
TDiff2D< double > FDiff2D
Definition hugin_math.h:162
std::vector< deghosting::BImagePtr > threshold(const std::vector< deghosting::FImagePtr > &inputImages, const double threshold, const uint16_t flags)
Threshold function used for creating alpha masks for images.
Definition threshold.h:41