Skip to content

Commit 700714d

Browse files
committed
Fixed issue of missing shapes in sliceplots of given grids and planes
Fixed error in tet_x_plane function in marching.jl which incorrectly assessed intersections between tetrahedron edges and plane Fixed calculation for intersections Adjusted the logic which determines an intersection between tetrahedron and plane Added new test case for specific data which caused issues beforehand Adjusted index.md for documentation Adjusting files to make documentation buildable Will be squashed later Changed position of docstring for Documentation Further adjustments for the documentation Changed the change log
1 parent 1e6ccd7 commit 700714d

File tree

6 files changed

+103
-30
lines changed

6 files changed

+103
-30
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## Future Release
6+
7+
### Fixed
8+
9+
- Renamed `tet_x_plane!()` to `calculate_plane_tetrahedron_intersection!()`
10+
- Adjusted logic in `calculate_plane_tetrahedron_intersection!()` to better determine intersection
11+
- Separated functionality of intersection determination and coordinate assignment in `calculate_plane_tetrahedron_intersection!()` into subfunctions
12+
513
## [3.0.0] - 2025-03-03
614

715
### Changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ version = "3.0.0"
77
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
88
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
99
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
10+
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1011
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
1112

1213
[compat]
1314
ColorSchemes = "3"
1415
Colors = "0.12, 0.13"
1516
DocStringExtensions = "0.8, 0.9"
17+
StaticArrays = "1.9.13"
1618
StaticArraysCore = "1.4"
1719
julia = "1.6"

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,5 @@ makeisolevels(collect(0:0.1:10), 1, (1,-1),nothing)
122122
## Private API
123123

124124
```@docs
125-
GridVisualizeTools.tet_x_plane!
125+
GridVisualizeTools.calculate_plane_tetrahedron_intersection!
126126
```

src/GridVisualizeTools.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import ColorSchemes
1010

1111
using DocStringExtensions: SIGNATURES, TYPEDEF, TYPEDSIGNATURES
1212
using StaticArraysCore: SVector
13+
using StaticArrays: @MArray
1314

1415
include("colors.jl")
1516
export region_cmap, bregion_cmap, rgbtuple, rgbcolor

src/marching.jl

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
1+
function assign_coordinates_at_point_in_plane!(
2+
ixcoord,
3+
ixvalues,
4+
coordinates,
5+
function_values,
6+
node_index,
7+
intersection_count
8+
)
9+
10+
@views ixcoord[:, intersection_count] .= coordinates[:, node_index]
11+
ixvalues[intersection_count] = function_values[node_index]
12+
13+
return nothing
14+
15+
end
16+
17+
function assign_coordinates_at_intersection!(
18+
ixcoord,
19+
ixvalues,
20+
coordinates,
21+
function_values,
22+
planeq_values_start,
23+
planeq_values_end,
24+
node_index_start,
25+
node_index_end,
26+
intersection_count
27+
)
28+
29+
t = planeq_values_start / (planeq_values_start - planeq_values_end)
30+
@views @. ixcoord[:, intersection_count] = coordinates[:, node_index_start] + t * (coordinates[:, node_index_end] - coordinates[:, node_index_start])
31+
ixvalues[intersection_count] = function_values[node_index_start] + t * (function_values[node_index_end] - function_values[node_index_start])
32+
33+
return nothing
34+
end
35+
36+
137
"""
238
$(SIGNATURES)
339
Calculate intersections between tetrahedron with given piecewise linear
@@ -10,8 +46,8 @@
1046
and the plane.
1147
1248
Input:
13-
- pointlist: 3xN array of grid point coordinates
14-
- node_indices: 4 element array of node indices (pointing into pointlist and function_values)
49+
- coordinates: 3xN array of grid point coordinates
50+
- node_indices: 4 element array of node indices (pointing into coordinates and function_values)
1551
- planeq_values: 4 element array of plane equation evaluated at the node coordinates
1652
- function_values: N element array of function values
1753
@@ -20,47 +56,47 @@
2056
- ixvalues: 4 element array of function values at plane - tetdedge intersections
2157
2258
Returns:
23-
- nxs,ixcoord,ixvalues
59+
- amount_intersections,ixcoord,ixvalues
2460
2561
This method can be used both for the evaluation of plane sections and for
2662
the evaluation of function isosurfaces.
2763
"""
28-
function tet_x_plane!(
64+
function calculate_plane_tetrahedron_intersection!(
2965
ixcoord,
3066
ixvalues,
31-
pointlist,
67+
coordinates,
3268
node_indices,
3369
planeq_values,
3470
function_values;
3571
tol = 0.0
3672
)
3773

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-
nxs = 0
48-
@inbounds @simd for n1 in 1:3
74+
75+
amount_intersections = 0
76+
77+
@inbounds for n1 in 1:4
4978
N1 = node_indices[n1]
50-
@inbounds @fastmath @simd for n2 in (n1 + 1):4
51-
N2 = node_indices[n2]
52-
if planeq_values[n1] != planeq_values[n2] &&
53-
planeq_values[n1] * planeq_values[n2] < tol
54-
nxs += 1
55-
t = planeq_values[n1] / (planeq_values[n1] - planeq_values[n2])
56-
ixcoord[1, nxs] = pointlist[1, N1] + t * (pointlist[1, N2] - pointlist[1, N1])
57-
ixcoord[2, nxs] = pointlist[2, N1] + t * (pointlist[2, N2] - pointlist[2, N1])
58-
ixcoord[3, nxs] = pointlist[3, N1] + t * (pointlist[3, N2] - pointlist[3, N1])
59-
ixvalues[nxs] = function_values[N1] + t * (function_values[N2] - function_values[N1])
79+
if abs(planeq_values[n1]) < tol
80+
amount_intersections += 1
81+
assign_coordinates_at_point_in_plane!(ixcoord, ixvalues, coordinates, function_values, N1, amount_intersections)
82+
else
83+
for n2 in (n1 + 1):4
84+
N2 = node_indices[n2]
85+
if (abs(planeq_values[n2]) < tol) # We do not allow the 2nd node to be in the plane
86+
continue
87+
end
88+
if planeq_values[n1] * planeq_values[n2] < tol^2
89+
amount_intersections += 1
90+
assign_coordinates_at_intersection!(ixcoord, ixvalues, coordinates, function_values, planeq_values[n1], planeq_values[n2], N1, N2, amount_intersections)
91+
end
6092
end
6193
end
6294
end
63-
return nxs
95+
96+
if amount_intersections > 4
97+
@warn "computed $(amount_intersections) intersection points of a tetrahedron and a plane. Expected at most 4."
98+
end
99+
return amount_intersections
64100
end
65101

66102
"""
@@ -190,7 +226,7 @@ function marching_tetrahedra(
190226

191227
function pushtris(ns, ixcoord, ixvalues)
192228
# number of intersection points can be 3 or 4
193-
return if ns >= 3
229+
if ns >= 3
194230
last_i = length(all_ixvalues)
195231
for is in 1:ns
196232
@views push!(all_ixcoord, ixcoord[:, is])
@@ -201,6 +237,7 @@ function marching_tetrahedra(
201237
push!(all_ixfaces, (last_i + 3, last_i + 2, last_i + 4))
202238
end
203239
end
240+
return nothing
204241
end
205242

206243
for igrid in 1:length(allcoords)
@@ -221,7 +258,7 @@ function marching_tetrahedra(
221258
planeq[2] = all_planeq[node_indices[2]]
222259
planeq[3] = all_planeq[node_indices[3]]
223260
planeq[4] = all_planeq[node_indices[4]]
224-
nxs = tet_x_plane!(
261+
nxs = calculate_plane_tetrahedron_intersection!(
225262
ixcoord,
226263
ixvalues,
227264
coord,

test/runtests.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,31 @@ using Test, Documenter, GridVisualizeTools, ColorTypes, Colors
33
DocMeta.setdocmeta!(GridVisualizeTools, :DocTestSetup, :(using GridVisualizeTools, ColorTypes, Colors); recursive = true)
44
doctest(GridVisualizeTools)
55

6+
7+
@testset "calculate_plane_tetrahedron_intersection" begin
8+
#Testing amount of intersected edges of (x,y,z)-tetrahedron (0,0,0),(1,0,0),(1,1,0),(1,1,1) with plane x+y-1=0
9+
@test GridVisualizeTools.calculate_plane_tetrahedron_intersection!(
10+
[0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0],
11+
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
12+
[0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0; 0.0 0.0 1.0 1.0 0.0 0.0 1.0 1.0; 0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0],
13+
Int32[1, 2, 4, 8],
14+
[-1.0, 0.0, 1.0, 1.0],
15+
[0, 0, 0, 0, 0, 0, 0, 1],
16+
tol = 1.0e-12
17+
) == 3
18+
#Testing amount of intersected edges for specific tetrahedron with plane x = 0.5
19+
@test GridVisualizeTools.calculate_plane_tetrahedron_intersection!(
20+
[0.5 0.5 0.500000001260275 0.5000000012855993 0.0 0.0; 0.7 1.0 0.13480492277555536 0.8372051924096586 0.0 0.0; 0.0 0.1 0.19515864670162444 0.18583544507073008 0.0 0.0],
21+
[1.460741148435986e-32, 1.2130506551371849e-32, 0.19103133044823084, 0.22244570933305352, 0.0, 0.0],
22+
[0.5 0.5 0.48305 0.55059; 0.7165 0.8 0.76944 0.76519; 0.12501 0.0 0.16147 0.16147],
23+
Int32[1, 2, 3, 4],
24+
[0.0, 0.0, -0.016950000077486038, 0.05059000104665756],
25+
[0.18823234602961633, 1.519472645376028e-32, 0.2384620788839228, 0.2550147563453821],
26+
tol = 1.0e-12
27+
) == 3
28+
end
29+
30+
631
if isdefined(Docs, :undocumented_names) # >=1.11
732
@testset "UndocumentedNames" begin
833
@test isempty(Docs.undocumented_names(GridVisualizeTools))

0 commit comments

Comments
 (0)