Use a SGGeod bounding box instead of SGVec3 for geodetic coordinates
This commit is contained in:
parent
c336c134bf
commit
8d4495d470
7 changed files with 30 additions and 51 deletions
|
@ -1,14 +1,9 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
#include <simgear/math/sg_geodesy.hxx>
|
||||
#include <simgear/math/SGVec3.hxx>
|
||||
#include <simgear/math/SGMisc.hxx>
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
#include <simgear/math/SGGeometryFwd.hxx>
|
||||
#include <simgear/math/SGBox.hxx>
|
||||
#include <simgear/math/SGIntersect.hxx>
|
||||
|
||||
#include <Geometry/poly_support.hxx>
|
||||
#include <Geometry/util.hxx>
|
||||
|
||||
// for debugging clipping errors
|
||||
#include <Polygon/chop.hxx>
|
||||
|
@ -931,7 +926,7 @@ int LinearFeature::BuildBtg(superpoly_list* line_polys, texparams_list* line_tps
|
|||
TGPolygon poly, tmp;
|
||||
void* ds_id = NULL; // If we are going to build shapefiles
|
||||
void* l_id = NULL; // datasource and layer IDs
|
||||
SGVec3d min, max, minp, maxp;
|
||||
SGGeod min, max, minp, maxp;
|
||||
|
||||
if ( make_shapefiles ) {
|
||||
char ds_name[128];
|
||||
|
@ -944,16 +939,16 @@ int LinearFeature::BuildBtg(superpoly_list* line_polys, texparams_list* line_tps
|
|||
{
|
||||
poly = marking_polys[i].get_poly();
|
||||
poly.get_bounding_box(minp, maxp);
|
||||
SGBoxd box1(minp, maxp);
|
||||
tg::Rectangle box1(minp, maxp);
|
||||
|
||||
for (int j= 0; j < lines->contours(); ++j)
|
||||
{
|
||||
tmp.erase();
|
||||
tmp.add_contour(lines->get_contour(j), 0);
|
||||
tmp.get_bounding_box(min, max);
|
||||
SGBoxd box2(min, max);
|
||||
tg::Rectangle box2(min, max);
|
||||
|
||||
if ( intersects(box2, box1 ) )
|
||||
if ( box2.intersects(box1) )
|
||||
{
|
||||
poly = tgPolygonDiffClipper( poly, tmp );
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ void TGConstruct::TesselatePolys( void )
|
|||
{
|
||||
// tesselate the polygons and prepair them for final output
|
||||
point_list poly_extra;
|
||||
SGVec3d min, max;
|
||||
SGGeod min, max;
|
||||
|
||||
for (unsigned int area = 0; area < TG_MAX_AREA_TYPES; area++) {
|
||||
for (unsigned int shape = 0; shape < polys_clipped.area_size(area); shape++ ) {
|
||||
|
@ -53,7 +53,7 @@ void TGConstruct::TesselatePolys( void )
|
|||
TGPolygon poly = polys_clipped.get_poly(area, shape, segment);
|
||||
|
||||
poly.get_bounding_box(min, max);
|
||||
poly_extra = nodes.get_geod_inside( Point3D::fromSGVec3(min), Point3D::fromSGVec3(max) );
|
||||
poly_extra = nodes.get_geod_inside( Point3D::fromSGGeod(min), Point3D::fromSGGeod(max) );
|
||||
|
||||
SG_LOG( SG_CLIPPER, SG_INFO, "Tesselating " << get_area_name( (AreaType)area ) << "(" << area << "): " <<
|
||||
shape+1 << "-" << segment << " of " << (int)polys_clipped.area_size(area) <<
|
||||
|
|
|
@ -111,14 +111,14 @@ TGPolygon add_nodes_to_poly( const TGPolygon& poly,
|
|||
TGPolygon add_tgnodes_to_poly( const TGPolygon& poly,
|
||||
const TGNodes* nodes ) {
|
||||
TGPolygon result; result.erase();
|
||||
SGVec3d min, max;
|
||||
SGGeod min, max;
|
||||
Point3D p0, p1;
|
||||
point_list poly_points;
|
||||
|
||||
poly.get_bounding_box(min, max);
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "add_tgnodes_to_poly : min " << min << " max " << max );
|
||||
|
||||
poly_points = nodes->get_geod_inside( Point3D::fromSGVec3(min), Point3D::fromSGVec3(max) );
|
||||
poly_points = nodes->get_geod_inside( Point3D::fromSGGeod(min), Point3D::fromSGGeod(max) );
|
||||
|
||||
for ( int i = 0; i < poly.contours(); ++i ) {
|
||||
SG_LOG(SG_GENERAL, SG_DEBUG, "contour = " << i);
|
||||
|
|
|
@ -64,7 +64,7 @@ Rectangle::isInside (const SGGeod &p) const
|
|||
}
|
||||
|
||||
bool
|
||||
Rectangle::isOverlapping (const Rectangle &r) const
|
||||
Rectangle::intersects (const Rectangle &r) const
|
||||
{
|
||||
const SGGeod &min = r.getMin();
|
||||
const SGGeod &max = r.getMax();
|
||||
|
|
|
@ -118,7 +118,7 @@ public:
|
|||
* @return true if the rectangle is touching or overlapping, false
|
||||
* otherwise.
|
||||
*/
|
||||
virtual bool isOverlapping (const Rectangle &r) const;
|
||||
virtual bool intersects (const Rectangle &r) const;
|
||||
|
||||
/**
|
||||
* Create a polygon representation of this rectangle.
|
||||
|
|
|
@ -18,13 +18,6 @@
|
|||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id: polygon.cxx,v 1.30 2007-11-05 14:02:21 curt Exp $
|
||||
|
||||
|
||||
// include Generic Polygon Clipping Library
|
||||
//
|
||||
// http://www.cs.man.ac.uk/aig/staff/alan/software/
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
@ -35,13 +28,8 @@
|
|||
#include <Geometry/point3d.hxx>
|
||||
#include <Geometry/poly_support.hxx>
|
||||
#include <simgear/math/sg_geodesy.hxx>
|
||||
#include <simgear/math/SGVec3.hxx>
|
||||
#include <simgear/math/SGMisc.hxx>
|
||||
#include <simgear/math/SGMath.hxx>
|
||||
#include <simgear/math/SGGeometryFwd.hxx>
|
||||
#include <simgear/math/SGBox.hxx>
|
||||
#include <simgear/math/SGIntersect.hxx>
|
||||
#include <simgear/structure/exception.hxx>
|
||||
#include <Geometry/util.hxx>
|
||||
|
||||
#include <Geometry/trinodes.hxx>
|
||||
|
||||
|
@ -60,7 +48,7 @@ TGPolygon::TGPolygon( void )
|
|||
TGPolygon::~TGPolygon( void ) {
|
||||
}
|
||||
|
||||
void TGPolygon::get_bounding_box( SGVec3d& min, SGVec3d& max ) const
|
||||
void TGPolygon::get_bounding_box( SGGeod& min, SGGeod& max ) const
|
||||
{
|
||||
double minx = std::numeric_limits<double>::infinity();
|
||||
double miny = std::numeric_limits<double>::infinity();
|
||||
|
@ -69,16 +57,16 @@ void TGPolygon::get_bounding_box( SGVec3d& min, SGVec3d& max ) const
|
|||
|
||||
for ( int i = 0; i < contours(); i++ ) {
|
||||
for (unsigned int j = 0; j < poly[i].size(); j++) {
|
||||
SGVec3d pt = poly[i][j].toSGVec3d();
|
||||
if ( pt.x() < minx ) { minx = pt.x(); }
|
||||
if ( pt.x() > maxx ) { maxx = pt.x(); }
|
||||
if ( pt.y() < miny ) { miny = pt.y(); }
|
||||
if ( pt.y() > maxy ) { maxy = pt.y(); }
|
||||
SGGeod pt = poly[i][j].toSGGeod();
|
||||
if ( pt.getLongitudeDeg() < minx ) { minx = pt.getLongitudeDeg(); }
|
||||
if ( pt.getLongitudeDeg() > maxx ) { maxx = pt.getLongitudeDeg(); }
|
||||
if ( pt.getLatitudeDeg() < miny ) { miny = pt.getLatitudeDeg(); }
|
||||
if ( pt.getLatitudeDeg() > maxy ) { maxy = pt.getLatitudeDeg(); }
|
||||
}
|
||||
}
|
||||
|
||||
min = SGVec3d( minx, miny, 0.0 );
|
||||
max = SGVec3d( maxx, maxy, 0.0 );
|
||||
min = SGGeod::fromDeg( minx, miny );
|
||||
max = SGGeod::fromDeg( maxx, maxy );
|
||||
}
|
||||
|
||||
|
||||
|
@ -420,17 +408,13 @@ static Point3D MakeTGPoint( ClipperLib::IntPoint pt )
|
|||
return tg_pt;
|
||||
}
|
||||
|
||||
static SGVec3d MakeSGVec3D( ClipperLib::IntPoint pt )
|
||||
static SGGeod MakeSGGeod( ClipperLib::IntPoint pt )
|
||||
{
|
||||
SGVec3d sgvec;
|
||||
double x, y;
|
||||
|
||||
x = (double)( ((double)pt.X) / (double)FIXEDPT );
|
||||
y = (double)( ((double)pt.Y) / (double)FIXEDPT );
|
||||
|
||||
sgvec = SGVec3d( x, y, 0.0f);
|
||||
|
||||
return sgvec;
|
||||
return SGGeod::fromDeg(x, y);
|
||||
}
|
||||
|
||||
double MakeClipperDelta( double mDelta )
|
||||
|
@ -502,7 +486,7 @@ void make_tg_poly_from_clipper( const ClipperLib::Polygons& in, TGPolygon *out )
|
|||
}
|
||||
|
||||
|
||||
void get_Clipper_bounding_box( const ClipperLib::Polygons& in, SGVec3d& min, SGVec3d& max )
|
||||
void get_Clipper_bounding_box( const ClipperLib::Polygons& in, SGGeod& min, SGGeod& max )
|
||||
{
|
||||
ClipperLib::IntPoint min_pt, max_pt;
|
||||
|
||||
|
@ -530,8 +514,8 @@ void get_Clipper_bounding_box( const ClipperLib::Polygons& in, SGVec3d& min, SGV
|
|||
}
|
||||
}
|
||||
|
||||
min = MakeSGVec3D( min_pt );
|
||||
max = MakeSGVec3D( max_pt );
|
||||
min = MakeSGGeod( min_pt );
|
||||
max = MakeSGGeod( max_pt );
|
||||
}
|
||||
|
||||
void clipper_to_shapefile( ClipperLib::Polygons polys, char* ds )
|
||||
|
@ -666,7 +650,7 @@ void tgPolygonAddToClipperAccumulator( const TGPolygon& subject, bool dump )
|
|||
TGPolygon tgPolygonDiffClipperWithAccumulator( const TGPolygon& subject )
|
||||
{
|
||||
TGPolygon result;
|
||||
SGVec3d min, max, minp, maxp;
|
||||
SGGeod min, max, minp, maxp;
|
||||
unsigned int num_hits = 0;
|
||||
|
||||
ClipperLib::Polygons clipper_subject;
|
||||
|
@ -675,7 +659,7 @@ TGPolygon tgPolygonDiffClipperWithAccumulator( const TGPolygon& subject )
|
|||
// Start with full poly
|
||||
result = subject;
|
||||
result.get_bounding_box(minp, maxp);
|
||||
SGBoxd box1(minp, maxp);
|
||||
tg::Rectangle box1(minp, maxp);
|
||||
|
||||
ClipperLib::Clipper c;
|
||||
c.Clear();
|
||||
|
@ -685,9 +669,9 @@ TGPolygon tgPolygonDiffClipperWithAccumulator( const TGPolygon& subject )
|
|||
// clip result against all polygons in the accum that intersect our bb
|
||||
for (unsigned int i=0; i < clipper_accumulator.size(); i++) {
|
||||
get_Clipper_bounding_box( clipper_accumulator[i], min, max);
|
||||
SGBoxd box2(min, max);
|
||||
tg::Rectangle box2(min, max);
|
||||
|
||||
if ( intersects( box2, box1 ) )
|
||||
if ( box2.intersects(box1) )
|
||||
{
|
||||
c.AddPolygons(clipper_accumulator[i], ClipperLib::ptClip);
|
||||
num_hits++;
|
||||
|
|
|
@ -138,7 +138,7 @@ public:
|
|||
poly[contour][i] = p;
|
||||
}
|
||||
|
||||
void get_bounding_box( SGVec3d& min, SGVec3d& max ) const;
|
||||
void get_bounding_box( SGGeod& min, SGGeod& max ) const;
|
||||
|
||||
// get and set an arbitrary point inside the specified polygon contour
|
||||
inline Point3D get_point_inside( const int contour ) const
|
||||
|
|
Loading…
Reference in a new issue