#include <dirent.h> // for directory reading
#include <Bucket/newbucket.hxx>
+#include <Include/fg_constants.h>
#include <Debug/logstream.hxx>
#include <Array/array.hxx>
if ( ! array.open(dem_path) ) {
cout << "ERROR: cannot open " << dem_path << endl;
- return 0;
}
- array.parse();
- array.fit( 200 );
+ array.parse( b );
return 1;
}
+// fit dem nodes, return number of fitted nodes
+int fit_dem(FGArray& array, int error) {
+ return array.fit( error );
+}
+
// do actual scan of directory and loading of files
int actual_load_polys( const string& dir, FGBucket& b, FGClipper& clipper ) {
{
cout << "Construct tile, bucket = " << b << endl;
+ // fit with ever increasing error tolerance until we produce <=
+ // 80% of max nodes. We should really have the sim end handle
+ // arbitrarily complex tiles.
+
+ const int min_nodes = 50;
+ const int max_nodes = (int)(MAX_NODES * 0.8);
+
+ bool acceptable = false;
+ double error = 200.0;
+ int count = 0;
+
// load and fit grid of elevation data
FGArray array;
load_dem( work_base, b, array );
- // load and clip 2d polygon data
- FGClipper clipper;
- load_polys( work_base, b, clipper );
-
- // triangulate the data for each polygon
FGTriangle t;
- do_triangulate( array, clipper, t );
+
+ while ( ! acceptable ) {
+ // fit the data
+ array.fit( error );
+
+ // load and clip 2d polygon data
+ FGClipper clipper;
+ load_polys( work_base, b, clipper );
+
+ // triangulate the data for each polygon
+ do_triangulate( array, clipper, t );
+
+ acceptable = true;
+
+ count = t.get_out_nodes_size();
+
+ if ( (count < min_nodes) && (error >= 25.0) ) {
+ // reduce error tolerance until number of points exceeds the
+ // minimum threshold
+ cout << "produced too few nodes ..." << endl;
+
+ acceptable = false;
+
+ error /= 1.5;
+ cout << "Setting error to " << error << " and retrying fit."
+ << endl;
+ }
+
+ if ( (count > max_nodes) && (error <= 1000.0) ) {
+ // increase error tolerance until number of points drops below
+ // the maximum threshold
+ cout << "produced too many nodes ..." << endl;
+
+ acceptable = false;
+
+ error *= 1.5;
+ cout << "Setting error to " << error << " and retrying fit."
+ << endl;
+ }
+ }
+
+ cout << "finished fit with error = " << error << " node count = "
+ << count << endl;
// generate the output
FGGenOutput output;
// lon = -90.757128; lat = 46.790212; // WI32
// lon = -122.220717; lat = 37.721291; // KOAK
// lon = -111.721477; lat = 40.215641; // KPVU
- lon = -122.309313; lat = 47.448982; // KSEA
+ // lon = -122.309313; lat = 47.448982; // KSEA
+ lon = -148.798131; lat = 63.645099; // AK06 (Danali, AK)
- double min_x = lon - 1;
+ double min_x = lon - 3;
double min_y = lat - 1;
FGBucket b_min( min_x, min_y );
- FGBucket b_max( lon + 1, lat + 1 );
+ FGBucket b_max( lon + 3, lat + 1 );
FGBucket b_omit(550314L);
- // FGBucket b(942698L);
+ // FGBucket b(517745L);
// FGBucket b(-146.248360, 61.133950);
// construct_tile( work_base, output_base, b );
// exit(0);
// $Log$
+// Revision 1.18 1999/04/05 02:16:51 curt
+// Dynamically update "error" until the resulting tile data scales within
+// a lower and upper bounds.
+//
// Revision 1.17 1999/04/03 05:22:57 curt
// Found a bug in dividing and adding unique verticle segments which could
// cause the triangulator to end up in an infinite loop. Basically the code
FGTriPoly poly;
int index;
+ in_nodes.clear();
+ trisegs.clear();
+
// Point3D junkp;
// int junkc = 0;
// char junkn[256];
cout << "prepairing node list and polygons" << endl;
for ( int i = 0; i < FG_MAX_AREA_TYPES; ++i ) {
+ polylist[i].clear();
+
// cout << "area type = " << i << endl;
current = gpc_polys.polys[i].begin();
last = gpc_polys.polys[i].end();
vorout.normlist = (REAL *) NULL; // Needed only if -v switch used.
// TEMPORARY
- write_out_data(&in);
+ // write_out_data(&in);
// Triangulate the points. Switches are chosen to read and write
// a PSLG (p), preserve the convex hull (c), number everything
triangulate(tri_options.c_str(), &in, &out, &vorout);
// TEMPORARY
- // write_out_data(&out);
+ write_out_data(&out);
// now copy the results back into the corresponding FGTriangle
// structures
// nodes
+ out_nodes.clear();
for ( int i = 0; i < out.numberofpoints; i++ ) {
Point3D p( out.pointlist[2*i], out.pointlist[2*i + 1], 0.0 );
// cout << "point = " << p << endl;
}
// triangles
+ elelist.clear();
int n1, n2, n3;
double attribute;
for ( int i = 0; i < out.numberoftriangles; i++ ) {
// $Log$
+// Revision 1.16 1999/04/05 02:17:11 curt
+// Dynamically update "error" until the resulting tile data scales within
+// a lower and upper bounds.
+//
// Revision 1.15 1999/04/03 05:22:58 curt
// Found a bug in dividing and adding unique verticle segments which could
// cause the triangulator to end up in an infinite loop. Basically the code
FGTriNodes( void );
~FGTriNodes( void );
+ // delete all the data out of node_list
+ inline void clear() { node_list.clear(); }
+
// 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 );
// return the ith point
inline Point3D get_node( int i ) const { return node_list[i]; }
+
+ // return the size of the node list
+ inline size_t size() const { return node_list.size(); }
};
// $Log$
+// Revision 1.8 1999/04/05 02:17:13 curt
+// Dynamically update "error" until the resulting tile data scales within
+// a lower and upper bounds.
+//
// Revision 1.7 1999/03/29 13:11:10 curt
// Shuffled stl type names a bit.
// Began adding support for tri-fanning (or maybe other arrangments too.)