Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
67 #include <panodata/PanoramaData.h>
68 #include <panodata/Panorama.h>
69 #include "OutputProjectionInfo.h"
70 #include <vigra/diff2d.hxx>
71 #include "TextureManager.h"
72 #include "MeshManager.h"
73 
75 
76 class GLViewer;
77 class VisualizationState;
78 
79 
81 {
82 public:
83  // constructor: we need to know what panorama we deal with.
84  ViewState(HuginBase::Panorama *pano, bool supportMultiTexture);
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:
93  void SetOptions(const HuginBase::PanoramaOptions *new_opts);
94  void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage *new_img);
95  void SetLens(unsigned int lens_nr, HuginBase::Lens *new_lens);
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 
102  HuginBase::SrcPanoImage *GetSrcImage(unsigned int image_nr);
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 
129 protected:
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 {
161 public:
162 
163  template <class M>
164  VisualizationState(HuginBase::Panorama* pano, ViewState* view_state, GLViewer * viewer, void (*RefreshFunction)(void*), void *arg, M* classArg)
165  {
166  m_pano = pano;
167  m_view_state = view_state;
168  RefreshFunc = RefreshFunction;
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;
180  m_viewer = viewer;
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 
191  virtual void SetOptions(const HuginBase::PanoramaOptions *new_opts) {}
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  */
220  visible_area = area;
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 
253 protected:
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 *);
276  void *refreshArg;
277 
278  // this stores all the meshes we need.
281 
283 private:
284  // don't copy this class
287 };
288 
290 {
291 public:
292  template <class M>
293  OverviewVisualizationState(HuginBase::Panorama* pano, ViewState* view_state, GLViewer * viewer, void(*RefreshFunction)(void*), void *arg, M* classArg)
294  : VisualizationState(pano, view_state, viewer, RefreshFunction, arg, (M*) classArg) {}
295 
296 };
297 
299 {
300 public:
301 
302  PanosphereOverviewVisualizationState(HuginBase::Panorama* pano, ViewState* view_state, GLViewer * viewer, void(*RefreshFunction)(void*), void *arg);
304 
307 
308 // HuginBase::SrcPanoImage *GetSrcImage(unsigned int image_nr);
309 // void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage * new_img );
310 
311  void SetOptions(const HuginBase::PanoramaOptions * new_opts);
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 
320  double getSphereRadius() {return sphere_radius;}
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 
329 protected:
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 {
348 public:
349 
350  PlaneOverviewVisualizationState(HuginBase::Panorama* pano, ViewState* view_state, GLViewer * viewer, void(*RefreshFunction)(void*), void *arg);
352 
355 
356  void SetOptions(const HuginBase::PanoramaOptions * new_opts);
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 
368 protected:
369 
370  double X;
371  double Y;
372  double R;
373  double fov;
374 
377 
378 };
379 
380 #endif
381 
HuginBase::PanoramaOptions opts
Definition: ViewState.h:375
PanosphereOverviewVisualizationState(HuginBase::Panorama *pano, ViewState *view_state, GLViewer *viewer, void(*RefreshFunction)(void *), void *arg)
Definition: ViewState.cpp:524
void SetLens(unsigned int lens_nr, HuginBase::Lens *new_lens)
void SetDirtyMesh(int image_nr)
Definition: ViewState.h:247
void SetScale(float scale)
Definition: ViewState.cpp:378
OutputProjectionInfo * projection_info
Definition: ViewState.h:376
void(* RefreshFunc)(void *)
Definition: ViewState.h:275
hugin_utils::FDiff2D GetViewingCenter() const
Definition: ViewState.h:232
bool dirty_image_sizes
Definition: ViewState.h:150
void Clean()
Definition: ViewState.cpp:330
vigra::Size2D m_canvasSize
Definition: ViewState.h:274
void SetOptions(const HuginBase::PanoramaOptions *new_opts)
Definition: ViewState.cpp:558
std::map< unsigned int, bool > active
Definition: ViewState.h:148
OutputProjectionInfo * GetProjectionInfo()
Definition: ViewState.cpp:278
void SetOptions(const HuginBase::PanoramaOptions *new_opts)
Definition: ViewState.cpp:630
void DoUpdates()
Definition: ViewState.cpp:338
void setInsideView(bool insideView)
Definition: ViewState.cpp:586
void ForceRequireRedraw()
Definition: ViewState.cpp:261
vigra::Rect2D visible_area
Definition: ViewState.h:271
bool dirty_photometrics
Definition: ViewState.h:147
void Redraw()
Definition: ViewState.cpp:345
HuginBase::Panorama * m_pano
Definition: ViewState.h:255
void SetCanvasSize(const vigra::Size2D &canvasSize)
Definition: ViewState.cpp:517
void ForceRequireRedraw()
Definition: ViewState.cpp:439
void FinishedDraw()
Definition: ViewState.cpp:314
VisualizationState & operator=(const VisualizationState &other)
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 panoramaChanged(HuginBase::Panorama &pano)
Notification about a Panorama change.
Definition: ViewState.cpp:63
MeshManager * m_mesh_manager
Definition: ViewState.h:279
double GetZoomLevel() const
Definition: ViewState.h:227
HuginBase::PanoramaOptions * GetOptions()
Definition: ViewState.cpp:273
std::set< unsigned int > UIntSet
Definition: PanoramaData.h:51
HuginBase::PanoramaOptions opts
Definition: ViewState.h:340
GLViewer * m_viewer
Definition: ViewState.h:282
Model for a panorama.
Definition: Panorama.h:152
OutputProjectionInfo * GetProjectionInfo()
Definition: ViewState.cpp:625
void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage *new_img)
Definition: ViewState.cpp:176
bool m_multiTexture
Definition: ViewState.h:156
MeshManager * GetMeshManager()
Definition: ViewState.h:207
virtual HuginBase::SrcPanoImage * GetSrcImage(unsigned int image_nr)
Definition: ViewState.cpp:478
std::size_t getNrOfImages() const
number of images.
Definition: Panorama.h:205
vigra::Rect2D GetVisibleArea()
Definition: ViewState.h:222
std::map< unsigned int, fbool > dirty_mesh
Definition: ViewState.h:267
ViewState * m_view_state
Definition: ViewState.h:280
TextureManager * GetTextureManager()
Definition: ViewState.h:104
virtual void SetOptions(const HuginBase::PanoramaOptions *new_opts)
Definition: ViewState.h:191
HuginBase::Panorama * m_pano
Definition: ViewState.h:131
TDiff2D< double > FDiff2D
Definition: hugin_math.h:150
virtual OutputProjectionInfo * GetProjectionInfo()
Definition: ViewState.cpp:473
bool RequireRecalculateViewport()
Definition: ViewState.cpp:415
ViewState * getViewState()
Definition: ViewState.h:239
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:133
OutputProjectionInfo * GetProjectionInfo()
Definition: ViewState.cpp:553
void SetViewingCenter(const hugin_utils::FDiff2D &center)
Definition: ViewState.cpp:493
PlaneOverviewVisualizationState(HuginBase::Panorama *pano, ViewState *view_state, GLViewer *viewer, void(*RefreshFunction)(void *), void *arg)
Definition: ViewState.cpp:596
A MeshManager handles the graphics system representation of a remapping, by creating OpenGL display l...
Definition: MeshManager.h:37
this handler class will receive change events from the Panorama.
Definition: PanoramaData.h:401
bool RequireRecalculateMesh(unsigned int image_nr)
Definition: ViewState.cpp:420
void SetVisibleArea(vigra::Rect2D area)
Definition: ViewState.h:213
bool RequireRecalculateMasks(unsigned int image_nr)
Definition: ViewState.cpp:304
bool RequireRecalculatePhotometric()
Definition: ViewState.cpp:294
virtual HuginBase::PanoramaOptions * GetOptions()
Definition: ViewState.cpp:468
virtual ~VisualizationState()
Definition: ViewState.cpp:366
void SetOptions(const HuginBase::PanoramaOptions *new_opts)
Definition: ViewState.cpp:120
GLViewer * GetViewer()
Definition: ViewState.h:251
HuginBase::PanoramaOptions * GetOptions()
Definition: ViewState.cpp:620
TextureManager * m_tex_manager
Definition: ViewState.h:155
bool RequireRecalculateImageSizes()
Definition: ViewState.cpp:289
OutputProjectionInfo * projection_info
Definition: ViewState.h:134
void panoramaImagesChanged(HuginBase::Panorama &, const HuginBase::UIntSet &)
notifies about changes to images
Definition: ViewState.cpp:114
bool ImagesRemoved()
Definition: ViewState.cpp:299
std::map< unsigned int, fbool > dirty_mask
Definition: ViewState.h:149
HuginBase::SrcPanoImage * GetSrcImage(unsigned int image_nr)
Definition: ViewState.cpp:283
All variables of a source image.
Definition: SrcPanoImage.h:194
void SetDirtyViewport()
Definition: ViewState.h:249
Panorama image options.
void SetZoomLevel(const float new_zoom)
Definition: ViewState.cpp:483
unsigned int GetMeshDisplayList(unsigned int image_nr)
Definition: ViewState.cpp:462
std::map< VisualizationState *, bool > vis_states
Definition: ViewState.h:127
bool GetSupportMultiTexture() const
Definition: ViewState.h:106
unsigned int number_of_images
Definition: ViewState.h:136
bool images_removed
Definition: ViewState.h:150
A wxWidget to display the fast preview.
Definition: GLViewer.h:51
VisualizationState(HuginBase::Panorama *pano, ViewState *view_state, GLViewer *viewer, void(*RefreshFunction)(void *), void *arg, M *classArg)
Definition: ViewState.h:164
std::map< unsigned int, HuginBase::SrcPanoImage > img_states
Definition: ViewState.h:132
OutputProjectionInfo * projection_info
Definition: ViewState.h:341
HuginBase::PanoramaOptions * GetOptions()
Definition: ViewState.cpp:548
ViewState(HuginBase::Panorama *pano, bool supportMultiTexture)
Definition: ViewState.cpp:32