Wildmeshing Toolkit
test_component_edge_insertion.cpp
Go to the documentation of this file.
1 // #include <catch2/catch_test_macros.hpp>
2 // #include <nlohmann/json.hpp>
3 // #include <tools/DEBUG_EdgeMesh.hpp>
4 // #include <tools/DEBUG_TetMesh.hpp>
5 // #include <tools/DEBUG_TriMesh.hpp>
6 // #include <tools/EdgeMesh_examples.hpp>
7 // #include <tools/TetMesh_examples.hpp>
8 // #include <tools/TriMesh_examples.hpp>
9 // #include <wmtk/Mesh.hpp>
10 // #include <wmtk/TriMesh.hpp>
11 // #include <wmtk/Types.hpp>
12 // #include <wmtk/components/base/Paths.hpp>
13 // #include <wmtk/components/edge_insertion/edge_insertion.hpp>
14 // #include <wmtk/components/edge_insertion/internal/edge_insertion.hpp>
15 // #include <wmtk/components/get_all_meshes/get_all_meshes.hpp>
16 // #include <wmtk/components/input/input.hpp>
17 // #include <wmtk/components/output/output.hpp>
18 // #include <wmtk/io/Cache.hpp>
19 // #include <wmtk/io/ParaviewWriter.hpp>
20 // #include <wmtk/utils/EigenMatrixWriter.hpp>
21 // #include <wmtk/utils/Rational.hpp>
22 // #include <wmtk/utils/mesh_utils.hpp>
23 
24 // using namespace wmtk::components::base;
25 // using namespace wmtk;
26 // using namespace wmtk::tests;
27 // using namespace wmtk::tests_3d;
28 
29 // using json = nlohmann::json;
30 
31 // const std::filesystem::path data_dir = WMTK_DATA_DIR;
32 
33 
34 // TEST_CASE("edge_insertion", "[components][edge_insertion][.]")
35 // {
36 // wmtk::io::Cache cache("wmtk_cache", ".");
37 
38 // MatrixX<Rational> V;
39 // V.resize(4, 2);
40 // V.row(0) = Vector2r(0, 0);
41 // V.row(1) = Vector2r(1, 0);
42 // V.row(2) = Vector2r(1, 1);
43 // V.row(3) = Vector2r(0, 1);
44 
45 // RowVectors3l F;
46 // F.resize(2, 3);
47 // F.row(0) << 0, 1, 2;
48 // F.row(1) << 0, 2, 3;
49 
50 // std::shared_ptr<DEBUG_TriMesh> tm = std::make_shared<DEBUG_TriMesh>();
51 // tm->initialize(F, false);
52 // mesh_utils::set_matrix_attribute(V, "vertices", PrimitiveType::Vertex, *tm);
53 
54 // MatrixX<Rational> V_e;
55 // V_e.resize(2, 2);
56 // V_e.row(0) = Vector2r(0.75, 0.25);
57 // V_e.row(1) = Vector2r(0.25, 0.75);
58 
59 // MatrixX<int64_t> E;
60 // E.resize(1, 2);
61 // E.row(0) << 0, 1;
62 
63 // std::shared_ptr<DEBUG_EdgeMesh> em = std::make_shared<DEBUG_EdgeMesh>();
64 // em->initialize(E);
65 // mesh_utils::set_matrix_attribute(V_e, "vertices", PrimitiveType::Vertex, *em);
66 
67 // cache.write_mesh(*tm, "trimesh");
68 // cache.write_mesh(*em, "edgemesh");
69 
70 // json input =
71 // R"({
72 // "edges": "edgemesh",
73 // "triangles": "trimesh",
74 // "output": "embedded_mesh"
75 // })"_json;
76 
77 // wmtk::components::edge_insertion(Paths(), input, cache);
78 
79 // json getall =
80 // R"({
81 // "input": "embedded_mesh",
82 // "name": "meshes"
83 // })"_json;
84 
85 // wmtk::components::get_all_meshes(Paths(), getall, cache);
86 
87 // json output = R"({
88 // "attributes": {
89 // "position": "vertices"
90 // },
91 // "file": "test_ei_out",
92 // "input": "embedded_mesh"
93 // })"_json;
94 
95 // wmtk::components::output(Paths(), output, cache);
96 
97 // json output2 = R"({
98 // "attributes": {
99 // "position": "vertices"
100 // },
101 // "file": "test_ei_edges_out",
102 // "input": "embedded_mesh.input_mesh"
103 // })"_json;
104 
105 // wmtk::components::output(Paths(), output2, cache);
106 // }
107 
108 // TEST_CASE("edge_insertion_2", "[components][edge_insertion][.]")
109 // {
110 // wmtk::io::Cache cache("wmtk_cache", ".");
111 
112 // MatrixX<Rational> V;
113 // V.resize(4, 2);
114 // V.row(0) = Vector2r(0, 0);
115 // V.row(1) = Vector2r(1, 0);
116 // V.row(2) = Vector2r(1, 1);
117 // V.row(3) = Vector2r(0, 1);
118 
119 // RowVectors3l F;
120 // F.resize(2, 3);
121 // F.row(0) << 0, 1, 2;
122 // F.row(1) << 0, 2, 3;
123 
124 // std::shared_ptr<DEBUG_TriMesh> tm = std::make_shared<DEBUG_TriMesh>();
125 // tm->initialize(F, false);
126 // mesh_utils::set_matrix_attribute(V, "vertices", PrimitiveType::Vertex, *tm);
127 
128 // MatrixX<Rational> V_e;
129 // V_e.resize(4, 2);
130 // V_e.row(0) = Vector2r(0.75, 0.25);
131 // V_e.row(1) = Vector2r(0.25, 0.75);
132 // V_e.row(2) = Vector2r(0.25, 0.25);
133 // V_e.row(3) = Vector2r(0.75, 0.75);
134 
135 // MatrixX<int64_t> E;
136 // E.resize(2, 2);
137 // E.row(0) << 0, 1;
138 // E.row(1) << 2, 3;
139 
140 // std::shared_ptr<DEBUG_EdgeMesh> em = std::make_shared<DEBUG_EdgeMesh>();
141 // em->initialize(E);
142 // mesh_utils::set_matrix_attribute(V_e, "vertices", PrimitiveType::Vertex, *em);
143 
144 // cache.write_mesh(*tm, "trimesh");
145 // cache.write_mesh(*em, "edgemesh");
146 
147 // json input =
148 // R"({
149 // "edges": "edgemesh",
150 // "triangles": "trimesh",
151 // "output": "embedded_mesh"
152 // })"_json;
153 
154 // wmtk::components::edge_insertion(Paths(), input, cache);
155 
156 // json getall =
157 // R"({
158 // "input": "embedded_mesh",
159 // "name": "meshes"
160 // })"_json;
161 
162 // wmtk::components::get_all_meshes(Paths(), getall, cache);
163 
164 // json output = R"({
165 // "attributes": {
166 // "position": "vertices"
167 // },
168 // "file": "test_ei_out",
169 // "input": "embedded_mesh"
170 // })"_json;
171 
172 // wmtk::components::output(Paths(), output, cache);
173 
174 // json output2 = R"({
175 // "attributes": {
176 // "position": "vertices"
177 // },
178 // "file": "test_ei_edges_out",
179 // "input": "embedded_mesh.input_mesh"
180 // })"_json;
181 
182 // wmtk::components::output(Paths(), output2, cache);
183 // }
184 
185 // TEST_CASE("edge_insertion_3", "[components][edge_insertion][.]")
186 // {
187 // wmtk::io::Cache cache("wmtk_cache", ".");
188 
189 // MatrixX<Rational> V;
190 // V.resize(6, 2);
191 // V.row(0) = Vector2r(0, 0);
192 // V.row(1) = Vector2r(1, 0);
193 // V.row(2) = Vector2r(1, 1);
194 // V.row(3) = Vector2r(0, 1);
195 // V.row(4) = Vector2r(0, 0.5);
196 // V.row(5) = Vector2r(1, 0.5);
197 
198 // RowVectors3l F;
199 // F.resize(4, 3);
200 // F.row(0) << 0, 1, 5;
201 // F.row(1) << 0, 5, 4;
202 // F.row(2) << 4, 5, 2;
203 // F.row(3) << 4, 2, 3;
204 
205 
206 // std::shared_ptr<DEBUG_TriMesh> tm = std::make_shared<DEBUG_TriMesh>();
207 // tm->initialize(F, false);
208 // mesh_utils::set_matrix_attribute(V, "vertices", PrimitiveType::Vertex, *tm);
209 
210 // MatrixX<Rational> V_e;
211 // V_e.resize(3, 2);
212 // V_e.row(0) = Vector2r(0, 1);
213 // V_e.row(1) = Vector2r(0.5, 0);
214 // V_e.row(2) = Vector2r(1, 1);
215 
216 // RowVectors2l E;
217 // E.resize(3, 2);
218 // E.row(0) << 0, 1;
219 // E.row(1) << 1, 2;
220 // E.row(2) << 0, 2;
221 
222 // std::shared_ptr<DEBUG_EdgeMesh> em = std::make_shared<DEBUG_EdgeMesh>();
223 // em->initialize(E);
224 // mesh_utils::set_matrix_attribute(V_e, "vertices", PrimitiveType::Vertex, *em);
225 
226 // cache.write_mesh(*tm, "trimesh");
227 // cache.write_mesh(*em, "edgemesh");
228 
229 // json input =
230 // R"({
231 // "edges": "edgemesh",
232 // "triangles": "trimesh",
233 // "output": "embedded_mesh"
234 // })"_json;
235 
236 // wmtk::components::edge_insertion(Paths(), input, cache);
237 
238 // json getall =
239 // R"({
240 // "input": "embedded_mesh",
241 // "name": "meshes"
242 // })"_json;
243 
244 // wmtk::components::get_all_meshes(Paths(), getall, cache);
245 
246 // json output = R"({
247 // "attributes": {
248 // "position": "vertices"
249 // },
250 // "file": "test_ei_out",
251 // "input": "embedded_mesh"
252 // })"_json;
253 
254 // wmtk::components::output(Paths(), output, cache);
255 
256 // json output2 = R"({
257 // "attributes": {
258 // "position": "vertices"
259 // },
260 // "file": "test_ei_edges_out",
261 // "input": "embedded_mesh.input_mesh"
262 // })"_json;
263 
264 // wmtk::components::output(Paths(), output2, cache);
265 // }
266 
267 // TEST_CASE("edge_insertion_4", "[components][edge_insertion][.]")
268 // {
269 // wmtk::io::Cache cache("wmtk_cache", ".");
270 
271 // MatrixX<Rational> V;
272 // V.resize(6, 2);
273 // V.row(0) = Vector2r(0, 0);
274 // V.row(1) = Vector2r(1, 0);
275 // V.row(2) = Vector2r(1, 1);
276 // V.row(3) = Vector2r(0, 1);
277 // V.row(4) = Vector2r(0, 0.5);
278 // V.row(5) = Vector2r(1, 0.5);
279 
280 // RowVectors3l F;
281 // F.resize(4, 3);
282 // F.row(0) << 0, 1, 5;
283 // F.row(1) << 0, 5, 4;
284 // F.row(2) << 4, 5, 2;
285 // F.row(3) << 4, 2, 3;
286 
287 
288 // std::shared_ptr<DEBUG_TriMesh> tm = std::make_shared<DEBUG_TriMesh>();
289 // tm->initialize(F, false);
290 // mesh_utils::set_matrix_attribute(V, "vertices", PrimitiveType::Vertex, *tm);
291 
292 // MatrixX<Rational> V_e;
293 // V_e.resize(7, 2);
294 // V_e.row(0) = Vector2r(0.25, 0.25);
295 // V_e.row(1) = Vector2r(0.75, 0.75);
296 // V_e.row(2) = Vector2r(0.25, 0.375);
297 // V_e.row(3) = Vector2r(0.75, 0.625);
298 // V_e.row(4) = Vector2r(0.25, 0.75);
299 // V_e.row(5) = Vector2r(0.75, 0.25);
300 // V_e.row(6) = Vector2r(0.5, 0.825);
301 
302 
303 // RowVectors2l E;
304 // E.resize(4, 2);
305 // E.row(0) << 0, 1;
306 // E.row(1) << 2, 3;
307 // E.row(2) << 4, 5;
308 // E.row(3) << 5, 6;
309 
310 // std::shared_ptr<DEBUG_EdgeMesh> em = std::make_shared<DEBUG_EdgeMesh>();
311 // em->initialize(E);
312 // mesh_utils::set_matrix_attribute(V_e, "vertices", PrimitiveType::Vertex, *em);
313 
314 // cache.write_mesh(*tm, "trimesh");
315 // cache.write_mesh(*em, "edgemesh");
316 
317 // json input =
318 // R"({
319 // "edges": "edgemesh",
320 // "triangles": "trimesh",
321 // "output": "embedded_mesh"
322 // })"_json;
323 
324 // wmtk::components::edge_insertion(Paths(), input, cache);
325 
326 // json getall =
327 // R"({
328 // "input": "embedded_mesh",
329 // "name": "meshes"
330 // })"_json;
331 
332 // wmtk::components::get_all_meshes(Paths(), getall, cache);
333 
334 // json output = R"({
335 // "attributes": {
336 // "position": "vertices"
337 // },
338 // "file": "test_ei_out",
339 // "input": "embedded_mesh"
340 // })"_json;
341 
342 // wmtk::components::output(Paths(), output, cache);
343 
344 // json output2 = R"({
345 // "attributes": {
346 // "position": "vertices"
347 // },
348 // "file": "test_ei_edges_out",
349 // "input": "embedded_mesh.input_mesh"
350 // })"_json;
351 
352 // wmtk::components::output(Paths(), output2, cache);
353 // }
354 
355 // TEST_CASE("edge_insertion_5", "[components][edge_insertion][.]")
356 // {
357 // wmtk::io::Cache cache("wmtk_cache", ".");
358 
359 // MatrixX<Rational> V;
360 // V.resize(6, 2);
361 // V.row(0) = Vector2r(0, 0);
362 // V.row(1) = Vector2r(1, 0);
363 // V.row(2) = Vector2r(1, 1);
364 // V.row(3) = Vector2r(0, 1);
365 // V.row(4) = Vector2r(0, 0.5);
366 // V.row(5) = Vector2r(1, 0.5);
367 
368 // RowVectors3l F;
369 // F.resize(4, 3);
370 // F.row(0) << 0, 1, 5;
371 // F.row(1) << 0, 5, 4;
372 // F.row(2) << 4, 5, 2;
373 // F.row(3) << 4, 2, 3;
374 
375 
376 // std::shared_ptr<DEBUG_TriMesh> tm = std::make_shared<DEBUG_TriMesh>();
377 // tm->initialize(F, false);
378 // mesh_utils::set_matrix_attribute(V, "vertices", PrimitiveType::Vertex, *tm);
379 
380 // MatrixX<Rational> V_e;
381 // V_e.resize(10, 2);
382 // V_e.row(0) = Vector2r(0.25, 0.25);
383 // V_e.row(1) = Vector2r(0.75, 0.75);
384 // V_e.row(2) = Vector2r(0.25, 0.375);
385 // V_e.row(3) = Vector2r(0.75, 0.625);
386 // V_e.row(4) = Vector2r(0.25, 0.75);
387 // V_e.row(5) = Vector2r(0.75, 0.25);
388 // V_e.row(6) = Vector2r(0.5, 0.825);
389 // V_e.row(7) = Vector2r(0, 1);
390 // V_e.row(8) = Vector2r(0.5, 0);
391 // V_e.row(9) = Vector2r(1, 1);
392 
393 
394 // RowVectors2l E;
395 // E.resize(7, 2);
396 // E.row(0) << 0, 1;
397 // E.row(1) << 2, 3;
398 // E.row(2) << 4, 5;
399 // E.row(3) << 5, 6;
400 // E.row(4) << 7, 8;
401 // E.row(5) << 8, 9;
402 // E.row(6) << 9, 7;
403 
404 // std::shared_ptr<DEBUG_EdgeMesh> em = std::make_shared<DEBUG_EdgeMesh>();
405 // em->initialize(E);
406 // mesh_utils::set_matrix_attribute(V_e, "vertices", PrimitiveType::Vertex, *em);
407 
408 // cache.write_mesh(*tm, "trimesh");
409 // cache.write_mesh(*em, "edgemesh");
410 
411 // json input =
412 // R"({
413 // "edges": "edgemesh",
414 // "triangles": "trimesh",
415 // "output": "embedded_mesh"
416 // })"_json;
417 
418 // wmtk::components::edge_insertion(Paths(), input, cache);
419 
420 // json getall =
421 // R"({
422 // "input": "embedded_mesh",
423 // "name": "meshes"
424 // })"_json;
425 
426 // wmtk::components::get_all_meshes(Paths(), getall, cache);
427 
428 // json output = R"({
429 // "attributes": {
430 // "position": "vertices"
431 // },
432 // "file": "test_ei_out",
433 // "input": "embedded_mesh"
434 // })"_json;
435 
436 // wmtk::components::output(Paths(), output, cache);
437 
438 // json output2 = R"({
439 // "attributes": {
440 // "position": "vertices"
441 // },
442 // "file": "test_ei_edges_out",
443 // "input": "embedded_mesh.input_mesh"
444 // })"_json;
445 
446 // wmtk::components::output(Paths(), output2, cache);
447 // }
448 
449 // TEST_CASE("edge_insertion_siggraph", "[components][edge_insertion][.]")
450 // {
451 // wmtk::io::Cache cache("wmtk_cache", ".");
452 
453 // MatrixX<Rational> V;
454 // V.resize(25, 2);
455 
456 // V.row(0) = Vector2r(-100, -100);
457 // V.row(1) = Vector2r(50, -100);
458 // V.row(2) = Vector2r(200, -100);
459 // V.row(3) = Vector2r(350, -100);
460 // V.row(4) = Vector2r(500, -100);
461 // V.row(5) = Vector2r(-100, 50);
462 // V.row(6) = Vector2r(50, 50);
463 // V.row(7) = Vector2r(200, 50);
464 // V.row(8) = Vector2r(350, 50);
465 // V.row(9) = Vector2r(500, 50);
466 // V.row(10) = Vector2r(-100, 200);
467 // V.row(11) = Vector2r(50, 200);
468 // V.row(12) = Vector2r(200, 200);
469 // V.row(13) = Vector2r(350, 200);
470 // V.row(14) = Vector2r(500, 200);
471 // V.row(15) = Vector2r(-100, 350);
472 // V.row(16) = Vector2r(50, 350);
473 // V.row(17) = Vector2r(200, 350);
474 // V.row(18) = Vector2r(350, 350);
475 // V.row(19) = Vector2r(500, 350);
476 // V.row(20) = Vector2r(-100, 500);
477 // V.row(21) = Vector2r(50, 500);
478 // V.row(22) = Vector2r(200, 500);
479 // V.row(23) = Vector2r(350, 500);
480 // V.row(24) = Vector2r(500, 500);
481 
482 
483 // RowVectors3l F;
484 // F.resize(32, 3);
485 // F.row(0) << 1, 2, 7;
486 // F.row(1) << 1, 7, 6;
487 // F.row(2) << 2, 3, 8;
488 // F.row(3) << 2, 8, 7;
489 // F.row(4) << 3, 4, 9;
490 // F.row(5) << 3, 9, 8;
491 // F.row(6) << 4, 5, 10;
492 // F.row(7) << 4, 10, 9;
493 // F.row(8) << 6, 7, 12;
494 // F.row(9) << 6, 12, 11;
495 // F.row(10) << 7, 8, 13;
496 // F.row(11) << 7, 13, 12;
497 // F.row(12) << 8, 9, 14;
498 // F.row(13) << 8, 14, 13;
499 // F.row(14) << 9, 10, 15;
500 // F.row(15) << 9, 15, 14;
501 // F.row(16) << 11, 12, 17;
502 // F.row(17) << 11, 17, 16;
503 // F.row(18) << 12, 13, 18;
504 // F.row(19) << 12, 18, 17;
505 // F.row(20) << 13, 14, 19;
506 // F.row(21) << 13, 19, 18;
507 // F.row(22) << 14, 15, 20;
508 // F.row(23) << 14, 20, 19;
509 // F.row(24) << 16, 17, 22;
510 // F.row(25) << 16, 22, 21;
511 // F.row(26) << 17, 18, 23;
512 // F.row(27) << 17, 23, 22;
513 // F.row(28) << 18, 19, 24;
514 // F.row(29) << 18, 24, 23;
515 // F.row(30) << 19, 20, 25;
516 // F.row(31) << 19, 25, 24;
517 
518 // for (int64_t i = 0; i < F.rows(); ++i) {
519 // for (int64_t j = 0; j < F.cols(); ++j) {
520 // F(i, j) -= 1;
521 // }
522 // }
523 
524 
525 // std::shared_ptr<DEBUG_TriMesh> tm = std::make_shared<DEBUG_TriMesh>();
526 // tm->initialize(F, false);
527 // mesh_utils::set_matrix_attribute(V, "vertices", PrimitiveType::Vertex, *tm);
528 
529 // cache.write_mesh(*tm, "trimesh");
530 
531 // wmtk::logger().info("read edges");
532 
533 // json edge_input =
534 // R"({
535 // "file": "/home/jiacheng/jiacheng/wmtk_hack/wildmeshing-toolkit/build_ei/siggraph_icon.msh",
536 // "name": "edgemesh",
537 // "ignore_z": true,
538 // "tetrahedron_attributes": []
539 // })"_json;
540 
541 // wmtk::components::input(Paths(), edge_input, cache);
542 
543 // // wmtk::logger().info("read tris");
544 
545 // // json tri_input =
546 // // R"({
547 // // "file": "/home/jiacheng/jiacheng/wmtk_hack/wildmeshing-toolkit/build_ei/background.msh",
548 // // "name": "trimesh",
549 // // "ignore_z": true,
550 // // "tetrahedron_attributes": []
551 // // })"_json;
552 
553 // // wmtk::components::input(Paths(), tri_input, cache);
554 
555 
556 // json input =
557 // R"({
558 // "edges": "edgemesh",
559 // "triangles": "trimesh",
560 // "output": "embedded_mesh"
561 // })"_json;
562 
563 // wmtk::logger().info("start edge insertion");
564 
565 // wmtk::components::edge_insertion(Paths(), input, cache);
566 
567 // wmtk::logger().info("end edge insertion");
568 
569 // json getall =
570 // R"({
571 // "input": "embedded_mesh",
572 // "name": "meshes"
573 // })"_json;
574 
575 // wmtk::components::get_all_meshes(Paths(), getall, cache);
576 
577 // json output = R"({
578 // "attributes": {
579 // "position": "vertices"
580 // },
581 // "file": "siggraph_icon_out",
582 // "input": "embedded_mesh"
583 // })"_json;
584 
585 // wmtk::components::output(Paths(), output, cache);
586 
587 // json output2 = R"({
588 // "attributes": {
589 // "position": "vertices"
590 // },
591 // "file": "siggraph_icon_edges_out",
592 // "input": "embedded_mesh.input_mesh"
593 // })"_json;
594 
595 // wmtk::components::output(Paths(), output2, cache);
596 // }