Directory: | ./ |
---|---|
File: | test/octree.cpp |
Date: | 2025-05-02 10:16:21 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 93 | 130 | 71.5% |
Branches: | 207 | 518 | 40.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Software License Agreement (BSD License) | ||
3 | * | ||
4 | * Copyright (c) 2019, CNRS-LAAS. | ||
5 | * Copyright (c) 2023, INRIA. | ||
6 | * All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * * Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * * Redistributions in binary form must reproduce the above | ||
15 | * copyright notice, this list of conditions and the following | ||
16 | * disclaimer in the documentation and/or other materials provided | ||
17 | * with the distribution. | ||
18 | * * Neither the name of Willow Garage, Inc. nor the names of its | ||
19 | * contributors may be used to endorse or promote products derived | ||
20 | * from this software without specific prior written permission. | ||
21 | * | ||
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
25 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
26 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
28 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
29 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
30 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
32 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
33 | * POSSIBILITY OF SUCH DAMAGE. | ||
34 | */ | ||
35 | |||
36 | /** \author Florent Lamiraux <florent@laas.fr> */ | ||
37 | |||
38 | #define BOOST_TEST_MODULE COAL_OCTREE | ||
39 | #include <fstream> | ||
40 | #include <boost/test/included/unit_test.hpp> | ||
41 | #include <boost/filesystem.hpp> | ||
42 | |||
43 | #include "coal/BVH/BVH_model.h" | ||
44 | #include "coal/collision.h" | ||
45 | #include "coal/distance.h" | ||
46 | #include "coal/hfield.h" | ||
47 | #include "coal/shape/geometric_shapes.h" | ||
48 | #include "coal/shape/geometric_shapes_utility.h" | ||
49 | #include "coal/internal/BV_splitter.h" | ||
50 | |||
51 | #include "utility.h" | ||
52 | #include "fcl_resources/config.h" | ||
53 | |||
54 | namespace utf = boost::unit_test::framework; | ||
55 | |||
56 | using namespace coal; | ||
57 | |||
58 | 3 | void makeMesh(const std::vector<Vec3s>& vertices, | |
59 | const std::vector<Triangle32>& triangles, | ||
60 | BVHModel<OBBRSS>& model) { | ||
61 | 3 | coal::SplitMethodType split_method(coal::SPLIT_METHOD_MEAN); | |
62 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | model.bv_splitter.reset(new BVSplitter<OBBRSS>(split_method)); |
63 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | model.bv_splitter.reset(new BVSplitter<OBBRSS>(split_method)); |
64 | |||
65 | 3 | model.beginModel(); | |
66 | 3 | model.addSubModel(vertices, triangles); | |
67 | 3 | model.endModel(); | |
68 | 3 | } | |
69 | |||
70 | ✗ | coal::OcTree makeOctree(const BVHModel<OBBRSS>& mesh, | |
71 | const Scalar& resolution) { | ||
72 | ✗ | Vec3s m(mesh.aabb_local.min_); | |
73 | ✗ | Vec3s M(mesh.aabb_local.max_); | |
74 | ✗ | coal::Box box(resolution, resolution, resolution); | |
75 | ✗ | CollisionRequest request(coal::CONTACT | coal::DISTANCE_LOWER_BOUND, 1); | |
76 | ✗ | CollisionResult result; | |
77 | ✗ | Transform3s tfBox; | |
78 | ✗ | octomap::OcTreePtr_t octree(new octomap::OcTree(resolution)); | |
79 | |||
80 | ✗ | for (Scalar x = resolution * floor(m[0] / resolution); x <= M[0]; | |
81 | ✗ | x += resolution) { | |
82 | ✗ | for (Scalar y = resolution * floor(m[1] / resolution); y <= M[1]; | |
83 | ✗ | y += resolution) { | |
84 | ✗ | for (Scalar z = resolution * floor(m[2] / resolution); z <= M[2]; | |
85 | ✗ | z += resolution) { | |
86 | ✗ | const Scalar half = Scalar(0.5); | |
87 | ✗ | Vec3s center(x + half * resolution, y + half * resolution, | |
88 | ✗ | z + half * resolution); | |
89 | ✗ | tfBox.setTranslation(center); | |
90 | ✗ | coal::collide(&box, tfBox, &mesh, Transform3s(), request, result); | |
91 | ✗ | if (result.isCollision()) { | |
92 | ✗ | octomap::point3d p((float)center[0], (float)center[1], | |
93 | ✗ | (float)center[2]); | |
94 | ✗ | octree->updateNode(p, true); | |
95 | ✗ | result.clear(); | |
96 | } | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | |||
101 | ✗ | octree->updateInnerOccupancy(); | |
102 | ✗ | octree->writeBinary("./env.octree"); | |
103 | ✗ | return OcTree(octree); | |
104 | } | ||
105 | |||
106 |
33/66✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
|
4 | BOOST_AUTO_TEST_CASE(octree_mesh) { |
107 | Eigen::IOFormat tuple(Eigen::FullPrecision, Eigen::DontAlignCols, "", ", ", | ||
108 |
7/14✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
|
4 | "", "", "(", ")"); |
109 | 2 | Scalar resolution(10.); | |
110 | 2 | std::vector<Vec3s> pRob, pEnv; | |
111 | 2 | std::vector<Triangle32> tRob, tEnv; | |
112 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | boost::filesystem::path path(TEST_RESOURCES_DIR); |
113 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
2 | loadOBJFile((path / "rob.obj").string().c_str(), pRob, tRob); |
114 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
2 | loadOBJFile((path / "env.obj").string().c_str(), pEnv, tEnv); |
115 | |||
116 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | BVHModel<OBBRSS> robMesh, envMesh; |
117 | // Build meshes with robot and environment | ||
118 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | makeMesh(pRob, tRob, robMesh); |
119 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | makeMesh(pEnv, tEnv, envMesh); |
120 | // Build octomap with environment | ||
121 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | envMesh.computeLocalAABB(); |
122 | // Load octree built from envMesh by makeOctree(envMesh, resolution) | ||
123 | OcTree envOctree( | ||
124 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
4 | coal::loadOctreeFile((path / "env.octree").string(), resolution)); |
125 | |||
126 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | std::cout << "Finished loading octree." << std::endl; |
127 | |||
128 | // Test operator== | ||
129 | { | ||
130 |
7/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✗ Branch 25 not taken.
✓ Branch 26 taken 1 times.
|
2 | BOOST_CHECK(envOctree == envOctree); |
131 |
8/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✗ Branch 29 not taken.
✓ Branch 30 taken 1 times.
|
2 | BOOST_CHECK(envOctree == OcTree(envOctree)); |
132 | |||
133 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
4 | const OcTree envOctree_from_tree(envOctree.getTree()); |
134 |
7/14✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1 times.
✗ Branch 18 not taken.
✓ Branch 20 taken 1 times.
✗ Branch 21 not taken.
✗ Branch 25 not taken.
✓ Branch 26 taken 1 times.
|
2 | BOOST_CHECK(envOctree == envOctree_from_tree); |
135 | 2 | } | |
136 | |||
137 | // Test tobytes() | ||
138 | { | ||
139 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | const std::vector<uint8_t> bytes = envOctree.tobytes(); |
140 |
10/22✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
✓ Branch 24 taken 1 times.
✗ Branch 25 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✗ Branch 35 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
|
2 | BOOST_CHECK(bytes.size() > 0 && bytes.size() <= envOctree.toBoxes().size() * |
141 | 3 * sizeof(Scalar)); | ||
142 | 2 | } | |
143 | |||
144 | 2 | std::vector<Transform3s> transforms; | |
145 | 2 | Scalar extents[] = {-2000, -2000, 0, 2000, 2000, 2000}; | |
146 | #ifndef NDEBUG // if debug mode | ||
147 | 2 | std::size_t N = 100; | |
148 | #else | ||
149 | std::size_t N = 10000; | ||
150 | #endif | ||
151 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | N = coal::getNbRun(utf::master_test_suite().argc, |
152 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | utf::master_test_suite().argv, N); |
153 | |||
154 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | generateRandomTransforms(extents, transforms, 2 * N); |
155 | |||
156 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | CollisionRequest request(coal::CONTACT | coal::DISTANCE_LOWER_BOUND, 1); |
157 |
2/2✓ Branch 0 taken 100 times.
✓ Branch 1 taken 1 times.
|
202 | for (std::size_t i = 0; i < N; ++i) { |
158 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
200 | CollisionResult resultMesh; |
159 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
200 | CollisionResult resultOctree; |
160 |
1/2✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
|
200 | Transform3s tf1(transforms[2 * i]); |
161 |
1/2✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
|
200 | Transform3s tf2(transforms[2 * i + 1]); |
162 | ; | ||
163 | // Test collision between meshes with random transform for robot. | ||
164 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
200 | coal::collide(&robMesh, tf1, &envMesh, tf2, request, resultMesh); |
165 | // Test collision between mesh and octree for the same transform. | ||
166 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
200 | coal::collide(&robMesh, tf1, &envOctree, tf2, request, resultOctree); |
167 | 200 | bool resMesh(resultMesh.isCollision()); | |
168 | 200 | bool resOctree(resultOctree.isCollision()); | |
169 |
9/16✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 100 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 100 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 53 times.
✓ Branch 14 taken 47 times.
✓ Branch 15 taken 53 times.
✗ Branch 16 not taken.
✓ Branch 18 taken 100 times.
✗ Branch 19 not taken.
✓ Branch 21 taken 100 times.
✗ Branch 22 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 100 times.
|
200 | BOOST_CHECK(!resMesh || resOctree); |
170 |
3/4✓ Branch 0 taken 47 times.
✓ Branch 1 taken 53 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 47 times.
|
200 | if (!resMesh && resOctree) { |
171 | ✗ | coal::DistanceRequest dreq; | |
172 | ✗ | coal::DistanceResult dres; | |
173 | ✗ | coal::distance(&robMesh, tf1, &envMesh, tf2, dreq, dres); | |
174 | ✗ | std::cout << "distance mesh mesh: " << dres.min_distance << std::endl; | |
175 | ✗ | BOOST_CHECK(dres.min_distance < sqrt(2.) * resolution); | |
176 | } | ||
177 | 200 | } | |
178 | 2 | } | |
179 | |||
180 |
33/66✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 19 taken 1 times.
✗ Branch 20 not taken.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
✓ Branch 27 taken 1 times.
✗ Branch 28 not taken.
✓ Branch 30 taken 1 times.
✗ Branch 31 not taken.
✓ Branch 33 taken 1 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 1 times.
✗ Branch 37 not taken.
✓ Branch 41 taken 1 times.
✗ Branch 42 not taken.
✓ Branch 45 taken 1 times.
✗ Branch 46 not taken.
✓ Branch 48 taken 1 times.
✗ Branch 49 not taken.
✓ Branch 52 taken 1 times.
✗ Branch 53 not taken.
✓ Branch 55 taken 1 times.
✗ Branch 56 not taken.
✓ Branch 58 taken 1 times.
✗ Branch 59 not taken.
✓ Branch 61 taken 1 times.
✗ Branch 62 not taken.
✓ Branch 66 taken 1 times.
✗ Branch 67 not taken.
✓ Branch 70 taken 1 times.
✗ Branch 71 not taken.
✓ Branch 73 taken 1 times.
✗ Branch 74 not taken.
✓ Branch 77 taken 1 times.
✗ Branch 78 not taken.
✓ Branch 80 taken 1 times.
✗ Branch 81 not taken.
✓ Branch 83 taken 1 times.
✗ Branch 84 not taken.
✓ Branch 86 taken 1 times.
✗ Branch 87 not taken.
✓ Branch 91 taken 1 times.
✗ Branch 92 not taken.
✓ Branch 95 taken 1 times.
✗ Branch 96 not taken.
✓ Branch 98 taken 1 times.
✗ Branch 99 not taken.
✓ Branch 102 taken 1 times.
✗ Branch 103 not taken.
✓ Branch 105 taken 1 times.
✗ Branch 106 not taken.
✓ Branch 108 taken 1 times.
✗ Branch 109 not taken.
✓ Branch 111 taken 1 times.
✗ Branch 112 not taken.
✓ Branch 116 taken 1 times.
✗ Branch 117 not taken.
|
4 | BOOST_AUTO_TEST_CASE(octree_height_field) { |
181 | Eigen::IOFormat tuple(Eigen::FullPrecision, Eigen::DontAlignCols, "", ", ", | ||
182 |
7/14✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 14 taken 1 times.
✗ Branch 15 not taken.
✓ Branch 18 taken 1 times.
✗ Branch 19 not taken.
✓ Branch 22 taken 1 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 1 times.
✗ Branch 26 not taken.
|
4 | "", "", "(", ")"); |
183 | 2 | Scalar resolution(10.); | |
184 | 2 | std::vector<Vec3s> pEnv; | |
185 | 2 | std::vector<Triangle32> tEnv; | |
186 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | boost::filesystem::path path(TEST_RESOURCES_DIR); |
187 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 9 taken 1 times.
✗ Branch 10 not taken.
|
2 | loadOBJFile((path / "env.obj").string().c_str(), pEnv, tEnv); |
188 | |||
189 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | BVHModel<OBBRSS> envMesh; |
190 | // Build meshes with robot and environment | ||
191 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | makeMesh(pEnv, tEnv, envMesh); |
192 | // Build octomap with environment | ||
193 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | envMesh.computeLocalAABB(); |
194 | // Load octree built from envMesh by makeOctree(envMesh, resolution) | ||
195 | OcTree envOctree( | ||
196 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
4 | coal::loadOctreeFile((path / "env.octree").string(), resolution)); |
197 | |||
198 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | std::cout << "Finished loading octree." << std::endl; |
199 | |||
200 | // Building hfield | ||
201 | 2 | const Scalar x_dim = 10, y_dim = 20; | |
202 | 2 | const int nx = 100, ny = 100; | |
203 | 2 | const Scalar max_altitude = 1., min_altitude = 0.; | |
204 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | const MatrixXs heights = MatrixXs::Constant(ny, nx, max_altitude); |
205 | |||
206 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | HeightField<AABB> hfield(x_dim, y_dim, heights, min_altitude); |
207 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | hfield.computeLocalAABB(); |
208 | |||
209 | 2 | std::vector<Transform3s> transforms; | |
210 | 2 | Scalar extents[] = {-2000, -2000, 0, 2000, 2000, 2000}; | |
211 | #ifndef NDEBUG // if debug mode | ||
212 | 2 | std::size_t N = 1000; | |
213 | #else | ||
214 | std::size_t N = 100000; | ||
215 | #endif | ||
216 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | N = coal::getNbRun(utf::master_test_suite().argc, |
217 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | utf::master_test_suite().argv, N); |
218 | |||
219 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | generateRandomTransforms(extents, transforms, 2 * N); |
220 | |||
221 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | CollisionRequest request(coal::CONTACT | coal::DISTANCE_LOWER_BOUND, 1); |
222 |
2/2✓ Branch 0 taken 1000 times.
✓ Branch 1 taken 1 times.
|
2002 | for (std::size_t i = 0; i < N; ++i) { |
223 |
1/2✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
|
2000 | CollisionResult resultBox; |
224 |
2/4✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1000 times.
✗ Branch 5 not taken.
|
2000 | CollisionResult resultHfield1, resultHfield2; |
225 |
1/2✓ Branch 2 taken 1000 times.
✗ Branch 3 not taken.
|
2000 | Transform3s tf1(transforms[2 * i]); |
226 |
1/2✓ Branch 2 taken 1000 times.
✗ Branch 3 not taken.
|
2000 | Transform3s tf2(transforms[2 * i + 1]); |
227 | |||
228 |
1/2✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
|
2000 | Box box; |
229 |
1/2✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
|
2000 | Transform3s box_tf; |
230 |
1/2✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
|
2000 | constructBox(hfield.aabb_local, tf2, box, box_tf); |
231 | |||
232 | // Test collision between octree and equivalent box. | ||
233 |
1/2✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
|
2000 | coal::collide(&envOctree, tf1, &box, box_tf, request, resultBox); |
234 | // Test collision between octree and hfield. | ||
235 |
1/2✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
|
2000 | coal::collide(&envOctree, tf1, &hfield, tf2, request, resultHfield1); |
236 |
1/2✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
|
2000 | coal::collide(&hfield, tf2, &envOctree, tf1, request, resultHfield2); |
237 | |||
238 | 2000 | bool resBox(resultBox.isCollision()); | |
239 | 2000 | bool resHfield(resultHfield1.isCollision()); | |
240 |
6/12✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1000 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1000 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 1000 times.
✗ Branch 15 not taken.
✓ Branch 17 taken 1000 times.
✗ Branch 18 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 1000 times.
|
2000 | BOOST_CHECK(resBox == resHfield); |
241 |
6/12✓ Branch 1 taken 1000 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1000 times.
✗ Branch 6 not taken.
✓ Branch 11 taken 1000 times.
✗ Branch 12 not taken.
✓ Branch 16 taken 1000 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 1000 times.
✗ Branch 20 not taken.
✗ Branch 24 not taken.
✓ Branch 25 taken 1000 times.
|
2000 | BOOST_CHECK(resultHfield1.isCollision() == resultHfield2.isCollision()); |
242 |
3/4✓ Branch 0 taken 984 times.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 984 times.
|
2000 | if (!resBox && resHfield) { |
243 | ✗ | coal::DistanceRequest dreq; | |
244 | ✗ | coal::DistanceResult dres; | |
245 | ✗ | coal::distance(&envMesh, tf1, &box, box_tf, dreq, dres); | |
246 | ✗ | std::cout << "distance mesh box: " << dres.min_distance << std::endl; | |
247 | ✗ | BOOST_CHECK(dres.min_distance < sqrt(2.) * resolution); | |
248 | } | ||
249 | 2000 | } | |
250 | 2 | } | |
251 |