}
-// triangulate the data for each polygon
-void do_triangulate( FGConstruct& c, const FGArray& array,
+// triangulate the data for each polygon ( first time before splitting )
+void first_triangulate( FGConstruct& c, const FGArray& array,
FGTriangle& t ) {
// first we need to consolidate the points of the DEM fit list and
// all the polygons into a more "Triangle" friendly format
cout << "done building node list and polygons" << endl;
cout << "ready to do triangulation" << endl;
- t.run_triangulate();
+ t.run_triangulate( 1 );
cout << "finished triangulation" << endl;
}
+// triangulate the data for each polygon ( second time after splitting
+// and reassembling )
+void second_triangulate( FGConstruct& c, FGTriangle& t ) {
+ t.rebuild( c );
+ cout << "done re building node list and polygons" << endl;
+
+ cout << "ready to do second triangulation" << endl;
+ t.run_triangulate( 2 );
+ cout << "finished second triangulation" << endl;
+}
+
+
// build the wgs-84 point list (and fix the elevations of the geodetic
// nodes)
static void fix_point_heights( FGConstruct& c, const FGArray& array ) {
// generate the flight gear scenery file
-void do_output( FGConstruct& c, const FGTriangle& t,
- const FGArray& array, FGGenOutput& output ) {
+void do_output( FGConstruct& c, FGGenOutput& output ) {
output.build( c );
output.write( c );
}
array.fit( error );
// triangulate the data for each polygon
- do_triangulate( c, array, t );
+ first_triangulate( c, array, t );
acceptable = true;
m.assemble_tile( c );
// now we must retriangulate the pasted together tile points
+ second_triangulate( c, t );
+
+ // save the results of the triangulation
+ c.set_tri_nodes( t.get_out_nodes() );
+ c.set_tri_elements( t.get_elelist() );
+ c.set_tri_segs( t.get_out_segs() );
+
+ // calculate wgs84 (cartesian) form of node list
+ fix_point_heights( c, array );
// generate the output
FGGenOutput output;
- do_output( c, t, array, output );
+ do_output( c, output );
}
}
+// populate this class based on the specified gpc_polys list
+int FGTriangle::rebuild( FGConstruct& c ) {
+ in_nodes.clear();
+ in_segs.clear();
+
+ in_nodes = c.get_tri_nodes();
+ in_segs = c.get_tri_segs();
+
+ return 0;
+}
+
+
static void write_out_data(struct triangulateio *out) {
FILE *node = fopen("tile.node", "w");
fprintf(node, "%d 2 %d 0\n",
}
-// triangulate each of the polygon areas
-int FGTriangle::run_triangulate() {
+// Front end triangulator for polygon list. Allocates and builds up
+// all the needed structures for the triangulator, runs it, copies the
+// results, and frees all the data structures used by the
+// triangulator. "pass" can be 1 or 2. 1 = first pass which
+// generates extra nodes for a better triangulation. 2 = second pass
+// after split/reassem where we don't want any extra nodes generated.
+
+int FGTriangle::run_triangulate( int pass ) {
FGPolygon poly;
Point3D p;
struct triangulateio in, out, vorout;
// from zero (z), assign a regional attribute to each element (A),
// and produce an edge list (e), and a triangle neighbor list (n).
- string tri_options = "pczq10Aen";
- // string tri_options = "pzAen";
- // string tri_options = "pczq15S400Aen";
+ string tri_options;
+ if ( pass == 1 ) {
+ // use a quality value of 10 (q10) meaning no interior
+ // triangle angles less than 10 degrees
+ tri_options = "pczq10Aen";
+ // string tri_options = "pzAen";
+ // string tri_options = "pczq15S400Aen";
+ } else if ( pass == 2 ) {
+ // no new points on boundary (Y), no internal segment
+ // splitting (YY), no quality refinement ()
+ tri_options = "pczYYAen";
+ } else {
+ cout << "unknown pass number = " << pass
+ << " in FGTriangle::run_triangulate()" << endl;
+ exit(-1);
+ }
cout << "Triangulation with options = " << tri_options << endl;
triangulate(tri_options.c_str(), &in, &out, &vorout);
#include <Array/array.hxx>
#include <Clipper/clipper.hxx>
+#include <Main/construct.hxx>
#include <Math/point3d.hxx>
#include <Polygon/names.hxx>
const point_list& fit_list,
const FGgpcPolyList& gpc_polys );
- // front end triangulator for polygon list
- int run_triangulate();
+ // populate this class based on the specified gpc_polys list
+ int rebuild( FGConstruct& c );
+
+ // Front end triangulator for polygon list. Allocates and builds
+ // up all the needed structures for the triangulator, runs it,
+ // copies the results, and frees all the data structures used by
+ // the triangulator. "pass" can be 1 or 2. 1 = first pass which
+ // generates extra nodes for a better triangulation. 2 = second
+ // pass after split/reassem where we don't want any extra nodes
+ // generated.
+ int run_triangulate( int pass );
inline FGTriNodes get_out_nodes() const { return out_nodes; }
inline size_t get_out_nodes_size() const { return out_nodes.size(); }