2010-08-31 10:00:40 -04:00
|
|
|
/*
|
2013-10-14 07:42:28 -04:00
|
|
|
|
|
|
|
Copyright (c) 2013, Project OSRM, Dennis Luxen, others
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
*/
|
2010-08-31 10:00:40 -04:00
|
|
|
|
|
|
|
#ifndef PHANTOMNODES_H_
|
|
|
|
#define PHANTOMNODES_H_
|
|
|
|
|
2013-12-20 07:12:56 -05:00
|
|
|
#include <osrm/Coordinate.h>
|
2014-03-19 11:42:37 -04:00
|
|
|
#include "../Util/SimpleLogger.h"
|
2013-12-18 06:00:58 -05:00
|
|
|
#include "../typedefs.h"
|
|
|
|
|
2011-07-11 11:16:14 -04:00
|
|
|
struct PhantomNode {
|
2013-08-14 07:12:28 -04:00
|
|
|
PhantomNode() :
|
2014-03-25 13:06:05 -04:00
|
|
|
forward_node_id(SPECIAL_NODEID),
|
|
|
|
reverse_node_id(SPECIAL_NODEID),
|
|
|
|
name_id(std::numeric_limits<unsigned>::max()),
|
2014-02-21 10:55:41 -05:00
|
|
|
forward_weight(INVALID_EDGE_WEIGHT),
|
|
|
|
reverse_weight(INVALID_EDGE_WEIGHT),
|
|
|
|
forward_offset(0),
|
|
|
|
reverse_offset(0),
|
2014-02-28 11:14:38 -05:00
|
|
|
packed_geometry_id(SPECIAL_EDGEID),
|
2014-02-26 09:55:04 -05:00
|
|
|
ratio(0.),
|
2014-02-28 11:14:38 -05:00
|
|
|
fwd_segment_position(0)
|
2013-08-14 07:12:28 -04:00
|
|
|
{ }
|
|
|
|
|
2014-02-11 05:42:24 -05:00
|
|
|
NodeID forward_node_id;
|
|
|
|
NodeID reverse_node_id;
|
|
|
|
unsigned name_id;
|
|
|
|
int forward_weight;
|
|
|
|
int reverse_weight;
|
2014-02-21 10:55:41 -05:00
|
|
|
int forward_offset;
|
|
|
|
int reverse_offset;
|
2014-02-28 11:14:38 -05:00
|
|
|
unsigned packed_geometry_id;
|
2012-02-10 11:14:30 -05:00
|
|
|
double ratio;
|
2013-08-14 07:12:28 -04:00
|
|
|
FixedPointCoordinate location;
|
2014-02-26 09:55:04 -05:00
|
|
|
unsigned short fwd_segment_position;
|
|
|
|
|
2014-02-11 05:42:24 -05:00
|
|
|
|
2014-03-25 13:06:05 -04:00
|
|
|
int GetForwardWeightPlusOffset() const
|
|
|
|
{
|
2014-03-19 11:42:37 -04:00
|
|
|
SimpleLogger().Write(logDEBUG) << "->fwd_offset: " << forward_offset << ", weight: " << forward_weight;
|
|
|
|
return reverse_offset + forward_weight;
|
2014-02-21 10:55:41 -05:00
|
|
|
}
|
|
|
|
|
2014-03-25 13:06:05 -04:00
|
|
|
int GetReverseWeightPlusOffset() const
|
|
|
|
{
|
2014-03-19 11:42:37 -04:00
|
|
|
SimpleLogger().Write(logDEBUG) << "->rev_offset: " << reverse_offset << ", weight: " << reverse_weight;
|
|
|
|
return forward_offset + reverse_weight;
|
2014-02-21 10:55:41 -05:00
|
|
|
}
|
|
|
|
|
2014-03-25 13:06:05 -04:00
|
|
|
void Reset()
|
|
|
|
{
|
2014-02-21 10:55:41 -05:00
|
|
|
forward_node_id = SPECIAL_NODEID;
|
|
|
|
name_id = SPECIAL_NODEID;
|
|
|
|
forward_weight = INVALID_EDGE_WEIGHT;
|
|
|
|
reverse_weight = INVALID_EDGE_WEIGHT;
|
|
|
|
forward_offset = 0;
|
|
|
|
reverse_offset = 0;
|
2012-02-10 11:14:30 -05:00
|
|
|
ratio = 0.;
|
2011-07-11 11:16:14 -04:00
|
|
|
location.Reset();
|
|
|
|
}
|
2014-02-21 10:55:41 -05:00
|
|
|
|
2014-03-25 13:06:05 -04:00
|
|
|
bool isBidirected() const
|
|
|
|
{
|
|
|
|
return (forward_node_id != SPECIAL_NODEID) &&
|
|
|
|
(reverse_node_id != SPECIAL_NODEID);
|
2014-02-21 10:55:41 -05:00
|
|
|
}
|
|
|
|
|
2014-03-25 13:06:05 -04:00
|
|
|
bool IsCompressed() const
|
|
|
|
{
|
2014-02-21 10:55:41 -05:00
|
|
|
return (forward_offset != 0) || (reverse_offset != 0);
|
2011-11-24 11:33:23 -05:00
|
|
|
}
|
2014-02-21 10:55:41 -05:00
|
|
|
|
2014-03-25 13:06:05 -04:00
|
|
|
bool isValid(const unsigned numberOfNodes) const
|
|
|
|
{
|
2014-02-11 05:42:24 -05:00
|
|
|
return
|
|
|
|
location.isValid() &&
|
2014-03-03 12:47:34 -05:00
|
|
|
(
|
|
|
|
(forward_node_id < numberOfNodes) ||
|
|
|
|
(reverse_node_id < numberOfNodes)
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
(forward_weight != INVALID_EDGE_WEIGHT) ||
|
|
|
|
(reverse_weight != INVALID_EDGE_WEIGHT)
|
|
|
|
) &&
|
2014-02-11 05:42:24 -05:00
|
|
|
(ratio >= 0.) &&
|
|
|
|
(ratio <= 1.) &&
|
2014-03-06 12:05:22 -05:00
|
|
|
(name_id != std::numeric_limits<unsigned>::max()
|
|
|
|
);
|
2012-03-05 13:08:10 -05:00
|
|
|
}
|
2012-09-27 08:55:48 -04:00
|
|
|
|
2014-03-25 13:06:05 -04:00
|
|
|
bool operator==(const PhantomNode & other) const
|
|
|
|
{
|
2012-09-27 08:55:48 -04:00
|
|
|
return location == other.location;
|
|
|
|
}
|
2011-07-11 11:16:14 -04:00
|
|
|
};
|
|
|
|
|
2014-03-25 13:06:05 -04:00
|
|
|
struct PhantomNodes
|
|
|
|
{
|
2014-03-25 12:48:25 -04:00
|
|
|
//TODO: rename to lower-case non-camel source_*,target_*
|
2014-03-25 13:06:05 -04:00
|
|
|
PhantomNode source_phantom;
|
|
|
|
PhantomNode target_phantom;
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
source_phantom.Reset();
|
|
|
|
target_phantom.Reset();
|
2011-06-10 04:25:26 -04:00
|
|
|
}
|
2011-07-18 11:48:30 -04:00
|
|
|
|
2014-03-25 13:06:05 -04:00
|
|
|
bool PhantomsAreOnSameNodeBasedEdge() const
|
|
|
|
{
|
|
|
|
return (source_phantom.forward_node_id == target_phantom.forward_node_id);
|
2011-07-18 11:48:30 -04:00
|
|
|
}
|
|
|
|
|
2014-03-25 13:06:05 -04:00
|
|
|
bool AtLeastOnePhantomNodeIsInvalid() const
|
|
|
|
{
|
|
|
|
return ((source_phantom.forward_node_id == SPECIAL_NODEID) && (source_phantom.reverse_node_id == SPECIAL_NODEID)) ||
|
|
|
|
((target_phantom.forward_node_id == SPECIAL_NODEID) && (target_phantom.reverse_node_id == SPECIAL_NODEID));
|
2011-07-18 11:48:30 -04:00
|
|
|
}
|
2012-09-27 08:55:48 -04:00
|
|
|
|
2014-03-25 13:06:05 -04:00
|
|
|
bool PhantomNodesHaveEqualLocation() const
|
|
|
|
{
|
|
|
|
return source_phantom == target_phantom;
|
2012-09-27 08:55:48 -04:00
|
|
|
}
|
2011-06-10 04:25:26 -04:00
|
|
|
};
|
|
|
|
|
2014-03-03 12:47:34 -05:00
|
|
|
inline std::ostream& operator<<(std::ostream &out, const PhantomNodes & pn) {
|
2014-03-25 13:06:05 -04:00
|
|
|
// out << "Node1: " << pn.source_phantom.forward_node_id << "\n";
|
|
|
|
// out << "Node2: " << pn.target_phantom.reverse_node_id << "\n";
|
|
|
|
out << "source_coord: " << pn.source_phantom.location << "\n";
|
|
|
|
out << "target_coord: " << pn.target_phantom.location << std::endl;
|
2011-06-10 04:25:26 -04:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2014-03-03 12:47:34 -05:00
|
|
|
inline std::ostream& operator<<(std::ostream &out, const PhantomNode & pn) {
|
|
|
|
out << "node1: " << pn.forward_node_id << ", " <<
|
|
|
|
"node2: " << pn.reverse_node_id << ", " <<
|
|
|
|
"name: " << pn.name_id << ", " <<
|
|
|
|
"fwd-w: " << pn.forward_weight << ", " <<
|
|
|
|
"rev-w: " << pn.reverse_weight << ", " <<
|
|
|
|
"fwd-o: " << pn.forward_offset << ", " <<
|
|
|
|
"rev-o: " << pn.reverse_offset << ", " <<
|
|
|
|
"ratio: " << pn.ratio << ", " <<
|
|
|
|
"geom: " << pn.packed_geometry_id << ", " <<
|
|
|
|
"pos: " << pn.fwd_segment_position << ", " <<
|
|
|
|
"loc: " << pn.location;
|
2012-02-29 08:30:19 -05:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
2010-08-31 10:00:40 -04:00
|
|
|
#endif /* PHANTOMNODES_H_ */
|