Line | Branch | Exec | Source |
---|---|---|---|
1 | // Copyright Contributors to the OpenVDB Project | ||
2 | // SPDX-License-Identifier: MPL-2.0 | ||
3 | |||
4 | #include <openvdb/tools/VolumeToMesh.h> | ||
5 | #include <openvdb/Exceptions.h> | ||
6 | |||
7 | #include <gtest/gtest.h> | ||
8 | |||
9 | #include <vector> | ||
10 | |||
11 | 2 | class TestVolumeToMesh: public ::testing::Test | |
12 | { | ||
13 | }; | ||
14 | |||
15 | |||
16 | //////////////////////////////////////// | ||
17 | |||
18 | |||
19 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | TEST_F(TestVolumeToMesh, testAuxiliaryDataCollection) |
20 | { | ||
21 | typedef openvdb::tree::Tree4<float, 5, 4, 3>::Type FloatTreeType; | ||
22 | typedef FloatTreeType::ValueConverter<bool>::Type BoolTreeType; | ||
23 | |||
24 | const float iso = 0.0f; | ||
25 | const openvdb::Coord ijk(0,0,0); | ||
26 | |||
27 | 2 | FloatTreeType inputTree(1.0f); | |
28 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | inputTree.setValue(ijk, -1.0f); |
29 | |||
30 | 2 | BoolTreeType intersectionTree(false); | |
31 | |||
32 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | openvdb::tools::volume_to_mesh_internal::identifySurfaceIntersectingVoxels( |
33 | intersectionTree, inputTree, iso); | ||
34 | |||
35 |
2/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
1 | EXPECT_EQ(size_t(8), size_t(intersectionTree.activeVoxelCount())); |
36 | |||
37 | typedef FloatTreeType::ValueConverter<openvdb::Int16>::Type Int16TreeType; | ||
38 | typedef FloatTreeType::ValueConverter<openvdb::Index32>::Type Index32TreeType; | ||
39 | |||
40 | 2 | Int16TreeType signFlagsTree(0); | |
41 | 2 | Index32TreeType pointIndexTree(99999); | |
42 | |||
43 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | openvdb::tools::volume_to_mesh_internal::computeAuxiliaryData( |
44 | signFlagsTree, pointIndexTree, intersectionTree, inputTree, iso); | ||
45 | |||
46 | 1 | const int flags = int(signFlagsTree.getValue(ijk)); | |
47 | |||
48 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_TRUE(bool(flags & openvdb::tools::volume_to_mesh_internal::INSIDE)); |
49 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_TRUE(bool(flags & openvdb::tools::volume_to_mesh_internal::EDGES)); |
50 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_TRUE(bool(flags & openvdb::tools::volume_to_mesh_internal::XEDGE)); |
51 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_TRUE(bool(flags & openvdb::tools::volume_to_mesh_internal::YEDGE)); |
52 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_TRUE(bool(flags & openvdb::tools::volume_to_mesh_internal::ZEDGE)); |
53 | 1 | } | |
54 | |||
55 | |||
56 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | TEST_F(TestVolumeToMesh, testUniformMeshing) |
57 | { | ||
58 | typedef openvdb::tree::Tree4<float, 5, 4, 3>::Type FloatTreeType; | ||
59 | typedef openvdb::Grid<FloatTreeType> FloatGridType; | ||
60 | |||
61 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
2 | FloatGridType grid(1.0f); |
62 | |||
63 | // test voxel region meshing | ||
64 | |||
65 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | openvdb::CoordBBox bbox(openvdb::Coord(1), openvdb::Coord(6)); |
66 | |||
67 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | grid.tree().fill(bbox, -1.0f); |
68 | |||
69 | std::vector<openvdb::Vec3s> points; | ||
70 | std::vector<openvdb::Vec4I> quads; | ||
71 | std::vector<openvdb::Vec3I> triangles; | ||
72 | |||
73 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | openvdb::tools::volumeToMesh(grid, points, quads); |
74 | |||
75 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_TRUE(!points.empty()); |
76 |
2/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
1 | EXPECT_EQ(size_t(216), quads.size()); |
77 | |||
78 | |||
79 | points.clear(); | ||
80 | quads.clear(); | ||
81 | triangles.clear(); | ||
82 | grid.clear(); | ||
83 | |||
84 | |||
85 | // test tile region meshing | ||
86 | |||
87 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | grid.tree().addTile(FloatTreeType::LeafNodeType::LEVEL + 1, openvdb::Coord(0), -1.0f, true); |
88 | |||
89 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | openvdb::tools::volumeToMesh(grid, points, quads); |
90 | |||
91 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_TRUE(!points.empty()); |
92 |
2/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
1 | EXPECT_EQ(size_t(384), quads.size()); |
93 | |||
94 | |||
95 | points.clear(); | ||
96 | quads.clear(); | ||
97 | triangles.clear(); | ||
98 | grid.clear(); | ||
99 | |||
100 | |||
101 | // test tile region and bool volume meshing | ||
102 | |||
103 | typedef FloatTreeType::ValueConverter<bool>::Type BoolTreeType; | ||
104 | typedef openvdb::Grid<BoolTreeType> BoolGridType; | ||
105 | |||
106 |
2/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
2 | BoolGridType maskGrid(false); |
107 | |||
108 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | maskGrid.tree().addTile(BoolTreeType::LeafNodeType::LEVEL + 1, openvdb::Coord(0), true, true); |
109 | |||
110 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | openvdb::tools::volumeToMesh(maskGrid, points, quads); |
111 | |||
112 |
1/16✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
1 | EXPECT_TRUE(!points.empty()); |
113 |
2/16✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
|
1 | EXPECT_EQ(size_t(384), quads.size()); |
114 | 1 | } | |
115 |