Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
54 unsigned int ProjectionGridTool::texture_num = 0;
55 
57 {
58  mesh_info = NULL;
59 }
60 
62 {
63  if (mesh_info)
64  {
65  delete mesh_info;
66  }
67 }
68 
70 {
73 }
74 
76 {
77 }
78 
80 {
81  DEBUG_DEBUG("begin");
82  if (!texture_created)
83  {
84  if (!createTexture())
85  {
86  return;
87  }
88  }
89  if (!mesh_info)
90  {
91  createMesh();
92  }
93 
94  mesh_info->Update();
95  glColor4f(1,1,1,1);
96  glEnable( GL_TEXTURE_2D );
97  glEnable(GL_BLEND);
98  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
100  {
101  glActiveTexture(GL_TEXTURE1);
102  glDisable(GL_TEXTURE_2D);
103  glActiveTexture(GL_TEXTURE0);
104  glBindTexture(GL_TEXTURE_2D, texture_num);
105  }
106  else
107  {
108  glBindTexture(GL_TEXTURE_2D, texture_num);
109  };
110  glMatrixMode(GL_TEXTURE);
111  glPushMatrix();
112  glMatrixMode(GL_MODELVIEW);
113  mesh_info->CallList();
114  glMatrixMode(GL_TEXTURE);
115  glPopMatrix();
116  glMatrixMode(GL_MODELVIEW);
117  glDisable(GL_BLEND);
118 }
119 
121 {
126 }
127 
129 {
130 }
131 
133 {
134 }
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);
149  glEnable( GL_TEXTURE_2D );
150  glEnable(GL_BLEND);
151  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
153  {
154  glActiveTexture(GL_TEXTURE1);
155  glDisable(GL_TEXTURE_2D);
156  glActiveTexture(GL_TEXTURE0);
157  glBindTexture(GL_TEXTURE_2D, texture_num);
158  }
159  else
160  {
161  glBindTexture(GL_TEXTURE_2D, texture_num);
162  };
163 
164  glMatrixMode(GL_TEXTURE);
165  // using just a sphere instead of the remapped mesh for better quality
166  glPushMatrix();
167  glRotated(180,1,0,0);
168  glMatrixMode(GL_MODELVIEW);
169  GLUquadric* grid = gluNewQuadric();
170  gluQuadricTexture(grid, GL_TRUE);
171 
172  glPushMatrix();
173  glScalef(-1,1,1);
174  glRotated(-90,1,0,0);
175  gluSphere(grid, 101,40,20);
176  glPopMatrix();
177 
178  glMatrixMode(GL_TEXTURE);
179  glPopMatrix();
180 
181  glDisable(GL_BLEND);
182  glMatrixMode(GL_MODELVIEW);
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);
197  glEnable( GL_TEXTURE_2D );
198  glEnable(GL_BLEND);
199  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
200  DEBUG_DEBUG("proj grid tex " << texture_num);
202  {
203  glActiveTexture(GL_TEXTURE0);
204  glBindTexture(GL_TEXTURE_2D, texture_num);
205  }
206  else
207  {
208  glBindTexture(GL_TEXTURE_2D, texture_num);
209  };
210  glMatrixMode(GL_TEXTURE);
211 
212  //using just a sphere instead of the remapped mesh for better quality
213  glPushMatrix();
214  glRotated(180,1,0,0);
215  glMatrixMode(GL_MODELVIEW);
216 
217  GLUquadric* grid = gluNewQuadric();
218  gluQuadricTexture(grid, GL_TRUE);
219  glPushMatrix();
220  glScalef(-1,1,1);
221  glRotated(-90,1,0,0);
222  gluSphere(grid, 101,40,20);
223  glPopMatrix();
224 
225  glMatrixMode(GL_TEXTURE);
226  glPopMatrix();
227 
228  glDisable(GL_BLEND);
229  glMatrixMode(GL_MODELVIEW);
230 
231 }
232 
234 {
236  image.setSize(vigra::Size2D(3600,1780));
237  image.setHFOV(360);
240 }
241 
246 {
247  glGenTextures(1,(GLuint*) &texture_num);
248 
250  {
251  glActiveTexture(GL_TEXTURE0);
252  glBindTexture(GL_TEXTURE_2D, texture_num);
253  }
254  else
255  {
256  glBindTexture(GL_TEXTURE_2D, texture_num);
257  };
258 
259 
260  GLint texSize;
261  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &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;
333  if (!checked_anisotropic)
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
339  if (GLEW_EXT_texture_filter_anisotropic)
340 #endif
341  {
342  has_anisotropic = true;
343  glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropy);
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  {
354  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,
355  anisotropy);
356  }
357  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
358  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
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 }
#define DEBUG_INFO(msg)
Definition: utils.h:69
static bool texture_created
MeshManager::MeshInfo * mesh_info
ViewState * GetViewStatePtr()
Definition: ToolHelper.cpp:305
void AfterDrawImagesFrontEvent()
Draw using opengl anything after drawing the back face culled images.
void AfterDrawImagesEvent()
Draw (using OpenGL) images above the others.
HuginBase::Panorama * GetPanoramaPtr()
Definition: ToolHelper.cpp:310
void Activate()
Switch on a tool.
void NotifyMe(Event event, Tool *tool)
Definition: ToolHelper.cpp:315
VisualizationState * GetVisualizationStatePtr()
Definition: ToolHelper.cpp:300
void BeforeDrawImagesBackEvent()
Draw using opengl anything before drawing the front face culled images.
ToolHelper * helper
The PreviewToolHelper that uses the same preview window and panorama as the tool should.
Definition: Tool.h:102
void BeforeDrawImagesEvent()
Draw using OpenGL anything the tool requires underneath the images.
bool createTexture()
create the texture by iterating through each pixela and checking how much each pixel should be filled...
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.
implementation of PanosphereSphereTool Class
#define DEBUG_ERROR(msg)
Definition: utils.h:76
ProjectionGridTool(ToolHelper *helper)
void AfterDrawImagesBackEvent()
Draw using opengl anything after drawing the front face culled images.
Handles the remapper and a display list for a specific image.
Definition: MeshManager.h:64
#define DEBUG_DEBUG(msg)
Definition: utils.h:68
void setSize(vigra::Size2D val)
Set the image size in pixels.
static unsigned int texture_num
All variables of a source image.
Definition: SrcPanoImage.h:194
void CallList() const
Draw the mesh.
static T min(T x, T y)
Definition: svm.cpp:62
bool GetSupportMultiTexture() const
Definition: ViewState.h:106