Renamed IndexedSurfacePatch to SurfaceMesh.
This commit is contained in:
@ -22,7 +22,7 @@ freely, subject to the following restrictions:
|
||||
*******************************************************************************/
|
||||
|
||||
#include "GradientEstimators.h"
|
||||
#include "IndexedSurfacePatch.h"
|
||||
#include "SurfaceMesh.h"
|
||||
#include "SurfaceVertex.h"
|
||||
#include "PolyVoxImpl/TypeDef.h"
|
||||
|
||||
@ -30,13 +30,13 @@ using namespace std;
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
void computeNormalsForVertices(Volume<uint8_t>* volumeData, IndexedSurfacePatch& isp, NormalGenerationMethod normalGenerationMethod)
|
||||
void computeNormalsForVertices(Volume<uint8_t>* volumeData, SurfaceMesh& mesh, NormalGenerationMethod normalGenerationMethod)
|
||||
{
|
||||
std::vector<SurfaceVertex>& vecVertices = isp.getRawVertexData();
|
||||
std::vector<SurfaceVertex>& vecVertices = mesh.getRawVertexData();
|
||||
std::vector<SurfaceVertex>::iterator iterSurfaceVertex = vecVertices.begin();
|
||||
while(iterSurfaceVertex != vecVertices.end())
|
||||
{
|
||||
const Vector3DFloat& v3dPos = iterSurfaceVertex->getPosition() + static_cast<Vector3DFloat>(isp.m_Region.getLowerCorner());
|
||||
const Vector3DFloat& v3dPos = iterSurfaceVertex->getPosition() + static_cast<Vector3DFloat>(mesh.m_Region.getLowerCorner());
|
||||
const Vector3DInt16 v3dFloor = static_cast<Vector3DInt16>(v3dPos);
|
||||
|
||||
VolumeSampler<uint8_t> volIter(volumeData);
|
||||
|
@ -25,31 +25,31 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include "Mesh.h"
|
||||
|
||||
#include "IndexedSurfacePatch.h"
|
||||
#include "SurfaceMesh.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
void Mesh::buildFromISP(IndexedSurfacePatch* pIsp)
|
||||
void Mesh::buildFromMesh(SurfaceMesh* pMesh)
|
||||
{
|
||||
//First we copy the vertices across.
|
||||
//We also keep track of where each vertex went
|
||||
std::vector< std::set<MeshVertex*>::iterator > vertexMapper(pIsp->getNoOfVertices());
|
||||
std::vector< std::set<MeshVertex*>::iterator > vertexMapper(pMesh->getNoOfVertices());
|
||||
|
||||
for(int ct = 0; ct < pIsp->getNoOfVertices(); ct++)
|
||||
for(int ct = 0; ct < pMesh->getNoOfVertices(); ct++)
|
||||
{
|
||||
MeshVertex* pMeshVertex = new MeshVertex;
|
||||
pMeshVertex->m_vertexData = pIsp->m_vecVertices[ct];
|
||||
pMeshVertex->m_vertexData = pMesh->m_vecVertices[ct];
|
||||
vertexMapper[ct] = m_vertices.insert(pMeshVertex).first;
|
||||
}
|
||||
|
||||
//Next, we add each triangle to the mesh
|
||||
for(int triCt = 0; triCt < pIsp->getNoOfIndices() / 3; triCt++)
|
||||
for(int triCt = 0; triCt < pMesh->getNoOfIndices() / 3; triCt++)
|
||||
{
|
||||
int index0 = pIsp->m_vecTriangleIndices[triCt * 3];
|
||||
int index1 = pIsp->m_vecTriangleIndices[triCt * 3 + 1];
|
||||
int index2 = pIsp->m_vecTriangleIndices[triCt * 3 + 2];
|
||||
int index0 = pMesh->m_vecTriangleIndices[triCt * 3];
|
||||
int index1 = pMesh->m_vecTriangleIndices[triCt * 3 + 1];
|
||||
int index2 = pMesh->m_vecTriangleIndices[triCt * 3 + 2];
|
||||
|
||||
MeshVertex* meshVertex0 = *(vertexMapper[index0]);
|
||||
MeshVertex* meshVertex1 = *(vertexMapper[index1]);
|
||||
@ -188,14 +188,14 @@ namespace PolyVox
|
||||
}
|
||||
}
|
||||
|
||||
void Mesh::fillISP(IndexedSurfacePatch* pIsp)
|
||||
void Mesh::fillMesh(SurfaceMesh* pMesh)
|
||||
{
|
||||
pIsp->clear();
|
||||
pMesh->clear();
|
||||
|
||||
for(std::set<MeshVertex*>::iterator vertItor = m_vertices.begin(); vertItor != m_vertices.end(); vertItor++)
|
||||
{
|
||||
MeshVertex* meshVertex = *vertItor;
|
||||
meshVertex->m_index = pIsp->addVertex(meshVertex->m_vertexData);
|
||||
meshVertex->m_index = pMesh->addVertex(meshVertex->m_vertexData);
|
||||
}
|
||||
|
||||
for(std::set<MeshFace*>::iterator faceItor = m_faces.begin(); faceItor != m_faces.end(); faceItor++)
|
||||
@ -205,14 +205,14 @@ namespace PolyVox
|
||||
MeshVertex* v1 = meshFace->m_pEdge->m_pNextEdge->m_pSrc;
|
||||
MeshVertex* v2 = meshFace->m_pEdge->m_pNextEdge->m_pNextEdge->m_pSrc;
|
||||
|
||||
pIsp->addTriangle(v0->m_index, v1->m_index, v2->m_index);
|
||||
pMesh->addTriangle(v0->m_index, v1->m_index, v2->m_index);
|
||||
}
|
||||
|
||||
pIsp->m_vecLodRecords.clear();
|
||||
pMesh->m_vecLodRecords.clear();
|
||||
LodRecord lodRecord;
|
||||
lodRecord.beginIndex = 0;
|
||||
lodRecord.endIndex = pIsp->getNoOfIndices();
|
||||
pIsp->m_vecLodRecords.push_back(lodRecord);
|
||||
lodRecord.endIndex = pMesh->getNoOfIndices();
|
||||
pMesh->m_vecLodRecords.push_back(lodRecord);
|
||||
}
|
||||
|
||||
void Mesh::removeEdge(MeshEdge* pMeshEdge)
|
||||
|
@ -23,7 +23,7 @@ freely, subject to the following restrictions:
|
||||
|
||||
#include "SurfaceExtractor.h"
|
||||
|
||||
#include "IndexedSurfacePatch.h"
|
||||
#include "SurfaceMesh.h"
|
||||
#include "PolyVoxImpl/MarchingCubesTables.h"
|
||||
#include "SurfaceVertex.h"
|
||||
|
||||
@ -49,7 +49,7 @@ namespace PolyVox
|
||||
m_uStepSize = 1 << uLodLevel;
|
||||
}
|
||||
|
||||
POLYVOX_SHARED_PTR<IndexedSurfacePatch> SurfaceExtractor::extractSurfaceForRegion(Region region)
|
||||
POLYVOX_SHARED_PTR<SurfaceMesh> SurfaceExtractor::extractSurfaceForRegion(Region region)
|
||||
{
|
||||
m_regInputUncropped = region;
|
||||
|
||||
@ -62,7 +62,7 @@ namespace PolyVox
|
||||
m_regInputCropped = region;
|
||||
m_regInputCropped.cropTo(m_regVolumeCropped);
|
||||
|
||||
m_ispCurrent = new IndexedSurfacePatch();
|
||||
m_meshCurrent = new SurfaceMesh();
|
||||
|
||||
m_uRegionWidth = m_regInputCropped.width();
|
||||
m_uRegionHeight = m_regInputCropped.height();
|
||||
@ -111,15 +111,15 @@ namespace PolyVox
|
||||
delete[] m_pPreviousVertexIndicesZ;
|
||||
delete[] m_pCurrentVertexIndicesZ;
|
||||
|
||||
m_ispCurrent->m_Region = m_regInputUncropped;
|
||||
m_meshCurrent->m_Region = m_regInputUncropped;
|
||||
|
||||
m_ispCurrent->m_vecLodRecords.clear();
|
||||
m_meshCurrent->m_vecLodRecords.clear();
|
||||
LodRecord lodRecord;
|
||||
lodRecord.beginIndex = 0;
|
||||
lodRecord.endIndex = m_ispCurrent->getNoOfIndices();
|
||||
m_ispCurrent->m_vecLodRecords.push_back(lodRecord);
|
||||
lodRecord.endIndex = m_meshCurrent->getNoOfIndices();
|
||||
m_meshCurrent->m_vecLodRecords.push_back(lodRecord);
|
||||
|
||||
return POLYVOX_SHARED_PTR<IndexedSurfacePatch>(m_ispCurrent);
|
||||
return POLYVOX_SHARED_PTR<SurfaceMesh>(m_meshCurrent);
|
||||
}
|
||||
|
||||
template<uint8_t uLodLevel>
|
||||
@ -636,7 +636,7 @@ namespace PolyVox
|
||||
surfaceVertex.setOnGeometryEdgePosY(isPosYEdge);
|
||||
surfaceVertex.setOnGeometryEdgeNegZ(isNegZEdge);
|
||||
surfaceVertex.setOnGeometryEdgePosZ(isPosZEdge);
|
||||
uint32_t uLastVertexIndex = m_ispCurrent->addVertex(surfaceVertex);
|
||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesX[getIndex(uXVolSpace - m_regInputCropped.getLowerCorner().getX(),uYVolSpace - m_regInputCropped.getLowerCorner().getY())] = uLastVertexIndex;
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 8)
|
||||
@ -654,7 +654,7 @@ namespace PolyVox
|
||||
surfaceVertex.setOnGeometryEdgePosY(isPosYEdge);
|
||||
surfaceVertex.setOnGeometryEdgeNegZ(isNegZEdge);
|
||||
surfaceVertex.setOnGeometryEdgePosZ(isPosZEdge);
|
||||
uint32_t uLastVertexIndex = m_ispCurrent->addVertex(surfaceVertex);
|
||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesY[getIndex(uXVolSpace - m_regInputCropped.getLowerCorner().getX(),uYVolSpace - m_regInputCropped.getLowerCorner().getY())] = uLastVertexIndex;
|
||||
}
|
||||
if (edgeTable[iCubeIndex] & 256)
|
||||
@ -672,7 +672,7 @@ namespace PolyVox
|
||||
surfaceVertex.setOnGeometryEdgePosY(isPosYEdge);
|
||||
surfaceVertex.setOnGeometryEdgeNegZ(isNegZEdge);
|
||||
surfaceVertex.setOnGeometryEdgePosZ(isPosZEdge);
|
||||
uint32_t uLastVertexIndex = m_ispCurrent->addVertex(surfaceVertex);
|
||||
uint32_t uLastVertexIndex = m_meshCurrent->addVertex(surfaceVertex);
|
||||
m_pCurrentVertexIndicesZ[getIndex(uXVolSpace - m_regInputCropped.getLowerCorner().getX(),uYVolSpace - m_regInputCropped.getLowerCorner().getY())] = uLastVertexIndex;
|
||||
}
|
||||
}//For each cell
|
||||
@ -785,7 +785,7 @@ namespace PolyVox
|
||||
assert(ind0 < 1000000);
|
||||
assert(ind1 < 1000000);
|
||||
assert(ind2 < 1000000);
|
||||
m_ispCurrent->addTriangle(ind0, ind1, ind2);
|
||||
m_meshCurrent->addTriangle(ind0, ind1, ind2);
|
||||
}
|
||||
}//For each triangle
|
||||
}//For each cell
|
||||
|
@ -23,7 +23,7 @@ freely, subject to the following restrictions:
|
||||
*******************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#include "IndexedSurfacePatch.h"
|
||||
#include "SurfaceMesh.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <list>
|
||||
@ -32,26 +32,26 @@ using namespace std;
|
||||
|
||||
namespace PolyVox
|
||||
{
|
||||
IndexedSurfacePatch::IndexedSurfacePatch()
|
||||
SurfaceMesh::SurfaceMesh()
|
||||
{
|
||||
m_iTimeStamp = -1;
|
||||
}
|
||||
|
||||
IndexedSurfacePatch::~IndexedSurfacePatch()
|
||||
SurfaceMesh::~SurfaceMesh()
|
||||
{
|
||||
}
|
||||
|
||||
const std::vector<uint32_t>& IndexedSurfacePatch::getIndices(void) const
|
||||
const std::vector<uint32_t>& SurfaceMesh::getIndices(void) const
|
||||
{
|
||||
return m_vecTriangleIndices;
|
||||
}
|
||||
|
||||
uint32_t IndexedSurfacePatch::getNoOfIndices(void) const
|
||||
uint32_t SurfaceMesh::getNoOfIndices(void) const
|
||||
{
|
||||
return m_vecTriangleIndices.size();
|
||||
}
|
||||
|
||||
uint32_t IndexedSurfacePatch::getNoOfNonUniformTrianges(void) const
|
||||
uint32_t SurfaceMesh::getNoOfNonUniformTrianges(void) const
|
||||
{
|
||||
uint32_t result = 0;
|
||||
for(uint32_t i = 0; i < m_vecTriangleIndices.size() - 2; i += 3)
|
||||
@ -68,7 +68,7 @@ namespace PolyVox
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t IndexedSurfacePatch::getNoOfUniformTrianges(void) const
|
||||
uint32_t SurfaceMesh::getNoOfUniformTrianges(void) const
|
||||
{
|
||||
uint32_t result = 0;
|
||||
for(uint32_t i = 0; i < m_vecTriangleIndices.size() - 2; i += 3)
|
||||
@ -82,22 +82,22 @@ namespace PolyVox
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t IndexedSurfacePatch::getNoOfVertices(void) const
|
||||
uint32_t SurfaceMesh::getNoOfVertices(void) const
|
||||
{
|
||||
return m_vecVertices.size();
|
||||
}
|
||||
|
||||
std::vector<SurfaceVertex>& IndexedSurfacePatch::getRawVertexData(void)
|
||||
std::vector<SurfaceVertex>& SurfaceMesh::getRawVertexData(void)
|
||||
{
|
||||
return m_vecVertices;
|
||||
}
|
||||
|
||||
const std::vector<SurfaceVertex>& IndexedSurfacePatch::getVertices(void) const
|
||||
const std::vector<SurfaceVertex>& SurfaceMesh::getVertices(void) const
|
||||
{
|
||||
return m_vecVertices;
|
||||
}
|
||||
|
||||
void IndexedSurfacePatch::addTriangle(uint32_t index0, uint32_t index1, uint32_t index2)
|
||||
void SurfaceMesh::addTriangle(uint32_t index0, uint32_t index1, uint32_t index2)
|
||||
{
|
||||
m_vecTriangleIndices.push_back(index0);
|
||||
m_vecTriangleIndices.push_back(index1);
|
||||
@ -115,13 +115,13 @@ namespace PolyVox
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t IndexedSurfacePatch::addVertex(const SurfaceVertex& vertex)
|
||||
uint32_t SurfaceMesh::addVertex(const SurfaceVertex& vertex)
|
||||
{
|
||||
m_vecVertices.push_back(vertex);
|
||||
return m_vecVertices.size() - 1;
|
||||
}
|
||||
|
||||
void IndexedSurfacePatch::clear(void)
|
||||
void SurfaceMesh::clear(void)
|
||||
{
|
||||
m_vecVertices.clear();
|
||||
m_vecTriangleIndices.clear();
|
||||
@ -129,7 +129,7 @@ namespace PolyVox
|
||||
m_mapUsedMaterials.clear();
|
||||
}
|
||||
|
||||
const bool IndexedSurfacePatch::isEmpty(void) const
|
||||
const bool SurfaceMesh::isEmpty(void) const
|
||||
{
|
||||
return (getNoOfVertices() == 0) || (getNoOfIndices() == 0);
|
||||
}
|
||||
@ -142,10 +142,10 @@ namespace PolyVox
|
||||
/// \param fAmount A factor controlling how much the vertices move by. Find a good
|
||||
/// value by experimentation, starting with something small such as 0.1f.
|
||||
/// \param bIncludeGeometryEdgeVertices Indicates whether vertices on the edge of an
|
||||
/// IndexedSurfacePatch should be smoothed. This can cause dicontinuities between
|
||||
/// SurfaceMesh should be smoothed. This can cause dicontinuities between
|
||||
/// neighbouring patches.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void IndexedSurfacePatch::smoothPositions(float fAmount, bool bIncludeGeometryEdgeVertices)
|
||||
void SurfaceMesh::smoothPositions(float fAmount, bool bIncludeGeometryEdgeVertices)
|
||||
{
|
||||
if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise...
|
||||
{
|
||||
@ -221,7 +221,7 @@ namespace PolyVox
|
||||
/// vertex. Usually, the resulting normals should be renormalised afterwards.
|
||||
/// Note: This function can cause lighting discontinuities accross region boundaries.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void IndexedSurfacePatch::sumNearbyNormals(bool bNormaliseResult)
|
||||
void SurfaceMesh::sumNearbyNormals(bool bNormaliseResult)
|
||||
{
|
||||
if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise...
|
||||
{
|
||||
@ -262,7 +262,7 @@ namespace PolyVox
|
||||
}
|
||||
}
|
||||
|
||||
void IndexedSurfacePatch::generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices)
|
||||
void SurfaceMesh::generateAveragedFaceNormals(bool bNormalise, bool bIncludeEdgeVertices)
|
||||
{
|
||||
Vector3DFloat offset = static_cast<Vector3DFloat>(m_Region.getLowerCorner());
|
||||
|
||||
@ -313,7 +313,7 @@ namespace PolyVox
|
||||
|
||||
//This function looks at every vertex in the mesh and determines
|
||||
//how many of it's neighbours have the same material.
|
||||
void IndexedSurfacePatch::countNoOfNeighboursUsingMaterial(void)
|
||||
void SurfaceMesh::countNoOfNeighboursUsingMaterial(void)
|
||||
{
|
||||
//Find all the neighbouring vertices for each vertex
|
||||
std::vector< std::set<int> > neighbouringVertices(m_vecVertices.size());
|
||||
@ -348,9 +348,9 @@ namespace PolyVox
|
||||
}
|
||||
}
|
||||
|
||||
POLYVOX_SHARED_PTR<IndexedSurfacePatch> IndexedSurfacePatch::extractSubset(std::set<uint8_t> setMaterials)
|
||||
POLYVOX_SHARED_PTR<SurfaceMesh> SurfaceMesh::extractSubset(std::set<uint8_t> setMaterials)
|
||||
{
|
||||
POLYVOX_SHARED_PTR<IndexedSurfacePatch> result(new IndexedSurfacePatch);
|
||||
POLYVOX_SHARED_PTR<SurfaceMesh> result(new SurfaceMesh);
|
||||
|
||||
if(m_vecVertices.size() == 0) //FIXME - I don't think we should need this test, but I have seen crashes otherwise...
|
||||
{
|
||||
@ -413,7 +413,7 @@ namespace PolyVox
|
||||
return result;
|
||||
}
|
||||
|
||||
/*int IndexedSurfacePatch::countMaterialBoundary(void)
|
||||
/*int SurfaceMesh::countMaterialBoundary(void)
|
||||
{
|
||||
int count = 0;
|
||||
for(int ct = 0; ct < m_vecVertices.size(); ct++)
|
||||
@ -426,7 +426,7 @@ namespace PolyVox
|
||||
return count;
|
||||
}
|
||||
|
||||
void IndexedSurfacePatch::growMaterialBoundary(void)
|
||||
void SurfaceMesh::growMaterialBoundary(void)
|
||||
{
|
||||
std::vector<SurfaceVertex> vecNewVertices = m_vecVertices;
|
||||
|
||||
@ -453,7 +453,7 @@ namespace PolyVox
|
||||
m_vecVertices = vecNewVertices;
|
||||
}*/
|
||||
|
||||
void IndexedSurfacePatch::decimate(float fMinDotProductForCollapse)
|
||||
void SurfaceMesh::decimate(float fMinDotProductForCollapse)
|
||||
{
|
||||
// We will need the information from this function to
|
||||
// determine when material boundary edges can collapse.
|
||||
@ -475,7 +475,7 @@ namespace PolyVox
|
||||
}
|
||||
|
||||
// Returns true if every bit which is set in 'a' is also set in 'b'. The reverse does not need to be true.
|
||||
bool IndexedSurfacePatch::isSubset(std::bitset<VF_NO_OF_FLAGS> a, std::bitset<VF_NO_OF_FLAGS> b)
|
||||
bool SurfaceMesh::isSubset(std::bitset<VF_NO_OF_FLAGS> a, std::bitset<VF_NO_OF_FLAGS> b)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
@ -494,7 +494,7 @@ namespace PolyVox
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t IndexedSurfacePatch::performDecimationPass(float fMinDotProductForCollapse)
|
||||
uint32_t SurfaceMesh::performDecimationPass(float fMinDotProductForCollapse)
|
||||
{
|
||||
// I'm using a vector of lists here, rather than a vector of sets,
|
||||
// because I don't believe that duplicaes should occur. But this
|
||||
@ -783,7 +783,7 @@ namespace PolyVox
|
||||
return noOfEdgesCollapsed;
|
||||
}
|
||||
|
||||
int IndexedSurfacePatch::noOfDegenerateTris(void)
|
||||
int SurfaceMesh::noOfDegenerateTris(void)
|
||||
{
|
||||
int count = 0;
|
||||
for(int triCt = 0; triCt < m_vecTriangleIndices.size();)
|
||||
@ -803,7 +803,7 @@ namespace PolyVox
|
||||
return count;
|
||||
}
|
||||
|
||||
void IndexedSurfacePatch::removeDegenerateTris(void)
|
||||
void SurfaceMesh::removeDegenerateTris(void)
|
||||
{
|
||||
int noOfNonDegenerate = 0;
|
||||
int targetCt = 0;
|
Reference in New Issue
Block a user