Code-style consistency improvement:
Apply clang-format-all.sh using the _clang-format file through all the cpp/.h files. make sure not to apply it to certain serialization structures, since some parser expects the * as part of the name, instead of type. This commit contains no other changes aside from adding and applying clang-format-all.sh
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -17,16 +17,16 @@ subject to the following restrictions:
|
||||
|
||||
int gNumAlignedAllocs = 0;
|
||||
int gNumAlignedFree = 0;
|
||||
int gTotalBytesAlignedAllocs = 0; //detect memory leaks
|
||||
int gTotalBytesAlignedAllocs = 0; //detect memory leaks
|
||||
|
||||
static void* btAllocDefault(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
static void btFreeDefault(void* ptr)
|
||||
{
|
||||
free(ptr);
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
static btAllocFunc* sAllocFunc = btAllocDefault;
|
||||
@@ -36,52 +36,55 @@ static btFreeFunc* sFreeFunc = btFreeDefault;
|
||||
#include <malloc.h>
|
||||
static void* btAlignedAllocDefault(size_t size, int alignment)
|
||||
{
|
||||
return _aligned_malloc(size, (size_t)alignment);
|
||||
return _aligned_malloc(size, (size_t)alignment);
|
||||
}
|
||||
|
||||
static void btAlignedFreeDefault(void* ptr)
|
||||
{
|
||||
_aligned_free(ptr);
|
||||
_aligned_free(ptr);
|
||||
}
|
||||
#elif defined(__CELLOS_LV2__)
|
||||
#include <stdlib.h>
|
||||
|
||||
static inline void* btAlignedAllocDefault(size_t size, int alignment)
|
||||
{
|
||||
return memalign(alignment, size);
|
||||
return memalign(alignment, size);
|
||||
}
|
||||
|
||||
static inline void btAlignedFreeDefault(void* ptr)
|
||||
{
|
||||
free(ptr);
|
||||
free(ptr);
|
||||
}
|
||||
#else
|
||||
static inline void* btAlignedAllocDefault(size_t size, int alignment)
|
||||
{
|
||||
void* ret;
|
||||
char* real;
|
||||
unsigned long offset;
|
||||
void* ret;
|
||||
char* real;
|
||||
unsigned long offset;
|
||||
|
||||
real = (char*)sAllocFunc(size + sizeof(void*) + (alignment - 1));
|
||||
if (real) {
|
||||
offset = (alignment - (unsigned long)(real + sizeof(void*))) & (alignment - 1);
|
||||
ret = (void*)((real + sizeof(void*)) + offset);
|
||||
*((void**)(ret)-1) = (void*)(real);
|
||||
}
|
||||
else {
|
||||
ret = (void*)(real);
|
||||
}
|
||||
return (ret);
|
||||
real = (char*)sAllocFunc(size + sizeof(void*) + (alignment - 1));
|
||||
if (real)
|
||||
{
|
||||
offset = (alignment - (unsigned long)(real + sizeof(void*))) & (alignment - 1);
|
||||
ret = (void*)((real + sizeof(void*)) + offset);
|
||||
*((void**)(ret)-1) = (void*)(real);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (void*)(real);
|
||||
}
|
||||
return (ret);
|
||||
}
|
||||
|
||||
static inline void btAlignedFreeDefault(void* ptr)
|
||||
{
|
||||
void* real;
|
||||
void* real;
|
||||
|
||||
if (ptr) {
|
||||
real = *((void**)(ptr)-1);
|
||||
sFreeFunc(real);
|
||||
}
|
||||
if (ptr)
|
||||
{
|
||||
real = *((void**)(ptr)-1);
|
||||
sFreeFunc(real);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -90,14 +93,14 @@ static btAlignedFreeFunc* sAlignedFreeFunc = btAlignedFreeDefault;
|
||||
|
||||
void btAlignedAllocSetCustomAligned(btAlignedAllocFunc* allocFunc, btAlignedFreeFunc* freeFunc)
|
||||
{
|
||||
sAlignedAllocFunc = allocFunc ? allocFunc : btAlignedAllocDefault;
|
||||
sAlignedFreeFunc = freeFunc ? freeFunc : btAlignedFreeDefault;
|
||||
sAlignedAllocFunc = allocFunc ? allocFunc : btAlignedAllocDefault;
|
||||
sAlignedFreeFunc = freeFunc ? freeFunc : btAlignedFreeDefault;
|
||||
}
|
||||
|
||||
void btAlignedAllocSetCustom(btAllocFunc* allocFunc, btFreeFunc* freeFunc)
|
||||
{
|
||||
sAllocFunc = allocFunc ? allocFunc : btAllocDefault;
|
||||
sFreeFunc = freeFunc ? freeFunc : btFreeDefault;
|
||||
sAllocFunc = allocFunc ? allocFunc : btAllocDefault;
|
||||
sFreeFunc = freeFunc ? freeFunc : btFreeDefault;
|
||||
}
|
||||
|
||||
#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
@@ -106,71 +109,75 @@ void btAlignedAllocSetCustom(btAllocFunc* allocFunc, btFreeFunc* freeFunc)
|
||||
|
||||
void* btAlignedAllocInternal(size_t size, int alignment, int line, char* filename)
|
||||
{
|
||||
void* ret;
|
||||
char* real;
|
||||
unsigned long offset;
|
||||
void* ret;
|
||||
char* real;
|
||||
unsigned long offset;
|
||||
|
||||
gTotalBytesAlignedAllocs += size;
|
||||
gNumAlignedAllocs++;
|
||||
gTotalBytesAlignedAllocs += size;
|
||||
gNumAlignedAllocs++;
|
||||
|
||||
real = (char*)sAllocFunc(size + 2 * sizeof(void*) + (alignment - 1));
|
||||
if (real) {
|
||||
offset = (alignment - (unsigned long)(real + 2 * sizeof(void*))) & (alignment - 1);
|
||||
ret = (void*)((real + 2 * sizeof(void*)) + offset);
|
||||
*((void**)(ret)-1) = (void*)(real);
|
||||
*((int*)(ret)-2) = size;
|
||||
}
|
||||
else {
|
||||
ret = (void*)(real); //??
|
||||
}
|
||||
real = (char*)sAllocFunc(size + 2 * sizeof(void*) + (alignment - 1));
|
||||
if (real)
|
||||
{
|
||||
offset = (alignment - (unsigned long)(real + 2 * sizeof(void*))) & (alignment - 1);
|
||||
ret = (void*)((real + 2 * sizeof(void*)) + offset);
|
||||
*((void**)(ret)-1) = (void*)(real);
|
||||
*((int*)(ret)-2) = size;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = (void*)(real); //??
|
||||
}
|
||||
|
||||
printf("allocation#%d at address %x, from %s,line %d, size %d\n", gNumAlignedAllocs, real, filename, line, size);
|
||||
printf("allocation#%d at address %x, from %s,line %d, size %d\n", gNumAlignedAllocs, real, filename, line, size);
|
||||
|
||||
int* ptr = (int*)ret;
|
||||
*ptr = 12;
|
||||
return (ret);
|
||||
int* ptr = (int*)ret;
|
||||
*ptr = 12;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void btAlignedFreeInternal(void* ptr, int line, char* filename)
|
||||
{
|
||||
void* real;
|
||||
gNumAlignedFree++;
|
||||
|
||||
void* real;
|
||||
gNumAlignedFree++;
|
||||
if (ptr)
|
||||
{
|
||||
real = *((void**)(ptr)-1);
|
||||
int size = *((int*)(ptr)-2);
|
||||
gTotalBytesAlignedAllocs -= size;
|
||||
|
||||
if (ptr) {
|
||||
real = *((void**)(ptr)-1);
|
||||
int size = *((int*)(ptr)-2);
|
||||
gTotalBytesAlignedAllocs -= size;
|
||||
printf("free #%d at address %x, from %s,line %d, size %d\n", gNumAlignedFree, real, filename, line, size);
|
||||
|
||||
printf("free #%d at address %x, from %s,line %d, size %d\n", gNumAlignedFree, real, filename, line, size);
|
||||
|
||||
sFreeFunc(real);
|
||||
}
|
||||
else {
|
||||
printf("NULL ptr\n");
|
||||
}
|
||||
sFreeFunc(real);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("NULL ptr\n");
|
||||
}
|
||||
}
|
||||
|
||||
#else //BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
#else //BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
|
||||
void* btAlignedAllocInternal(size_t size, int alignment)
|
||||
{
|
||||
gNumAlignedAllocs++;
|
||||
void* ptr;
|
||||
ptr = sAlignedAllocFunc(size, alignment);
|
||||
// printf("btAlignedAllocInternal %d, %x\n",size,ptr);
|
||||
return ptr;
|
||||
gNumAlignedAllocs++;
|
||||
void* ptr;
|
||||
ptr = sAlignedAllocFunc(size, alignment);
|
||||
// printf("btAlignedAllocInternal %d, %x\n",size,ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void btAlignedFreeInternal(void* ptr)
|
||||
{
|
||||
if (!ptr) {
|
||||
return;
|
||||
}
|
||||
if (!ptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
gNumAlignedFree++;
|
||||
// printf("btAlignedFreeInternal %x\n",ptr);
|
||||
sAlignedFreeFunc(ptr);
|
||||
gNumAlignedFree++;
|
||||
// printf("btAlignedFreeInternal %x\n",ptr);
|
||||
sAlignedFreeFunc(ptr);
|
||||
}
|
||||
|
||||
#endif //BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
#endif //BT_DEBUG_MEMORY_ALLOCATIONS
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -13,18 +13,19 @@
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include "vhacdManifoldMesh.h"
|
||||
namespace VHACD {
|
||||
namespace VHACD
|
||||
{
|
||||
TMMVertex::TMMVertex(void)
|
||||
{
|
||||
Initialize();
|
||||
Initialize();
|
||||
}
|
||||
void TMMVertex::Initialize()
|
||||
{
|
||||
m_name = 0;
|
||||
m_id = 0;
|
||||
m_duplicate = 0;
|
||||
m_onHull = false;
|
||||
m_tag = false;
|
||||
m_name = 0;
|
||||
m_id = 0;
|
||||
m_duplicate = 0;
|
||||
m_onHull = false;
|
||||
m_tag = false;
|
||||
}
|
||||
|
||||
TMMVertex::~TMMVertex(void)
|
||||
@@ -32,29 +33,30 @@ TMMVertex::~TMMVertex(void)
|
||||
}
|
||||
TMMEdge::TMMEdge(void)
|
||||
{
|
||||
Initialize();
|
||||
Initialize();
|
||||
}
|
||||
void TMMEdge::Initialize()
|
||||
{
|
||||
m_id = 0;
|
||||
m_triangles[0] = m_triangles[1] = m_newFace = 0;
|
||||
m_vertices[0] = m_vertices[1] = 0;
|
||||
m_id = 0;
|
||||
m_triangles[0] = m_triangles[1] = m_newFace = 0;
|
||||
m_vertices[0] = m_vertices[1] = 0;
|
||||
}
|
||||
TMMEdge::~TMMEdge(void)
|
||||
{
|
||||
}
|
||||
void TMMTriangle::Initialize()
|
||||
{
|
||||
m_id = 0;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
m_edges[i] = 0;
|
||||
m_vertices[0] = 0;
|
||||
}
|
||||
m_visible = false;
|
||||
m_id = 0;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
m_edges[i] = 0;
|
||||
m_vertices[0] = 0;
|
||||
}
|
||||
m_visible = false;
|
||||
}
|
||||
TMMTriangle::TMMTriangle(void)
|
||||
{
|
||||
Initialize();
|
||||
Initialize();
|
||||
}
|
||||
TMMTriangle::~TMMTriangle(void)
|
||||
{
|
||||
@@ -67,136 +69,167 @@ TMMesh::~TMMesh(void)
|
||||
}
|
||||
void TMMesh::GetIFS(Vec3<double>* const points, Vec3<int>* const triangles)
|
||||
{
|
||||
size_t nV = m_vertices.GetSize();
|
||||
size_t nT = m_triangles.GetSize();
|
||||
size_t nV = m_vertices.GetSize();
|
||||
size_t nT = m_triangles.GetSize();
|
||||
|
||||
for (size_t v = 0; v < nV; v++) {
|
||||
points[v] = m_vertices.GetData().m_pos;
|
||||
m_vertices.GetData().m_id = v;
|
||||
m_vertices.Next();
|
||||
}
|
||||
for (size_t f = 0; f < nT; f++) {
|
||||
TMMTriangle& currentTriangle = m_triangles.GetData();
|
||||
triangles[f].X() = static_cast<int>(currentTriangle.m_vertices[0]->GetData().m_id);
|
||||
triangles[f].Y() = static_cast<int>(currentTriangle.m_vertices[1]->GetData().m_id);
|
||||
triangles[f].Z() = static_cast<int>(currentTriangle.m_vertices[2]->GetData().m_id);
|
||||
m_triangles.Next();
|
||||
}
|
||||
for (size_t v = 0; v < nV; v++)
|
||||
{
|
||||
points[v] = m_vertices.GetData().m_pos;
|
||||
m_vertices.GetData().m_id = v;
|
||||
m_vertices.Next();
|
||||
}
|
||||
for (size_t f = 0; f < nT; f++)
|
||||
{
|
||||
TMMTriangle& currentTriangle = m_triangles.GetData();
|
||||
triangles[f].X() = static_cast<int>(currentTriangle.m_vertices[0]->GetData().m_id);
|
||||
triangles[f].Y() = static_cast<int>(currentTriangle.m_vertices[1]->GetData().m_id);
|
||||
triangles[f].Z() = static_cast<int>(currentTriangle.m_vertices[2]->GetData().m_id);
|
||||
m_triangles.Next();
|
||||
}
|
||||
}
|
||||
void TMMesh::Clear()
|
||||
{
|
||||
m_vertices.Clear();
|
||||
m_edges.Clear();
|
||||
m_triangles.Clear();
|
||||
m_vertices.Clear();
|
||||
m_edges.Clear();
|
||||
m_triangles.Clear();
|
||||
}
|
||||
void TMMesh::Copy(TMMesh& mesh)
|
||||
{
|
||||
Clear();
|
||||
// updating the id's
|
||||
size_t nV = mesh.m_vertices.GetSize();
|
||||
size_t nE = mesh.m_edges.GetSize();
|
||||
size_t nT = mesh.m_triangles.GetSize();
|
||||
for (size_t v = 0; v < nV; v++) {
|
||||
mesh.m_vertices.GetData().m_id = v;
|
||||
mesh.m_vertices.Next();
|
||||
}
|
||||
for (size_t e = 0; e < nE; e++) {
|
||||
mesh.m_edges.GetData().m_id = e;
|
||||
mesh.m_edges.Next();
|
||||
}
|
||||
for (size_t f = 0; f < nT; f++) {
|
||||
mesh.m_triangles.GetData().m_id = f;
|
||||
mesh.m_triangles.Next();
|
||||
}
|
||||
// copying data
|
||||
m_vertices = mesh.m_vertices;
|
||||
m_edges = mesh.m_edges;
|
||||
m_triangles = mesh.m_triangles;
|
||||
Clear();
|
||||
// updating the id's
|
||||
size_t nV = mesh.m_vertices.GetSize();
|
||||
size_t nE = mesh.m_edges.GetSize();
|
||||
size_t nT = mesh.m_triangles.GetSize();
|
||||
for (size_t v = 0; v < nV; v++)
|
||||
{
|
||||
mesh.m_vertices.GetData().m_id = v;
|
||||
mesh.m_vertices.Next();
|
||||
}
|
||||
for (size_t e = 0; e < nE; e++)
|
||||
{
|
||||
mesh.m_edges.GetData().m_id = e;
|
||||
mesh.m_edges.Next();
|
||||
}
|
||||
for (size_t f = 0; f < nT; f++)
|
||||
{
|
||||
mesh.m_triangles.GetData().m_id = f;
|
||||
mesh.m_triangles.Next();
|
||||
}
|
||||
// copying data
|
||||
m_vertices = mesh.m_vertices;
|
||||
m_edges = mesh.m_edges;
|
||||
m_triangles = mesh.m_triangles;
|
||||
|
||||
// generate mapping
|
||||
CircularListElement<TMMVertex>** vertexMap = new CircularListElement<TMMVertex>*[nV];
|
||||
CircularListElement<TMMEdge>** edgeMap = new CircularListElement<TMMEdge>*[nE];
|
||||
CircularListElement<TMMTriangle>** triangleMap = new CircularListElement<TMMTriangle>*[nT];
|
||||
for (size_t v = 0; v < nV; v++) {
|
||||
vertexMap[v] = m_vertices.GetHead();
|
||||
m_vertices.Next();
|
||||
}
|
||||
for (size_t e = 0; e < nE; e++) {
|
||||
edgeMap[e] = m_edges.GetHead();
|
||||
m_edges.Next();
|
||||
}
|
||||
for (size_t f = 0; f < nT; f++) {
|
||||
triangleMap[f] = m_triangles.GetHead();
|
||||
m_triangles.Next();
|
||||
}
|
||||
// generate mapping
|
||||
CircularListElement<TMMVertex>** vertexMap = new CircularListElement<TMMVertex>*[nV];
|
||||
CircularListElement<TMMEdge>** edgeMap = new CircularListElement<TMMEdge>*[nE];
|
||||
CircularListElement<TMMTriangle>** triangleMap = new CircularListElement<TMMTriangle>*[nT];
|
||||
for (size_t v = 0; v < nV; v++)
|
||||
{
|
||||
vertexMap[v] = m_vertices.GetHead();
|
||||
m_vertices.Next();
|
||||
}
|
||||
for (size_t e = 0; e < nE; e++)
|
||||
{
|
||||
edgeMap[e] = m_edges.GetHead();
|
||||
m_edges.Next();
|
||||
}
|
||||
for (size_t f = 0; f < nT; f++)
|
||||
{
|
||||
triangleMap[f] = m_triangles.GetHead();
|
||||
m_triangles.Next();
|
||||
}
|
||||
|
||||
// updating pointers
|
||||
for (size_t v = 0; v < nV; v++) {
|
||||
if (vertexMap[v]->GetData().m_duplicate) {
|
||||
vertexMap[v]->GetData().m_duplicate = edgeMap[vertexMap[v]->GetData().m_duplicate->GetData().m_id];
|
||||
}
|
||||
}
|
||||
for (size_t e = 0; e < nE; e++) {
|
||||
if (edgeMap[e]->GetData().m_newFace) {
|
||||
edgeMap[e]->GetData().m_newFace = triangleMap[edgeMap[e]->GetData().m_newFace->GetData().m_id];
|
||||
}
|
||||
if (nT > 0) {
|
||||
for (int f = 0; f < 2; f++) {
|
||||
if (edgeMap[e]->GetData().m_triangles[f]) {
|
||||
edgeMap[e]->GetData().m_triangles[f] = triangleMap[edgeMap[e]->GetData().m_triangles[f]->GetData().m_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int v = 0; v < 2; v++) {
|
||||
if (edgeMap[e]->GetData().m_vertices[v]) {
|
||||
edgeMap[e]->GetData().m_vertices[v] = vertexMap[edgeMap[e]->GetData().m_vertices[v]->GetData().m_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t f = 0; f < nT; f++) {
|
||||
if (nE > 0) {
|
||||
for (int e = 0; e < 3; e++) {
|
||||
if (triangleMap[f]->GetData().m_edges[e]) {
|
||||
triangleMap[f]->GetData().m_edges[e] = edgeMap[triangleMap[f]->GetData().m_edges[e]->GetData().m_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int v = 0; v < 3; v++) {
|
||||
if (triangleMap[f]->GetData().m_vertices[v]) {
|
||||
triangleMap[f]->GetData().m_vertices[v] = vertexMap[triangleMap[f]->GetData().m_vertices[v]->GetData().m_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
delete[] vertexMap;
|
||||
delete[] edgeMap;
|
||||
delete[] triangleMap;
|
||||
// updating pointers
|
||||
for (size_t v = 0; v < nV; v++)
|
||||
{
|
||||
if (vertexMap[v]->GetData().m_duplicate)
|
||||
{
|
||||
vertexMap[v]->GetData().m_duplicate = edgeMap[vertexMap[v]->GetData().m_duplicate->GetData().m_id];
|
||||
}
|
||||
}
|
||||
for (size_t e = 0; e < nE; e++)
|
||||
{
|
||||
if (edgeMap[e]->GetData().m_newFace)
|
||||
{
|
||||
edgeMap[e]->GetData().m_newFace = triangleMap[edgeMap[e]->GetData().m_newFace->GetData().m_id];
|
||||
}
|
||||
if (nT > 0)
|
||||
{
|
||||
for (int f = 0; f < 2; f++)
|
||||
{
|
||||
if (edgeMap[e]->GetData().m_triangles[f])
|
||||
{
|
||||
edgeMap[e]->GetData().m_triangles[f] = triangleMap[edgeMap[e]->GetData().m_triangles[f]->GetData().m_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int v = 0; v < 2; v++)
|
||||
{
|
||||
if (edgeMap[e]->GetData().m_vertices[v])
|
||||
{
|
||||
edgeMap[e]->GetData().m_vertices[v] = vertexMap[edgeMap[e]->GetData().m_vertices[v]->GetData().m_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (size_t f = 0; f < nT; f++)
|
||||
{
|
||||
if (nE > 0)
|
||||
{
|
||||
for (int e = 0; e < 3; e++)
|
||||
{
|
||||
if (triangleMap[f]->GetData().m_edges[e])
|
||||
{
|
||||
triangleMap[f]->GetData().m_edges[e] = edgeMap[triangleMap[f]->GetData().m_edges[e]->GetData().m_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int v = 0; v < 3; v++)
|
||||
{
|
||||
if (triangleMap[f]->GetData().m_vertices[v])
|
||||
{
|
||||
triangleMap[f]->GetData().m_vertices[v] = vertexMap[triangleMap[f]->GetData().m_vertices[v]->GetData().m_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
delete[] vertexMap;
|
||||
delete[] edgeMap;
|
||||
delete[] triangleMap;
|
||||
}
|
||||
bool TMMesh::CheckConsistancy()
|
||||
{
|
||||
size_t nE = m_edges.GetSize();
|
||||
size_t nT = m_triangles.GetSize();
|
||||
for (size_t e = 0; e < nE; e++) {
|
||||
for (int f = 0; f < 2; f++) {
|
||||
if (!m_edges.GetHead()->GetData().m_triangles[f]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_edges.Next();
|
||||
}
|
||||
for (size_t f = 0; f < nT; f++) {
|
||||
for (int e = 0; e < 3; e++) {
|
||||
int found = 0;
|
||||
for (int k = 0; k < 2; k++) {
|
||||
if (m_triangles.GetHead()->GetData().m_edges[e]->GetData().m_triangles[k] == m_triangles.GetHead()) {
|
||||
found++;
|
||||
}
|
||||
}
|
||||
if (found != 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_triangles.Next();
|
||||
}
|
||||
return true;
|
||||
size_t nE = m_edges.GetSize();
|
||||
size_t nT = m_triangles.GetSize();
|
||||
for (size_t e = 0; e < nE; e++)
|
||||
{
|
||||
for (int f = 0; f < 2; f++)
|
||||
{
|
||||
if (!m_edges.GetHead()->GetData().m_triangles[f])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_edges.Next();
|
||||
}
|
||||
for (size_t f = 0; f < nT; f++)
|
||||
{
|
||||
for (int e = 0; e < 3; e++)
|
||||
{
|
||||
int found = 0;
|
||||
for (int k = 0; k < 2; k++)
|
||||
{
|
||||
if (m_triangles.GetHead()->GetData().m_edges[e]->GetData().m_triangles[k] == m_triangles.GetHead())
|
||||
{
|
||||
found++;
|
||||
}
|
||||
}
|
||||
if (found != 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
m_triangles.Next();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} // namespace VHACD
|
||||
@@ -23,301 +23,336 @@
|
||||
#include <stdlib.h>
|
||||
#include <string>
|
||||
|
||||
namespace VHACD {
|
||||
namespace VHACD
|
||||
{
|
||||
Mesh::Mesh()
|
||||
{
|
||||
m_diag = 1.0;
|
||||
m_diag = 1.0;
|
||||
}
|
||||
Mesh::~Mesh()
|
||||
{
|
||||
}
|
||||
double Mesh::ComputeVolume() const
|
||||
{
|
||||
const size_t nV = GetNPoints();
|
||||
const size_t nT = GetNTriangles();
|
||||
if (nV == 0 || nT == 0) {
|
||||
return 0.0;
|
||||
}
|
||||
const size_t nV = GetNPoints();
|
||||
const size_t nT = GetNTriangles();
|
||||
if (nV == 0 || nT == 0)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
Vec3<double> bary(0.0, 0.0, 0.0);
|
||||
for (size_t v = 0; v < nV; v++) {
|
||||
bary += GetPoint(v);
|
||||
}
|
||||
bary /= static_cast<double>(nV);
|
||||
Vec3<double> bary(0.0, 0.0, 0.0);
|
||||
for (size_t v = 0; v < nV; v++)
|
||||
{
|
||||
bary += GetPoint(v);
|
||||
}
|
||||
bary /= static_cast<double>(nV);
|
||||
|
||||
Vec3<double> ver0, ver1, ver2;
|
||||
double totalVolume = 0.0;
|
||||
for (int t = 0; t < nT; t++) {
|
||||
const Vec3<int>& tri = GetTriangle(t);
|
||||
ver0 = GetPoint(tri[0]);
|
||||
ver1 = GetPoint(tri[1]);
|
||||
ver2 = GetPoint(tri[2]);
|
||||
totalVolume += ComputeVolume4(ver0, ver1, ver2, bary);
|
||||
}
|
||||
return totalVolume / 6.0;
|
||||
Vec3<double> ver0, ver1, ver2;
|
||||
double totalVolume = 0.0;
|
||||
for (int t = 0; t < nT; t++)
|
||||
{
|
||||
const Vec3<int>& tri = GetTriangle(t);
|
||||
ver0 = GetPoint(tri[0]);
|
||||
ver1 = GetPoint(tri[1]);
|
||||
ver2 = GetPoint(tri[2]);
|
||||
totalVolume += ComputeVolume4(ver0, ver1, ver2, bary);
|
||||
}
|
||||
return totalVolume / 6.0;
|
||||
}
|
||||
|
||||
void Mesh::ComputeConvexHull(const double* const pts,
|
||||
const size_t nPts)
|
||||
const size_t nPts)
|
||||
{
|
||||
ResizePoints(0);
|
||||
ResizeTriangles(0);
|
||||
btConvexHullComputer ch;
|
||||
ch.compute(pts, 3 * sizeof(double), (int)nPts, -1.0, -1.0);
|
||||
for (int v = 0; v < ch.vertices.size(); v++) {
|
||||
AddPoint(Vec3<double>(ch.vertices[v].getX(), ch.vertices[v].getY(), ch.vertices[v].getZ()));
|
||||
}
|
||||
const int nt = ch.faces.size();
|
||||
for (int t = 0; t < nt; ++t) {
|
||||
const btConvexHullComputer::Edge* sourceEdge = &(ch.edges[ch.faces[t]]);
|
||||
int a = sourceEdge->getSourceVertex();
|
||||
int b = sourceEdge->getTargetVertex();
|
||||
const btConvexHullComputer::Edge* edge = sourceEdge->getNextEdgeOfFace();
|
||||
int c = edge->getTargetVertex();
|
||||
while (c != a) {
|
||||
AddTriangle(Vec3<int>(a, b, c));
|
||||
edge = edge->getNextEdgeOfFace();
|
||||
b = c;
|
||||
c = edge->getTargetVertex();
|
||||
}
|
||||
}
|
||||
ResizePoints(0);
|
||||
ResizeTriangles(0);
|
||||
btConvexHullComputer ch;
|
||||
ch.compute(pts, 3 * sizeof(double), (int)nPts, -1.0, -1.0);
|
||||
for (int v = 0; v < ch.vertices.size(); v++)
|
||||
{
|
||||
AddPoint(Vec3<double>(ch.vertices[v].getX(), ch.vertices[v].getY(), ch.vertices[v].getZ()));
|
||||
}
|
||||
const int nt = ch.faces.size();
|
||||
for (int t = 0; t < nt; ++t)
|
||||
{
|
||||
const btConvexHullComputer::Edge* sourceEdge = &(ch.edges[ch.faces[t]]);
|
||||
int a = sourceEdge->getSourceVertex();
|
||||
int b = sourceEdge->getTargetVertex();
|
||||
const btConvexHullComputer::Edge* edge = sourceEdge->getNextEdgeOfFace();
|
||||
int c = edge->getTargetVertex();
|
||||
while (c != a)
|
||||
{
|
||||
AddTriangle(Vec3<int>(a, b, c));
|
||||
edge = edge->getNextEdgeOfFace();
|
||||
b = c;
|
||||
c = edge->getTargetVertex();
|
||||
}
|
||||
}
|
||||
}
|
||||
void Mesh::Clip(const Plane& plane,
|
||||
SArray<Vec3<double> >& positivePart,
|
||||
SArray<Vec3<double> >& negativePart) const
|
||||
SArray<Vec3<double> >& positivePart,
|
||||
SArray<Vec3<double> >& negativePart) const
|
||||
{
|
||||
const size_t nV = GetNPoints();
|
||||
if (nV == 0) {
|
||||
return;
|
||||
}
|
||||
double d;
|
||||
for (size_t v = 0; v < nV; v++) {
|
||||
const Vec3<double>& pt = GetPoint(v);
|
||||
d = plane.m_a * pt[0] + plane.m_b * pt[1] + plane.m_c * pt[2] + plane.m_d;
|
||||
if (d > 0.0) {
|
||||
positivePart.PushBack(pt);
|
||||
}
|
||||
else if (d < 0.0) {
|
||||
negativePart.PushBack(pt);
|
||||
}
|
||||
else {
|
||||
positivePart.PushBack(pt);
|
||||
negativePart.PushBack(pt);
|
||||
}
|
||||
}
|
||||
const size_t nV = GetNPoints();
|
||||
if (nV == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
double d;
|
||||
for (size_t v = 0; v < nV; v++)
|
||||
{
|
||||
const Vec3<double>& pt = GetPoint(v);
|
||||
d = plane.m_a * pt[0] + plane.m_b * pt[1] + plane.m_c * pt[2] + plane.m_d;
|
||||
if (d > 0.0)
|
||||
{
|
||||
positivePart.PushBack(pt);
|
||||
}
|
||||
else if (d < 0.0)
|
||||
{
|
||||
negativePart.PushBack(pt);
|
||||
}
|
||||
else
|
||||
{
|
||||
positivePart.PushBack(pt);
|
||||
negativePart.PushBack(pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
bool Mesh::IsInside(const Vec3<double>& pt) const
|
||||
{
|
||||
const size_t nV = GetNPoints();
|
||||
const size_t nT = GetNTriangles();
|
||||
if (nV == 0 || nT == 0) {
|
||||
return false;
|
||||
}
|
||||
Vec3<double> ver0, ver1, ver2;
|
||||
double volume;
|
||||
for (int t = 0; t < nT; t++) {
|
||||
const Vec3<int>& tri = GetTriangle(t);
|
||||
ver0 = GetPoint(tri[0]);
|
||||
ver1 = GetPoint(tri[1]);
|
||||
ver2 = GetPoint(tri[2]);
|
||||
volume = ComputeVolume4(ver0, ver1, ver2, pt);
|
||||
if (volume < 0.0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
const size_t nV = GetNPoints();
|
||||
const size_t nT = GetNTriangles();
|
||||
if (nV == 0 || nT == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Vec3<double> ver0, ver1, ver2;
|
||||
double volume;
|
||||
for (int t = 0; t < nT; t++)
|
||||
{
|
||||
const Vec3<int>& tri = GetTriangle(t);
|
||||
ver0 = GetPoint(tri[0]);
|
||||
ver1 = GetPoint(tri[1]);
|
||||
ver2 = GetPoint(tri[2]);
|
||||
volume = ComputeVolume4(ver0, ver1, ver2, pt);
|
||||
if (volume < 0.0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
double Mesh::ComputeDiagBB()
|
||||
{
|
||||
const size_t nPoints = GetNPoints();
|
||||
if (nPoints == 0)
|
||||
return 0.0;
|
||||
Vec3<double> minBB = m_points[0];
|
||||
Vec3<double> maxBB = m_points[0];
|
||||
double x, y, z;
|
||||
for (size_t v = 1; v < nPoints; v++) {
|
||||
x = m_points[v][0];
|
||||
y = m_points[v][1];
|
||||
z = m_points[v][2];
|
||||
if (x < minBB[0])
|
||||
minBB[0] = x;
|
||||
else if (x > maxBB[0])
|
||||
maxBB[0] = x;
|
||||
if (y < minBB[1])
|
||||
minBB[1] = y;
|
||||
else if (y > maxBB[1])
|
||||
maxBB[1] = y;
|
||||
if (z < minBB[2])
|
||||
minBB[2] = z;
|
||||
else if (z > maxBB[2])
|
||||
maxBB[2] = z;
|
||||
}
|
||||
return (m_diag = (maxBB - minBB).GetNorm());
|
||||
const size_t nPoints = GetNPoints();
|
||||
if (nPoints == 0)
|
||||
return 0.0;
|
||||
Vec3<double> minBB = m_points[0];
|
||||
Vec3<double> maxBB = m_points[0];
|
||||
double x, y, z;
|
||||
for (size_t v = 1; v < nPoints; v++)
|
||||
{
|
||||
x = m_points[v][0];
|
||||
y = m_points[v][1];
|
||||
z = m_points[v][2];
|
||||
if (x < minBB[0])
|
||||
minBB[0] = x;
|
||||
else if (x > maxBB[0])
|
||||
maxBB[0] = x;
|
||||
if (y < minBB[1])
|
||||
minBB[1] = y;
|
||||
else if (y > maxBB[1])
|
||||
maxBB[1] = y;
|
||||
if (z < minBB[2])
|
||||
minBB[2] = z;
|
||||
else if (z > maxBB[2])
|
||||
maxBB[2] = z;
|
||||
}
|
||||
return (m_diag = (maxBB - minBB).GetNorm());
|
||||
}
|
||||
|
||||
#ifdef VHACD_DEBUG_MESH
|
||||
bool Mesh::SaveVRML2(const std::string& fileName) const
|
||||
{
|
||||
std::ofstream fout(fileName.c_str());
|
||||
if (fout.is_open()) {
|
||||
const Material material;
|
||||
std::ofstream fout(fileName.c_str());
|
||||
if (fout.is_open())
|
||||
{
|
||||
const Material material;
|
||||
|
||||
if (SaveVRML2(fout, material)) {
|
||||
fout.close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
if (SaveVRML2(fout, material))
|
||||
{
|
||||
fout.close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool Mesh::SaveVRML2(std::ofstream& fout, const Material& material) const
|
||||
{
|
||||
if (fout.is_open()) {
|
||||
fout.setf(std::ios::fixed, std::ios::floatfield);
|
||||
fout.setf(std::ios::showpoint);
|
||||
fout.precision(6);
|
||||
size_t nV = m_points.Size();
|
||||
size_t nT = m_triangles.Size();
|
||||
fout << "#VRML V2.0 utf8" << std::endl;
|
||||
fout << "" << std::endl;
|
||||
fout << "# Vertices: " << nV << std::endl;
|
||||
fout << "# Triangles: " << nT << std::endl;
|
||||
fout << "" << std::endl;
|
||||
fout << "Group {" << std::endl;
|
||||
fout << " children [" << std::endl;
|
||||
fout << " Shape {" << std::endl;
|
||||
fout << " appearance Appearance {" << std::endl;
|
||||
fout << " material Material {" << std::endl;
|
||||
fout << " diffuseColor " << material.m_diffuseColor[0] << " "
|
||||
<< material.m_diffuseColor[1] << " "
|
||||
<< material.m_diffuseColor[2] << std::endl;
|
||||
fout << " ambientIntensity " << material.m_ambientIntensity << std::endl;
|
||||
fout << " specularColor " << material.m_specularColor[0] << " "
|
||||
<< material.m_specularColor[1] << " "
|
||||
<< material.m_specularColor[2] << std::endl;
|
||||
fout << " emissiveColor " << material.m_emissiveColor[0] << " "
|
||||
<< material.m_emissiveColor[1] << " "
|
||||
<< material.m_emissiveColor[2] << std::endl;
|
||||
fout << " shininess " << material.m_shininess << std::endl;
|
||||
fout << " transparency " << material.m_transparency << std::endl;
|
||||
fout << " }" << std::endl;
|
||||
fout << " }" << std::endl;
|
||||
fout << " geometry IndexedFaceSet {" << std::endl;
|
||||
fout << " ccw TRUE" << std::endl;
|
||||
fout << " solid TRUE" << std::endl;
|
||||
fout << " convex TRUE" << std::endl;
|
||||
if (nV > 0) {
|
||||
fout << " coord DEF co Coordinate {" << std::endl;
|
||||
fout << " point [" << std::endl;
|
||||
for (size_t v = 0; v < nV; v++) {
|
||||
fout << " " << m_points[v][0] << " "
|
||||
<< m_points[v][1] << " "
|
||||
<< m_points[v][2] << "," << std::endl;
|
||||
}
|
||||
fout << " ]" << std::endl;
|
||||
fout << " }" << std::endl;
|
||||
}
|
||||
if (nT > 0) {
|
||||
fout << " coordIndex [ " << std::endl;
|
||||
for (size_t f = 0; f < nT; f++) {
|
||||
fout << " " << m_triangles[f][0] << ", "
|
||||
<< m_triangles[f][1] << ", "
|
||||
<< m_triangles[f][2] << ", -1," << std::endl;
|
||||
}
|
||||
fout << " ]" << std::endl;
|
||||
}
|
||||
fout << " }" << std::endl;
|
||||
fout << " }" << std::endl;
|
||||
fout << " ]" << std::endl;
|
||||
fout << "}" << std::endl;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (fout.is_open())
|
||||
{
|
||||
fout.setf(std::ios::fixed, std::ios::floatfield);
|
||||
fout.setf(std::ios::showpoint);
|
||||
fout.precision(6);
|
||||
size_t nV = m_points.Size();
|
||||
size_t nT = m_triangles.Size();
|
||||
fout << "#VRML V2.0 utf8" << std::endl;
|
||||
fout << "" << std::endl;
|
||||
fout << "# Vertices: " << nV << std::endl;
|
||||
fout << "# Triangles: " << nT << std::endl;
|
||||
fout << "" << std::endl;
|
||||
fout << "Group {" << std::endl;
|
||||
fout << " children [" << std::endl;
|
||||
fout << " Shape {" << std::endl;
|
||||
fout << " appearance Appearance {" << std::endl;
|
||||
fout << " material Material {" << std::endl;
|
||||
fout << " diffuseColor " << material.m_diffuseColor[0] << " "
|
||||
<< material.m_diffuseColor[1] << " "
|
||||
<< material.m_diffuseColor[2] << std::endl;
|
||||
fout << " ambientIntensity " << material.m_ambientIntensity << std::endl;
|
||||
fout << " specularColor " << material.m_specularColor[0] << " "
|
||||
<< material.m_specularColor[1] << " "
|
||||
<< material.m_specularColor[2] << std::endl;
|
||||
fout << " emissiveColor " << material.m_emissiveColor[0] << " "
|
||||
<< material.m_emissiveColor[1] << " "
|
||||
<< material.m_emissiveColor[2] << std::endl;
|
||||
fout << " shininess " << material.m_shininess << std::endl;
|
||||
fout << " transparency " << material.m_transparency << std::endl;
|
||||
fout << " }" << std::endl;
|
||||
fout << " }" << std::endl;
|
||||
fout << " geometry IndexedFaceSet {" << std::endl;
|
||||
fout << " ccw TRUE" << std::endl;
|
||||
fout << " solid TRUE" << std::endl;
|
||||
fout << " convex TRUE" << std::endl;
|
||||
if (nV > 0)
|
||||
{
|
||||
fout << " coord DEF co Coordinate {" << std::endl;
|
||||
fout << " point [" << std::endl;
|
||||
for (size_t v = 0; v < nV; v++)
|
||||
{
|
||||
fout << " " << m_points[v][0] << " "
|
||||
<< m_points[v][1] << " "
|
||||
<< m_points[v][2] << "," << std::endl;
|
||||
}
|
||||
fout << " ]" << std::endl;
|
||||
fout << " }" << std::endl;
|
||||
}
|
||||
if (nT > 0)
|
||||
{
|
||||
fout << " coordIndex [ " << std::endl;
|
||||
for (size_t f = 0; f < nT; f++)
|
||||
{
|
||||
fout << " " << m_triangles[f][0] << ", "
|
||||
<< m_triangles[f][1] << ", "
|
||||
<< m_triangles[f][2] << ", -1," << std::endl;
|
||||
}
|
||||
fout << " ]" << std::endl;
|
||||
}
|
||||
fout << " }" << std::endl;
|
||||
fout << " }" << std::endl;
|
||||
fout << " ]" << std::endl;
|
||||
fout << "}" << std::endl;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool Mesh::SaveOFF(const std::string& fileName) const
|
||||
{
|
||||
std::ofstream fout(fileName.c_str());
|
||||
if (fout.is_open()) {
|
||||
size_t nV = m_points.Size();
|
||||
size_t nT = m_triangles.Size();
|
||||
fout << "OFF" << std::endl;
|
||||
fout << nV << " " << nT << " " << 0 << std::endl;
|
||||
for (size_t v = 0; v < nV; v++) {
|
||||
fout << m_points[v][0] << " "
|
||||
<< m_points[v][1] << " "
|
||||
<< m_points[v][2] << std::endl;
|
||||
}
|
||||
for (size_t f = 0; f < nT; f++) {
|
||||
fout << "3 " << m_triangles[f][0] << " "
|
||||
<< m_triangles[f][1] << " "
|
||||
<< m_triangles[f][2] << std::endl;
|
||||
}
|
||||
fout.close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
std::ofstream fout(fileName.c_str());
|
||||
if (fout.is_open())
|
||||
{
|
||||
size_t nV = m_points.Size();
|
||||
size_t nT = m_triangles.Size();
|
||||
fout << "OFF" << std::endl;
|
||||
fout << nV << " " << nT << " " << 0 << std::endl;
|
||||
for (size_t v = 0; v < nV; v++)
|
||||
{
|
||||
fout << m_points[v][0] << " "
|
||||
<< m_points[v][1] << " "
|
||||
<< m_points[v][2] << std::endl;
|
||||
}
|
||||
for (size_t f = 0; f < nT; f++)
|
||||
{
|
||||
fout << "3 " << m_triangles[f][0] << " "
|
||||
<< m_triangles[f][1] << " "
|
||||
<< m_triangles[f][2] << std::endl;
|
||||
}
|
||||
fout.close();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Mesh::LoadOFF(const std::string& fileName, bool invert)
|
||||
{
|
||||
FILE* fid = fopen(fileName.c_str(), "r");
|
||||
if (fid) {
|
||||
const std::string strOFF("OFF");
|
||||
char temp[1024];
|
||||
fscanf(fid, "%s", temp);
|
||||
if (std::string(temp) != strOFF) {
|
||||
fclose(fid);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
int nv = 0;
|
||||
int nf = 0;
|
||||
int ne = 0;
|
||||
fscanf(fid, "%i", &nv);
|
||||
fscanf(fid, "%i", &nf);
|
||||
fscanf(fid, "%i", &ne);
|
||||
m_points.Resize(nv);
|
||||
m_triangles.Resize(nf);
|
||||
Vec3<double> coord;
|
||||
float x, y, z;
|
||||
for (int p = 0; p < nv; p++) {
|
||||
fscanf(fid, "%f", &x);
|
||||
fscanf(fid, "%f", &y);
|
||||
fscanf(fid, "%f", &z);
|
||||
m_points[p][0] = x;
|
||||
m_points[p][1] = y;
|
||||
m_points[p][2] = z;
|
||||
}
|
||||
int i, j, k, s;
|
||||
for (int t = 0; t < nf; ++t) {
|
||||
fscanf(fid, "%i", &s);
|
||||
if (s == 3) {
|
||||
fscanf(fid, "%i", &i);
|
||||
fscanf(fid, "%i", &j);
|
||||
fscanf(fid, "%i", &k);
|
||||
m_triangles[t][0] = i;
|
||||
if (invert) {
|
||||
m_triangles[t][1] = k;
|
||||
m_triangles[t][2] = j;
|
||||
}
|
||||
else {
|
||||
m_triangles[t][1] = j;
|
||||
m_triangles[t][2] = k;
|
||||
}
|
||||
}
|
||||
else // Fix me: support only triangular meshes
|
||||
{
|
||||
for (int h = 0; h < s; ++h)
|
||||
fscanf(fid, "%i", &s);
|
||||
}
|
||||
}
|
||||
fclose(fid);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif // VHACD_DEBUG_MESH
|
||||
FILE* fid = fopen(fileName.c_str(), "r");
|
||||
if (fid)
|
||||
{
|
||||
const std::string strOFF("OFF");
|
||||
char temp[1024];
|
||||
fscanf(fid, "%s", temp);
|
||||
if (std::string(temp) != strOFF)
|
||||
{
|
||||
fclose(fid);
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
int nv = 0;
|
||||
int nf = 0;
|
||||
int ne = 0;
|
||||
fscanf(fid, "%i", &nv);
|
||||
fscanf(fid, "%i", &nf);
|
||||
fscanf(fid, "%i", &ne);
|
||||
m_points.Resize(nv);
|
||||
m_triangles.Resize(nf);
|
||||
Vec3<double> coord;
|
||||
float x, y, z;
|
||||
for (int p = 0; p < nv; p++)
|
||||
{
|
||||
fscanf(fid, "%f", &x);
|
||||
fscanf(fid, "%f", &y);
|
||||
fscanf(fid, "%f", &z);
|
||||
m_points[p][0] = x;
|
||||
m_points[p][1] = y;
|
||||
m_points[p][2] = z;
|
||||
}
|
||||
int i, j, k, s;
|
||||
for (int t = 0; t < nf; ++t)
|
||||
{
|
||||
fscanf(fid, "%i", &s);
|
||||
if (s == 3)
|
||||
{
|
||||
fscanf(fid, "%i", &i);
|
||||
fscanf(fid, "%i", &j);
|
||||
fscanf(fid, "%i", &k);
|
||||
m_triangles[t][0] = i;
|
||||
if (invert)
|
||||
{
|
||||
m_triangles[t][1] = k;
|
||||
m_triangles[t][2] = j;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_triangles[t][1] = j;
|
||||
m_triangles[t][2] = k;
|
||||
}
|
||||
}
|
||||
else // Fix me: support only triangular meshes
|
||||
{
|
||||
for (int h = 0; h < s; ++h)
|
||||
fscanf(fid, "%i", &s);
|
||||
}
|
||||
}
|
||||
fclose(fid);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif // VHACD_DEBUG_MESH
|
||||
} // namespace VHACD
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user