1
0
Fork 0

Debugging various problems with prepairing input that triangle() can

handle.
This commit is contained in:
curt 1999-05-19 02:51:07 +00:00
parent accb6a88ff
commit 1cbe332e1c
7 changed files with 117 additions and 60 deletions

View file

@ -54,6 +54,9 @@ class FGConstruct {
private: private:
// minimum interior angle for triangulation
string angle;
// paths // paths
string work_base; string work_base;
string output_base; string output_base;
@ -101,6 +104,10 @@ public:
// Destructor // Destructor
~FGConstruct(); ~FGConstruct();
// minimum interior angle for triangulation
inline string get_angle() const { return angle; }
inline void set_angle( const string s ) { angle = s; }
// paths // paths
inline string get_work_base() const { return work_base; } inline string get_work_base() const { return work_base; }
inline void set_work_base( const string s ) { work_base = s; } inline void set_work_base( const string s ) { work_base = s; }

View file

@ -167,7 +167,7 @@ void first_triangulate( FGConstruct& c, const FGArray& array,
cout << "done building node list and polygons" << endl; cout << "done building node list and polygons" << endl;
cout << "ready to do triangulation" << endl; cout << "ready to do triangulation" << endl;
t.run_triangulate( 1 ); t.run_triangulate( c.get_angle(), 1 );
cout << "finished triangulation" << endl; cout << "finished triangulation" << endl;
} }
@ -179,7 +179,7 @@ void second_triangulate( FGConstruct& c, FGTriangle& t ) {
cout << "done re building node list and polygons" << endl; cout << "done re building node list and polygons" << endl;
cout << "ready to do second triangulation" << endl; cout << "ready to do second triangulation" << endl;
t.run_triangulate( 2 ); t.run_triangulate( c.get_angle(), 2 );
cout << "finished second triangulation" << endl; cout << "finished second triangulation" << endl;
} }
@ -461,9 +461,9 @@ void construct_tile( FGConstruct& c ) {
// display usage and exit // display usage and exit
void usage( const string name ) { void usage( const string name ) {
cout << "Usage: " << name cout << "Usage: " << name
<< " <work_base> <output_base> tile_id" << endl; << " <min_tri_angle> <work_base> <output_base> tile_id" << endl;
cout << "Usage: " << name cout << "Usage: " << name
<< " <work_base> <output_base> center_lon center_lat xdist ydist" << " <min_tri_angle> <work_base> <output_base> center_lon center_lat xdist ydist"
<< endl; << endl;
exit(-1); exit(-1);
} }
@ -474,15 +474,16 @@ main(int argc, char **argv) {
fglog().setLogLevels( FG_ALL, FG_DEBUG ); fglog().setLogLevels( FG_ALL, FG_DEBUG );
if ( argc < 3 ) { if ( argc < 4 ) {
usage( argv[0] ); usage( argv[0] );
} }
// main construction data management class // main construction data management class
FGConstruct c; FGConstruct c;
c.set_work_base( argv[1] ); c.set_angle( argv[1] );
c.set_output_base( argv[2] ); c.set_work_base( argv[2] );
c.set_output_base( argv[3] );
c.set_min_nodes( 50 ); c.set_min_nodes( 50 );
c.set_max_nodes( (int)(FG_MAX_NODES * 0.8) ); c.set_max_nodes( (int)(FG_MAX_NODES * 0.8) );
@ -506,20 +507,20 @@ main(int argc, char **argv) {
// lon = -76.201239; lat = 36.894606; // KORF (Norfolk, Virginia) // lon = -76.201239; lat = 36.894606; // KORF (Norfolk, Virginia)
// lon = -147.166; lat = 60.9925; // Hale-bop test // lon = -147.166; lat = 60.9925; // Hale-bop test
if ( argc == 4 ) { if ( argc == 5 ) {
// construct a specific tile and exit // construct a specific tile and exit
long index = atoi( argv[3] ); long index = atoi( argv[4] );
FGBucket b( index ); FGBucket b( index );
c.set_bucket( b ); c.set_bucket( b );
construct_tile( c ); construct_tile( c );
} else if ( argc == 7 ) { } else if ( argc == 8 ) {
// build all the tiles in an area // build all the tiles in an area
lon = atof( argv[3] ); lon = atof( argv[4] );
lat = atof( argv[4] ); lat = atof( argv[5] );
double xdist = atof( argv[5] ); double xdist = atof( argv[6] );
double ydist = atof( argv[6] ); double ydist = atof( argv[7] );
double min_x = lon - xdist; double min_x = lon - xdist;
double min_y = lat - ydist; double min_y = lat - ydist;

View file

@ -110,25 +110,42 @@ long int get_next_task( const string& host, int port, long int last_tile ) {
// successfully // successfully
bool construct_tile( const string& work_base, const string& output_base, bool construct_tile( const string& work_base, const string& output_base,
const FGBucket& b, const string& result_file ) { const FGBucket& b, const string& result_file ) {
string command = "../Main/construct " + work_base + " " + output_base + " " double angle = 10.0;
+ b.gen_index_str() + " > " + result_file + " 2>&1"; bool still_trying = true;
cout << command << endl;
system( command.c_str() ); while ( still_trying ) {
still_trying = false;
FILE *fp = fopen( result_file.c_str(), "r" ); char angle_str[256];
char line[256]; sprintf(angle_str, "%.0f", angle);
while ( fgets( line, 256, fp ) != NULL ) { string command = "../Main/construct ";
string line_str = line; command += angle_str;
line_str = line_str.substr(0, line_str.length() - 1); command += " " + work_base + " " + output_base + " "
cout << line_str << endl; + b.gen_index_str() + " > " + result_file + " 2>&1";
if ( line_str == "[Finished successfully]" ) { cout << command << endl;
fclose(fp);
return true; system( command.c_str() );
FILE *fp = fopen( result_file.c_str(), "r" );
char line[256];
while ( fgets( line, 256, fp ) != NULL ) {
string line_str = line;
line_str = line_str.substr(0, line_str.length() - 1);
cout << line_str << endl;
if ( line_str == "[Finished successfully]" ) {
fclose(fp);
return true;
} else if ( line_str == "Error: Ran out of precision at" ) {
if ( angle > 9.0 ) {
angle = 5.0;
still_trying = true;
} else if ( angle > 4.0 ) {
angle = 0.0;
still_trying = true;
}
}
} }
fclose(fp);
} }
fclose(fp);
return false; return false;
} }

View file

@ -273,7 +273,7 @@ static void write_out_data(struct triangulateio *out) {
// generates extra nodes for a better triangulation. 2 = second pass // generates extra nodes for a better triangulation. 2 = second pass
// after split/reassem where we don't want any extra nodes generated. // after split/reassem where we don't want any extra nodes generated.
int FGTriangle::run_triangulate( int pass ) { int FGTriangle::run_triangulate( const string& angle, const int pass ) {
FGPolygon poly; FGPolygon poly;
Point3D p; Point3D p;
struct triangulateio in, out, vorout; struct triangulateio in, out, vorout;
@ -414,7 +414,11 @@ int FGTriangle::run_triangulate( int pass ) {
// use a quality value of 10 (q10) meaning no interior // use a quality value of 10 (q10) meaning no interior
// triangle angles less than 10 degrees // triangle angles less than 10 degrees
// tri_options = "pczAen"; // tri_options = "pczAen";
tri_options = "pczq10Aen"; if ( angle == "0" ) {
tri_options = "pczAen";
} else {
tri_options = "pczq" + angle + "Aen";
}
// // string tri_options = "pzAen"; // // string tri_options = "pzAen";
// // string tri_options = "pczq15S400Aen"; // // string tri_options = "pczq15S400Aen";
} else if ( pass == 2 ) { } else if ( pass == 2 ) {

View file

@ -91,7 +91,7 @@ public:
// generates extra nodes for a better triangulation. 2 = second // generates extra nodes for a better triangulation. 2 = second
// pass after split/reassem where we don't want any extra nodes // pass after split/reassem where we don't want any extra nodes
// generated. // generated.
int run_triangulate( int pass ); int run_triangulate( const string& angle, const int pass );
inline FGTriNodes get_out_nodes() const { return out_nodes; } inline FGTriNodes get_out_nodes() const { return out_nodes; }
inline size_t get_out_nodes_size() const { return out_nodes.size(); } inline size_t get_out_nodes_size() const { return out_nodes.size(); }

View file

@ -37,7 +37,7 @@
#include <Main/construct_types.hxx> #include <Main/construct_types.hxx>
#define FG_PROXIMITY_EPSILON 0.000001 #define FG_PROXIMITY_EPSILON 0.00002
#define FG_COURSE_EPSILON 0.0003 #define FG_COURSE_EPSILON 0.0003

View file

@ -47,6 +47,13 @@ int FGTriSegments::unique_add( const FGTriSeg& s )
// cout << s.get_n1() << "," << s.get_n2() << endl; // cout << s.get_n1() << "," << s.get_n2() << endl;
// check if segment has duplicated endpoints
if ( s.get_n1() == s.get_n2() ) {
cout << "WARNING: ignoring null segment with the same "
<< "point for both endpoints" << endl;
return -1;
}
// check if segment already exists // check if segment already exists
current = seg_list.begin(); current = seg_list.begin();
last = seg_list.end(); last = seg_list.end();
@ -77,7 +84,7 @@ void FGTriSegments::unique_divide_and_add( const point_list& nodes,
bool found_extra = false; bool found_extra = false;
int extra_index = 0; int extra_index = 0;
int counter; int counter;
double m, b, y_err, x_err; double m, m1, b, b1, y_err, x_err, y_err_min, x_err_min;
const_point_list_iterator current, last; const_point_list_iterator current, last;
// bool temp = false; // bool temp = false;
@ -86,7 +93,12 @@ void FGTriSegments::unique_divide_and_add( const point_list& nodes,
// temp = true; // temp = true;
// } // }
if ( fabs(p0.x() - p1.x()) > 3 * FG_EPSILON ) { double xdist = fabs(p0.x() - p1.x());
double ydist = fabs(p0.y() - p1.y());
x_err_min = xdist + 1.0;
y_err_min = ydist + 1.0;
if ( xdist > ydist ) {
// use y = mx + b // use y = mx + b
// sort these in a sensible order // sort these in a sensible order
@ -116,48 +128,64 @@ void FGTriSegments::unique_divide_and_add( const point_list& nodes,
y_err = fabs(current->y() - (m * current->x() + b)); y_err = fabs(current->y() - (m * current->x() + b));
if ( y_err < 20 * FG_EPSILON ) { if ( y_err < FG_PROXIMITY_EPSILON ) {
// cout << "FOUND EXTRA SEGMENT NODE (Y)" << endl; cout << "FOUND EXTRA SEGMENT NODE (Y)" << endl;
// cout << p0 << " < " << *current << " < " cout << p0 << " < " << *current << " < "
// << p1 << endl; << p1 << endl;
found_extra = true; found_extra = true;
extra_index = counter; if ( y_err < y_err_min ) {
break; extra_index = counter;
y_err_min = y_err;
}
} }
} }
++counter; ++counter;
} }
} else { } else {
// use x = constant // use x = m1 * y + b1
// cout << "FOUND VERTICLE SEGMENT" << endl; // sort these in a sensible order
// sort these in a sensable order
if ( p0.y() > p1.y() ) { if ( p0.y() > p1.y() ) {
Point3D tmp = p0; Point3D tmp = p0;
p0 = p1; p0 = p1;
p1 = tmp; p1 = tmp;
} }
// cout << " p0 = " << p0 << " p1 = " << p1 << endl; m1 = (p0.x() - p1.x()) / (p0.y() - p1.y());
b1 = p1.x() - m1 * p1.y();
// bool temp = true;
// if ( temp ) {
// cout << "xdist = " << xdist << " ydist = " << ydist << endl;
// cout << " p0 = " << p0 << " p1 = " << p1 << endl;
// cout << " m1 = " << m1 << " b1 = " << b1 << endl;
// }
// cout << " should = 0 = " << fabs(p0.x() - (m1 * p0.y() + b1)) << endl;;
// cout << " should = 0 = " << fabs(p1.x() - (m1 * p1.y() + b1)) << endl;;
current = nodes.begin(); current = nodes.begin();
last = nodes.end(); last = nodes.end();
counter = 0; counter = 0;
for ( ; current != last; ++current ) { for ( ; current != last; ++current ) {
// cout << counter << endl; if ( (current->y() > (p0.y() + FG_EPSILON))
if ( (current->y() > (p0.y() + FG_EPSILON))
&& (current->y() < (p1.y() - FG_EPSILON)) ) { && (current->y() < (p1.y() - FG_EPSILON)) ) {
x_err = fabs(current->x() - p0.x());
// cout << " found a potential point, x err = " x_err = fabs(current->x() - (m1 * current->y() + b1));
// << x_err << endl;
if ( x_err < 20 * FG_EPSILON ) { // if ( temp ) {
// cout << "FOUND EXTRA SEGMENT NODE (X)" << endl; // cout << " (" << counter << ") x_err = " << x_err << endl;
// cout << p0 << " < " << *current << " < " // }
// << p1 << endl;
if ( x_err < FG_PROXIMITY_EPSILON ) {
cout << "FOUND EXTRA SEGMENT NODE (X)" << endl;
cout << p0 << " < " << *current << " < "
<< p1 << endl;
found_extra = true; found_extra = true;
extra_index = counter; if ( x_err < x_err_min ) {
break; extra_index = counter;
x_err_min = x_err;
}
} }
} }
++counter; ++counter;
@ -166,8 +194,8 @@ void FGTriSegments::unique_divide_and_add( const point_list& nodes,
if ( found_extra ) { if ( found_extra ) {
// recurse with two sub segments // recurse with two sub segments
// cout << "dividing " << s.get_n1() << " " << extra_index cout << "dividing " << s.get_n1() << " " << extra_index
// << " " << s.get_n2() << endl; << " " << s.get_n2() << endl;
unique_divide_and_add( nodes, FGTriSeg( s.get_n1(), extra_index ) ); unique_divide_and_add( nodes, FGTriSeg( s.get_n1(), extra_index ) );
unique_divide_and_add( nodes, FGTriSeg( extra_index, s.get_n2() ) ); unique_divide_and_add( nodes, FGTriSeg( extra_index, s.get_n2() ) );
} else { } else {