Hugin trunk 0.1
Loading...
Searching...
No Matches
ProjectionGridTool.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
24#ifdef _WIN32
25#include "wx/msw/wrapwin.h"
26#endif
27#include "hugin_config.h"
28#if defined HAVE_EPOXY && HAVE_EPOXY
29#include <epoxy/gl.h>
30#ifdef __WXMAC__
31#include <OpenGL/glu.h>
32#else
33#include <GL/glu.h>
34#endif
35#else
36#include <GL/glew.h>
37#ifdef __WXMAC__
38#include <OpenGL/gl.h>
39#include <OpenGL/glu.h>
40#else
41#include <GL/gl.h>
42#include <GL/glu.h>
43#endif
44#endif
45#ifdef __APPLE__
46 #include <GLUT/glut.h>
47#endif
48
49
50#include "ProjectionGridTool.h"
51
52// initialize static class members
54unsigned int ProjectionGridTool::texture_num = 0;
55
57{
59}
60
62{
63 if (mesh_info)
64 {
65 delete mesh_info;
66 }
67}
68
74
78
119
127
131
135
137{
138 DEBUG_DEBUG("begin");
139 if (!texture_created)
140 {
141 if (!createTexture())
142 {
143 return;
144 }
145 }
146
147 DEBUG_DEBUG("resources created");
148 glColor4f(1.0f, 1.0f, 1.0f, 0.3f);
153 {
158 }
159 else
160 {
162 };
163
165 // using just a sphere instead of the remapped mesh for better quality
166 glPushMatrix();
167 glRotated(180,1,0,0);
169 GLUquadric* grid = gluNewQuadric();
171
172 glPushMatrix();
173 glScalef(-1,1,1);
174 glRotated(-90,1,0,0);
175 gluSphere(grid, 101,40,20);
176 glPopMatrix();
177
179 glPopMatrix();
180
183 DEBUG_DEBUG("end");
184}
185
187{
188 if (!texture_created)
189 {
190 if (!createTexture())
191 {
192 return;
193 }
194 }
195
196 glColor4f(1,1,1,1);
200 DEBUG_DEBUG("proj grid tex " << texture_num);
202 {
205 }
206 else
207 {
209 };
211
212 //using just a sphere instead of the remapped mesh for better quality
213 glPushMatrix();
214 glRotated(180,1,0,0);
216
217 GLUquadric* grid = gluNewQuadric();
219 glPushMatrix();
220 glScalef(-1,1,1);
221 glRotated(-90,1,0,0);
222 gluSphere(grid, 101,40,20);
223 glPopMatrix();
224
226 glPopMatrix();
227
230
231}
232
234{
236 image.setSize(vigra::Size2D(3600,1780));
237 image.setHFOV(360);
240}
241
246{
248
250 {
253 }
254 else
255 {
257 };
258
259
260 GLint texSize;
262 int width_p = 12;
263 int height_p = 11;
264 int width = std::min(1 << width_p,texSize);
265 int height = std::min(1 << height_p, texSize >> 1);
266
267 int hor_lines = 20;
268 int ver_lines = 40;
269 double line_width_per = 0.02;
270 double dw = width / ver_lines;
271 double dh = height / hor_lines;
272 double line_width = (dw < dh) ? line_width_per * dw : line_width_per * dh;
273
274 GLubyte *image = new GLubyte[width * height * 4];
275 GLubyte *pix_start = image;
276
277 int horLineNr=0;
278 for (int y = 0 ; y < height ; y++)
279 {
280 bool onHorLine=false;
281 if((horLineNr+0.5)*dh-line_width/2.0<y)
282 {
283 if(y<=(horLineNr+0.5)*dh+line_width/2.0)
284 {
285 onHorLine=true;
286 }
287 else
288 {
289 horLineNr++;
290 };
291 };
292 int verLineNr=0;
293 for (int x = 0 ; x < width ; x++)
294 {
295 bool onVerLine=false;
296 if((verLineNr+0.5)*dw-line_width/2.0<x)
297 {
298 if(x<=(verLineNr+0.5)*dw+line_width/2.0)
299 {
300 onVerLine=true;
301 }
302 else
303 {
304 verLineNr++;
305 };
306 };
307
308 if(onHorLine || onVerLine)
309 {
310 pix_start[0]=0;
311 pix_start[1]=255;
312 pix_start[2]=255;
313 pix_start[3]=255;
314 }
315 else
316 {
317 pix_start[0]=255;
318 pix_start[1]=255;
319 pix_start[2]=255;
320 pix_start[3]=0;
321 }
322 pix_start += 4;
323 }
324 }
325
326 bool has_error = false;
327 GLint error;
328 error = gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA8, width, height, GL_RGBA, GL_UNSIGNED_BYTE, image);
329 delete [] image;
330 static bool checked_anisotropic = false;
331 static bool has_anisotropic;
332 static float anisotropy;
334 {
335 // check if it is supported
336#if defined HAVE_EPOXY && HAVE_EPOXY
337 if(epoxy_has_gl_extension("GL_EXT_texture_filter_anisotropic"))
338#else
340#endif
341 {
342 has_anisotropic = true;
344 DEBUG_INFO("Using anisotropic filtering at maximum value "
345 << anisotropy);
346 } else {
347 has_anisotropic = false;
348 DEBUG_INFO("Anisotropic filtering is not available.");
349 }
350 checked_anisotropic = true;
351 }
352 if (has_anisotropic)
353 {
355 anisotropy);
356 }
359
360 if (error)
361 {
362 DEBUG_ERROR("GLU Error when building mipmap levels: "
363 << gluErrorString(error) << ".");
364 has_error = true;
365 }
366 error = glGetError();
367 if (error != GL_NO_ERROR)
368 {
369 DEBUG_ERROR("GL Error when building mipmap levels: "
370 << gluErrorString(error) << ".");
371 has_error = true;
372 }
373 DEBUG_INFO("Finsihed loading texture.");
374 if (has_error) {
375 return false;
376 } else {
377 texture_created = true;
378 return true;
379 }
380}
implementation of PanosphereSphereTool Class
All variables of a source image.
void setSize(vigra::Size2D val)
Set the image size in pixels.
Handles the remapper and a display list for a specific image.
Definition MeshManager.h:65
void CallList() const
Draw the mesh.
void Update()
Recreate the mesh when the image or panorama it represents changes.
void BeforeDrawImagesFrontEvent()
Draw using opengl anything before drawing the back face culled images.
void AfterDrawImagesBackEvent()
Draw using opengl anything after drawing the front face culled images.
void BeforeDrawImagesBackEvent()
Draw using opengl anything before drawing the front face culled images.
void AfterDrawImagesFrontEvent()
Draw using opengl anything after drawing the back face culled images.
void Activate()
Switch on a tool.
void AfterDrawImagesEvent()
Draw (using OpenGL) images above the others.
void BeforeDrawImagesEvent()
Draw using OpenGL anything the tool requires underneath the images.
static unsigned int texture_num
bool createTexture()
create the texture by iterating through each pixela and checking how much each pixel should be filled
ProjectionGridTool(ToolHelper *helper)
MeshManager::MeshInfo * mesh_info
HuginBase::Panorama * GetPanoramaPtr()
void NotifyMe(Event event, Tool *tool)
ViewState * GetViewStatePtr()
VisualizationState * GetVisualizationStatePtr()
@ DRAW_UNDER_IMAGES
Definition ToolHelper.h:82
@ DRAW_OVER_IMAGES
Definition ToolHelper.h:82
ToolHelper * helper
The PreviewToolHelper that uses the same preview window and panorama as the tool should.
Definition Tool.h:109
bool GetSupportMultiTexture() const
Definition ViewState.h:106
#define DEBUG_ERROR(msg)
Definition utils.h:76
#define DEBUG_DEBUG(msg)
Definition utils.h:68
#define DEBUG_INFO(msg)
Definition utils.h:69
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