Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages
hugin1/hugin/ViewState.h
Go to the documentation of this file.00001 // -*- c-basic-offset: 4 -*- 00002 00023 /* A ViewState holds information about what is visible, the state of the 00024 * various bits of the panorama as it is shown in a preview, and the scaling of 00025 * the preview. The state of the panorama options and images are stored so 00026 * that we can continuously change properties interactively without bothering 00027 * the real panorama object and therefore the undo / redo history. The ViewState 00028 * also manages what needs to be recalculated to update the view. 00029 * 00030 * When a change occurs, we examine any differences with our stored state that 00031 * we care about. It doesn't matter if the change is caused by an interactive 00032 * tool or an update to the panorama object. 00033 * If we find a change that makes our preview out of sync, we record what needs 00034 * to be done to bring it up to date. Note some changes do not create any 00035 * difference to the preview, so we don't even want to redraw sometimes. 00036 * After the changes have been made, we can state what needs redoing when asked. 00037 * The texture manager and mesh manager will ask what they need to do. 00038 * After that, any changes we suggested should have been made, and FinishDraw() 00039 * is called. At this point we declare everything is clean and up to date again. 00040 * 00041 * We don't intitiate the calculations ourself when doing things interactively 00042 * so we can group several changes together, e.g. when dragging a group of 00043 * images together SetSrcImage is called for each image but we only want to 00044 * redraw after they have all been moved. However, when the panorama changes 00045 * we want to initiate an update the preview ourself, so all the main GUI 00046 * interactions work. 00047 */ 00048 00049 #ifndef __VIEWSTATE_H 00050 #define __VIEWSTATE_H 00051 00052 #include "hugin_utils/utils.h" 00053 #include <panodata/PanoramaData.h> 00054 #include <panodata/Panorama.h> 00055 #include "PT/Panorama.h" 00056 #include "OutputProjectionInfo.h" 00057 #include <vigra/diff2d.hxx> 00058 #include "TextureManager.h" 00059 #include "MeshManager.h" 00060 00061 class ViewState : public HuginBase::PanoramaObserver 00062 { 00063 public: 00064 // constructor: we need to know what panorama we deal with. 00065 ViewState(PT::Panorama *pano, void (*RefreshFunction)(void *), bool supportMultiTexture, void *arg); 00066 ~ViewState(); 00067 // the scale is the number of screen pixels per panorama pixel. 00068 float GetScale(); 00069 void SetScale(float scale); 00070 00071 // when the real panorama changes, we want to update ourself to reflect it. 00072 // we will force a redraw if anything worthwhile changes. 00073 void panoramaChanged(HuginBase::PanoramaData &pano); 00074 void panoramaImagesChanged(HuginBase::PanoramaData&, const HuginBase::UIntSet&); 00075 00076 // For interactive control, the real panorama does not change. Instead one 00077 // of the following functions will be called: 00078 void SetOptions(const HuginBase::PanoramaOptions *new_opts); 00079 void SetSrcImage(unsigned int image_nr, HuginBase::SrcPanoImage *new_img); 00080 void SetLens(unsigned int lens_nr, HuginBase::Lens *new_lens); 00081 // someone else decides we need to redraw next time around. 00082 void ForceRequireRedraw(); 00083 // then we compare with the stored state and set dirty flags as neceassry. 00084 00085 HuginBase::PanoramaOptions *GetOptions(); 00086 OutputProjectionInfo *GetProjectionInfo(); 00087 HuginBase::SrcPanoImage *GetSrcImage(unsigned int image_nr); 00088 00089 // stuff used directly for drawing the preview, made accessible for tools. 00090 unsigned int GetMeshDisplayList(unsigned int image_nr); 00091 MeshManager * GetMeshManager() {return m_mesh_manager;} 00092 TextureManager * GetTextureManager() {return m_tex_manager;} 00093 00094 bool GetSupportMultiTexture() const { return m_multiTexture; }; 00095 // These functions are used to identify what needs to be redone on the next 00096 // redraw. 00097 // return true if we need to recalculate the mesh 00098 bool RequireRecalculateMesh (unsigned int image_nr); 00099 // return true if we should check the generated mip levels of the textures 00100 bool RequireRecalculateImageSizes(); 00101 // return true if we should update a texture's photometric correction 00102 bool RequireRecalculatePhotometric(); 00103 // return true if we should update a mask 00104 bool RequireRecalculateMasks(unsigned int image_nr); 00105 // return true if we need to redraw at all 00106 bool RequireDraw(); 00107 // return true if we should check the renderers' viewport 00108 bool RequireRecalculateViewport(); 00109 // return true if images have been removed 00110 bool ImagesRemoved(); 00111 00112 // this is called when a draw has been performed, so we can assume the 00113 // drawing state (textures, meshes) are now all up to date. 00114 void FinishedDraw(); 00115 00116 // The visible area is the part of the panarama visible in the view. The 00117 // coordinates are in panorama pixels. 00118 void SetVisibleArea(vigra::Rect2D area) 00119 { 00120 /* TODO with zooming, update meshes that were generated with this area 00121 * in mind. Zooming changes the scale, which updates the meshes. 00122 * Panning on the other hand needs to recalculate meshes as they can 00123 * ignore the stuff off-screen 00124 */ 00125 visible_area = area; 00126 } 00127 vigra::Rect2D GetVisibleArea() 00128 { 00129 return visible_area; 00130 } 00131 00132 // redraw the preview, but only if something has changed. 00133 void Redraw(); 00134 // update the meshes and textures as necessary before drawing. 00135 void DoUpdates(); 00136 protected: 00137 PT::Panorama *m_pano; 00138 float scale, genscale; 00139 vigra::Rect2D visible_area; 00140 void (*RefreshFunc)(void *); 00141 void *refreshArg; 00142 std::map<unsigned int, HuginBase::SrcPanoImage> img_states; 00143 HuginBase::PanoramaOptions opts; 00144 OutputProjectionInfo *projection_info; 00145 // std::map<unsigned int, HuginBase::Lens> lens_states; 00146 unsigned int number_of_images; 00147 class fbool // a bool that initialises to false. 00148 { 00149 public: 00150 fbool() 00151 { 00152 val = false; 00153 } 00154 bool val; 00155 }; 00156 // what needs redoing? 00157 bool dirty_photometrics; 00158 std::map<unsigned int, fbool> dirty_mesh; 00159 std::map<unsigned int, fbool> dirty_mask; 00160 std::map<unsigned int, bool> active; 00161 bool dirty_image_sizes, dirty_draw, images_removed, dirty_viewport; 00162 00163 // reset all the dirty flags. 00164 void Clean(); 00165 00166 // this stores all the textures we need. 00167 TextureManager *m_tex_manager; 00168 // this stores all the meshes we need. 00169 MeshManager *m_mesh_manager; 00170 bool m_multiTexture; 00171 }; 00172 00173 #endif 00174
1.3.9.1