octomap_python.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2014 Aldebaran Robotics
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 /* Boost Python module that can convert a string to an Octomap
00018 */
00019 
00020 #include <boost/python.hpp>
00021 #include <boost/python/stl_iterator.hpp>
00022 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
00023 
00024 #include <octomap_msgs/conversions.h>
00025 
00026 template<class T>
00027 boost::python::list std_vector_to_py_list(const std::vector<T>& vec)
00028 {
00029   typename std::vector<T>::const_iterator iter;
00030   boost::python::list res;
00031   for (iter = vec.begin(); iter != vec.end(); ++iter) {
00032     res.append(*iter);
00033   }
00034   return res;
00035 }
00036 
00038 boost::python::tuple octomap_str_to_tuple(const std::string &str_msg)
00039 {
00040   std::stringstream ss;
00041   ss << str_msg;
00042   ss.seekg(0);
00043   octomap::OcTree* octree = dynamic_cast<octomap::OcTree*>(octomap::OcTree::read(ss));
00044 
00045   octomap_msgs::Octomap msg;
00046   bool res = octomap_msgs::fullMapToMsg(*octree, msg);
00047 
00048   return boost::python::make_tuple(msg.binary, msg.id, msg.resolution, std_vector_to_py_list(msg.data));
00049 }
00050 
00051 BOOST_PYTHON_MODULE(octomap_python)
00052 {
00053   boost::python::def("octomap_str_to_tuple", octomap_str_to_tuple);
00054 }


naoqi_sensors
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 Fri Jul 3 2015 15:25:16