Debian Codegraph @

dynamicEDT3D/src/examples/exampleEDT3D.cpp

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