Skip to content

Commit 9e5f993

Browse files
committed
Merge branch 'master' into ids
2 parents 9cc95f1 + 7d2d4ef commit 9e5f993

File tree

6 files changed

+135
-10
lines changed

6 files changed

+135
-10
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@
3030
*.exe
3131
*.out
3232
*.app
33+
build/

CMakeLists.txt.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ project(googletest-download NONE)
55
include(ExternalProject)
66
ExternalProject_Add(googletest
77
GIT_REPOSITORY https://github.com/google/googletest.git
8-
GIT_TAG master
8+
GIT_TAG release-1.10.0
99
SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src"
1010
BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build"
1111
CONFIGURE_COMMAND ""

storage.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,20 +1095,26 @@ class abstract_chunked_voxel_storage : public regular_voxel_storage {
10951095
release(get_chunk(this, ijk));
10961096
}
10971097

1098-
abstract_voxel_storage* a2 = a->is_explicit() ? a->copy(n->next_slot()) : a->make_explicit(n->next_slot());
1098+
abstract_voxel_storage* a_explicit = a->is_explicit() ? (inplace ? a : a->copy(n->next_slot())) : a->make_explicit(n->next_slot());
10991099
// b is temporary, so not assigned next_slot
1100-
abstract_voxel_storage* b2 = b->is_explicit() ? nullptr : b->make_explicit();
1101-
abstract_voxel_storage* b3 = b2 ? b2 : b;
1100+
abstract_voxel_storage* b_temp = b->is_explicit() ? nullptr : b->make_explicit();
1101+
abstract_voxel_storage* b_forced_explicit = b_temp ? b_temp : b;
11021102
if (mode == OP_UNION) {
1103-
a2->boolean_union(b3);
1103+
a_explicit->boolean_union(b_forced_explicit);
11041104
} else if (mode == OP_SUBTRACTION) {
1105-
a2->boolean_subtraction(b3);
1105+
a_explicit->boolean_subtraction(b_forced_explicit);
11061106
} else if (mode == OP_INTERSECTION) {
1107-
a2->boolean_intersection(b3);
1107+
a_explicit->boolean_intersection(b_forced_explicit);
11081108
}
1109-
delete b2;
1110-
set_chunk(n, ijk, a2);
1109+
delete b_temp;
11111110

1111+
if (inplace && a_explicit != a) {
1112+
delete a;
1113+
}
1114+
if (!inplace || a_explicit != a) {
1115+
set_chunk(n, ijk, a_explicit);
1116+
}
1117+
11121118
END_LOOP;
11131119

11141120
return n;

tests/test_validate.cpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include "../voxelizer.h"
2+
#include "../volume.h"
3+
#include "../writer.h"
4+
#include "../traversal.h"
5+
6+
#include <gtest/gtest.h>
7+
8+
#include <BRepPrimAPI_MakeBox.hxx>
9+
#include <BRepMesh_IncrementalMesh.hxx>
10+
11+
#include <ctime>
12+
13+
namespace {
14+
void voxelize(double vsize, bool rotated) {
15+
auto storage = new chunked_voxel_storage<bit_t>(0., 0., 0., vsize, 10. / vsize, 10. / vsize, 10. / vsize, 32);
16+
17+
gp_Ax2 ax;
18+
if (rotated) {
19+
ax = gp_Ax2(gp_Pnt(3, 4, 4), gp_Dir(1, 1, 1));
20+
} else {
21+
ax = gp_Ax2(gp_Pnt(1, 1, 1), gp::DZ());
22+
}
23+
24+
BRepPrimAPI_MakeBox mb(ax, 3., 3., 3.);
25+
auto solid = mb.Solid();
26+
BRepMesh_IncrementalMesh(solid, 0.001);
27+
28+
/*
29+
TopExp_Explorer exp(solid, TopAbs_VERTEX);
30+
std::set< std::tuple<double, double, double> > points;
31+
for (; exp.More(); exp.Next()) {
32+
gp_Pnt p = BRep_Tool::Pnt(TopoDS::Vertex(exp.Current()));
33+
points.insert(std::make_tuple(p.X(), p.Y(), p.Z()));
34+
}
35+
36+
for (auto& p : points) {
37+
std::cout << std::get<0>(p) << " " << std::get<1>(p) << " " << std::get<2>(p) << std::endl;
38+
}
39+
*/
40+
41+
double t_vox, t_vol;
42+
43+
{
44+
std::clock_t c_start = std::clock();
45+
auto vox = voxelizer(solid, storage);
46+
vox.Convert();
47+
std::clock_t c_end = std::clock();
48+
49+
t_vox = (double) (c_end - c_start) / CLOCKS_PER_SEC;
50+
}
51+
52+
/*
53+
std::ofstream fs("rotated.obj");
54+
storage->obj_export(fs);
55+
*/
56+
57+
regular_voxel_storage* volume;
58+
{
59+
std::clock_t c_start = std::clock();
60+
traversal_voxel_filler_inverse filler;
61+
volume = filler(storage);
62+
std::clock_t c_end = std::clock();
63+
64+
t_vol = (double) (c_end - c_start) / CLOCKS_PER_SEC;
65+
}
66+
67+
68+
auto surface_count = storage->count();
69+
auto volume_count = volume->count();
70+
71+
double total_volume = (volume_count + surface_count / 2) * (vsize * vsize * vsize);
72+
73+
std::cout << std::setprecision(15) << vsize << "," << rotated << "," << t_vol << "," << t_vox << "," << total_volume << std::endl;
74+
75+
delete storage;
76+
delete volume;
77+
}
78+
}
79+
80+
TEST(Validation, Volume) {
81+
std::cout.precision(15);
82+
83+
for (int j = 1; j < 3; ++j) {
84+
double b = 1. / std::pow(10, j);
85+
for (int i = 1; i < 10; ++i) {
86+
voxelize(b * i, false);
87+
voxelize(b * i, true);
88+
}
89+
}
90+
}

tests/test_volume.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,28 @@ TEST(Voxelizer, TraversalVolumeTripleSeparate) {
146146

147147
delete surface;
148148
delete volume;
149-
}
149+
}
150+
151+
TEST(Voxelizer, TraversalVolumeTripleInverted) {
152+
auto surface = new chunked_voxel_storage<bit_t>(0., 0., 0., 0.1, 300, 100, 100, 32);
153+
154+
for (int i = 0; i < 3; ++i) {
155+
BRepPrimAPI_MakeBox mb(gp_Pnt(i * 10. + 1., 1., 1.), 8., 8., 8.);
156+
auto vox = voxelizer(mb.Solid(), surface);
157+
vox.Convert();
158+
}
159+
160+
// Traversal is done on external and then inverted
161+
traversal_voxel_filler_inverse filler;
162+
auto volume = filler(surface);
163+
auto A = surface->count();
164+
auto B = volume->count();
165+
166+
ASSERT_EQ(A, 3 * (81 * 81 * 2 + 81 * 79 * 2 + 79 * 79 * 2));
167+
ASSERT_EQ(B, 3 * (79 * 79 * 79));
168+
ASSERT_EQ(A + B, 3 * (81 * 81 * 81));
169+
170+
delete surface;
171+
delete volume;
172+
}
173+

traversal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,10 @@ class visitor {
421421
queue.pop_front();
422422
}
423423
}
424+
425+
~visitor() {
426+
delete visited_;
427+
}
424428
};
425429

426430
class query_leftmost {

0 commit comments

Comments
 (0)