Added new mesh smoothing algorithm.

This commit is contained in:
David Williams 2009-04-08 22:07:16 +00:00
parent 3c5e2e6202
commit 6d72169e11
5 changed files with 58 additions and 2 deletions

View File

@ -2,6 +2,9 @@
#include <QMouseEvent> #include <QMouseEvent>
#include "GradientEstimators.h"
#include "SurfaceAdjusters.h"
//Some namespaces we need //Some namespaces we need
using namespace std; using namespace std;
using namespace PolyVox; using namespace PolyVox;
@ -56,6 +59,12 @@ void OpenGLWidget::setVolume(PolyVox::Volume<PolyVox::uint8_t>* volData)
//Extract the surface for this region //Extract the surface for this region
extractReferenceSurface(m_volData, PolyVox::Region(regLowerCorner, regUpperCorner), ispCurrent); 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); Vector3DUint8 v3dRegPos(uRegionX,uRegionY,uRegionZ);

View File

@ -55,7 +55,7 @@ namespace PolyVox
int32_t m_iTimeStamp; int32_t m_iTimeStamp;
private: public:
std::vector<uint32_t> m_vecTriangleIndices; std::vector<uint32_t> m_vecTriangleIndices;
std::vector<SurfaceVertex> m_vecVertices; std::vector<SurfaceVertex> m_vecVertices;
}; };

View File

@ -33,6 +33,7 @@ namespace PolyVox
{ {
POLYVOXCORE_API void smoothRegionGeometry(Volume<uint8_t>* volumeData, IndexedSurfacePatch& isp); POLYVOXCORE_API void smoothRegionGeometry(Volume<uint8_t>* volumeData, IndexedSurfacePatch& isp);
POLYVOXCORE_API void adjustDecimatedGeometry(Volume<uint8_t>* volumeData, IndexedSurfacePatch& isp, uint8_t val); POLYVOXCORE_API void adjustDecimatedGeometry(Volume<uint8_t>* volumeData, IndexedSurfacePatch& isp, uint8_t val);
POLYVOXCORE_API IndexedSurfacePatch getSmoothedSurface(IndexedSurfacePatch ispInput);
} }
#endif #endif

View File

@ -44,7 +44,7 @@ namespace PolyVox
std::string tostring(void) const; std::string tostring(void) const;
private: public:
Vector3DFloat position; Vector3DFloat position;
Vector3DFloat normal; Vector3DFloat normal;
float material; float material;

View File

@ -147,4 +147,50 @@ namespace PolyVox
++iterSurfaceVertex; ++iterSurfaceVertex;
} //while(iterSurfaceVertex != vecVertices.end()) } //while(iterSurfaceVertex != vecVertices.end())
} }
IndexedSurfacePatch getSmoothedSurface(IndexedSurfacePatch ispInput)
{
IndexedSurfacePatch ispOutput = ispInput;
for(vector<uint32_t>::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;
}
} }