|
25 | 25 | This method can be used both for the evaluation of plane sections and for |
26 | 26 | the evaluation of function isosurfaces. |
27 | 27 | """ |
28 | | -function tet_x_plane!( |
| 28 | +function assign_coordinates_at_point_in_plane!( |
29 | 29 | ixcoord, |
30 | 30 | ixvalues, |
31 | | - pointlist, |
| 31 | + coordinates, |
| 32 | + function_values, |
| 33 | + node_index, |
| 34 | + intersection_count |
| 35 | + ) |
| 36 | + |
| 37 | + @views ixcoord[:, intersection_count] .= coordinates[:, node_index] |
| 38 | + ixvalues[intersection_count] = function_values[node_index] |
| 39 | + |
| 40 | + return nothing |
| 41 | + |
| 42 | +end |
| 43 | + |
| 44 | +function assign_coordinates_at_intersection!( |
| 45 | + ixcoord, |
| 46 | + ixvalues, |
| 47 | + coordinates, |
| 48 | + function_values, |
| 49 | + planeq_values_start, |
| 50 | + planeq_values_end, |
| 51 | + node_index_start, |
| 52 | + node_index_end, |
| 53 | + intersection_count |
| 54 | + ) |
| 55 | + |
| 56 | + t = planeq_values_start / (planeq_values_start - planeq_values_end) |
| 57 | + @views @. ixcoord[:, intersection_count] = coordinates[:, node_index_start] + t * (coordinates[:, node_index_end] - coordinates[:, node_index_start]) |
| 58 | + ixvalues[intersection_count] = function_values[node_index_start] + t * (function_values[node_index_end] - function_values[node_index_start]) |
| 59 | + |
| 60 | + return nothing |
| 61 | +end |
| 62 | + |
| 63 | +function calculate_plane_tetrahedron_intersection!( |
| 64 | + ixcoord, |
| 65 | + ixvalues, |
| 66 | + coordinates, |
32 | 67 | node_indices, |
33 | 68 | planeq_values, |
34 | 69 | function_values; |
35 | 70 | tol = 0.0 |
36 | 71 | ) |
37 | 72 |
|
38 | | - # If all nodes lie on one side of the plane, no intersection |
39 | | - @fastmath if ( |
40 | | - mapreduce(a -> a < -tol, *, planeq_values) || |
41 | | - mapreduce(a -> a > tol, *, planeq_values) |
42 | | - ) |
43 | | - return 0 |
44 | | - end |
45 | | - # Interpolate coordinates and function_values according to |
46 | | - # evaluation of the plane equation |
47 | | - intersection_count = 0 |
48 | | - # List to check whether a node has already been visited, when checking for possible intersections |
49 | | - visited_list = @MArray zeros(Bool, 4) |
50 | | - @inbounds @simd for n1 in 1:3 |
51 | | - N1 = node_indices[n1] |
52 | | - @inbounds @fastmath @simd for n2 in (n1 + 1):4 |
53 | | - N2 = node_indices[n2] |
54 | 73 |
|
55 | | - if planeq_values[n1] * planeq_values[n2] < tol && !visited_list[n1] && !visited_list[n2] |
| 74 | + amount_intersections = 0 |
56 | 75 |
|
57 | | - abs(planeq_values[n1]) < tol && (visited_list[n1] = true) |
58 | | - abs(planeq_values[n2]) < tol && (visited_list[n2] = true) |
59 | | - |
60 | | - intersection_count += 1 |
61 | | - t = planeq_values[n1] / (planeq_values[n1] - planeq_values[n2]) |
62 | | - ixcoord[1, intersection_count] = pointlist[1, N1] + t * (pointlist[1, N2] - pointlist[1, N1]) |
63 | | - ixcoord[2, intersection_count] = pointlist[2, N1] + t * (pointlist[2, N2] - pointlist[2, N1]) |
64 | | - ixcoord[3, intersection_count] = pointlist[3, N1] + t * (pointlist[3, N2] - pointlist[3, N1]) |
65 | | - ixvalues[intersection_count] = function_values[N1] + t * (function_values[N2] - function_values[N1]) |
| 76 | + @inbounds for n1 in 1:4 |
| 77 | + N1 = node_indices[n1] |
| 78 | + if abs(planeq_values[n1]) < tol |
| 79 | + amount_intersections += 1 |
| 80 | + assign_coordinates_at_point_in_plane!(ixcoord, ixvalues, coordinates, function_values, N1, amount_intersections) |
| 81 | + else |
| 82 | + for n2 in (n1 + 1):4 |
| 83 | + N2 = node_indices[n2] |
| 84 | + if (abs(planeq_values[n2]) < tol) # We do not allow the 2nd node to be in the plane |
| 85 | + continue |
| 86 | + end |
| 87 | + if planeq_values[n1] * planeq_values[n2] < tol^2 |
| 88 | + amount_intersections += 1 |
| 89 | + assign_coordinates_at_intersection!(ixcoord, ixvalues, coordinates, function_values, planeq_values[n1], planeq_values[n2], N1, N2, amount_intersections) |
| 90 | + end |
66 | 91 | end |
67 | 92 | end |
68 | 93 | end |
69 | | - if intersection_count > 4 |
70 | | - @warn "computed $intersection_count intersection points of a tetrahedron and a plane. Expected at most 4." |
| 94 | + |
| 95 | + if amount_intersections > 4 |
| 96 | + @warn "computed $(amount_intersections) intersection points of a tetrahedron and a plane. Expected at most 4." |
71 | 97 | end |
72 | | - return intersection_count |
| 98 | + return amount_intersections |
73 | 99 | end |
74 | 100 |
|
75 | 101 | """ |
@@ -231,7 +257,7 @@ function marching_tetrahedra( |
231 | 257 | planeq[2] = all_planeq[node_indices[2]] |
232 | 258 | planeq[3] = all_planeq[node_indices[3]] |
233 | 259 | planeq[4] = all_planeq[node_indices[4]] |
234 | | - nxs = tet_x_plane!( |
| 260 | + nxs = calculate_plane_tetrahedron_intersection!( |
235 | 261 | ixcoord, |
236 | 262 | ixvalues, |
237 | 263 | coord, |
|
0 commit comments