octomap 1.5.0
include/octomap/MapNode.hxx
Go to the documentation of this file.
00001 // $Id: MapNode.hxx 402 2012-08-06 13:39:42Z ahornung $
00002 
00011 /*
00012  * Copyright (c) 2009, K. M. Wurm, A. Hornung, University of Freiburg
00013  * All rights reserved.
00014  *
00015  * Redistribution and use in source and binary forms, with or without
00016  * modification, are permitted provided that the following conditions are met:
00017  *
00018  *     * Redistributions of source code must retain the above copyright
00019  *       notice, this list of conditions and the following disclaimer.
00020  *     * Redistributions in binary form must reproduce the above copyright
00021  *       notice, this list of conditions and the following disclaimer in the
00022  *       documentation and/or other materials provided with the distribution.
00023  *     * Neither the name of the University of Freiburg nor the names of its
00024  *       contributors may be used to endorse or promote products derived from
00025  *       this software without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 namespace octomap {
00041 
00042   template <class TREETYPE>
00043   MapNode<TREETYPE>::MapNode(): node_map(0) {
00044   }
00045 
00046   template <class TREETYPE>
00047   MapNode<TREETYPE>::MapNode(TREETYPE* node_map, pose6d origin) {
00048     this->node_map = node_map;
00049     this->origin = origin;
00050   }
00051 
00052   template <class TREETYPE>
00053   MapNode<TREETYPE>::MapNode(const Pointcloud& cloud, pose6d origin): node_map(0) {
00054   }
00055 
00056   template <class TREETYPE>
00057   MapNode<TREETYPE>::MapNode(std::string filename, pose6d origin): node_map(0){
00058     readMap(filename);
00059     this->origin = origin;
00060     id = filename;
00061   }
00062 
00063   template <class TREETYPE>
00064   MapNode<TREETYPE>::~MapNode() {
00065     clear();
00066   }
00067     
00068   template <class TREETYPE>
00069   void MapNode<TREETYPE>::updateMap(const Pointcloud& cloud, point3d sensor_origin) {
00070   }
00071 
00072   template <class TREETYPE>
00073   Pointcloud MapNode<TREETYPE>::generatePointcloud() {
00074     Pointcloud pc;
00075     point3d_list occs;
00076     node_map->getOccupied(occs);
00077     for(point3d_list::iterator it = occs.begin(); it != occs.end(); ++it){
00078       pc.push_back(*it);
00079     }
00080     return pc;
00081   }
00082 
00083   template <class TREETYPE>
00084   void MapNode<TREETYPE>::clear(){
00085     if(node_map != 0){
00086       delete node_map;
00087       node_map = 0;
00088       id = "";
00089       origin = pose6d(0.0,0.0,0.0,0.0,0.0,0.0);
00090     }
00091   }
00092 
00093   template <class TREETYPE>
00094   bool MapNode<TREETYPE>::readMap(std::string filename){
00095     if(node_map != 0)
00096       delete node_map;
00097 
00098     node_map = new TREETYPE(0.05);
00099     return node_map->readBinary(filename);
00100   }
00101 
00102   template <class TREETYPE>
00103   bool MapNode<TREETYPE>::writeMap(std::string filename){
00104     return node_map->writeBinary(filename);
00105   }
00106 
00107 } // namespace