Implement find_points_on_line().
This commit is contained in:
parent
0c90f0f22b
commit
b062af211a
3 changed files with 99 additions and 11 deletions
61
include/mapnik/path_processor.hpp
Normal file
61
include/mapnik/path_processor.hpp
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#ifndef MAPNIK_PATH_PROCESSOR_HPP
|
||||||
|
#define MAPNIK_PATH_PROCESSOR_HPP
|
||||||
|
|
||||||
|
//mapnik
|
||||||
|
#include "pixel_position.hpp"
|
||||||
|
|
||||||
|
// agg
|
||||||
|
#include "agg_path_length.h"
|
||||||
|
namespace mapnik
|
||||||
|
{
|
||||||
|
template <typename T>
|
||||||
|
class path_processor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
path_processor(T &path)
|
||||||
|
: path_(path), length_(agg::path_length(path_)), valid_(true)
|
||||||
|
{
|
||||||
|
rewind();
|
||||||
|
}
|
||||||
|
|
||||||
|
double length() const { return length_ ;}
|
||||||
|
|
||||||
|
bool next()
|
||||||
|
{
|
||||||
|
if (!valid_) return false;
|
||||||
|
valid_ = path_.vertex(¤t_point_.x, ¤t_point_.y);
|
||||||
|
return valid_;
|
||||||
|
}
|
||||||
|
|
||||||
|
pixel_position const& current_point() const
|
||||||
|
{
|
||||||
|
return current_point_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rewind()
|
||||||
|
{
|
||||||
|
path_.rewind(0);
|
||||||
|
valid_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool valid() const { return valid_; }
|
||||||
|
|
||||||
|
/** Skip a certain amount of space.
|
||||||
|
*
|
||||||
|
* This function automatically calculates new points if the position is not exactly
|
||||||
|
* on a point on the path.
|
||||||
|
*/
|
||||||
|
bool skip(double length)
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
return valid_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
T &path_;
|
||||||
|
double length_;
|
||||||
|
bool valid_;
|
||||||
|
pixel_position current_point_;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif // PATH_PROCESSOR_HPP
|
|
@ -32,6 +32,7 @@
|
||||||
|
|
||||||
//stl
|
//stl
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
//boost
|
//boost
|
||||||
#include <boost/utility.hpp>
|
#include <boost/utility.hpp>
|
||||||
|
@ -85,7 +86,8 @@ private:
|
||||||
};
|
};
|
||||||
typedef boost::shared_ptr<glyph_positions> glyph_positions_ptr;
|
typedef boost::shared_ptr<glyph_positions> glyph_positions_ptr;
|
||||||
|
|
||||||
struct text_symbolizer_properties;
|
typedef std::list<glyph_positions_ptr> placements_list;
|
||||||
|
typedef boost::shared_ptr<placements_list> placements_list_ptr;
|
||||||
|
|
||||||
class placement_finder_ng : boost::noncopyable
|
class placement_finder_ng : boost::noncopyable
|
||||||
{
|
{
|
||||||
|
@ -101,10 +103,10 @@ public:
|
||||||
glyph_positions_ptr find_point_placement(pixel_position pos);
|
glyph_positions_ptr find_point_placement(pixel_position pos);
|
||||||
/** Iterate over the given path, placing line-following labels with respect to label_spacing. */
|
/** Iterate over the given path, placing line-following labels with respect to label_spacing. */
|
||||||
template <typename T>
|
template <typename T>
|
||||||
glyph_positions_ptr find_line_placements(T & path);
|
placements_list_ptr find_line_placements(T & path);
|
||||||
/** Iterate over the given path, placing point labels with respect to label_spacing. */
|
/** Iterate over the given path, placing point labels with respect to label_spacing. */
|
||||||
template <typename T>
|
template <typename T>
|
||||||
glyph_positions_ptr find_point_on_line_placements(T & path);
|
placements_list_ptr find_point_on_line_placements(T & path);
|
||||||
/** Try next position alternative from placement_info. */
|
/** Try next position alternative from placement_info. */
|
||||||
bool next_position();
|
bool next_position();
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <mapnik/debug.hpp>
|
#include <mapnik/debug.hpp>
|
||||||
#include <mapnik/label_collision_detector.hpp>
|
#include <mapnik/label_collision_detector.hpp>
|
||||||
#include <mapnik/ctrans.hpp>
|
#include <mapnik/ctrans.hpp>
|
||||||
|
#include <mapnik/path_processor.hpp>
|
||||||
|
|
||||||
//boost
|
//boost
|
||||||
#include <boost/make_shared.hpp>
|
#include <boost/make_shared.hpp>
|
||||||
|
@ -222,15 +223,39 @@ glyph_positions_ptr placement_finder_ng::find_point_placement(pixel_position pos
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
glyph_positions_ptr placement_finder_ng::find_point_on_line_placements(T & path)
|
placements_list_ptr placement_finder_ng::find_point_on_line_placements(T & path)
|
||||||
{
|
{
|
||||||
return glyph_positions_ptr();
|
path_processor<T> pp(path);
|
||||||
|
placements_list_ptr list = boost::make_shared<placements_list>();
|
||||||
|
if (!pp.valid() || !layout_.size()) return list;
|
||||||
|
if (pp.length() == 0.0)
|
||||||
|
{
|
||||||
|
list->push_back(find_point_placement(pp.current_point()));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
int num_labels = 1;
|
||||||
|
if (info_->properties.label_spacing > 0)
|
||||||
|
num_labels = static_cast<int> (floor(pp.length() / info_->properties.label_spacing * scale_factor_));
|
||||||
|
|
||||||
|
if (info_->properties.force_odd_labels && num_labels % 2 == 0)
|
||||||
|
num_labels--;
|
||||||
|
if (num_labels <= 0)
|
||||||
|
num_labels = 1;
|
||||||
|
|
||||||
|
double spacing = pp.length() / num_labels;
|
||||||
|
pp.skip(spacing/2.); // first label should be placed at half the spacing
|
||||||
|
do
|
||||||
|
{
|
||||||
|
list->push_back(find_point_placement(pp.current_point()));
|
||||||
|
} while (pp.skip(spacing));
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
glyph_positions_ptr placement_finder_ng::find_line_placements(T & path)
|
placements_list_ptr placement_finder_ng::find_line_placements(T & path)
|
||||||
{
|
{
|
||||||
return glyph_positions_ptr();
|
return placements_list_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -291,10 +316,10 @@ void glyph_positions::set_base_point(pixel_position base_point)
|
||||||
typedef agg::conv_clip_polyline<geometry_type> clipped_geometry_type;
|
typedef agg::conv_clip_polyline<geometry_type> clipped_geometry_type;
|
||||||
typedef coord_transform<CoordTransform,clipped_geometry_type> ClippedPathType;
|
typedef coord_transform<CoordTransform,clipped_geometry_type> ClippedPathType;
|
||||||
typedef coord_transform<CoordTransform,geometry_type> PathType;
|
typedef coord_transform<CoordTransform,geometry_type> PathType;
|
||||||
template glyph_positions_ptr placement_finder_ng::find_point_on_line_placements<ClippedPathType>(ClippedPathType &);
|
template placements_list_ptr placement_finder_ng::find_point_on_line_placements<ClippedPathType>(ClippedPathType &);
|
||||||
template glyph_positions_ptr placement_finder_ng::find_line_placements<ClippedPathType>(ClippedPathType &);
|
template placements_list_ptr placement_finder_ng::find_line_placements<ClippedPathType>(ClippedPathType &);
|
||||||
template glyph_positions_ptr placement_finder_ng::find_point_on_line_placements<PathType>(PathType &);
|
template placements_list_ptr placement_finder_ng::find_point_on_line_placements<PathType>(PathType &);
|
||||||
template glyph_positions_ptr placement_finder_ng::find_line_placements<PathType>(PathType &);
|
template placements_list_ptr placement_finder_ng::find_line_placements<PathType>(PathType &);
|
||||||
|
|
||||||
|
|
||||||
}// ns mapnik
|
}// ns mapnik
|
||||||
|
|
Loading…
Add table
Reference in a new issue