refactor and streamline use of TurnInstructionsClass members

This commit is contained in:
Dennis Luxen 2014-03-26 15:14:39 +01:00
parent 7b5902a580
commit 44077cb007
5 changed files with 87 additions and 83 deletions

View File

@ -826,7 +826,7 @@ void EdgeBasedGraphFactory::Run(
} }
const int turn_penalty = GetTurnPenalty(u, v, w, lua_state); const int turn_penalty = GetTurnPenalty(u, v, w, lua_state);
TurnInstruction turn_instruction = AnalyzeTurn(u, v, w); TurnInstruction turn_instruction = AnalyzeTurn(u, v, w);
if(turn_instruction == TurnInstructions.UTurn){ if(turn_instruction == TurnInstructionsClass::UTurn){
distance += speed_profile.uTurnPenalty; distance += speed_profile.uTurnPenalty;
} }
distance += turn_penalty; distance += turn_penalty;
@ -934,7 +934,7 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(
const NodeID w const NodeID w
) const { ) const {
if(u == w) { if(u == w) {
return TurnInstructions.UTurn; return TurnInstructionsClass::UTurn;
} }
const EdgeIterator edge1 = m_node_based_graph->FindEdge(u, v); const EdgeIterator edge1 = m_node_based_graph->FindEdge(u, v);
@ -944,10 +944,10 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(
const EdgeData & data2 = m_node_based_graph->GetEdgeData(edge2); const EdgeData & data2 = m_node_based_graph->GetEdgeData(edge2);
if(!data1.contraFlow && data2.contraFlow) { if(!data1.contraFlow && data2.contraFlow) {
return TurnInstructions.EnterAgainstAllowedDirection; return TurnInstructionsClass::EnterAgainstAllowedDirection;
} }
if(data1.contraFlow && !data2.contraFlow) { if(data1.contraFlow && !data2.contraFlow) {
return TurnInstructions.LeaveAgainstAllowedDirection; return TurnInstructionsClass::LeaveAgainstAllowedDirection;
} }
//roundabouts need to be handled explicitely //roundabouts need to be handled explicitely
@ -955,19 +955,19 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(
//Is a turn possible? If yes, we stay on the roundabout! //Is a turn possible? If yes, we stay on the roundabout!
if( 1 == m_node_based_graph->GetOutDegree(v) ) { if( 1 == m_node_based_graph->GetOutDegree(v) ) {
//No turn possible. //No turn possible.
return TurnInstructions.NoTurn; return TurnInstructionsClass::NoTurn;
} }
return TurnInstructions.StayOnRoundAbout; return TurnInstructionsClass::StayOnRoundAbout;
} }
//Does turn start or end on roundabout? //Does turn start or end on roundabout?
if(data1.roundabout || data2.roundabout) { if(data1.roundabout || data2.roundabout) {
//We are entering the roundabout //We are entering the roundabout
if( (!data1.roundabout) && data2.roundabout) { if( (!data1.roundabout) && data2.roundabout) {
return TurnInstructions.EnterRoundAbout; return TurnInstructionsClass::EnterRoundAbout;
} }
//We are leaving the roundabout //We are leaving the roundabout
if(data1.roundabout && (!data2.roundabout) ) { if(data1.roundabout && (!data2.roundabout) ) {
return TurnInstructions.LeaveRoundAbout; return TurnInstructionsClass::LeaveRoundAbout;
} }
} }
@ -977,9 +977,9 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(
//TODO: Here we should also do a small graph exploration to check for //TODO: Here we should also do a small graph exploration to check for
// more complex situations // more complex situations
if( 0 != data1.nameID ) { if( 0 != data1.nameID ) {
return TurnInstructions.NoTurn; return TurnInstructionsClass::NoTurn;
} else if (m_node_based_graph->GetOutDegree(v) <= 2) { } else if (m_node_based_graph->GetOutDegree(v) <= 2) {
return TurnInstructions.NoTurn; return TurnInstructionsClass::NoTurn;
} }
} }
@ -988,7 +988,7 @@ TurnInstruction EdgeBasedGraphFactory::AnalyzeTurn(
m_node_info_list[v], m_node_info_list[v],
m_node_info_list[w] m_node_info_list[w]
); );
return TurnInstructions.GetTurnDirectionOfInstruction(angle); return TurnInstructionsClass::GetTurnDirectionOfInstruction(angle);
} }
unsigned EdgeBasedGraphFactory::GetNumberOfEdgeBasedNodes() const { unsigned EdgeBasedGraphFactory::GetNumberOfEdgeBasedNodes() const {

View File

@ -92,6 +92,4 @@ struct TurnInstructionsClass : boost::noncopyable {
}; };
static TurnInstructionsClass TurnInstructions;
#endif /* TURNINSTRUCTIONS_H_ */ #endif /* TURNINSTRUCTIONS_H_ */

View File

@ -179,7 +179,7 @@ public:
if(pathDescription.size() > 2){ if(pathDescription.size() > 2){
pathDescription.pop_back(); pathDescription.pop_back();
pathDescription.back().necessary = true; pathDescription.back().necessary = true;
pathDescription.back().turn_instruction = TurnInstructions.NoTurn; pathDescription.back().turn_instruction = TurnInstructionsClass::NoTurn;
target_phantom.name_id = (pathDescription.end()-2)->name_id; target_phantom.name_id = (pathDescription.end()-2)->name_id;
} }
} else { } else {
@ -188,7 +188,7 @@ public:
if(std::numeric_limits<double>::epsilon() > pathDescription[0].length) { if(std::numeric_limits<double>::epsilon() > pathDescription[0].length) {
if(pathDescription.size() > 2) { if(pathDescription.size() > 2) {
pathDescription.erase(pathDescription.begin()); pathDescription.erase(pathDescription.begin());
pathDescription[0].turn_instruction = TurnInstructions.HeadOn; pathDescription[0].turn_instruction = TurnInstructionsClass::HeadOn;
pathDescription[0].necessary = true; pathDescription[0].necessary = true;
start_phantom.name_id = pathDescription[0].name_id; start_phantom.name_id = pathDescription[0].name_id;
} }

View File

@ -44,6 +44,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
template<class DataFacadeT> template<class DataFacadeT>
class JSONDescriptor : public BaseDescriptor<DataFacadeT> { class JSONDescriptor : public BaseDescriptor<DataFacadeT> {
private: private:
// TODO: initalize in c'tor
DataFacadeT * facade; DataFacadeT * facade;
DescriptorConfig config; DescriptorConfig config;
DescriptionFactory description_factory; DescriptionFactory description_factory;
@ -59,7 +60,7 @@ private:
int start_index; int start_index;
int name_id; int name_id;
int leave_at_exit; int leave_at_exit;
} roundAbout; } round_about;
struct Segment { struct Segment {
Segment() : name_id(-1), length(-1), position(-1) {} Segment() : name_id(-1), length(-1), position(-1) {}
@ -419,56 +420,61 @@ public:
//Segment information has following format: //Segment information has following format:
//["instruction","streetname",length,position,time,"length","earth_direction",azimuth] //["instruction","streetname",length,position,time,"length","earth_direction",azimuth]
//Example: ["Turn left","High Street",200,4,10,"200m","NE",22.5] //Example: ["Turn left","High Street",200,4,10,"200m","NE",22.5]
//See also: http://developers.cloudmade.com/wiki/navengine/JSON_format unsigned necessary_segments_running_index = 0;
unsigned prefixSumOfNecessarySegments = 0; round_about.leave_at_exit = 0;
roundAbout.leave_at_exit = 0; round_about.name_id = 0;
roundAbout.name_id = 0; std::string temp_dist, temp_length, temp_duration, temp_bearing, temp_instruction;
std::string tmpDist, tmpLength, tmpDuration, tmpBearing, tmpInstruction;
//Fetch data from Factory and generate a string from it. //Fetch data from Factory and generate a string from it.
BOOST_FOREACH(const SegmentInformation & segment, description_factory.pathDescription) { BOOST_FOREACH(const SegmentInformation & segment, description_factory.pathDescription) {
TurnInstruction current_instruction = segment.turn_instruction & TurnInstructions.InverseAccessRestrictionFlag; TurnInstruction current_instruction = segment.turn_instruction & TurnInstructionsClass::InverseAccessRestrictionFlag;
entered_restricted_area_count += (current_instruction != segment.turn_instruction); entered_restricted_area_count += (current_instruction != segment.turn_instruction);
if(TurnInstructions.TurnIsNecessary( current_instruction) ) { if (TurnInstructionsClass::TurnIsNecessary( current_instruction) )
if(TurnInstructions.EnterRoundAbout == current_instruction) { {
roundAbout.name_id = segment.name_id; if (TurnInstructionsClass::EnterRoundAbout == current_instruction)
roundAbout.start_index = prefixSumOfNecessarySegments; {
} else { round_about.name_id = segment.name_id;
if(0 != prefixSumOfNecessarySegments){ round_about.start_index = necessary_segments_running_index;
}
else
{
if (0 != necessary_segments_running_index)
{
reply.content.push_back(","); reply.content.push_back(",");
} }
reply.content.push_back("[\""); reply.content.push_back("[\"");
if(TurnInstructions.LeaveRoundAbout == current_instruction) { if(TurnInstructionsClass::LeaveRoundAbout == current_instruction) {
intToString(TurnInstructions.EnterRoundAbout, tmpInstruction); intToString(TurnInstructionsClass::EnterRoundAbout, temp_instruction);
reply.content.push_back(tmpInstruction); reply.content.push_back(temp_instruction);
reply.content.push_back("-"); reply.content.push_back("-");
intToString(roundAbout.leave_at_exit+1, tmpInstruction); intToString(round_about.leave_at_exit+1, temp_instruction);
reply.content.push_back(tmpInstruction); reply.content.push_back(temp_instruction);
roundAbout.leave_at_exit = 0; round_about.leave_at_exit = 0;
} else { } else {
intToString(current_instruction, tmpInstruction); intToString(current_instruction, temp_instruction);
reply.content.push_back(tmpInstruction); reply.content.push_back(temp_instruction);
} }
reply.content.push_back("\",\""); reply.content.push_back("\",\"");
reply.content.push_back(facade->GetEscapedNameForNameID(segment.name_id)); reply.content.push_back(facade->GetEscapedNameForNameID(segment.name_id));
reply.content.push_back("\","); reply.content.push_back("\",");
intToString(segment.length, tmpDist); intToString(segment.length, temp_dist);
reply.content.push_back(tmpDist); reply.content.push_back(temp_dist);
reply.content.push_back(","); reply.content.push_back(",");
intToString(prefixSumOfNecessarySegments, tmpLength); intToString(necessary_segments_running_index, temp_length);
reply.content.push_back(tmpLength); reply.content.push_back(temp_length);
reply.content.push_back(","); reply.content.push_back(",");
intToString(segment.duration/10, tmpDuration); intToString(segment.duration/10, temp_duration);
reply.content.push_back(tmpDuration); reply.content.push_back(temp_duration);
reply.content.push_back(",\""); reply.content.push_back(",\"");
intToString(segment.length, tmpLength); intToString(segment.length, temp_length);
reply.content.push_back(tmpLength); reply.content.push_back(temp_length);
reply.content.push_back("m\",\""); reply.content.push_back("m\",\"");
double bearing_value = round(segment.bearing/10.); double bearing_value = round(segment.bearing/10.);
reply.content.push_back(Azimuth::Get(bearing_value)); reply.content.push_back(Azimuth::Get(bearing_value));
reply.content.push_back("\","); reply.content.push_back("\",");
intToString(bearing_value, tmpBearing); intToString(bearing_value, temp_bearing);
reply.content.push_back(tmpBearing); reply.content.push_back(temp_bearing);
reply.content.push_back("]"); reply.content.push_back("]");
route_segments_list.push_back( route_segments_list.push_back(
@ -479,22 +485,22 @@ public:
) )
); );
} }
} else if(TurnInstructions.StayOnRoundAbout == current_instruction) { } else if(TurnInstructionsClass::StayOnRoundAbout == current_instruction) {
++roundAbout.leave_at_exit; ++round_about.leave_at_exit;
} }
if(segment.necessary) if(segment.necessary)
++prefixSumOfNecessarySegments; ++necessary_segments_running_index;
} }
if(INT_MAX != route_length) { if(INT_MAX != route_length) {
reply.content.push_back(",[\""); reply.content.push_back(",[\"");
intToString(TurnInstructions.ReachedYourDestination, tmpInstruction); intToString(TurnInstructionsClass::ReachedYourDestination, temp_instruction);
reply.content.push_back(tmpInstruction); reply.content.push_back(temp_instruction);
reply.content.push_back("\",\""); reply.content.push_back("\",\"");
reply.content.push_back("\","); reply.content.push_back("\",");
reply.content.push_back("0"); reply.content.push_back("0");
reply.content.push_back(","); reply.content.push_back(",");
intToString(prefixSumOfNecessarySegments-1, tmpLength); intToString(necessary_segments_running_index-1, temp_length);
reply.content.push_back(tmpLength); reply.content.push_back(temp_length);
reply.content.push_back(","); reply.content.push_back(",");
reply.content.push_back("0"); reply.content.push_back("0");
reply.content.push_back(",\""); reply.content.push_back(",\"");

View File

@ -104,7 +104,7 @@ struct SharedDataLayout {
(graph_edge_list_size * sizeof(QueryGraph::_StrEdge) ) + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge) ) +
(timestamp_length * sizeof(char) ) + (timestamp_length * sizeof(char) ) +
(coordinate_list_size * sizeof(FixedPointCoordinate) ) + (coordinate_list_size * sizeof(FixedPointCoordinate) ) +
(turn_instruction_list_size * sizeof(TurnInstructions) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) +
(r_search_tree_size * sizeof(RTreeNode) ) + (r_search_tree_size * sizeof(RTreeNode) ) +
sizeof(checksum) + sizeof(checksum) +
1024*sizeof(char); 1024*sizeof(char);
@ -192,7 +192,7 @@ struct SharedDataLayout {
(graph_edge_list_size * sizeof(QueryGraph::_StrEdge) ) + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge) ) +
(timestamp_length * sizeof(char) ) + (timestamp_length * sizeof(char) ) +
(coordinate_list_size * sizeof(FixedPointCoordinate) ) + (coordinate_list_size * sizeof(FixedPointCoordinate) ) +
(turn_instruction_list_size * sizeof(TurnInstructions) ); (turn_instruction_list_size * sizeof(TurnInstructionsClass));
return result; return result;
} }
uint64_t GetChecksumOffset() const { uint64_t GetChecksumOffset() const {
@ -205,7 +205,7 @@ struct SharedDataLayout {
(graph_edge_list_size * sizeof(QueryGraph::_StrEdge) ) + (graph_edge_list_size * sizeof(QueryGraph::_StrEdge) ) +
(timestamp_length * sizeof(char) ) + (timestamp_length * sizeof(char) ) +
(coordinate_list_size * sizeof(FixedPointCoordinate) ) + (coordinate_list_size * sizeof(FixedPointCoordinate) ) +
(turn_instruction_list_size * sizeof(TurnInstructions) ) + (turn_instruction_list_size * sizeof(TurnInstructionsClass)) +
(r_search_tree_size * sizeof(RTreeNode) ); (r_search_tree_size * sizeof(RTreeNode) );
return result; return result;
} }