diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index 506fb7dc..b0c2440b 100644 --- a/examples/OpenGL/OpenGLWidget.cpp +++ b/examples/OpenGL/OpenGLWidget.cpp @@ -2,6 +2,9 @@ #include +#include "GradientEstimators.h" +#include "SurfaceAdjusters.h" + //Some namespaces we need using namespace std; using namespace PolyVox; @@ -56,6 +59,12 @@ void OpenGLWidget::setVolume(PolyVox::Volume* volData) //Extract the surface for this region extractReferenceSurface(m_volData, PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent); + computeNormalsForVertices(m_volData, *ispCurrent, SOBEL_SMOOTHED); + + //for(int ct = 0; ct < 100; ct++) + //{ + *ispCurrent = getSmoothedSurface(*ispCurrent); + //} Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ); diff --git a/library/PolyVoxCore/include/IndexedSurfacePatch.h b/library/PolyVoxCore/include/IndexedSurfacePatch.h index b005a322..0ae65dad 100644 --- a/library/PolyVoxCore/include/IndexedSurfacePatch.h +++ b/library/PolyVoxCore/include/IndexedSurfacePatch.h @@ -55,7 +55,7 @@ namespace PolyVox int32_t m_iTimeStamp; - private: + public: std::vector m_vecTriangleIndices; std::vector m_vecVertices; }; diff --git a/library/PolyVoxCore/include/SurfaceAdjusters.h b/library/PolyVoxCore/include/SurfaceAdjusters.h index 1aa41675..6bcf79a8 100644 --- a/library/PolyVoxCore/include/SurfaceAdjusters.h +++ b/library/PolyVoxCore/include/SurfaceAdjusters.h @@ -33,6 +33,7 @@ namespace PolyVox { POLYVOXCORE_API void smoothRegionGeometry(Volume* volumeData, IndexedSurfacePatch& isp); POLYVOXCORE_API void adjustDecimatedGeometry(Volume* volumeData, IndexedSurfacePatch& isp, uint8_t val); + POLYVOXCORE_API IndexedSurfacePatch getSmoothedSurface(IndexedSurfacePatch ispInput); } #endif \ No newline at end of file diff --git a/library/PolyVoxCore/include/SurfaceVertex.h b/library/PolyVoxCore/include/SurfaceVertex.h index ff86e115..74a23c34 100644 --- a/library/PolyVoxCore/include/SurfaceVertex.h +++ b/library/PolyVoxCore/include/SurfaceVertex.h @@ -44,7 +44,7 @@ namespace PolyVox std::string tostring(void) const; - private: + public: Vector3DFloat position; Vector3DFloat normal; float material; diff --git a/library/PolyVoxCore/source/SurfaceAdjusters.cpp b/library/PolyVoxCore/source/SurfaceAdjusters.cpp index ea92c753..f1f39e08 100644 --- a/library/PolyVoxCore/source/SurfaceAdjusters.cpp +++ b/library/PolyVoxCore/source/SurfaceAdjusters.cpp @@ -147,4 +147,50 @@ namespace PolyVox ++iterSurfaceVertex; } //while(iterSurfaceVertex != vecVertices.end()) } + + IndexedSurfacePatch getSmoothedSurface(IndexedSurfacePatch ispInput) + { + IndexedSurfacePatch ispOutput = ispInput; + + for(vector::iterator iterIndex = ispInput.m_vecTriangleIndices.begin(); iterIndex != ispInput.m_vecTriangleIndices.end();) + { + SurfaceVertex& v0 = ispOutput.m_vecVertices[*iterIndex]; + iterIndex++; + SurfaceVertex& v1 = ispOutput.m_vecVertices[*iterIndex]; + iterIndex++; + SurfaceVertex& v2 = ispOutput.m_vecVertices[*iterIndex]; + iterIndex++; + + Vector3DFloat v0Opp = (v1.position + v2.position) / 2.0f; + Vector3DFloat v1Opp = (v0.position + v2.position) / 2.0f; + Vector3DFloat v2Opp = (v0.position + v1.position) / 2.0f; + + Vector3DFloat v0ToOpp = v0Opp - v0.position; + v0ToOpp.normalise(); + Vector3DFloat v1ToOpp = v1Opp - v1.position; + v1ToOpp.normalise(); + Vector3DFloat v2ToOpp = v2Opp - v2.position; + v2ToOpp.normalise(); + + Vector3DFloat n0 = v0.getNormal(); + n0.normalise(); + Vector3DFloat n1 = v1.getNormal(); + n1.normalise(); + Vector3DFloat n2 = v2.getNormal(); + n2.normalise(); + + v0.position += (n0 * (n0.dot(v0ToOpp)) * 0.1f); + v1.position += (n1 * (n1.dot(v1ToOpp)) * 0.1f); + v2.position += (n2 * (n2.dot(v2ToOpp)) * 0.1f); + + /*Vector3DFloat triNormal = (v0.getPosition() - v1.getPosition()).cross(v2.getPosition() - v1.getPosition()); + triNormal.normalise(); + + v0.position += (n0 * (triNormal.dot(n0)) * -0.01f); + v1.position += (n1 * (triNormal.dot(n1)) * -0.01f); + v2.position += (n2 * (triNormal.dot(n2)) * -0.01f);*/ + } + + return ispOutput; + } } \ No newline at end of file