From 7e237e7572409a84651ec0e4cf22eeef97c6c859 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 17 Mar 1999 23:51:59 +0000 Subject: [PATCH] Initial revision. --- Triangulate/Makefile.am | 10 +++++ Triangulate/triangle.cxx | 73 +++++++++++++++++++++++++++++++++++++ Triangulate/triangle.hxx | 79 ++++++++++++++++++++++++++++++++++++++++ Triangulate/trinodes.cxx | 79 ++++++++++++++++++++++++++++++++++++++++ Triangulate/trinodes.hxx | 79 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 320 insertions(+) create mode 100644 Triangulate/Makefile.am create mode 100644 Triangulate/triangle.cxx create mode 100644 Triangulate/triangle.hxx create mode 100644 Triangulate/trinodes.cxx create mode 100644 Triangulate/trinodes.hxx diff --git a/Triangulate/Makefile.am b/Triangulate/Makefile.am new file mode 100644 index 000000000..503e359b2 --- /dev/null +++ b/Triangulate/Makefile.am @@ -0,0 +1,10 @@ +noinst_LIBRARIES = libTriangulate.a + +libTriangulate_a_SOURCES = \ + triangle.cxx triangle.hxx \ + trinodes.cxx trinodes.hxx + +INCLUDES += \ + -I$(top_builddir) \ + -I$(top_builddir)/Lib \ + -I$(top_builddir)/Tools/Construct diff --git a/Triangulate/triangle.cxx b/Triangulate/triangle.cxx new file mode 100644 index 000000000..2a226dd3b --- /dev/null +++ b/Triangulate/triangle.cxx @@ -0,0 +1,73 @@ +// triangle.cxx -- "Triangle" interface class +// +// Written by Curtis Olson, started March 1999. +// +// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) + + +#include "triangle.hxx" + + +// Constructor +FGTriangle::FGTriangle( void ) { +} + + +// Destructor +FGTriangle::~FGTriangle( void ) { +} + + +// populate this class based on the specified gpc_polys list +int FGTriangle::build( FGgpcPolyList gpc_polys ) { + // 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) + + gpc_polygon *gpc_poly; + gpcpoly_iterator current, last; + + // process polygons in priority order + cout << "prepairing node list and polygons" << endl; + + for ( int i = 0; i < FG_MAX_AREAS; ++i ) { + cout << "area type = " << i << endl; + current = gpc_polys.polys[i].begin(); + last = gpc_polys.polys[i].end(); + for ( ; current != last; ++current ) { + gpc_poly = *current; + + for ( int j = 0; j < gpc_poly->num_contours; j++ ) { + for ( int k = 0; k < gpc_poly->contour[j].num_vertices; k++ ) { + Point3D p( gpc_poly->contour[j].vertex[k].x, + gpc_poly->contour[j].vertex[k].y, + 0 ); + cout << trinodes.unique_add( p ) << endl; + } + } + } + } +} + + +// $Log$ +// Revision 1.1 1999/03/17 23:51:59 curt +// Initial revision. +// diff --git a/Triangulate/triangle.hxx b/Triangulate/triangle.hxx new file mode 100644 index 000000000..5879abd18 --- /dev/null +++ b/Triangulate/triangle.hxx @@ -0,0 +1,79 @@ +// triandgle.hxx -- "Triangle" interface class +// +// Written by Curtis Olson, started March 1999. +// +// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) + + +#ifndef _TRIANGLE_HXX +#define _TRIANGLE_HXX + + +#ifndef __cplusplus +# error This library requires C++ +#endif + + +#include + +#include + +#include +#include + +#include "trinodes.hxx" + +FG_USING_STD(vector); + + +typedef vector < int > tripoly; +typedef tripoly::iterator tripoly_iterator; +typedef tripoly::const_iterator const_tripoly_iterator; + +typedef vector < int > tripoly_list; +typedef tripoly_list::iterator tripoly_list_iterator; +typedef tripoly_list::const_iterator const_tripoly_list_iterator; + + +class FGTriangle { + +private: + + FGTriNodes trinodes; + tripoly_list polylist; + +public: + + // Constructor and destructor + FGTriangle( void ); + ~FGTriangle( void ); + + // populate this class based on the specified gpc_polys list + int build( FGgpcPolyList gpc_polys ); +}; + + +#endif // _TRIANGLE_HXX + + +// $Log$ +// Revision 1.1 1999/03/17 23:51:59 curt +// Initial revision. +// diff --git a/Triangulate/trinodes.cxx b/Triangulate/trinodes.cxx new file mode 100644 index 000000000..5c2508e00 --- /dev/null +++ b/Triangulate/trinodes.cxx @@ -0,0 +1,79 @@ +// trinodes.cxx -- "Triangle" nodes management class +// +// Written by Curtis Olson, started March 1999. +// +// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) + + +#include "trinodes.hxx" + + +// Constructor +FGTriNodes::FGTriNodes( void ) { +} + + +// Destructor +FGTriNodes::~FGTriNodes( void ) { +} + + +// return true of the two points are "close enough" as defined by +// FG_PROXIMITY_EPSILON +inline bool FGTriNodes::close_enough( const Point3D& p1, const Point3D& p2 ) { + if ( ( fabs(p1.x() - p2.x()) < FG_PROXIMITY_EPSILON ) && + ( fabs(p1.y() - p2.y()) < FG_PROXIMITY_EPSILON ) ) { + return true; + } else { + return false; + } +} + + +// 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; + int counter = 0; + + // see if point already exists + current = point_list.begin(); + last = point_list.end(); + for ( ; current != last; ++current ) { + if ( close_enough(p, *current) ) { + return counter; + } + + ++counter; + } + + // add to list + point_list.push_back( p ); + + return counter; +} + + +// $Log$ +// Revision 1.1 1999/03/17 23:52:00 curt +// Initial revision. +// + + diff --git a/Triangulate/trinodes.hxx b/Triangulate/trinodes.hxx new file mode 100644 index 000000000..2245b5a8c --- /dev/null +++ b/Triangulate/trinodes.hxx @@ -0,0 +1,79 @@ +// trinodes.hxx -- "Triangle" nodes management class +// +// Written by Curtis Olson, started March 1999. +// +// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) + + +#ifndef _TRINODES_HXX +#define _TRINODES_HXX + + +#ifndef __cplusplus +# error This library requires C++ +#endif + + +#include + +#include + +#include + +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; + + +class FGTriNodes { + +private: + + point_container point_list; + + // return true of the two points are "close enough" as defined by + // FG_PROXIMITY_EPSILON + bool close_enough( const Point3D& p, const Point3D& p ); + +public: + + // Constructor and destructor + FGTriNodes( void ); + ~FGTriNodes( void ); + + // 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 unique_add( const Point3D& p ); +}; + + +#endif // _TRINODES_HXX + + +// $Log$ +// Revision 1.1 1999/03/17 23:52:00 curt +// Initial revision. +//