primitives/Point.h
Go to the documentation of this file.
1 #pragma once
2 #pragma GCC diagnostic push
3 #if defined __GNUC__ && (__GNUC__ >= 6)
4 #pragma GCC diagnostic ignored "-Wignored-attributes"
5 #pragma GCC diagnostic ignored "-Wint-in-bool-context"
6 #endif
7 #include <Eigen/Core>
8 #pragma GCC diagnostic pop
9 #include <utility>
10 
11 #include "lanelet2_core/Forward.h"
16 
17 namespace lanelet {
18 
19 using BasicPoint3d = Eigen::Vector3d;
20 using BasicPoint2d = Eigen::Matrix<double, 2, 1, Eigen::DontAlign>;
21 using BasicPoints2d = std::vector<Eigen::Vector2d,
22  Eigen::aligned_allocator<Eigen::Vector2d>>;
23 using BasicPoints3d = std::vector<BasicPoint3d>;
24 
25 namespace internal {
26 template <>
27 class Converter<const BasicPoint2d> {
28  public:
29  template <typename InType>
30  const BasicPoint2d& convert(const InType& t) const {
31  return t.basicPoint2d();
32  }
33 };
34 } // namespace internal
35 
36 namespace traits {
38 template <>
44  using Category = PointTag;
45 };
46 template <>
52  using Category = PointTag;
53 };
54 template <>
55 struct PrimitiveTraits<Eigen::Vector2d> {
60  using Category = PointTag;
61 };
62 template <>
63 struct PointTraits<BasicPoint3d> : PrimitiveTraits<BasicPoint3d> {
67  static constexpr bool IsPrimitive = false;
68  static constexpr Dimensions Dimension = Dimensions::Three;
69 };
70 template <>
71 struct PointTraits<BasicPoint2d> : PrimitiveTraits<BasicPoint2d> {
75  static constexpr bool IsPrimitive = false;
76  static constexpr Dimensions Dimension = Dimensions::Two;
77 };
78 template <>
79 struct PointTraits<Eigen::Vector2d> : PrimitiveTraits<Eigen::Vector2d> {
83  static constexpr bool IsPrimitive = false;
84  static constexpr Dimensions Dimension = Dimensions::Two;
85 };
86 
87 template <>
88 inline BasicPoint3d to3D(const BasicPoint2d& primitive) {
89  return {primitive.x(), primitive.y(), 0};
90 }
91 template <>
92 inline BasicPoint2d to2D(const BasicPoint3d& primitive) {
93  return {primitive.x(), primitive.y()};
94 }
95 } // namespace traits
96 
99  double length{0.};
100  double distance{0.};
101 };
102 
105 class PointData : public PrimitiveData { // NOLINT
106  public:
107  PointData(Id id, BasicPoint3d point, const AttributeMap& attributes = AttributeMap())
108  : PrimitiveData(id, attributes), point(point), point2d_{point.x(), point.y()} {}
109  PointData(const PointData&) = delete;
110  PointData& operator=(const LineStringData&) = delete;
111  PointData(PointData&&) = default;
112  PointData& operator=(PointData&&) = default;
113  ~PointData() = default;
114  const BasicPoint2d& point2d() const {
115  if (BOOST_UNLIKELY(point.head<2>() != point2d_)) {
116  point2d_ = point.head<2>();
117  }
118  return point2d_;
119  }
120 
121  BasicPoint3d point; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes)
122 
123  private:
125 };
126 
144 
150 class ConstPoint2d : public ConstPrimitive<PointData> {
151  public:
158  static constexpr traits::Dimensions Dimension = traits::Dimensions::Two;
159 
161 
163  ConstPoint2d(Id id, const BasicPoint3d& point, const AttributeMap& attributes = AttributeMap())
164  : ConstPrimitive<PointData>{std::make_shared<PointData>(id, point, attributes)} {} // NOLINT
165 
167 
171  explicit ConstPoint2d(Id id = InvalId, double x = 0., double y = 0., double z = 0.,
172  const AttributeMap& attributes = AttributeMap())
173  : ConstPrimitive<PointData>{std::make_shared<PointData>( // NOLINT
174  id, BasicPoint3d(x, y, z), attributes)} {}
175 
177  operator BasicPoint2d() const noexcept { // NOLINT
178  return point2d();
179  }
180 
182  const BasicPoint& basicPoint() const noexcept { return point2d(); }
183 
186  const BasicPoint2d& basicPoint2d() const noexcept { return point2d(); }
187 
189  double x() const noexcept { return point().x(); }
190 
192  double y() const noexcept { return point().y(); }
193 
194  protected:
195  const BasicPoint3d& point() const { return constData()->point; }
196  const BasicPoint2d& point2d() const { return constData()->point2d(); }
197 };
198 
202 class ConstPoint3d : public ConstPoint2d {
203  public:
207  static constexpr traits::Dimensions Dimension = traits::Dimensions::Three;
208 
210  ConstPoint3d() = default;
211  explicit ConstPoint3d(const ConstPoint2d& other) : ConstPoint2d(other) {}
212 
213  operator BasicPoint2d() const noexcept = delete; // NOLINT
214 
216  operator const BasicPoint3d&() const noexcept { // NOLINT
217  return point();
218  }
219 
221  const BasicPoint& basicPoint() const noexcept { return point(); }
222 
224  double z() const noexcept { return point().z(); }
225 };
226 
230 class Point2d : public Primitive<ConstPoint3d> {
231  public:
235  using TwoDType = Point2d;
237  static constexpr traits::Dimensions Dimension = traits::Dimensions::Two;
238 
239  using Primitive::Primitive;
240  using Primitive::x;
241  using Primitive::y;
242  Point2d() = default;
243  operator const BasicPoint3d&() const = delete;
244 
246  operator BasicPoint2d() const noexcept { // NOLINT
247  return point().head<2>();
248  }
249 
251  auto basicPoint() noexcept { return point().head<2>(); }
252 
254  const BasicPoint2d& basicPoint() const noexcept { return point2d(); }
255 
257  double& x() noexcept { return point().x(); }
258 
260  double& y() noexcept { return point().y(); }
261  double z() const noexcept = delete;
262 
263  protected:
264  using Primitive::point;
265  BasicPoint3d& point() { return data()->point; }
266 };
267 
271 class Point3d : public Point2d {
272  public:
276  Point3d() = default;
277  static constexpr traits::Dimensions Dimension = traits::Dimensions::Three;
278 
279  using Point2d::Point2d;
280 
282  explicit Point3d(const Point2d& other) : Point2d(other) {}
283 
284  using Primitive::x;
285  using Primitive::y;
286  using Primitive::z;
287 
288  operator BasicPoint2d() const noexcept = delete;
289 
291  operator BasicPoint3d&() noexcept { return point(); } // NOLINT
292 
294  operator const BasicPoint3d&() const noexcept { return point(); } // NOLINT
295 
297  BasicPoint& basicPoint() noexcept { return point(); }
298 
300  const BasicPoint& basicPoint() const noexcept { return point(); }
301 
303  double& x() noexcept { return point().x(); }
304 
306  double& y() noexcept { return point().y(); }
307 
309  double& z() noexcept { return point().z(); }
310 };
311 
312 inline std::ostream& operator<<(std::ostream& stream, const ConstPoint2d& obj) {
313  return stream << "[id: " << obj.id() << " x: " << obj.x() << " y: " << obj.y() << "]";
314 }
315 
316 inline std::ostream& operator<<(std::ostream& stream, const ConstPoint3d& obj) {
317  return stream << "[id: " << obj.id() << " x: " << obj.x() << " y: " << obj.y() << " z: " << obj.z() << "]";
318 }
319 
320 inline std::ostream& operator<<(std::ostream& stream, const Point2d& obj) {
321  return stream << "[id: " << obj.id() << " x: " << obj.x() << " y: " << obj.y() << "]";
322 }
323 
324 inline std::ostream& operator<<(std::ostream& stream, const Point3d& obj) {
325  return stream << "[id: " << obj.id() << " x: " << obj.x() << " y: " << obj.y() << " z: " << obj.z() << "]";
326 }
327 
328 namespace traits {
329 template <typename T>
330 constexpr bool isPointT() {
331  return isCategory<T, traits::PointTag>();
332 }
333 } // namespace traits
334 template <typename T, typename RetT>
335 using IfPT = std::enable_if_t<traits::isPointT<T>(), RetT>;
336 
337 } // namespace lanelet
338 
339 // Hash function for usage in containers
340 namespace std {
341 template <>
342 struct hash<lanelet::Point3d> : public lanelet::HashBase<lanelet::Point3d> {};
343 template <>
344 struct hash<lanelet::ConstPoint3d> : public lanelet::HashBase<lanelet::ConstPoint3d> {};
345 template <>
346 struct hash<lanelet::Point2d> : public lanelet::HashBase<lanelet::Point2d> {};
347 template <>
348 struct hash<lanelet::ConstPoint2d> : public lanelet::HashBase<lanelet::ConstPoint2d> {};
349 } // namespace std
std::vector< BasicPoint3d > BasicPoints3d
multiple simple 3d-points
typename PrimitiveTraits< BasicPoint2d >::ConstType ConstPoint
std::vector< Eigen::Vector2d, Eigen::aligned_allocator< Eigen::Vector2d > > BasicPoints2d
multiple simple 2d-points
PointData(Id id, BasicPoint3d point, const AttributeMap &attributes=AttributeMap())
Id id() const noexcept
get the unique id of this primitive
Definition: Primitive.h:96
typename PrimitiveTraits< BasicPoint2d >::MutableType MutablePoint
double & y() noexcept
gets a mutable reference to the y coordinate
auto basicPoint() noexcept
get a mutable reference to the 2d point data
double & z() noexcept
gets a mutable reference to the z coordinate
ConstPoint3d(const ConstPoint2d &other)
const BasicPoint2d & convert(const InType &t) const
typename PrimitiveTraits< BasicPoint3d >::ConstType ConstPoint
int64_t Id
Definition: Forward.h:198
Eigen::Vector3d BasicPoint3d
a simple 3d-point
Point3d(const Point2d &other)
constructs a 3D from a 2D point. No data is lost in that process.
std::ostream & operator<<(std::ostream &stream, const Attribute &obj)
Definition: Attribute.h:369
HybridMap< Attribute, decltype(AttributeNamesString::Map)&, AttributeNamesString::Map > AttributeMap
Definition: Attribute.h:371
double z() const noexcept
get the z coordinate
const BasicPoint2d & basicPoint() const noexcept
get a basic 2d point
Point2d()=default
BasicPoint3d to3D(const BasicPoint2d &primitive)
typename T::MutableType MutableType
Definition: Traits.h:23
typename PrimitiveTraits< BasicPoint2d >::ConstType ConstPoint
An immutable 2d point.
double & y() noexcept
gets a mutable reference to the y coordinate
Describes a position in linestring coordinates.
std::enable_if_t< traits::isPointT< T >(), RetT > IfPT
constexpr bool isPointT()
Identifies RegulatoryElementPrimitives.
Definition: Traits.h:20
BasicPoint3d & point()
A mutable 3d point.
const BasicPoint & basicPoint() const noexcept
get a basic 3d point
BasicPoint2d BasicPoint
returned basic point type
double & x() noexcept
gets a mutable reference to the x coordinate
typename PrimitiveTraits< BasicPoint2d >::MutableType MutablePoint
double & x() noexcept
gets a mutable reference to the x coordinate
Optional< double > distance
typename PrimitiveTraits< BasicPoint3d >::MutableType MutablePoint
Basic Primitive class for all primitives of lanelet2.
Definition: Primitive.h:70
Base class for all mutable Primitives of lanelet2.
Definition: Primitive.h:243
Common data class for all lanelet primitivesThis class provides the data that all lanelet primitives ...
Definition: Primitive.h:31
BasicPoint2d to2D(const BasicPoint3d &primitive)
const BasicPoint2d & point2d() const
BasicPoint & basicPoint() noexcept
Get a mutable reference to the internal 3d point.
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > BasicPoint2d
a simple 2d-point
const BasicPoint & basicPoint() const noexcept
Get an immutable reference to the internal 3d point.
Id id
Definition: LaneletMap.cpp:63
An immutable 3d point.
ConstPoint2d(Id id, const BasicPoint3d &point, const AttributeMap &attributes=AttributeMap())
Construct from an id and a point.
ConstPrimitive(const std::shared_ptr< const Data > &data)
Construct from a pointer to the data.
Definition: Primitive.h:78
A mutable 2d point.
Specialization of traits for points.
Definition: Traits.h:133
typename T::ConstType ConstType
Definition: Traits.h:22
constexpr Id InvalId
indicates a primitive that is not part of a map
Definition: Forward.h:199


lanelet2_core
Author(s): Fabian Poggenhans
autogenerated on Tue Jun 6 2023 02:23:32