exampleEDTOctomap.cpp
Go to the documentation of this file.
00001 
00009 /*
00010  * Copyright (c) 2011-2012, C. Sprunk, B. Lau, W. Burgard, University of Freiburg
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  *     * Redistributions of source code must retain the above copyright
00017  *       notice, this list of conditions and the following disclaimer.
00018  *     * Redistributions in binary form must reproduce the above copyright
00019  *       notice, this list of conditions and the following disclaimer in the
00020  *       documentation and/or other materials provided with the distribution.
00021  *     * Neither the name of the University of Freiburg nor the names of its
00022  *       contributors may be used to endorse or promote products derived from
00023  *       this software without specific prior written permission.
00024  *
00025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00028  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00030  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00031  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00033  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00034  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  * POSSIBILITY OF SUCH DAMAGE.
00036  */
00037 
00038 #include <dynamicEDT3D/dynamicEDTOctomap.h>
00039 
00040 #include <iostream>
00041 
00042 
00043 
00044 int main( int argc, char *argv[] ) {
00045   if(argc<=1){
00046     std::cout<<"usage: "<<argv[0]<<" <octoMap.bt>"<<std::endl;
00047     exit(0);
00048   }
00049 
00050   octomap::OcTree *tree = NULL;
00051   tree = new octomap::OcTree(0.05);
00052 
00053   //read in octotree
00054   tree->readBinary(argv[1]);
00055 
00056   std::cout<<"read in tree, "<<tree->getNumLeafNodes()<<" leaves "<<std::endl;
00057 
00058   double x,y,z;
00059   tree->getMetricMin(x,y,z);
00060   octomap::point3d min(x,y,z);
00061   //std::cout<<"Metric min: "<<x<<","<<y<<","<<z<<std::endl;
00062   tree->getMetricMax(x,y,z);
00063   octomap::point3d max(x,y,z);
00064   //std::cout<<"Metric max: "<<x<<","<<y<<","<<z<<std::endl;
00065 
00066   bool unknownAsOccupied = true;
00067   unknownAsOccupied = false;
00068   float maxDist = 1.0;
00069   //- the first argument ist the max distance at which distance computations are clamped
00070   //- the second argument is the octomap
00071   //- arguments 3 and 4 can be used to restrict the distance map to a subarea
00072   //- argument 5 defines whether unknown space is treated as occupied or free
00073   //The constructor copies data but does not yet compute the distance map
00074   DynamicEDTOctomap distmap(maxDist, tree, min, max, unknownAsOccupied);
00075 
00076   //This computes the distance map
00077   distmap.update(); 
00078 
00079   //This is how you can query the map
00080   octomap::point3d p(5.0,5.0,0.6);
00081   //As we don't know what the dimension of the loaded map are, we modify this point
00082   p.x() = min.x() + 0.3 * (max.x() - min.x());
00083   p.y() = min.y() + 0.6 * (max.y() - min.y());
00084   p.z() = min.z() + 0.5 * (max.z() - min.z());
00085 
00086   octomap::point3d closestObst;
00087   float distance;
00088 
00089   distmap.getDistanceAndClosestObstacle(p, distance, closestObst);
00090 
00091   std::cout<<"\n\ndistance at point "<<p.x()<<","<<p.y()<<","<<p.z()<<" is "<<distance<<std::endl;
00092   if(distance < distmap.getMaxDist())
00093     std::cout<<"closest obstacle to "<<p.x()<<","<<p.y()<<","<<p.z()<<" is at "<<closestObst.x()<<","<<closestObst.y()<<","<<closestObst.z()<<std::endl;
00094 
00095   //if you modify the octree via tree->insertScan() or tree->updateNode()
00096   //just call distmap.update() again to adapt the distance map to the changes made
00097 
00098   delete tree;
00099 
00100   return 0;
00101 }


dynamicEDT3D
Author(s): Christoph Sprunk
autogenerated on Thu Feb 11 2016 23:51:18