Utilize SGBucket::get_corner when building clip rectangles in
ogr-decode, genapts, and tg-construct.
This commit is contained in:
parent
5d45916b23
commit
c9074ab45c
3 changed files with 25 additions and 66 deletions
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include <terragear/tg_accumulator.hxx>
|
#include <terragear/tg_accumulator.hxx>
|
||||||
#include <terragear/tg_shapefile.hxx>
|
#include <terragear/tg_shapefile.hxx>
|
||||||
|
#include <terragear/tg_misc.hxx>
|
||||||
|
|
||||||
#include "tgconstruct.hxx"
|
#include "tgconstruct.hxx"
|
||||||
|
|
||||||
|
@ -39,32 +40,28 @@ bool TGConstruct::ClipLandclassPolys( void ) {
|
||||||
tgPolygon safety_base;
|
tgPolygon safety_base;
|
||||||
tgcontour_list slivers;
|
tgcontour_list slivers;
|
||||||
SGGeod p;
|
SGGeod p;
|
||||||
SGVec2d min, max;
|
|
||||||
bool debug_area, debug_shape;
|
bool debug_area, debug_shape;
|
||||||
static int accum_idx = 0;
|
static int accum_idx = 0;
|
||||||
|
|
||||||
// Get clip bounds
|
|
||||||
min.x() = bucket.get_center_lon() - 0.5 * bucket.get_width();
|
|
||||||
min.y() = bucket.get_center_lat() - 0.5 * bucket.get_height();
|
|
||||||
max.x() = bucket.get_center_lon() + 0.5 * bucket.get_width();
|
|
||||||
max.y() = bucket.get_center_lat() + 0.5 * bucket.get_height();
|
|
||||||
|
|
||||||
tgAccumulator accum;
|
tgAccumulator accum;
|
||||||
|
|
||||||
// set up clipping tile : and remember to add the nodes!
|
// set up clipping tile : and remember to add the nodes!
|
||||||
p = SGGeod::fromDegM( min.x(), min.y(), -9999.0 );
|
p = bucket.get_corner( SG_BUCKET_SW );
|
||||||
|
p.setElevationM( -9999.0 );
|
||||||
safety_base.AddNode( 0, p );
|
safety_base.AddNode( 0, p );
|
||||||
nodes.unique_add( p );
|
nodes.unique_add( p );
|
||||||
|
|
||||||
p = SGGeod::fromDegM( max.x(), min.y(), -9999.0 );
|
p = bucket.get_corner( SG_BUCKET_SE );
|
||||||
|
p.setElevationM( -9999.0 );
|
||||||
safety_base.AddNode( 0, p );
|
safety_base.AddNode( 0, p );
|
||||||
nodes.unique_add( p );
|
nodes.unique_add( p );
|
||||||
|
|
||||||
p = SGGeod::fromDegM( max.x(), max.y(), -9999.0 );
|
p = bucket.get_corner( SG_BUCKET_NE );
|
||||||
|
p.setElevationM( -9999.0 );
|
||||||
safety_base.AddNode( 0, p );
|
safety_base.AddNode( 0, p );
|
||||||
nodes.unique_add( p );
|
nodes.unique_add( p );
|
||||||
|
|
||||||
p = SGGeod::fromDegM( min.x(), max.y(), -9999.0 );
|
p = bucket.get_corner( SG_BUCKET_NW );
|
||||||
|
p.setElevationM( -9999.0 );
|
||||||
safety_base.AddNode( 0, p );
|
safety_base.AddNode( 0, p );
|
||||||
nodes.unique_add( p );
|
nodes.unique_add( p );
|
||||||
|
|
||||||
|
|
|
@ -6,44 +6,21 @@
|
||||||
#include <simgear/misc/sg_path.hxx>
|
#include <simgear/misc/sg_path.hxx>
|
||||||
#include <simgear/io/lowlevel.hxx>
|
#include <simgear/io/lowlevel.hxx>
|
||||||
|
|
||||||
|
|
||||||
#include "tg_chopper.hxx"
|
#include "tg_chopper.hxx"
|
||||||
#include "tg_shapefile.hxx"
|
#include "tg_shapefile.hxx"
|
||||||
|
#include "tg_misc.hxx"
|
||||||
unsigned int clip_num = 0;
|
|
||||||
|
|
||||||
tgPolygon tgChopper::Clip( const tgPolygon& subject,
|
tgPolygon tgChopper::Clip( const tgPolygon& subject,
|
||||||
const std::string& type,
|
const std::string& type,
|
||||||
SGBucket& b )
|
SGBucket& b )
|
||||||
{
|
{
|
||||||
// p;
|
|
||||||
|
|
||||||
SGGeod min, max;
|
|
||||||
SGGeod c = b.get_center();
|
|
||||||
double span = b.get_width();
|
|
||||||
tgPolygon base, result;
|
tgPolygon base, result;
|
||||||
|
|
||||||
// calculate bucket dimensions
|
// set up clipping tile : and remember to add the nodes!
|
||||||
if ( (c.getLatitudeDeg() >= -89.0) && (c.getLatitudeDeg() < 89.0) ) {
|
base.AddNode( 0, b.get_corner( SG_BUCKET_SW ) );
|
||||||
min = SGGeod::fromDeg( c.getLongitudeDeg() - span/2.0, c.getLatitudeDeg() - SG_HALF_BUCKET_SPAN );
|
base.AddNode( 0, b.get_corner( SG_BUCKET_SE ) );
|
||||||
max = SGGeod::fromDeg( c.getLongitudeDeg() + span/2.0, c.getLatitudeDeg() + SG_HALF_BUCKET_SPAN );
|
base.AddNode( 0, b.get_corner( SG_BUCKET_NE ) );
|
||||||
} else if ( c.getLatitudeDeg() < -89.0) {
|
base.AddNode( 0, b.get_corner( SG_BUCKET_NW ) );
|
||||||
min = SGGeod::fromDeg( -90.0, -180.0 );
|
|
||||||
max = SGGeod::fromDeg( -89.0, 180.0 );
|
|
||||||
} else if ( c.getLatitudeDeg() >= 89.0) {
|
|
||||||
min = SGGeod::fromDeg( 89.0, -180.0 );
|
|
||||||
max = SGGeod::fromDeg( 90.0, 180.0 );
|
|
||||||
} else {
|
|
||||||
SG_LOG( SG_GENERAL, SG_ALERT, "Out of range latitude in clip_and_write_poly() = " << c.getLatitudeDeg() );
|
|
||||||
}
|
|
||||||
|
|
||||||
SG_LOG( SG_GENERAL, SG_DEBUG, " (" << min << ") (" << max << ")" );
|
|
||||||
|
|
||||||
// set up clipping tile
|
|
||||||
base.AddNode( 0, SGGeod::fromDeg( min.getLongitudeDeg(), min.getLatitudeDeg()) );
|
|
||||||
base.AddNode( 0, SGGeod::fromDeg( max.getLongitudeDeg(), min.getLatitudeDeg()) );
|
|
||||||
base.AddNode( 0, SGGeod::fromDeg( max.getLongitudeDeg(), max.getLatitudeDeg()) );
|
|
||||||
base.AddNode( 0, SGGeod::fromDeg( min.getLongitudeDeg(), max.getLatitudeDeg()) );
|
|
||||||
|
|
||||||
result = tgPolygon::Intersect( subject, base );
|
result = tgPolygon::Intersect( subject, base );
|
||||||
if ( result.Contours() > 0 ) {
|
if ( result.Contours() > 0 ) {
|
||||||
|
@ -123,12 +100,10 @@ void tgChopper::Add( const tgPolygon& subject, const std::string& type )
|
||||||
|
|
||||||
for ( int row = 0; row <= dy; row++ )
|
for ( int row = 0; row <= dy; row++ )
|
||||||
{
|
{
|
||||||
// Generate a clip rectangle - add some buffer on top and bottom, so we don't clip directly on an edge when we
|
// Generate a clip rectangle for the whole row
|
||||||
// clip the individual buckets
|
|
||||||
// TODO : May no longer be necessary
|
|
||||||
SGBucket b_clip = sgBucketOffset( bb.getMin().getLongitudeDeg(), bb.getMin().getLatitudeDeg(), 0, row );
|
SGBucket b_clip = sgBucketOffset( bb.getMin().getLongitudeDeg(), bb.getMin().getLatitudeDeg(), 0, row );
|
||||||
double clip_bottom = b_clip.get_center_lat() - SG_HALF_BUCKET_SPAN; // + 0.01);
|
double clip_bottom = b_clip.get_center_lat() - SG_HALF_BUCKET_SPAN;
|
||||||
double clip_top = b_clip.get_center_lat() + SG_HALF_BUCKET_SPAN; // + 0.01);
|
double clip_top = b_clip.get_center_lat() + SG_HALF_BUCKET_SPAN;
|
||||||
tgPolygon clip_row, clipped;
|
tgPolygon clip_row, clipped;
|
||||||
|
|
||||||
SG_LOG( SG_GENERAL, SG_DEBUG, " CLIPPED row " << row << " center lat is " << b_clip.get_center_lat() << " clip_botton is " << clip_bottom << " clip_top is " << clip_top );
|
SG_LOG( SG_GENERAL, SG_DEBUG, " CLIPPED row " << row << " center lat is " << b_clip.get_center_lat() << " clip_botton is " << clip_bottom << " clip_top is " << clip_top );
|
||||||
|
@ -153,26 +128,6 @@ void tgChopper::Add( const tgPolygon& subject, const std::string& type )
|
||||||
clipped.SetFlag(type);
|
clipped.SetFlag(type);
|
||||||
|
|
||||||
ClipRow( clipped, b_clip.get_center_lat(), type );
|
ClipRow( clipped, b_clip.get_center_lat(), type );
|
||||||
|
|
||||||
#if 0
|
|
||||||
{
|
|
||||||
char layer[32];
|
|
||||||
char ds_name[64];
|
|
||||||
sprintf(ds_name, "./stripped_%s", type.c_str() );
|
|
||||||
|
|
||||||
sprintf(layer, "orig_%d", clip_num );
|
|
||||||
tgShapefile::FromPolygon( subject, ds_name, layer, "poly" );
|
|
||||||
|
|
||||||
sprintf(layer, "clip_row_%d", clip_num );
|
|
||||||
tgShapefile::FromPolygon( clip_row, ds_name, layer, "poly" );
|
|
||||||
|
|
||||||
sprintf(layer, "result_%d", clip_num );
|
|
||||||
tgShapefile::FromPolygon( clipped, ds_name, layer, "poly" );
|
|
||||||
|
|
||||||
clip_num++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,13 @@
|
||||||
#include "clipper.hpp"
|
#include "clipper.hpp"
|
||||||
#include "tg_rectangle.hxx"
|
#include "tg_rectangle.hxx"
|
||||||
|
|
||||||
|
// SGBucket corners
|
||||||
|
#define SG_BUCKET_SW (0)
|
||||||
|
#define SG_BUCKET_SE (1)
|
||||||
|
#define SG_BUCKET_NE (2)
|
||||||
|
#define SG_BUCKET_NW (3)
|
||||||
|
|
||||||
|
|
||||||
// SGGeod Cleanup
|
// SGGeod Cleanup
|
||||||
SGGeod SGGeod_snap( const SGGeod& in, double grid );
|
SGGeod SGGeod_snap( const SGGeod& in, double grid );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue