From 8fad6bd0391847719fd5bbe3cdbf2bb0781b246c Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 29 Jul 2019 12:29:25 +0100 Subject: [PATCH] Refactored the mesh setup to use GL_TRIANGLE_STIP instead of GL_QUADS --- src/osgVolume/MultipassTechnique.cpp | 61 ++++++++++------------------ src/osgVolume/RayTracedTechnique.cpp | 54 +++++++++--------------- 2 files changed, 40 insertions(+), 75 deletions(-) diff --git a/src/osgVolume/MultipassTechnique.cpp b/src/osgVolume/MultipassTechnique.cpp index 3d5cdc1c2..f1b451867 100644 --- a/src/osgVolume/MultipassTechnique.cpp +++ b/src/osgVolume/MultipassTechnique.cpp @@ -422,62 +422,43 @@ void MultipassTechnique::init() { osg::Geometry* geom = new osg::Geometry; - osg::Vec3Array* coords = new osg::Vec3Array(8); - (*coords)[0] = osg::Vec3d(0.0,0.0,0.0); - (*coords)[1] = osg::Vec3d(1.0,0.0,0.0); - (*coords)[2] = osg::Vec3d(1.0,1.0,0.0); - (*coords)[3] = osg::Vec3d(0.0,1.0,0.0); - (*coords)[4] = osg::Vec3d(0.0,0.0,1.0); - (*coords)[5] = osg::Vec3d(1.0,0.0,1.0); - (*coords)[6] = osg::Vec3d(1.0,1.0,1.0); - (*coords)[7] = osg::Vec3d(0.0,1.0,1.0); - geom->setVertexArray(coords); - osg::Vec4Array* colours = new osg::Vec4Array(1); (*colours)[0].set(1.0f,1.0f,1.0,1.0f); geom->setColorArray(colours, osg::Array::BIND_OVERALL); - osg::DrawElementsUShort* drawElements = new osg::DrawElementsUShort(GL_QUADS); - // bottom + // triangle strip of cube based on : http://www.cs.umd.edu/gvil/papers/av_ts.pdf + osg::Vec3Array* coords = new osg::Vec3Array(8); + (*coords)[0] = osg::Vec3d(0.0,1.0,1.0); // Back-top-left + (*coords)[1] = osg::Vec3d(1.0,1.0,1.0); // Back-top-right + (*coords)[2] = osg::Vec3d(0.0,0.0,1.0); // Front-top-left + (*coords)[3] = osg::Vec3d(1.0,0.0,1.0); // Front-top-right + (*coords)[4] = osg::Vec3d(0.0,1.0,0.0); // Back-bottom-left + (*coords)[5] = osg::Vec3d(1.0,1.0,0.0); // Back-bottom-right + (*coords)[6] = osg::Vec3d(1.0,0.0,0.0); // Front-bottom-right + (*coords)[7] = osg::Vec3d(0.0,0.0,0.0); // Front-bottom-left + geom->setVertexArray(coords); + + osg::DrawElementsUShort* drawElements = new osg::DrawElementsUShort(GL_TRIANGLE_STRIP); + drawElements->push_back(3); drawElements->push_back(2); - drawElements->push_back(1); - drawElements->push_back(0); - - // bottom - drawElements->push_back(7);//7623 drawElements->push_back(6); - drawElements->push_back(2); - drawElements->push_back(3); - - // left - drawElements->push_back(4);//4730 drawElements->push_back(7); - drawElements->push_back(3); - drawElements->push_back(0); - - // right - drawElements->push_back(1);//1265 - drawElements->push_back(2); - drawElements->push_back(6); - drawElements->push_back(5); - - // front - drawElements->push_back(5);//5401 drawElements->push_back(4); + drawElements->push_back(2); drawElements->push_back(0); - drawElements->push_back(1); - // top - drawElements->push_back(4);//4567 - drawElements->push_back(5); + drawElements->push_back(3); + drawElements->push_back(1); drawElements->push_back(6); - drawElements->push_back(7); + drawElements->push_back(5); + drawElements->push_back(4); + drawElements->push_back(1); + drawElements->push_back(0); geom->addPrimitiveSet(drawElements); geode->addDrawable(geom); - } _transform = new osg::MatrixTransform; diff --git a/src/osgVolume/RayTracedTechnique.cpp b/src/osgVolume/RayTracedTechnique.cpp index d49112173..67cab2843 100644 --- a/src/osgVolume/RayTracedTechnique.cpp +++ b/src/osgVolume/RayTracedTechnique.cpp @@ -425,62 +425,46 @@ void RayTracedTechnique::init() { osg::Geometry* geom = new osg::Geometry; - osg::Vec3Array* coords = new osg::Vec3Array(8); - (*coords)[0] = osg::Vec3d(0.0,0.0,0.0); - (*coords)[1] = osg::Vec3d(1.0,0.0,0.0); - (*coords)[2] = osg::Vec3d(1.0,1.0,0.0); - (*coords)[3] = osg::Vec3d(0.0,1.0,0.0); - (*coords)[4] = osg::Vec3d(0.0,0.0,1.0); - (*coords)[5] = osg::Vec3d(1.0,0.0,1.0); - (*coords)[6] = osg::Vec3d(1.0,1.0,1.0); - (*coords)[7] = osg::Vec3d(0.0,1.0,1.0); - geom->setVertexArray(coords); - osg::Vec4Array* colours = new osg::Vec4Array(1); (*colours)[0].set(1.0f,1.0f,1.0,1.0f); geom->setColorArray(colours, osg::Array::BIND_OVERALL); - osg::DrawElementsUShort* drawElements = new osg::DrawElementsUShort(GL_QUADS); - // bottom - drawElements->push_back(0); - drawElements->push_back(1); - drawElements->push_back(2); - drawElements->push_back(3); + // triangle strip of cube based on : http://www.cs.umd.edu/gvil/papers/av_ts.pdf + osg::Vec3Array* coords = new osg::Vec3Array(8); + (*coords)[0] = osg::Vec3d(1.0,1.0,1.0); // Back-top-right + (*coords)[1] = osg::Vec3d(0.0,1.0,1.0); // Back-top-left + (*coords)[2] = osg::Vec3d(1.0,0.0,1.0); // Front-top-right + (*coords)[3] = osg::Vec3d(0.0,0.0,1.0); // Front-top-left + (*coords)[4] = osg::Vec3d(1.0,1.0,0.0); // Back-bottom-right + (*coords)[5] = osg::Vec3d(0.0,1.0,0.0); // Back-bottom-left + (*coords)[6] = osg::Vec3d(0.0,0.0,0.0); // Front-bottom-left + (*coords)[7] = osg::Vec3d(1.0,0.0,0.0); // Front-bottom-right + geom->setVertexArray(coords); + + OSG_NOTICE<<"New RayTracedTechnique"<push_back(3); drawElements->push_back(2); drawElements->push_back(6); drawElements->push_back(7); - - // left - drawElements->push_back(0); - drawElements->push_back(3); - drawElements->push_back(7); drawElements->push_back(4); - - // right - drawElements->push_back(5); - drawElements->push_back(6); drawElements->push_back(2); - drawElements->push_back(1); - - // front - drawElements->push_back(1); drawElements->push_back(0); - drawElements->push_back(4); - drawElements->push_back(5); - // top - drawElements->push_back(7); + drawElements->push_back(3); + drawElements->push_back(1); drawElements->push_back(6); drawElements->push_back(5); drawElements->push_back(4); + drawElements->push_back(1); + drawElements->push_back(0); geom->addPrimitiveSet(drawElements); geode->addDrawable(geom); - } if (cpv._sampleDensityWhenMovingProperty.valid())