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 
51 #include <serialization/adapters/std/vector>
52 
53 #include <geometry/Point.h>
54 #include <geometry/Line.h>
55 #include <geometry/Polygon.h>
56 #include <geometry/Rect.h>
57 
58 #include <boost/geometry/strategies/strategies.hpp>
59 #include <boost/geometry/algorithms/distance.hpp>
60 
61 namespace mira {
62 
64 
70 class Footprint : public std::vector<Polygon2f>
71 {
72  typedef std::vector<Polygon2f> Base;
73 public:
74 
75  template<typename Reflector>
76  void reflect(Reflector& r)
77  {
78  MIRA_REFLECT_BASE(r, Base);
79  }
80 
81 public:
82 
84  float getInnerRadius() const {
85 
86  float rMin = std::numeric_limits<float>::infinity();
87  foreach(const Polygon2f& polygon,*this)
88  {
89  for(std::size_t i=1; i<polygon.size(); ++i)
90  {
91  Line2f l(polygon[i-1], polygon[i]);
92  float d = boost::geometry::distance(Point2f(0,0), l);
93  if(d<rMin)
94  rMin = d;
95  }
96  }
97  if(rMin==std::numeric_limits<float>::infinity())
98  return 0.0f;
99  return rMin;
100  }
101 
103  float getOuterRadius() const {
104 
105  float rSq = 0.0f;
106  foreach(const Polygon2f& polygon,*this)
107  {
108  foreach(const Point2f& p, polygon)
109  {
110  float d = p.x()*p.x() + p.y()*p.y();
111  if(d>rSq)
112  rSq = d;
113  }
114  }
115  return std::sqrt(rSq);
116  }
117 
121  auto boundingBox = Rect2f::invalid();
122  foreach (const Polygon2f& polygon, *this) {
123  foreach (const Point2f& p, polygon) {
124  boundingBox |= p;
125  }
126  }
127  return boundingBox;
128  }
129 
132  float getWidth() const {
133  const auto boundingBox = getBoundingBox();
134  if(boundingBox.isValid())
135  // this is no mistake
136  return boundingBox.height();
137 
138  return 0.0f;
139  }
140 
141 
142 };
143 
145 
146 } // namespace
147 
148 #endif
Rect2f getBoundingBox() const
Returns the bounding box of the footprint Returns an invalid rect if the footprint is empty...
Definition: Footprint.h:120
float getOuterRadius() const
Returns the radius of the escribed circle (excircle) of the footprint.
Definition: Footprint.h:103
float getInnerRadius() const
Returns the radius of the inscribed circle (incircle) of the footprint.
Definition: Footprint.h:84
#define MIRA_REFLECT_BASE(reflector, BaseClass)
float getWidth() const
Returns the width (w.r.t.
Definition: Footprint.h:132
void reflect(Reflector &r)
Definition: Footprint.h:76
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:70