[Bf-blender-cvs] [5cd49e46f41] newboolean: Added a sphere/grid test to mesh intersect performance tests.
Howard Trickey
noreply at git.blender.org
Wed Aug 19 03:52:34 CEST 2020
Commit: 5cd49e46f4117a96e68ae736eec8c4871eafff6e
Author: Howard Trickey
Date: Tue Aug 18 06:12:47 2020 -0400
Branches: newboolean
https://developer.blender.org/rB5cd49e46f4117a96e68ae736eec8c4871eafff6e
Added a sphere/grid test to mesh intersect performance tests.
===================================================================
M source/blender/blenlib/tests/BLI_mesh_intersect_test.cc
===================================================================
diff --git a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc
index 9761a71c507..305afc383a1 100644
--- a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc
+++ b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc
@@ -711,170 +711,318 @@ TEST(mesh_intersect, CubeCubeStep)
#if DO_PERF_TESTS
-static void spheresphere_test(int nrings, double y_offset, bool use_self)
+static void get_sphere_params(int nrings,
+ int nsegs,
+ bool triangulate,
+ int *r_num_verts,
+ int *r_num_faces)
{
- /* Make two icospheres with nrings rings ad 2*nrings segments. */
- if (nrings < 2) {
- return;
+ *r_num_verts = nsegs * (nrings - 1) + 2;
+ if (triangulate) {
+ *r_num_faces = 2 * nsegs + 2 * nsegs * (nrings - 2);
}
- BLI_task_scheduler_init(); /* Without this, no parallelism. */
- double time_start = PIL_check_seconds_timer();
- MArena arena;
- bool triangulate = true;
+ else {
+ *r_num_faces = nsegs * nrings;
+ }
+}
+
+static void fill_sphere_data(int nrings,
+ int nsegs,
+ const double3 ¢er,
+ double radius,
+ bool triangulate,
+ MutableSpan<Facep> face,
+ int vid_start,
+ int fid_start,
+ MArena *arena)
+{
+ int num_verts;
+ int num_faces;
+ get_sphere_params(nrings, nsegs, triangulate, &num_verts, &num_faces);
+ BLI_assert(num_faces == face.size());
+ Array<Vertp> vert(num_verts);
const bool nrings_even = (nrings % 2 == 0);
int half_nrings = nrings / 2;
- int nsegs = 2 * nrings;
- const bool nsegs_even = true;
+ const bool nsegs_even = (nsegs % 2) == 0;
const bool nsegs_four_divisible = (nsegs % 4 == 0);
int half_nsegs = nrings;
int quarter_nsegs = half_nsegs / 2;
- double radius = 1.0;
- int num_sphere_verts = nsegs * (nrings - 1) + 2;
- int num_sphere_faces = nsegs * nrings;
- int num_sphere_tris = 2 * nsegs + 2 * nsegs * (nrings - 2);
- arena.reserve(2 * 2 * num_sphere_verts,
- 2 * 2 * (triangulate ? num_sphere_tris : num_sphere_faces));
- double center_y[2] = {0.0, y_offset};
double delta_phi = 2 * M_PI / nsegs;
double delta_theta = M_PI / nrings;
- int fid = 0;
- int vid = 0;
- Array<Facep> faces(2 * (triangulate ? num_sphere_tris : num_sphere_faces));
- Array<Vertp> verts(2 * num_sphere_verts);
- int face_start[2] = {0, (triangulate ? num_sphere_tris : num_sphere_faces)};
- int vert_start[2] = {0, num_sphere_verts};
- auto vert_index_fn = [nrings, &vert_start](int sphere, int seg, int ring) {
+ int fid = fid_start;
+ int vid = vid_start;
+ auto vert_index_fn = [nrings, num_verts](int seg, int ring) {
if (ring == 0) { /* Top vert. */
- return vert_start[sphere] + vert_start[1] - 2;
+ return num_verts - 2;
}
if (ring == nrings) { /* Bottom vert. */
- return vert_start[sphere] + vert_start[1] - 1;
+ return num_verts - 1;
}
- return vert_start[sphere] + seg * (nrings - 1) + (ring - 1);
+ return seg * (nrings - 1) + (ring - 1);
};
- auto face_index_fn = [nrings, &face_start](int sphere, int seg, int ring) {
- return face_start[sphere] + seg * nrings + ring;
+ auto face_index_fn = [nrings](int seg, int ring) {
+ return seg * nrings + ring;
};
- auto tri_index_fn = [nrings, nsegs, &face_start](int sphere, int seg, int ring, int tri) {
+ auto tri_index_fn = [nrings, nsegs](int seg, int ring, int tri) {
if (ring == 0) {
- return face_start[sphere] + seg;
+ return seg;
}
if (ring < nrings - 1) {
- return face_start[sphere] + nsegs + 2 * (ring - 1) * nsegs + 2 * seg + tri;
+ return nsegs + 2 * (ring - 1) * nsegs + 2 * seg + tri;
}
- return face_start[sphere] + nsegs + 2 * (nrings - 2) * nsegs + seg;
+ return nsegs + 2 * (nrings - 2) * nsegs + seg;
};
Array<int> eid = {0, 0, 0, 0}; /* Don't care about edge ids. */
- for (int sphere : {0, 1}) {
- /*
- * (x, y , z) is given from inclination theta and azimuth phi,
- * where 0 <= theta <= pi; 0 <= phi <= 2pi.
- * x = radius * sin(theta) cos(phi)
- * y = radius * sin(theta) sin(phi)
- * z = radius * cos(theta)
- */
- for (int s = 0; s < nsegs; ++s) {
- double phi = s * delta_phi;
- double sin_phi;
- double cos_phi;
- if (s == 0) {
- /* phi = 0. */
- sin_phi = 0.0;
- cos_phi = 1.0;
+ /*
+ * (x, y , z) is given from inclination theta and azimuth phi,
+ * where 0 <= theta <= pi; 0 <= phi <= 2pi.
+ * x = radius * sin(theta) cos(phi)
+ * y = radius * sin(theta) sin(phi)
+ * z = radius * cos(theta)
+ */
+ for (int s = 0; s < nsegs; ++s) {
+ double phi = s * delta_phi;
+ double sin_phi;
+ double cos_phi;
+ /* Avoid use of trig functions for pi/2 divisible angles. */
+ if (s == 0) {
+ /* phi = 0. */
+ sin_phi = 0.0;
+ cos_phi = 1.0;
+ }
+ else if (nsegs_even && s == half_nsegs) {
+ /* phi = pi. */
+ sin_phi = 0.0;
+ cos_phi = -1.0;
+ }
+ else if (nsegs_four_divisible && s == quarter_nsegs) {
+ /* phi = pi/2. */
+ sin_phi = 1.0;
+ cos_phi = 0.0;
+ }
+ else if (nsegs_four_divisible && s == 3 * quarter_nsegs) {
+ /* phi = 3pi/2. */
+ sin_phi = -1.0;
+ cos_phi = 0.0;
+ }
+ else {
+ sin_phi = sin(phi);
+ cos_phi = cos(phi);
+ }
+ for (int r = 1; r < nrings; ++r) {
+ double theta = r * delta_theta;
+ double r_sin_theta;
+ double r_cos_theta;
+ if (nrings_even && r == half_nrings) {
+ /* theta = pi/2. */
+ r_sin_theta = radius;
+ r_cos_theta = 0.0;
}
- else if (nsegs_even && s == half_nsegs) {
- /* phi = pi. */
- sin_phi = 0.0;
- cos_phi = -1.0;
+ else {
+ r_sin_theta = radius * sin(theta);
+ r_cos_theta = radius * cos(theta);
}
- else if (nsegs_four_divisible && s == quarter_nsegs) {
- /* phi = pi/2. */
- sin_phi = 1.0;
- cos_phi = 0.0;
+ double x = r_sin_theta * cos_phi + center[0];
+ double y = r_sin_theta * sin_phi + center[1];
+ double z = r_cos_theta + center[2];
+ Vertp v = arena->add_or_find_vert(mpq3(x, y, z), vid++);
+ vert[vert_index_fn(s, r)] = v;
+ }
+ }
+ Vertp vtop = arena->add_or_find_vert(mpq3(center[0], center[1], center[2] + radius), vid++);
+ Vertp vbot = arena->add_or_find_vert(mpq3(center[0], center[1], center[2] - radius), vid++);
+ vert[vert_index_fn(0, 0)] = vtop;
+ vert[vert_index_fn(0, nrings)] = vbot;
+ for (int s = 0; s < nsegs; ++s) {
+ int snext = (s + 1) % nsegs;
+ for (int r = 0; r < nrings; ++r) {
+ int rnext = r + 1;
+ int i0 = vert_index_fn(s, r);
+ int i1 = vert_index_fn(s, rnext);
+ int i2 = vert_index_fn(snext, rnext);
+ int i3 = vert_index_fn(snext, r);
+ Facep f;
+ Facep f2 = nullptr;
+ if (r == 0) {
+ f = arena->add_face({vert[i0], vert[i1], vert[i2]}, fid++, eid);
}
- else if (nsegs_four_divisible && s == 3 * quarter_nsegs) {
- /* phi = 3pi/2. */
- sin_phi = -1.0;
- cos_phi = 0.0;
+ else if (r == nrings - 1) {
+ f = arena->add_face({vert[i0], vert[i1], vert[i3]}, fid++, eid);
}
else {
- sin_phi = sin(phi);
- cos_phi = cos(phi);
- }
- for (int r = 1; r < nrings; ++r) {
- double theta = r * delta_theta;
- double r_sin_theta;
- double r_cos_theta;
- if (nrings_even && r == half_nrings) {
- /* theta = pi/2. */
- r_sin_theta = radius;
- r_cos_theta = 0.0;
+ if (triangulate) {
+ f = arena->add_face({vert[i0], vert[i1], vert[i2]}, fid++, eid);
+ f2 = arena->add_face({vert[i2], vert[i3], vert[i0]}, fid++, eid);
}
else {
- r_sin_theta = radius * sin(theta);
- r_cos_theta = radius * cos(theta);
+ f = arena->add_face({vert[i0], vert[i1], vert[i2], vert[i3]}, fid++, eid);
}
- double x = r_sin_theta * cos_phi;
- double y = r_sin_theta * sin_phi + center_y[sphere];
- double z = r_cos_theta;
- Vertp v = arena.add_or_find_vert(mpq3(x, y, z), vid++);
- int vindex = vert_index_fn(sphere, s, r);
- verts[vindex] = v;
}
- }
- Vertp vtop = arena.add_or_find_vert(mpq3(0, center_y[sphere], radius), vid++);
- Vertp vbot = arena.add_or_find_vert(mpq3(0, center_y[sphere], -radius), vid++);
- verts[vert_index_fn(sphere, 0, 0)] = vtop;
- verts[vert_index_fn(sphere, 0, nrings)] = vbot;
- for (int s = 0; s < nsegs; ++s) {
- int snext = (s + 1) % nsegs;
- for (int r = 0; r < nrings; ++r) {
- int rnext = r + 1;
- int i0 = vert_index_fn(sphere, s, r);
- int i1 = vert_index_fn(sphere, s, rnext);
- int i2 = vert_index_fn(sphere, snext, rnext);
- int i3 = vert_index_fn(sphere, snext, r);
- Facep f;
- Facep f2 = nullptr;
- if (r == 0) {
- f = arena.add_face({verts[i0], verts[i1], verts[i2]}, fid++, eid);
- }
- else if (r == nrings - 1) {
- f = arena.add_face({verts[i0], verts[i1], verts[i3]}, fid++, eid);
- }
- else {
- if (triangulate) {
- f = arena.add_face({verts[i0], verts[i1], verts[i2]}, fid++, eid);
- f2 = arena.add_face({verts[i2], verts[i3], verts[i0]}, fid++, eid);
- }
- else {
- f = arena.add_face({verts[i0], verts[i1], verts[i2], verts[i3]}, fid++, eid);
- }
- }
- if (triangulate) {
- int f_index = tri_index_fn(sphere, s, r, 0);
- faces[f_index] = f;
- if (r != 0 && r != nrings - 1) {
- int f_index2 = tri_index_fn(sphere, s, r, 1);
- faces[f_index2] = f2;
- }
- }
- else {
- int f_index = face_index_fn(sphere, s, r);
- faces[f_index] = f;
+ i
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list