ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
bordersequence.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  ********************************************************************************/
14 #pragma once
15 #include <vector>
17 
18 namespace adore
19 {
20 namespace env
21 {
22 namespace BorderBased
23 {
27 class BorderSequence: public std::vector<Border*>
28 {
29  public:
30 
31 
36  double getLength() const
37  {
38  double result = 0.0;
39  for(auto it = begin();it!=end();it++)
40  {
41  result += (*it)->getLength();
42  }
43  return result;
44  }
45 
56  template<typename TArray1,typename TArray2>
57  bool sample(TArray1 sample_array,int i0,int i1,TArray2& outx,TArray2& outy,TArray2& outz)
58  {
59  if(size()==0)return false;
60  auto value_position = begin();
61  double range_start = 0;
62  double range_end = (*begin())->getLength();
63  for(int i=i0;i<=i1;i++)
64  {
65  double sample = sample_array[i];
66  while(range_end<sample)
67  {
68  value_position++;
69  if(value_position==end())return false;
70  range_start = range_end;
71  range_end += (*value_position)->getLength();
72  }
73  if(sample<range_start)return false;
74  if((*value_position)->m_path==nullptr)
75  {
76  double s = (sample-range_start)/(range_end-range_start);
77  outx[i] = (*value_position)->m_id.m_first.m_X + s*((*value_position)->m_id.m_last.m_X - (*value_position)->m_id.m_first.m_X);
78  outy[i] = (*value_position)->m_id.m_first.m_Y + s*((*value_position)->m_id.m_last.m_Y - (*value_position)->m_id.m_first.m_Y);
79  outz[i] = (*value_position)->m_id.m_first.m_Z + s*((*value_position)->m_id.m_last.m_Z - (*value_position)->m_id.m_first.m_Z);
80  }
81  else
82  {
83  auto p = (*value_position)->m_path->f(sample-range_start);
84  outx[i] = p(0);
85  outy[i] = p(1);
86  outz[i] = p(2);
87  }
88  }
89  return true;
90  }
91 
92 
93 
94  struct LineIterator
95  {
96  std::vector<Border*>::iterator bit_;
97  int idx_;
98  bool valid_;
99  LineIterator(std::vector<Border*>::iterator bit,int idx,bool valid=true):bit_(bit),idx_(idx),valid_(valid){}
100 
101  static LineIterator begin(std::vector<Border*>* bs)
102  {
103  if(bs->size()==0)return LineIterator(bs->end(),0,false);
104  return LineIterator(bs->begin(),0);
105  }
106  static LineIterator end(std::vector<Border*>* bs)
107  {
108  if(bs->size()==0)return LineIterator(bs->end(),0,false);
109  auto it = std::next(bs->begin(),bs->size()-1);
110  if((*it)->m_path==nullptr)return LineIterator(it,1);
111  return LineIterator(it,(*it)->m_path->getData().nc()-1);
112  }
113 
114 
115  bool operator!=(const LineIterator& other)const
116  {
117  if(!valid_&&!other.valid_)return false;
118  else return (*bit_)!=(*other.bit_) || idx_!=other.idx_;
119  }
120  void operator++(int)
121  {
122  if( (*bit_)->m_path==nullptr )
123  {
124  if(idx_==0)
125  {
126  idx_++;
127  }
128  else
129  {
130  idx_=0;
131  bit_++;
132  }
133  }
134  else
135  {
136  if((*bit_)->m_path->getData().nc()-1==idx_)
137  {
138  bit_++;
139  idx_ = 0;
140  }
141  else
142  {
143  idx_++;
144  }
145  }
146  }
147  void getValue_nopath(double& x0,double& y0,double& z0,double& x1,double& y1, double& z1)
148  {
149  x0 = (*bit_)->m_id.m_first.m_X;
150  y0 = (*bit_)->m_id.m_first.m_Y;
151  z0 = (*bit_)->m_id.m_first.m_Z;
152  x1 = (*bit_)->m_id.m_last.m_X;
153  y1 = (*bit_)->m_id.m_last.m_Y;
154  z1 = (*bit_)->m_id.m_last.m_Z;
155  }
156  void getValue_gap(double& x0,double& y0,double& z0,double& x1,double& y1, double& z1)
157  {
158  auto next = std::next(bit_);
159  x0 = (*bit_)->m_id.m_last.m_X;
160  y0 = (*bit_)->m_id.m_last.m_Y;
161  z0 = (*bit_)->m_id.m_last.m_Z;
162  x1 = (*next)->m_id.m_first.m_X;
163  y1 = (*next)->m_id.m_first.m_Y;
164  z1 = (*next)->m_id.m_first.m_Z;
165  }
166  void getValue_normal(double& x0,double& y0,double& z0,double& x1,double& y1, double& z1)
167  {
168  x0 = (*bit_)->m_path->getData()(1,idx_);
169  y0 = (*bit_)->m_path->getData()(2,idx_);
170  z0 = (*bit_)->m_path->getData()(3,idx_);
171  x1 = (*bit_)->m_path->getData()(1,idx_+1);
172  y1 = (*bit_)->m_path->getData()(2,idx_+1);
173  z1 = (*bit_)->m_path->getData()(3,idx_+1);
174  }
175  void getValue(double& x0,double& y0,double& z0,double& x1,double& y1, double& z1)
176  {
177  if((*bit_)->m_path==nullptr)
178  {
179  if(idx_==0)
180  {
182  }
183  else
184  {
186  }
187  }
188  else
189  {
190  if(idx_==(*bit_)->m_path->getData().nc()-1)
191  {
193  }
194  else
195  {
197  }
198 
199  }
200  }
201  };
202 
205 };
206 
207 }
208 }
209 }
A class which augments a vector of Border* with some sampling features.
Definition: bordersequence.h:28
bool sample(TArray1 sample_array, int i0, int i1, TArray2 &outx, TArray2 &outy, TArray2 &outz)
step through border sequence and sample the values along the borders
Definition: bordersequence.h:57
LineIterator beginLines()
Definition: bordersequence.h:203
double getLength() const
returns the total lenght of all contained borders
Definition: bordersequence.h:36
LineIterator endLines()
Definition: bordersequence.h:204
x0
Definition: adore_set_goal.py:25
y0
Definition: adore_set_goal.py:26
z0
Definition: adore_set_goal.py:27
y1
Definition: adore_set_pose.py:29
x1
Definition: adore_set_pose.py:28
z1
Definition: adore_set_pose.py:30
Definition: areaofeffectconverter.h:20
bool operator!=(const LineIterator &other) const
Definition: bordersequence.h:115
void getValue_nopath(double &x0, double &y0, double &z0, double &x1, double &y1, double &z1)
Definition: bordersequence.h:147
bool valid_
Definition: bordersequence.h:98
void getValue_gap(double &x0, double &y0, double &z0, double &x1, double &y1, double &z1)
Definition: bordersequence.h:156
void getValue(double &x0, double &y0, double &z0, double &x1, double &y1, double &z1)
Definition: bordersequence.h:175
void operator++(int)
Definition: bordersequence.h:120
static LineIterator begin(std::vector< Border * > *bs)
Definition: bordersequence.h:101
void getValue_normal(double &x0, double &y0, double &z0, double &x1, double &y1, double &z1)
Definition: bordersequence.h:166
static LineIterator end(std::vector< Border * > *bs)
Definition: bordersequence.h:106
LineIterator(std::vector< Border * >::iterator bit, int idx, bool valid=true)
Definition: bordersequence.h:99
std::vector< Border * >::iterator bit_
Definition: bordersequence.h:96