--- /dev/null
+// array.cxx -- Array management class
+//
+// Written by Curtis Olson, started March 1998.
+//
+// Copyright (C) 1998 - 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$
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+
+#include "match.hxx"
+
+
+
+FGMatch::FGMatch( void ) {
+}
+
+
+FGMatch::~FGMatch( void ) {
+}
+
+
+// extract the shared edge points, normals, and segments. This must
+// be done after calling load_neighbor_data() and will ignore any
+// shared data from the current tile that already exists from a
+// neighbor.
+void FGMatch::extract_shared( FGConstruct& c ) {
+
+ cout << "Extracting (shared) edge nodes and normals" << endl;
+
+ // calculate tile boundaries
+ point2d min, max;
+ FGBucket b = c.get_bucket();
+ min.x = b.get_center_lon() - 0.5 * b.get_width();
+ min.y = b.get_center_lat() - 0.5 * b.get_height();
+ max.x = b.get_center_lon() + 0.5 * b.get_width();
+ max.y = b.get_center_lat() + 0.5 * b.get_height();
+
+ // separate nodes and normals into components
+
+ north_nodes.clear();
+ south_nodes.clear();
+ east_nodes.clear();
+ west_nodes.clear();
+ body_nodes.clear();
+
+ point_list nodes = c.get_geod_nodes();
+ point_list point_normals = c.get_point_normals();
+
+ for ( int i = 0; i < (int)nodes.size(); ++i ) {
+ Point3D node = nodes[i];
+ Point3D normal = point_normals[i];
+
+ if ( (fabs(node.y() - min.y) < FG_EPSILON) &&
+ (fabs(node.x() - min.x) < FG_EPSILON) ) {
+ sw_node = node;
+ sw_normal = normal;
+ } else if ( (fabs(node.y() - min.y) < FG_EPSILON) &&
+ (fabs(node.x() - max.x) < FG_EPSILON) ) {
+ se_node = node;
+ se_normal = normal;
+ } else if ( (fabs(node.y() - max.y) < FG_EPSILON) &&
+ (fabs(node.x() - max.x) < FG_EPSILON)) {
+ ne_node = node;
+ ne_normal = normal;
+ } else if ( (fabs(node.y() - max.y) < FG_EPSILON) &&
+ (fabs(node.x() - min.x) < FG_EPSILON) ) {
+ nw_node = node;
+ nw_normal = normal;
+ } else if ( fabs(node.x() - min.x) < FG_EPSILON ) {
+ west_nodes.push_back( node );
+ west_normals.push_back( normal );
+ } else if ( fabs(node.x() - max.x) < FG_EPSILON ) {
+ east_nodes.push_back( node );
+ east_normals.push_back( normal );
+ } else if ( fabs(node.y() - min.y) < FG_EPSILON ) {
+ south_nodes.push_back( node );
+ south_normals.push_back( normal );
+ } else if ( fabs(node.y() - max.y) < FG_EPSILON ) {
+ north_nodes.push_back( node );
+ north_normals.push_back( normal );
+ } else {
+ body_nodes.push_back( node );
+ body_normals.push_back( normal );
+ }
+ }
+
+ // separate area edge segment into components
+ cout << "Extracting (shared) area edge segments" << endl;
+
+ FGTriSeg seg;
+ Point3D p1, p2;
+ triseg_list seg_list = c.get_tri_segs().get_seg_list();
+ triseg_list_iterator current = seg_list.begin();
+ triseg_list_iterator last = seg_list.end();
+
+ for ( ; current != last; ++current ) {
+ seg = *current;
+ p1 = nodes[ seg.get_n1() ];
+ p2 = nodes[ seg.get_n2() ];
+
+ if ( fabs(p1.y() - p2.y()) < FG_EPSILON ) {
+ // check if horizontal
+ if ( fabs(p1.y() - max.y) < FG_EPSILON ) {
+ north_segs.push_back( seg );
+ } else if ( fabs(p1.y() - min.y) < FG_EPSILON ) {
+ south_segs.push_back( seg );
+ } else {
+ body_segs.push_back( seg );
+ }
+ } else if ( fabs(p1.x() - p2.x()) < FG_EPSILON ) {
+ // check if vertical
+ if ( fabs(p1.x() - max.x) < FG_EPSILON ) {
+ east_segs.push_back( seg );
+ } else if ( fabs(p1.x() - min.x) < FG_EPSILON ) {
+ west_segs.push_back( seg );
+ } else {
+ body_segs.push_back( seg );
+ }
+ } else {
+ body_segs.push_back( seg );
+ }
+ }
+}
+
+
+// write the shared edge points, normals, and segments for this tile
+void FGMatch::write_shared( FGConstruct& c ) {
+ string base = c.get_work_base();
+ FGBucket b = c.get_bucket();
+
+ string dir = base + ".shared/Scenery/" + b.gen_base_path();
+ string command = "mkdir -p " + dir;
+ string file = dir + "/" + b.gen_index_str();
+ cout << "shared data will be written to " << file << endl;
+
+ system(command.c_str());
+
+ FILE *fp;
+ if ( (fp = fopen( file.c_str(), "w" )) == NULL ) {
+ cout << "ERROR: opening " << file << " for writing!" << endl;
+ exit(-1);
+ }
+
+ fprintf( fp, "sw_node %.6f %.6f %.6f\n",
+ sw_node.x(), sw_node.y(), sw_node.z() );
+ fprintf( fp, "sw_normal %.6f %.6f %.6f\n",
+ sw_normal.x(), sw_normal.y(), sw_normal.z() );
+
+ fprintf( fp, "se_node %.6f %.6f %.6f\n",
+ se_node.x(), se_node.y(), se_node.z() );
+ fprintf( fp, "se_normal %.6f %.6f %.6f\n",
+ se_normal.x(), se_normal.y(), se_normal.z() );
+
+ fprintf( fp, "nw_node %.6f %.6f %.6f\n",
+ nw_node.x(), nw_node.y(), nw_node.z() );
+ fprintf( fp, "nw_normal %.6f %.6f %.6f\n",
+ nw_normal.x(), nw_normal.y(), nw_normal.z() );
+
+ fprintf( fp, "ne_node %.6f %.6f %.6f\n",
+ ne_node.x(), ne_node.y(), ne_node.z() );
+ fprintf( fp, "ne_normal %.6f %.6f %.6f\n",
+ ne_normal.x(), ne_normal.y(), ne_normal.z() );
+
+ for ( int i = 0; i < (int)north_nodes.size(); ++i ) {
+ fprintf( fp, "n_node %.6f %.6f %.6f\n",
+ north_nodes[i].x(), north_nodes[i].y(), north_nodes[i].z() );
+ fprintf( fp, "n_normal %.6f %.6f %.6f\n",
+ north_normals[i].x(), north_normals[i].y(),
+ north_normals[i].z() );
+ }
+
+ for ( int i = 0; i < (int)south_nodes.size(); ++i ) {
+ fprintf( fp, "s_node %.6f %.6f %.6f\n",
+ south_nodes[i].x(), south_nodes[i].y(), south_nodes[i].z() );
+ fprintf( fp, "s_normal %.6f %.6f %.6f\n",
+ south_normals[i].x(), south_normals[i].y(),
+ south_normals[i].z() );
+ }
+
+ for ( int i = 0; i < (int)east_nodes.size(); ++i ) {
+ fprintf( fp, "e_node %.6f %.6f %.6f\n",
+ east_nodes[i].x(), east_nodes[i].y(), east_nodes[i].z() );
+ fprintf( fp, "e_normal %.6f %.6f %.6f\n",
+ east_normals[i].x(), east_normals[i].y(),
+ east_normals[i].z() );
+ }
+
+ for ( int i = 0; i < (int)west_nodes.size(); ++i ) {
+ fprintf( fp, "w_node %.6f %.6f %.6f\n",
+ west_nodes[i].x(), west_nodes[i].y(), west_nodes[i].z() );
+ fprintf( fp, "w_normal %.6f %.6f %.6f\n",
+ west_normals[i].x(), west_normals[i].y(),
+ west_normals[i].z() );
+ }
+
+ point_list nodes = c.get_geod_nodes();
+ Point3D p1, p2;
+
+ for ( int i = 0; i < (int)north_segs.size(); ++i ) {
+ p1 = nodes[ north_segs[i].get_n1() ];
+ p2 = nodes[ north_segs[i].get_n2() ];
+ fprintf( fp, "n_seg %.6f %.6f %.6f %.6f\n",
+ p1.x(), p1.y(), p2.x(), p2.y() );
+ }
+
+ for ( int i = 0; i < (int)south_segs.size(); ++i ) {
+ p1 = nodes[ south_segs[i].get_n1() ];
+ p2 = nodes[ south_segs[i].get_n2() ];
+ fprintf( fp, "s_seg %.6f %.6f %.6f %.6f\n",
+ p1.x(), p1.y(), p2.x(), p2.y() );
+ }
+
+ for ( int i = 0; i < (int)east_segs.size(); ++i ) {
+ p1 = nodes[ east_segs[i].get_n1() ];
+ p2 = nodes[ east_segs[i].get_n2() ];
+ fprintf( fp, "e_seg %.6f %.6f %.6f %.6f\n",
+ p1.x(), p1.y(), p2.x(), p2.y() );
+ }
+
+ for ( int i = 0; i < (int)west_segs.size(); ++i ) {
+ p1 = nodes[ west_segs[i].get_n1() ];
+ p2 = nodes[ west_segs[i].get_n2() ];
+ fprintf( fp, "w_seg %.6f %.6f %.6f %.6f\n",
+ p1.x(), p1.y(), p2.x(), p2.y() );
+ }
+
+ fclose( fp );
+}
--- /dev/null
+// match.hxx -- Class to help match up tile edges
+//
+// Written by Curtis Olson, started April 1999.
+//
+// Copyright (C) 1998 - 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$
+
+
+#ifndef _MATCH_HXX
+#define _MATCH_HXX
+
+
+#ifndef __cplusplus
+# error This library requires C++
+#endif
+
+
+#include <Include/compiler.h>
+
+#include <Bucket/newbucket.hxx>
+
+#include <Main/construct_types.hxx>
+#include <Main/construct.hxx>
+
+
+class FGMatch {
+
+private:
+
+ // nodes breakdown
+ Point3D sw_node, se_node, ne_node, nw_node;
+ point_list north_nodes, south_nodes, east_nodes, west_nodes;
+ point_list body_nodes;
+
+ // normals breakdown
+ Point3D sw_normal, se_normal, ne_normal, nw_normal;
+ point_list north_normals, south_normals, east_normals, west_normals;
+ point_list body_normals;
+
+ // segment breakdown
+ triseg_list north_segs, south_segs, east_segs, west_segs;
+ triseg_list body_segs;
+
+public:
+
+ // Constructor
+ FGMatch( void );
+
+ // Destructor
+ ~FGMatch( void );
+
+ // load any previously existing shared data from all neighbors
+ void load_neighbor_data();
+
+ // extract the shared edge points, normals, and segments. This
+ // must be done after calling load_neighbor_data() and will ignore
+ // any shared data from the current tile that already exists from
+ // a neighbor.
+ void extract_shared( FGConstruct& c );
+
+ // write the shared edge points, normals, and segments for this tile
+ void write_shared( FGConstruct& c );
+};
+
+
+#endif // _MATCH_HXX