de-templetize polyline generalizer
This commit is contained in:
parent
1863e85bf5
commit
8f4b0c8078
@ -29,6 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#define DOUGLASPEUCKER_H_
|
#define DOUGLASPEUCKER_H_
|
||||||
|
|
||||||
#include "../DataStructures/Coordinate.h"
|
#include "../DataStructures/Coordinate.h"
|
||||||
|
#include "../DataStructures/SegmentInformation.h"
|
||||||
|
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
@ -49,7 +50,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
||||||
static double DouglasPeuckerThresholds[19] = { 32000000., 16240000., 80240000., 40240000., 20000000., 10000000., 500000., 240000., 120000., 60000., 30000., 19000., 5000., 2000., 200, 16, 6, 3. , 3. };
|
static double DouglasPeuckerThresholds[19] = { 32000000., 16240000., 80240000., 40240000., 20000000., 10000000., 500000., 240000., 120000., 60000., 30000., 19000., 5000., 2000., 200, 16, 6, 3. , 3. };
|
||||||
|
|
||||||
template<class PointT>
|
|
||||||
class DouglasPeucker {
|
class DouglasPeucker {
|
||||||
private:
|
private:
|
||||||
typedef std::pair<std::size_t, std::size_t> PairOfPoints;
|
typedef std::pair<std::size_t, std::size_t> PairOfPoints;
|
||||||
@ -60,8 +60,7 @@ private:
|
|||||||
* This distance computation does integer arithmetic only and is about twice as fast as
|
* This distance computation does integer arithmetic only and is about twice as fast as
|
||||||
* the other distance function. It is an approximation only, but works more or less ok.
|
* the other distance function. It is an approximation only, but works more or less ok.
|
||||||
*/
|
*/
|
||||||
template<class CoordT>
|
inline int fastDistance(const FixedPointCoordinate& point, const FixedPointCoordinate& segA, const FixedPointCoordinate& segB) const {
|
||||||
inline int fastDistance(const CoordT& point, const CoordT& segA, const CoordT& segB) const {
|
|
||||||
const int p2x = (segB.lon - segA.lat);
|
const int p2x = (segB.lon - segA.lat);
|
||||||
const int p2y = (segB.lon - segA.lat);
|
const int p2y = (segB.lon - segA.lat);
|
||||||
const int something = p2x*p2x + p2y*p2y;
|
const int something = p2x*p2x + p2y*p2y;
|
||||||
@ -86,7 +85,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void Run(std::vector<PointT> & input_geometry, const unsigned zoom_level) {
|
void Run(std::vector<SegmentInformation> & input_geometry, const unsigned zoom_level) {
|
||||||
{
|
{
|
||||||
BOOST_ASSERT_MSG(zoom_level < 19, "unsupported zoom level");
|
BOOST_ASSERT_MSG(zoom_level < 19, "unsupported zoom level");
|
||||||
BOOST_ASSERT_MSG(1 < input_geometry.size(), "geometry invalid");
|
BOOST_ASSERT_MSG(1 < input_geometry.size(), "geometry invalid");
|
||||||
|
@ -98,18 +98,18 @@ void DescriptionFactory::AppendEncodedPolylineString(
|
|||||||
std::string & output
|
std::string & output
|
||||||
) {
|
) {
|
||||||
if(return_encoded) {
|
if(return_encoded) {
|
||||||
pc.printEncodedString(pathDescription, output);
|
polyline_compressor.printEncodedString(pathDescription, output);
|
||||||
} else {
|
} else {
|
||||||
pc.printUnencodedString(pathDescription, output);
|
polyline_compressor.printUnencodedString(pathDescription, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptionFactory::AppendEncodedPolylineString(std::string &output) const {
|
void DescriptionFactory::AppendEncodedPolylineString(std::string &output) const {
|
||||||
pc.printEncodedString(pathDescription, output);
|
polyline_compressor.printEncodedString(pathDescription, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptionFactory::AppendUnencodedPolylineString(std::string &output) const {
|
void DescriptionFactory::AppendUnencodedPolylineString(std::string &output) const {
|
||||||
pc.printUnencodedString(pathDescription, output);
|
polyline_compressor.printUnencodedString(pathDescription, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
// void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLevel) {
|
// void DescriptionFactory::Run(const SearchEngine &sEngine, const unsigned zoomLevel) {
|
||||||
|
@ -45,8 +45,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
* and produces the description plus the encoded polyline */
|
* and produces the description plus the encoded polyline */
|
||||||
|
|
||||||
class DescriptionFactory {
|
class DescriptionFactory {
|
||||||
DouglasPeucker<SegmentInformation> dp;
|
DouglasPeucker polyline_generalizer;
|
||||||
PolylineCompressor pc;
|
PolylineCompressor polyline_compressor;
|
||||||
PhantomNode start_phantom, target_phantom;
|
PhantomNode start_phantom, target_phantom;
|
||||||
|
|
||||||
double DegreeToRadian(const double degree) const;
|
double DegreeToRadian(const double degree) const;
|
||||||
@ -202,7 +202,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Generalize poly line
|
//Generalize poly line
|
||||||
dp.Run(pathDescription, zoomLevel);
|
polyline_generalizer.Run(pathDescription, zoomLevel);
|
||||||
|
|
||||||
//fix what needs to be fixed else
|
//fix what needs to be fixed else
|
||||||
for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){
|
for(unsigned i = 0; i < pathDescription.size()-1 && pathDescription.size() >= 2; ++i){
|
||||||
|
Loading…
Reference in New Issue
Block a user