Skip to content

Commit c8b64c8

Browse files
committed
Implementation of function / if-statements to assess number of intersections of plane and tetrahedra
Currently causes problems when trying to plot more complex examples than unit-cubes and simple planes
1 parent 344056b commit c8b64c8

3 files changed

Lines changed: 50 additions & 9 deletions

File tree

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"

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: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ function tet_x_plane!(
3535
tol = 0.0
3636
)
3737

38+
39+
debug = false
40+
3841
# If all nodes lie on one side of the plane, no intersection
3942
@fastmath if (
4043
mapreduce(a -> a < -tol, *, planeq_values) ||
@@ -44,23 +47,32 @@ function tet_x_plane!(
4447
end
4548
# Interpolate coordinates and function_values according to
4649
# evaluation of the plane equation
47-
nxs = 0
50+
intersection_counter = 0
51+
prohibitedList = @MArray zeros(Bool, 4)
52+
debug && @info node_indices
4853
@inbounds @simd for n1 in 1:3
4954
N1 = node_indices[n1]
5055
@inbounds @fastmath @simd for n2 in (n1 + 1):4
5156
N2 = node_indices[n2]
5257
if planeq_values[n1] != planeq_values[n2] &&
53-
planeq_values[n1] * planeq_values[n2] < tol
54-
nxs += 1
58+
planeq_values[n1] * planeq_values[n2] < tol #&&
59+
#abs(planeq_values[n2]) > tol
60+
#=if abs(planeq_values[n1] - planeq_values[n2]) > tol && prohibitedList[n1] == false && prohibitedList[n2] == false
61+
if planeq_values[n2] == 0
62+
prohibitedList[n2] = true
63+
end=#
64+
intersection_counter += 1
5565
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])
66+
ixcoord[1, intersection_counter] = pointlist[1, N1] + t * (pointlist[1, N2] - pointlist[1, N1])
67+
ixcoord[2, intersection_counter] = pointlist[2, N1] + t * (pointlist[2, N2] - pointlist[2, N1])
68+
ixcoord[3, intersection_counter] = pointlist[3, N1] + t * (pointlist[3, N2] - pointlist[3, N1])
69+
ixvalues[intersection_counter] = function_values[N1] + t * (function_values[N2] - function_values[N1])
70+
debug && @show ixcoord
6071
end
6172
end
6273
end
63-
return nxs
74+
debug && @info "amount of intersections: " intersection_counter
75+
return intersection_counter
6476
end
6577

6678
"""
@@ -190,7 +202,7 @@ function marching_tetrahedra(
190202

191203
function pushtris(ns, ixcoord, ixvalues)
192204
# number of intersection points can be 3 or 4
193-
return if ns >= 3
205+
if ns >= 3
194206
last_i = length(all_ixvalues)
195207
for is in 1:ns
196208
@views push!(all_ixcoord, ixcoord[:, is])
@@ -201,6 +213,7 @@ function marching_tetrahedra(
201213
push!(all_ixfaces, (last_i + 3, last_i + 2, last_i + 4))
202214
end
203215
end
216+
return nothing
204217
end
205218

206219
for igrid in 1:length(allcoords)
@@ -407,3 +420,28 @@ function marching_triangles(
407420
end
408421
return points, adjacencies, values
409422
end
423+
424+
425+
"""
426+
Function to estimate amount of intersections of plane and tetrahedron
427+
This was used as a testing function and is not used otherwise
428+
"""
429+
430+
function getAmountOfIntersections(planeq_values, tol)
431+
prohibitedList = @MArray zeros(Bool, 4)
432+
amountOfIntersections = 0
433+
for i in 1:(length(planeq_values) - 1)
434+
for j in (i + 1):length(planeq_values)
435+
#=if planeq_values[n1] != planeq_values[n2] &&
436+
planeq_values[n1] * planeq_values[n2] < tol &&
437+
abs(planeq_values[n2]) > tol =#
438+
if abs(planeq_values[i] - planeq_values[j]) > tol && prohibitedList[i] == false && prohibitedList[j] == false
439+
amountOfIntersections += 1
440+
if planeq_values[j] == 0
441+
prohibitedList[j] = true
442+
end
443+
end
444+
end
445+
end
446+
return amountOfIntersections
447+
end

0 commit comments

Comments
 (0)