ViewState.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00024 /* A ViewState or VisualizationState holds information about what is visible, the state of the
00025  * various bits of the panorama as it is shown in a preview, and the scaling of
00026  * the preview. The state of the panorama  options and images are stored so
00027  * that we can continuously change properties interactively without bothering
00028  * the real panorama object and therefore the undo / redo history. The classes
00029  * also manages what needs to be recalculated to update the view.
00030  *
00031  * When a change occurs, we examine any differences with our stored state that
00032  * we care about. It doesn't matter if the change is caused by an interactive
00033  * tool or an update to the panorama object.
00034  * If we find a change that makes our preview out of sync, we record what needs
00035  * to be done to bring it up to date. Note some changes do not create any
00036  * difference to the preview, so we don't even want to redraw sometimes.
00037  * After the changes have been made, we can state what needs redoing when asked.
00038  * The texture manager and mesh manager will ask what they need to do.
00039  * After that, any changes we suggested should have been made, and FinishDraw()
00040  * is called. At this point we declare everything is clean and up to date again.
00041  *
00042  * We don't intitiate the calculations ourself when doing things interactively
00043  * so we can group several changes together, e.g. when dragging a group of
00044  * images together SetSrcImage is called for each image but we only want to
00045  * redraw after they have all been moved. However, when the panorama changes
00046  * we want to initiate an update the preview ourself, so all the main GUI
00047  * interactions work.
00048  *
00049  * The information is divided into two classes:
00050  *      -   The first class is the ViewState class which holds information that is 
00051  *          relevant for all Visualizations like the preview, panosphere or plane.
00052  *          This is mainly dominated by the manipulation of the Textures related stuff
00053  *          which are the same for all visualizations.
00054  *          The ViewState also encapsulates all the VisualizationState in itself so that
00055  *          it can properly inform them when any change occurs
00056  *
00057  *      -   The second class is the VisualizationState class which is subclassed for each
00058  *          type of visualization. The VisualizationState class holds information specific
00059  *          to each visualization. This includes the state of the meshes, state of the viewport, etc.
00060  *
00061  */
00062 
00063 #ifndef __VIEWSTATE_H
00064 #define __VIEWSTATE_H
00065 
00066 #include "hugin_utils/utils.h"
00067 #include <panodata/PanoramaData.h>
00068 #include <panodata/Panorama.h>
00069 #include "OutputProjectionInfo.h"
00070 #include <vigra/diff2d.hxx>
00071 #include "TextureManager.h"
00072 #include "MeshManager.h"
00073 
00074 #include <panodata/PanoramaOptions.h>
00075 
00076 class GLViewer;
00077 class VisualizationState;
00078 
00079 
00080 class ViewState : public HuginBase::PanoramaObserver
00081 {
00082 public:
00083     // constructor: we need to know what panorama we deal with.
00084     ViewState(HuginBase::Panorama *pano,  bool supportMultiTexture);
00085     ~ViewState();
00086     // when the real panorama changes, we want to update ourself to reflect it.
00087     // we will force a redraw if anything worthwhile changes.
00088     void panoramaChanged(HuginBase::Panorama &pano);
00089     void panoramaImagesChanged(HuginBase::Panorama&, const HuginBase::UIntSet&);
00090 
00091     // For interactive control, the real panorama does not change. Instead one
00092     // of the following functions will be called:
00093     void SetOptions(const HuginBase::PanoramaOptions *new_opts);
00094     void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage *new_img);
00095     void SetLens(unsigned int lens_nr, HuginBase::Lens *new_lens);
00096     // someone else decides we need to redraw next time around.
00097     void ForceRequireRedraw();
00098     // then we compare with the stored state and set dirty flags as neceassry.
00099     
00100     HuginBase::PanoramaOptions *GetOptions();
00101     OutputProjectionInfo *GetProjectionInfo();
00102     HuginBase::SrcPanoImage *GetSrcImage(unsigned int image_nr);
00103     
00104     TextureManager * GetTextureManager() {return m_tex_manager;}
00105     
00106     bool GetSupportMultiTexture() const { return m_multiTexture; };
00107     // These functions are used to identify what needs to be redone on the next
00108     // redraw.
00109     // return true if we should update a texture's photometric correction
00110     bool RequireRecalculatePhotometric();
00111     // return true if we should check the generated mip levels of the textures
00112     bool RequireRecalculateImageSizes();
00113     // return true if we should update a mask
00114     bool RequireRecalculateMasks(unsigned int image_nr);
00115     // return true if images have been removed
00116     bool ImagesRemoved();
00117     
00118     // this is called when a draw has been performed, so we can assume the
00119     // drawing state (textures, meshes) are now all up to date.
00120     void FinishedDraw();
00121     
00122     // update the meshes and textures as necessary before drawing.
00123     void DoUpdates();
00124 
00125     void Redraw();
00126 
00127     std::map<VisualizationState*, bool> vis_states;
00128 
00129 protected:
00130 
00131     HuginBase::Panorama *m_pano;
00132     std::map<unsigned int, HuginBase::SrcPanoImage> img_states;
00133     HuginBase::PanoramaOptions opts;
00134     OutputProjectionInfo *projection_info;
00135     // std::map<unsigned int, HuginBase::Lens> lens_states;
00136     unsigned int number_of_images;
00137     class fbool // a bool that initialises to false.
00138     {
00139     public:
00140         fbool()
00141         {
00142             val = false;
00143         }
00144         bool val;
00145     };
00146     // what needs redoing?
00147     bool dirty_photometrics;
00148     std::map<unsigned int, bool> active;
00149     std::map<unsigned int, fbool> dirty_mask;
00150     bool dirty_image_sizes, images_removed;
00151     // reset all the dirty flags.
00152     void Clean();
00153     
00154     // this stores all the textures we need.
00155     TextureManager *m_tex_manager;
00156     bool m_multiTexture;
00157 };
00158 
00159 class VisualizationState
00160 {
00161 public:
00162 
00163     template <class M>
00164     VisualizationState(HuginBase::Panorama* pano, ViewState* view_state, GLViewer * viewer, void (*RefreshFunction)(void*), void *arg, M* classArg)
00165     {
00166         m_pano = pano;
00167         m_view_state = view_state;
00168         RefreshFunc = RefreshFunction;
00169         refreshArg = arg;
00170         dirty_draw = true;
00171         dirty_viewport = true;
00172         unsigned int number_of_images = m_pano->getNrOfImages();
00173         for (unsigned int img = 0; img < number_of_images; img++)
00174         {
00175             dirty_mesh[img].val = true;
00176         }
00177         genscale = 0.0;
00178         m_mesh_manager = new M(m_pano, this);
00179         m_view_state->vis_states[this] = true;
00180         m_viewer = viewer;
00181     }
00182 
00183     virtual ~VisualizationState();
00184 
00185     virtual HuginBase::PanoramaOptions *GetOptions();
00186     virtual OutputProjectionInfo *GetProjectionInfo();
00187     virtual HuginBase::SrcPanoImage *GetSrcImage(unsigned int image_nr);
00188 
00189     virtual void SetOptions(const HuginBase::PanoramaOptions *new_opts) {}
00190     virtual void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage * new_img) {}
00191 
00192     // return true if we need to recalculate the mesh
00193     bool RequireRecalculateMesh (unsigned int image_nr);
00194     // return true if we need to redraw at all
00195     bool RequireDraw();
00196     // return true if we should check the renderers' viewport
00197     bool RequireRecalculateViewport();
00198 
00199     // the scale is the number of screen pixels per panorama pixel.
00200     float GetScale();
00201     void SetScale(float scale);
00202 
00203     // stuff used directly for drawing the preview, made accessible for tools.
00204     unsigned int GetMeshDisplayList(unsigned int image_nr);
00205     MeshManager * GetMeshManager() {return m_mesh_manager;}
00206 
00207     void FinishedDraw();
00208 
00209     // The visible area is the part of the panarama visible in the view. The
00210     // coordinates are in panorama pixels.
00211     void SetVisibleArea(vigra::Rect2D area)
00212     {
00213         /* TODO with zooming, update meshes that were generated with this area
00214          * in mind. Zooming changes the scale, which updates the meshes.
00215          * Panning on the other hand needs to recalculate meshes as they can
00216          * ignore the stuff off-screen
00217          */
00218         visible_area = area;
00219     }
00220     vigra::Rect2D GetVisibleArea()
00221     {
00222         return visible_area;
00223     }
00224 
00225     ViewState* getViewState() {return m_view_state;}
00226 
00227     // redraw the preview, but only if something has changed.
00228     void Redraw();
00229 
00230     // update the meshes and textures as necessary before drawing.
00231     void DoUpdates();
00232 
00233     void SetDirtyMesh(int image_nr) {dirty_mesh[image_nr].val = true;}
00234     void ForceRequireRedraw();
00235     void SetDirtyViewport() {dirty_viewport = true;}
00236 
00237     GLViewer * GetViewer() {return m_viewer;}
00238 
00239 protected:
00240 
00241     HuginBase::Panorama *m_pano;
00242 
00243     class fbool // a bool that initialises to false.
00244     {
00245     public:
00246         fbool()
00247         {
00248             val = false;
00249         }
00250         bool val;
00251     };
00252     // redoing specific only for a certain visualization
00253     std::map<unsigned int, fbool> dirty_mesh;
00254     bool dirty_draw, dirty_viewport;
00255 
00256     float scale, genscale, gl_scale;
00257     vigra::Rect2D visible_area;
00258     void (*RefreshFunc)(void *);
00259     void *refreshArg;
00260 
00261     // this stores all the meshes we need.
00262     MeshManager *m_mesh_manager;
00263     ViewState *m_view_state;
00264 
00265     GLViewer * m_viewer;
00266 private:
00267     // don't copy this class
00268     VisualizationState(const VisualizationState& other);
00269     VisualizationState& operator=(const VisualizationState& other);
00270 };
00271 
00272 class OverviewVisualizationState : public VisualizationState
00273 {
00274 public:
00275     template <class M>
00276     OverviewVisualizationState(HuginBase::Panorama* pano, ViewState* view_state, GLViewer * viewer, void(*RefreshFunction)(void*), void *arg, M* classArg)
00277         : VisualizationState(pano, view_state, viewer, RefreshFunction, arg, (M*) classArg) {}
00278 
00279 };
00280 
00281 class PanosphereOverviewVisualizationState : public OverviewVisualizationState
00282 {
00283 public:
00284 
00285     PanosphereOverviewVisualizationState(HuginBase::Panorama* pano, ViewState* view_state, GLViewer * viewer, void(*RefreshFunction)(void*), void *arg);
00286     ~PanosphereOverviewVisualizationState();
00287 
00288     HuginBase::PanoramaOptions *GetOptions();
00289     OutputProjectionInfo *GetProjectionInfo();
00290 
00291 //    HuginBase::SrcPanoImage *GetSrcImage(unsigned int image_nr);
00292 //    void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage * new_img );
00293 
00294     void SetOptions(const HuginBase::PanoramaOptions * new_opts);
00295 
00296     //camera properties
00297     double getAngY() {return angy;}
00298     double getAngX() {return angx;}
00299     double getR() {return R;}
00300     double getFOV() {return fov;}
00301 
00302     double getSphereRadius() {return sphere_radius;}
00303 
00304     void setAngX(double angx_in);
00305     void setAngY(double angy_in);
00306     void setR(double r) {R = r;}
00307 
00308 
00309 protected:
00310 
00311     double angy;
00312     double angx;
00313     double R;
00314     double fov;
00315 
00316     double sphere_radius;
00317 
00318 //    std::map<unsigned int, HuginBase::SrcPanoImage> img_states;
00319     HuginBase::PanoramaOptions opts;
00320     OutputProjectionInfo *projection_info;
00321 
00322 
00323 };
00324 
00325 class PlaneOverviewVisualizationState : public OverviewVisualizationState
00326 {
00327 public:
00328 
00329     PlaneOverviewVisualizationState(HuginBase::Panorama* pano, ViewState* view_state, GLViewer * viewer, void(*RefreshFunction)(void*), void *arg);
00330     ~PlaneOverviewVisualizationState();
00331 
00332     HuginBase::PanoramaOptions *GetOptions();
00333     OutputProjectionInfo *GetProjectionInfo();
00334 
00335     void SetOptions(const HuginBase::PanoramaOptions * new_opts);
00336 
00337     //camera properties
00338     double getR() {return R;}
00339     double getFOV() {return fov;}
00340     double getX() {return X;}
00341     double getY() {return Y;}
00342 
00343     void setR(double r) {R = r;}
00344     void setX(double x) {X = x;}
00345     void setY(double y) {Y = y;}
00346     
00347 protected:
00348 
00349     double X;
00350     double Y;
00351     double R;
00352     double fov;
00353 
00354     HuginBase::PanoramaOptions opts;
00355     OutputProjectionInfo *projection_info;
00356 
00357 };
00358 
00359 #endif
00360 

Generated on 31 Jul 2015 for Hugintrunk by  doxygen 1.4.7