5#include "testing/testing.h"
21namespace blender::meshintersect::tests {
23constexpr bool DO_OBJ =
false;
32 static constexpr int MAX_FACE_LEN = 1000;
34 static int edge_index(
int face_index,
int facepos)
36 return face_index * MAX_FACE_LEN + facepos;
39 static std::pair<int, int> face_and_pos_for_edge_index(
int e_index)
41 return std::pair<int, int>(e_index / MAX_FACE_LEN, e_index % MAX_FACE_LEN);
52 IMeshBuilder(
const char *spec)
54 std::istringstream ss(spec);
57 std::istringstream hdrss(line);
60 if (nv == 0 || nf == 0) {
63 arena.reserve(nv, nf);
64 Vector<const Vert *>
verts;
68 while (v_index < nv && spec_ok && getline(ss, line)) {
69 std::istringstream iss(line);
73 iss >> p0 >> p1 >> p2;
74 spec_ok = !iss.fail();
75 verts.append(arena.add_or_find_vert(mpq3(p0, p1, p2), v_index));
82 while (f_index < nf && spec_ok && getline(ss, line)) {
83 std::istringstream fss(line);
84 Vector<const Vert *> face_verts;
85 Vector<int> edge_orig;
87 while (spec_ok && fss >> v_index) {
88 if (v_index < 0 || v_index >= nv) {
92 face_verts.append(
verts[v_index]);
93 edge_orig.append(edge_index(f_index, fpos));
96 Face *facep = arena.add_face(face_verts, f_index, edge_orig);
104 std::cout <<
"Bad spec: " << spec;
107 imesh = IMesh(faces);
111static int all_shape_zero(
int )
116TEST(boolean_trimesh, Empty)
120 IMesh out = boolean_trimesh(in, BoolOpType::None, 1, all_shape_zero,
true,
false, &arena);
126TEST(boolean_trimesh, TetTetTrimesh)
128 const char *spec = R
"(8 8
147 IMeshBuilder mb(spec);
148 IMesh out = boolean_trimesh(
149 mb.imesh, BoolOpType::None, 1, all_shape_zero, true,
false, &mb.arena);
154 write_obj_mesh(out,
"tettet_tm");
157 IMeshBuilder mb2(spec);
158 IMesh out2 = boolean_trimesh(
159 mb2.imesh, BoolOpType::Union, 1, all_shape_zero,
true,
false, &mb2.arena);
160 out2.populate_vert();
164 write_obj_mesh(out2,
"tettet_union_tm");
167 IMeshBuilder mb3(spec);
168 IMesh out3 = boolean_trimesh(
172 [](
int t) { return t < 4 ? 0 : 1; },
176 out3.populate_vert();
180 write_obj_mesh(out3,
"tettet_union_binary_tm");
183 IMeshBuilder mb4(spec);
184 IMesh out4 = boolean_trimesh(
188 [](
int t) { return t < 4 ? 0 : 1; },
192 out4.populate_vert();
196 write_obj_mesh(out4,
"tettet_union_binary_self_tm");
199 IMeshBuilder mb5(spec);
200 IMesh out5 = boolean_trimesh(
202 BoolOpType::Intersect,
204 [](
int t) { return t < 4 ? 0 : 1; },
208 out5.populate_vert();
212 write_obj_mesh(out5,
"tettet_intersect_binary_tm");
215 IMeshBuilder mb6(spec);
216 IMesh out6 = boolean_trimesh(
218 BoolOpType::Difference,
220 [](
int t) { return t < 4 ? 0 : 1; },
224 out6.populate_vert();
228 write_obj_mesh(out6,
"tettet_difference_binary_tm");
231 IMeshBuilder mb7(spec);
232 IMesh out7 = boolean_trimesh(
234 BoolOpType::Difference,
236 [](
int t) { return t < 4 ? 1 : 0; },
240 out7.populate_vert();
244 write_obj_mesh(out7,
"tettet_difference_rev_binary_tm");
248TEST(boolean_trimesh, TetTet2Trimesh)
250 const char *spec = R
"(8 8
269 IMeshBuilder mb(spec);
270 IMesh out = boolean_trimesh(
271 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true,
false, &mb.arena);
276 write_obj_mesh(out,
"tettet2_union_tm");
280TEST(boolean_trimesh, CubeTetTrimesh)
282 const char *spec = R
"(12 16
313 IMeshBuilder mb(spec);
314 IMesh out = boolean_trimesh(
315 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true,
false, &mb.arena);
320 write_obj_mesh(out,
"cubetet_union_tm");
324TEST(boolean_trimesh, BinaryTetTetTrimesh)
326 const char *spec = R
"(8 8
345 IMeshBuilder mb(spec);
346 IMesh out = boolean_trimesh(
348 BoolOpType::Intersect,
350 [](int t) { return t < 4 ? 0 : 1; },
358 write_obj_mesh(out,
"binary_tettet_isect_tm");
362TEST(boolean_trimesh, TetTetCoplanarTrimesh)
364 const char *spec = R
"(8 8
383 IMeshBuilder mb(spec);
384 IMesh out = boolean_trimesh(
385 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true,
false, &mb.arena);
390 write_obj_mesh(out,
"tettet_coplanar_tm");
394TEST(boolean_trimesh, TetInsideTetTrimesh)
396 const char *spec = R
"(8 8
415 IMeshBuilder mb(spec);
416 IMesh out = boolean_trimesh(
417 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true,
false, &mb.arena);
422 write_obj_mesh(out,
"tetinsidetet_tm");
426TEST(boolean_trimesh, TetBesideTetTrimesh)
428 const char *spec = R
"(8 8
447 IMeshBuilder mb(spec);
448 IMesh out = boolean_trimesh(
449 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true,
false, &mb.arena);
454 write_obj_mesh(out,
"tetbesidetet_tm");
458TEST(boolean_trimesh, DegenerateTris)
460 const char *spec = R
"(10 10
483 IMeshBuilder mb(spec);
484 IMesh out = boolean_trimesh(
486 BoolOpType::Intersect,
488 [](int t) { return t < 5 ? 0 : 1; },
496 write_obj_mesh(out,
"degenerate_tris_tm");
500TEST(boolean_polymesh, TetTet)
502 const char *spec = R
"(8 8
521 IMeshBuilder mb(spec);
522 IMesh out = boolean_mesh(
523 mb.imesh, BoolOpType::None, 1, all_shape_zero, true,
false,
nullptr, &mb.arena);
528 write_obj_mesh(out,
"tettet");
531 IMeshBuilder mb2(spec);
532 IMesh out2 = boolean_mesh(
536 [](
int t) { return t < 4 ? 0 : 1; },
541 out2.populate_vert();
545 write_obj_mesh(out,
"tettet2");
549TEST(boolean_polymesh, CubeCube)
551 const char *spec = R
"(16 12
582 IMeshBuilder mb(spec);
584 write_obj_mesh(mb.imesh,
"cube_cube_in");
586 IMesh out = boolean_mesh(
587 mb.imesh, BoolOpType::Union, 1, all_shape_zero,
true,
false,
nullptr, &mb.arena);
592 write_obj_mesh(out,
"cubecube_union");
595 IMeshBuilder mb2(spec);
596 IMesh out2 = boolean_mesh(
600 [](
int t) { return t < 6 ? 0 : 1; },
605 out2.populate_vert();
609 write_obj_mesh(out2,
"cubecube_none");
613TEST(boolean_polymesh, CubeCone)
615 const char *spec = R
"(14 12
643 IMeshBuilder mb(spec);
644 IMesh out = boolean_mesh(
645 mb.imesh, BoolOpType::Union, 1, all_shape_zero, true,
false,
nullptr, &mb.arena);
650 write_obj_mesh(out,
"cubeccone");
654TEST(boolean_polymesh, CubeCubeCoplanar)
656 const char *spec = R
"(16 12
687 IMeshBuilder mb(spec);
688 IMesh out = boolean_mesh(
692 [](int t) { return t < 6 ? 0 : 1; },
701 write_obj_mesh(out,
"cubecube_coplanar");
705TEST(boolean_polymesh, TetTeTCoplanarDiff)
707 const char *spec = R
"(8 8
726 IMeshBuilder mb(spec);
727 IMesh out = boolean_mesh(
729 BoolOpType::Difference,
731 [](int t) { return t < 4 ? 0 : 1; },
740 write_obj_mesh(out,
"tettet_coplanar_diff");
744TEST(boolean_polymesh, CubeCubeStep)
746 const char *spec = R
"(16 12
777 IMeshBuilder mb(spec);
778 IMesh out = boolean_mesh(
780 BoolOpType::Difference,
782 [](int t) { return t < 6 ? 0 : 1; },
791 write_obj_mesh(out,
"cubecubestep");
795TEST(boolean_polymesh, CubeCyl4)
797 const char *spec = R
"(16 12
828 IMeshBuilder mb(spec);
829 IMesh out = boolean_mesh(
831 BoolOpType::Difference,
833 [](int t) { return t < 6 ? 1 : 0; },
842 write_obj_mesh(out,
"cubecyl4");
846TEST(boolean_polymesh, CubeCubesubdivDiff)
849 const char *spec = R
"(26 22
900 IMeshBuilder mb(spec);
901 IMesh out = boolean_mesh(
903 BoolOpType::Difference,
905 [](int t) { return t < 16 ? 1 : 0; },
914 write_obj_mesh(out,
"cubecubesubdivdiff");
918TEST(boolean_polymesh, CubePlane)
920 const char *spec = R
"(12 7
942 IMeshBuilder mb(spec);
943 IMesh out = boolean_mesh(
945 BoolOpType::Difference,
947 [](int t) { return t >= 1 ? 0 : 1; },
956 write_obj_mesh(out,
"cubeplane");
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
Read Guarded memory(de)allocation.
TEST(math_rotation, DefaultConstructor)