| 1 | #!/bin/sh |
| 2 | # autopkgtest check |
| 3 | # (C) 2020 Leopold Palomo-Avellaneda |
| 4 | |
| 5 | set -e |
| 6 | |
| 7 | WORKDIR=$(mktemp -d) |
| 8 | #trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM |
| 9 | cd $WORKDIR |
| 10 | cat <<EOF > exampleEDTO3D.cpp |
| 11 | /** |
| 12 | * dynamicEDT3D: |
| 13 | * A library for incrementally updatable Euclidean distance transforms in 3D. |
| 14 | * @author C. Sprunk, B. Lau, W. Burgard, University of Freiburg, Copyright (C) 2011. |
| 15 | * @see http://octomap.sourceforge.net/ |
| 16 | * License: New BSD License |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | * Copyright (c) 2011-2012, C. Sprunk, B. Lau, W. Burgard, University of Freiburg |
| 21 | * All rights reserved. |
| 22 | * |
| 23 | * Redistribution and use in source and binary forms, with or without |
| 24 | * modification, are permitted provided that the following conditions are met: |
| 25 | * |
| 26 | * * Redistributions of source code must retain the above copyright |
| 27 | * notice, this list of conditions and the following disclaimer. |
| 28 | * * Redistributions in binary form must reproduce the above copyright |
| 29 | * notice, this list of conditions and the following disclaimer in the |
| 30 | * documentation and/or other materials provided with the distribution. |
| 31 | * * Neither the name of the University of Freiburg nor the names of its |
| 32 | * contributors may be used to endorse or promote products derived from |
| 33 | * this software without specific prior written permission. |
| 34 | * |
| 35 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 36 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 38 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 39 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 40 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 41 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 42 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 43 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 44 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 45 | * POSSIBILITY OF SUCH DAMAGE. |
| 46 | */ |
| 47 | |
| 48 | #include <dynamicEDT3D/dynamicEDT3D.h> |
| 49 | |
| 50 | #include <iostream> |
| 51 | #include <stdlib.h> |
| 52 | |
| 53 | int main( int , char** ) { |
| 54 | |
| 55 | //we build a sample map |
| 56 | int sizeX, sizeY, sizeZ; |
| 57 | sizeX=100; |
| 58 | sizeY=100; |
| 59 | sizeZ=100; |
| 60 | |
| 61 | bool*** map; |
| 62 | map = new bool**[sizeX]; |
| 63 | for(int x=0; x<sizeX; x++){ |
| 64 | map[x] = new bool*[sizeY]; |
| 65 | for(int y=0; y<sizeY; y++){ |
| 66 | map[x][y] = new bool[sizeZ]; |
| 67 | for(int z=0; z<sizeZ; z++){ |
| 68 | if(x<2 || x > sizeX-3 || y < 2 || y > sizeY-3 || z<2 || z > sizeZ-3) |
| 69 | map[x][y][z] = 1; |
| 70 | else |
| 71 | map[x][y][z] = 0; |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | map[51][45][67] = 1; |
| 77 | map[50][50][68] = 1; |
| 78 | |
| 79 | // create the EDT object and initialize it with the map |
| 80 | int maxDistInCells = 20; |
| 81 | DynamicEDT3D distmap(maxDistInCells*maxDistInCells); |
| 82 | distmap.initializeMap(sizeX, sizeY, sizeZ, map); |
| 83 | |
| 84 | //compute the distance map |
| 85 | distmap.update(); |
| 86 | |
| 87 | // now perform some updates with random obstacles |
| 88 | int numPoints = 20; |
| 89 | for (int frame=1; frame<=10; frame++) { |
| 90 | std::cout<<"\n\nthis is frame #"<<frame<<std::endl; |
| 91 | std::vector<IntPoint3D> newObstacles; |
| 92 | for (int i=0; i<numPoints; i++) { |
| 93 | double x = 2+rand()/(double)RAND_MAX*(sizeX-4); |
| 94 | double y = 2+rand()/(double)RAND_MAX*(sizeY-4); |
| 95 | double z = 2+rand()/(double)RAND_MAX*(sizeZ-4); |
| 96 | newObstacles.push_back(IntPoint3D(x,y,z)); |
| 97 | } |
| 98 | |
| 99 | // register the new obstacles (old ones will be removed) |
| 100 | distmap.exchangeObstacles(newObstacles); |
| 101 | |
| 102 | //update the distance map |
| 103 | distmap.update(); |
| 104 | |
| 105 | //retrieve distance at a point |
| 106 | float dist = distmap.getDistance(30,67,33); |
| 107 | int distSquared = distmap.getSQCellDistance(30,67,33); |
| 108 | std::cout<<"distance at 30,67,33: "<< dist << " squared: "<< distSquared << std::endl; |
| 109 | if(distSquared == maxDistInCells*maxDistInCells) |
| 110 | std::cout<<"we hit a cell with d = dmax, distance value is clamped."<<std::endl; |
| 111 | |
| 112 | //retrieve closest occupied cell at a point |
| 113 | IntPoint3D closest = distmap.getClosestObstacle(30,67,33); |
| 114 | if(closest.x == DynamicEDT3D::invalidObstData) |
| 115 | std::cout<<"we hit a cell with d = dmax, no information about closest occupied cell."<<std::endl; |
| 116 | else |
| 117 | std::cout<<"closest occupied cell to 30,67,33: "<< closest.x<<","<<closest.y<<","<<closest.z<<std::endl; |
| 118 | |
| 119 | } |
| 120 | |
| 121 | |
| 122 | std::cout<<"\n\nthis is the last frame"<<std::endl; |
| 123 | |
| 124 | // now remove all random obstacles again. |
| 125 | std::vector<IntPoint3D> empty; |
| 126 | distmap.exchangeObstacles(empty); |
| 127 | distmap.update(); |
| 128 | |
| 129 | |
| 130 | //retrieve distance at a point |
| 131 | float dist = distmap.getDistance(30,67,33); |
| 132 | int distSquared = distmap.getSQCellDistance(30,67,33); |
| 133 | std::cout<<"distance at 30,67,33: "<< dist << " squared: "<< distSquared << std::endl; |
| 134 | if(distSquared == maxDistInCells*maxDistInCells) |
| 135 | std::cout<<"we hit a cell with d = dmax, distance value is clamped."<<std::endl; |
| 136 | |
| 137 | //retrieve closest occupied cell at a point |
| 138 | IntPoint3D closest = distmap.getClosestObstacle(30,67,33); |
| 139 | if(closest.x == DynamicEDT3D::invalidObstData) |
| 140 | std::cout<<"we hit a cell with d = dmax, no information about closest occupied cell."<<std::endl; |
| 141 | else |
| 142 | std::cout<<"closest occupied cell to 30,67,33: "<< closest.x<<","<<closest.y<<","<<closest.z<<std::endl; |
| 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | EOF |
| 148 | cat <<EOF > CMakeLists.txt |
| 149 | cmake_minimum_required(VERSION 3.10) |
| 150 | PROJECT( demo2 ) |
| 151 | |
| 152 | find_package(dynamicEDT3D REQUIRED) |
| 153 | |
| 154 | include_directories(\${OCTOMAP_INCLUDE_DIRS}) |
| 155 | message(STATUS "Found dynamicEDT3D version: " \${dynamicEDT3D_VERSION}) |
| 156 | message(STATUS "dynamicEDT3D libraries: \${DYNAMICEDT3D_LIBRARIES}") |
| 157 | |
| 158 | add_executable(demo2 exampleEDTO3D.cpp) |
| 159 | target_link_libraries (demo2 \${DYNAMICEDT3D_LIBRARIES}) |
| 160 | EOF |
| 161 | |
| 162 | cmake . |
| 163 | make |
| 164 | [ -x demo2 ] |
| 165 | echo "build: OK" |
| 166 | [ -x demo2 ] |
| 167 | ./demo2 && echo run:OK || echo run:Failed |
| 168 | |
| 169 |