First mostly successful tile triangulation works. There's plenty of tweaking
to do, but we are marching in the right direction.
This commit is contained in:
parent
e07ae2989e
commit
b4a9bde0e9
9 changed files with 341 additions and 107 deletions
|
@ -60,14 +60,14 @@ FG_USING_STD(string);
|
||||||
FGArray::FGArray( void ) {
|
FGArray::FGArray( void ) {
|
||||||
// cout << "class FGArray CONstructor called." << endl;
|
// cout << "class FGArray CONstructor called." << endl;
|
||||||
in_data = new float[ARRAY_SIZE_1][ARRAY_SIZE_1];
|
in_data = new float[ARRAY_SIZE_1][ARRAY_SIZE_1];
|
||||||
out_data = new float[ARRAY_SIZE_1][ARRAY_SIZE_1];
|
// out_data = new float[ARRAY_SIZE_1][ARRAY_SIZE_1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FGArray::FGArray( const string &file ) {
|
FGArray::FGArray( const string &file ) {
|
||||||
// cout << "class FGArray CONstructor called." << endl;
|
// cout << "class FGArray CONstructor called." << endl;
|
||||||
in_data = new float[ARRAY_SIZE_1][ARRAY_SIZE_1];
|
in_data = new float[ARRAY_SIZE_1][ARRAY_SIZE_1];
|
||||||
out_data = new float[ARRAY_SIZE_1][ARRAY_SIZE_1];
|
// out_data = new float[ARRAY_SIZE_1][ARRAY_SIZE_1];
|
||||||
|
|
||||||
FGArray::open(file);
|
FGArray::open(file);
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,16 @@ FGArray::parse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// add a node to the output (fitted) node list
|
||||||
|
void FGArray::add_fit_node( int i, int j, double val ) {
|
||||||
|
double x = (originx + i * col_step) / 3600.0;
|
||||||
|
double y = (originy + j * row_step) / 3600.0;
|
||||||
|
cout << Point3D(x, y, val) << endl;
|
||||||
|
node_list.push_back( Point3D(x, y, val) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
// Initialize output mesh structure
|
// Initialize output mesh structure
|
||||||
void FGArray::outputmesh_init( void ) {
|
void FGArray::outputmesh_init( void ) {
|
||||||
int i, j;
|
int i, j;
|
||||||
|
@ -153,6 +163,7 @@ void FGArray::outputmesh_set_pt( int i, int j, double value ) {
|
||||||
// cout << "Setting data[" << i << "][" << j << "] = " << value << endl;
|
// cout << "Setting data[" << i << "][" << j << "] = " << value << endl;
|
||||||
out_data[i][j] = value;
|
out_data[i][j] = value;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Use least squares to fit a simpler data set to dem data
|
// Use least squares to fit a simpler data set to dem data
|
||||||
|
@ -170,7 +181,7 @@ void FGArray::fit( double error ) {
|
||||||
error_sq = error * error;
|
error_sq = error * error;
|
||||||
|
|
||||||
cout << " Initializing output mesh structure" << endl;
|
cout << " Initializing output mesh structure" << endl;
|
||||||
outputmesh_init();
|
// outputmesh_init();
|
||||||
|
|
||||||
// determine dimensions
|
// determine dimensions
|
||||||
colmin = 0;
|
colmin = 0;
|
||||||
|
@ -181,10 +192,10 @@ void FGArray::fit( double error ) {
|
||||||
<< colmax << "," << rowmax << endl;;
|
<< colmax << "," << rowmax << endl;;
|
||||||
|
|
||||||
// include the corners explicitly
|
// include the corners explicitly
|
||||||
outputmesh_set_pt(colmin, rowmin, in_data[colmin][rowmin]);
|
add_fit_node( colmin, rowmin, in_data[colmin][rowmin] );
|
||||||
outputmesh_set_pt(colmin, rowmax, in_data[colmin][rowmax]);
|
add_fit_node( colmin, rowmax-1, in_data[colmin][rowmax] );
|
||||||
outputmesh_set_pt(colmax, rowmax, in_data[colmax][rowmax]);
|
add_fit_node( colmax-1, rowmin, in_data[colmax][rowmin] );
|
||||||
outputmesh_set_pt(colmax, rowmin, in_data[colmax][rowmin]);
|
add_fit_node( colmax-1, rowmax-1, in_data[colmax][rowmax] );
|
||||||
|
|
||||||
cout << " Beginning best fit procedure" << endl;
|
cout << " Beginning best fit procedure" << endl;
|
||||||
lasty = 0;
|
lasty = 0;
|
||||||
|
@ -276,7 +287,7 @@ void FGArray::fit( double error ) {
|
||||||
if ( start > colmin ) {
|
if ( start > colmin ) {
|
||||||
// skip this for the first line segment
|
// skip this for the first line segment
|
||||||
cury = m * x[0] + b;
|
cury = m * x[0] + b;
|
||||||
outputmesh_set_pt(start, row, (lasty + cury) / 2);
|
add_fit_node( start, row, (lasty + cury) / 2 );
|
||||||
// fprintf(fit, "%.2f %.2f\n", x[0], (lasty + cury) / 2);
|
// fprintf(fit, "%.2f %.2f\n", x[0], (lasty + cury) / 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,11 +555,15 @@ void FGArray::outputmesh_output_nodes( const string& fg_root, FGBucket& p )
|
||||||
FGArray::~FGArray( void ) {
|
FGArray::~FGArray( void ) {
|
||||||
// printf("class FGArray DEstructor called.\n");
|
// printf("class FGArray DEstructor called.\n");
|
||||||
delete [] in_data;
|
delete [] in_data;
|
||||||
delete [] out_data;
|
// delete [] out_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.4 1999/03/20 20:32:51 curt
|
||||||
|
// First mostly successful tile triangulation works. There's plenty of tweaking
|
||||||
|
// to do, but we are marching in the right direction.
|
||||||
|
//
|
||||||
// Revision 1.3 1999/03/17 23:48:17 curt
|
// Revision 1.3 1999/03/17 23:48:17 curt
|
||||||
// Removed forced -g compile flag.
|
// Removed forced -g compile flag.
|
||||||
// Fixed a couple compiler warnings.
|
// Fixed a couple compiler warnings.
|
||||||
|
|
|
@ -31,14 +31,26 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include <Include/compiler.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <Bucket/newbucket.hxx>
|
#include <Bucket/newbucket.hxx>
|
||||||
|
#include <Math/point3d.hxx>
|
||||||
#include <Misc/fgstream.hxx>
|
#include <Misc/fgstream.hxx>
|
||||||
|
|
||||||
|
FG_USING_STD(vector);
|
||||||
|
|
||||||
|
|
||||||
#define ARRAY_SIZE 1200
|
#define ARRAY_SIZE 1200
|
||||||
#define ARRAY_SIZE_1 1201
|
#define ARRAY_SIZE_1 1201
|
||||||
|
|
||||||
|
|
||||||
|
typedef vector < Point3D > fitnode_list;
|
||||||
|
typedef fitnode_list::iterator fitnode_list_iterator;
|
||||||
|
typedef fitnode_list::const_iterator const_fitnode_list_iterator;
|
||||||
|
|
||||||
|
|
||||||
class FGArray {
|
class FGArray {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -58,37 +70,23 @@ private:
|
||||||
|
|
||||||
// pointers to the actual grid data allocated here
|
// pointers to the actual grid data allocated here
|
||||||
float (*in_data)[ARRAY_SIZE_1];
|
float (*in_data)[ARRAY_SIZE_1];
|
||||||
float (*out_data)[ARRAY_SIZE_1];
|
// float (*out_data)[ARRAY_SIZE_1];
|
||||||
|
|
||||||
// Current "A" Record Information
|
// output nodes
|
||||||
// char dem_description[80], dem_quadrangle[80];
|
fitnode_list node_list;
|
||||||
// double dem_x1, dem_y1, dem_x2, dem_y2, dem_x3, dem_y3, dem_x4, dem_y4;
|
|
||||||
// double dem_z1, dem_z2;
|
|
||||||
// int dem_resolution, dem_num_profiles;
|
|
||||||
|
|
||||||
// Current "B" Record Information
|
|
||||||
// int prof_col, prof_row;
|
|
||||||
// int prof_num_cols, prof_num_rows;
|
|
||||||
// double prof_x1, prof_y1;
|
|
||||||
// int prof_data;
|
|
||||||
|
|
||||||
// temporary values for the class to use
|
|
||||||
// char option_name[32];
|
|
||||||
// int do_data;
|
|
||||||
// int cur_col, cur_row;
|
|
||||||
|
|
||||||
// Initialize output mesh structure
|
// Initialize output mesh structure
|
||||||
void outputmesh_init( void );
|
// void outputmesh_init( void );
|
||||||
|
|
||||||
// Get the value of a mesh node
|
// Get the value of a mesh node
|
||||||
double outputmesh_get_pt( int i, int j );
|
// double outputmesh_get_pt( int i, int j );
|
||||||
|
|
||||||
// Set the value of a mesh node
|
// Set the value of a mesh node
|
||||||
void outputmesh_set_pt( int i, int j, double value );
|
// void outputmesh_set_pt( int i, int j, double value );
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// Write out a node file that can be used by the "triangle" program
|
// Write out a node file that can be used by the "triangle" program
|
||||||
void outputmesh_output_nodes( const string& fg_root, FGBucket& p );
|
// void outputmesh_output_nodes( const string& fg_root, FGBucket& p );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -112,6 +110,9 @@ public:
|
||||||
// Use least squares to fit a simpler data set to dem data
|
// Use least squares to fit a simpler data set to dem data
|
||||||
void fit( double error );
|
void fit( double error );
|
||||||
|
|
||||||
|
// add a node to the output (fitted) node list
|
||||||
|
void add_fit_node( int i, int j, double val );
|
||||||
|
|
||||||
// return the current altitude based on grid data. We should
|
// return the current altitude based on grid data. We should
|
||||||
// rewrite this to interpolate exact values, but for now this is
|
// rewrite this to interpolate exact values, but for now this is
|
||||||
// good enough
|
// good enough
|
||||||
|
@ -124,6 +125,8 @@ public:
|
||||||
inline int get_rows() const { return rows; }
|
inline int get_rows() const { return rows; }
|
||||||
inline double get_col_step() const { return col_step; }
|
inline double get_col_step() const { return col_step; }
|
||||||
inline double get_row_step() const { return row_step; }
|
inline double get_row_step() const { return row_step; }
|
||||||
|
|
||||||
|
inline fitnode_list get_fit_node_list() const { return node_list; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,6 +134,10 @@ public:
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.3 1999/03/20 20:32:52 curt
|
||||||
|
// First mostly successful tile triangulation works. There's plenty of tweaking
|
||||||
|
// to do, but we are marching in the right direction.
|
||||||
|
//
|
||||||
// Revision 1.2 1999/03/13 23:50:27 curt
|
// Revision 1.2 1999/03/13 23:50:27 curt
|
||||||
// Tweaked output formatting a bit.
|
// Tweaked output formatting a bit.
|
||||||
//
|
//
|
||||||
|
|
|
@ -7,6 +7,7 @@ construct_LDADD = \
|
||||||
$(top_builddir)/Tools/Construct/Clipper/libClipper.a \
|
$(top_builddir)/Tools/Construct/Clipper/libClipper.a \
|
||||||
$(top_builddir)/Tools/Construct/Triangulate/libTriangulate.a \
|
$(top_builddir)/Tools/Construct/Triangulate/libTriangulate.a \
|
||||||
$(top_builddir)/Tools/Lib/Polygon/libPolygon.a \
|
$(top_builddir)/Tools/Lib/Polygon/libPolygon.a \
|
||||||
|
$(top_builddir)/Tools/Lib/Triangle/libTriangle.a \
|
||||||
$(top_builddir)/Lib/Bucket/libBucket.a \
|
$(top_builddir)/Lib/Bucket/libBucket.a \
|
||||||
$(top_builddir)/Lib/Math/libMath.a \
|
$(top_builddir)/Lib/Math/libMath.a \
|
||||||
$(top_builddir)/Lib/Misc/libMisc.a \
|
$(top_builddir)/Lib/Misc/libMisc.a \
|
||||||
|
|
|
@ -32,8 +32,10 @@
|
||||||
#include <Triangulate/triangle.hxx>
|
#include <Triangulate/triangle.hxx>
|
||||||
|
|
||||||
|
|
||||||
// load regular grid of elevation data (dem based)
|
// load regular grid of elevation data (dem based), return list of
|
||||||
|
// fitted nodes
|
||||||
int load_dem(const string& work_base, FGBucket& b, FGArray& array) {
|
int load_dem(const string& work_base, FGBucket& b, FGArray& array) {
|
||||||
|
fitnode_list result;
|
||||||
char tile_name[256];
|
char tile_name[256];
|
||||||
string base = b.gen_base_path();
|
string base = b.gen_base_path();
|
||||||
long int b_index = b.gen_index();
|
long int b_index = b.gen_index();
|
||||||
|
@ -44,8 +46,10 @@ int load_dem(const string& work_base, FGBucket& b, FGArray& array) {
|
||||||
cout << "dem_path = " << dem_path << endl;
|
cout << "dem_path = " << dem_path << endl;
|
||||||
|
|
||||||
if ( ! array.open(dem_path) ) {
|
if ( ! array.open(dem_path) ) {
|
||||||
|
cout << "ERROR: cannot open " << dem_path << endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
array.parse();
|
array.parse();
|
||||||
array.fit( 100 );
|
array.fit( 100 );
|
||||||
|
|
||||||
|
@ -133,21 +137,26 @@ int load_polys( const string& work_base, FGBucket& b, FGClipper& clipper) {
|
||||||
|
|
||||||
|
|
||||||
// triangulate the data for each polygon
|
// triangulate the data for each polygon
|
||||||
void triangulate( const FGArray& array, const FGClipper& clipper,
|
void do_triangulate( const FGArray& array, const FGClipper& clipper,
|
||||||
FGTriangle& t ) {
|
FGTriangle& t ) {
|
||||||
// first we need to consolidate the points of all the polygons
|
// first we need to consolidate the points of the DEM fit list and
|
||||||
// into a more "Triangle" friendly format
|
// all the polygons into a more "Triangle" friendly format
|
||||||
FGgpcPolyList gpc_polys;
|
|
||||||
|
|
||||||
gpc_polys = clipper.get_polys_clipped();
|
fitnode_list fit_list = array.get_fit_node_list();
|
||||||
|
FGgpcPolyList gpc_polys = clipper.get_polys_clipped();
|
||||||
|
|
||||||
cout << "ready to build node list and polygons" << endl;
|
cout << "ready to build node list and polygons" << endl;
|
||||||
t.build( gpc_polys );
|
t.build( fit_list, gpc_polys );
|
||||||
cout << "done building node list and polygons" << endl;
|
cout << "done building node list and polygons" << endl;
|
||||||
|
|
||||||
|
cout << "ready to do triangulation" << endl;
|
||||||
|
t.run_triangulate();
|
||||||
|
cout << "finished triangulation" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
main(int argc, char **argv) {
|
main(int argc, char **argv) {
|
||||||
|
fitnode_list fit_list;
|
||||||
double lon, lat;
|
double lon, lat;
|
||||||
|
|
||||||
if ( argc != 2 ) {
|
if ( argc != 2 ) {
|
||||||
|
@ -173,11 +182,15 @@ main(int argc, char **argv) {
|
||||||
|
|
||||||
// triangulate the data for each polygon
|
// triangulate the data for each polygon
|
||||||
FGTriangle t;
|
FGTriangle t;
|
||||||
triangulate( array, clipper, t );
|
do_triangulate( array, clipper, t );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.4 1999/03/20 20:32:54 curt
|
||||||
|
// First mostly successful tile triangulation works. There's plenty of tweaking
|
||||||
|
// to do, but we are marching in the right direction.
|
||||||
|
//
|
||||||
// Revision 1.3 1999/03/19 00:26:52 curt
|
// Revision 1.3 1999/03/19 00:26:52 curt
|
||||||
// Minor tweaks ...
|
// Minor tweaks ...
|
||||||
//
|
//
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include "triangle.hxx"
|
#include "triangle.hxx"
|
||||||
#include "tripoly.hxx"
|
#include "tripoly.hxx"
|
||||||
|
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
FGTriangle::FGTriangle( void ) {
|
FGTriangle::FGTriangle( void ) {
|
||||||
}
|
}
|
||||||
|
@ -37,11 +36,23 @@ FGTriangle::~FGTriangle( void ) {
|
||||||
|
|
||||||
|
|
||||||
// populate this class based on the specified gpc_polys list
|
// populate this class based on the specified gpc_polys list
|
||||||
int FGTriangle::build( const FGgpcPolyList& gpc_polys ) {
|
int
|
||||||
|
FGTriangle::build( const fitnode_list& fit_list,
|
||||||
|
const FGgpcPolyList& gpc_polys )
|
||||||
|
{
|
||||||
int index;
|
int index;
|
||||||
// traverse the gpc_polys and build a unified node list and a set
|
|
||||||
// of Triangle PSLG that reference the node list by index
|
// traverse the dem fit list and gpc_polys building a unified node
|
||||||
// (starting at zero)
|
// list and converting the polygons so that they reference the
|
||||||
|
// node list by index (starting at zero) rather than listing the
|
||||||
|
// points explicitely
|
||||||
|
|
||||||
|
const_fitnode_list_iterator f_current, f_last;
|
||||||
|
f_current = fit_list.begin();
|
||||||
|
f_last = fit_list.end();
|
||||||
|
for ( ; f_current != f_last; ++f_current ) {
|
||||||
|
index = trinodes.unique_add( *f_current );
|
||||||
|
}
|
||||||
|
|
||||||
gpc_polygon *gpc_poly;
|
gpc_polygon *gpc_poly;
|
||||||
const_gpcpoly_iterator current, last;
|
const_gpcpoly_iterator current, last;
|
||||||
|
@ -67,7 +78,7 @@ int FGTriangle::build( const FGgpcPolyList& gpc_polys ) {
|
||||||
|
|
||||||
if (gpc_poly->num_contours > 1 ) {
|
if (gpc_poly->num_contours > 1 ) {
|
||||||
cout << "FATAL ERROR! no multi-contour support" << endl;
|
cout << "FATAL ERROR! no multi-contour support" << endl;
|
||||||
sleep(5);
|
sleep(2);
|
||||||
// exit(-1);
|
// exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,30 +104,31 @@ int FGTriangle::build( const FGgpcPolyList& gpc_polys ) {
|
||||||
<< polylist[i].size() << endl;
|
<< polylist[i].size() << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// traverse the polygon lists and build the segment (edge) list
|
||||||
|
// that is used by the "Triangle" lib.
|
||||||
|
|
||||||
// do actual triangulation
|
FGTriPoly poly;
|
||||||
int FGTriangle::do_triangulate( const FGTriPoly& poly ) {
|
int i1, i2;
|
||||||
trinode_list node_list;
|
for ( int i = 0; i < FG_MAX_AREA_TYPES; ++i ) {
|
||||||
struct triangulateio in, out;
|
cout << "area type = " << i << endl;
|
||||||
int counter;
|
tripoly_list_iterator tp_current, tp_last;
|
||||||
|
tp_current = polylist[i].begin();
|
||||||
|
tp_last = polylist[i].end();
|
||||||
|
|
||||||
// define input points
|
// process each polygon in list
|
||||||
node_list = trinodes.get_node_list();
|
for ( ; tp_current != tp_last; ++tp_current ) {
|
||||||
|
poly = *tp_current;
|
||||||
|
|
||||||
in.numberofpoints = node_list.size();
|
for ( int j = 0; j < (int)(poly.size()) - 1; ++j ) {
|
||||||
in.numberofpointattributes = 0;
|
i1 = poly.get_pt_index( j );
|
||||||
in.pointlist = (REAL *) malloc(in.numberofpoints * 2 * sizeof(REAL));
|
i2 = poly.get_pt_index( j + 1 );
|
||||||
|
trisegs.unique_add( FGTriSeg(i1, i2) );
|
||||||
trinode_list_iterator current, last;
|
}
|
||||||
current = node_list.begin();
|
i1 = poly.get_pt_index( 0 );
|
||||||
last = node_list.end();
|
i2 = poly.get_pt_index( poly.size() - 1 );
|
||||||
counter = 0;
|
trisegs.unique_add( FGTriSeg(i1, i2) );
|
||||||
for ( ; current != last; ++current ) {
|
}
|
||||||
in.pointlist[counter++] = current->x();
|
|
||||||
in.pointlist[counter++] = current->y();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -124,72 +136,175 @@ int FGTriangle::do_triangulate( const FGTriPoly& poly ) {
|
||||||
|
|
||||||
|
|
||||||
// triangulate each of the polygon areas
|
// triangulate each of the polygon areas
|
||||||
int FGTriangle::triangulate() {
|
int FGTriangle::run_triangulate() {
|
||||||
FGTriPoly poly;
|
FGTriPoly poly;
|
||||||
struct triangulateio in, out;
|
Point3D p;
|
||||||
|
struct triangulateio in, out, vorout;
|
||||||
trinode_list node_list = trinodes.get_node_list();
|
int counter;
|
||||||
|
|
||||||
// point list
|
// point list
|
||||||
|
trinode_list node_list = trinodes.get_node_list();
|
||||||
in.numberofpoints = node_list.size();
|
in.numberofpoints = node_list.size();
|
||||||
in.numberofpointattributes = 1;
|
|
||||||
in.pointlist = (REAL *) malloc(in.numberofpoints * 2 * sizeof(REAL));
|
in.pointlist = (REAL *) malloc(in.numberofpoints * 2 * sizeof(REAL));
|
||||||
|
|
||||||
trinode_list_iterator tn_current, tn_last;
|
trinode_list_iterator tn_current, tn_last;
|
||||||
tn_current = node_list.begin();
|
tn_current = node_list.begin();
|
||||||
tn_last = node_list.end();
|
tn_last = node_list.end();
|
||||||
int counter = 0;
|
counter = 0;
|
||||||
for ( ; tn_current != tn_last; ++tn_current ) {
|
for ( ; tn_current != tn_last; ++tn_current ) {
|
||||||
in.pointlist[counter++] = tn_current->x();
|
in.pointlist[counter++] = tn_current->x();
|
||||||
in.pointlist[counter++] = tn_current->y();
|
in.pointlist[counter++] = tn_current->y();
|
||||||
}
|
}
|
||||||
|
|
||||||
in.pointattributelist = (REAL *) NULL;
|
in.numberofpointattributes = 1;
|
||||||
in.pointmarkerlist = (int *) NULL;
|
in.pointattributelist = (REAL *) malloc(in.numberofpoints *
|
||||||
|
in.numberofpointattributes *
|
||||||
|
sizeof(REAL));
|
||||||
|
for ( int i = 0; i < in.numberofpoints * in.numberofpointattributes; i++) {
|
||||||
|
in.pointattributelist[i] = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
in.pointmarkerlist = (int *) malloc(in.numberofpoints * sizeof(int));
|
||||||
|
for ( int i = 0; i < in.numberofpoints; i++) {
|
||||||
|
in.pointmarkerlist[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// segment list
|
// segment list
|
||||||
in.numberofsegments = 0;
|
triseg_list seg_list = trisegs.get_seg_list();
|
||||||
|
in.numberofsegments = seg_list.size();
|
||||||
|
in.segmentlist = (int *) malloc(in.numberofsegments * 2 * sizeof(int));
|
||||||
|
|
||||||
tripoly_list_iterator tp_current, tp_last;
|
triseg_list_iterator s_current, s_last;
|
||||||
|
s_current = seg_list.begin();
|
||||||
|
s_last = seg_list.end();
|
||||||
|
counter = 0;
|
||||||
|
for ( ; s_current != s_last; ++s_current ) {
|
||||||
|
in.segmentlist[counter++] = s_current->get_n1();
|
||||||
|
in.segmentlist[counter++] = s_current->get_n2();
|
||||||
|
}
|
||||||
|
|
||||||
|
// hole list (make holes for airport ignore areas)
|
||||||
|
in.numberofholes = polylist[(int)AirportIgnoreArea].size();
|
||||||
|
in.holelist = (REAL *) malloc(in.numberofholes * 2 * sizeof(REAL));
|
||||||
|
|
||||||
|
tripoly_list_iterator h_current, h_last;
|
||||||
|
h_current = polylist[(int)AirportIgnoreArea].begin();
|
||||||
|
h_last = polylist[(int)AirportIgnoreArea].end();
|
||||||
|
counter = 0;
|
||||||
|
for ( ; h_current != h_last; ++h_current ) {
|
||||||
|
poly = *h_current;
|
||||||
|
p = poly.get_point_inside();
|
||||||
|
in.holelist[counter++] = p.x();
|
||||||
|
in.holelist[counter++] = p.y();
|
||||||
|
}
|
||||||
|
|
||||||
|
// region list
|
||||||
|
in.numberofregions = 0;
|
||||||
for ( int i = 0; i < FG_MAX_AREA_TYPES; ++i ) {
|
for ( int i = 0; i < FG_MAX_AREA_TYPES; ++i ) {
|
||||||
cout << "area type = " << i << endl;
|
in.numberofregions += polylist[i].size();
|
||||||
tp_current = polylist[i].begin();
|
|
||||||
tp_last = polylist[i].end();
|
|
||||||
for ( ; tp_current != tp_last; ++tp_current ) {
|
|
||||||
poly = *tp_current;
|
|
||||||
in.numberofsegments += poly.size() + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
in.numberofsegments = 0;
|
|
||||||
|
|
||||||
in.numberofholes = 0;
|
|
||||||
in.numberofregions = 1;
|
|
||||||
in.regionlist = (REAL *) malloc(in.numberofregions * 4 * sizeof(REAL));
|
in.regionlist = (REAL *) malloc(in.numberofregions * 4 * sizeof(REAL));
|
||||||
in.regionlist[0] = 0.5;
|
|
||||||
in.regionlist[1] = 5.0;
|
|
||||||
in.regionlist[2] = 7.0; /* Regional attribute (for whole mesh). */
|
|
||||||
in.regionlist[3] = 0.1; /* Area constraint that will not be used. */
|
|
||||||
|
|
||||||
/*
|
|
||||||
tripoly_list_iterator current, last;
|
|
||||||
for ( int i = 0; i < FG_MAX_AREA_TYPES; ++i ) {
|
for ( int i = 0; i < FG_MAX_AREA_TYPES; ++i ) {
|
||||||
cout << "area type = " << i << endl;
|
tripoly_list_iterator h_current, h_last;
|
||||||
current = polylist[i].begin();
|
h_current = polylist[(int)AirportIgnoreArea].begin();
|
||||||
last = polylist[i].end();
|
h_last = polylist[(int)AirportIgnoreArea].end();
|
||||||
for ( ; current != last; ++current ) {
|
counter = 0;
|
||||||
poly = *current;
|
for ( ; h_current != h_last; ++h_current ) {
|
||||||
cout << "triangulating a polygon, size = " << poly.size() << endl;
|
poly = *h_current;
|
||||||
|
p = poly.get_point_inside();
|
||||||
|
in.regionlist[counter++] = p.x(); // x coord
|
||||||
|
in.regionlist[counter++] = p.y(); // y coord
|
||||||
|
in.regionlist[counter++] = i; // region attribute
|
||||||
|
in.regionlist[counter++] = -1.0; // area constraint (unused)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
do_triangulate( poly );
|
// prep the output structures
|
||||||
|
out.pointlist = (REAL *) NULL; // Not needed if -N switch used.
|
||||||
|
// Not needed if -N switch used or number of point attributes is zero:
|
||||||
|
out.pointattributelist = (REAL *) NULL;
|
||||||
|
out.pointmarkerlist = (int *) NULL; // Not needed if -N or -B switch used.
|
||||||
|
out.trianglelist = (int *) NULL; // Not needed if -E switch used.
|
||||||
|
// Not needed if -E switch used or number of triangle attributes is zero:
|
||||||
|
out.triangleattributelist = (REAL *) NULL;
|
||||||
|
out.neighborlist = (int *) NULL; // Needed only if -n switch used.
|
||||||
|
// Needed only if segments are output (-p or -c) and -P not used:
|
||||||
|
out.segmentlist = (int *) NULL;
|
||||||
|
// Needed only if segments are output (-p or -c) and -P and -B not used:
|
||||||
|
out.segmentmarkerlist = (int *) NULL;
|
||||||
|
out.edgelist = (int *) NULL; // Needed only if -e switch used.
|
||||||
|
out.edgemarkerlist = (int *) NULL; // Needed if -e used and -B not used.
|
||||||
|
|
||||||
|
vorout.pointlist = (REAL *) NULL; // Needed only if -v switch used.
|
||||||
|
// Needed only if -v switch used and number of attributes is not zero:
|
||||||
|
vorout.pointattributelist = (REAL *) NULL;
|
||||||
|
vorout.edgelist = (int *) NULL; // Needed only if -v switch used.
|
||||||
|
vorout.normlist = (REAL *) NULL; // Needed only if -v switch used.
|
||||||
|
|
||||||
|
// Triangulate the points. Switches are chosen to read and write
|
||||||
|
// a PSLG (p), preserve the convex hull (c), number everything
|
||||||
|
// from zero (z), assign a regional attribute to each element (A),
|
||||||
|
// and produce an edge list (e), and a triangle neighbor list (n).
|
||||||
|
|
||||||
|
triangulate("pczAen", &in, &out, &vorout);
|
||||||
|
|
||||||
|
// TEMPORARY
|
||||||
|
//
|
||||||
|
|
||||||
|
// Write out the triangulated data to files so we can check
|
||||||
|
// visually that things seem reasonable
|
||||||
|
|
||||||
|
FILE *node = fopen("tile.node", "w");
|
||||||
|
fprintf(node, "%d 2 %d 0\n",
|
||||||
|
out.numberofpoints, out.numberofpointattributes);
|
||||||
|
for (int i = 0; i < out.numberofpoints; i++) {
|
||||||
|
fprintf(node, "%d %.6f %.6f %.2f\n",
|
||||||
|
i, out.pointlist[2*i], out.pointlist[2*i + 1], 0.0);
|
||||||
}
|
}
|
||||||
|
fclose(node);
|
||||||
|
|
||||||
|
FILE *ele = fopen("tile.ele", "w");
|
||||||
|
fprintf(ele, "%d 3 0\n", out.numberoftriangles);
|
||||||
|
for (int i = 0; i < out.numberoftriangles; i++) {
|
||||||
|
fprintf(ele, "%d ", i);
|
||||||
|
for (int j = 0; j < out.numberofcorners; j++) {
|
||||||
|
fprintf(ele, "%d ", out.trianglelist[i * out.numberofcorners + j]);
|
||||||
}
|
}
|
||||||
*/
|
fprintf(ele, "\n");
|
||||||
|
}
|
||||||
|
fclose(ele);
|
||||||
|
|
||||||
|
// free mem allocated to the "Triangle" structures
|
||||||
|
free(in.pointlist);
|
||||||
|
free(in.pointattributelist);
|
||||||
|
free(in.pointmarkerlist);
|
||||||
|
free(in.regionlist);
|
||||||
|
free(out.pointlist);
|
||||||
|
free(out.pointattributelist);
|
||||||
|
free(out.pointmarkerlist);
|
||||||
|
free(out.trianglelist);
|
||||||
|
free(out.triangleattributelist);
|
||||||
|
// free(out.trianglearealist);
|
||||||
|
free(out.neighborlist);
|
||||||
|
free(out.segmentlist);
|
||||||
|
free(out.segmentmarkerlist);
|
||||||
|
free(out.edgelist);
|
||||||
|
free(out.edgemarkerlist);
|
||||||
|
free(vorout.pointlist);
|
||||||
|
free(vorout.pointattributelist);
|
||||||
|
free(vorout.edgelist);
|
||||||
|
free(vorout.normlist);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.7 1999/03/20 20:32:55 curt
|
||||||
|
// First mostly successful tile triangulation works. There's plenty of tweaking
|
||||||
|
// to do, but we are marching in the right direction.
|
||||||
|
//
|
||||||
// Revision 1.6 1999/03/20 13:22:11 curt
|
// Revision 1.6 1999/03/20 13:22:11 curt
|
||||||
// Added trisegs.[ch]xx tripoly.[ch]xx.
|
// Added trisegs.[ch]xx tripoly.[ch]xx.
|
||||||
//
|
//
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <Array/array.hxx>
|
||||||
#include <Clipper/clipper.hxx>
|
#include <Clipper/clipper.hxx>
|
||||||
#include <Math/point3d.hxx>
|
#include <Math/point3d.hxx>
|
||||||
#include <Polygon/names.hxx>
|
#include <Polygon/names.hxx>
|
||||||
|
@ -46,6 +47,7 @@ extern "C" {
|
||||||
|
|
||||||
#include "trinodes.hxx"
|
#include "trinodes.hxx"
|
||||||
#include "tripoly.hxx"
|
#include "tripoly.hxx"
|
||||||
|
#include "trisegs.hxx"
|
||||||
|
|
||||||
FG_USING_STD(vector);
|
FG_USING_STD(vector);
|
||||||
|
|
||||||
|
@ -59,7 +61,13 @@ class FGTriangle {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
// list of nodes
|
||||||
FGTriNodes trinodes;
|
FGTriNodes trinodes;
|
||||||
|
|
||||||
|
// list of segments
|
||||||
|
FGTriSegments trisegs;
|
||||||
|
|
||||||
|
// polygon list
|
||||||
tripoly_list polylist[FG_MAX_AREA_TYPES];
|
tripoly_list polylist[FG_MAX_AREA_TYPES];
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -72,13 +80,10 @@ public:
|
||||||
int add_nodes();
|
int add_nodes();
|
||||||
|
|
||||||
// populate this class based on the specified gpc_polys list
|
// populate this class based on the specified gpc_polys list
|
||||||
int build( const FGgpcPolyList& gpc_polys );
|
int build( const fitnode_list& fit_list, const FGgpcPolyList& gpc_polys );
|
||||||
|
|
||||||
// do actual triangulation
|
|
||||||
int do_triangulate( const FGTriPoly& poly );
|
|
||||||
|
|
||||||
// front end triangulator for polygon list
|
// front end triangulator for polygon list
|
||||||
int triangulate();
|
int run_triangulate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,6 +91,10 @@ public:
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.6 1999/03/20 20:32:56 curt
|
||||||
|
// First mostly successful tile triangulation works. There's plenty of tweaking
|
||||||
|
// to do, but we are marching in the right direction.
|
||||||
|
//
|
||||||
// Revision 1.5 1999/03/20 02:21:53 curt
|
// Revision 1.5 1999/03/20 02:21:53 curt
|
||||||
// Continue shaping the code towards triangulation bliss. Added code to
|
// Continue shaping the code towards triangulation bliss. Added code to
|
||||||
// calculate some point guaranteed to be inside a polygon.
|
// calculate some point guaranteed to be inside a polygon.
|
||||||
|
|
|
@ -64,9 +64,13 @@ public:
|
||||||
// return size
|
// return size
|
||||||
inline int size() const { return poly.size(); }
|
inline int size() const { return poly.size(); }
|
||||||
|
|
||||||
|
// return the ith polygon point index
|
||||||
|
inline int get_pt_index( int i ) const { return poly[i]; }
|
||||||
|
|
||||||
// calculate an "arbitrary" point inside this polygon for
|
// calculate an "arbitrary" point inside this polygon for
|
||||||
// assigning attribute areas
|
// assigning attribute areas
|
||||||
void calc_point_inside( const FGTriNodes& trinodes );
|
void calc_point_inside( const FGTriNodes& trinodes );
|
||||||
|
inline Point3D get_point_inside() const { return inside; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -74,6 +78,10 @@ public:
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.2 1999/03/20 20:32:58 curt
|
||||||
|
// First mostly successful tile triangulation works. There's plenty of tweaking
|
||||||
|
// to do, but we are marching in the right direction.
|
||||||
|
//
|
||||||
// Revision 1.1 1999/03/20 13:21:36 curt
|
// Revision 1.1 1999/03/20 13:21:36 curt
|
||||||
// Initial revision.
|
// Initial revision.
|
||||||
//
|
//
|
||||||
|
|
|
@ -25,7 +25,48 @@
|
||||||
#include "trisegs.hxx"
|
#include "trisegs.hxx"
|
||||||
|
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
FGTriSegments::FGTriSegments( void ) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
FGTriSegments::~FGTriSegments( 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 FGTriSegments::unique_add( const FGTriSeg& s ) {
|
||||||
|
triseg_list_iterator current, last;
|
||||||
|
int counter = 0;
|
||||||
|
|
||||||
|
cout << s.get_n1() << "," << s.get_n2() << endl;
|
||||||
|
|
||||||
|
// see if point already exists
|
||||||
|
current = seg_list.begin();
|
||||||
|
last = seg_list.end();
|
||||||
|
for ( ; current != last; ++current ) {
|
||||||
|
if ( s == *current ) {
|
||||||
|
cout << "found an existing segment match" << endl;
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
++counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add to list
|
||||||
|
seg_list.push_back( s );
|
||||||
|
|
||||||
|
return counter;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.2 1999/03/20 20:32:59 curt
|
||||||
|
// First mostly successful tile triangulation works. There's plenty of tweaking
|
||||||
|
// to do, but we are marching in the right direction.
|
||||||
|
//
|
||||||
// Revision 1.1 1999/03/20 13:21:36 curt
|
// Revision 1.1 1999/03/20 13:21:36 curt
|
||||||
// Initial revision.
|
// Initial revision.
|
||||||
//
|
//
|
||||||
|
|
|
@ -40,10 +40,31 @@ FG_USING_STD(vector);
|
||||||
|
|
||||||
// a segment is two integer pointers into the node list
|
// a segment is two integer pointers into the node list
|
||||||
class FGTriSeg {
|
class FGTriSeg {
|
||||||
public:
|
|
||||||
int n1, n2;
|
int n1, n2;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
// Constructor and destructor
|
||||||
|
inline FGTriSeg( void ) { };
|
||||||
|
inline FGTriSeg( int i1, int i2 ) { n1 = i1; n2 = i2; }
|
||||||
|
|
||||||
|
inline ~FGTriSeg( void ) { };
|
||||||
|
|
||||||
|
inline int get_n1() const { return n1; }
|
||||||
|
inline void set_n1( int i ) { n1 = i; }
|
||||||
|
inline int get_n2() const { return n2; }
|
||||||
|
inline void set_n2( int i ) { n2 = i; }
|
||||||
|
|
||||||
|
friend bool operator == (const FGTriSeg& a, const FGTriSeg& b);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bool operator == (const FGTriSeg& a, const FGTriSeg& b)
|
||||||
|
{
|
||||||
|
return ((a.n1 == b.n1) && (a.n2 == b.n2))
|
||||||
|
|| ((a.n1 == b.n2) && (a.n2 == b.n1));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef vector < FGTriSeg > triseg_list;
|
typedef vector < FGTriSeg > triseg_list;
|
||||||
typedef triseg_list::iterator triseg_list_iterator;
|
typedef triseg_list::iterator triseg_list_iterator;
|
||||||
|
@ -78,6 +99,10 @@ public:
|
||||||
|
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.2 1999/03/20 20:33:00 curt
|
||||||
|
// First mostly successful tile triangulation works. There's plenty of tweaking
|
||||||
|
// to do, but we are marching in the right direction.
|
||||||
|
//
|
||||||
// Revision 1.1 1999/03/20 13:21:36 curt
|
// Revision 1.1 1999/03/20 13:21:36 curt
|
||||||
// Initial revision.
|
// Initial revision.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in a new issue