Wildmeshing Toolkit
test_component_tag_intersection.cpp
Go to the documentation of this file.
1 #include <catch2/catch_test_macros.hpp>
2 #include <nlohmann/json.hpp>
3 #include <tools/DEBUG_TetMesh.hpp>
4 #include <tools/DEBUG_TriMesh.hpp>
5 #include <tools/TetMesh_examples.hpp>
6 #include <tools/TriMesh_examples.hpp>
10 
12 using namespace wmtk;
13 using namespace tests;
14 
15 TEST_CASE("component_tag_intersection_options", "[components][tag_intersection]")
16 {
17  using namespace components::internal;
18 
19  json o = R"(
20  {
21  "input": "input_mesh",
22  "output": "output_mesh",
23  "attributes": {
24  "vertex_labels": [],
25  "edge_labels": [],
26  "face_labels": [],
27  "tetrahedron_labels": []
28  },
29  "values": {
30  "vertex_values": [],
31  "edge_values": [],
32  "face_values": [],
33  "tetrahedron_values": []
34  },
35  "output_attributes": {
36  "vertex_labels": [],
37  "edge_labels": [],
38  "face_labels": [],
39  "tetrahedron_labels": []
40  },
41  "output_values": {
42  "vertex_values": [],
43  "edge_values": [],
44  "face_values": [],
45  "tetrahedron_values": []
46  },
47  "pass_through": []
48  }
49  )"_json;
50 
51  CHECK_NOTHROW(o.get<TagIntersectionOptions>());
52 }
53 
54 TEST_CASE("component_tag_intersection_tri", "[components][tag_intersection]")
55 {
56  tests::DEBUG_TriMesh m = tests::edge_region_with_position();
57 
58  SECTION("two_face_tags_edgeintersection")
59  {
60  auto tag1 = m.register_attribute<int64_t>("tag1", PrimitiveType::Triangle, 1, 0);
61  auto tag2 = m.register_attribute<int64_t>("tag2", PrimitiveType::Triangle, 1, 0);
62 
63  {
64  auto tag1_acc = m.create_accessor<int64_t>(tag1);
65  auto tag2_acc = m.create_accessor<int64_t>(tag2);
66  tag1_acc.scalar_attribute(m.face_tuple_from_vids(1, 4, 5)) = 1;
67  tag2_acc.scalar_attribute(m.face_tuple_from_vids(4, 8, 5)) = 1;
68  }
69 
70  auto v_otag = m.register_attribute<int64_t>("v_otag", PrimitiveType::Vertex, 1, 0);
71  auto e_otag = m.register_attribute<int64_t>("e_otag", PrimitiveType::Edge, 1, 0);
72 
73  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> input_tags = {
74  {tag1, 1},
75  {tag2, 1}};
76  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> output_tags = {
77  {v_otag, 1},
78  {e_otag, 1}};
79 
81  tag_intersection.compute_intersection(m, input_tags, output_tags);
82 
83  auto v_otag_acc = m.create_accessor<int64_t>(v_otag);
84  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 5)) == 1);
85  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 4)) == 1);
86  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 4)) == 0);
87  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(8, 4)) == 0);
88 
89  auto e_otag_acc = m.create_accessor<int64_t>(e_otag);
90  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 5)) == 1);
91  }
92 
93  SECTION("two_face_tags_vertexintersection")
94  {
95  auto tag1 = m.register_attribute<int64_t>("tag1", PrimitiveType::Triangle, 1, 0);
96  auto tag2 = m.register_attribute<int64_t>("tag2", PrimitiveType::Triangle, 1, 0);
97 
98  {
99  auto tag1_acc = m.create_accessor<int64_t>(tag1);
100  auto tag2_acc = m.create_accessor<int64_t>(tag2);
101  tag1_acc.scalar_attribute(m.face_tuple_from_vids(3, 4, 7)) = 1;
102  tag2_acc.scalar_attribute(m.face_tuple_from_vids(4, 1, 5)) = 1;
103  }
104 
105  auto v_otag = m.register_attribute<int64_t>("v_otag", PrimitiveType::Vertex, 1, 0);
106  auto e_otag = m.register_attribute<int64_t>("e_otag", PrimitiveType::Edge, 1, 0);
107 
108  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> input_tags = {
109  {tag1, 1},
110  {tag2, 1}};
111  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> output_tags = {
112  {v_otag, 1},
113  {e_otag, 1}};
114 
116  tag_intersection.compute_intersection(m, input_tags, output_tags);
117 
118  auto v_otag_acc = m.create_accessor<int64_t>(v_otag);
119  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 5)) == 1);
120  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 4)) == 0);
121  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 3)) == 1);
122  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(3, 4)) == 0);
123 
124  auto e_otag_acc = m.create_accessor<int64_t>(e_otag);
125  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 1)) == 0);
126  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 5)) == 0);
127  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 7)) == 0);
128  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 3)) == 0);
129  }
130 
131  SECTION("four_blocks_tags_edgeintersection")
132  {
133  auto tag1 = m.register_attribute<int64_t>("tag1", PrimitiveType::Triangle, 1, 0);
134  auto tag2 = m.register_attribute<int64_t>("tag2", PrimitiveType::Triangle, 1, 0);
135  auto tag3 = m.register_attribute<int64_t>("tag3", PrimitiveType::Triangle, 1, 0);
136  auto tag4 = m.register_attribute<int64_t>("tag4", PrimitiveType::Triangle, 1, 0);
137 
138  {
139  auto tag1_acc = m.create_accessor<int64_t>(tag1);
140  auto tag2_acc = m.create_accessor<int64_t>(tag2);
141  auto tag3_acc = m.create_accessor<int64_t>(tag3);
142  auto tag4_acc = m.create_accessor<int64_t>(tag4);
143  tag1_acc.scalar_attribute(m.face_tuple_from_vids(3, 4, 7)) = 1;
144  tag2_acc.scalar_attribute(m.face_tuple_from_vids(4, 1, 5)) = 1;
145  tag3_acc.scalar_attribute(m.face_tuple_from_vids(4, 7, 8)) = 1;
146  tag3_acc.scalar_attribute(m.face_tuple_from_vids(8, 5, 4)) = 1;
147  tag4_acc.scalar_attribute(m.face_tuple_from_vids(3, 4, 0)) = 1;
148  tag4_acc.scalar_attribute(m.face_tuple_from_vids(4, 1, 0)) = 1;
149  }
150 
151  auto v_otag = m.register_attribute<int64_t>("v_otag", PrimitiveType::Vertex, 1, 0);
152  auto e_otag = m.register_attribute<int64_t>("e_otag", PrimitiveType::Edge, 1, 0);
153 
154  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> input_tags = {
155  {tag1, 1},
156  {tag2, 1},
157  {tag3, 1},
158  {tag4, 1}};
159  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> output_tags = {
160  {v_otag, 1},
161  {e_otag, 1}};
162 
164  tag_intersection.compute_intersection(m, input_tags, output_tags);
165 
166  auto v_otag_acc = m.create_accessor<int64_t>(v_otag);
167  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 1)) == 1);
168  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 4)) == 0);
169  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 4)) == 0);
170  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(7, 4)) == 0);
171  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(3, 4)) == 0);
172 
173  auto e_otag_acc = m.create_accessor<int64_t>(e_otag);
174  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(3, 4)) == 0);
175  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(7, 4)) == 0);
176  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 4)) == 0);
177  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 4)) == 0);
178  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 4)) == 0);
179  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(8, 4)) == 0);
180  }
181  SECTION("two_seperated_vertices_and_two_intersected_vertices")
182  {
183  auto tag1 = m.register_attribute<int64_t>("tag1", PrimitiveType::Vertex, 1, 0);
184  auto tag2 = m.register_attribute<int64_t>("tag2", PrimitiveType::Vertex, 1, 0);
185 
186  {
187  auto tag1_acc = m.create_accessor<int64_t>(tag1);
188  auto tag2_acc = m.create_accessor<int64_t>(tag2);
189  tag1_acc.scalar_attribute(m.edge_tuple_from_vids(4, 5)) = 1;
190  tag1_acc.scalar_attribute(m.edge_tuple_from_vids(1, 2)) = 1;
191  tag2_acc.scalar_attribute(m.edge_tuple_from_vids(5, 4)) = 1;
192  tag2_acc.scalar_attribute(m.edge_tuple_from_vids(1, 0)) = 1;
193  }
194 
195  auto v_otag = m.register_attribute<int64_t>("v_otag", PrimitiveType::Vertex, 1, 0);
196  auto e_otag = m.register_attribute<int64_t>("e_otag", PrimitiveType::Edge, 1, 0);
197 
198  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> input_tags = {
199  {tag1, 1},
200  {tag2, 1}};
201  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> output_tags = {
202  {v_otag, 1},
203  {e_otag, 1}};
204 
206  tag_intersection.compute_intersection(m, input_tags, output_tags);
207 
208  auto v_otag_acc = m.create_accessor<int64_t>(v_otag);
209  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 5)) == 0);
210  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 4)) == 0);
211  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 2)) == 1);
212 
213  auto e_otag_acc = m.create_accessor<int64_t>(e_otag);
214  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 5)) == 0);
215  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 4)) == 0);
216  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 5)) == 0);
217  }
218  SECTION("two_seperated_edges_and_two_intersected_edges")
219  {
220  auto tag1 = m.register_attribute<int64_t>("tag1", PrimitiveType::Edge, 1, 0);
221  auto tag2 = m.register_attribute<int64_t>("tag2", PrimitiveType::Edge, 1, 0);
222 
223  {
224  auto tag1_acc = m.create_accessor<int64_t>(tag1);
225  auto tag2_acc = m.create_accessor<int64_t>(tag2);
226  tag1_acc.scalar_attribute(m.edge_tuple_from_vids(0, 4)) = 1;
227  tag1_acc.scalar_attribute(m.edge_tuple_from_vids(4, 5)) = 1;
228  tag2_acc.scalar_attribute(m.edge_tuple_from_vids(2, 5)) = 1;
229  tag2_acc.scalar_attribute(m.edge_tuple_from_vids(5, 4)) = 1;
230  }
231 
232  auto v_otag = m.register_attribute<int64_t>("v_otag", PrimitiveType::Vertex, 1, 0);
233  auto e_otag = m.register_attribute<int64_t>("e_otag", PrimitiveType::Edge, 1, 0);
234 
235  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> input_tags = {
236  {tag1, 1},
237  {tag2, 1}};
238  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> output_tags = {
239  {v_otag, 1},
240  {e_otag, 1}};
241 
243  tag_intersection.compute_intersection(m, input_tags, output_tags);
244 
245  auto v_otag_acc = m.create_accessor<int64_t>(v_otag);
246  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 5)) == 1);
247  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 4)) == 1);
248  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 4)) == 0);
249  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(2, 5)) == 0);
250 
251  auto e_otag_acc = m.create_accessor<int64_t>(e_otag);
252  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 5)) == 1);
253  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 4)) == 0);
254  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(2, 5)) == 0);
255  }
256  SECTION("two_overlap_blocks")
257  {
258  auto tag1 = m.register_attribute<int64_t>("tag1", PrimitiveType::Triangle, 1, 0);
259  auto tag2 = m.register_attribute<int64_t>("tag2", PrimitiveType::Triangle, 1, 0);
260 
261  {
262  auto tag1_acc = m.create_accessor<int64_t>(tag1);
263  auto tag2_acc = m.create_accessor<int64_t>(tag2);
264  tag1_acc.scalar_attribute(m.face_tuple_from_vids(4, 1, 0)) = 1;
265  tag1_acc.scalar_attribute(m.face_tuple_from_vids(4, 5, 1)) = 1;
266  tag2_acc.scalar_attribute(m.face_tuple_from_vids(4, 5, 1)) = 1;
267  tag2_acc.scalar_attribute(m.face_tuple_from_vids(8, 5, 4)) = 1;
268  }
269 
270  auto v_otag = m.register_attribute<int64_t>("v_otag", PrimitiveType::Vertex, 1, 0);
271  auto e_otag = m.register_attribute<int64_t>("e_otag", PrimitiveType::Edge, 1, 0);
272  auto f_otag = m.register_attribute<int64_t>("f_otag", PrimitiveType::Triangle, 1, 0);
273 
274  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> input_tags = {
275  {tag1, 1},
276  {tag2, 1}};
277  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> output_tags = {
278  {v_otag, 1},
279  {e_otag, 1},
280  {f_otag, 1}};
281 
283  tag_intersection.compute_intersection(m, input_tags, output_tags);
284 
285  auto v_otag_acc = m.create_accessor<int64_t>(v_otag);
286  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 5)) == 1);
287  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 1)) == 1);
288  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 4)) == 1);
289  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 4)) == 0);
290  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(8, 5)) == 0);
291 
292  auto e_otag_acc = m.create_accessor<int64_t>(e_otag);
293  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 4)) == 1);
294  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 5)) == 1);
295  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 1)) == 1);
296  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 4)) == 0);
297  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 1)) == 0);
298  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(8, 4)) == 0);
299  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(8, 5)) == 0);
300 
301  auto f_otag_acc = m.create_accessor<int64_t>(f_otag);
302  CHECK(f_otag_acc.const_scalar_attribute(m.face_tuple_from_vids(4, 5, 1)) == 1);
303  CHECK(f_otag_acc.const_scalar_attribute(m.face_tuple_from_vids(0, 4, 1)) == 0);
304  CHECK(f_otag_acc.const_scalar_attribute(m.face_tuple_from_vids(8, 5, 4)) == 0);
305  }
306 }
307 
308 TEST_CASE("component_tag_intersection_tet", "[components][tag_intersection]")
309 {
310  tests_3d::DEBUG_TetMesh m = tests_3d::six_cycle_tets();
311  SECTION("seperated_vertices_and_intersected_vertices")
312  {
313  auto tag1 = m.register_attribute<int64_t>("tag1", PrimitiveType::Vertex, 1, 0);
314  auto tag2 = m.register_attribute<int64_t>("tag2", PrimitiveType::Vertex, 1, 0);
315 
316  {
317  auto tag1_acc = m.create_accessor<int64_t>(tag1);
318  auto tag2_acc = m.create_accessor<int64_t>(tag2);
319  tag1_acc.scalar_attribute(m.edge_tuple_from_vids(2, 3)) = 1;
320  tag1_acc.scalar_attribute(m.edge_tuple_from_vids(3, 2)) = 1;
321  tag2_acc.scalar_attribute(m.edge_tuple_from_vids(2, 3)) = 1;
322  tag2_acc.scalar_attribute(m.edge_tuple_from_vids(5, 3)) = 1;
323  }
324 
325  auto v_otag = m.register_attribute<int64_t>("v_otag", PrimitiveType::Vertex, 1, 0);
326  auto e_otag = m.register_attribute<int64_t>("e_otag", PrimitiveType::Edge, 1, 0);
327  auto f_otag = m.register_attribute<int64_t>("f_otag", PrimitiveType::Triangle, 1, 0);
328  auto t_otag = m.register_attribute<int64_t>("t_otag", PrimitiveType::Tetrahedron, 1, 0);
329 
330  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> input_tags = {
331  {tag1, 1},
332  {tag2, 1}};
333  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> output_tags = {
334  {v_otag, 1},
335  {e_otag, 1},
336  {f_otag, 1},
337  {t_otag, 1}};
338 
340  tag_intersection.compute_intersection(m, input_tags, output_tags);
341 
342  auto v_otag_acc = m.create_accessor<int64_t>(v_otag);
343  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(2, 3)) == 1);
344  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(3, 5)) == 0);
345  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 4)) == 0);
346 
347  auto e_otag_acc = m.create_accessor<int64_t>(e_otag);
348  for (const Tuple& e : m.get_all(PrimitiveType::Edge)) {
349  CHECK(e_otag_acc.const_scalar_attribute(e) == 0);
350  }
351 
352  auto f_otag_acc = m.create_accessor<int64_t>(f_otag);
353  for (const Tuple& f : m.get_all(PrimitiveType::Triangle)) {
354  CHECK(f_otag_acc.const_scalar_attribute(f) == 0);
355  }
356 
357  auto t_otag_acc = m.create_accessor<int64_t>(t_otag);
358  for (const Tuple& t : m.get_all(PrimitiveType::Tetrahedron)) {
359  CHECK(t_otag_acc.const_scalar_attribute(t) == 0);
360  }
361  }
362  SECTION("seperated_and_intersected_edges")
363  {
364  auto tag1 = m.register_attribute<int64_t>("tag1", PrimitiveType::Edge, 1, 0);
365  auto tag2 = m.register_attribute<int64_t>("tag2", PrimitiveType::Edge, 1, 0);
366 
367  {
368  auto tag1_acc = m.create_accessor<int64_t>(tag1);
369  auto tag2_acc = m.create_accessor<int64_t>(tag2);
370  tag1_acc.scalar_attribute(m.edge_tuple_from_vids(0, 1)) = 1;
371  tag1_acc.scalar_attribute(m.edge_tuple_from_vids(1, 2)) = 1;
372  tag1_acc.scalar_attribute(m.edge_tuple_from_vids(2, 3)) = 1;
373  tag2_acc.scalar_attribute(m.edge_tuple_from_vids(7, 5)) = 1;
374  tag2_acc.scalar_attribute(m.edge_tuple_from_vids(5, 3)) = 1;
375  tag2_acc.scalar_attribute(m.edge_tuple_from_vids(3, 2)) = 1;
376  }
377 
378  auto v_otag = m.register_attribute<int64_t>("v_otag", PrimitiveType::Vertex, 1, 0);
379  auto e_otag = m.register_attribute<int64_t>("e_otag", PrimitiveType::Edge, 1, 0);
380  auto f_otag = m.register_attribute<int64_t>("f_otag", PrimitiveType::Triangle, 1, 0);
381  auto t_otag = m.register_attribute<int64_t>("t_otag", PrimitiveType::Tetrahedron, 1, 0);
382 
383  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> input_tags = {
384  {tag1, 1},
385  {tag2, 1}};
386  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> output_tags = {
387  {v_otag, 1},
388  {e_otag, 1},
389  {f_otag, 1},
390  {t_otag, 1}};
391 
393  tag_intersection.compute_intersection(m, input_tags, output_tags);
394 
395  auto v_otag_acc = m.create_accessor<int64_t>(v_otag);
396  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(2, 3)) == 1);
397  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(3, 2)) == 1);
398  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 4)) == 0);
399  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 2)) == 0);
400  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 4)) == 0);
401  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(4, 0)) == 0);
402  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(6, 7)) == 0);
403  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(7, 6)) == 0);
404 
405  auto e_otag_acc = m.create_accessor<int64_t>(e_otag);
406  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(2, 3)) == 1);
407  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 3)) == 0);
408  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 2)) == 0);
409  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 3)) == 0);
410  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 2)) == 0);
411  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(5, 7)) == 0);
412  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 1)) == 0);
413 
414  auto f_otag_acc = m.create_accessor<int64_t>(f_otag);
415  for (const Tuple& f : m.get_all(PrimitiveType::Triangle)) {
416  CHECK(f_otag_acc.const_scalar_attribute(f) == 0);
417  }
418 
419  auto t_otag_acc = m.create_accessor<int64_t>(t_otag);
420  for (const Tuple& t : m.get_all(PrimitiveType::Tetrahedron)) {
421  CHECK(t_otag_acc.const_scalar_attribute(t) == 0);
422  }
423  }
424  SECTION("two_blocks_contact")
425  {
426  auto tag1 = m.register_attribute<int64_t>("tag1", PrimitiveType::Tetrahedron, 1, 0);
427  auto tag2 = m.register_attribute<int64_t>("tag2", PrimitiveType::Tetrahedron, 1, 0);
428 
429  {
430  auto tag1_acc = m.create_accessor<int64_t>(tag1);
431  auto tag2_acc = m.create_accessor<int64_t>(tag2);
432  tag1_acc.scalar_attribute(m.tet_tuple_from_vids(0, 1, 2, 3)) = 1;
433  tag1_acc.scalar_attribute(m.tet_tuple_from_vids(1, 2, 3, 6)) = 1;
434  tag2_acc.scalar_attribute(m.tet_tuple_from_vids(0, 2, 3, 4)) = 1;
435  tag2_acc.scalar_attribute(m.tet_tuple_from_vids(2, 3, 4, 5)) = 1;
436  }
437 
438  auto v_otag = m.register_attribute<int64_t>("v_otag", PrimitiveType::Vertex, 1, 0);
439  auto e_otag = m.register_attribute<int64_t>("e_otag", PrimitiveType::Edge, 1, 0);
440  auto f_otag = m.register_attribute<int64_t>("f_otag", PrimitiveType::Triangle, 1, 0);
441  auto t_otag = m.register_attribute<int64_t>("t_otag", PrimitiveType::Tetrahedron, 1, 0);
442 
443  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> input_tags = {
444  {tag1, 1},
445  {tag2, 1}};
446  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> output_tags = {
447  {v_otag, 1},
448  {e_otag, 1},
449  {f_otag, 1},
450  {t_otag, 1}};
451 
453  tag_intersection.compute_intersection(m, input_tags, output_tags);
454 
455  auto v_otag_acc = m.create_accessor<int64_t>(v_otag);
456  int sum = 0;
457  for (const Tuple& v : m.get_all(PrimitiveType::Vertex)) {
458  if (v_otag_acc.const_scalar_attribute(v) == 1) {
459  ++sum;
460  }
461  }
462  CHECK(sum == 3);
463  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(2, 3)) == 1);
464  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(3, 2)) == 1);
465  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 2)) == 1);
466 
467  auto e_otag_acc = m.create_accessor<int64_t>(e_otag);
468  sum = 0;
469  for (const Tuple& e : m.get_all(PrimitiveType::Edge)) {
470  if (e_otag_acc.const_scalar_attribute(e) == 1) {
471  ++sum;
472  }
473  }
474  CHECK(sum == 3);
475  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(2, 3)) == 1);
476  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 3)) == 1);
477  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 2)) == 1);
478 
479  auto f_otag_acc = m.create_accessor<int64_t>(f_otag);
480  sum = 0;
481  for (const Tuple& f : m.get_all(PrimitiveType::Triangle)) {
482  if (f_otag_acc.const_scalar_attribute(f) == 1) {
483  ++sum;
484  }
485  }
486  CHECK(sum == 1);
487  CHECK(f_otag_acc.const_scalar_attribute(m.face_tuple_from_vids(0, 2, 3)) == 1);
488 
489  auto t_otag_acc = m.create_accessor<int64_t>(t_otag);
490  for (const Tuple& t : m.get_all(PrimitiveType::Tetrahedron)) {
491  CHECK(t_otag_acc.const_scalar_attribute(t) == 0);
492  }
493  }
494  SECTION("two_blocks_intersect")
495  {
496  auto tag1 = m.register_attribute<int64_t>("tag1", PrimitiveType::Tetrahedron, 1, 0);
497  auto tag2 = m.register_attribute<int64_t>("tag2", PrimitiveType::Tetrahedron, 1, 0);
498 
499  {
500  auto tag1_acc = m.create_accessor<int64_t>(tag1);
501  auto tag2_acc = m.create_accessor<int64_t>(tag2);
502  tag1_acc.scalar_attribute(m.tet_tuple_from_vids(0, 1, 2, 3)) = 1;
503  tag1_acc.scalar_attribute(m.tet_tuple_from_vids(1, 2, 3, 6)) = 1;
504  tag2_acc.scalar_attribute(m.tet_tuple_from_vids(0, 2, 3, 4)) = 1;
505  tag2_acc.scalar_attribute(m.tet_tuple_from_vids(2, 3, 4, 5)) = 1;
506  tag2_acc.scalar_attribute(m.tet_tuple_from_vids(0, 1, 2, 3)) = 1;
507  }
508 
509  auto v_otag = m.register_attribute<int64_t>("v_otag", PrimitiveType::Vertex, 1, 0);
510  auto e_otag = m.register_attribute<int64_t>("e_otag", PrimitiveType::Edge, 1, 0);
511  auto f_otag = m.register_attribute<int64_t>("f_otag", PrimitiveType::Triangle, 1, 0);
512  auto t_otag = m.register_attribute<int64_t>("t_otag", PrimitiveType::Tetrahedron, 1, 0);
513 
514  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> input_tags = {
515  {tag1, 1},
516  {tag2, 1}};
517  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> output_tags = {
518  {v_otag, 1},
519  {e_otag, 1},
520  {f_otag, 1},
521  {t_otag, 1}};
522 
524  tag_intersection.compute_intersection(m, input_tags, output_tags);
525 
526  auto v_otag_acc = m.create_accessor<int64_t>(v_otag);
527  int sum = 0;
528  for (const Tuple& v : m.get_all(PrimitiveType::Vertex)) {
529  if (v_otag_acc.const_scalar_attribute(v) == 1) {
530  ++sum;
531  }
532  }
533  CHECK(sum == 4);
534  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(2, 3)) == 1);
535  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(3, 2)) == 1);
536  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 2)) == 1);
537  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 2)) == 1);
538 
539  auto e_otag_acc = m.create_accessor<int64_t>(e_otag);
540  sum = 0;
541  for (const Tuple& e : m.get_all(PrimitiveType::Edge)) {
542  if (e_otag_acc.const_scalar_attribute(e) == 1) {
543  ++sum;
544  }
545  }
546  CHECK(sum == 6);
547  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 1)) == 1);
548  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 2)) == 1);
549  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(0, 3)) == 1);
550  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(1, 2)) == 1);
551  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(2, 3)) == 1);
552  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(3, 1)) == 1);
553 
554  auto f_otag_acc = m.create_accessor<int64_t>(f_otag);
555  sum = 0;
556  for (const Tuple& f : m.get_all(PrimitiveType::Triangle)) {
557  if (f_otag_acc.const_scalar_attribute(f) == 1) {
558  ++sum;
559  }
560  }
561  CHECK(sum == 4);
562  CHECK(f_otag_acc.const_scalar_attribute(m.face_tuple_from_vids(0, 1, 2)) == 1);
563  CHECK(f_otag_acc.const_scalar_attribute(m.face_tuple_from_vids(0, 1, 3)) == 1);
564  CHECK(f_otag_acc.const_scalar_attribute(m.face_tuple_from_vids(0, 2, 3)) == 1);
565  CHECK(f_otag_acc.const_scalar_attribute(m.face_tuple_from_vids(1, 2, 3)) == 1);
566 
567  auto t_otag_acc = m.create_accessor<int64_t>(t_otag);
568  sum = 0;
569  for (const Tuple& t : m.get_all(PrimitiveType::Tetrahedron)) {
570  if (t_otag_acc.const_scalar_attribute(t) == 1) {
571  ++sum;
572  }
573  }
574  CHECK(sum == 1);
575  CHECK(t_otag_acc.const_scalar_attribute(m.tet_tuple_from_vids(0, 1, 2, 3)) == 1);
576  }
577  SECTION("three_blocks")
578  {
579  auto tag1 = m.register_attribute<int64_t>("tag1", PrimitiveType::Tetrahedron, 1, 0);
580  auto tag2 = m.register_attribute<int64_t>("tag2", PrimitiveType::Tetrahedron, 1, 0);
581  auto tag3 = m.register_attribute<int64_t>("tag3", PrimitiveType::Tetrahedron, 1, 0);
582 
583  {
584  auto tag1_acc = m.create_accessor<int64_t>(tag1);
585  auto tag2_acc = m.create_accessor<int64_t>(tag2);
586  auto tag3_acc = m.create_accessor<int64_t>(tag3);
587  tag1_acc.scalar_attribute(m.tet_tuple_from_vids(0, 1, 2, 3)) = 1;
588  tag1_acc.scalar_attribute(m.tet_tuple_from_vids(1, 2, 3, 6)) = 1;
589  tag2_acc.scalar_attribute(m.tet_tuple_from_vids(0, 2, 3, 4)) = 1;
590  tag2_acc.scalar_attribute(m.tet_tuple_from_vids(2, 3, 4, 5)) = 1;
591  tag3_acc.scalar_attribute(m.tet_tuple_from_vids(2, 3, 6, 7)) = 1;
592  tag3_acc.scalar_attribute(m.tet_tuple_from_vids(2, 3, 5, 7)) = 1;
593  }
594 
595  auto v_otag = m.register_attribute<int64_t>("v_otag", PrimitiveType::Vertex, 1, 0);
596  auto e_otag = m.register_attribute<int64_t>("e_otag", PrimitiveType::Edge, 1, 0);
597  auto f_otag = m.register_attribute<int64_t>("f_otag", PrimitiveType::Triangle, 1, 0);
598  auto t_otag = m.register_attribute<int64_t>("t_otag", PrimitiveType::Tetrahedron, 1, 0);
599 
600  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> input_tags = {
601  {tag1, 1},
602  {tag2, 1},
603  {tag3, 1}};
604  std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>> output_tags = {
605  {v_otag, 1},
606  {e_otag, 1},
607  {f_otag, 1},
608  {t_otag, 1}};
609 
611  tag_intersection.compute_intersection(m, input_tags, output_tags);
612 
613  auto v_otag_acc = m.create_accessor<int64_t>(v_otag);
614  int sum = 0;
615  for (const Tuple& v : m.get_all(PrimitiveType::Vertex)) {
616  if (v_otag_acc.const_scalar_attribute(v) == 1) {
617  ++sum;
618  }
619  }
620  CHECK(sum == 2);
621  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(2, 3)) == 1);
622  CHECK(v_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(3, 2)) == 1);
623 
624  auto e_otag_acc = m.create_accessor<int64_t>(e_otag);
625  sum = 0;
626  for (const Tuple& e : m.get_all(PrimitiveType::Edge)) {
627  if (e_otag_acc.const_scalar_attribute(e) == 1) {
628  ++sum;
629  }
630  }
631  CHECK(sum == 1);
632  CHECK(e_otag_acc.const_scalar_attribute(m.edge_tuple_from_vids(2, 3)) == 1);
633 
634  auto f_otag_acc = m.create_accessor<int64_t>(f_otag);
635  sum = 0;
636  for (const Tuple& f : m.get_all(PrimitiveType::Triangle)) {
637  if (f_otag_acc.const_scalar_attribute(f) == 1) {
638  ++sum;
639  }
640  }
641  CHECK(sum == 0);
642 
643  auto t_otag_acc = m.create_accessor<int64_t>(t_otag);
644  for (const Tuple& t : m.get_all(PrimitiveType::Tetrahedron)) {
645  CHECK(t_otag_acc.const_scalar_attribute(t) == 0);
646  }
647  }
648 }
void tag_intersection(const utils::Paths &paths, const nlohmann::json &j, io::Cache &cache)
Definition: Accessor.hpp:6
nlohmann::json json
TEST_CASE("component_tag_intersection_options", "[components][tag_intersection]")
nlohmann::json json
Definition: input.cpp:9