MIRA
GridMapWrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 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  * Redistribution and modification of this code is strictly prohibited.
9  *
10  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
11  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
12  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
13  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
16  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
18  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
19  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
20  */
21 
29 #include <python/BoostPythonWrapper.h>
30 
31 #include <maps/GridMap.h>
32 #include <python/UnitWrapper.h> // for MIRA_PYTHONCONNECTOR_TYPE_FOOTER
33 #include <python/ImageWrapper.h>
34 
35 namespace mira { namespace python {
37 
38 template<typename Scalar, int Channels = 1,
42 
43  static Point2f map2world(const T &map, const Point2i &p)
44  {
45  return map.map2world(p);
46  }
47 
48  static Point2f map2worldf(const T &map, const Point2f &p)
49  {
50  return map.map2world(p);
51  }
52 
53  static Scalar get(const T &map, int x, int y)
54  {
55  return map(x, y);
56  }
57 
58  static void set(T &map, int x, int y, Scalar value)
59  {
60  map(x, y) = value;
61  }
62 
63  static boost::python::object getMat(const T &map)
64  {
65  return ImageAccessorBase<ImgType>::getMat(map);
66  }
67 #if BOOST_HAS_NUMPY_API
68  static void setMat(T &map, const boost::python::numpy::ndarray& arr)
69 #else
70  static void setMat(T &map, const boost::python::numeric::array& arr)
71 #endif
72  {
73  ImageAccessor<ImgType>::setMat(map, arr);
74  }
75 };
76 
77 template<typename Scalar, int Channels = 1,
79 void registerGridMapType(const char* name)
80 {
81  using namespace boost::python;
82  class_<T> (name, init<float>())
83  .def(init<Size2i, float, Point2i>())
84  .def("getCellSize", &T::getCellSize)
85  .def("width", &T::width)
86  .def("height", &T::height)
87  .def("getOffset", &T::getOffset)
88  .def("getWorldOffset", &T::getWorldOffset)
89  .def("world2map", &T::world2mapf)
90  .def("map2world", &GridMapAccessor<Scalar>::map2world)
91  .def("map2worldf", &GridMapAccessor<Scalar>::map2worldf)
92  .def("get", &GridMapAccessor<Scalar>::get)
93  .def("set", &GridMapAccessor<Scalar>::set)
94  .def("getMat", &GridMapAccessor<Scalar>::getMat)
95  .def("setMat", &GridMapAccessor<Scalar>::setMat)
96  MIRA_PYTHONCONNECTOR_TYPE_FOOTER(T)
97  ;
98 }
99 
101 
102 }}
static boost::python::object getMat(const T &map)
Definition: GridMapWrapper.h:63
Definition: GridMap.h:67
Img< Scalar, Channels > ImgType
Definition: GridMapWrapper.h:41
Definition: GridMapWrapper.h:40
Description.
static Point2f map2world(const T &map, const Point2i &p)
Definition: GridMapWrapper.h:43
static void setMat(T &map, const boost::python::numeric::array &arr)
Definition: GridMapWrapper.h:70
void registerGridMapType(const char *name)
Definition: GridMapWrapper.h:79
static Point2f map2worldf(const T &map, const Point2f &p)
Definition: GridMapWrapper.h:48