Hugin trunk 0.1
Loading...
Searching...
No Matches
TextureManager.h
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
2
23/* a TextureManager sets up openGL textures for each of the input images in a
24 * panorama. It scales images down so they should fit in graphics memory.
25 */
26
27/* Texture sizes must be powers of two. The texture sizes are the biggest size
28 * that does not scale up the input image, or the biggest size supported by the
29 * hardware, whichever is smaller. However, not all of the texture is defined
30 * at any time, so the memory consumption is limited.
31 * The textures are mipmapped, i.e. they use progressivly smaller versions.
32 * The mipmaps are defined in a range from the smallest 1*1 pixel version to
33 * the largest mipmap that doesn't go over the texture space budget. OpenGL
34 * uses mip level 0 to be the original image, and log2(max(width, height)) + 1
35 * to be the smallest 1 by 1 pixel image. We use this convention too.
36 */
37
38#ifndef _TextureManager_h
39#define _TextureManager_h
40
41#include <string>
42#include <map>
43#include <memory>
44#include <huginapp/ImageCache.h>
45#include "panodata/Panorama.h"
46
47//class GLViewer;
48class ViewState;
49
51{
52public:
54 virtual ~TextureManager();
55 // selct the texture for the requested image in opengl
56 void DrawImage(unsigned int image_number, unsigned int display_list);
57 // react to the images & fields of view changing. We can update the
58 // textures here.
59 void CheckUpdate();
60 // change the OpenGL state for rendering the textures.
61 void Begin();
62 void End();
63 // set to true if we are doing photmetric correction
64 void SetPhotometricCorrect(bool state);
65 // return true if we are doing photometric correction.
67 // get the OpneGL texture name for a given image
68 unsigned int GetTextureName(unsigned int image_number);
69 // binds the texture for a given image
70 void BindTexture(unsigned int image_number);
71 // disables the image textures
72 void DisableTexture(bool maskOnly=false);
73 // update the texture when image cache has finished loading
74 void LoadingImageFinished(int min, int max,
77 const HuginBase::SrcPanoImage &state);
78
79protected:
83 // remove textures for deleted images.
84 void CleanTextures();
86 {
87 public:
89 // specify log2(width) and log2(height) for the new texture's size.
90 // this is the size of mip level 0, which may or may not be defined.
91 TextureInfo(ViewState *new_view_state, unsigned int width_p, unsigned int height_p);
93 // width and height are the size of the texture. This can be different
94 // to the image size, we have to scale to powers of two. The texture
95 // size is the biggest we can use for the image without scaling up
96 // (unless the hardware doesn't support textures that big)
97 // we generally have only lower mip levels defined though.
98 unsigned int width, height;
99 // log base 2 of the above, cached.
100 unsigned int width_p, height_p;
101 // min_lod is the most detailed mipmap level defined
103
104 void DefineLevels(int min, int max,
107 const HuginBase::SrcPanoImage &state);
110 void SetMaxLevel(int level);
111 void Bind();
112 void BindImageTexture();
113 void BindMaskTexture();
114 unsigned int GetNumber() {return num;};
115 // if the image has a mask, we want to use alpha blending to draw it.
116 bool GetUseAlpha() {return has_mask;};
118 private:
119 unsigned int num; // the openGL texture name
120 unsigned int numMask; // the openGL texture name for the mask
121 bool has_mask; // this is the alpha channel
122 bool has_active_masks; // has active masks
126 // this binds a new texture in openGL and sets the various parameters
127 // we need for it.
128 void CreateTexture();
129 void SetParameters();
130 };
131
132 // A TextureKey uniquely identifies a texture. It contains the filename
133 // of the image and the photometric correction properties used to make it.
135 {
136 public:
139
140 // TODO all of this lot should probably be made read only
141 std::string filename;
143 std::vector<float> EMoR_params;
144 std::vector<double> radial_vig_corr_coeff;
148 std::vector<double> radial_distortion_red;
149 std::vector<double> radial_distortion_blue;
150 double gamma;
151 std::string masks;
152
153 // when stored in the textures map, this should be set to something that
154 // always indicates if photometric correction comparisons should be made
156 // we need to specify our own comparison function as the photometric
157 // correction parameters do not need to be compared when we are not
158 // using photometric correction.
159 const bool operator==(const TextureKey& comp) const;
160 // we need to be able to order the keys
161 const bool operator<(const TextureKey& comp) const;
162 private:
164 };
165 // we map filenames to TexturesInfos, so we can keep track of
166 // images' textures when the numbers change.
167 typedef std::map<TextureKey, std::shared_ptr<TextureInfo> > TexturesMap;
169 // Our pixel budget for all textures.
170 unsigned int GetMaxTotalTexels();
171 // this is the maximum size a single texture is supported on the hardware.
172 unsigned int GetMaxTextureSizePower();
173 float texel_density; // multiply by angles to get optimal size.
175};
176
177#endif
178
std::shared_ptr< Request > RequestPtr
Reference counted request for an image to load.
Definition ImageCache.h:151
Panorama image options.
Model for a panorama.
Definition Panorama.h:153
All variables of a source image.
void DefineMaskTexture(const HuginBase::SrcPanoImage &srcImg)
HuginBase::ImageCache::RequestPtr m_imageRequest
a request for an image, if it was not loaded before.
void UpdateMask(const HuginBase::SrcPanoImage &srcImg)
void DefineLevels(int min, int max, bool photometric_correct, const HuginBase::PanoramaOptions &dest_img, const HuginBase::SrcPanoImage &state)
const bool operator==(const TextureKey &comp) const
std::vector< float > EMoR_params
void SetOptions(const HuginBase::SrcPanoImage *source)
HuginBase::SrcPanoImage::ResponseType response_type
hugin_utils::FDiff2D radial_vig_corr_center_shift
std::vector< double > radial_vig_corr_coeff
const bool operator<(const TextureKey &comp) const
std::vector< double > radial_distortion_red
std::vector< double > radial_distortion_blue
virtual ~TextureManager()
void BindTexture(unsigned int image_number)
HuginBase::Panorama * m_pano
TexturesMap textures
void DrawImage(unsigned int image_number, unsigned int display_list)
std::map< TextureKey, std::shared_ptr< TextureInfo > > TexturesMap
void LoadingImageFinished(int min, int max, bool texture_photometric_correct, const HuginBase::PanoramaOptions &dest_img, const HuginBase::SrcPanoImage &state)
void SetPhotometricCorrect(bool state)
ViewState * view_state
bool GetPhotometricCorrect()
unsigned int GetTextureName(unsigned int image_number)
unsigned int GetMaxTotalTexels()
void DisableTexture(bool maskOnly=false)
unsigned int GetMaxTextureSizePower()
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