Hugin trunk 0.1
Loading...
Searching...
No Matches
GLRenderer.cpp
Go to the documentation of this file.
1// -*- c-basic-offset: 4 -*-
23#include <wx/wx.h>
24#include <wx/platform.h>
25
26#ifdef __WXMAC__
27#include <OpenGL/gl.h>
28#include <OpenGL/glu.h>
29#else
30#ifdef __WXMSW__
31#include <vigra/windows.h>
32#endif
33#include <GL/gl.h>
34#include <GL/glu.h>
35
36#endif
37
38#include "hugin_config.h"
39
40#include "panoinc.h"
41
42#include "TextureManager.h"
43#include "MeshManager.h"
44#include "ViewState.h"
45#include "GLRenderer.h"
46#include "GLViewer.h"
47#include "ToolHelper.h"
49
54
59
60void GLRenderer::SetBackground(unsigned char red, unsigned char green, unsigned char blue)
61{
62 glClearColor((float) red / 255.0, (float) green / 255.0, (float) blue / 255.0, 1.0);
63}
64
68
79
90
102
104{
105 width = in_width;
107 glViewport(0, 0, width, height);
108 // notify viewstate about current canvas size,
109 // maybe needed for a changed image center
111 // we use the view_state rather than the panorama to allow interactivity.
113 width_o = options->getWidth();
114 height_o = options->getHeight();
115 double aspect_screen = double(width) / double (height),
119 double scale;
121 {
122 // the panorama is wider than the screen
123 scale = width_o / width;
124 } else {
125 // the screen is wider than the panorama
126 scale = height_o / height;
127 }
128 hugin_utils::FDiff2D center(0.5, 0.5);
130 {
131 // apply scale and translate only when not in layout mode
134 };
135 const hugin_utils::FDiff2D lookAt((center.x - 0.5) * width_o, (center.y - 0.5) * height_o);
136
137 double x_offs = (scale * double(width) - width_o) / 2.0,
138 y_offs = (scale * double(height) - height_o) / 2.0;
139 // set up the projection, so we can use panorama coordinates.
140 glOrtho(-x_offs, width * scale - x_offs,
141 height * scale - y_offs, -y_offs,
142 -1.0, 1.0);
143 glTranslatef(-lookAt.x, -lookAt.y, 0);
144 // scissor to the panorama.
145 glScissor((x_offs-lookAt.x) / scale, (y_offs+lookAt.y) / scale,
146 width_o / scale, height_o / scale);
148 // tell the view state the region we are displaying.
149 // TODO add support for zooming and panning.
150 m_visualization_state->SetVisibleArea(vigra::Rect2D((center.x-0.5) * width_o, (center.y-0.5) * height_o,
151 (0.5 + center.x) * width_o, (0.5 + center.y) * height_o));
152 m_visualization_state->SetScale(1.0 / scale);
153
154 // return the offset from the top left corner of the viewpoer to the top left
155 // corner of the panorama.
156 return vigra::Diff2D(int (x_offs / scale), int (y_offs / scale));
157}
158
160{
164 // background color of flat pano preview
165 glColor3f((float)m_background_color.Red()/255, (float)m_background_color.Green()/255, (float)m_background_color.Blue()/255);
167 glVertex2f(0.0, 0.0);
168 glVertex2f(width_o, 0.0);
170 glVertex2f(0.0, height_o);
171 glEnd();
172 glColor3f(1.0, 1.0, 1.0);
173 // draw things under the preview images
174 // draw each active image.
175 int imgs = m_pano->getNrOfImages();
176 // offset by a half a pixel
177 glPushMatrix();
178 glTranslatef(0.5, 0.5, 0.0);
180 m_tex_man->Begin();
182 // The old preview shows the lowest numbered image on top, so do the same:
183 for (int img = imgs - 1; img != -1; img--)
184 {
185 // only draw active images
186 if (m_pano->getImage(img).getActive())
187 {
188 // the tools can cancel drawing of images.
190 {
191 // the texture manager may need to call the display list
192 // multiple times with blending, so we pass it the display list
193 // rather than switching to the texture and then calling the
194 // list ourselves.
197 }
198 }
199 }
200 m_tex_man->End();
201 // drawn things after the active image.
204 glPopMatrix();
205 // darken the cropped out range, except in layout mode
207 {
210 glColor4f(0.0, 0.0, 0.0, 0.5);
211 // construct a strip of quads, with each pair being one of the corners.
212 const vigra::Rect2D roi = m_visualization_state->getViewState()->GetOptions()->getROI();
214 glVertex2f(0.0, 0.0); glVertex2i(roi.left(), roi.top());
215 glVertex2f(width_o, 0.0); glVertex2i(roi.right(), roi.top());
216 glVertex2f(width_o, height_o); glVertex2i(roi.right(), roi.bottom());
217 glVertex2f(0.0, height_o); glVertex2i(roi.left(), roi.bottom());
218 glVertex2f(0.0, 0.0); glVertex2i(roi.left(), roi.top());
219 glEnd();
220 // draw lines around cropped area.
221 // we want to invert the color to make it stand out.
223 glColor3f(1.0, 1.0, 1.0);
225 glVertex2i(roi.left(), roi.top());
226 glVertex2i(roi.right(), roi.top());
227 glVertex2i(roi.right(), roi.bottom());
228 glVertex2i(roi.left(), roi.bottom());
229 glEnd();
231 };
233
235}
236
237
239{
240 glClearColor(0,0,0,1);
242
244
246
247 double R = m_visualization_state->getR();
248 double angx = m_visualization_state->getAngX();
249 double angy = m_visualization_state->getAngY();
250
252 if (insideView)
253 {
254 gluLookAt(0, 0, 0, R * cos(angy) * cos(angx), R * sin(angy), R * cos(angy) * sin(angx), 0, 1, 0);
255 }
256 else
257 {
258 // view from outside
259 gluLookAt(R * cos(angy) * cos(angx), R * sin(angy), R * cos(angy) * sin(angx), 0, 0, 0, 0, 1, 0);
260 };
261
262 // draw things under the preview images
263 // draw each active image.
264 int imgs = m_pano->getNrOfImages();
265 // offset by a half a pixel
266 glPushMatrix();
267
268 if (!insideView)
269 {
270 //draw the rectangle around the sphere
271 glColor3f(0.5, 0.5, 0.5);
272
273 double side = 150;
275 glVertex3f(-side, side, 0);
276 glVertex3f(side, side, 0);
277 glVertex3f(side, -side, 0);
278 glVertex3f(-side, -side, 0);
279 glEnd();
280
281 //draw the axes, to give a sense of orientation
282 double axis = 200;
284 glColor3f(1, 0, 0);
285 glVertex3f(-axis, 0, 0);
286 glVertex3f(axis, 0, 0);
287
288 glColor3f(0, 1, 0);
289 glVertex3f(0, 0, 0);
290 glVertex3f(0, axis, 0);
291
292 glColor3f(0, 0, 1);
293 glVertex3f(0, 0, 0);
294 glVertex3f(0, 0, axis);
295 glEnd();
296 };
297
299
300 if (insideView)
301 {
302 // in inside view we only need to draw one side of the textures, the other side is not visible at all
303 // but we need also the BeforeDrawImages[Back/Front] because all PanosphereTools were written
304 // for the outside view where back/front textures are used
305 static_cast<PanosphereOverviewToolHelper*>(m_tool_helper)->BeforeDrawImagesBack();
306 m_tex_man->Begin();
308 // The old preview shows the lowest numbered image on top, so do the same:
309 for (int img = imgs - 1; img != -1; img--)
310 {
311 // only draw active images
312 if (m_pano->getImage(img).getActive())
313 {
314 // the tools can cancel drawing of images.
316 {
317 // the texture manager may need to call the display list
318 // multiple times with blending, so we pass it the display list
319 // rather than switching to the texture and then calling the
320 // list ourselves.
323 }
324 }
325 }
326 // drawn things after the active image.
328 m_tex_man->End();
329 static_cast<PanosphereOverviewToolHelper*>(m_tool_helper)->AfterDrawImagesBack();
331 }
332 else
333 {
334 //To avoid z-order fight of the images if depth buffer is used, depth buffer is disabled and meshes are drawn twice,
335 //first with back faces culled so that the inner face of the sphere is visible and below the outter face,
336 //and afterwards the meshes are drawn again with the front faces culled
337
340
341 //event called only before drawing of the images with front faces culled (the inner face of the panosphere)
342 static_cast<PanosphereOverviewToolHelper*>(m_tool_helper)->BeforeDrawImagesBack();
343 //generic draw before images are drawn (called twice with front and back faces culled)
344 m_tex_man->Begin();
346
347 // The old preview shows the lowest numbered image on top, so do the same:
348 for (int img = imgs - 1; img != -1; img--)
349 {
350 // only draw active images
351 if (m_pano->getImage(img).getActive())
352 {
353 // the tools can cancel drawing of images.
355 {
356 // the texture manager may need to call the display list
357 // multiple times with blending, so we pass it the display list
358 // rather than switching to the texture and then calling the
359 // list ourselves.
362 }
363 }
364 }
365
366 m_tex_man->End();
369 static_cast<PanosphereOverviewToolHelper*>(m_tool_helper)->AfterDrawImagesBack();
370
371 // #ifdef __WXGTK__
390 // #endif
391
394
395 static_cast<PanosphereOverviewToolHelper*>(m_tool_helper)->BeforeDrawImagesFront();
396
398 m_tex_man->Begin();
400
401 // The old preview shows the lowest numbered image on top, so do the same:
402 for (int img = imgs - 1; img != -1; img--)
403 {
404 // only draw active images
405 if (m_pano->getImage(img).getActive())
406 {
407 // the tools can cancel drawing of images.
409 {
410 // the texture manager may need to call the display list
411 // multiple times with blending, so we pass it the display list
412 // rather than switching to the texture and then calling the
413 // list ourselves.
416 }
417 }
418 }
419
420 m_tex_man->End();
421 // drawn things after the active image.
424 static_cast<PanosphereOverviewToolHelper*>(m_tool_helper)->AfterDrawImagesFront();
425
427
429 };
430 glPopMatrix();
431}
432
434{
435
436 width = w;
437 height = h;
438 glViewport(0, 0, width, height);
439 // we use the view_state rather than the panorama to allow interactivity.
441 width_o = options->getWidth();
442 height_o = options->getHeight();
443
444 //since gluPerspective needs vertical field of view, depending on the aspect ratio we convert from vertical to horizontal FOV if needed
445 double fov = m_visualization_state->getFOV();
446 double fovy;
447 if (h > w) {
448 fovy = 2.0 * atan( tan(fov * M_PI / 360.0) * (float) h / (float) w) / M_PI * 180.0;
449 } else {
450 fovy = fov;
451 }
452
453 float ratio = 1.0* w / h;
454// aspect = ratio;
457 glViewport(0, 0, w, h);
458 gluPerspective(fovy,ratio,1,1000000);
459
460 m_visualization_state->SetVisibleArea(vigra::Rect2D(0, 0, options->getWidth(),
461 options->getHeight()));
462
464 {
466 }
467 else
468 {
469 //calculate the scale depending on the section of the panosphere in the center of the screen
470 double R = m_visualization_state->getR();
471 double radius = m_visualization_state->getSphereRadius();
472 //height of the screen in screen pixels over the length of the panosphere in panorama pixels when spread out
473 double scrscale = (float)h / (2 * tan(fovy / 360.0 * M_PI) * (R - radius) / (2 * radius * M_PI) * (options->getWidth()));
475 };
477// DEBUG_DEBUG("renderer " << scrscale << " " << h << " " << R << " " << fovy);
478// DEBUG_DEBUG("renderer scale " << scrscale);
479
480// return vigra::Diff2D(w / 2, h / 2);
481 return vigra::Diff2D(0,0);
482
483}
484
486{
487 // background color of mosaic plane
488 glClearColor((float)m_background_color.Red()/255, (float)m_background_color.Green()/255, (float)m_background_color.Blue()/255,1.0);
489
491
493
495
496 double R = m_visualization_state->getR();
497
498 double X = m_visualization_state->getX();
499 double Y = m_visualization_state->getY();
500
501 gluLookAt(X,Y,R, X, Y, 0, 0, 1, 0);
502
503 // draw things under the preview images
505 int imgs = m_pano->getNrOfImages();
506 glPushMatrix();
507
508 glColor3f(0.5,0.5,0.5);
509 double side = 150;
511
512 glVertex3f(-side,side,0);
514 glVertex3f(side,-side,0);
515 glVertex3f(-side,-side,0);
516
517 glEnd();
518
519 double axis = 200;
521
522 glColor3f(1,0,0);
523 glVertex3f(-axis,0,0);
524 glVertex3f(axis,0,0);
525
526 glColor3f(0,1,0);
527 glVertex3f(0,0,0);
528 glVertex3f(0,axis,0);
529
530 glColor3f(0,0,1);
531 glVertex3f(0,0,0);
532 glVertex3f(0,0,axis);
533
534 glEnd();
535
536
538
539 m_tex_man->Begin();
540 // The old preview shows the lowest numbered image on top, so do the same:
541 for (int img = imgs - 1; img != -1; img--)
542 {
543 // only draw active images
544 if (m_pano->getImage(img).getActive())
545 {
546 // the tools can cancel drawing of images.
548 {
549 // the texture manager may need to call the display list
550 // multiple times with blending, so we pass it the display list
551 // rather than switching to the texture and then calling the
552 // list ourselves.
555 }
556 }
557 }
558
559 m_tex_man->End();
561
563
565
567 m_tex_man->Begin();
568
570 // The old preview shows the lowest numbered image on top, so do the same:
571 for (int img = imgs - 1; img != -1; img--)
572 {
573 // only draw active images
574 if (m_pano->getImage(img).getActive())
575 {
576 // the tools can cancel drawing of images.
578 {
579 // the texture manager may need to call the display list
580 // multiple times with blending, so we pass it the display list
581 // rather than switching to the texture and then calling the
582 // list ourselves.
585 }
586 }
587 }
588
589 m_tex_man->End();
590 // drawn things after the active image.
593
594 glPopMatrix();
595}
596
597
598vigra::Diff2D GLPlaneOverviewRenderer::Resize(int w, int h)
599{
600 width = w;
601 height = h;
602 glViewport(0, 0, width, height);
603 // we use the view_state rather than the panorama to allow interactivity.
605 width_o = options->getWidth();
606 height_o = options->getHeight();
607
610
611 double fov = m_visualization_state->getFOV();
612 double fovy;
613 if (h > w) {
614 fovy = 2.0 * atan( tan(fov * M_PI / 360.0) * (float) h / (float) w) / M_PI * 180.0;
615 } else {
616 fovy = fov;
617 }
618
619 float ratio = 1.0* w / h;
620// aspect = ratio;
623 gluPerspective(fovy,ratio,1,1000000);
624
625 m_visualization_state->SetVisibleArea(vigra::Rect2D(0, 0, options->getWidth(),
626 options->getHeight()));
627
628 double R = m_visualization_state->getR();
629 double scrscale = (float) h / (2 * tan(fovy / 360.0 * M_PI) * R * options->getWidth() / MeshManager::PlaneOverviewMeshInfo::scale);
631// m_visualization_state->SetGLScale(gl_scale);
633
634 return vigra::Diff2D(0,0);
635}
636
#define M_PI
GLPanosphereOverviewRenderer(HuginBase::Panorama *pano, TextureManager *tex_man, MeshManager *mesh_man, PanosphereOverviewVisualizationState *visualization_state, PanosphereOverviewToolHelper *tool_helper, const wxColour backgroundColour)
vigra::Diff2D Resize(int width, int height)
Resize the viewport because the window's dimensions have changed.
PanosphereOverviewVisualizationState * m_visualization_state
Definition GLRenderer.h:111
vigra::Diff2D Resize(int width, int height)
Resize the viewport because the window's dimensions have changed.
PlaneOverviewVisualizationState * m_visualization_state
Definition GLRenderer.h:128
GLPlaneOverviewRenderer(HuginBase::Panorama *pano, TextureManager *tex_man, MeshManager *mesh_man, PlaneOverviewVisualizationState *visualization_state, PlaneOverviewToolHelper *tool_helper, const wxColour backgroundColour)
GLPreviewRenderer(HuginBase::Panorama *pano, TextureManager *tex_man, MeshManager *mesh_man, VisualizationState *visualization_state, PreviewToolHelper *tool_helper, const wxColour backgroundColour)
VisualizationState * m_visualization_state
Definition GLRenderer.h:95
vigra::Diff2D Resize(int width, int height)
Resize the viewport because the window's dimensions have changed.
The renderer handles drawing the opengl scene.
Definition GLRenderer.h:48
void SetBackground(unsigned char red, unsigned char green, unsigned char blue)
MeshManager * m_mesh_man
Definition GLRenderer.h:74
GLRenderer(const wxColour backgroundColour)
ctor.
float height_o
Definition GLRenderer.h:67
void SetPreviewBackgroundColor(const wxColour c)
sets the preview background color
wxColour m_background_color
Definition GLRenderer.h:77
ToolHelper * m_tool_helper
Definition GLRenderer.h:75
TextureManager * m_tex_man
Definition GLRenderer.h:73
virtual ~GLRenderer()
dtor.
float width_o
Definition GLRenderer.h:67
HuginBase::Panorama * m_pano
Definition GLRenderer.h:72
void MarkToolsDirty()
Definition GLViewer.cpp:480
Panorama image options.
const vigra::Rect2D & getROI() const
unsigned int getWidth() const
unsigned int getHeight() const
get panorama height
Model for a panorama.
Definition Panorama.h:153
const SrcPanoImage & getImage(std::size_t nr) const
get a panorama image, counting starts with 0
Definition Panorama.h:211
std::size_t getNrOfImages() const
number of images.
Definition Panorama.h:205
A MeshManager handles the graphics system representation of a remapping, by creating OpenGL display l...
Definition MeshManager.h:38
bool GetLayoutMode() const
return if layout mode is active
unsigned int GetDisplayList(unsigned int image_number) const
HuginBase::PanoramaOptions * GetOptions()
void DrawImage(unsigned int image_number, unsigned int display_list)
void DisableTexture(bool maskOnly=false)
bool BeforeDrawImageNumber(unsigned int image)
void BeforeDrawImages()
void AfterDrawImages()
void AfterDrawImageNumber(unsigned int image)
HuginBase::PanoramaOptions * GetOptions()
MeshManager * GetMeshManager()
Definition ViewState.h:207
void SetScale(float scale)
GLViewer * GetViewer()
Definition ViewState.h:251
ViewState * getViewState()
Definition ViewState.h:239
double GetZoomLevel() const
Definition ViewState.h:227
void SetVisibleArea(vigra::Rect2D area)
Definition ViewState.h:213
void SetCanvasSize(const vigra::Size2D &canvasSize)
hugin_utils::FDiff2D GetViewingCenter() const
Definition ViewState.h:232
implementation of huginApp Class
#define DEG_TO_RAD(x)
Definition hugin_math.h:44
double X
double Y
include file for the hugin project
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