Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add protobuf descriptor #1161

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8f8cb6a
keep server instance in a unique_ptr
DennisOSRM Aug 20, 2014
96318bb
switch from unique to shared ptr
DennisOSRM Aug 20, 2014
6a8c5c8
fix typo
DennisOSRM Aug 20, 2014
d6c6fbf
use more osrm::irange
DennisOSRM Aug 20, 2014
05b9397
Revert "use more osrm::irange"
DennisOSRM Aug 20, 2014
2727091
Merge pull request #1154 from Project-OSRM/feature/travel_mode
DennisOSRM Aug 21, 2014
85c244e
Merge pull request #1166 from Project-OSRM/server_instance_unique_ptr
DennisOSRM Aug 21, 2014
6aac8ed
Initial commit for protobuf descriptor.
Zhdanovich Aug 12, 2014
4afa244
Update cmake file to generate protobuf files and create a dependancy
Zhdanovich Aug 15, 2014
722f189
Add protobuf file.
Zhdanovich Aug 15, 2014
03ecfae
Update ViaRoutePlugin to use protobuf descriptor.
Zhdanovich Aug 15, 2014
5acc5e0
Add protobuf to description table.
Zhdanovich Aug 15, 2014
848712e
Create functions for Polyline Compressor and Description Factory to r…
Zhdanovich Aug 16, 2014
cd14ab4
Intermediate result for adding data to protobuf response.
Zhdanovich Aug 16, 2014
9d4541e
Add protobuf message Route. In response message create main and addit…
Zhdanovich Aug 16, 2014
8f725e1
Add alternative way description
Zhdanovich Aug 16, 2014
c49ec5e
Add route names.
Zhdanovich Aug 16, 2014
04135c7
add Hint.
Zhdanovich Aug 16, 2014
b80cea3
Add RouteInstructions
Zhdanovich Aug 16, 2014
ead04c4
Pass vector as reference.
Zhdanovich Aug 16, 2014
320945d
Refactoring. Move common parts to Descriptor.h
Zhdanovich Aug 17, 2014
afae7eb
Code review fixes
Zhdanovich Aug 18, 2014
4354b8c
Add route instructions travel mode
Zhdanovich Aug 21, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions Algorithms/PolylineCompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ void PolylineCompressor::encodeNumber(int number_to_encode, std::string &output)
}
}

JSON::String PolylineCompressor::printEncodedString(const std::vector<SegmentInformation> &polyline)
const
std::string PolylineCompressor::printEncodedStr(const std::vector<SegmentInformation> &polyline) const
{
std::string output;
std::vector<int> delta_numbers;
std::string output;
if (!polyline.empty())
{
FixedPointCoordinate last_coordinate = {0, 0};
Expand All @@ -90,25 +89,40 @@ JSON::String PolylineCompressor::printEncodedString(const std::vector<SegmentInf
}
encodeVectorSignedNumber(delta_numbers, output);
}
return output;
}

JSON::String PolylineCompressor::printEncodedString(const std::vector<SegmentInformation> &polyline) const
{
std::string output = printEncodedStr(polyline);
JSON::String return_value(output);
return return_value;
}

JSON::Array
PolylineCompressor::printUnencodedString(const std::vector<SegmentInformation> &polyline) const
std::vector<std::string> PolylineCompressor::printUnencodedStr(const std::vector<SegmentInformation> &polyline) const
{
JSON::Array json_geometry_array;
std::vector<std::string> output;
for (const auto &segment : polyline)
{
if (segment.necessary)
{
std::string tmp, output;
std::string tmp, res;
FixedPointCoordinate::convertInternalLatLonToString(segment.location.lat, tmp);
output += (tmp + ",");
res += (tmp + ",");
FixedPointCoordinate::convertInternalLatLonToString(segment.location.lon, tmp);
output += tmp;
json_geometry_array.values.push_back(output);
res += tmp;
output.push_back(res);
}
}
return output;
}

JSON::Array
PolylineCompressor::printUnencodedString(const std::vector<SegmentInformation> &polyline) const
{
JSON::Array json_geometry_array;
std::vector<std::string> output = printUnencodedStr(polyline);
for (std::string str : output)
json_geometry_array.values.push_back(str);
return json_geometry_array;
}
4 changes: 4 additions & 0 deletions Algorithms/PolylineCompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class PolylineCompressor
void encodeNumber(int number_to_encode, std::string &output) const;

public:
std::string printEncodedStr(const std::vector<SegmentInformation> &polyline) const;

std::vector<std::string> printUnencodedStr(const std::vector<SegmentInformation> &polyline) const;

JSON::String printEncodedString(const std::vector<SegmentInformation> &polyline) const;

JSON::Array printUnencodedString(const std::vector<SegmentInformation> &polyline) const;
Expand Down
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include(CheckCXXCompilerFlag)
include(FindPackageHandleStandardArgs)


find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})
file(GLOB ProtoFiles "${CMAKE_CURRENT_SOURCE_DIR}/Descriptors/*.proto")
PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders ${ProtoFiles})
add_library(messages STATIC ${ProtoSources} ${ProtoHeaders})

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(GetGitRevisionDescription)
git_describe(GIT_DESCRIPTION)
Expand Down Expand Up @@ -52,7 +59,9 @@ configure_file(
)
file(GLOB ExtractorGlob Extractor/*.cpp)
file(GLOB ImporterGlob DataStructures/Import*.cpp)
add_library(IMPORT STATIC ${ImporterGlob})

include_directories(${CMAKE_BINARY_DIR})
add_library(IMPORT STATIC ${ImporterGlob} ${ProtoHeaders})
set(ExtractorSources extractor.cpp ${ExtractorGlob})
add_executable(osrm-extract ${ExtractorSources})

Expand Down Expand Up @@ -200,7 +209,7 @@ include_directories(${Boost_INCLUDE_DIRS})
target_link_libraries(OSRM ${Boost_LIBRARIES} COORDLIB)
target_link_libraries(osrm-extract ${Boost_LIBRARIES} FINGERPRINT GITDESCRIPTION COORDLIB IMPORT)
target_link_libraries(osrm-prepare ${Boost_LIBRARIES} FINGERPRINT GITDESCRIPTION COORDLIB IMPORT)
target_link_libraries(osrm-routed ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM FINGERPRINT GITDESCRIPTION)
target_link_libraries(osrm-routed ${Boost_LIBRARIES} ${OPTIONAL_SOCKET_LIBS} OSRM FINGERPRINT GITDESCRIPTION messages)
target_link_libraries(osrm-datastore ${Boost_LIBRARIES} FINGERPRINT GITDESCRIPTION COORDLIB)
target_link_libraries(datastructure-tests ${Boost_LIBRARIES} COORDLIB)
target_link_libraries(rtree-bench ${Boost_LIBRARIES} COORDLIB)
Expand Down Expand Up @@ -270,6 +279,9 @@ find_package(Protobuf REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})
target_link_libraries(osrm-extract ${PROTOBUF_LIBRARY})
target_link_libraries(osrm-prepare ${PROTOBUF_LIBRARY})
target_link_libraries(osrm-routed ${PROTOBUF_LIBRARY})



find_package(BZip2 REQUIRED)
include_directories(${BZIP_INCLUDE_DIRS})
Expand Down
173 changes: 168 additions & 5 deletions Descriptors/BaseDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef BASE_DESCRIPTOR_H
#define BASE_DESCRIPTOR_H

#include "../typedefs.h"

#include "DescriptionFactory.h"
#include "../Algorithms/ObjectToBase64.h"
#include "../Algorithms/ExtractRouteNames.h"
#include "../DataStructures/Range.h"
#include "../DataStructures/SegmentInformation.h"
#include "../DataStructures/TurnInstructions.h"
#include "../DataStructures/PhantomNodes.h"
#include "../DataStructures/RawRouteData.h"
#include "../typedefs.h"
#include "../Util/Azimuth.h"
#include "../Util/StringUtil.h"
#include "../Util/TimingUtil.h"

#include <osrm/Reply.h>

#include <algorithm>
#include <string>
#include <vector>

Expand All @@ -50,12 +61,164 @@ struct DescriptorConfig

template <class DataFacadeT> class BaseDescriptor
{
public:
BaseDescriptor() {}
// Maybe someone can explain the pure virtual destructor thing to me (dennis)
public:
DataFacadeT *facade;
DescriptorConfig config;
DescriptionFactory description_factory, alternate_description_factory;
FixedPointCoordinate current;
unsigned entered_restricted_area_count;
struct RoundAbout
{
RoundAbout() : start_index(INT_MAX), name_id(INVALID_NAMEID), leave_at_exit(INT_MAX) {}
int start_index;
unsigned name_id;
int leave_at_exit;
} round_about;

struct Segment
{
Segment() : name_id(INVALID_NAMEID), length(-1), position(0) {}
Segment(unsigned n, int l, unsigned p) : name_id(n), length(l), position(p) {}
unsigned name_id;
int length;
unsigned position;
};
std::vector<Segment> shortest_path_segments, alternative_path_segments;
ExtractRouteNames<DataFacadeT, Segment> GenerateRouteNames;

BaseDescriptor(DataFacadeT *facade) : facade(facade), entered_restricted_area_count(0) {}

void SetConfig(const DescriptorConfig &c) { config = c; }

unsigned DescribeLeg(const std::vector<PathData> &route_leg,
const PhantomNodes &leg_phantoms,
const bool target_traversed_in_reverse,
const bool is_via_leg)
{
unsigned added_element_count = 0;
// Get all the coordinates for the computed route
FixedPointCoordinate current_coordinate;
for (const PathData &path_data : route_leg)
{
current_coordinate = facade->GetCoordinateOfNode(path_data.node);
description_factory.AppendSegment(current_coordinate, path_data);
++added_element_count;
}
description_factory.SetEndSegment(leg_phantoms.target_phantom, target_traversed_in_reverse, is_via_leg);
++added_element_count;
BOOST_ASSERT((route_leg.size() + 1) == added_element_count);
return added_element_count;
}

struct Instruction
{
Instruction() : instructionId(""), streetName(""), length(0),
position(0), time(0), lengthStr(""), earthDirection(""), azimuth(0),
travelMode(0)
{}
Instruction(const std::string &i, const std::string &s, const int l,
const int p, const int t, const std::string &ls, const std::string &e,
const int a, TravelMode const tm) : instructionId(i), streetName(s), length(l),
position(p), time(t), lengthStr(ls), earthDirection(e), azimuth(a), travelMode(tm)
{}
std::string instructionId;
std::string streetName;
int length;
int position;
int time;
std::string lengthStr;
std::string earthDirection;
int azimuth;
TravelMode travelMode;
};



inline void BuildTextualDescription(DescriptionFactory &description_factory,
std::vector<Instruction> &instructions,
const int route_length,
std::vector<Segment> &route_segments_list)
{
// Segment information has following format:
//["instruction id","streetname",length,position,time,"length","earth_direction",azimuth]
unsigned necessary_segments_running_index = 0;
round_about.leave_at_exit = 0;
round_about.name_id = 0;
std::string temp_dist, temp_length, temp_duration, temp_bearing, temp_instruction;

// Fetch data from Factory and generate a string from it.
Instruction instruction;

for (const SegmentInformation &segment : description_factory.path_description)
{
TurnInstruction current_instruction = segment.turn_instruction;
entered_restricted_area_count += (current_instruction != segment.turn_instruction);
if (TurnInstructionsClass::TurnIsNecessary(current_instruction))
{
if (TurnInstruction::EnterRoundAbout == current_instruction)
{
round_about.name_id = segment.name_id;
round_about.start_index = necessary_segments_running_index;
}
else
{
std::string current_turn_instruction;
if (TurnInstruction::LeaveRoundAbout == current_instruction)
{
temp_instruction =
IntToString(as_integer(TurnInstruction::EnterRoundAbout));
current_turn_instruction += temp_instruction;
current_turn_instruction += "-";
temp_instruction = IntToString(round_about.leave_at_exit + 1);
current_turn_instruction += temp_instruction;
round_about.leave_at_exit = 0;
}
else
{
temp_instruction = IntToString(as_integer(current_instruction));
current_turn_instruction += temp_instruction;
}

instruction.instructionId = current_turn_instruction;
instruction.streetName = facade->GetEscapedNameForNameID(segment.name_id);
instruction.length = std::round(segment.length);
instruction.position = necessary_segments_running_index;
instruction.time = round(segment.duration / 10);
instruction.lengthStr = UintToString(static_cast<int>(segment.length)) + "m";
const double bearing_value = (segment.bearing / 10.);
instruction.earthDirection = Azimuth::Get(bearing_value);
instruction.azimuth = static_cast<unsigned>(round(bearing_value));
instruction.travelMode = segment.travel_mode;

route_segments_list.emplace_back(
segment.name_id, static_cast<int>(segment.length), static_cast<unsigned>(route_segments_list.size()));
instructions.push_back(instruction);
}
}
else if (TurnInstruction::StayOnRoundAbout == current_instruction)
{
++round_about.leave_at_exit;
}
if (segment.necessary)
{
++necessary_segments_running_index;
}
}

temp_instruction = IntToString(as_integer(TurnInstruction::ReachedYourDestination));
instruction.instructionId = temp_instruction;
instruction.streetName = "";
instruction.length = 0;
instruction.position = necessary_segments_running_index - 1;
instruction.time = 0;
instruction.lengthStr = "0m";
instruction.earthDirection = Azimuth::Get(0.0);
instruction.azimuth = 0.;
instructions.push_back(instruction);
}

virtual ~BaseDescriptor() {}
virtual void Run(const RawRouteData &raw_route, http::Reply &reply) = 0;
virtual void SetConfig(const DescriptorConfig &config) = 0;
};

#endif // BASE_DESCRIPTOR_H
11 changes: 11 additions & 0 deletions Descriptors/DescriptionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@ void DescriptionFactory::AppendSegment(const FixedPointCoordinate &coordinate,
path_point.travel_mode);
}

std::string DescriptionFactory::AppendEncodedPolylineStringEncoded()
{
return polyline_compressor.printEncodedStr(path_description);
}

std::vector<std::string> DescriptionFactory::AppendEncodedPolylineStringUnencoded()
{
return polyline_compressor.printUnencodedStr(path_description);
}


JSON::Value DescriptionFactory::AppendEncodedPolylineString(const bool return_encoded)
{
if (return_encoded)
Expand Down
2 changes: 2 additions & 0 deletions Descriptors/DescriptionFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class DescriptionFactory
void BuildRouteSummary(const double distance, const unsigned time);
void SetStartSegment(const PhantomNode &start_phantom, const bool traversed_in_reverse);
void SetEndSegment(const PhantomNode &start_phantom, const bool traversed_in_reverse, const bool is_via_location = false);
std::string AppendEncodedPolylineStringEncoded();
std::vector<std::string> AppendEncodedPolylineStringUnencoded();
JSON::Value AppendEncodedPolylineString(const bool return_encoded);
std::vector<unsigned> const & GetViaIndices() const;

Expand Down
4 changes: 2 additions & 2 deletions Descriptors/GPXDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ template <class DataFacadeT> class GPXDescriptor : public BaseDescriptor<DataFac
}

public:
GPXDescriptor(DataFacadeT *facade) : facade(facade) {}
GPXDescriptor(DataFacadeT *facade) : BaseDescriptor<DataFacadeT>(facade) {}

void SetConfig(const DescriptorConfig &c) final { config = c; }
void SetConfig(const DescriptorConfig &c) { config = c; }

// TODO: reorder parameters
void Run(const RawRouteData &raw_route, http::Reply &reply) final
Expand Down
Loading