share collision detector between labels and text.

This commit is contained in:
Artem Pavlenko 2007-05-12 11:34:55 +00:00
parent a6a31f42f6
commit d3d40234c9
4 changed files with 40 additions and 27 deletions

View file

@ -75,8 +75,9 @@ namespace mapnik {
T & pixmap_;
CoordTransform t_;
face_manager<freetype_engine> font_manager_;
placement_finder finder_;
label_collision_detector2 point_detector_; //Note: May want to merge this with placement_finder
label_collision_detector3 detector_;
placement_finder<label_collision_detector3> finder_;
//label_collision_detector2 point_detector_; //Note: May want to merge this with placement_finder
};
}

View file

@ -109,11 +109,12 @@ namespace mapnik
template <typename DetectorT>
class placement_finder : boost::noncopyable
{
public:
//e is the dimensions of the map, buffer is the buffer used for collission detection.
placement_finder(Envelope<double> e, unsigned buffer);
placement_finder(DetectorT & detector,Envelope<double> const& e);
bool find_placements(placement *p);
void clear();
@ -124,7 +125,7 @@ namespace mapnik
bool build_path_horizontal(placement *p, double target_distance);
void update_detector(placement *p);
Envelope<double> dimensions_;
label_collision_detector3 detector_;
DetectorT & detector_;
};
}

View file

@ -94,8 +94,9 @@ namespace mapnik
: feature_style_processor<agg_renderer>(m),
pixmap_(pixmap),
t_(m.getWidth(),m.getHeight(),m.getCurrentExtent(),offset_x,offset_y),
finder_(Envelope<double>(0 ,0, m.getWidth(), m.getHeight()), 64),
point_detector_(Envelope<double>(-64 ,-64, m.getWidth() + 64 ,m.getHeight() + 64))
detector_(Envelope<double>(-64 ,-64, m.getWidth() + 64 ,m.getHeight() + 64)),
finder_(detector_,Envelope<double>(0 ,0, m.getWidth(), m.getHeight()))
//point_detector_(Envelope<double>(-64 ,-64, m.getWidth() + 64 ,m.getHeight() + 64))
{
Color const& bg = m.getBackground();
pixmap_.setBackground(bg);
@ -317,14 +318,15 @@ namespace mapnik
int h = data->height();
int px=int(floor(x - 0.5 * w));
int py=int(floor(y - 0.5 * h));
Envelope<double> label_ext (floor(x - 0.5 * w),
floor(y - 0.5 * h),
ceil (x + 0.5 * w),
ceil (y + 0.5 * h));
if (sym.get_allow_overlap() ||
point_detector_.has_placement(Envelope<double>(floor(x - 0.5 * w),
floor(y - 0.5 * h),
ceil (x + 0.5 * w),
ceil (y + 0.5 * h))))
detector_.has_placement(label_ext))
{
pixmap_.set_rectangle_alpha(px,py,*data);
detector_.insert(label_ext);
}
}
}

View file

@ -181,15 +181,16 @@ namespace mapnik
}
placement_finder::placement_finder(Envelope<double> e, unsigned buffer)
: dimensions_(e),
detector_(Envelope<double>(e.minx() - buffer, e.miny() - buffer, e.maxx() + buffer, e.maxy() + buffer))
template <typename DetectorT>
placement_finder<DetectorT>::placement_finder(DetectorT & detector,Envelope<double> const& e)
: detector_(detector),
dimensions_(e)
//detector_(Envelope<double>(e.minx() - buffer, e.miny() - buffer, e.maxx() + buffer, e.maxy() + buffer))
{
}
bool placement_finder::find_placements(placement *p)
template <typename DetectorT>
bool placement_finder<DetectorT>::find_placements(placement *p)
{
if (p->label_placement == point_placement)
{
@ -203,7 +204,8 @@ namespace mapnik
return false;
}
bool placement_finder::find_placement_follow(placement *p)
template <typename DetectorT>
bool placement_finder<DetectorT>::find_placement_follow(placement *p)
{
std::pair<double, double> string_dimensions = p->info->get_dimensions();
double string_width = string_dimensions.first;
@ -293,8 +295,9 @@ namespace mapnik
return FoundPlacement;
}
bool placement_finder::find_placement_horizontal(placement *p)
template <typename DetectorT>
bool placement_finder<DetectorT>::find_placement_horizontal(placement *p)
{
if (p->path_size() == 1) // point geometry
{
@ -328,8 +331,9 @@ namespace mapnik
}
return false;
}
void placement_finder::update_detector(placement *p)
template <typename DetectorT>
void placement_finder<DetectorT>::update_detector(placement *p)
{
while (!p->envelopes.empty())
{
@ -341,7 +345,8 @@ namespace mapnik
}
}
bool placement_finder::build_path_follow(placement *p, double target_distance)
template <typename DetectorT>
bool placement_finder<DetectorT>::build_path_follow(placement *p, double target_distance)
{
double new_x, new_y, old_x, old_y;
unsigned cur_node = 0;
@ -517,8 +522,8 @@ namespace mapnik
return true;
}
bool placement_finder::build_path_horizontal(placement *p, double target_distance)
template <typename DetectorT>
bool placement_finder<DetectorT>::build_path_horizontal(placement *p, double target_distance)
{
double x, y;
@ -679,9 +684,13 @@ namespace mapnik
return true;
}
void placement_finder::clear()
template <typename DetectorT>
void placement_finder<DetectorT>::clear()
{
detector_.clear();
}
template class placement_finder<label_collision_detector3>;
} // namespace