From: <fli...@li...> - 2015-11-25 15:53:36
|
psadro pushed a commit to branch master in repository terragear. The following commit(s) were added to refs/heads/master by this push: new 24746e5 tgconstruct now uses tgmesh ( same as genapt850 ) - todo - second stage triangulation ( matching nodes ) 24746e5 is described below SF URL: http://sourceforge.net/p/flightgear/terragear/ci/24746e58a73b6350c3510db985465c87ee78f47e/ Commit: 24746e58a73b6350c3510db985465c87ee78f47e Author: Peter Sadrozinski Committer: Peter Sadrozinski Date: Wed Nov 25 10:52:17 2015 -0500 tgconstruct now uses tgmesh ( same as genapt850 ) - todo - second stage triangulation ( matching nodes ) --- src/Airports/GenAirports850/airport_base.cxx | 5 +- src/BuildTiles/Main/main.cxx | 32 ++-- src/BuildTiles/Main/tgconstruct.cxx | 238 +++++++++-------- src/BuildTiles/Main/tgconstruct.hxx | 157 ++++++------ src/BuildTiles/Main/tgconstruct_cleanup.cxx | 6 + src/BuildTiles/Main/tgconstruct_clip.cxx | 11 +- src/BuildTiles/Main/tgconstruct_debug.cxx | 12 +- src/BuildTiles/Main/tgconstruct_elevation.cxx | 8 +- src/BuildTiles/Main/tgconstruct_lookup.cxx | 6 + src/BuildTiles/Main/tgconstruct_math.cxx | 10 +- src/BuildTiles/Main/tgconstruct_mesh.cxx | 14 +- src/BuildTiles/Main/tgconstruct_output.cxx | 37 ++-- src/BuildTiles/Main/tgconstruct_poly.cxx | 70 ++++- src/BuildTiles/Main/tgconstruct_shared.cxx | 30 ++- src/BuildTiles/Main/tgconstruct_tesselate.cxx | 4 +- src/BuildTiles/Main/tgconstruct_texture.cxx | 4 +- src/Lib/terragear/mesh/tg_mesh.cxx | 71 ++++-- src/Lib/terragear/mesh/tg_mesh.hxx | 5 +- src/Lib/terragear/polygon_set/tg_polygon_set.hxx | 5 + .../terragear/polygon_set/tg_polygon_set_io.cxx | 284 +++++++------------- .../terragear/polygon_set/tg_polygon_set_meta.cxx | 6 + 21 files changed, 563 insertions(+), 452 deletions(-) diff --git a/src/Airports/GenAirports850/airport_base.cxx b/src/Airports/GenAirports850/airport_base.cxx index 067cfb7..2f168b1 100644 --- a/src/Airports/GenAirports850/airport_base.cxx +++ b/src/Airports/GenAirports850/airport_base.cxx @@ -38,8 +38,9 @@ void Airport::BuildBase( void ) tgPolygonSetList innerBasePolys, outerBasePolys; bool userBoundary = false; - /* initialize tgAreas for the number of layers we have */ - baseMesh.init( AIRPORT_NUM_AREAS, area_names, icao ); + /* initialize tgMesh for the number of layers we have */ + baseMesh.initPriorities( area_names ); + baseMesh.initDebug( icao ); if (boundary.size()) { TG_LOG(SG_GENERAL, SG_INFO, "Build Base with user defined boundary" ); diff --git a/src/BuildTiles/Main/main.cxx b/src/BuildTiles/Main/main.cxx index e1e5965..ae621ab 100644 --- a/src/BuildTiles/Main/main.cxx +++ b/src/BuildTiles/Main/main.cxx @@ -38,11 +38,11 @@ #include "priorities.hxx" #include "usgs.hxx" -using std::string; -using std::vector; +//using std::string; +//using std::vector; // display usage and exit -static void usage( const string name ) { +static void usage( const std::string& name ) { SG_LOG(SG_GENERAL, SG_ALERT, "Usage: " << name); SG_LOG(SG_GENERAL, SG_ALERT, "[ --output-dir=<directory>"); SG_LOG(SG_GENERAL, SG_ALERT, " --work-dir=<directory>"); @@ -76,24 +76,24 @@ void RemoveDuplicateBuckets( std::vector<SGBucket>& keep, std::vector<SGBucket>& } int main(int argc, char **argv) { - string output_dir = "."; - string work_dir = "."; - string share_dir = ""; - string match_dir = ""; - string cover = ""; - string priorities_file = DEFAULT_PRIORITIES_FILE; - string usgs_map_file = DEFAULT_USGS_MAPFILE; + std::string output_dir = "."; + std::string work_dir = "."; + std::string share_dir = ""; + std::string match_dir = ""; + std::string cover = ""; + std::string priorities_file = DEFAULT_PRIORITIES_FILE; + std::string usgs_map_file = DEFAULT_USGS_MAPFILE; SGGeod min, max; long tile_id = -1; int num_threads = 1; - vector<string> load_dirs; + std::vector<std::string> load_dirs; bool ignoreLandmass = false; double nudge=0.0; - string debug_dir = "."; - vector<string> debug_shape_defs; - vector<string> debug_area_defs; + std::string debug_dir = "."; + std::vector<std::string> debug_shape_defs; + std::vector<std::string> debug_area_defs; sglog().setLogLevels( SG_ALL, SG_INFO ); @@ -102,7 +102,7 @@ int main(int argc, char **argv) { // int arg_pos; for (arg_pos = 1; arg_pos < argc; arg_pos++) { - string arg = argv[arg_pos]; + std::string arg = argv[arg_pos]; if (arg.find("--output-dir=") == 0) { output_dir = arg.substr(13); @@ -218,7 +218,7 @@ int main(int argc, char **argv) { TGConstruct* construct = new TGConstruct( areas, 1, wq, &filelock ); //construct->set_cover( cover ); construct->set_paths( work_dir, share_dir, match_dir, output_dir, load_dirs ); - construct->CreateMatchedEdgeFiles( matchList ); + //construct->CreateMatchedEdgeFiles( matchList ); delete construct; } diff --git a/src/BuildTiles/Main/tgconstruct.cxx b/src/BuildTiles/Main/tgconstruct.cxx index 2ebd59e..972faa6 100644 --- a/src/BuildTiles/Main/tgconstruct.cxx +++ b/src/BuildTiles/Main/tgconstruct.cxx @@ -25,35 +25,37 @@ # include <config.h> #endif -#include <iomanip> +//#include <iomanip> #include <simgear/debug/logstream.hxx> #include "tgconstruct.hxx" -#include "tgconstruct_mesh.hxx" +//#include "tgconstruct_mesh.hxx" -const double TGConstruct::gSnap = 0.00000001; // approx 1 mm +// const double TGConstruct::gSnap = 0.00000001; // approx 1 mm // Constructor TGConstruct::TGConstruct( const TGAreaDefinitions& areas, unsigned int s, SGLockedQueue<SGBucket>& q, SGMutex* l) : area_defs(areas), - workQueue(q), - stage(s), - ignoreLandmass(false), - debug_all(false), - ds_id((void*)-1), - isOcean(false) + workQueue(q) + //stage(s), + //ignoreLandmass(false), + //debug_all(false), + //ds_id((void*)-1), + //isOcean(false) { - total_tiles = q.size(); - num_areas = areas.size(); - + total_tiles = q.size(); lock = l; + + /* initialize tgMesh for the number of layers we have */ + std::vector<std::string> area_names = area_defs.get_name_array(); + tileMesh.initPriorities( area_names ); } // Destructor TGConstruct::~TGConstruct() { // All Nodes - nodes.clear(); + //nodes.clear(); } // TGConstruct: Setup @@ -68,8 +70,8 @@ void TGConstruct::set_paths( const std::string work, const std::string share, } void TGConstruct::set_options( bool ignore_lm, double n ) { - ignoreLandmass = ignore_lm; - nudge = n; + //ignoreLandmass = ignore_lm; + //nudge = n; } void TGConstruct::run() @@ -84,40 +86,54 @@ void TGConstruct::run() // assume non ocean tile until proven otherwise isOcean = false; + tileMesh.initDebug( bucket.gen_index_str() ); + // Initialize the landclass lists with the number of area definitions - polys_in.init( num_areas, area_defs.get_name_array() ); - polys_clipped.init( num_areas, area_defs.get_name_array() ); + //polys_in.init( num_areas, area_defs.get_name_array() ); + //polys_clipped.init( num_areas, area_defs.get_name_array() ); SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Construct in " << bucket.gen_base_path() << " tile " << tiles_complete << " of " << total_tiles << " using thread " << current() ); // Init debug shapes and area for this bucket - get_debug(); - if ( debug_shapes.size() || debug_all ) { - sprintf(ds_name, "%s/constructdbg_%s", debug_path.c_str(), bucket.gen_index_str().c_str() ); - } else { - strcpy( ds_name, "" ); - } - - if ( stage > 1 ) { - LoadFromIntermediateFiles( stage-1 ); - LoadSharedEdgeData( stage-1 ); - } - - switch( stage ) { - case 1: - // STEP 1) - // Load grid of elevation data (Array), and add the nodes - LoadElevationArray( true ); + //get_debug(); + //if ( debug_shapes.size() || debug_all ) { + // sprintf(ds_name, "%s/constructdbg_%s", debug_path.c_str(), bucket.gen_index_str().c_str() ); + //} else { + // strcpy( ds_name, "" ); + //} + + // STEP 1 - read in the polygon soup for this tile + LoadLandclassPolys(); + + // Step 2 - add the fitted nodes ( important elevation points ) + // add them to the mesh - which adds them in triangulation + // LoadElevation(); + + // generate the tile + tileMesh.generate(); + + tileMesh.clear(); + + //if ( stage > 1 ) { + // LoadFromIntermediateFiles( stage-1 ); + // LoadSharedEdgeData( stage-1 ); + //} + + //switch( stage ) { + // case 1: + // // STEP 1) + // // Load grid of elevation data (Array), and add the nodes + // LoadElevationArray( true ); // STEP 2) // Clip 2D polygons against one another - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Loading landclass polys" ); - if ( LoadLandclassPolys() == 0 ) { - // don't build the tile if there is no 2d data ... it *must* - // be ocean and the sim can build the tile on the fly. - isOcean = true; - break; - } + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Loading landclass polys" ); + // if ( LoadLandclassPolys() == 0 ) { + // // don't build the tile if there is no 2d data ... it *must* + // // be ocean and the sim can build the tile on the fly. + // isOcean = true; + // break; + // } #if 0 // STEP 3) @@ -128,17 +144,17 @@ void TGConstruct::run() } #endif - // STEP 4) - // Clip the Landclass polygons - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Clipping landclass polys" ); - ClipLandclassPolys(); - { - // TEST TEST TEST Generate a mesh from the clipped polys - tgMesh mesh(area_defs, polys_clipped); - mesh.ToShapefile("./mesh"); - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Saved mesh" ); - exit(0); - } + // // STEP 4) + // // Clip the Landclass polygons + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Clipping landclass polys" ); + // ClipLandclassPolys(); + // { + // // TEST TEST TEST Generate a mesh from the clipped polys + // tgMesh mesh(area_defs, polys_clipped); + // mesh.ToShapefile("./mesh"); + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Saved mesh" ); + // exit(0); + // } // Now make sure any newly added intersection nodes are added to the tgnodes // polys_clipped.SyncNodes( nodes ); @@ -151,32 +167,32 @@ void TGConstruct::run() // Now make sure any newly added intersection nodes are added to the tgnodes //SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Syn nodes" ); //polys_clipped.SyncNodes( nodes ); - break; + // break; - case 2: - if ( !IsOceanTile() ) { - // STEP 6) - // Need the array of elevation data for stage 2, but don't add the nodes - we already have them - LoadElevationArray( false ); + // case 2: + // if ( !IsOceanTile() ) { + // // STEP 6) + // // Need the array of elevation data for stage 2, but don't add the nodes - we already have them + // LoadElevationArray( false ); // STEP 7) // Fix T-Junctions by finding nodes that lie close to polygon edges, and // inserting them into the edge - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Fix T-Junctions" ); - nodes.init_spacial_query(); - FixTJunctions(); + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Fix T-Junctions" ); + // nodes.init_spacial_query(); + // FixTJunctions(); - // Now make sure any newly added intersection nodes are added to the tgnodes - polys_clipped.SyncNodes( nodes ); + // // Now make sure any newly added intersection nodes are added to the tgnodes + // polys_clipped.SyncNodes( nodes ); // STEP 8) // Generate triangles - we can't generate the node-face lookup table // until all polys are tesselated, as extra nodes can still be generated - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Tesselate" ); - TesselatePolys(); + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Tesselate" ); + // TesselatePolys(); // Now make sure any newly added intersection nodes are added to the tgnodes - polys_clipped.SyncNodes( nodes ); + // polys_clipped.SyncNodes( nodes ); // STEP 9) // We have all the nodes we need (plus extra that were clipped away) @@ -186,13 +202,13 @@ void TGConstruct::run() // STEP 10) // Generate triangle vertex coordinates to node index lists // NOTE: After this point, no new nodes can be added - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Lookup Nodes Per Vertex"); - LookupNodesPerVertex(); + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Lookup Nodes Per Vertex"); + // LookupNodesPerVertex(); // STEP 11) // Interpolate elevations, and flatten stuff - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Calculate Elevation Per Node"); - CalcElevations(); + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Calculate Elevation Per Node"); + // CalcElevations(); #if 0 // ROADS ON AIRPORT DEBUGGING // debug : dump the nodes nodes.ToShapefile( bucket.gen_index_str() ); @@ -202,34 +218,34 @@ void TGConstruct::run() // ONLY do this when saving edge nodes... // STEP 11) // Generate face-connected list - needed for saving the edge data - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Lookup Faces Per Node"); - LookupFacesPerNode(); - } - break; + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Lookup Faces Per Node"); + // LookupFacesPerNode(); + // } + // break; - case 3: - if ( !IsOceanTile() ) { + // case 3: + // if ( !IsOceanTile() ) { // STEP 12 // Generate face-connectd list (again) - it was needed to save faces of the // edge nodes, but saving the entire tile is i/o intensive - it's faster // too just recompute the list - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Lookup Faces Per Node (again)"); - LookupFacesPerNode(); + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Lookup Faces Per Node (again)"); + // LookupFacesPerNode(); // STEP 13) // Average out the elevation for nodes on tile boundaries - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Average Edge Node Elevations"); - AverageEdgeElevations(); + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Average Edge Node Elevations"); + // AverageEdgeElevations(); // STEP 14) // Calculate Face Normals - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Calculate Face Normals"); - CalcFaceNormals(); + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Calculate Face Normals"); + // CalcFaceNormals(); // STEP 15) // Calculate Point Normals - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Calculate Point Normals"); - CalcPointNormals(); + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Calculate Point Normals"); + // CalcPointNormals(); #if 0 // STEP 16) @@ -243,43 +259,43 @@ void TGConstruct::run() // STEP 17) // Calculate Texture Coordinates - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Calculate Texture Coordinates"); - CalcTextureCoordinates(); + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Calculate Texture Coordinates"); + // CalcTextureCoordinates(); // STEP 18) // Generate the mesh file for LOD - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Generate Mesh File"); - WriteMeshFile(); + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Generate Mesh File"); + // WriteMeshFile(); // STEP 19) // Generate the btg file - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Generate BTG File"); - WriteBtgFile(); + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Generate BTG File"); + // WriteBtgFile(); // STEP 20) // Write Custom objects to .stg file - SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Generate Custom Objects"); - AddCustomObjects(); - } - break; - } - - if ( ( stage < 3 ) && ( !IsOceanTile() ) ) { - // Save data for next stage - if ( stage == 2 ) { - nodes.init_spacial_query(); // for stage 2 only... - } - SaveSharedEdgeData( stage ); - SaveToIntermediateFiles( stage ); - } + // SG_LOG(SG_GENERAL, SG_ALERT, bucket.gen_index_str() << " - Generate Custom Objects"); + // AddCustomObjects(); + // } + // break; + // } + + // if ( ( stage < 3 ) && ( !IsOceanTile() ) ) { + // // Save data for next stage + // if ( stage == 2 ) { + // nodes.init_spacial_query(); // for stage 2 only... + // } + // SaveSharedEdgeData( stage ); + // SaveToIntermediateFiles( stage ); + // } // Clean up for next work queue item - array.unload(); - polys_in.clear(); - polys_clipped.clear(); - nodes.clear(); - neighbor_faces.clear(); - debug_shapes.clear(); - debug_areas.clear(); + // array.unload(); + // polys_in.clear(); + // polys_clipped.clear(); + // nodes.clear(); + // neighbor_faces.clear(); + // debug_shapes.clear(); + // debug_areas.clear(); } } \ No newline at end of file diff --git a/src/BuildTiles/Main/tgconstruct.hxx b/src/BuildTiles/Main/tgconstruct.hxx index 1190e4e..4970bae 100644 --- a/src/BuildTiles/Main/tgconstruct.hxx +++ b/src/BuildTiles/Main/tgconstruct.hxx @@ -34,29 +34,30 @@ #include <simgear/threads/SGThread.hxx> #include <simgear/threads/SGQueue.hxx> +#include <terragear/mesh/tg_mesh.hxx> #include <terragear/tg_array.hxx> -#include <terragear/tg_nodes.hxx> -#include <terragear/tg_areas.hxx> +//#include <terragear/tg_nodes.hxx> +//#include <terragear/tg_areas.hxx> -#include <landcover/landcover.hxx> +//#include <landcover/landcover.hxx> #include "priorities.hxx" -#define FIND_SLIVERS (0) +//#define FIND_SLIVERS (0) // Stage2 shared edge data -struct TGNeighborFaces { -public: - SGGeod node; - - double_list elevations; // we'll take the average - double_list face_areas; - std::vector<SGVec3f> face_normals; -}; +//struct TGNeighborFaces { +//public: +// SGGeod node; +// +// 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 neighbor_face_list::iterator neighbor_face_list_iterator; -typedef neighbor_face_list::const_iterator const_neighbor_face_list_iterator; +//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; class TGConstruct : public SGThread { @@ -68,8 +69,8 @@ public: ~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 (); @@ -90,18 +91,18 @@ public: void set_options( bool ignore_lm, double n ); // TODO : REMOVE - inline TGNodes* get_nodes() { return &nodes; } + //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 CreateMatchedEdgeFiles( std::vector<SGBucket>& bucketList ); + //void CreateMatchedEdgeFiles( std::vector<SGBucket>& bucketList ); private: virtual void run(); @@ -111,66 +112,69 @@ private: // Load Data void LoadElevationArray( bool add_nodes ); + int LoadLandclassPolys( void ); - - bool CheckMatchingNode( SGGeod& node, bool road, bool fixed ); + void processLayer(OGRLayer* poLayer); + int addShape(OGRFeature *poFeature, OGRPolygon* poGeometry); + + //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 ); + //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 ); // Shared edge Matching - void SaveSharedEdgeData( int stage ); - void LoadSharedEdgeData( int stage ); - void LoadMatchedEdgeFiles(); + //void SaveSharedEdgeData( int stage ); + //void LoadSharedEdgeData( int stage ); + //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 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 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 LookupUnusedNodes( void ); - void LookupNodesPerVertex( void ); - void LookupFacesPerNode( void ); - void CalcFaceNormals( void ); - void CalcPointNormals( void ); - void CalcTextureCoordinates( void ); + //void LookupUnusedNodes( 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 WriteMeshFile( void ); - void WriteBtgFile( void ); + //void WriteMeshFile( 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; @@ -178,49 +182,48 @@ private: // construct stage to perform SGLockedQueue<SGBucket>& workQueue; unsigned int total_tiles; - unsigned int stage; + //unsigned int stage; // path to land-cover file (if any) - std::string cover; + //std::string cover; - std::vector<SGGeod> nm_north, nm_south, nm_east, nm_west; + //std::vector<SGGeod> nm_north, nm_south, nm_east, nm_west; // paths std::string work_base; std::string output_base; std::string share_base; std::string match_base; - 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; + //bool ignoreLandmass; // I think we should remove this - double nudge; + //double nudge; // path to the debug shapes std::string debug_path; - bool debug_all; + //bool debug_all; // list of debug definitions (for a whole tgconstruct run - std::vector<std::string> debug_area_defs; - std::vector<std::string> debug_shape_defs; + //std::vector<std::string> debug_area_defs; + //std::vector<std::string> debug_shape_defs; // list of shapes to dump during debug (for a single tile) - std::vector<unsigned int> debug_areas; - std::vector<unsigned int> debug_shapes; + //std::vector<unsigned int> debug_areas; + //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; @@ -228,23 +231,25 @@ private: // Elevation data tgArray array; + tgMesh tileMesh; + // land class polygons - tgAreas polys_in; - tgAreas polys_clipped; + //tgAreas polys_in; + //tgAreas polys_clipped; // All Nodes - TGNodes nodes; + //TGNodes nodes; // ocean tile? bool isOcean; - unsigned int num_areas; + //unsigned int num_areas; // Neighbor Faces - neighbor_face_list neighbor_faces; + //neighbor_face_list neighbor_faces; // file lock SGMutex* lock; }; -#endif // _CONSTRUCT_HXX +#endif // _CONSTRUCT_HXX \ No newline at end of file diff --git a/src/BuildTiles/Main/tgconstruct_cleanup.cxx b/src/BuildTiles/Main/tgconstruct_cleanup.cxx index 6e4c4f4..2eb622a 100644 --- a/src/BuildTiles/Main/tgconstruct_cleanup.cxx +++ b/src/BuildTiles/Main/tgconstruct_cleanup.cxx @@ -32,6 +32,7 @@ #include "tgconstruct.hxx" +#if 0 void TGConstruct::FixTJunctions( void ) { int before, after; std::vector<TGNode*> points; @@ -57,6 +58,7 @@ void TGConstruct::FixTJunctions( void ) { } } } +#endif #if 0 // Attempt to merge slivers into a list of polygons. @@ -81,6 +83,7 @@ void TGConstruct::merge_slivers( TGLandclass& clipped, tgcontour_list& sliver_l } #endif +#if 0 void TGConstruct::CleanClippedPolys() { // Clean the polys for ( unsigned int area = 0; area < area_defs.size(); area++ ) { @@ -121,7 +124,9 @@ void TGConstruct::CleanClippedPolys() { } } } +#endif +#if 0 void TGConstruct::AverageEdgeElevations( void ) { for ( unsigned int i = 0; i < neighbor_faces.size(); i++ ) { @@ -148,3 +153,4 @@ void TGConstruct::AverageEdgeElevations( void ) } } } +#endif \ No newline at end of file diff --git a/src/BuildTiles/Main/tgconstruct_clip.cxx b/src/BuildTiles/Main/tgconstruct_clip.cxx index d45026b..700c701 100644 --- a/src/BuildTiles/Main/tgconstruct_clip.cxx +++ b/src/BuildTiles/Main/tgconstruct_clip.cxx @@ -27,9 +27,9 @@ #include <simgear/debug/logstream.hxx> #include <terragear/polygon_set/tg_polygon_accumulator.hxx> -#include <terragear/tg_shapefile.hxx> -#include <terragear/tg_misc.hxx> -#include <terragear/tg_arrangement.hxx> +//#include <terragear/tg_shapefile.hxx> +//#include <terragear/tg_misc.hxx> +//#include <terragear/tg_arrangement.hxx> #include "tgconstruct.hxx" @@ -43,8 +43,7 @@ // The polygon is now a valid Polygon_2_with_holes. // It should always be able to clip against the others. -using std::string; - +#if 0 #if USE_CGAL bool TGConstruct::ClipLandclassPolys( void ) { tgPolygon clipped, tmp; @@ -483,4 +482,6 @@ bool TGConstruct::ClipLandclassPolys( void ) { return true; } +#endif + #endif \ No newline at end of file diff --git a/src/BuildTiles/Main/tgconstruct_debug.cxx b/src/BuildTiles/Main/tgconstruct_debug.cxx index 68a464a..a372adc 100644 --- a/src/BuildTiles/Main/tgconstruct_debug.cxx +++ b/src/BuildTiles/Main/tgconstruct_debug.cxx @@ -36,10 +36,11 @@ void TGConstruct::set_debug( std::string path, std::vector<string> a_defs, std:: { debug_path = path; - debug_area_defs = a_defs; - debug_shape_defs = s_defs; + //debug_area_defs = a_defs; + //debug_shape_defs = s_defs; } +#if 0 void TGConstruct::get_debug( void ) { // clear out any previous entries @@ -101,7 +102,9 @@ void TGConstruct::get_debug( void ) } } } +#endif +#if 0 bool TGConstruct::IsDebugShape( unsigned int id ) { bool is_debug = false; @@ -120,7 +123,9 @@ bool TGConstruct::IsDebugShape( unsigned int id ) return is_debug; } +#endif +#if 0 bool TGConstruct::IsDebugArea( unsigned int area ) { bool is_debug = false; @@ -138,4 +143,5 @@ bool TGConstruct::IsDebugArea( unsigned int area ) } return is_debug; -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/BuildTiles/Main/tgconstruct_elevation.cxx b/src/BuildTiles/Main/tgconstruct_elevation.cxx index 9414957..8f8d021 100644 --- a/src/BuildTiles/Main/tgconstruct_elevation.cxx +++ b/src/BuildTiles/Main/tgconstruct_elevation.cxx @@ -28,8 +28,9 @@ #include "tgconstruct.hxx" -using std::string; +//using std::string; +#if 0 // 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 ) { @@ -62,7 +63,9 @@ void TGConstruct::LoadElevationArray( bool add_nodes ) { } } } +#endif +#if 0 // 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... @@ -213,4 +216,5 @@ void TGConstruct::CalcElevations( void ) } } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/BuildTiles/Main/tgconstruct_lookup.cxx b/src/BuildTiles/Main/tgconstruct_lookup.cxx index a334446..bbe04f9 100644 --- a/src/BuildTiles/Main/tgconstruct_lookup.cxx +++ b/src/BuildTiles/Main/tgconstruct_lookup.cxx @@ -29,6 +29,7 @@ #include "tgconstruct.hxx" +#if 0 void TGConstruct::LookupUnusedNodes( void ) { // for each node, traverse all the triangles - and create face lists @@ -47,7 +48,9 @@ void TGConstruct::LookupUnusedNodes( void ) nodes.DeleteUnused(); } +#endif +#if 0 // 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) @@ -72,7 +75,9 @@ void TGConstruct::LookupNodesPerVertex( void ) } } } +#endif +#if 0 void TGConstruct::LookupFacesPerNode( void ) { // Add each face that includes a node to the node's face list @@ -89,3 +94,4 @@ void TGConstruct::LookupFacesPerNode( void ) } } } +#endif \ No newline at end of file diff --git a/src/BuildTiles/Main/tgconstruct_math.cxx b/src/BuildTiles/Main/tgconstruct_math.cxx index 333de7a..b3257d4 100644 --- a/src/BuildTiles/Main/tgconstruct_math.cxx +++ b/src/BuildTiles/Main/tgconstruct_math.cxx @@ -28,6 +28,7 @@ #include "tgconstruct.hxx" +#if 0 SGVec3f TGConstruct::calc_normal( double area, const SGVec3d& p1, const SGVec3d& p2, const SGVec3d& p3 ) const { SGVec3f v1, v2; SGVec3f normal; @@ -65,7 +66,9 @@ SGVec3f TGConstruct::calc_normal( double area, const SGVec3d& p1, const SGVec3d& return normal; } +#endif +#if 0 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; @@ -87,7 +90,9 @@ void TGConstruct::calc_normals( std::vector<SGGeod>& geod_nodes, std::vector<SGV poly.SetTriFaceNormal( tri, normal ); } } +#endif +#if 0 void TGConstruct::CalcFaceNormals( void ) { // traverse the superpols, and calc normals for each tri within @@ -104,7 +109,9 @@ void TGConstruct::CalcFaceNormals( void ) } } } +#endif +#if 0 void TGConstruct::CalcPointNormals( void ) { // traverse triangle structure building the face normal table @@ -162,4 +169,5 @@ void TGConstruct::CalcPointNormals( void ) average /= total_area; nodes.SetNormal( i, average ); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/BuildTiles/Main/tgconstruct_mesh.cxx b/src/BuildTiles/Main/tgconstruct_mesh.cxx index 9d06665..ec568d0 100644 --- a/src/BuildTiles/Main/tgconstruct_mesh.cxx +++ b/src/BuildTiles/Main/tgconstruct_mesh.cxx @@ -27,14 +27,15 @@ #endif #include <simgear/debug/logstream.hxx> -#include <terragear/tg_polygon.hxx> -#include <terragear/tg_shapefile.hxx> -#include <terragear/tg_shapefile.hxx> -#include <terragear/tg_cgal.hxx> -#include "tgconstruct_mesh.hxx" +//#include <terragear/tg_polygon.hxx> +//#include <terragear/tg_shapefile.hxx> +//#include <terragear/tg_shapefile.hxx> +//#include <terragear/tg_cgal.hxx> +//#include "tgconstruct_mesh.hxx" +#if 0 tgMesh::tgMesh( const TGAreaDefinitions& ad, const tgAreas& p ) : area_defs(ad), polys(p) { meshObserver obs(mesh, this); @@ -182,4 +183,5 @@ void tgMesh::ToShapefile( const char* path ) for ( unsigned int i=0; i<materialLookup.size(); i++ ) { SaveFace( materialLookup[i].face, path, materialLookup[i].material.c_str() ); } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/BuildTiles/Main/tgconstruct_output.cxx b/src/BuildTiles/Main/tgconstruct_output.cxx index 274d84a..7fa923c 100644 --- a/src/BuildTiles/Main/tgconstruct_output.cxx +++ b/src/BuildTiles/Main/tgconstruct_output.cxx @@ -24,29 +24,29 @@ # include <config.h> #endif -#include <simgear/math/SGGeometry.hxx> +//#include <simgear/math/SGGeometry.hxx> #include <simgear/misc/sg_dir.hxx> -#include <simgear/io/sg_binobj.hxx> -#include <simgear/structure/exception.hxx> +//#include <simgear/io/sg_binobj.hxx> +//#include <simgear/structure/exception.hxx> #include <simgear/debug/logstream.hxx> -#include <terragear/tg_unique_vec3f.hxx> -#include <terragear/tg_unique_vec2f.hxx> +//#include <terragear/tg_unique_vec3f.hxx> +//#include <terragear/tg_unique_vec2f.hxx> #include "tgconstruct.hxx" -using std::string; +//using std::string; // collect custom objects and move to scenery area void TGConstruct::AddCustomObjects( void ) { // Create/open the output .stg file for writing SGPath dest_d(output_base.c_str()); dest_d.append(bucket.gen_base_path().c_str()); - string dest_dir = dest_d.str_native(); + std::string dest_dir = dest_d.str_native(); SGPath dest_i(dest_d); dest_i.append(bucket.gen_index_str()); dest_i.concat(".stg"); - string dest_ind = dest_i.str_native(); + std::string dest_ind = dest_i.str_native(); FILE *fp; @@ -71,7 +71,7 @@ void TGConstruct::AddCustomObjects( void ) { SGPath index(base); index.append( bucket.gen_index_str() ); index.concat(".ind"); - string index_file = index.str_native(); + std::string index_file = index.str_native(); sg_gzifstream in( index_file ); @@ -93,11 +93,11 @@ void TGConstruct::AddCustomObjects( void ) { SGPath srcbase(base); srcbase.append(name); srcbase.concat(".gz"); - string basecom = srcbase.str_native(); + std::string basecom = srcbase.str_native(); #ifdef _MSC_VER - string command = "copy " + basecom + " " + dest_dir; + std::string command = "copy " + basecom + " " + dest_dir; #else - string command = "cp " + basecom + " " + dest_dir; + std::string command = "cp " + basecom + " " + dest_dir; #endif SG_LOG( SG_GENERAL, SG_DEBUG, "running " << command ); @@ -120,7 +120,7 @@ void TGConstruct::AddCustomObjects( void ) { SGPath index(base); index.append( bucket.gen_index_str() ); index.concat(".ind"); - string index_file = index.str_native(); + std::string index_file = index.str_native(); sg_gzifstream in( index_file ); @@ -142,11 +142,11 @@ void TGConstruct::AddCustomObjects( void ) { SGPath srcbase(base); srcbase.append(name); srcbase.concat(".gz"); - string basecom = srcbase.str_native(); + std::string basecom = srcbase.str_native(); #ifdef _MSC_VER - string command = "copy " + basecom + " " + dest_dir; + std::string command = "copy " + basecom + " " + dest_dir; #else - string command = "cp " + basecom + " " + dest_dir; + std::string command = "cp " + basecom + " " + dest_dir; #endif SG_LOG( SG_GENERAL, SG_DEBUG, "running " << command ); @@ -169,6 +169,7 @@ void TGConstruct::AddCustomObjects( void ) { lock->unlock(); } +#if 0 void TGConstruct::WriteBtgFile( void ) { UniqueSGVec3fSet normals; @@ -262,9 +263,11 @@ void TGConstruct::WriteBtgFile( void ) } } } +#endif +#if 0 void TGConstruct::WriteMeshFile( void ) { } - +#endif diff --git a/src/BuildTiles/Main/tgconstruct_poly.cxx b/src/BuildTiles/Main/tgconstruct_poly.cxx index 0fa5129..eaeb8f6 100644 --- a/src/BuildTiles/Main/tgconstruct_poly.cxx +++ b/src/BuildTiles/Main/tgconstruct_poly.cxx @@ -30,26 +30,68 @@ #include <simgear/debug/logstream.hxx> #include <simgear/timing/timestamp.hxx> -#include <terragear/tg_shapefile.hxx> +// #include <terragear/tg_shapefile.hxx> #include "tgconstruct.hxx" -using std::string; +int TGConstruct::LoadLandclassPolys( void ) +{ + std::string base = bucket.gen_base_path(); + std::string index = bucket.gen_index_str(); + std::string poly_path; + tgPolygonSetList polys; + unsigned int total_polys_read = 0; + + // load 2D polygons from correct path + poly_path = work_base + "/" + base + '/' + index; + simgear::Dir d(poly_path); + if (d.exists() ) { + simgear::PathList files = d.children(simgear::Dir::TYPE_FILE); + SG_LOG( SG_CLIPPER, SG_INFO, files.size() << " Files in " << d.path() ); + + BOOST_FOREACH(const SGPath& p, files) { + std::string lext = p.complete_lower_extension(); + + // look for .shp files to load + if (lext == "shp") { + SG_LOG(SG_GENERAL, SG_INFO, "load: " << p); + + // shapefile contains multiple polygons. + // read an array of them + tgPolygonSet::fromShapefile( p, polys ); + + SG_LOG(SG_GENERAL, SG_INFO, "tgShapefile::ToPolygons returned " << polys.size() << " polygons" ); + + for ( unsigned int i=0; i<polys.size(); i++ ) { + std::string material = polys[i].getMeta().getMaterial(); + + SG_LOG(SG_GENERAL, SG_INFO, "tgShapefile::ToPolygons poly " << i << " material is " << material ); + + int area = area_defs.get_area_priority( material ); -static unsigned int cur_poly_id = 0; + SG_LOG(SG_GENERAL, SG_INFO, "tgShapefile::ToPolygons poly " << i << " area is " << area ); + + tileMesh.addPoly( area, polys[i] ); + } + } + } + } + + return 0; +} -#if 1 +#if 0 // when do we add the nodes when using CGAL? TBD // maybe just keep a list of the fixed elevation nodes. int TGConstruct::LoadLandclassPolys( void ) { int i; - string base = bucket.gen_base_path(); - string index = bucket.gen_index_str(); - string poly_path; + std::string base = bucket.gen_base_path(); + std::string index = bucket.gen_index_str(); + std::string poly_path; unsigned int total_polys_read = 0; - tgPolygon poly; - tgpolygon_list polys; + //tgPolygon poly; + //tgpolygon_list polys; SGTimeStamp addnode; SGTimeStamp start, end; @@ -126,7 +168,9 @@ int TGConstruct::LoadLandclassPolys( void ) { return total_polys_read; } -#else +#endif + +#if 0 // load all 2d polygons from the specified load disk directories and // clip against each other to resolve any overlaps int TGConstruct::LoadLandclassPolys( void ) { @@ -227,6 +271,7 @@ int TGConstruct::LoadLandclassPolys( void ) { } #endif +#if 0 bool TGConstruct::CheckMatchingNode( SGGeod& node, bool road, bool fixed ) { bool matched = false; @@ -302,7 +347,9 @@ bool TGConstruct::CheckMatchingNode( SGGeod& node, bool road, bool fixed ) return added; } +#endif +#if 0 SGGeod TGConstruct::GetNearestNodeLongitude( const SGGeod& node, const std::vector<SGGeod>& selection ) { double min_dist = std::numeric_limits<double>::infinity(); @@ -319,7 +366,9 @@ SGGeod TGConstruct::GetNearestNodeLongitude( const SGGeod& node, const std::vect return selection[min_idx]; } +#endif +#if 0 SGGeod TGConstruct::GetNearestNodeLatitude( const SGGeod& node, const std::vector<SGGeod>& selection ) { double min_dist = std::numeric_limits<double>::infinity(); @@ -336,3 +385,4 @@ SGGeod TGConstruct::GetNearestNodeLatitude( const SGGeod& node, const std::vecto return selection[min_idx]; } +#endif \ No newline at end of file diff --git a/src/BuildTiles/Main/tgconstruct_shared.cxx b/src/BuildTiles/Main/tgconstruct_shared.cxx index 79ee0f4..4597215 100644 --- a/src/BuildTiles/Main/tgconstruct_shared.cxx +++ b/src/BuildTiles/Main/tgconstruct_shared.cxx @@ -27,14 +27,15 @@ #include <iomanip> #include <simgear/misc/sg_dir.hxx> -#include <simgear/io/sg_binobj.hxx> +//#include <simgear/io/sg_binobj.hxx> #include <simgear/debug/logstream.hxx> -#include <simgear/io/lowlevel.hxx> +//#include <simgear/io/lowlevel.hxx> #include "tgconstruct.hxx" -using std::string; +//using std::string; +#if 0 void TGConstruct::CreateMatchedEdgeFiles( std::vector<SGBucket>& bucketList ) { // todo - add to work queue @@ -116,7 +117,9 @@ void TGConstruct::CreateMatchedEdgeFiles( std::vector<SGBucket>& bucketList ) lock->unlock(); } } +#endif +#if 0 void TGConstruct::LoadMatchedEdgeFiles() { // try to load matched edges - on successful load, the edge is marked immutable @@ -174,7 +177,9 @@ void TGConstruct::LoadMatchedEdgeFiles() } } } +#endif +#if 0 void TGConstruct::SaveSharedEdgeData( int stage ) { switch( stage ) { @@ -333,7 +338,9 @@ void TGConstruct::SaveSharedEdgeData( int stage ) break; } } +#endif +#if 0 void TGConstruct::LoadSharedEdgeData( int stage ) { switch( stage ) { @@ -428,7 +435,9 @@ void TGConstruct::LoadSharedEdgeData( int stage ) break; } } +#endif +#if 0 // Neighbor faces void TGConstruct::WriteNeighborFaces( gzFile& fp, const SGGeod& pt ) const { @@ -461,7 +470,9 @@ void TGConstruct::WriteNeighborFaces( gzFile& fp, const SGGeod& pt ) const sgWriteVec3( fp, face_normal ); } } +#endif +#if 0 TGNeighborFaces* TGConstruct::FindNeighborFaces( const SGGeod& node ) { TGNeighborFaces* faces = NULL; @@ -475,7 +486,9 @@ TGNeighborFaces* TGConstruct::FindNeighborFaces( const SGGeod& node ) return faces; } +#endif +#if 0 TGNeighborFaces* TGConstruct::AddNeighborFaces( const SGGeod& node ) { TGNeighborFaces faces; @@ -485,7 +498,9 @@ TGNeighborFaces* TGConstruct::AddNeighborFaces( const SGGeod& node ) return &neighbor_faces[neighbor_faces.size()-1]; } +#endif +#if 0 void TGConstruct::ReadNeighborFaces( gzFile& fp ) { int count; @@ -532,8 +547,10 @@ void TGConstruct::ReadNeighborFaces( gzFile& fp ) } } } +#endif +#if 0 // Tile data void TGConstruct::SaveToIntermediateFiles( int stage ) { @@ -613,7 +630,9 @@ void TGConstruct::SaveToIntermediateFiles( int stage ) } } } +#endif +#if 0 void TGConstruct::LoadNeighboorEdgeDataStage1( SGBucket& b, std::vector<SGGeod>& north, std::vector<SGGeod>& south, std::vector<SGGeod>& east, std::vector<SGGeod>& west ) { string dir; @@ -667,7 +686,9 @@ void TGConstruct::LoadNeighboorEdgeDataStage1( SGBucket& b, std::vector<SGGeod>& gzclose( fp ); } } +#endif +#if 0 void TGConstruct::LoadNeighboorMatchDataStage1( SGBucket& b, std::vector<SGGeod>& north, std::vector<SGGeod>& south, std::vector<SGGeod>& east, std::vector<SGGeod>& west ) { string dir; @@ -721,7 +742,9 @@ void TGConstruct::LoadNeighboorMatchDataStage1( SGBucket& b, std::vector<SGGeod> gzclose( fp ); } } +#endif +#if 0 void TGConstruct::LoadFromIntermediateFiles( int stage ) { string dir; @@ -783,3 +806,4 @@ void TGConstruct::LoadFromIntermediateFiles( int stage ) isOcean = true; } } +#endif \ No newline at end of file diff --git a/src/BuildTiles/Main/tgconstruct_tesselate.cxx b/src/BuildTiles/Main/tgconstruct_tesselate.cxx index 9d88231..1c63ac6 100644 --- a/src/BuildTiles/Main/tgconstruct_tesselate.cxx +++ b/src/BuildTiles/Main/tgconstruct_tesselate.cxx @@ -27,10 +27,11 @@ #include <simgear/debug/logstream.hxx> -#include <terragear/tg_shapefile.hxx> +//#include <terragear/tg_shapefile.hxx> #include "tgconstruct.hxx" +#if 0 void TGConstruct::TesselatePolys( void ) { // tesselate the polygons and prepair them for final output @@ -67,3 +68,4 @@ void TGConstruct::TesselatePolys( void ) } } } +#endif \ No newline at end of file diff --git a/src/BuildTiles/Main/tgconstruct_texture.cxx b/src/BuildTiles/Main/tgconstruct_texture.cxx index 0df5785..5ad1c82 100644 --- a/src/BuildTiles/Main/tgconstruct_texture.cxx +++ b/src/BuildTiles/Main/tgconstruct_texture.cxx @@ -28,6 +28,7 @@ #include <simgear/debug/logstream.hxx> #include "tgconstruct.hxx" +#if 0 void TGConstruct::CalcTextureCoordinates( void ) { for ( unsigned int area = 0; area < area_defs.size(); area++ ) { @@ -40,4 +41,5 @@ void TGConstruct::CalcTextureCoordinates( void ) polys_clipped.set_poly(area, p, poly); } } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/Lib/terragear/mesh/tg_mesh.cxx b/src/Lib/terragear/mesh/tg_mesh.cxx index 0d4187d..7ab367f 100644 --- a/src/Lib/terragear/mesh/tg_mesh.cxx +++ b/src/Lib/terragear/mesh/tg_mesh.cxx @@ -2,18 +2,41 @@ #include "tg_mesh.hxx" -void tgMesh::init( unsigned int pris, const std::vector<std::string>& names, const std::string& dbgRoot ) +void tgMesh::initPriorities( const std::vector<std::string>& names ) { - numPriorities = pris; priorityNames = names; + numPriorities = names.size(); + + for ( unsigned int i=0; i<numPriorities; i++ ) { + tgPolygonSetList lc; + sourcePolys.push_back( lc ); + } +} + +void tgMesh::initDebug( const std::string& dbgRoot ) +{ snprintf(datasource, sizeof(datasource), "./%s", dbgRoot.c_str() ); + sourcePolys.clear(); for ( unsigned int i=0; i<numPriorities; i++ ) { tgPolygonSetList lc; sourcePolys.push_back( lc ); } } +void tgMesh::clear( void ) +{ + // clear source polys + for ( unsigned int i=0; i<numPriorities; i++ ) { + sourcePolys.clear(); + } + + meshPointLocation.detach(); + meshArr.clear(); + meshTriangulation.clear(); + metaLookup.clear(); +} + void tgMesh::addPoly( unsigned int priority, const tgPolygonSet& poly ) { sourcePolys[priority].push_back( poly ); @@ -31,24 +54,38 @@ tgPolygonSet tgMesh::join( unsigned int priority, const tgPolygonSetMeta& meta ) void tgMesh::generate( void ) { + bool havePolys = false; + + for ( unsigned int i=0; i<numPriorities && !havePolys; i++ ) { + std::vector<tgPolygonSet>::iterator poly_it; + if ( !sourcePolys[i].empty() ) { + havePolys = true; + } + } + // mesh generation from polygon soup :) + if ( havePolys ) { + SG_LOG(SG_GENERAL, SG_ALERT, "have source polys" ); - // Step 1 - clip polys against one another - highest priority first ( on top ) - clipPolys(); + // Step 1 - clip polys against one another - highest priority first ( on top ) + clipPolys(); - // Step 2 - insert clipped polys into an arrangement. - // From this point on, we don't need the individual polygons. - arrangePolys(); + // Step 2 - insert clipped polys into an arrangement. + // From this point on, we don't need the individual polygons. + arrangePolys(); - // step 3 - clean up the arrangement - cluster nodes that are too close - don't want - // really small triangles blowing up the refined mesh. - // NOTE / TODO: - // The cluster size MUST be smaller than the minimum distance of interiorPoints. - // we should remember be checking the delta in interiorPoints to see if we have - // polys that don't meat this criteria. - // and if it doesn't - what do we do? - cleanArrangement(); + // step 3 - clean up the arrangement - cluster nodes that are too close - don't want + // really small triangles blowing up the refined mesh. + // NOTE / TODO: + // The cluster size MUST be smaller than the minimum distance of interiorPoints. + // we should remember be checking the delta in interiorPoints to see if we have + // polys that don't meat this criteria. + // and if it doesn't - what do we do? + cleanArrangement(); - // step 4 - create constrained triangulation with arrangement edges as the constraints - constrainedTriangulate(); + // step 4 - create constrained triangulation with arrangement edges as the constraints + constrainedTriangulate(); + } else { + SG_LOG(SG_GENERAL, SG_ALERT, "no source polys" ); + } } \ No newline at end of file diff --git a/src/Lib/terragear/mesh/tg_mesh.hxx b/src/Lib/terragear/mesh/tg_mesh.hxx index 47d134a..f71e9bf 100644 --- a/src/Lib/terragear/mesh/tg_mesh.hxx +++ b/src/Lib/terragear/mesh/tg_mesh.hxx @@ -20,7 +20,10 @@ public: class tgMesh { public: - void init( unsigned int numPriorities, const std::vector<std::string>& priorityNames, const std::string& dbgRoot ); + void initDebug( const std::string& dbgRoot ); + void initPriorities( const std::vector<std::string>& priorityNames ); + void clear( void ); + void addPoly( unsigned int priority, const tgPolygonSet& poly ); void addPolys( unsigned int priority, const tgPolygonSetList& polys ); diff --git a/src/Lib/terragear/polygon_set/tg_polygon_set.hxx b/src/Lib/terragear/polygon_set/tg_polygon_set.hxx index fa516c5..3560538 100644 --- a/src/Lib/terragear/polygon_set/tg_polygon_set.hxx +++ b/src/Lib/terragear/polygon_set/tg_polygon_set.hxx @@ -84,6 +84,7 @@ public: max_clipv = max_v; } + const std::string& getMaterial( void ) { return material; } void setMaterial( const std::string& mat ) { material = mat; } void setTextureRef( const cgalPoly_Point& r, double w, double l, double h ) { @@ -191,6 +192,7 @@ public: void toShapefile( OGRLayer* layer ) const; static void toShapefile( const cgalPoly_Polygon& poly, const char* datasource, const char* layer ); + static void fromShapefile( const SGPath& p, tgPolygonSetList& polys ); void toSegments( std::vector<cgalPoly_Segment>& segs, bool withHoles ) const; @@ -226,6 +228,9 @@ private: void toShapefile( OGRLayer* poLayer, const cgalPoly_Polygon& poly ) const; void toShapefile( OGRLayer* poLayer, const cgalPoly_Arrangement& arr ) const; + static void fromShapefile( const OGRFeatureDefn* poFDefn, OGRCoordinateTransformation* poCT, OGRFeature* poFeature, tgPolygonSetList& polys ); + static void processLayer( OGRLayer* poLayer, tgPolygonSetList& polys ); + void polygonToSegmentList( const cgalPoly_Polygon& p, std::vector<cgalPoly_Segment>& segs ) const; void findIntersections( const cgalPoly_PolygonWithHoles& pwh, const cgalPoly_Line& line, std::vector<cgalPoly_Point>& intersections ) const; cgalPoly_Point getInteriorPoint( const cgalPoly_PolygonWithHoles& pwh ) const; diff --git a/src/Lib/terragear/polygon_set/tg_polygon_set_io.cxx b/src/Lib/terragear/polygon_set/tg_polygon_set_io.cxx index c3adca1..048fd3c 100644 --- a/src/Lib/terragear/polygon_set/tg_polygon_set_io.cxx +++ b/src/Lib/terragear/polygon_set/tg_polygon_set_io.cxx @@ -84,6 +84,8 @@ tgPolygonSet::tgPolygonSet( OGRFeature* poFeature, OGRPolygon* poGeometry ) // generate texture info from feature meta.getFeatureFields( poFeature ); + SG_LOG( SG_GENERAL, SG_INFO, "got material: " << meta.getMaterial() ); + // create PolygonSet from the outer ring OGRLinearRing const *ring = poGeometry->getExteriorRing(); nodes.clear(); @@ -159,7 +161,12 @@ OGRLayer* tgPolygonSet::openLayer( GDALDataset* poDS, OGRwkbGeometryType lt, con if( poLayer->CreateField( &idField ) != OGRERR_NONE ) { SG_LOG( SG_GENERAL, SG_ALERT, "Creation of field 'tg_id' failed" ); } - + + OGRFieldDefn metaField( "tg_meta", OFTInteger ); + if( poLayer->CreateField( &metaField ) != OGRERR_NONE ) { + SG_LOG( SG_GENERAL, SG_ALERT, "Creation of field 'meta' failed" ); + } + OGRFieldDefn fidField( "OGC_FID", OFTInteger ); if( poLayer->CreateField( &fidField ) != OGRERR_NONE ) { SG_LOG( SG_GENERAL, SG_ALERT, "Creation of field 'OGC_FID' failed" ); @@ -577,205 +584,122 @@ void tgPolygonSet::toShapefile( const cgalPoly_Polygon& poly, const char* dataso GDALClose( poDS ); } -#if 0 // native from GDAL -tgPolygonSet tgPolygonSet::fromGDAL( OGRPolygon* poGeometry ) -{ - cgalPoly_Arrangement arr; - cgalPoly_PolygonSet boundaries; - cgalPoly_PolygonSet holes; - - // for each boundary contour, we add it to its own arrangement - // then read the resulting faces as a list of polygons with holes - // note that a self intersecting face ( like a donut ) will generate - // more than one face. We need to determine for each face wether it is a - // hole or not. - // ___________ - // | ______ | - // | \ / | - // | \ / | - // |___\/____| - // - // Example of a single self intersecting contour that should be represented by a polygon - for (unsigned int i=0; i<subject.Contours(); i++ ) { - char layer[128]; - - //sprintf( layer, "%04u_original_contour_%d"... [truncated message content] |