crossing.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 
33 namespace tuw_graph
34 {
35  Crossing::Crossing(const std::vector< Eigen::Vector2d > &_segment_points) : segments_start_(), segments_end_()
36  {
37  int min_x = __INT_MAX__;
38  int max_x = 0;
39  int min_y = __INT_MAX__;
40  int max_y = 0;
41 
42  for(auto it = _segment_points.begin(); it != _segment_points.end(); ++it)
43  {
44  if((*it)[0] > max_x)
45  max_x = (*it)[0];
46 
47  if((*it)[0] < min_x)
48  min_x = (*it)[0];
49 
50  if((*it)[1] > max_y)
51  max_y = (*it)[1];
52 
53  if((*it)[1] < min_y)
54  min_y = (*it)[1];
55  }
56 
57  surroundingPoints_ = _segment_points;
58  center_[0] = ((float)(max_x + min_x)) / 2.0;
59  center_[1] = ((float)(max_y + min_y)) / 2.0;
60 
61  }
62 
64  {
65  for(const Eigen::Vector2d &srPoint : surroundingPoints_)
66  {
67  if(srPoint[0] == _seg.getStart()[0] && srPoint[1] == _seg.getStart()[1])
68  {
69  for(uint32_t &s_idx : segments_start_)
70  {
71  _seg.addPredecessor(s_idx);
72  (*segmentReference_)[s_idx].addPredecessor(_seg.getId());
73  }
74 
75  for(uint32_t &s_idx : segments_end_)
76  {
77  _seg.addPredecessor(s_idx);
78  (*segmentReference_)[s_idx].addSuccessor(_seg.getId());
79  }
80 
81  std::vector<Eigen::Vector2d> p = _seg.getPath();
82  p.insert(p.begin(), center_);
83  _seg.setPath(p);
84  segments_start_.push_back(_seg.getId());
85  return true;
86  }
87 
88  if(srPoint[0] == _seg.getEnd()[0] && srPoint[1] == _seg.getEnd()[1])
89  {
90  for(uint32_t &s_idx : segments_start_)
91  {
92  _seg.addSuccessor(s_idx);
93  (*segmentReference_)[s_idx].addPredecessor(_seg.getId());
94 
95  }
96 
97  for(uint32_t &s_idx : segments_end_)
98  {
99  _seg.addSuccessor(s_idx);
100  (*segmentReference_)[s_idx].addSuccessor(_seg.getId());
101  }
102 
103  std::vector<Eigen::Vector2d> p = _seg.getPath();
104  p.push_back(center_);
105  _seg.setPath(p);
106  segments_end_.push_back(_seg.getId());
107  return true;
108  }
109  }
110 
111  return false;
112  }
113 
114  Eigen::Vector2d Crossing::getCenter() const
115  {
116  return center_;
117  }
118 
119  void Crossing::setSegmentReference(const std::shared_ptr< std::vector< Segment > > &segs)
120  {
121  segmentReference_ = segs;
122  }
123 
124 }
Eigen::Vector2d center_
Definition: crossing.h:66
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
void setPath(const std::vector< Eigen::Vector2d > &_path)
sets a new path of the robot
Definition: segment.cpp:192
Crossing(const std::vector< Eigen::Vector2d > &_segment_points)
constructor
Definition: crossing.cpp:35
const Eigen::Vector2d & getEnd() const
returns const ref to endpoint
Definition: segment.cpp:138
Eigen::Vector2d getCenter() const
returns the center of the crossing (average of all pts)
Definition: crossing.cpp:114
void setSegmentReference(const std::shared_ptr< std::vector< Segment >> &segs)
saves the reference to the vector containing all segments to have access to them to alter other segme...
Definition: crossing.cpp:119
std::shared_ptr< std::vector< Segment > > segmentReference_
Definition: crossing.h:67
void addSuccessor(const uint32_t _successor)
adds a successor to the object
Definition: segment.cpp:81
std::vector< uint32_t > segments_end_
Definition: crossing.h:65
bool tryAddSegment(Segment &_seg)
tries to add the segment to the crossing and adds the given segment to each segments neighbors in the...
Definition: crossing.cpp:63
std::vector< Eigen::Vector2d > getPath() const
returns the path
Definition: segment.cpp:187
std::vector< uint32_t > segments_start_
Definition: crossing.h:64
const Eigen::Vector2d & getStart() const
returns const ref to startpoint
Definition: segment.cpp:143
std::vector< Eigen::Vector2d > surroundingPoints_
Definition: crossing.h:63


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