ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
borderid.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2020 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  * Daniel Heß - initial API and implementation
13  * Stephan Lapoehn - initial API and implementation
14  ********************************************************************************/
15 
16 #pragma once
18 #include <string>
19 
20 namespace adore
21 {
22  namespace env
23  {
24  namespace BorderBased
25  {
30  struct BorderID
31  {
33  BorderID() {}
34  BorderID(Coordinate first, Coordinate last) :m_first(first), m_last(last) {}
42  void translate(double dx,double dy,double dz)
43  {
44  m_first.translate(dx,dy,dz);
45  m_last.translate(dx,dy,dz);
46  }
51  double distance(const BorderID& other)const
52  {
53  return this->m_first.distance(other.m_first)
54  + this->m_last.distance(other.m_last);
55  }
59  double distance()const
60  {
61  return this->m_first.distance(this->m_last);
62  }
66  double getLength()
67  {
68  const double dx = m_first.m_X-m_last.m_X;
69  const double dy = m_first.m_Y-m_last.m_Y;
70  const double dz = m_first.m_Z-m_last.m_Z;
71  return std::sqrt(dx*dx+dy*dy+dz*dz);
72  }
73 
78  void rotate(double angle, double x0=0.0, double y0=0.0)
79  {
80  m_first.rotate(angle, x0, y0);
81  m_last.rotate(angle, x0, y0);
82  }
90  bool operator==(const BorderID& other)const
91  {
92  return this->m_first == other.m_first && this->m_last == other.m_last;
93  }
98  {
99  return BorderID(m_last,m_first);
100  }
108  bool operator<(const BorderID& other)const
109  {
110  double tx=this->m_first.m_X;
111  double ty=this->m_first.m_Y;
112  double tz=this->m_first.m_Z;
113  double ox=other.m_first.m_X;
114  double oy=other.m_first.m_Y;
115  double oz=other.m_first.m_Z;
116  return std::sqrt(tx*tx+ty*ty+tz*tz)<std::sqrt(ox*ox+oy*oy+oz*oz);
117  }
118 
119  //bool operator<(const BorderID* rhs)
120  //{
121  // unsigned int hash = BorderBased::BorderIDHasher()(*this);
122  // unsigned int hashr = BorderBased::BorderIDHasher()(*rhs);
123  // return hash < hashr;
124  //}
125 
131  std::string toString() const
132  {
133  std::stringstream s;
134  s<<"BID<"<<m_first.toString()<<";"<<m_last.toString()<<">";
135  return s.str();
136  }
137 
148  bool isInArea(double x_min, double x_max, double y_min, double y_max) const
149  {
150  return m_first.isInArea(x_min, x_max, y_min, y_max) && m_last.isInArea(x_min, x_max, y_min, y_max);
151  }
161  {
162  auto test = BorderID(b.m_last,b.m_first);
163  return test;
164  }
166  {
167  return BorderID(m_last,m_first);
168  }
169  };
170 
176  {
178  std::size_t operator()(const BorderID& b) const
179  {
180  std::size_t first = ch(b.m_first);
181  std::size_t last = ch(b.m_last);
182  return first ^ (last << 16) ^ (last >> 16);//first=[fhi,flo], last=[lhi,llo] --> return [fhi xor llo, flo xor lhi]
183  }
184  };
185  }
186  }
187 }
x0
Definition: adore_set_goal.py:25
y0
Definition: adore_set_goal.py:26
Definition: areaofeffectconverter.h:20
a functor, which hashes a BorderID object -> std::unordered_set<BorderID,BorderIDHasher> amap(0);
Definition: borderid.h:176
CoordinateHasher ch
Definition: borderid.h:177
std::size_t operator()(const BorderID &b) const
Definition: borderid.h:178
This struct identifies a Border by the coordinates of the starting and the end point.
Definition: borderid.h:31
double distance(const BorderID &other) const
returns sum of distance between this.m_first and other.m_first and distance between this....
Definition: borderid.h:51
Coordinate m_last
Definition: borderid.h:32
BorderID inverse() const
returns the inverse of this
Definition: borderid.h:97
double getLength()
Definition: borderid.h:66
BorderID(Coordinate first, Coordinate last)
Definition: borderid.h:34
bool isInArea(double x_min, double x_max, double y_min, double y_max) const
Check whether the starting point and the end point of the BorderID are in a certain area.
Definition: borderid.h:148
Coordinate m_first
Definition: borderid.h:32
BorderID getReverseDirectionID(const BorderID &b)
Get a BorderID with the reverse direction of a given BorderID.
Definition: borderid.h:160
bool operator==(const BorderID &other) const
Check equality of two BorderIDs.
Definition: borderid.h:90
std::string toString() const
Write information of the BorderID to a string.
Definition: borderid.h:131
BorderID()
Definition: borderid.h:33
void translate(double dx, double dy, double dz)
Translate a border.
Definition: borderid.h:42
bool operator<(const BorderID &other) const
Compare two BorderIDs.
Definition: borderid.h:108
void rotate(double angle, double x0=0.0, double y0=0.0)
Definition: borderid.h:78
double distance() const
returns distance between coordinates in id
Definition: borderid.h:59
BorderID getReverseDirectionID() const
Definition: borderid.h:165
a functor, which hashes a Coordinate object -> std::unordered_set<Coordinate,CoordinateHasher> amap(0...
Definition: coordinate.h:281
This struct represents 3-dimensional coordines.
Definition: coordinate.h:34
bool isInArea(double x_min, double x_max, double y_min, double y_max) const
Check whether a Coordinate is in a certain area.
Definition: coordinate.h:216
void rotate(double angle, double x0=0.0, double y0=0.0)
rotate around x0,y0
Definition: coordinate.h:100
void translate(double dx, double dy, double dz)
Translate a coordinate object.
Definition: coordinate.h:87
double m_Y
Definition: coordinate.h:35
double distance(const Coordinate &other) const
Calculate the distance between two Coordinates.
Definition: coordinate.h:133
double m_Z
Definition: coordinate.h:35
double m_X
Definition: coordinate.h:35
std::string toString() const
Write information of the Coordinate to a string.
Definition: coordinate.h:191