Skip to content

Commit 7d2d4ef

Browse files
committed
volume calculation validation code
1 parent b06fb8c commit 7d2d4ef

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

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+
}

0 commit comments

Comments
 (0)