Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions meshing/TriMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
#include <locale.h>
#include <iostream>
#include <utils/stringutils.h>
#include <utils/IntPair.h>
#include <math3d/geometry3d.h>
#include <math3d/misc.h>
#include <GLdraw/GL.h>
#include <GLdraw/drawextra.h>
#include <fstream>
#include <algorithm>
#include <map>
#include <errors.h>
namespace Meshing {

Expand Down Expand Up @@ -98,6 +100,44 @@ bool TriMesh::IsValid() const
return res;
}

bool TriMesh::IsWatertight() const
{
size_t numedges = tris.size()*3;
std::map<IntPair, int> edgegroup = {};
for(size_t i=0;i<tris.size();i++) {
for(int j=0;j<3;j++) {
int v1, v2;
GetEdge(i,j,v1,v2);
if(v1>v2) {
std::swap(v1,v2);
}
IntPair edge(v1,v2);

std::map<IntPair, int>::iterator it;
it = edgegroup.find(edge);
if(it==edgegroup.end()) {
edgegroup.insert(std::make_pair(edge,1));
} else {
it->second++;
}
}
}

size_t numsharededges = 0;
std::map<IntPair, int>::iterator it;
for(it=edgegroup.begin();it!=edgegroup.end();it++) {
if(it->second==2) {
numsharededges++;
}
}

if(numsharededges*2==numedges) {
return true;
} else {
return false;
}
}

void TriMesh::GetAABB(Vector3& bmin, Vector3& bmax) const
{
bmin.set(Inf);
Expand Down
2 changes: 2 additions & 0 deletions meshing/TriMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ struct TriMesh
///@name Calculations
//@{
bool IsValid() const;
//returns true if every edge of a triangle is shared by two triangles
bool IsWatertight() const;
void GetAABB(Vector3& bmin, Vector3& bmax) const;
//returns the closest/collided triangle
int ClosestPoint(const Vector3& pt,Vector3& cp) const;
Expand Down