Continue shaping the code towards triangulation bliss. Added code to
calculate some point guaranteed to be inside a polygon.
This commit is contained in:
parent
453a82a030
commit
45da0562fb
5 changed files with 46 additions and 26 deletions
|
@ -2,7 +2,8 @@ noinst_LIBRARIES = libTriangulate.a
|
|||
|
||||
libTriangulate_a_SOURCES = \
|
||||
triangle.cxx triangle.hxx \
|
||||
trinodes.cxx trinodes.hxx
|
||||
trinodes.cxx trinodes.hxx \
|
||||
tripoly.cxx tripoly.hxx
|
||||
|
||||
INCLUDES += \
|
||||
-I$(top_builddir) \
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
|
||||
#include "triangle.hxx"
|
||||
#include "tripoly.hxx"
|
||||
|
||||
|
||||
// Constructor
|
||||
|
@ -38,8 +39,6 @@ FGTriangle::~FGTriangle( void ) {
|
|||
// populate this class based on the specified gpc_polys list
|
||||
int FGTriangle::build( const FGgpcPolyList& gpc_polys ) {
|
||||
int index;
|
||||
tripoly poly;
|
||||
|
||||
// traverse the gpc_polys and build a unified node list and a set
|
||||
// of Triangle PSLG that reference the node list by index
|
||||
// (starting at zero)
|
||||
|
@ -59,7 +58,7 @@ int FGTriangle::build( const FGgpcPolyList& gpc_polys ) {
|
|||
cout << "processing a polygon, contours = "
|
||||
<< gpc_poly->num_contours << endl;
|
||||
|
||||
poly.erase(poly.begin(), poly.end());
|
||||
FGTriPoly poly;
|
||||
|
||||
if (gpc_poly->num_contours <= 0 ) {
|
||||
cout << "FATAL ERROR! no contours in this polygon" << endl;
|
||||
|
@ -78,9 +77,11 @@ int FGTriangle::build( const FGgpcPolyList& gpc_polys ) {
|
|||
gpc_poly->contour[j].vertex[k].y,
|
||||
0 );
|
||||
index = trinodes.unique_add( p );
|
||||
poly.push_back(index);
|
||||
poly.add_node(index);
|
||||
// cout << index << endl;
|
||||
}
|
||||
poly.calc_point_inside( trinodes );
|
||||
cout << endl;
|
||||
polylist[i].push_back(poly);
|
||||
}
|
||||
}
|
||||
|
@ -97,8 +98,8 @@ int FGTriangle::build( const FGgpcPolyList& gpc_polys ) {
|
|||
|
||||
|
||||
// do actual triangulation
|
||||
int FGTriangle::do_triangulate( const tripoly& poly ) {
|
||||
point_container node_list;
|
||||
int FGTriangle::do_triangulate( const FGTriPoly& poly ) {
|
||||
trinode_list node_list;
|
||||
struct triangulateio in, mid, out, vorout;
|
||||
int counter;
|
||||
|
||||
|
@ -108,7 +109,7 @@ int FGTriangle::do_triangulate( const tripoly& poly ) {
|
|||
in.numberofpoints = node_list.size();
|
||||
in.pointlist = (REAL *) malloc(in.numberofpoints * 2 * sizeof(REAL));
|
||||
|
||||
point_iterator current, last;
|
||||
trinode_list_iterator current, last;
|
||||
current = node_list.begin();
|
||||
last = node_list.end();
|
||||
counter = 0;
|
||||
|
@ -116,12 +117,14 @@ int FGTriangle::do_triangulate( const tripoly& poly ) {
|
|||
in.pointlist[counter++] = current->x();
|
||||
in.pointlist[counter++] = current->y();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// triangulate each of the polygon areas
|
||||
int FGTriangle::triangulate() {
|
||||
tripoly poly;
|
||||
FGTriPoly poly;
|
||||
|
||||
tripoly_list_iterator current, last;
|
||||
|
||||
|
@ -142,6 +145,10 @@ int FGTriangle::triangulate() {
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.5 1999/03/20 02:21:52 curt
|
||||
// Continue shaping the code towards triangulation bliss. Added code to
|
||||
// calculate some point guaranteed to be inside a polygon.
|
||||
//
|
||||
// Revision 1.4 1999/03/19 22:29:04 curt
|
||||
// Working on preparationsn for triangulation.
|
||||
//
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// triandgle.hxx -- "Triangle" interface class
|
||||
// triangle.hxx -- "Triangle" interface class
|
||||
//
|
||||
// Written by Curtis Olson, started March 1999.
|
||||
//
|
||||
|
@ -45,15 +45,12 @@ extern "C" {
|
|||
}
|
||||
|
||||
#include "trinodes.hxx"
|
||||
#include "tripoly.hxx"
|
||||
|
||||
FG_USING_STD(vector);
|
||||
|
||||
|
||||
typedef vector < int > tripoly;
|
||||
typedef tripoly::iterator tripoly_iterator;
|
||||
typedef tripoly::const_iterator const_tripoly_iterator;
|
||||
|
||||
typedef vector < tripoly > tripoly_list;
|
||||
typedef vector < FGTriPoly > tripoly_list;
|
||||
typedef tripoly_list::iterator tripoly_list_iterator;
|
||||
typedef tripoly_list::const_iterator const_tripoly_list_iterator;
|
||||
|
||||
|
@ -78,7 +75,7 @@ public:
|
|||
int build( const FGgpcPolyList& gpc_polys );
|
||||
|
||||
// do actual triangulation
|
||||
int do_triangulate( const tripoly& poly );
|
||||
int do_triangulate( const FGTriPoly& poly );
|
||||
|
||||
// front end triangulator for polygon list
|
||||
int triangulate();
|
||||
|
@ -89,6 +86,10 @@ public:
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.5 1999/03/20 02:21:53 curt
|
||||
// Continue shaping the code towards triangulation bliss. Added code to
|
||||
// calculate some point guaranteed to be inside a polygon.
|
||||
//
|
||||
// Revision 1.4 1999/03/19 22:29:05 curt
|
||||
// Working on preparationsn for triangulation.
|
||||
//
|
||||
|
|
|
@ -50,17 +50,17 @@ inline bool FGTriNodes::close_enough( const Point3D& p1, const Point3D& p2 ) {
|
|||
// Add a point to the point list if it doesn't already exist. Returns
|
||||
// the index (starting at zero) of the point in the list.
|
||||
int FGTriNodes::unique_add( const Point3D& p ) {
|
||||
point_iterator current, last;
|
||||
trinode_list_iterator current, last;
|
||||
int counter = 0;
|
||||
|
||||
// cout << p.x() << "," << p.y() << endl;
|
||||
|
||||
// see if point already exists
|
||||
current = point_list.begin();
|
||||
last = point_list.end();
|
||||
current = node_list.begin();
|
||||
last = node_list.end();
|
||||
for ( ; current != last; ++current ) {
|
||||
if ( close_enough(p, *current) ) {
|
||||
cout << "found an existing match!" << endl;
|
||||
// cout << "found an existing match!" << endl;
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
@ -68,13 +68,17 @@ int FGTriNodes::unique_add( const Point3D& p ) {
|
|||
}
|
||||
|
||||
// add to list
|
||||
point_list.push_back( p );
|
||||
node_list.push_back( p );
|
||||
|
||||
return counter;
|
||||
}
|
||||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.3 1999/03/20 02:21:54 curt
|
||||
// Continue shaping the code towards triangulation bliss. Added code to
|
||||
// calculate some point guaranteed to be inside a polygon.
|
||||
//
|
||||
// Revision 1.2 1999/03/19 00:27:12 curt
|
||||
// Continued work on triangulation preparation.
|
||||
//
|
||||
|
|
|
@ -43,16 +43,16 @@ FG_USING_STD(vector);
|
|||
#define FG_PROXIMITY_EPSILON 0.000001
|
||||
|
||||
|
||||
typedef vector < Point3D > point_container;
|
||||
typedef point_container::iterator point_iterator;
|
||||
typedef point_container::const_iterator const_point_iterator;
|
||||
typedef vector < Point3D > trinode_list;
|
||||
typedef trinode_list::iterator trinode_list_iterator;
|
||||
typedef trinode_list::const_iterator const_trinode_list_iterator;
|
||||
|
||||
|
||||
class FGTriNodes {
|
||||
|
||||
private:
|
||||
|
||||
point_container point_list;
|
||||
trinode_list node_list;
|
||||
|
||||
// return true of the two points are "close enough" as defined by
|
||||
// FG_PROXIMITY_EPSILON
|
||||
|
@ -69,7 +69,10 @@ public:
|
|||
int unique_add( const Point3D& p );
|
||||
|
||||
// return the master node list
|
||||
inline point_container get_node_list() const { return point_list; }
|
||||
inline trinode_list get_node_list() const { return node_list; }
|
||||
|
||||
// return the ith point
|
||||
inline Point3D get_node( int i ) const { return node_list[i]; }
|
||||
};
|
||||
|
||||
|
||||
|
@ -77,6 +80,10 @@ public:
|
|||
|
||||
|
||||
// $Log$
|
||||
// Revision 1.3 1999/03/20 02:21:55 curt
|
||||
// Continue shaping the code towards triangulation bliss. Added code to
|
||||
// calculate some point guaranteed to be inside a polygon.
|
||||
//
|
||||
// Revision 1.2 1999/03/19 22:29:06 curt
|
||||
// Working on preparationsn for triangulation.
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue