octomap_python.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Aldebaran Robotics
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /* Boost Python module that can convert a string to an Octomap
18 */
19 
20 #include <boost/python.hpp>
21 #include <boost/python/stl_iterator.hpp>
22 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
23 
25 
26 template<class T>
27 boost::python::list std_vector_to_py_list(const std::vector<T>& vec)
28 {
29  typename std::vector<T>::const_iterator iter;
30  boost::python::list res;
31  for (iter = vec.begin(); iter != vec.end(); ++iter) {
32  res.append(*iter);
33  }
34  return res;
35 }
36 
38 boost::python::tuple octomap_str_to_tuple(const std::string &str_msg)
39 {
40  std::stringstream ss;
41  ss << str_msg;
42  ss.seekg(0);
43  octomap::OcTree* octree = static_cast<octomap::OcTree*>(octomap::OcTree::read(ss));
44  if (!octree) {
45  std::cout << "Cast failed.";
46  return boost::python::make_tuple();
47  }
48  octomap_msgs::Octomap msg;
49  bool res = octomap_msgs::binaryMapToMsg(*octree, msg);
50  delete(octree);
51  return boost::python::make_tuple(msg.binary, msg.id, msg.resolution, std_vector_to_py_list(msg.data));
52 }
53 
54 BOOST_PYTHON_MODULE(octomap_python)
55 {
56  boost::python::def("octomap_str_to_tuple", octomap_str_to_tuple);
57 }
static AbstractOcTree * read(const std::string &filename)
boost::python::tuple octomap_str_to_tuple(const std::string &str_msg)
static bool binaryMapToMsg(const OctomapT &octomap, Octomap &msg)
BOOST_PYTHON_MODULE(octomap_python)
boost::python::list std_vector_to_py_list(const std::vector< T > &vec)


naoqi_sensors_py
Author(s): Séverin Lemaignan, Vincent Rabaud, Karsten Knese, Jack O'Quin, Ken Tossell, Patrick Beeson, Nate Koenig, Andrew Howard, Damien Douxchamps, Dan Dennedy, Daniel Maier
autogenerated on Thu Jul 16 2020 03:18:33