1
0
Fork 0

Use a SGGeod bounding box instead of SGVec3 for geodetic coordinates

This commit is contained in:
Christian Schmitt 2012-10-17 23:06:29 +02:00
parent c336c134bf
commit 8d4495d470
7 changed files with 30 additions and 51 deletions

View file

@ -1,14 +1,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <simgear/math/sg_geodesy.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 <Geometry/poly_support.hxx> #include <Geometry/poly_support.hxx>
#include <Geometry/util.hxx>
// for debugging clipping errors // for debugging clipping errors
#include <Polygon/chop.hxx> #include <Polygon/chop.hxx>
@ -931,7 +926,7 @@ int LinearFeature::BuildBtg(superpoly_list* line_polys, texparams_list* line_tps
TGPolygon poly, tmp; TGPolygon poly, tmp;
void* ds_id = NULL; // If we are going to build shapefiles void* ds_id = NULL; // If we are going to build shapefiles
void* l_id = NULL; // datasource and layer IDs void* l_id = NULL; // datasource and layer IDs
SGVec3d min, max, minp, maxp; SGGeod min, max, minp, maxp;
if ( make_shapefiles ) { if ( make_shapefiles ) {
char ds_name[128]; 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 = marking_polys[i].get_poly();
poly.get_bounding_box(minp, maxp); poly.get_bounding_box(minp, maxp);
SGBoxd box1(minp, maxp); tg::Rectangle box1(minp, maxp);
for (int j= 0; j < lines->contours(); ++j) for (int j= 0; j < lines->contours(); ++j)
{ {
tmp.erase(); tmp.erase();
tmp.add_contour(lines->get_contour(j), 0); tmp.add_contour(lines->get_contour(j), 0);
tmp.get_bounding_box(min, max); 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 ); poly = tgPolygonDiffClipper( poly, tmp );
} }

View file

@ -39,7 +39,7 @@ void TGConstruct::TesselatePolys( void )
{ {
// tesselate the polygons and prepair them for final output // tesselate the polygons and prepair them for final output
point_list poly_extra; point_list poly_extra;
SGVec3d min, max; SGGeod min, max;
for (unsigned int area = 0; area < TG_MAX_AREA_TYPES; area++) { for (unsigned int area = 0; area < TG_MAX_AREA_TYPES; area++) {
for (unsigned int shape = 0; shape < polys_clipped.area_size(area); shape++ ) { 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); TGPolygon poly = polys_clipped.get_poly(area, shape, segment);
poly.get_bounding_box(min, max); 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 << "): " << SG_LOG( SG_CLIPPER, SG_INFO, "Tesselating " << get_area_name( (AreaType)area ) << "(" << area << "): " <<
shape+1 << "-" << segment << " of " << (int)polys_clipped.area_size(area) << shape+1 << "-" << segment << " of " << (int)polys_clipped.area_size(area) <<

View file

@ -111,14 +111,14 @@ TGPolygon add_nodes_to_poly( const TGPolygon& poly,
TGPolygon add_tgnodes_to_poly( const TGPolygon& poly, TGPolygon add_tgnodes_to_poly( const TGPolygon& poly,
const TGNodes* nodes ) { const TGNodes* nodes ) {
TGPolygon result; result.erase(); TGPolygon result; result.erase();
SGVec3d min, max; SGGeod min, max;
Point3D p0, p1; Point3D p0, p1;
point_list poly_points; point_list poly_points;
poly.get_bounding_box(min, max); poly.get_bounding_box(min, max);
SG_LOG(SG_GENERAL, SG_DEBUG, "add_tgnodes_to_poly : min " << min << " max " << 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 ) { for ( int i = 0; i < poly.contours(); ++i ) {
SG_LOG(SG_GENERAL, SG_DEBUG, "contour = " << i); SG_LOG(SG_GENERAL, SG_DEBUG, "contour = " << i);

View file

@ -64,7 +64,7 @@ Rectangle::isInside (const SGGeod &p) const
} }
bool bool
Rectangle::isOverlapping (const Rectangle &r) const Rectangle::intersects (const Rectangle &r) const
{ {
const SGGeod &min = r.getMin(); const SGGeod &min = r.getMin();
const SGGeod &max = r.getMax(); const SGGeod &max = r.getMax();

View file

@ -118,7 +118,7 @@ public:
* @return true if the rectangle is touching or overlapping, false * @return true if the rectangle is touching or overlapping, false
* otherwise. * otherwise.
*/ */
virtual bool isOverlapping (const Rectangle &r) const; virtual bool intersects (const Rectangle &r) const;
/** /**
* Create a polygon representation of this rectangle. * Create a polygon representation of this rectangle.

View file

@ -18,13 +18,6 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. // 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 <iostream>
#include <fstream> #include <fstream>
@ -35,13 +28,8 @@
#include <Geometry/point3d.hxx> #include <Geometry/point3d.hxx>
#include <Geometry/poly_support.hxx> #include <Geometry/poly_support.hxx>
#include <simgear/math/sg_geodesy.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 <simgear/structure/exception.hxx>
#include <Geometry/util.hxx>
#include <Geometry/trinodes.hxx> #include <Geometry/trinodes.hxx>
@ -60,7 +48,7 @@ TGPolygon::TGPolygon( void )
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 minx = std::numeric_limits<double>::infinity();
double miny = 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 ( int i = 0; i < contours(); i++ ) {
for (unsigned int j = 0; j < poly[i].size(); j++) { for (unsigned int j = 0; j < poly[i].size(); j++) {
SGVec3d pt = poly[i][j].toSGVec3d(); SGGeod pt = poly[i][j].toSGGeod();
if ( pt.x() < minx ) { minx = pt.x(); } if ( pt.getLongitudeDeg() < minx ) { minx = pt.getLongitudeDeg(); }
if ( pt.x() > maxx ) { maxx = pt.x(); } if ( pt.getLongitudeDeg() > maxx ) { maxx = pt.getLongitudeDeg(); }
if ( pt.y() < miny ) { miny = pt.y(); } if ( pt.getLatitudeDeg() < miny ) { miny = pt.getLatitudeDeg(); }
if ( pt.y() > maxy ) { maxy = pt.y(); } if ( pt.getLatitudeDeg() > maxy ) { maxy = pt.getLatitudeDeg(); }
} }
} }
min = SGVec3d( minx, miny, 0.0 ); min = SGGeod::fromDeg( minx, miny );
max = SGVec3d( maxx, maxy, 0.0 ); max = SGGeod::fromDeg( maxx, maxy );
} }
@ -420,17 +408,13 @@ static Point3D MakeTGPoint( ClipperLib::IntPoint pt )
return tg_pt; return tg_pt;
} }
static SGVec3d MakeSGVec3D( ClipperLib::IntPoint pt ) static SGGeod MakeSGGeod( ClipperLib::IntPoint pt )
{ {
SGVec3d sgvec;
double x, y; double x, y;
x = (double)( ((double)pt.X) / (double)FIXEDPT ); x = (double)( ((double)pt.X) / (double)FIXEDPT );
y = (double)( ((double)pt.Y) / (double)FIXEDPT ); y = (double)( ((double)pt.Y) / (double)FIXEDPT );
sgvec = SGVec3d( x, y, 0.0f); return SGGeod::fromDeg(x, y);
return sgvec;
} }
double MakeClipperDelta( double mDelta ) 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; 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 ); min = MakeSGGeod( min_pt );
max = MakeSGVec3D( max_pt ); max = MakeSGGeod( max_pt );
} }
void clipper_to_shapefile( ClipperLib::Polygons polys, char* ds ) 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 tgPolygonDiffClipperWithAccumulator( const TGPolygon& subject )
{ {
TGPolygon result; TGPolygon result;
SGVec3d min, max, minp, maxp; SGGeod min, max, minp, maxp;
unsigned int num_hits = 0; unsigned int num_hits = 0;
ClipperLib::Polygons clipper_subject; ClipperLib::Polygons clipper_subject;
@ -675,7 +659,7 @@ TGPolygon tgPolygonDiffClipperWithAccumulator( const TGPolygon& subject )
// Start with full poly // Start with full poly
result = subject; result = subject;
result.get_bounding_box(minp, maxp); result.get_bounding_box(minp, maxp);
SGBoxd box1(minp, maxp); tg::Rectangle box1(minp, maxp);
ClipperLib::Clipper c; ClipperLib::Clipper c;
c.Clear(); c.Clear();
@ -685,9 +669,9 @@ TGPolygon tgPolygonDiffClipperWithAccumulator( const TGPolygon& subject )
// clip result against all polygons in the accum that intersect our bb // clip result against all polygons in the accum that intersect our bb
for (unsigned int i=0; i < clipper_accumulator.size(); i++) { for (unsigned int i=0; i < clipper_accumulator.size(); i++) {
get_Clipper_bounding_box( clipper_accumulator[i], min, max); 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); c.AddPolygons(clipper_accumulator[i], ClipperLib::ptClip);
num_hits++; num_hits++;

View file

@ -138,7 +138,7 @@ public:
poly[contour][i] = p; 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 // get and set an arbitrary point inside the specified polygon contour
inline Point3D get_point_inside( const int contour ) const inline Point3D get_point_inside( const int contour ) const