MIRA
Footprint.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_FOOTPRINT_H_
48 #define _MIRA_FOOTPRINT_H_
49 
50 #include <serialization/adapters/std/vector>
51 
52 #include <geometry/Line.h>
53 #include <geometry/Polygon.h>
54 #include <geometry/Rect.h>
55 
56 namespace mira {
57 
59 
65 class Footprint : public std::vector<Polygon2f>
66 {
67  typedef std::vector<Polygon2f> Base;
68 public:
69 
70  template<typename Reflector>
71  void reflect(Reflector& r)
72  {
73  MIRA_REFLECT_BASE(r, Base);
74  }
75 
76 public:
77 
79  float getInnerRadius() const {
80 
81  float rMin = std::numeric_limits<float>::infinity();
82  foreach(const Polygon2f& polygon,*this)
83  {
84  for(std::size_t i=1; i<polygon.size(); ++i)
85  {
86  Line2f l(polygon[i-1], polygon[i]);
87  float d = boost::geometry::distance(Point2f(0,0), l);
88  if(d<rMin)
89  rMin = d;
90  }
91  }
92  if(rMin==std::numeric_limits<float>::infinity())
93  return 0.0f;
94  return rMin;
95  }
96 
98  float getOuterRadius() const {
99 
100  float rSq = 0.0f;
101  foreach(const Polygon2f& polygon,*this)
102  {
103  foreach(const Point2f& p, polygon)
104  {
105  float d = p.x()*p.x() + p.y()*p.y();
106  if(d>rSq)
107  rSq = d;
108  }
109  }
110  return std::sqrt(rSq);
111  }
112 
116  auto boundingBox = Rect2f::invalid();
117  foreach (const Polygon2f& polygon, *this) {
118  foreach (const Point2f& p, polygon) {
119  boundingBox |= p;
120  }
121  }
122  return boundingBox;
123  }
124 
127  float getWidth() const {
128  const auto boundingBox = getBoundingBox();
129  if(boundingBox.isValid())
130  // this is no mistake
131  return boundingBox.height();
132 
133  return 0.0f;
134  }
135 
136 
137 };
138 
140 
141 } // namespace
142 
143 #endif
Rect2f getBoundingBox() const
Returns the bounding box of the footprint Returns an invalid rect if the footprint is empty...
Definition: Footprint.h:115
float getOuterRadius() const
Returns the radius of the escribed circle (excircle) of the footprint.
Definition: Footprint.h:98
float getInnerRadius() const
Returns the radius of the inscribed circle (incircle) of the footprint.
Definition: Footprint.h:79
#define MIRA_REFLECT_BASE(reflector, BaseClass)
float getWidth() const
Returns the width (w.r.t.
Definition: Footprint.h:127
void reflect(Reflector &r)
Definition: Footprint.h:71
static Rect< float, 2 > invalid()
Point< float, 2 > Point2f
boost::geometry::model::ring< Point2f > Polygon2f
Represents the footprint of a rigid model that is the 2D projection of the 3D model onto the xy-plane...
Definition: Footprint.h:65