Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Corrections to bounding box calculations
  • Loading branch information
seandepagnier committed Apr 16, 2016
1 parent 289adec commit d8b8205
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 40 deletions.
2 changes: 1 addition & 1 deletion include/Track.h
Expand Up @@ -134,7 +134,7 @@ class Track
double ComputeScale(int left, int right);
void InsertSubTracks(LLBBox &box, int level, int pos);

void AddPointToList(std::list<wxPoint> &pointlist, int n);
void AddPointToList(std::list< std::list<wxPoint> > &pointlists, int n);
void AddPointToLists(std::list< std::list<wxPoint> > &pointlists, int &last, int n);

void Assemble(std::list< std::list<wxPoint> > &pointlists, const LLBBox &box, double scale, int &last, int level, int pos);
Expand Down
4 changes: 2 additions & 2 deletions src/RoutePoint.cpp
Expand Up @@ -545,9 +545,9 @@ void RoutePoint::DrawGL( ViewPort &vp, bool use_cached_screen_coords )
cc1->GetCanvasPixPoint(r.x+hilitebox.x+hilitebox.width, r.y+hilitebox.y, lat2, lon2);

if(lon1 > lon2)
m_wpBBox.Set(lon1, lat1, lon2+360, lat2);
m_wpBBox.Set(lat1, lon1, lat2, lon2+360);
else
m_wpBBox.Set(lon1, lat1, lon2, lat2);
m_wpBBox.Set(lat1, lon1, lat2, lon2);

m_wpBBox_view_scale_ppm = vp.view_scale_ppm;
m_wpBBox_rotation = vp.rotation;
Expand Down
23 changes: 17 additions & 6 deletions src/Track.cpp
Expand Up @@ -467,11 +467,20 @@ void ActiveTrack::AddPointNow( bool do_add_point )
m_prev_time = now;
}

void Track::AddPointToList(std::list<wxPoint> &pointlist, int n)
void Track::AddPointToList(std::list< std::list<wxPoint> > &pointlists, int n)
{
wxPoint r;
cc1->GetCanvasPointPix( TrackPoints[n]->m_lat, TrackPoints[n]->m_lon, &r );


std::list<wxPoint> &pointlist = pointlists.back();
if(r.x == INVALID_COORD) {
if(pointlist.size()) {
std::list<wxPoint> new_list;
pointlists.push_back(new_list);
}
return;
}

if(pointlist.size() == 0)
pointlist.push_back(r);
else {
Expand Down Expand Up @@ -502,9 +511,9 @@ void Track::Assemble(std::list< std::list<wxPoint> > &pointlists, const LLBBox &
}

if(last < pos)
AddPointToList(pointlists.back(), pos);
AddPointToList(pointlists, pos);
last = wxMin(pos + (1<<level), TrackPoints.size() - 1);
AddPointToList(pointlists.back(), last);
AddPointToList(pointlists, last);
} else {
Assemble(pointlists, box, scale, last, level-1, pos<<1);
Assemble(pointlists, box, scale, last, level-1, (pos<<1)+1);
Expand Down Expand Up @@ -654,7 +663,9 @@ static double heading_diff(double x)
}

/* Computes the scale factor when these particular segments
essentially are smaller than 1 pixel */
essentially are smaller than 1 pixel, This is assuming
a simplistic flat projection, it might be useful to
add a mercator or other term, but this works in practice */
double Track::ComputeScale(int left, int right)
{
const double z = WGS84_semimajor_axis_meters * mercator_k0;
Expand Down Expand Up @@ -752,7 +763,7 @@ void Track::GetPointLists(std::list< std::list<wxPoint> > &pointlists,
if( IsRunning() ) {
std::list<wxPoint> new_list;
pointlists.push_back(new_list);
AddPointToList(pointlists.back(), TrackPoints.size()-1);
AddPointToList(pointlists, TrackPoints.size()-1);
wxPoint r;
cc1->GetCanvasPointPix( gLat, gLon, &r );
pointlists.back().push_back(r);
Expand Down
22 changes: 6 additions & 16 deletions src/bbox.cpp
Expand Up @@ -370,10 +370,7 @@ void wxBoundingBox::MapBbox( const wxTransformMatrix& matrix)

void LLBBox::Set(double minlat, double minlon, double maxlat, double maxlon)
{
assert (minlat <= maxlat );
assert (minlon <= maxlon );

#if 0
#if 0
// ensure average is from -180 to 180
if(minlon + maxlon >= 360)
minlon -= 360, maxlon -= 360;
Expand All @@ -386,17 +383,14 @@ void LLBBox::Set(double minlat, double minlon, double maxlat, double maxlon)
m_minlon = minlon;
m_maxlat = maxlat;
m_maxlon = maxlon;
m_valid = TRUE;
m_valid = minlat <= maxlat && minlon <= maxlon;
}

void LLBBox::SetFromSegment(double lat1, double lon1, double lat2, double lon2)
{
m_minlat = wxMin(lat1, lat2);
m_maxlat = wxMax(lat1, lat2);
#if 0
m_minlon = wxMin(lon1, lon2);
m_maxlon = wxMax(lon1, lon2);
#else

double minlon[3], maxlon[3];
double lon[2][3] = {{lon1}, {lon2}};
for(int i=0; i<2; i++) {
Expand Down Expand Up @@ -431,7 +425,7 @@ void LLBBox::SetFromSegment(double lat1, double lon1, double lat2, double lon2)

m_minlon = minlon[mink];
m_maxlon = maxlon[mink];
#endif

m_valid = TRUE;
}

Expand Down Expand Up @@ -569,17 +563,13 @@ bool LLBBox::IntersectOutGetBias( const LLBBox &other, double bias ) const
return (m_minlon + bias > other.m_maxlon) || (m_maxlon + bias < other.m_minlon);
}

#if 0 // use needed...
#if 0 // use if needed...
OVERLAP LLBox::Intersect( const LLBBox &other) const
{
if(IntersectOut(other))
return _OUT;

// Check if other.bbox is inside this bbox
if ((m_minx <= other.m_minx) &&
(m_maxx >= other.m_maxx) &&
(m_maxy >= other.m_maxy) &&
(m_miny <= other.m_miny))
if(IntersectIn(other))
return _IN;

// Boundingboxes intersect
Expand Down
4 changes: 2 additions & 2 deletions src/chcanv.cpp
Expand Up @@ -10108,8 +10108,8 @@ emboss_data *ChartCanvas::CreateEmbossMapData( wxFont &font, int width, int heig
void ChartCanvas::DrawAllTracksInBBox( ocpnDC& dc, LLBBox& BltBBox )
{
Track *active_track = NULL;
wxTrackListNode *node = pTrackList->GetFirst();
while( node ) {
for(wxTrackListNode *node = pTrackList->GetFirst();
node; node = node->GetNext()) {
Track *pTrackDraw = node->GetData();

if( g_pActiveTrack == pTrackDraw ) {
Expand Down
3 changes: 2 additions & 1 deletion src/glChartCanvas.cpp
Expand Up @@ -1679,7 +1679,8 @@ ViewPort glChartCanvas::ClippedViewport(const ViewPort &vp, const LLRegion &regi
bbox.Set(bbox.GetMinLat(), bbox.GetMinLon() - 360,
bbox.GetMaxLat(), bbox.GetMaxLon() - 360);
cvp.SetBBoxDirect(bbox);
}
} else
cvp.SetBBoxDirect(bbox);

return cvp;
}
Expand Down
24 changes: 12 additions & 12 deletions src/s57chart.cpp
Expand Up @@ -575,8 +575,8 @@ S57Obj::S57Obj( char *buf, int size, wxInputStream *pfpx, double dummy, double d
m_lon = xll;
m_lat = yll;

BBObj.Set( m_lon - .25, m_lat - .25,
m_lon + .25, m_lat + .25 );
BBObj.Set( m_lat - .25, m_lon - .25,
m_lat + .25, m_lon + .25 );
BBObj.Invalidate();
} else {
Primitive_type = GEO_POINT;
Expand Down Expand Up @@ -623,7 +623,7 @@ S57Obj::S57Obj( char *buf, int size, wxInputStream *pfpx, double dummy, double d
float ymax = *pfs++;
float ymin = *pfs;

BBObj.Set( xmin, ymin, xmax, ymax );
BBObj.Set( ymin, xmin, ymax, xmax );
}
break;
}
Expand Down Expand Up @@ -675,7 +675,7 @@ S57Obj::S57Obj( char *buf, int size, wxInputStream *pfpx, double dummy, double d
free( buft );

// set s57obj bbox as lat/lon
BBObj.Set( xmin, ymin, xmax, ymax );
BBObj.Set( ymin, xmin, ymax, xmax );

// and declare x/y of the object to be average east/north of all points
double e1, e2, n1, n2;
Expand Down Expand Up @@ -748,8 +748,8 @@ S57Obj::S57Obj( char *buf, int size, wxInputStream *pfpx, double dummy, double d
pPolyTessGeo = ppg;

// Set the s57obj bounding box as lat/lon
BBObj.Set( ppg->Get_xmin(), ppg->Get_ymin(),
ppg->Get_xmax(), ppg->Get_ymax() );
BBObj.Set( ppg->Get_ymin(), ppg->Get_xmin(),
ppg->Get_ymax(), ppg->Get_xmax() );

// and declare x/y of the object to be average east/north of all points
double e1, e2, n1, n2;
Expand Down Expand Up @@ -2567,8 +2567,8 @@ bool s57chart::DoRenderViewOnDC( wxMemoryDC& dc, const ViewPort& VPoint, RenderT
fromSM( temp_easting_lr, temp_northing_lr, ref_lat, ref_lon, &temp_lat_bot,
&temp_lon_right );

temp_vp.GetBBox().Set( temp_lon_left, temp_lat_bot,
temp_lon_right, temp_lat_top );
temp_vp.GetBBox().Set( temp_lat_bot, temp_lon_left,
temp_lat_top, temp_lon_right );

// Allow some slop in the viewport
// TODO Investigate why this fails if greater than 5 percent
Expand Down Expand Up @@ -3197,8 +3197,8 @@ bool s57chart::BuildThumbnail( const wxString &bmpname )

vp.m_projection_type = PROJECTION_MERCATOR;

vp.GetBBox().Set( m_FullExtent.WLON, m_FullExtent.SLAT,
m_FullExtent.ELON, m_FullExtent.NLAT );
vp.GetBBox().Set( m_FullExtent.SLAT, m_FullExtent.WLON,
m_FullExtent.NLAT, m_FullExtent.ELON );

vp.chart_scale = 10000000 - 1;
vp.Validate();
Expand Down Expand Up @@ -4620,8 +4620,8 @@ void s57chart::ResetPointBBoxes( const ViewPort &vp_last, const ViewPort &vp_thi
double lon1 = (lon - minlon) * d;
double lon2 = (lon - maxlon) * d;

top->obj->BBObj.Set( lon - lon1, lat - lat1,
lon - lon2, lat - lat2 );
top->obj->BBObj.Set( lat - lat1, lon - lon1,
lat - lat2, lon - lon2 );

// this method is very close, but errors accumulate
top->obj->BBObj.Invalidate();
Expand Down

0 comments on commit d8b8205

Please sign in to comment.