From f672000458455a83c056ad160d9099db85f0ee53 Mon Sep 17 00:00:00 2001 From: ganovelli Date: Fri, 13 Jan 2017 13:57:33 +0100 Subject: [PATCH] viewport and frustum fixed viewport and frustum --- src/meshlab_mini.pro | 8 +++- .../edit_CADtexturing/CADtexturingedit.cpp | 42 +++++++++++++------ .../edit_CADtexturing/CADtexturingedit.h | 1 + 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/meshlab_mini.pro b/src/meshlab_mini.pro index a82210093..520bf62a7 100644 --- a/src/meshlab_mini.pro +++ b/src/meshlab_mini.pro @@ -13,13 +13,17 @@ CONFIG += ordered SUBDIRS = common \ meshlab \ # the GUI framework meshlabplugins/io_base\ # a few basic file formats (ply, obj, off), without this you cannot open anything - meshlabplugins/filter_meshing \ + meshlabplugins/filter_meshing \ + sampleplugins/sample_filtergpu \ + plugins_experimental/edit_panosample \ + plugins_experimental/edit_CADtexturing \ # # Next some other useful, but still easy to be compiled, plugins # Uncomment them if you succeed in compiling the above ones. # meshlabplugins/decorate_background \ # meshlabplugins/decorate_base \ - meshlabplugins/edit_align \ +# meshlabplugins/edit_align \ + plugins_experimental/edit_panosample \ # meshlabplugins/edit_manipulators \ # meshlabplugins/edit_select \ # meshlabplugins/filter_clean\ diff --git a/src/plugins_experimental/edit_CADtexturing/CADtexturingedit.cpp b/src/plugins_experimental/edit_CADtexturing/CADtexturingedit.cpp index c6fa65d57..acdc54474 100644 --- a/src/plugins_experimental/edit_CADtexturing/CADtexturingedit.cpp +++ b/src/plugins_experimental/edit_CADtexturing/CADtexturingedit.cpp @@ -65,12 +65,26 @@ void CADtexturingEditPlugin::mouseReleaseEvent(QMouseEvent * event, MeshModel &/ //curVertPtr = 0; //pIndex = 0; } -void CADtexturingEditPlugin::renderEdges(GLArea * gla){ - int winsize = 512; - int width = winsize; - int height = winsize; +void CADtexturingEditPlugin::ComputeNearFar(const vcg::Shotf & s,float & nearplane, float & farplane ) +{ + float sx, dx, bt, tp,nr; + s.Intrinsics.GetFrustum(sx, dx, bt, tp, nr); + GLfloat fAspect = fabs((dx - sx) / (tp - bt)); + + vcg::Box3f b = this->meshmodel->cm.bbox; + vcg::Box3f bb; + for (int i = 0; i < 8; ++i) bb.Add(s.ConvertWorldToCameraCoordinates(b.P(i))); + nearplane = bb.min.Z(); + farplane = bb.max.Z(); +} + + + + +void CADtexturingEditPlugin::renderEdges(GLArea * gla){ + //glarea = gla; if (gla->mvc() == NULL) return; @@ -78,17 +92,19 @@ void CADtexturingEditPlugin::renderEdges(GLArea * gla){ if (shared == NULL) return; + vcg::Point2i cp = gla->mvc()->meshDoc.rm()->shot.Intrinsics.ViewportPx; + Context ctx; ctx.acquire(); - RenderbufferHandle hDepth = createRenderbuffer(ctx, GL_DEPTH_COMPONENT24, width, height); - Texture2DHandle hColor = createTexture2D(ctx, GL_RGBA8, width, height, GL_RGBA, GL_UNSIGNED_BYTE); + RenderbufferHandle hDepth = createRenderbuffer(ctx, GL_DEPTH_COMPONENT24, cp[0], cp[1]); + Texture2DHandle hColor = createTexture2D(ctx, GL_RGBA8, cp[0], cp[1], GL_RGBA, GL_UNSIGNED_BYTE); FramebufferHandle hFramebuffer = createFramebuffer(ctx, renderbufferTarget(hDepth), texture2DTarget(hColor)); GLint vp[4]; glGetIntegerv(GL_VIEWPORT, vp); - glViewport(0, 0, winsize, winsize); + glViewport(0, 0, cp[0], cp[1]); ctx.bindReadDrawFramebuffer(hFramebuffer); GLW_CHECK_GL_READ_DRAW_FRAMEBUFFER_STATUS; @@ -98,16 +114,18 @@ void CADtexturingEditPlugin::renderEdges(GLArea * gla){ shared->getRenderInfoPerMeshView(gla->context(), dt); - QImage image(int(width), int(height), QImage::Format_ARGB32); + QImage image(int(cp[0]), int(cp[1]), QImage::Format_ARGB32); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glViewport(0, 0, winsize, winsize); + glViewport(0, 0, cp[0], cp[1]); glPushMatrix(); /* set camera*/ - GlShot::SetView(gla->mvc()->meshDoc.rm()->shot, 1, 10000); + float np, fp; + ComputeNearFar(gla->mvc()->meshDoc.rm()->shot, np, fp); + GlShot::SetView(gla->mvc()->meshDoc.rm()->shot, np,fp); /**/ @@ -143,15 +161,13 @@ void CADtexturingEditPlugin::renderEdges(GLArea * gla){ glDisable(GL_POLYGON_OFFSET_FILL); drawer.DrawWirePolygonal(); - - } } } GlShot::UnsetView(); - glReadPixels(0, 0, winsize, winsize, GL_RGBA, GL_UNSIGNED_BYTE, image.bits()); + glReadPixels(0, 0, cp[0], cp[1], GL_RGBA, GL_UNSIGNED_BYTE, image.bits()); image.rgbSwapped().mirrored().save("edges.jpg"); diff --git a/src/plugins_experimental/edit_CADtexturing/CADtexturingedit.h b/src/plugins_experimental/edit_CADtexturing/CADtexturingedit.h index a266c76fc..27638c18a 100644 --- a/src/plugins_experimental/edit_CADtexturing/CADtexturingedit.h +++ b/src/plugins_experimental/edit_CADtexturing/CADtexturingedit.h @@ -49,6 +49,7 @@ public: void mouseMoveEvent(QMouseEvent *, MeshModel &, GLArea * ) {}; void mouseReleaseEvent(QMouseEvent *event, MeshModel &/*m*/, GLArea * ); void keyReleaseEvent(QKeyEvent *, MeshModel &, GLArea *); + void ComputeNearFar(const vcg::Shotf & s, float & near, float & far); void renderEdges(GLArea *gla); vcg::GlTrimesh drawer;