Skip to content

Commit 7159040

Browse files
committed
resolve benchmark bug
1 parent 1d7bca6 commit 7159040

File tree

7 files changed

+92
-34
lines changed

7 files changed

+92
-34
lines changed

include/mcut/internal/nfg/memPool.h

+27-3
Original file line numberDiff line numberDiff line change
@@ -250,23 +250,47 @@ inline IN_pool::IN_pool(IN_pool&& p) noexcept
250250
// If V==0 use standard free()
251251
// else if V==N release a block is the corresponding IN_pool
252252

253+
#if 1
254+
#include <type_traits>
255+
template <typename T>
256+
int CountLeadingZeros(const T& DATA)
257+
{
258+
T MASK{1};
259+
int BITSN{sizeof(T) * CHAR_BIT}, LEADINGN{0};
260+
MASK <<= BITSN - 1;
261+
for(int I = BITSN; I > 0; I--, LEADINGN++, MASK >>= 1)
262+
{
263+
if(DATA & MASK)
264+
{
265+
break;
266+
}
267+
}
268+
return LEADINGN;
269+
}
270+
#endif
253271
class MultiPool
254272
{
255273
std::vector<IN_pool> IN_pools;
256274
uint32_t max_block_size;
257275

258276
IN_pool& pickPoolFromSize(uint32_t bs)
259277
{
260-
#if 0
278+
#if 0
261279
auto cz = std::countl_zero(bs - 1);
262280
cz = (cz == 32) ? (31) : (cz);
263281
return IN_pools[31 - cz];
264-
#else
282+
#else
283+
#if 0
284+
auto cz = CountLeadingZeros(bs - 1);
285+
cz = (cz == 32) ? (31) : (cz);
286+
return IN_pools[31 - cz];
287+
#else
265288
//// FOR COMPILERS THAT DO NOT SUPPORT C++20 REPLACE THE ABOVE WITH THE FOLLOWING
266289
std::vector<IN_pool>::iterator i = IN_pools.begin();
267290
while ((*i).blockSize() < bs) i++;
268291
return *i;
269-
#endif
292+
#endif
293+
#endif
270294
}
271295

272296
public:

source/bvh.cpp

+28-7
Original file line numberDiff line numberDiff line change
@@ -301,23 +301,44 @@ void build_oibvh(
301301

302302
#if defined(MCUT_WITH_COMPUTE_HELPER_THREADPOOL)
303303
{
304+
#if 1
304305
std::mutex bbox_expansion_mtx;
305-
auto fn_compute_mesh_bbox = [&](vertex_array_iterator_t block_start_, vertex_array_iterator_t block_end_) {
306+
auto fn_compute_mesh_bbox = [&](std::vector<bounding_box_t<vec3>>::const_iterator block_start_,
307+
std::vector<bounding_box_t<vec3>>::const_iterator block_end_) {
306308
bounding_box_t<vec3> meshBbox_local;
307-
for (vertex_array_iterator_t v = block_start_; v != block_end_; ++v) {
308-
const vec3& coords = mesh.vertex(*v);
309-
meshBbox_local.expand(coords);
309+
for(std::vector<bounding_box_t<vec3>>::const_iterator v = block_start_;
310+
v != block_end_;
311+
++v)
312+
{
313+
//const vec3& coords = mesh.vertex(*v);
314+
meshBbox_local.expand(*v /*coords*/);
310315
}
311316

312317
std::lock_guard<std::mutex> lock(bbox_expansion_mtx);
313318
meshBbox.expand(meshBbox_local);
314319
};
315320

316321
parallel_for(
317-
pool,
318-
mesh.vertices_begin(),
319-
mesh.vertices_end(),
322+
pool, face_bboxes.cbegin()/*mesh.vertices_begin()*/,
323+
face_bboxes.cend()/*mesh.vertices_end()*/,
320324
fn_compute_mesh_bbox);
325+
#else
326+
std::mutex bbox_expansion_mtx;
327+
auto fn_compute_mesh_bbox = [&](vertex_array_iterator_t block_start_,
328+
vertex_array_iterator_t block_end_) {
329+
bounding_box_t<vec3> meshBbox_local;
330+
for(vertex_array_iterator_t v = block_start_; v != block_end_; ++v)
331+
{
332+
const vec3& coords = mesh.vertex(*v);
333+
meshBbox_local.expand(coords);
334+
}
335+
336+
std::lock_guard<std::mutex> lock(bbox_expansion_mtx);
337+
meshBbox.expand(meshBbox_local);
338+
};
339+
340+
parallel_for(pool, mesh.vertices_begin(), mesh.vertices_end(), fn_compute_mesh_bbox);
341+
#endif
321342
}
322343
#else
323344
// for each vertex in mesh

source/kernel.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -4145,7 +4145,7 @@ void dispatch(output_t& output, const input_t& input)
41454145
if (prev_edge == hmesh_t::null_edge() || fpi.polygon_vertices.size() < cutpath_sequence.size()) {
41464146
const std::vector<ed_t>& evec = SAFE_ACCESS(ivtx_to_cp_edges, cur->first);
41474147
std::vector<ed_t>::const_iterator fiter = std::find_if(evec.cbegin(), evec.cend(), [&](const ed_t& e) { return e != prev_edge; });
4148-
4148+
MCUT_ASSERT(fiter != evec.cend());
41494149
ed_t edge = *fiter;
41504150
vd_t next_vertex = m0.vertex(edge, 0);
41514151

source/math.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -970,8 +970,8 @@
970970
num = a[0] * (d[1] - c[1]) + //
971971
c[0] * (a[1] - d[1]) + //
972972
d[0] * (c[1] - a[1]);
973-
std::cout << "test\n";
974-
std::cout << num.get_str() << std::endl << denom.get_str() << std::endl;
973+
//std::cout << "test\n";
974+
//std::cout << num.get_str() << std::endl << denom.get_str() << std::endl;
975975
if ((num == scalar_t(0.0)) || (num == denom)) {
976976
code = 'v';
977977
}

source/preproc.cpp

+28-19
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ bool client_input_arrays_to_hmesh(std::shared_ptr<context_t>& context_ptr,
9393
{
9494

9595
#if MCUT_WITH_ARBITRARY_PRECISION_NUMBERS
96-
const float& x = (vptr[(i * 3) + 0] - srcmesh_cutmesh_com[0]) + pre_quantization_translation[0];
97-
const float& y = (vptr[(i * 3) + 1] - srcmesh_cutmesh_com[1]) + pre_quantization_translation[1];
98-
const float& z = (vptr[(i * 3) + 2] - srcmesh_cutmesh_com[2]) + pre_quantization_translation[2];
96+
const float x = (vptr[(i * 3) + 0] - srcmesh_cutmesh_com[0]) + pre_quantization_translation[0];
97+
const float y = (vptr[(i * 3) + 1] - srcmesh_cutmesh_com[1]) + pre_quantization_translation[1];
98+
const float z = (vptr[(i * 3) + 2] - srcmesh_cutmesh_com[2]) + pre_quantization_translation[2];
9999
vec3 quantized_vertex(scalar_t::quantize(x, multiplier),
100100
scalar_t::quantize(y, multiplier),
101101
scalar_t::quantize(z, multiplier));
@@ -117,11 +117,11 @@ bool client_input_arrays_to_hmesh(std::shared_ptr<context_t>& context_ptr,
117117

118118
vd_t vd = halfedgeMesh.add_vertex(quantized_vertex);
119119
#else
120-
const float& x =
120+
const float x =
121121
(vptr[(i * 3) + 0] - srcmesh_cutmesh_com[0]) + pre_quantization_translation[0];
122-
const float& y =
122+
const float y =
123123
(vptr[(i * 3) + 1] - srcmesh_cutmesh_com[1]) + pre_quantization_translation[1];
124-
const float& z =
124+
const float z =
125125
(vptr[(i * 3) + 2] - srcmesh_cutmesh_com[2]) + pre_quantization_translation[2];
126126
// insert our vertex into halfedge mesh
127127
vd_t vd = halfedgeMesh.add_vertex(
@@ -140,9 +140,15 @@ bool client_input_arrays_to_hmesh(std::shared_ptr<context_t>& context_ptr,
140140
// for each input mesh-vertex
141141
for(McUint32 i = 0; i < numVertices; ++i)
142142
{
143-
const double& x = (vptr[(i * 3) + 0] - srcmesh_cutmesh_com[0]) + pre_quantization_translation[0];
144-
const double& y = (vptr[(i * 3) + 1] - srcmesh_cutmesh_com[1]) + pre_quantization_translation[1];
145-
const double& z = (vptr[(i * 3) + 2] - srcmesh_cutmesh_com[2]) + pre_quantization_translation[2];
143+
const double x_ =
144+
vptr[(i * 3) + 0];
145+
const double y_ =
146+
vptr[(i * 3) + 1];
147+
const double z_ = vptr[(i * 3) + 2];
148+
149+
const double x = (x_ - srcmesh_cutmesh_com[0]) + pre_quantization_translation[0];
150+
const double y = (y_ - srcmesh_cutmesh_com[1]) + pre_quantization_translation[1];
151+
const double z = (z_ - srcmesh_cutmesh_com[2]) + pre_quantization_translation[2];
146152

147153
#if MCUT_WITH_ARBITRARY_PRECISION_NUMBERS
148154
vec3 quantized_vertex(scalar_t::quantize(x, multiplier),
@@ -2205,11 +2211,10 @@ bool calculate_vertex_parameters(
22052211
vec3_<double> srcmesh_cutmesh_bboxmin = compwise_min(srcmesh_bboxmin, cutmesh_bboxmin);
22062212
vec3_<double> srcmesh_cutmesh_bboxmax = compwise_max(srcmesh_bboxmax, cutmesh_bboxmax);
22072213

2208-
vec3_<double> offset_from_origin = vec3_<double>(
2209-
1.0,
2210-
1.0,
2211-
1.0); // ensure that when meshes are place into positive quadrant, no vertex coincides with the origin.
2214+
22122215
vec3_<double> to_positive_quadrant = (srcmesh_cutmesh_com - srcmesh_cutmesh_bboxmin);
2216+
vec3_<double> offset_from_origin =
2217+
normalize(to_positive_quadrant); // ensures that when meshes are place into positive quadrant, no vertex coincides with the origin.
22132218

22142219
pre_quantization_translation = to_positive_quadrant + offset_from_origin;
22152220

@@ -2218,16 +2223,19 @@ bool calculate_vertex_parameters(
22182223
//
22192224
srcmesh_com = srcmesh_com + pre_quantization_translation;
22202225
cutmesh_com = cutmesh_com + pre_quantization_translation;
2221-
srcmesh_cutmesh_com = srcmesh_cutmesh_com + pre_quantization_translation;
2226+
//srcmesh_cutmesh_com = srcmesh_cutmesh_com + pre_quantization_translation;
22222227
srcmesh_bboxmin = srcmesh_bboxmin + pre_quantization_translation;
22232228
srcmesh_bboxmax = srcmesh_bboxmax + pre_quantization_translation;
22242229
cutmesh_bboxmin = cutmesh_bboxmin + pre_quantization_translation;
22252230
cutmesh_bboxmax = cutmesh_bboxmax + pre_quantization_translation;
22262231
srcmesh_cutmesh_bboxmin = srcmesh_cutmesh_bboxmin + pre_quantization_translation;
22272232
srcmesh_cutmesh_bboxmax = srcmesh_cutmesh_bboxmax + pre_quantization_translation;
22282233

2229-
2230-
double max_coord = std::numeric_limits<double>::lowest();
2234+
vec3_<double> diag = srcmesh_cutmesh_bboxmax - srcmesh_cutmesh_bboxmin;
2235+
MCUT_ASSERT(diag[0] > 0);
2236+
MCUT_ASSERT(diag[1] > 0);
2237+
MCUT_ASSERT(diag[2] > 0);
2238+
/*double max_coord = std::numeric_limits<double>::lowest();
22312239
double min_coord = std::numeric_limits<double>::max();
22322240
22332241
for(int i = 0; i < 3; ++i)
@@ -2236,9 +2244,10 @@ bool calculate_vertex_parameters(
22362244
std::min(srcmesh_cutmesh_bboxmin[1], srcmesh_cutmesh_bboxmin[2]));
22372245
max_coord = std::max(srcmesh_cutmesh_bboxmax[0],
22382246
std::max(srcmesh_cutmesh_bboxmax[1], srcmesh_cutmesh_bboxmax[2]));
2239-
}
2247+
}*/
22402248

2241-
const double M = std::max(std::abs(min_coord), std::abs(max_coord));
2249+
const double M = std::max(diag[0],std::max(diag[1], diag[2]));
2250+
/*Std::max(std::abs(min_coord), std::abs(max_coord));*/
22422251

22432252
auto is_pow2 = [](uint64_t x) { return (x != 0) && !(x & (x - 1)); };
22442253

@@ -2259,7 +2268,7 @@ bool calculate_vertex_parameters(
22592268
// The "+ 1" to cater to instances where "(uint64_t)(M + 0.5)" is a power-of-two: Here numerical perturbation will lead to
22602269
// some vertex coordinates being larger than "(uint64_t)(M + 0.5)". Therefore we add 1 to cover even instances that involve perturbation.
22612270
const auto M_ = (uint64_t)(M + 0.5) + 1;
2262-
const auto M_np2 = is_pow2(M_+1) ? M_ : next_pow2(M_);
2271+
const auto M_np2 = is_pow2(M_+1) ? M_ : next_pow2(M_+1);
22632272

22642273
quantization_multiplier = (double)M_np2;
22652274

tests/source/benchmark.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ UTEST_I_TEARDOWN(Benchmark)
103103

104104
UTEST_I(Benchmark, inputID, NUMBER_OF_BENCHMARKS)
105105
{
106-
106+
/*if(utest_fixture->benchmarkIndex == 42 || utest_fixture->benchmarkIndex == 42)
107+
{
108+
return;
109+
}*/
110+
107111
std::vector<std::pair<std::string, std::string>> benchmarkMeshPairs;
108112

109113
std::stringstream ss;

tests/source/degenerateInput.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ UTEST_F(DegenerateInput, edgeEdgeIntersection)
8181
MC_INVALID_OPERATION);
8282
}
8383

84-
#if 0
84+
#if 1
8585
// An intersection between two triangles where a vertex from the cut-mesh triangle
8686
// lies on the src-mesh triangle. (This will only work with exact arith)
8787
UTEST_F(DegenerateInput, faceVertexIntersection)

0 commit comments

Comments
 (0)