2011-11-17 12:56:45 -05:00
|
|
|
/*
|
|
|
|
|
2014-11-27 12:54:20 -05:00
|
|
|
Copyright (c) 2014, Project OSRM, Dennis Luxen, others
|
2013-10-14 07:42:28 -04:00
|
|
|
All rights reserved.
|
2011-11-17 12:56:45 -05:00
|
|
|
|
2013-10-14 07:42:28 -04:00
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
2011-11-17 12:56:45 -05:00
|
|
|
|
2013-10-14 07:42:28 -04:00
|
|
|
Redistributions of source code must retain the above copyright notice, this list
|
|
|
|
of conditions and the following disclaimer.
|
|
|
|
Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
other materials provided with the distribution.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
*/
|
2011-11-17 12:56:45 -05:00
|
|
|
|
2014-11-28 08:36:38 -05:00
|
|
|
#ifndef DESCRIPTION_FACTORY_HPP
|
|
|
|
#define DESCRIPTION_FACTORY_HPP
|
2011-11-17 12:56:45 -05:00
|
|
|
|
2014-11-28 04:12:08 -05:00
|
|
|
#include "../algorithms/douglas_peucker.hpp"
|
2014-11-28 06:13:18 -05:00
|
|
|
#include "../data_structures/phantom_node.hpp"
|
|
|
|
#include "../data_structures/segment_information.hpp"
|
|
|
|
#include "../data_structures/turn_instructions.hpp"
|
2013-06-26 19:48:22 -04:00
|
|
|
|
2014-11-24 09:51:52 -05:00
|
|
|
#include <boost/assert.hpp>
|
|
|
|
|
2014-11-24 11:57:01 -05:00
|
|
|
#include <osrm/coordinate.hpp>
|
|
|
|
#include <osrm/json_container.hpp>
|
2013-12-17 11:59:44 -05:00
|
|
|
|
2014-11-25 08:52:21 -05:00
|
|
|
#include <cmath>
|
|
|
|
|
2013-10-02 07:05:54 -04:00
|
|
|
#include <limits>
|
2013-06-26 19:48:22 -04:00
|
|
|
#include <vector>
|
2011-11-17 12:56:45 -05:00
|
|
|
|
2014-06-11 06:25:57 -04:00
|
|
|
struct PathData;
|
2011-11-17 12:56:45 -05:00
|
|
|
/* This class is fed with all way segments in consecutive order
|
|
|
|
* and produces the description plus the encoded polyline */
|
|
|
|
|
2014-05-02 13:07:55 -04:00
|
|
|
class DescriptionFactory
|
|
|
|
{
|
2013-11-13 17:33:19 -05:00
|
|
|
DouglasPeucker polyline_generalizer;
|
2013-11-13 15:52:01 -05:00
|
|
|
PhantomNode start_phantom, target_phantom;
|
2012-02-10 11:14:30 -05:00
|
|
|
|
2012-06-11 10:36:33 -04:00
|
|
|
double DegreeToRadian(const double degree) const;
|
|
|
|
double RadianToDegree(const double degree) const;
|
2014-05-02 13:07:55 -04:00
|
|
|
|
2014-05-26 09:31:30 -04:00
|
|
|
std::vector<unsigned> via_indices;
|
|
|
|
|
2014-10-27 12:21:29 -04:00
|
|
|
double entire_length;
|
|
|
|
|
2014-05-02 13:07:55 -04:00
|
|
|
public:
|
|
|
|
struct RouteSummary
|
|
|
|
{
|
2014-05-16 10:09:40 -04:00
|
|
|
unsigned distance;
|
|
|
|
EdgeWeight duration;
|
|
|
|
unsigned source_name_id;
|
|
|
|
unsigned target_name_id;
|
|
|
|
RouteSummary() : distance(0), duration(0), source_name_id(0), target_name_id(0) {}
|
2014-05-02 13:07:55 -04:00
|
|
|
|
2014-05-16 10:09:40 -04:00
|
|
|
void BuildDurationAndLengthStrings(const double raw_distance, const unsigned raw_duration)
|
2014-05-02 13:07:55 -04:00
|
|
|
{
|
|
|
|
// compute distance/duration for route summary
|
2014-11-25 08:49:33 -05:00
|
|
|
distance = static_cast<unsigned>(std::round(raw_distance));
|
|
|
|
duration = static_cast<unsigned>(std::round(raw_duration / 10.));
|
2012-02-10 11:14:30 -05:00
|
|
|
}
|
|
|
|
} summary;
|
|
|
|
|
2014-05-02 13:07:55 -04:00
|
|
|
// I know, declaring this public is considered bad. I'm lazy
|
|
|
|
std::vector<SegmentInformation> path_description;
|
2011-11-17 12:56:45 -05:00
|
|
|
DescriptionFactory();
|
2014-05-02 13:07:55 -04:00
|
|
|
void AppendSegment(const FixedPointCoordinate &coordinate, const PathData &data);
|
2012-09-21 16:40:38 -04:00
|
|
|
void BuildRouteSummary(const double distance, const unsigned time);
|
2014-05-27 10:54:10 -04:00
|
|
|
void SetStartSegment(const PhantomNode &start_phantom, const bool traversed_in_reverse);
|
2014-09-15 08:23:43 -04:00
|
|
|
void SetEndSegment(const PhantomNode &start_phantom,
|
|
|
|
const bool traversed_in_reverse,
|
|
|
|
const bool is_via_location = false);
|
|
|
|
JSON::Value AppendGeometryString(const bool return_encoded);
|
|
|
|
std::vector<unsigned> const &GetViaIndices() const;
|
2014-05-02 13:07:55 -04:00
|
|
|
|
2014-10-27 12:21:29 -04:00
|
|
|
double get_entire_length() const
|
|
|
|
{
|
|
|
|
return entire_length;
|
|
|
|
}
|
|
|
|
|
2015-01-06 14:05:33 -05:00
|
|
|
void Run(const unsigned zoom_level);
|
2011-11-22 10:47:15 -05:00
|
|
|
};
|
|
|
|
|
2014-11-28 08:36:38 -05:00
|
|
|
#endif /* DESCRIPTION_FACTORY_HPP */
|