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 informations are 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 "PT/Panorama.h"
00070 #include "OutputProjectionInfo.h"
00071 #include <vigra/diff2d.hxx>
00072 #include "TextureManager.h"
00073 #include "MeshManager.h"
00074 
00075 #include <panodata/PanoramaOptions.h>
00076 
00077 class GLViewer;
00078 class VisualizationState;
00079 
00080 
00081 class ViewState : public HuginBase::PanoramaObserver
00082 {
00083 public:
00084     // constructor: we need to know what panorama we deal with.
00085     ViewState(PT::Panorama *pano,  bool supportMultiTexture);
00086     ~ViewState();
00087     // when the real panorama changes, we want to update ourself to reflect it.
00088     // we will force a redraw if anything worthwhile changes.
00089     void panoramaChanged(HuginBase::PanoramaData &pano);
00090     void panoramaImagesChanged(HuginBase::PanoramaData&, const HuginBase::UIntSet&);
00091 
00092     // For interactive control, the real panorama does not change. Instead one
00093     // of the following functions will be called:
00094     void SetOptions(const HuginBase::PanoramaOptions *new_opts);
00095     void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage *new_img);
00096     void SetLens(unsigned int lens_nr, HuginBase::Lens *new_lens);
00097     // someone else decides we need to redraw next time around.
00098     void ForceRequireRedraw();
00099     // then we compare with the stored state and set dirty flags as neceassry.
00100     
00101     HuginBase::PanoramaOptions *GetOptions();
00102     OutputProjectionInfo *GetProjectionInfo();
00103     HuginBase::SrcPanoImage *GetSrcImage(unsigned int image_nr);
00104     
00105     TextureManager * GetTextureManager() {return m_tex_manager;}
00106     
00107     bool GetSupportMultiTexture() const { return m_multiTexture; };
00108     // These functions are used to identify what needs to be redone on the next
00109     // redraw.
00110     // return true if we should update a texture's photometric correction
00111     bool RequireRecalculatePhotometric();
00112     // return true if we should check the generated mip levels of the textures
00113     bool RequireRecalculateImageSizes();
00114     // return true if we should update a mask
00115     bool RequireRecalculateMasks(unsigned int image_nr);
00116     // return true if images have been removed
00117     bool ImagesRemoved();
00118     
00119     // this is called when a draw has been performed, so we can assume the
00120     // drawing state (textures, meshes) are now all up to date.
00121     void FinishedDraw();
00122     
00123     // update the meshes and textures as necessary before drawing.
00124     void DoUpdates();
00125 
00126     void Redraw();
00127 
00128     std::map<VisualizationState*, bool> vis_states;
00129 
00130 protected:
00131 
00132     PT::Panorama *m_pano;
00133     std::map<unsigned int, HuginBase::SrcPanoImage> img_states;
00134     HuginBase::PanoramaOptions opts;
00135     OutputProjectionInfo *projection_info;
00136     // std::map<unsigned int, HuginBase::Lens> lens_states;
00137     unsigned int number_of_images;
00138     class fbool // a bool that initialises to false.
00139     {
00140     public:
00141         fbool()
00142         {
00143             val = false;
00144         }
00145         bool val;
00146     };
00147     // what needs redoing?
00148     bool dirty_photometrics;
00149     std::map<unsigned int, bool> active;
00150     std::map<unsigned int, fbool> dirty_mask;
00151     bool dirty_image_sizes, images_removed;
00152     // reset all the dirty flags.
00153     void Clean();
00154     
00155     // this stores all the textures we need.
00156     TextureManager *m_tex_manager;
00157     bool m_multiTexture;
00158 };
00159 
00160 class VisualizationState
00161 {
00162 public:
00163 
00164     template <class M>
00165     VisualizationState(PT::Panorama* pano, ViewState* view_state, GLViewer * viewer, void (*RefreshFunction)(void*), void *arg, M* classArg)
00166     {
00167         m_pano = pano;
00168         m_view_state = view_state;
00169         RefreshFunc = RefreshFunction;
00170         refreshArg = arg;
00171         dirty_draw = true;
00172         dirty_viewport = true;
00173         unsigned int number_of_images = m_pano->getNrOfImages();
00174         for (unsigned int img = 0; img < number_of_images; img++)
00175         {
00176             dirty_mesh[img].val = true;
00177         }
00178         genscale = 0.0;
00179         m_mesh_manager = new M(m_pano, this);
00180         m_view_state->vis_states[this] = true;
00181         m_viewer = viewer;
00182     }
00183 
00184     virtual ~VisualizationState();
00185 
00186     virtual HuginBase::PanoramaOptions *GetOptions();
00187     virtual OutputProjectionInfo *GetProjectionInfo();
00188     virtual HuginBase::SrcPanoImage *GetSrcImage(unsigned int image_nr);
00189 
00190     virtual void SetOptions(const HuginBase::PanoramaOptions *new_opts) {}
00191     virtual void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage * new_img) {}
00192 
00193     // return true if we need to recalculate the mesh
00194     bool RequireRecalculateMesh (unsigned int image_nr);
00195     // return true if we need to redraw at all
00196     bool RequireDraw();
00197     // return true if we should check the renderers' viewport
00198     bool RequireRecalculateViewport();
00199 
00200     // the scale is the number of screen pixels per panorama pixel.
00201     float GetScale();
00202     void SetScale(float scale);
00203 
00204     // stuff used directly for drawing the preview, made accessible for tools.
00205     unsigned int GetMeshDisplayList(unsigned int image_nr);
00206     MeshManager * GetMeshManager() {return m_mesh_manager;}
00207 
00208     void FinishedDraw();
00209 
00210     // The visible area is the part of the panarama visible in the view. The
00211     // coordinates are in panorama pixels.
00212     void SetVisibleArea(vigra::Rect2D area)
00213     {
00214         /* TODO with zooming, update meshes that were generated with this area
00215          * in mind. Zooming changes the scale, which updates the meshes.
00216          * Panning on the other hand needs to recalculate meshes as they can
00217          * ignore the stuff off-screen
00218          */
00219         visible_area = area;
00220     }
00221     vigra::Rect2D GetVisibleArea()
00222     {
00223         return visible_area;
00224     }
00225 
00226     ViewState* getViewState() {return m_view_state;}
00227 
00228     // redraw the preview, but only if something has changed.
00229     void Redraw();
00230 
00231     // update the meshes and textures as necessary before drawing.
00232     void DoUpdates();
00233 
00234     void SetDirtyMesh(int image_nr) {dirty_mesh[image_nr].val = true;}
00235     void ForceRequireRedraw();
00236     void SetDirtyViewport() {dirty_viewport = true;}
00237 
00238     GLViewer * GetViewer() {return m_viewer;}
00239 
00240 protected:
00241 
00242     PT::Panorama *m_pano;
00243 
00244     class fbool // a bool that initialises to false.
00245     {
00246     public:
00247         fbool()
00248         {
00249             val = false;
00250         }
00251         bool val;
00252     };
00253     // redoing specific only for a certain visualization
00254     std::map<unsigned int, fbool> dirty_mesh;
00255     bool dirty_draw, dirty_viewport;
00256 
00257     float scale, genscale, gl_scale;
00258     vigra::Rect2D visible_area;
00259     void (*RefreshFunc)(void *);
00260     void *refreshArg;
00261 
00262     // this stores all the meshes we need.
00263     MeshManager *m_mesh_manager;
00264     ViewState *m_view_state;
00265 
00266     GLViewer * m_viewer;
00267 
00268 };
00269 
00270 class OverviewVisualizationState : public VisualizationState
00271 {
00272 public:
00273     template <class M>
00274     OverviewVisualizationState(PT::Panorama* pano, ViewState* view_state, GLViewer * viewer, void (*RefreshFunction)(void*), void *arg, M* classArg)
00275         : VisualizationState(pano, view_state, viewer, RefreshFunction, arg, (M*) classArg) {}
00276 
00277 };
00278 
00279 class PanosphereOverviewVisualizationState : public OverviewVisualizationState
00280 {
00281 public:
00282 
00283     PanosphereOverviewVisualizationState(PT::Panorama* pano, ViewState* view_state, GLViewer * viewer, void (*RefreshFunction)(void*), void *arg);
00284     ~PanosphereOverviewVisualizationState();
00285 
00286     HuginBase::PanoramaOptions *GetOptions();
00287     OutputProjectionInfo *GetProjectionInfo();
00288 
00289 //    HuginBase::SrcPanoImage *GetSrcImage(unsigned int image_nr);
00290 //    void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage * new_img );
00291 
00292     void SetOptions(const HuginBase::PanoramaOptions * new_opts);
00293 
00294     //camera properties
00295     double getAngY() {return angy;}
00296     double getAngX() {return angx;}
00297     double getR() {return R;}
00298     double getFOV() {return fov;}
00299 
00300     double getSphereRadius() {return sphere_radius;}
00301 
00302     void setAngX(double angx_in);
00303     void setAngY(double angy_in);
00304     void setR(double r) {R = r;}
00305 
00306 
00307 protected:
00308 
00309     double angy;
00310     double angx;
00311     double R;
00312     double fov;
00313 
00314     double sphere_radius;
00315 
00316 //    std::map<unsigned int, HuginBase::SrcPanoImage> img_states;
00317     HuginBase::PanoramaOptions opts;
00318     OutputProjectionInfo *projection_info;
00319 
00320 
00321 };
00322 
00323 class PlaneOverviewVisualizationState : public OverviewVisualizationState
00324 {
00325 public:
00326 
00327     PlaneOverviewVisualizationState(PT::Panorama* pano, ViewState* view_state, GLViewer * viewer, void (*RefreshFunction)(void*), void *arg);
00328     ~PlaneOverviewVisualizationState();
00329 
00330     HuginBase::PanoramaOptions *GetOptions();
00331     OutputProjectionInfo *GetProjectionInfo();
00332 
00333     void SetOptions(const HuginBase::PanoramaOptions * new_opts);
00334 
00335     //camera properties
00336     double getR() {return R;}
00337     double getFOV() {return fov;}
00338     double getX() {return X;}
00339     double getY() {return Y;}
00340 
00341     void setR(double r) {R = r;}
00342     void setX(double x) {X = x;}
00343     void setY(double y) {Y = y;}
00344     
00345 protected:
00346 
00347     double X;
00348     double Y;
00349     double R;
00350     double fov;
00351 
00352     HuginBase::PanoramaOptions opts;
00353     OutputProjectionInfo *projection_info;
00354 
00355 };
00356 
00357 #endif
00358 

Generated on Wed Jul 30 01:25:42 2014 for Hugintrunk by  doxygen 1.3.9.1