Skip to content

Commit

Permalink
[!] refactoring Delaunay3D namespace:
Browse files Browse the repository at this point in the history
	- moved most tetrahedra_t methods to its private namespace so that they don't need to be exposed on the header
	- extracted all static methods from Delaunay3D class into the namespace to hide them from the header (exposes a much cleaner interface)
  • Loading branch information
joesfer committed Feb 2, 2012
1 parent 12dea5d commit e5620f3
Show file tree
Hide file tree
Showing 5 changed files with 660 additions and 692 deletions.
2 changes: 1 addition & 1 deletion include/dataStructs/kdtree/kdTree.inl
Expand Up @@ -162,7 +162,7 @@ bool KdTree::traceClosest( const TraceDesc& trace, const RenderLib::DataStructur
const Point3f& p1 = verts[ indices[ triangleOffset + 1] ].position;
const Point3f& p2 = verts[ indices[ triangleOffset + 2] ].position;

if ( SegmentTriangleIntersect_DoubleSided( ray.origin, ray.direction, tMin, tMax, p0, p1, p2, t, v, w ) ) {
if ( segmentTriangleIntersect_DoubleSided( ray.origin, ray.direction, tMin, tMax, p0, p1, p2, t, v, w ) ) {
if ( trace.testOnly ) {
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions include/geometry/intersection/intersection.h
Expand Up @@ -113,7 +113,7 @@ namespace Geometry {
}

template< typename T >
inline bool SegmentTriangleIntersect_DoubleSided( const RenderLib::Math::Point3<T>& p, const RenderLib::Math::Vector3<T>& dir,
inline bool segmentTriangleIntersect_DoubleSided( const RenderLib::Math::Point3<T>& p, const RenderLib::Math::Vector3<T>& dir,
T minT, T maxT,
const RenderLib::Math::Point3<T>& a, const RenderLib::Math::Point3<T>& b, const RenderLib::Math::Point3<T>& c,
T& t, T& v, T& w,
Expand Down Expand Up @@ -148,15 +148,15 @@ namespace Geometry {
}

template< typename T >
inline bool SegmentTriangleIntersect_DoubleSided( const RenderLib::Math::Point3<T>& p, const RenderLib::Math::Point3<T>& q,
inline bool segmentTriangleIntersect_DoubleSided( const RenderLib::Math::Point3<T>& p, const RenderLib::Math::Point3<T>& q,
const RenderLib::Math::Point3<T>& a, const RenderLib::Math::Point3<T>& b, const RenderLib::Math::Point3<T>& c,
T& t, T& v, T& w,
const T epsilon = 1e-5 ) {
using namespace RenderLib::Math;
Vector3<T> dir = q - p;
T maxT = dir.normalize();
const T lengthEpsilon = 1e-4;
return SegmentTriangleIntersect_DoubleSided<T>( p, dir, -lengthEpsilon, maxT + lengthEpsilon, a, b, c, t, v, w, epsilon );
return segmentTriangleIntersect_DoubleSided<T>( p, dir, -lengthEpsilon, maxT + lengthEpsilon, a, b, c, t, v, w, epsilon );
}

} // namespace Geometry
Expand Down
114 changes: 1 addition & 113 deletions include/geometry/tessellation/delaunay/delaunay3D.h
Expand Up @@ -49,53 +49,10 @@ namespace Delaunay3D {
int face[ 4 ][ 3 ]; // vertex indices for each face

tetrahedron_t();

tetrahedron_t( const tetrahedron_t& other );

void markInvalid();

bool isValid() const;

bool containsVertex( const int vert ) const;

void getFaceVertices( const int f, int& a, int& b, int& c ) const;

REAL getFaceArea( const int f, const CoreLib::List< Point >& vertices ) const;

int getFaceFromVertices( const int a, const int b, const int c ) const;

int getVertexOutsideFace( int f ) const;


// We use this function to check whether two faces sharing the same vertices are reversed
// without needing to calculate the normal
bool sameWinding( const int v1[3], const int v2[3] ) const;

int sharedFace( const tetrahedron_t& other, bool reversed ) const;

bool adjacentTo( const tetrahedron_t& other ) const;

bool checkNeighbors( const int thisIndex, const CoreLib::List< tetrahedron_t >& tetrahedra, const CoreLib::List< Point >& vertices ) const;

void destroy( CoreLib::List< tetrahedron_t >& tetrahedra );

// checks whether 'face' has the same orientation than 'otherFace' (normals point toward the same direction)
bool sameOrientation( const int face, const tetrahedron_t& other, const int otherFace, const CoreLib::List< Point >& vertices ) const;

void reverseFace( const int f );

//////////////////////////////////////////////////////////////////////////
// tetrahedron_t::IsFlat
//
// A tetrahedron is flat if its 4 vertices lie in the same plane
// A flat tetrahedron has no circumsphere
//////////////////////////////////////////////////////////////////////////
bool isFlat( const CoreLib::List< Point >& vertices ) const;

// ensure the tetrahedron centroid lies behind every face
void fixFaceOrientations( const CoreLib::List< Point >& vertices );

bool checkFaceOrientations( const CoreLib::List< Point >& vertices ) const;
};

//////////////////////////////////////////////////////////////////////////
Expand All @@ -105,7 +62,6 @@ namespace Delaunay3D {
//////////////////////////////////////////////////////////////////////////

class Delaunay3D {
friend struct tetrahedron_t;
public:
#if LEAVE_CONTAINING_TETRAHEDRON
bool tetrahedralize( CoreLib::List< Point >& points,
Expand All @@ -115,75 +71,7 @@ namespace Delaunay3D {
CoreLib::List< tetrahedron_t >& tetrahedra );
#endif

private:

// Predicates //////////////////////////////////////////////////////////////////////////

// Determines whether p is above the plane ( > 0 ), below ( < 0 ) or on the plane ( = 0 )
static REAL orient( const Point& a,
const Point& b,
const Point& c,
const Point& p );

// returns > 0 if p is inside the sphere described by A,B,C,D, < 0 outside, = 0 on the sphere
static REAL inSphere( const Point& a,
const Point& b,
const Point& c,
const Point& d,
const Point& p );

// Is p inside tetrahedron t?
static bool inside( const Point& p, const tetrahedron_t& t, const CoreLib::List< Point >& vertices );

// whether 4 points are coplanar
static bool coplanar( const Point& a, const Point& b, const Point& c, const Point& d );

// Bistellar flips /////////////////////////////////////////////////////////////////////

static void flip14( const unsigned int pointIndex, const unsigned int tetrahedron,
CoreLib::List< tetrahedron_t >& tetrahedra,
const CoreLib::List< Point >& vertices,
unsigned int resultingTetrahedra[4] );

static bool flip23( const unsigned int tetrahedron1, const unsigned int tetrahedron2,
CoreLib::List< tetrahedron_t >& tetrahedra,
const CoreLib::List< Point >& vertices,
unsigned int resultingTetrahedra[3] );

static void flip32( const unsigned int tetrahedron1, const unsigned int tetrahedron2, const unsigned int tetrahedron3,
CoreLib::List< tetrahedron_t >& tetrahedra,
const CoreLib::List< Point >& vertices,
unsigned int resultingTetrahedra[2] );

static void flip44( const unsigned int tetrahedron1, const unsigned int tetrahedron2, const unsigned int tetrahedron3, const unsigned int tetrahedron4,
CoreLib::List< tetrahedron_t >& tetrahedra,
const CoreLib::List< Point >& vertices,
unsigned int resultingTetrahedra[4] );

// Auxiliary operations ////////////////////////////////////////////////////////////////

static void containingTetrahedron( const RenderLib::Math::Point3f& center, const float radius, // circumsphere
tetrahedron_t& t, CoreLib::List< Point >& points );

// Given a tetrahedron and a face, ensures the potential adjacent tetrahedron sharing
// that face points to the given tetrahedron.
static void adjustNeighborVicinity( const int iT, const int f, CoreLib::List< tetrahedron_t >& tetrahedra );

// returns the index of the tetrahedron containing p, or -1 if not found.
// It retrieves the result by searching from a given sourceT tetrahedron index.
static int walk( const Point& p, const int sourceT, const CoreLib::List< Point >& vertices, const CoreLib::List< tetrahedron_t >& tetrahedra );

// Flips two given tetrahedra: T and Ta, which are non-Delaunay,
// into a Delaunay configuration using bistellar flips
static void flip( const int T, const int Ta, const int p,
const CoreLib::List< Point >& vertices,
CoreLib::List< tetrahedron_t >& tetrahedra,
std::stack< unsigned int >& needTesting );

static void insertOnePoint( const CoreLib::List< Point >& vertices, const int pointIndex,
CoreLib::List< tetrahedron_t >& tetrahedra );

private:
private:

CoreLib::List< REAL > tempVertices;

Expand Down
2 changes: 1 addition & 1 deletion include/geometry/utils.h
Expand Up @@ -57,7 +57,7 @@ namespace Geometry {

// Triangle Area using Heron's formula
template< typename T >
T TriangleArea( const RenderLib::Math::Point3<T> &a, const RenderLib::Math::Point3<T> &b, const RenderLib::Math::Point3<T> &c ) {
T triangleArea( const RenderLib::Math::Point3<T> &a, const RenderLib::Math::Point3<T> &b, const RenderLib::Math::Point3<T> &c ) {
const T sa = b.distanceTo( c );
const T sb = a.distanceTo( c );
const T sc = a.distanceTo( b );
Expand Down

0 comments on commit e5620f3

Please sign in to comment.