1
0
Fork 0

whitespace only

This commit is contained in:
scttgs0 2023-05-07 18:41:09 -05:00
parent 631bc02111
commit d021c32840
12 changed files with 385 additions and 354 deletions

View file

@ -178,8 +178,6 @@ bool Airport::isDebugFeature( int feat )
return dbg;
}
void Airport::BuildBtg(const std::string& root, const string_list& elev_src )
{
tgcontour_list slivers;

View file

@ -158,7 +158,7 @@ private:
SGTimeStamp triangulation_time;
// debug
std::string debug_path;
std::string debug_path;
debug_map debug_runways;
debug_map debug_pavements;
debug_map debug_taxiways;

View file

@ -611,7 +611,6 @@ void Runway::gen_rwy( tgpolygon_list& rwy_polys,
runway_half.AddNode( 0, runway.GetNode(5) );
runway_half.AddNode( 0, runway.GetNode(2) );
}
else {
heading = rwy.heading;

View file

@ -19,7 +19,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
// $Id: names.hxx,v 1.14 2005-09-28 16:43:18 curt Exp $
#ifndef _PRIORITIES_HXX
#define _PRIORITIES_HXX
@ -31,11 +31,11 @@
#include <terragear/tg_polygon.hxx>
class TGAreaDefinition {
class TGAreaDefinition
{
public:
TGAreaDefinition( const std::string& n, const std::string& c, unsigned int p ) :
name(n),
category(c)
TGAreaDefinition(const std::string& n, const std::string& c, unsigned int p) : name(n),
category(c)
{
priority = p;
smooth_method = 0;
@ -43,128 +43,143 @@ public:
default_layer = 0;
};
std::string const& GetName() const {
std::string const& GetName() const
{
return name;
}
unsigned int GetPriority() const {
unsigned int GetPriority() const
{
return priority;
}
std::string const& GetCategory() const {
std::string const& GetCategory() const
{
return category;
}
private:
std::string name;
std::string name;
unsigned int priority;
std::string category;
std::string category;
// future improvements
unsigned int smooth_method;
tgTexMethod texture_method;
bool layered;
tgTexMethod texture_method;
bool layered;
unsigned int default_layer;
};
typedef std::vector<TGAreaDefinition> area_definition_list;
typedef area_definition_list::const_iterator area_definition_iterator;
class TGAreaDefinitions {
class TGAreaDefinitions
{
public:
TGAreaDefinitions() :
sliver_area_name("<unnamed>")
TGAreaDefinitions() : sliver_area_name("<unnamed>")
{
sliver_area_priority = 0;
};
int init( const std::string& filename );
unsigned int size() const {
int init(const std::string& filename);
unsigned int size() const
{
return area_defs.size();
}
bool is_hole_area( unsigned int p ) const {
if ( area_defs[p].GetCategory() == "hole" ) {
bool is_hole_area(unsigned int p) const
{
if (area_defs[p].GetCategory() == "hole") {
return true;
} else {
return false;
}
}
bool is_landmass_area( unsigned int p ) const {
if (( area_defs[p].GetCategory() == "landmass" ) ||
( area_defs[p].GetCategory() == "other" ) ||
( area_defs[p].GetCategory() == "cliff" )) {
bool is_landmass_area(unsigned int p) const
{
if ((area_defs[p].GetCategory() == "landmass") ||
(area_defs[p].GetCategory() == "other") ||
(area_defs[p].GetCategory() == "cliff")) {
return true;
} else {
return false;
}
}
bool is_island_area( unsigned int p ) const {
if ( area_defs[p].GetCategory() == "island" ) {
bool is_island_area(unsigned int p) const
{
if (area_defs[p].GetCategory() == "island") {
return true;
} else {
return false;
}
}
bool is_road_area( unsigned int p ) const {
if ( area_defs[p].GetCategory() == "road" ) {
bool is_road_area(unsigned int p) const
{
if (area_defs[p].GetCategory() == "road") {
return true;
} else {
return false;
}
}
bool is_water_area( unsigned int p ) const {
if ( ( area_defs[p].GetCategory() == "ocean" ) ||
( area_defs[p].GetCategory() == "lake" ) ){
bool is_water_area(unsigned int p) const
{
if ((area_defs[p].GetCategory() == "ocean") ||
(area_defs[p].GetCategory() == "lake")) {
return true;
} else {
return false;
}
}
bool is_lake_area( unsigned int p ) const {
if ( area_defs[p].GetCategory() == "lake" ) {
bool is_lake_area(unsigned int p) const
{
if (area_defs[p].GetCategory() == "lake") {
return true;
} else {
return false;
}
}
bool is_stream_area( unsigned int p ) const {
if ( area_defs[p].GetCategory() == "stream" ) {
bool is_stream_area(unsigned int p) const
{
if (area_defs[p].GetCategory() == "stream") {
return true;
} else {
return false;
}
}
bool is_ocean_area( unsigned int p ) const {
if ( area_defs[p].GetCategory() == "ocean" ) {
bool is_ocean_area(unsigned int p) const
{
if (area_defs[p].GetCategory() == "ocean") {
return true;
} else {
return false;
}
}
bool is_cliff_area( unsigned int p ) const {
if (area_defs[p].GetCategory() == "cliff" ) {
return true;
} else {
return false;
}
}
bool is_cliff_area(unsigned int p) const
{
if (area_defs[p].GetCategory() == "cliff") {
return true;
} else {
return false;
}
}
std::string const& get_area_name( unsigned int p ) const {
std::string const& get_area_name(unsigned int p) const
{
return area_defs[p].GetName();
}
unsigned int get_area_priority( const std::string& name ) const {
for (unsigned int i=0; i < area_defs.size(); i++) {
if ( area_defs[i].GetName() == name ) {
unsigned int get_area_priority(const std::string& name) const
{
for (unsigned int i = 0; i < area_defs.size(); i++) {
if (area_defs[i].GetName() == name) {
return i;
}
}
@ -175,18 +190,20 @@ public:
}
std::string const& get_sliver_area_name( void ) const {
std::string const& get_sliver_area_name(void) const
{
return sliver_area_name;
}
unsigned int get_sliver_area_priority( void ) const {
unsigned int get_sliver_area_priority(void) const
{
return sliver_area_priority;
}
private:
area_definition_list area_defs;
std::string sliver_area_name;
std::string sliver_area_name;
unsigned int sliver_area_priority;
};

View file

@ -26,33 +26,33 @@
#define _CONSTRUCT_HXX
#ifndef __cplusplus
# error This library requires C++
#endif
#ifndef __cplusplus
#error This library requires C++
#endif
#include <simgear/threads/SGThread.hxx>
#include <simgear/threads/SGQueue.hxx>
#include <simgear/threads/SGThread.hxx>
#include <Array/array.hxx>
#include <terragear/tg_nodes.hxx>
#include <landcover/landcover.hxx>
#include <terragear/tg_nodes.hxx>
#include "tglandclass.hxx"
#include "priorities.hxx"
#define FIND_SLIVERS (0)
#define FIND_SLIVERS (0)
// Stage2 shared edge data
struct TGNeighborFaces {
public:
SGGeod node;
SGGeod node;
double_list elevations; // we'll take the average
double_list elevations; // we'll take the average
double_list face_areas;
std::vector<SGVec3f> face_normals;
};
typedef std::vector < TGNeighborFaces > neighbor_face_list;
typedef std::vector<TGNeighborFaces> neighbor_face_list;
typedef neighbor_face_list::iterator neighbor_face_list_iterator;
typedef neighbor_face_list::const_iterator const_neighbor_face_list_iterator;
@ -60,14 +60,14 @@ class TGConstruct : public SGThread
{
public:
// Constructor
TGConstruct( const TGAreaDefinitions& areas, unsigned int s, SGLockedQueue<SGBucket>& q, SGMutex* l );
TGConstruct(const TGAreaDefinitions& areas, unsigned int s, SGLockedQueue<SGBucket>& q, SGMutex* l);
// Destructor
~TGConstruct();
// New shared edge matching
void SaveToIntermediateFiles( int stage );
void LoadFromIntermediateFiles( int stage );
void SaveToIntermediateFiles(int stage);
void LoadFromIntermediateFiles(int stage);
#if 0
int load_landcover ();
@ -83,93 +83,96 @@ public:
#endif
// paths
void set_paths( const std::string& work, const std::string& share, const std::string& match,
const std::string& output, const std::vector<std::string>& load_dirs );
void set_options( bool ignore_lm, double n );
void set_paths(const std::string& work, const std::string& share, const std::string& match,
const std::string& output, const std::vector<std::string>& load_dirs);
void set_options(bool ignore_lm, double n);
// TODO : REMOVE
inline TGNodes* get_nodes() { return &nodes; }
// node list in geodetic coords (with fixed elevation)
inline void get_geod_nodes( std::vector<SGGeod>& points ) const { nodes.get_geod_nodes( points ); }
inline void get_geod_nodes(std::vector<SGGeod>& points) const { nodes.get_geod_nodes(points); }
// normal list (for each point) in cart coords (for smooth shading)
inline void get_point_normals( std::vector<SGVec3f>& normals ) const { nodes.get_normals( normals ); }
inline void get_point_normals(std::vector<SGVec3f>& normals) const { nodes.get_normals(normals); }
// Debug
void set_debug( std::string path, std::vector<std::string> area_defs, std::vector<std::string> shape_defs );
void set_debug(std::string path, std::vector<std::string> area_defs, std::vector<std::string> shape_defs);
void CreateMatchedEdgeFiles(std::vector<SGBucket>& bucketList);
void CreateMatchedEdgeFiles( std::vector<SGBucket>& bucketList );
private:
virtual void run();
// Ocean tile or not
bool IsOceanTile() { return isOcean; }
bool IsOceanTile() { return isOcean; }
// Load Data
void LoadElevationArray( bool add_nodes );
int LoadLandclassPolys( void );
bool CheckMatchingNode( SGGeod& node, bool road, bool fixed );
SGGeod GetNearestNodeLatitude( const SGGeod& node, const std::vector<SGGeod>& selection );
SGGeod GetNearestNodeLongitude( const SGGeod& node, const std::vector<SGGeod>& selection );
void LoadElevationArray(bool add_nodes);
int LoadLandclassPolys(void);
bool CheckMatchingNode(SGGeod& node, bool road, bool fixed);
SGGeod GetNearestNodeLatitude(const SGGeod& node, const std::vector<SGGeod>& selection);
SGGeod GetNearestNodeLongitude(const SGGeod& node, const std::vector<SGGeod>& selection);
// Clip Data
bool ClipLandclassPolys( void );
bool ClipLandclassPolys(void);
// Clip Helpers
// void move_slivers( TGPolygon& in, TGPolygon& out );
// void merge_slivers( TGLandclass& clipped, tgcontour_list& sliver_list );
// void move_slivers( TGPolygon& in, TGPolygon& out );
// void merge_slivers( TGLandclass& clipped, tgcontour_list& sliver_list );
// Shared edge Matching
void SaveSharedEdgeData( int stage );
void LoadSharedEdgeData( int stage );
void writeGeodCollection(std::vector<SGGeod>&, gzFile&);
void writeFaceCollection(std::string&&, std::vector<SGGeod>&);
void SaveSharedEdgeData(int stage);
void LoadSharedEdgeData(int stage);
void LoadMatchedEdge(int, int);
void LoadMatchedEdgeFiles();
void LoadNeighboorEdgeDataStage1( SGBucket& b, std::vector<SGGeod>& north, std::vector<SGGeod>& south, std::vector<SGGeod>& east, std::vector<SGGeod>& west );
void LoadNeighboorMatchDataStage1( SGBucket& b, std::vector<SGGeod>& north, std::vector<SGGeod>& south, std::vector<SGGeod>& east, std::vector<SGGeod>& west );
void LoadNeighborEdgeDataStage1(SGBucket& b, std::vector<SGGeod>& north, std::vector<SGGeod>& south, std::vector<SGGeod>& east, std::vector<SGGeod>& west);
void LoadNeighborMatchDataStage1(SGBucket& b, std::vector<SGGeod>& north, std::vector<SGGeod>& south, std::vector<SGGeod>& east, std::vector<SGGeod>& west);
void ReadNeighborFaces( gzFile& fp );
void WriteNeighborFaces( gzFile& fp, const SGGeod& pt ) const;
TGNeighborFaces* AddNeighborFaces( const SGGeod& node );
TGNeighborFaces* FindNeighborFaces( const SGGeod& node );
void ReadNeighborFaces(gzFile& fp);
void WriteNeighborFaces(gzFile& fp, const SGGeod& pt) const;
TGNeighborFaces* AddNeighborFaces(const SGGeod& node);
TGNeighborFaces* FindNeighborFaces(const SGGeod& node);
// Polygon Cleaning
void CleanClippedPolys( void );
void FixTJunctions( void );
void CleanClippedPolys(void);
void FixTJunctions(void);
// Tesselation
void TesselatePolys( void );
void TesselatePolys(void);
// Elevation and Flattening
void CalcElevations( void );
void AverageEdgeElevations( void );
void CalcElevations(void);
void AverageEdgeElevations(void);
// Normals and texture coords
void LookupNodesPerVertex( void );
void LookupFacesPerNode( void );
void CalcFaceNormals( void );
void CalcPointNormals( void );
void CalcTextureCoordinates( void );
void LookupNodesPerVertex(void);
void LookupFacesPerNode(void);
void CalcFaceNormals(void);
void CalcPointNormals(void);
void CalcTextureCoordinates(void);
// Helpers
SGVec3f calc_normal( double area, const SGVec3d& p1, const SGVec3d& p2, const SGVec3d& p3 ) const;
SGVec3f calc_normal(double area, const SGVec3d& p1, const SGVec3d& p2, const SGVec3d& p3) const;
// Output
void WriteBtgFile( void );
void AddCustomObjects( void );
void WriteBtgFile(void);
void AddCustomObjects(void);
// Misc
void calc_normals( std::vector<SGGeod>& geod_nodes, std::vector<SGVec3d>& wgs84_nodes, tgPolygon& sp );
void calc_normals(std::vector<SGGeod>& geod_nodes, std::vector<SGVec3d>& wgs84_nodes, tgPolygon& sp);
// debug
void get_debug( void );
bool IsDebugShape( unsigned int id );
bool IsDebugArea( unsigned int area );
void get_debug(void);
bool IsDebugShape(unsigned int id);
bool IsDebugArea(unsigned int area);
private:
TGAreaDefinitions const& area_defs;
// construct stage to perform
SGLockedQueue<SGBucket>& workQueue;
unsigned int total_tiles;
@ -187,7 +190,7 @@ private:
std::vector<std::string> load_dirs;
const static double gSnap; // approx 1 mm
const static double gSnap; // approx 1 mm
// flag indicating whether to ignore the landmass
bool ignoreLandmass;
@ -209,11 +212,11 @@ private:
std::vector<unsigned int> debug_shapes;
// OGR encode variables for debug:
void* ds_id; // If we are going to build shapefiles
void* l_id; // datasource and layer IDs
char ds_name[128];
char layer_name[128];
char feature_name[128];
void* ds_id; // If we are going to build shapefiles
void* l_id; // datasource and layer IDs
char ds_name[128];
char layer_name[128];
char feature_name[128];
// this bucket
SGBucket bucket;
@ -234,10 +237,10 @@ private:
unsigned int num_areas;
// Neighbor Faces
neighbor_face_list neighbor_faces;
neighbor_face_list neighbor_faces;
// file lock
SGMutex* lock;
SGMutex* lock;
};
#endif // _CONSTRUCT_HXX

View file

@ -22,7 +22,7 @@
// $Id: construct.cxx,v 1.4 2004-11-19 22:25:49 curt Exp $
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <config.h>
#endif
#include <simgear/compiler.h>
@ -32,28 +32,29 @@
#include "tgconstruct.hxx"
void TGConstruct::FixTJunctions( void ) {
void TGConstruct::FixTJunctions(void)
{
int before, after;
std::vector<TGNode*> points;
tgRectangle bb;
// traverse each poly, and add intermediate nodes
for ( unsigned int i = 0; i < area_defs.size(); ++i ) {
for( unsigned int j = 0; j < polys_clipped.area_size(i); ++j ) {
for (unsigned int i = 0; i < area_defs.size(); ++i) {
for (unsigned int j = 0; j < polys_clipped.area_size(i); ++j) {
tgPolygon current = polys_clipped.get_poly(i, j);
bb = current.GetBoundingBox();
nodes.get_nodes_inside( bb.getMin(), bb.getMax(), points );
nodes.get_nodes_inside(bb.getMin(), bb.getMax(), points);
before = current.TotalNodes();
current = tgPolygon::AddColinearNodes( current, points );
after = current.TotalNodes();
before = current.TotalNodes();
current = tgPolygon::AddColinearNodes(current, points);
after = current.TotalNodes();
if (before != after) {
SG_LOG( SG_CLIPPER, SG_DEBUG, "Fixed T-Junctions in " << area_defs.get_area_name(i) << ":" << j+1 << " of " << (int)polys_clipped.area_size(i) << " nodes increased from " << before << " to " << after );
SG_LOG(SG_CLIPPER, SG_DEBUG, "Fixed T-Junctions in " << area_defs.get_area_name(i) << ":" << j + 1 << " of " << (int)polys_clipped.area_size(i) << " nodes increased from " << before << " to " << after);
}
/* Save it back */
polys_clipped.set_poly( i, j, current );
polys_clipped.set_poly(i, j, current);
}
}
}
@ -81,33 +82,34 @@ void TGConstruct::merge_slivers( TGLandclass& clipped, tgcontour_list& sliver_l
}
#endif
void TGConstruct::CleanClippedPolys() {
void TGConstruct::CleanClippedPolys()
{
// Clean the polys
for ( unsigned int area = 0; area < area_defs.size(); area++ ) {
for( unsigned int p = 0; p < polys_clipped.area_size(area); p++ ) {
for (unsigned int area = 0; area < area_defs.size(); area++) {
for (unsigned int p = 0; p < polys_clipped.area_size(area); p++) {
char layer[32];
tgPolygon poly = polys_clipped.get_poly(area, p);
// step 1 : snap
poly = tgPolygon::Snap(poly, gSnap);
if ( IsDebugShape( poly.GetId() ) ) {
sprintf(layer, "snapped_%d", poly.GetId() );
tgShapefile::FromPolygon( poly, ds_name, layer, "poly" );
if (IsDebugShape(poly.GetId())) {
sprintf(layer, "snapped_%d", poly.GetId());
tgShapefile::FromPolygon(poly, ds_name, layer, "poly");
}
// step 2 : remove_dups
poly = tgPolygon::RemoveDups( poly );
if ( IsDebugShape( poly.GetId() ) ) {
sprintf(layer, "rem_dups_%d", poly.GetId() );
tgShapefile::FromPolygon( poly, ds_name, layer, "poly" );
poly = tgPolygon::RemoveDups(poly);
if (IsDebugShape(poly.GetId())) {
sprintf(layer, "rem_dups_%d", poly.GetId());
tgShapefile::FromPolygon(poly, ds_name, layer, "poly");
}
// step 3 : remove cycles
poly = tgPolygon::RemoveCycles( poly );
if ( IsDebugShape( poly.GetId() ) ) {
sprintf(layer, "rem_cycles_%d", poly.GetId() );
tgShapefile::FromPolygon( poly, ds_name, layer, "poly" );
poly = tgPolygon::RemoveCycles(poly);
if (IsDebugShape(poly.GetId())) {
sprintf(layer, "rem_cycles_%d", poly.GetId());
tgShapefile::FromPolygon(poly, ds_name, layer, "poly");
}
polys_clipped.set_poly(area, p, poly);
@ -115,28 +117,28 @@ void TGConstruct::CleanClippedPolys() {
}
}
void TGConstruct::AverageEdgeElevations( void )
void TGConstruct::AverageEdgeElevations(void)
{
for ( unsigned int i = 0; i < neighbor_faces.size(); i++ ) {
for (unsigned int i = 0; i < neighbor_faces.size(); i++) {
TGNeighborFaces faces = neighbor_faces[i];
double elevation = 0.0;
unsigned int num_elevations = faces.elevations.size();
for ( unsigned int j = 0; j < num_elevations; j++ ) {
for (unsigned int j = 0; j < num_elevations; j++) {
elevation += faces.elevations[j];
}
elevation = elevation / num_elevations;
/* Find this node, and update it's elevation */
int idx = nodes.find( faces.node );
int idx = nodes.find(faces.node);
if (idx != -1) {
TGNode const& node = nodes.get_node( idx );
TGNode const& node = nodes.get_node(idx);
if ( !node.GetFixedPosition() ) {
if (!node.GetFixedPosition()) {
// set elevation as the average between all tiles that have it
nodes.SetElevation( idx, elevation );
nodes.SetElevation(idx, elevation);
}
}
}

View file

@ -21,7 +21,7 @@
// $Id: construct.cxx,v 1.4 2004-11-19 22:25:49 curt Exp $
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <config.h>
#endif
#include <sstream>
@ -32,7 +32,7 @@
using std::string;
void TGConstruct::set_debug( std::string path, std::vector<string> a_defs, std::vector<string> s_defs )
void TGConstruct::set_debug(std::string path, std::vector<string> a_defs, std::vector<string> s_defs)
{
debug_path = path;
@ -40,7 +40,7 @@ void TGConstruct::set_debug( std::string path, std::vector<string> a_defs, std::
debug_shape_defs = s_defs;
}
void TGConstruct::get_debug( void )
void TGConstruct::get_debug(void)
{
// clear out any previous entries
debug_areas.clear();
@ -48,20 +48,19 @@ void TGConstruct::get_debug( void )
/* Find any ids for our tile */
for (unsigned int i = 0; i < debug_area_defs.size(); ++i) {
string dsd = debug_area_defs[i];
size_t d_pos = dsd.find(":");
string tile = dsd.substr(0, d_pos);
string dsd = debug_area_defs[i];
size_t d_pos = dsd.find(":");
string tile = dsd.substr(0, d_pos);
if ( tile == bucket.gen_index_str() ) {
if (tile == bucket.gen_index_str()) {
dsd.erase(0, d_pos + 1);
if ( dsd == "all" ) {
if (dsd == "all") {
debug_all = true;
} else {
std::stringstream ss(dsd);
int idx;
while (ss >> idx)
{
while (ss >> idx) {
SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug area " << idx);
debug_areas.push_back(idx);
@ -74,20 +73,19 @@ void TGConstruct::get_debug( void )
}
for (unsigned int i = 0; i < debug_shape_defs.size(); ++i) {
string dsd = debug_shape_defs[i];
size_t d_pos = dsd.find(":");
string tile = dsd.substr(0, d_pos);
string dsd = debug_shape_defs[i];
size_t d_pos = dsd.find(":");
string tile = dsd.substr(0, d_pos);
if ( tile == bucket.gen_index_str() ) {
if (tile == bucket.gen_index_str()) {
dsd.erase(0, d_pos + 1);
if ( dsd == "all" ) {
if (dsd == "all") {
debug_all = true;
} else {
std::stringstream ss(dsd);
int idx;
while (ss >> idx)
{
while (ss >> idx) {
SG_LOG(SG_GENERAL, SG_ALERT, "Adding debug shape " << idx);
debug_shapes.push_back(idx);
@ -100,16 +98,16 @@ void TGConstruct::get_debug( void )
}
}
bool TGConstruct::IsDebugShape( unsigned int id )
bool TGConstruct::IsDebugShape(unsigned int id)
{
bool is_debug = false;
/* Check global flag */
if ( debug_all ) {
if (debug_all) {
is_debug = true;
} else {
for (unsigned int i=0; i<debug_shapes.size(); i++) {
if ( debug_shapes[i] == id ) {
for (unsigned int i = 0; i < debug_shapes.size(); i++) {
if (debug_shapes[i] == id) {
is_debug = true;
break;
}
@ -119,16 +117,16 @@ bool TGConstruct::IsDebugShape( unsigned int id )
return is_debug;
}
bool TGConstruct::IsDebugArea( unsigned int area )
bool TGConstruct::IsDebugArea(unsigned int area)
{
bool is_debug = false;
/* Check global flag */
if ( debug_all ) {
if (debug_all) {
is_debug = true;
} else {
for (unsigned int i=0; i<debug_areas.size(); i++) {
if ( debug_areas[i] == area ) {
for (unsigned int i = 0; i < debug_areas.size(); i++) {
if (debug_areas[i] == area) {
is_debug = true;
break;
}

View file

@ -21,7 +21,7 @@
// $Id: construct.cxx,v 1.4 2004-11-19 22:25:49 curt Exp $
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <config.h>
#endif
#include <simgear/debug/logstream.hxx>
@ -32,33 +32,34 @@ using std::string;
// Load elevation data from an Array file (a regular grid of elevation data)
// and return list of fitted nodes.
void TGConstruct::LoadElevationArray( bool add_nodes ) {
void TGConstruct::LoadElevationArray(bool add_nodes)
{
string base = bucket.gen_base_path();
for ( int i = 0; i < (int)load_dirs.size(); ++i ) {
for (int i = 0; i < (int)load_dirs.size(); ++i) {
string array_path = work_base + "/" + load_dirs[i] + "/" + base + "/" + bucket.gen_index_str();
if ( array.open(array_path) ) {
if (array.open(array_path)) {
break;
} else {
SG_LOG(SG_GENERAL, SG_DEBUG, "Failed to open Array file " << array_path);
}
}
array.parse( bucket );
array.remove_voids( );
array.parse(bucket);
array.remove_voids();
if ( add_nodes ) {
if (add_nodes) {
std::vector<SGGeod> const& corner_list = array.get_corner_list();
for (unsigned int i = 0; i < corner_list.size(); ++i) {
nodes.unique_add( corner_list[i] );
nodes.unique_add(corner_list[i]);
}
std::vector<SGGeod> const& fit_list = array.get_fitted_list();
for (unsigned int i = 0; i < fit_list.size(); ++i) {
SGGeod node = fit_list[i];
if ( CheckMatchingNode( node, false, false ) ) {
nodes.unique_add( node );
if (CheckMatchingNode(node, false, false)) {
nodes.unique_add(node);
}
}
}
@ -67,19 +68,19 @@ void TGConstruct::LoadElevationArray( bool add_nodes ) {
// fix the elevations of the geodetic nodes
// This should be done in the nodes class itself, except for the need for the triangle type
// hopefully, this will get better when we have the area lookup via superpoly...
void TGConstruct::CalcElevations( void )
void TGConstruct::CalcElevations(void)
{
std::vector<SGGeod> raw_nodes;
double e1, e2, e3, min;
int n1, n2, n3;
int n1, n2, n3;
for (int i = 0; i < (int)nodes.size(); ++i) {
TGNode const& node = nodes.get_node( i );
TGNode const& node = nodes.get_node(i);
SGGeod pos = node.GetPosition();
if ( !node.GetFixedPosition() ) {
if (!node.GetFixedPosition()) {
// set elevation as interpolated point from DEM data.
nodes.SetElevation( i, array.altitude_from_grid(pos.getLongitudeDeg() * 3600.0, pos.getLatitudeDeg() * 3600.0) );
nodes.SetElevation(i, array.altitude_from_grid(pos.getLongitudeDeg() * 3600.0, pos.getLatitudeDeg() * 3600.0));
}
}
@ -87,137 +88,149 @@ void TGConstruct::CalcElevations( void )
// now flatten some stuff
for (unsigned int area = 0; area < area_defs.size(); area++) {
if ( area_defs.is_lake_area(area) ) {
for (int p = 0; p < (int)polys_clipped.area_size(area); ++p ) {
SG_LOG( SG_CLIPPER, SG_DEBUG, "Flattening " << area_defs.get_area_name(area) << ":" << p+1 << " of " << polys_clipped.area_size(area) );
tgPolygon poly = polys_clipped.get_poly( area, p );
if (area_defs.is_lake_area(area)) {
for (int p = 0; p < (int)polys_clipped.area_size(area); ++p) {
SG_LOG(SG_CLIPPER, SG_DEBUG, "Flattening " << area_defs.get_area_name(area) << ":" << p + 1 << " of " << polys_clipped.area_size(area));
tgPolygon poly = polys_clipped.get_poly(area, p);
for (unsigned int tri=0; tri < poly.Triangles(); tri++) {
n1 = poly.GetTriIdx( tri, 0 );
for (unsigned int tri = 0; tri < poly.Triangles(); tri++) {
n1 = poly.GetTriIdx(tri, 0);
e1 = nodes.get_node(n1).GetPosition().getElevationM();
n2 = poly.GetTriIdx( tri, 1 );
n2 = poly.GetTriIdx(tri, 1);
e2 = nodes.get_node(n2).GetPosition().getElevationM();
n3 = poly.GetTriIdx( tri, 2 );
n3 = poly.GetTriIdx(tri, 2);
e3 = nodes.get_node(n3).GetPosition().getElevationM();
min = e1;
if ( e2 < min ) { min = e2; }
if ( e3 < min ) { min = e3; }
if (e2 < min) { min = e2; }
if (e3 < min) { min = e3; }
nodes.SetElevation( n1, min );
nodes.SetElevation( n2, min );
nodes.SetElevation( n3, min );
nodes.SetElevation(n1, min);
nodes.SetElevation(n2, min);
nodes.SetElevation(n3, min);
}
}
}
if ( area_defs.is_stream_area(area) ) {
for (unsigned int p = 0; p < polys_clipped.area_size(area); ++p ) {
SG_LOG( SG_CLIPPER, SG_DEBUG, "Flattening " << area_defs.get_area_name(area) << ":" << p+1 << " of " << polys_clipped.area_size(area) );
tgPolygon poly = polys_clipped.get_poly( area, p );
if (area_defs.is_stream_area(area)) {
for (unsigned int p = 0; p < polys_clipped.area_size(area); ++p) {
SG_LOG(SG_CLIPPER, SG_DEBUG, "Flattening " << area_defs.get_area_name(area) << ":" << p + 1 << " of " << polys_clipped.area_size(area));
tgPolygon poly = polys_clipped.get_poly(area, p);
for (unsigned int tri=0; tri < poly.Triangles(); tri++) {
n1 = poly.GetTriIdx( tri, 0 );
for (unsigned int tri = 0; tri < poly.Triangles(); tri++) {
n1 = poly.GetTriIdx(tri, 0);
e1 = nodes.get_node(n1).GetPosition().getElevationM();
n2 = poly.GetTriIdx( tri, 1 );
n2 = poly.GetTriIdx(tri, 1);
e2 = nodes.get_node(n2).GetPosition().getElevationM();
n3 = poly.GetTriIdx( tri, 2 );
n3 = poly.GetTriIdx(tri, 2);
e3 = nodes.get_node(n3).GetPosition().getElevationM();
min = e1;
SGGeod src = raw_nodes[n1];
if ( e2 < min ) { min = e2; src = raw_nodes[n2]; }
if ( e3 < min ) { min = e3; src = raw_nodes[n3]; }
if (e2 < min) {
min = e2;
src = raw_nodes[n2];
}
if (e3 < min) {
min = e3;
src = raw_nodes[n3];
}
double d1, d2, d3;
if ( min == e1 ) {
if (min == e1) {
d1 = 0.0f;
} else {
d1 = SGGeodesy::distanceM( src, raw_nodes[n1] );
d1 = SGGeodesy::distanceM(src, raw_nodes[n1]);
}
if ( min == e2 ) {
if (min == e2) {
d2 = 0.0f;
} else {
d2 = SGGeodesy::distanceM( src, raw_nodes[n2] );
d2 = SGGeodesy::distanceM(src, raw_nodes[n2]);
}
if ( min == e3 ) {
if (min == e3) {
d3 = 0.0f;
} else {
d3 = SGGeodesy::distanceM( src, raw_nodes[n3] );
d3 = SGGeodesy::distanceM(src, raw_nodes[n3]);
}
double max1 = d1 * 0.20 + min;
double max2 = d2 * 0.20 + min;
double max3 = d3 * 0.20 + min;
if ( max1 < e1 ) { nodes.SetElevation( n1, max1 ); }
if ( max2 < e2 ) { nodes.SetElevation( n2, max2 ); }
if ( max3 < e3 ) { nodes.SetElevation( n3, max3 ); }
if (max1 < e1) { nodes.SetElevation(n1, max1); }
if (max2 < e2) { nodes.SetElevation(n2, max2); }
if (max3 < e3) { nodes.SetElevation(n3, max3); }
}
}
}
if ( area_defs.is_road_area(area) ) {
for (int p = 0; p < (int)polys_clipped.area_size(area); ++p ) {
SG_LOG( SG_CLIPPER, SG_DEBUG, "Flattening " << area_defs.get_area_name(area) << ":" << p+1 << " of " << polys_clipped.area_size(area) );
tgPolygon poly = polys_clipped.get_poly( area, p );
if (area_defs.is_road_area(area)) {
for (int p = 0; p < (int)polys_clipped.area_size(area); ++p) {
SG_LOG(SG_CLIPPER, SG_DEBUG, "Flattening " << area_defs.get_area_name(area) << ":" << p + 1 << " of " << polys_clipped.area_size(area));
tgPolygon poly = polys_clipped.get_poly(area, p);
for (unsigned int tri=0; tri < poly.Triangles(); tri++) {
n1 = poly.GetTriIdx( tri, 0 );
for (unsigned int tri = 0; tri < poly.Triangles(); tri++) {
n1 = poly.GetTriIdx(tri, 0);
e1 = nodes.get_node(n1).GetPosition().getElevationM();
n2 = poly.GetTriIdx( tri, 1 );
n2 = poly.GetTriIdx(tri, 1);
e2 = nodes.get_node(n2).GetPosition().getElevationM();
n3 = poly.GetTriIdx( tri, 2 );
n3 = poly.GetTriIdx(tri, 2);
e3 = nodes.get_node(n3).GetPosition().getElevationM();
min = e1;
SGGeod src = raw_nodes[n1];
if ( e2 < min ) { min = e2; src = raw_nodes[n2]; }
if ( e3 < min ) { min = e3; src = raw_nodes[n3]; }
if (e2 < min) {
min = e2;
src = raw_nodes[n2];
}
if (e3 < min) {
min = e3;
src = raw_nodes[n3];
}
double d1, d2, d3;
if ( min == e1 ) {
if (min == e1) {
d1 = 0.0f;
} else {
d1 = SGGeodesy::distanceM( src, raw_nodes[n1] );
d1 = SGGeodesy::distanceM(src, raw_nodes[n1]);
}
if ( min == e2 ) {
if (min == e2) {
d2 = 0.0f;
} else {
d2 = SGGeodesy::distanceM( src, raw_nodes[n2] );
d2 = SGGeodesy::distanceM(src, raw_nodes[n2]);
}
if ( min == e3 ) {
if (min == e3) {
d3 = 0.0f;
} else {
d3 = SGGeodesy::distanceM( src, raw_nodes[n3] );
d3 = SGGeodesy::distanceM(src, raw_nodes[n3]);
}
double max1 = d1 * 0.30 + min;
double max2 = d2 * 0.30 + min;
double max3 = d3 * 0.30 + min;
if ( max1 < e1 ) { nodes.SetElevation( n1, max1 ); }
if ( max2 < e2 ) { nodes.SetElevation( n2, max2 ); }
if ( max3 < e3 ) { nodes.SetElevation( n3, max3 ); }
if (max1 < e1) { nodes.SetElevation(n1, max1); }
if (max2 < e2) { nodes.SetElevation(n2, max2); }
if (max3 < e3) { nodes.SetElevation(n3, max3); }
}
}
}
if ( area_defs.is_ocean_area(area) ) {
for (int p = 0; p < (int)polys_clipped.area_size(area); ++p ) {
SG_LOG( SG_CLIPPER, SG_DEBUG, "Flattening " << area_defs.get_area_name(area) << ":" << p+1 << " of " << polys_clipped.area_size(area) );
tgPolygon poly = polys_clipped.get_poly( area, p );
if (area_defs.is_ocean_area(area)) {
for (int p = 0; p < (int)polys_clipped.area_size(area); ++p) {
SG_LOG(SG_CLIPPER, SG_DEBUG, "Flattening " << area_defs.get_area_name(area) << ":" << p + 1 << " of " << polys_clipped.area_size(area));
tgPolygon poly = polys_clipped.get_poly(area, p);
for (unsigned int tri=0; tri < poly.Triangles(); tri++) {
n1 = poly.GetTriIdx( tri, 0 );
n2 = poly.GetTriIdx( tri, 1 );
n3 = poly.GetTriIdx( tri, 2 );
for (unsigned int tri = 0; tri < poly.Triangles(); tri++) {
n1 = poly.GetTriIdx(tri, 0);
n2 = poly.GetTriIdx(tri, 1);
n3 = poly.GetTriIdx(tri, 2);
nodes.SetElevation( n1, 0.0 );
nodes.SetElevation( n2, 0.0 );
nodes.SetElevation( n3, 0.0 );
nodes.SetElevation(n1, 0.0);
nodes.SetElevation(n2, 0.0);
nodes.SetElevation(n3, 0.0);
}
}
}

View file

@ -22,7 +22,7 @@
// $Id: construct.cxx,v 1.4 2004-11-19 22:25:49 curt Exp $
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <config.h>
#endif
#include <simgear/debug/logstream.hxx>
@ -32,20 +32,20 @@
// This function populates the Superpoly tri_idx polygon.
// This polygon is a mirror of tris, except the verticies are
// indexes into the node array (cast as unsigned long)
void TGConstruct::LookupNodesPerVertex( void )
void TGConstruct::LookupNodesPerVertex(void)
{
// for each node, traverse all the triangles - and create face lists
for ( unsigned int area = 0; area < area_defs.size(); area++ ) {
for( unsigned int p = 0; p < polys_clipped.area_size(area); p++ ) {
tgPolygon& poly = polys_clipped.get_poly( area, p );
for (unsigned int area = 0; area < area_defs.size(); area++) {
for (unsigned int p = 0; p < polys_clipped.area_size(area); p++) {
tgPolygon& poly = polys_clipped.get_poly(area, p);
for (unsigned int tri=0; tri < poly.Triangles(); tri++) {
for (unsigned int tri = 0; tri < poly.Triangles(); tri++) {
for (unsigned int vertex = 0; vertex < 3; vertex++) {
int idx = nodes.find( poly.GetTriNode( tri, vertex ) );
int idx = nodes.find(poly.GetTriNode(tri, vertex));
if (idx >= 0) {
poly.SetTriIdx( tri, vertex, idx );
poly.SetTriIdx(tri, vertex, idx);
} else {
SG_LOG(SG_GENERAL, SG_ALERT, "didn't find vertex! " << poly.GetTriNode( tri, vertex ) );
SG_LOG(SG_GENERAL, SG_ALERT, "didn't find vertex! " << poly.GetTriNode(tri, vertex));
exit(0);
}
}
@ -54,17 +54,17 @@ void TGConstruct::LookupNodesPerVertex( void )
}
}
void TGConstruct::LookupFacesPerNode( void )
void TGConstruct::LookupFacesPerNode(void)
{
// Add each face that includes a node to the node's face list
for ( unsigned int area = 0; area < area_defs.size(); area++ ) {
for( unsigned int p = 0; p < polys_clipped.area_size(area); p++ ) {
tgPolygon const& poly = polys_clipped.get_poly(area, p );
for (unsigned int area = 0; area < area_defs.size(); area++) {
for (unsigned int p = 0; p < polys_clipped.area_size(area); p++) {
tgPolygon const& poly = polys_clipped.get_poly(area, p);
for (unsigned int tri=0; tri < poly.Triangles(); tri++) {
for (unsigned int tri = 0; tri < poly.Triangles(); tri++) {
for (int v = 0; v < 3; v++) {
int i = poly.GetTriIdx( tri, v );
nodes.AddFace( i, area, p, tri );
int i = poly.GetTriIdx(tri, v);
nodes.AddFace(i, area, p, tri);
}
}
}

View file

@ -21,14 +21,15 @@
// $Id: construct.cxx,v 1.4 2004-11-19 22:25:49 curt Exp $
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <config.h>
#endif
#include <simgear/debug/logstream.hxx>
#include "tgconstruct.hxx"
SGVec3f TGConstruct::calc_normal( double area, const SGVec3d& p1, const SGVec3d& p2, const SGVec3d& p3 ) const {
SGVec3f TGConstruct::calc_normal(double area, const SGVec3d& p1, const SGVec3d& p2, const SGVec3d& p3) const
{
SGVec3f v1, v2;
SGVec3f normal;
@ -41,17 +42,17 @@ SGVec3f TGConstruct::calc_normal( double area, const SGVec3d& p1, const SGVec3d&
bool degenerate = false;
const double area_eps = 1.0e-12;
if ( area < area_eps ) {
if (area < area_eps) {
degenerate = true;
} else if ( fabs(p1.x() - p2.x()) < SG_EPSILON && fabs(p1.x() - p3.x()) < SG_EPSILON ) {
} else if (fabs(p1.x() - p2.x()) < SG_EPSILON && fabs(p1.x() - p3.x()) < SG_EPSILON) {
degenerate = true;
} else if ( fabs(p1.y() - p2.y()) < SG_EPSILON && fabs(p1.y() - p3.y()) < SG_EPSILON ) {
} else if (fabs(p1.y() - p2.y()) < SG_EPSILON && fabs(p1.y() - p3.y()) < SG_EPSILON) {
degenerate = true;
} else if ( fabs(p1.z() - p2.z()) < SG_EPSILON && fabs(p1.z() - p3.z()) < SG_EPSILON ) {
} else if (fabs(p1.z() - p2.z()) < SG_EPSILON && fabs(p1.z() - p3.z()) < SG_EPSILON) {
degenerate = true;
}
if ( degenerate ) {
if (degenerate) {
normal = normalize(SGVec3f(p1.x(), p1.y(), p1.z()));
} else {
v1[0] = p2.x() - p1.x();
@ -66,90 +67,91 @@ SGVec3f TGConstruct::calc_normal( double area, const SGVec3d& p1, const SGVec3d&
return normal;
}
void TGConstruct::calc_normals( std::vector<SGGeod>& geod_nodes, std::vector<SGVec3d>& wgs84_nodes, tgPolygon& poly ) {
void TGConstruct::calc_normals(std::vector<SGGeod>& geod_nodes, std::vector<SGVec3d>& wgs84_nodes, tgPolygon& poly)
{
// for each face in the superpoly, calculate a face normal
SGVec3f normal;
for (unsigned int tri = 0; tri < poly.Triangles(); tri++) {
SGGeod g1 = geod_nodes[ poly.GetTriIdx( tri, 0 ) ];
SGGeod g2 = geod_nodes[ poly.GetTriIdx( tri, 1 ) ];
SGGeod g3 = geod_nodes[ poly.GetTriIdx( tri, 2 ) ];
SGGeod g1 = geod_nodes[poly.GetTriIdx(tri, 0)];
SGGeod g2 = geod_nodes[poly.GetTriIdx(tri, 1)];
SGGeod g3 = geod_nodes[poly.GetTriIdx(tri, 2)];
SGVec3d v1 = wgs84_nodes[ poly.GetTriIdx( tri, 0 ) ];
SGVec3d v2 = wgs84_nodes[ poly.GetTriIdx( tri, 1 ) ];
SGVec3d v3 = wgs84_nodes[ poly.GetTriIdx( tri, 2 ) ];
SGVec3d v1 = wgs84_nodes[poly.GetTriIdx(tri, 0)];
SGVec3d v2 = wgs84_nodes[poly.GetTriIdx(tri, 1)];
SGVec3d v3 = wgs84_nodes[poly.GetTriIdx(tri, 2)];
double area = tgTriangle::area( g1, g2, g3 );
normal = calc_normal( area, v1, v2, v3 );
double area = tgTriangle::area(g1, g2, g3);
normal = calc_normal(area, v1, v2, v3);
poly.SetTriFaceArea( tri, area );
poly.SetTriFaceNormal( tri, normal );
poly.SetTriFaceArea(tri, area);
poly.SetTriFaceNormal(tri, normal);
}
}
void TGConstruct::CalcFaceNormals( void )
void TGConstruct::CalcFaceNormals(void)
{
// traverse the superpols, and calc normals for each tri within
std::vector<SGVec3d> wgs84_nodes;
nodes.get_wgs84_nodes( wgs84_nodes );
nodes.get_wgs84_nodes(wgs84_nodes);
std::vector<SGGeod> geod_nodes;
nodes.get_geod_nodes( geod_nodes );
std::vector<SGGeod> geod_nodes;
nodes.get_geod_nodes(geod_nodes);
for (unsigned int area = 0; area < area_defs.size(); area++) {
for (unsigned int p = 0; p < polys_clipped.area_size(area); p++ ) {
SG_LOG( SG_CLIPPER, SG_DEBUG, "Calculating face normals for " << area_defs.get_area_name(area) << ":" << p+1 << " of " << polys_in.area_size(area) );
calc_normals( geod_nodes, wgs84_nodes, polys_clipped.get_poly( area, p ) );
for (unsigned int p = 0; p < polys_clipped.area_size(area); p++) {
SG_LOG(SG_CLIPPER, SG_DEBUG, "Calculating face normals for " << area_defs.get_area_name(area) << ":" << p + 1 << " of " << polys_in.area_size(area));
calc_normals(geod_nodes, wgs84_nodes, polys_clipped.get_poly(area, p));
}
}
}
void TGConstruct::CalcPointNormals( void )
void TGConstruct::CalcPointNormals(void)
{
// traverse triangle structure building the face normal table
SGVec3f normal;
double face_area;
double face_area;
std::vector<SGVec3d> wgs84_nodes;
nodes.get_wgs84_nodes( wgs84_nodes );
nodes.get_wgs84_nodes(wgs84_nodes);
unsigned int one_percent = nodes.size() / 100;
unsigned int cur_percent = 1;
for ( unsigned int i = 0; i<nodes.size(); i++ ) {
TGNode const& node = nodes.get_node( i );
TGFaceList const& faces = node.GetFaces();
for (unsigned int i = 0; i < nodes.size(); i++) {
TGNode const& node = nodes.get_node(i);
TGFaceList const& faces = node.GetFaces();
TGNeighborFaces const* neighbor_faces = NULL;
double total_area = 0.0;
SGVec3f average( 0.0, 0.0, 0.0 );
SGVec3f average(0.0, 0.0, 0.0);
if ( i == one_percent ) {
SG_LOG(SG_GENERAL, SG_DEBUG, "Calculating point normals: " << cur_percent << "%" );
if (i == one_percent) {
SG_LOG(SG_GENERAL, SG_DEBUG, "Calculating point normals: " << cur_percent << "%");
one_percent += nodes.size() / 100;
cur_percent += 1;
}
// for each triangle that shares this node
for ( unsigned int j = 0; j < faces.size(); ++j ) {
unsigned int at = faces[j].area;
unsigned int poly = faces[j].poly;
unsigned int tri = faces[j].tri;
for (unsigned int j = 0; j < faces.size(); ++j) {
unsigned int at = faces[j].area;
unsigned int poly = faces[j].poly;
unsigned int tri = faces[j].tri;
normal = polys_clipped.get_face_normal( at, poly, tri );
face_area = polys_clipped.get_face_area( at, poly, tri );
normal = polys_clipped.get_face_normal(at, poly, tri);
face_area = polys_clipped.get_face_area(at, poly, tri);
normal *= face_area; // scale normal weight relative to area
normal *= face_area; // scale normal weight relative to area
total_area += face_area;
average += normal;
}
// if this node exists in the shared edge db, add the faces from the neighbooring tile
neighbor_faces = FindNeighborFaces( node.GetPosition() );
if ( neighbor_faces ) {
// if this node exists in the shared edge db, add the faces from the neighboring tile
neighbor_faces = FindNeighborFaces(node.GetPosition());
if (neighbor_faces) {
int num_faces = neighbor_faces->face_areas.size();
for ( int j = 0; j < num_faces; j++ ) {
normal = neighbor_faces->face_normals[j];
for (int j = 0; j < num_faces; j++) {
normal = neighbor_faces->face_normals[j];
face_area = neighbor_faces->face_areas[j];
normal *= face_area;
@ -159,6 +161,6 @@ void TGConstruct::CalcPointNormals( void )
}
average /= total_area;
nodes.SetNormal( i, average );
nodes.SetNormal(i, average);
}
}

View file

@ -22,7 +22,7 @@
// $Id: construct.cxx,v 1.4 2004-11-19 22:25:49 curt Exp $
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <config.h>
#endif
#include <simgear/debug/logstream.hxx>
@ -31,56 +31,55 @@
#include "tgconstruct.hxx"
void TGConstruct::TesselatePolys( void )
void TGConstruct::TesselatePolys(void)
{
// tesselate the polygons and prepair them for final output
std::vector<SGGeod> poly_extra;
SGGeod min, max;
for (unsigned int area = 0; area < area_defs.size(); area++) {
for (unsigned int p = 0; p < polys_clipped.area_size(area); p++ ) {
tgPolygon poly = polys_clipped.get_poly(area, p );
for (unsigned int p = 0; p < polys_clipped.area_size(area); p++) {
tgPolygon poly = polys_clipped.get_poly(area, p);
if ( IsDebugShape( poly.GetId() ) ) {
if (IsDebugShape(poly.GetId())) {
char layer[32];
sprintf(layer, "pretess_%u_%u", area, p );
tgShapefile::FromPolygon( poly, ds_name, layer, "poly" );
sprintf(layer, "pretess_%u_%u", area, p);
tgShapefile::FromPolygon(poly, ds_name, layer, "poly");
}
tgRectangle rect = poly.GetBoundingBox();
nodes.get_geod_inside( rect.getMin(), rect.getMax(), poly_extra );
nodes.get_geod_inside(rect.getMin(), rect.getMax(), poly_extra);
SG_LOG( SG_CLIPPER, SG_DEBUG, "Tesselating " << area_defs.get_area_name(area) << "(" << area << "): " <<
p+1 << " of " << polys_clipped.area_size(area) << ": id = " << poly.GetId() );
SG_LOG(SG_CLIPPER, SG_DEBUG, "Tesselating " << area_defs.get_area_name(area) << "(" << area << "): " << p + 1 << " of " << polys_clipped.area_size(area) << ": id = " << poly.GetId());
if ( IsDebugShape( poly.GetId() ) ) {
SG_LOG( SG_CLIPPER, SG_INFO, poly );
if (IsDebugShape(poly.GetId())) {
SG_LOG(SG_CLIPPER, SG_INFO, poly);
}
poly.Tesselate( poly_extra );
poly.Tesselate(poly_extra);
polys_clipped.set_poly( area, p, poly );
polys_clipped.set_poly(area, p, poly);
}
}
for (unsigned int area = 0; area < area_defs.size(); area++) {
bool isRoad = area_defs.is_road_area( area );
for (unsigned int p = 0; p < polys_clipped.area_size(area); p++ ) {
tgPolygon& poly = polys_clipped.get_poly(area, p );
bool isRoad = area_defs.is_road_area(area);
for (unsigned int p = 0; p < polys_clipped.area_size(area); p++) {
tgPolygon& poly = polys_clipped.get_poly(area, p);
// ensure all added nodes are accounted for
for (unsigned int k=0; k < poly.Triangles(); k++) {
for (unsigned int k = 0; k < poly.Triangles(); k++) {
for (int l = 0; l < 3; l++) {
// ensure we have all nodes...
SGGeod node = poly.GetTriNode( k, l );
if ( CheckMatchingNode( node, isRoad, false ) ) {
nodes.unique_add( node );
SGGeod node = poly.GetTriNode(k, l);
if (CheckMatchingNode(node, isRoad, false)) {
nodes.unique_add(node);
} else {
SG_LOG( SG_GENERAL, SG_INFO, "after tesselation, we can't add a node - quit");
SG_LOG(SG_GENERAL, SG_INFO, "after tesselation, we can't add a node - quit");
exit(1);
}
}
}
}
}
}
}

View file

@ -27,7 +27,7 @@
// $Id: construct.hxx,v 1.13 2004-11-19 22:25:49 curt Exp $
#ifdef HAVE_CONFIG_H
# include <config.h>
#include <config.h>
#endif
#include "tglandclass.hxx"
@ -35,7 +35,7 @@
void TGLandclass::clear(void)
{
for (unsigned int i=0; i<polys.size(); i++) {
for (unsigned int i = 0; i < polys.size(); i++) {
polys[i].clear();
}
// keep the number of arrays intact - it's constant throughout construct
@ -47,32 +47,32 @@ void TGLandclass::LoadFromGzFile(gzFile& fp)
int i, j, num_layers, num_polys;
// Load all landclass shapes
sgReadInt( fp, &num_layers );
sgReadInt(fp, &num_layers);
polys.clear();
for (i=0; i<num_layers; i++) {
for (i = 0; i < num_layers; i++) {
tgpolygon_list lc;
sgReadInt( fp, &num_polys );
sgReadInt(fp, &num_polys);
lc.clear();
for (j=0; j<num_polys; j++) {
for (j = 0; j < num_polys; j++) {
tgPolygon poly;
poly.LoadFromGzFile( fp );
lc.push_back( poly );
poly.LoadFromGzFile(fp);
lc.push_back(poly);
}
polys.push_back(lc);
}
}
std::ostream& operator<< ( std::ostream& out, const TGLandclass& lc )
std::ostream& operator<<(std::ostream& out, const TGLandclass& lc)
{
tgPolygon poly;
// Save all landclass shapes
for (unsigned int i=0; i<lc.polys.size(); i++) {
for (unsigned int i = 0; i < lc.polys.size(); i++) {
unsigned int count = lc.polys[i].size();
out << count << "\n";
for (unsigned int j=0; j<count; j++) {
for (unsigned int j = 0; j < count; j++) {
out << lc.polys[i][j] << " ";
}
out << "\n";
@ -88,13 +88,13 @@ void TGLandclass::SaveToGzFile(gzFile& fp)
// Save all landclass shapes
num_layers = polys.size();
sgWriteInt( fp, num_layers );
for (i=0; i<num_layers; i++) {
sgWriteInt(fp, num_layers);
for (i = 0; i < num_layers; i++) {
int num_polys = polys[i].size();
sgWriteInt( fp, num_polys );
sgWriteInt(fp, num_polys);
for (j=0; j<num_polys; j++) {
polys[i][j].SaveToGzFile( fp );
for (j = 0; j < num_polys; j++) {
polys[i][j].SaveToGzFile(fp);
}
}
}