if geometries are polygons, default to 'largest_box' only

for label placement.
TODO: expose settings in XML
This commit is contained in:
Artem Pavlenko 2012-01-31 11:52:43 +00:00
parent b90de4874c
commit e00e8f98aa

View file

@ -81,10 +81,21 @@ text_placement_info_ptr text_symbolizer_helper<FaceManagerT, DetectorT>::get_poi
return text_placement_info_ptr(); return text_placement_info_ptr();
} }
struct largest_bbox_first
{
bool operator() (geometry_type const* g0, geometry_type const* g1) const
{
box2d<double> b0 = g0->envelope();
box2d<double> b1 = g1->envelope();
return b0.width()*b0.height() > b1.width()*b1.height();
}
};
template <typename FaceManagerT, typename DetectorT> template <typename FaceManagerT, typename DetectorT>
void text_symbolizer_helper<FaceManagerT, DetectorT>::initialize_geometries() void text_symbolizer_helper<FaceManagerT, DetectorT>::initialize_geometries()
{ {
bool largest_box_only = false;
unsigned num_geom = feature_.num_geometries(); unsigned num_geom = feature_.num_geometries();
for (unsigned i=0; i<num_geom; ++i) for (unsigned i=0; i<num_geom; ++i)
{ {
@ -92,19 +103,32 @@ void text_symbolizer_helper<FaceManagerT, DetectorT>::initialize_geometries()
// don't bother with empty geometries // don't bother with empty geometries
if (geom.num_points() == 0) continue; if (geom.num_points() == 0) continue;
eGeomType type = geom.type();
if ((geom.type() == Polygon) && sym_.get_minimum_path_length() > 0) if (type == Polygon)
{ {
// TODO - find less costly method than fetching full envelope largest_box_only = true;
box2d<double> gbox = t_.forward(geom.envelope(), prj_trans_); if (sym_.get_minimum_path_length() > 0)
if (gbox.width() < sym_.get_minimum_path_length())
{ {
continue; largest_box_only = true;
// TODO - find less costly method than fetching full envelope
box2d<double> gbox = t_.forward(geom.envelope(), prj_trans_);
if (gbox.width() < sym_.get_minimum_path_length())
{
continue;
}
} }
} }
// TODO - calculate length here as well // TODO - calculate length here as well
geometries_to_process_.push_back(const_cast<geometry_type*>(&geom)); geometries_to_process_.push_back(const_cast<geometry_type*>(&geom));
} }
if (largest_box_only)
{
geometries_to_process_.sort(largest_bbox_first());
geo_itr_ = geometries_to_process_.begin();
geometries_to_process_.erase(++geo_itr_,geometries_to_process_.end());
}
geo_itr_ = geometries_to_process_.begin(); geo_itr_ = geometries_to_process_.begin();
} }