segment.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, <copyright holder> <email>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the <organization> nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY <copyright holder> <email> ''AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <copyright holder> <email> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
30 #include <limits>
31 
32 namespace tuw_graph
33 {
34  uint32_t Segment::static_id_ = 0;
35 
36  void Segment::cleanNeighbors(uint32_t _id)
37  {
38  for(uint32_t i = 0; i < predecessor_.size(); i++)
39  {
40  if(predecessor_[i] == _id)
41  {
42  predecessor_.erase(predecessor_.begin() + i);
43  }
44  }
45 
46  for(uint32_t i = 0; i < successor_.size(); i++)
47  {
48  if(successor_[i] == _id)
49  {
50  successor_.erase(successor_.begin() + i);
51  }
52  }
53  }
54 
56  {
57  if(id_ >= _id)
58  id_--;
59 
60  for(uint32_t i = 0; i < predecessor_.size(); i++)
61  {
62  if(predecessor_[i] >= _id)
63  {
64  predecessor_[i]--;
65  }
66  }
67 
68  for(uint32_t i = 0; i < successor_.size(); i++)
69  {
70  if(successor_[i] >= _id)
71  {
72  successor_[i]--;
73  }
74  }
75  }
76 
77  void Segment::addPredecessor(const uint32_t _predecessor)
78  {
79  predecessor_.push_back(_predecessor);
80  }
81  void Segment::addSuccessor(const uint32_t _successor)
82  {
83  successor_.push_back(_successor);
84  }
85  Segment::Segment(const std::vector<Eigen::Vector2d> &_points, const float _min_space) : predecessor_(), successor_(), optimizedStart_(false), optimizedEnd_(false)
86  {
87  if(_points.size() > 0)
88  {
89  start_ = _points.front();
90  end_ = _points.back();
91  length_ = _points.size();
92  min_space_ = _min_space;
93  wayPoints_ = _points;
94  }
95 
96  id_ = static_id_++;
97  }
98  Segment::Segment(const uint32_t _id, const std::vector<Eigen::Vector2d> &_points, const float _min_space) : predecessor_(), successor_(), optimizedStart_(false), optimizedEnd_(false)
99  {
100  if(_points.size() > 0)
101  {
102  start_ = _points.front();
103  end_ = _points.back();
104  length_ = _points.size();
105  min_space_ = _min_space;
106  wayPoints_ = _points;
107  }
108 
109  id_ = _id;
110  }
111  void Segment::setStart(const Eigen::Vector2d &_pt)
112  {
113  if(wayPoints_.size() == 0)
114  wayPoints_.emplace_back(_pt);
115  wayPoints_[0] = _pt;
116  start_ = _pt;
117  }
118  void Segment::setEnd(const Eigen::Vector2d &_pt)
119  {
120  while(wayPoints_.size() <= 1)
121  {
122  wayPoints_.emplace_back(_pt);
123  }
124  wayPoints_[wayPoints_.size() - 1] = _pt;
125  end_ = _pt;
126  }
127 
128  uint32_t Segment::getId() const
129  {
130  return id_;
131  }
132 
133  void Segment::setId(uint32_t _id)
134  {
135  id_ = _id;
136  }
137 
138  const Eigen::Vector2d &Segment::getEnd() const
139  {
140  return end_;
141  }
142 
143  const Eigen::Vector2d &Segment::getStart() const
144  {
145  return start_;
146  }
147 
148  const std::vector<uint32_t > &Segment::getPredecessors() const
149  {
150  return predecessor_;
151  }
152 
153  const std::vector<uint32_t > &Segment::getSuccessors() const
154  {
155  return successor_;
156  }
157 
158  bool Segment::containsPredecessor(const uint32_t _predecessor)
159  {
160  for(const auto & pred : predecessor_)
161  {
162  if(pred == _predecessor)
163  return true;
164  }
165 
166  return false;
167  }
168 
169 
170  bool Segment::containsSuccessor(const uint32_t _successor)
171  {
172  for(uint32_t i = 0; i < successor_.size(); i++)
173  {
174  if(successor_[i] == _successor)
175  return true;
176  }
177 
178  return false;
179  }
180 
181 
183  {
184  static_id_ = 0;
185  }
186 
187  std::vector< Eigen::Vector2d > Segment::getPath() const
188  {
189  return wayPoints_;
190  }
191 
192  void Segment::setPath(const std::vector< Eigen::Vector2d > &_points)
193  {
194  if(_points.size() > 0)
195  {
196  start_ = _points.front();
197  end_ = _points.back();
198  length_ = _points.size();
199  wayPoints_ = _points;
200  }
201  }
202 
204  {
205  return min_space_;
206  }
207 
208  void Segment::setMinPathSpace(const float _space)
209  {
210  min_space_ = _space;
211  }
212 
213  int Segment::getLength() const
214  {
215  return length_;
216  }
217 
219  {
220  return optimizedStart_;
221  }
222 
224  {
225  return optimizedEnd_;
226  }
227 }
std::vector< uint32_t > successor_
Definition: segment.h:177
bool optimizedStart_
Definition: segment.h:182
void addPredecessor(const uint32_t _predecessor)
adds a predecessor to the object
Definition: segment.cpp:77
uint32_t getId() const
returns the id
Definition: segment.cpp:128
Segment(const std::vector< Eigen::Vector2d > &_path, const float _min_space)
constructor
Definition: segment.cpp:85
static void resetId()
resets the id counter (which is used to generate uinique ids)
Definition: segment.cpp:182
void setPath(const std::vector< Eigen::Vector2d > &_path)
sets a new path of the robot
Definition: segment.cpp:192
void setEnd(const Eigen::Vector2d &_pt)
sets endpoint
Definition: segment.cpp:118
Eigen::Vector2d end_
Definition: segment.h:171
static uint32_t static_id_
Definition: segment.h:179
float getMinPathSpace() const
returns the minimum space in a segment
Definition: segment.cpp:203
const Eigen::Vector2d & getEnd() const
returns const ref to endpoint
Definition: segment.cpp:138
bool containsPredecessor(const uint32_t _predecessor)
checks if the segment has a predecessor with id _predecessor
Definition: segment.cpp:158
bool containsSuccessor(const uint32_t _successor)
checks if the segment has a predecessor with id _successor
Definition: segment.cpp:170
void decreaseNeighborIdAbove(uint32_t _id)
decreases the id and all neighbor ids above or equal _id by one (needed to safely remove entities) ...
Definition: segment.cpp:55
bool & getOptEnd()
returns a reference to opt end used to save if a segment was allready optimized
Definition: segment.cpp:223
void setMinPathSpace(const float _space)
sets the minimum space of a segment
Definition: segment.cpp:208
void cleanNeighbors(uint32_t _id)
removing all predecessors or successors with id
Definition: segment.cpp:36
void setId(const uint32_t _id)
set the id
Definition: segment.cpp:133
void addSuccessor(const uint32_t _successor)
adds a successor to the object
Definition: segment.cpp:81
void setStart(const Eigen::Vector2d &_pt)
sets the startpoint
Definition: segment.cpp:111
uint32_t id_
Definition: segment.h:180
std::vector< uint32_t > predecessor_
Definition: segment.h:176
std::vector< Eigen::Vector2d > getPath() const
returns the path
Definition: segment.cpp:187
int getLength() const
returns the length of the path
Definition: segment.cpp:213
const Eigen::Vector2d & getStart() const
returns const ref to startpoint
Definition: segment.cpp:143
const std::vector< uint32_t > & getSuccessors() const
returns a const reference to the successor
Definition: segment.cpp:153
std::vector< Eigen::Vector2d > wayPoints_
Definition: segment.h:174
bool & getOptStart()
returns a reference to opt start used to save if a segment was allready optimized ...
Definition: segment.cpp:218
Eigen::Vector2d start_
Definition: segment.h:171
const std::vector< uint32_t > & getPredecessors() const
returns a const reference to the predecessors
Definition: segment.cpp:148


tuw_voronoi_graph
Author(s): Benjamin Binder
autogenerated on Mon Jun 10 2019 15:42:44