Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
fixes polygon triangulation
Browse files Browse the repository at this point in the history
  • Loading branch information
vmora committed Mar 31, 2014
1 parent 9568eef commit ab93456
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
9 changes: 7 additions & 2 deletions include/SFCGAL/algorithm/plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,13 @@ void plane3D(
template < typename Kernel >
CGAL::Plane_3< Kernel > plane3D( const Polygon& polygon, bool exact = true )
{
CGAL::Vector_3< Kernel > normal = normal3D< Kernel >( polygon, exact );
return CGAL::Plane_3< Kernel >( polygon.exteriorRing().pointN( 0 ).toPoint_3(), normal );
CGAL::Vector_3< Kernel > nrml = normal3D< Kernel >( polygon, exact );
if ( !exact )
{
const double nrm = std::sqrt( CGAL::to_double( nrml.squared_length() ) );
nrml = CGAL::Vector_3< Kernel >( nrml.x()/nrm, nrml.y()/nrm, nrml.z()/nrm );
}
return CGAL::Plane_3< Kernel >( polygon.exteriorRing().pointN( 0 ).toPoint_3(), nrml );
}


Expand Down
15 changes: 5 additions & 10 deletions src/SFCGAL/detail/triangulate/ConstraintDelaunayTriangulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,11 @@ ConstraintDelaunayTriangulation::Vertex_handle ConstraintDelaunayTriangulation::
) );
}

if ( _projectionPlane ) {
Vertex_handle vertex = _cdt.insert( _projectionPlane->to_2d( position.toPoint_3() ) );
vertex->info().original = position ;
return vertex ;
}
else {
Vertex_handle vertex = _cdt.insert( position.toPoint_2() );
vertex->info().original = position ;
return vertex ;
}
Vertex_handle vertex = _projectionPlane
? _cdt.insert( _projectionPlane->to_2d( position.toPoint_3() ) )
: _cdt.insert( position.toPoint_2() );
vertex->info().original = position ;
return vertex ;
}

///
Expand Down
18 changes: 10 additions & 8 deletions src/SFCGAL/triangulate/triangulatePolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <SFCGAL/detail/triangulate/ConstraintDelaunayTriangulation.h>

#include <SFCGAL/algorithm/plane.h>
#include <SFCGAL/algorithm/normal.h>
#include <SFCGAL/algorithm/isValid.h>

#include <iostream>
Expand Down Expand Up @@ -162,17 +163,18 @@ void triangulatePolygon3D(
for ( size_t i = 0; i < polygon.numRings(); i++ ) {
const LineString& ring = polygon.ringN( i );

Vertex_handle v_prev ;

for ( size_t j = 0; j < ring.numPoints(); j++ ) {
/*
* note, we do not include the last point, since it's equal to the last and that
*/
if (!ring.numPoints()) continue;
Vertex_handle v_prev = cdt.addVertex( ring.pointN( 0 ).coordinate() );
Vertex_handle v_0 = v_prev;
for ( size_t j = 1; j < ring.numPoints()-1; j++ ) {
Vertex_handle vh = cdt.addVertex( ring.pointN( j ).coordinate() );

if ( j != 0 ) {
cdt.addConstraint( vh, v_prev );
}

cdt.addConstraint( v_prev, vh );
v_prev = vh;
}
cdt.addConstraint( v_prev, v_0 );
}

/*
Expand Down

0 comments on commit ab93456

Please sign in to comment.