124124Checks if a voxel has faces. Should be false for most voxels.
125125This function should be made as fast as possible.
126126"""
127- function hasFaces (vals:: Vector{T } , iso:: T ) where T <: Real
127+ function hasFaces (vals:: Vector{<:Real } , iso:: Real )
128128 @inbounds v = vals[1 ]
129129 if v < iso
130130 @inbounds for i= 2 : 8
141141"""
142142Determines which case in the triangle table we are dealing with
143143"""
144- function tetIx (tIx:: IType , vals:: Vector{T } , iso:: T , vxidx:: VoxelIndices{IType} ) where {T <: Real , IType <: Integer }
144+ function tetIx (tIx:: IType , vals:: Vector{<:Real } , iso:: Real , vxidx:: VoxelIndices{IType} ) where {IType <: Integer }
145145 @inbounds v1 = vals[vxidx. subTets[tIx][1 ]]
146146 @inbounds v2 = vals[vxidx. subTets[tIx][2 ]]
147147 @inbounds v3 = vals[vxidx. subTets[tIx][3 ]]
@@ -160,7 +160,7 @@ regardless of which of its neighboring voxels is asking for it) in order
160160for vertex sharing to be implemented properly.
161161"""
162162function vertId (e:: IType , x:: IType , y:: IType , z:: IType ,
163- nx:: IType , ny:: IType , vxidx:: VoxelIndices{IType} ) where IType <: Integer
163+ nx:: IType , ny:: IType , vxidx:: VoxelIndices{IType} ) where { IType <: Integer }
164164 @inbounds dx, dy, dz = vxidx. voxCrnrPos[vxidx. voxEdgeCrnrs[e][1 ]]
165165 vxidx. voxEdgeDir[e]+ 7 * (x- 1 + dx+ nx* (y- 1 + dy+ ny* (z- 1 + dz)))
166166end
@@ -172,18 +172,17 @@ eps represents the "bump" factor to keep vertices away from voxel
172172corners (thereby preventing degeneracies).
173173"""
174174function vertPos (e:: IType , x:: IType , y:: IType , z:: IType ,
175- vals:: Vector{T} , iso:: T , eps:: T , vxidx:: VoxelIndices{IType} ) where {T<: Real , IType <: Integer }
175+ vals:: Vector{T} , iso:: Real , eps:: Real , vxidx:: VoxelIndices{IType} ) where {T<: Real , IType <: Integer }
176176
177177 @inbounds ixs = vxidx. voxEdgeCrnrs[e]
178178 @inbounds srcVal = vals[ixs[1 ]]
179179 @inbounds tgtVal = vals[ixs[2 ]]
180- a = (iso- srcVal)/ (tgtVal- srcVal)
181- a = min (max (a, eps), one (T)- eps)
180+ a = min (max ((iso- srcVal)/ (tgtVal- srcVal), eps), one (T)- eps)
182181 b = one (T)- a
183182 @inbounds c1x,c1y,c1z = vxidx. voxCrnrPos[ixs[1 ]]
184183 @inbounds c2x,c2y,c2z = vxidx. voxCrnrPos[ixs[2 ]]
185184
186- Point {3,T} (
185+ Point (
187186 x+ b* c1x+ a* c2x,
188187 y+ b* c1y+ a* c2y,
189188 z+ b* c1z+ a* c2z
@@ -196,9 +195,9 @@ present.
196195"""
197196function getVertId (e:: IType , x:: IType , y:: IType , z:: IType ,
198197 nx:: IType , ny:: IType ,
199- vals:: Vector{T} , iso:: T ,
200- vts:: Dict{IType, Point{3,T }} ,
201- eps:: T , vxidx:: VoxelIndices{IType} ) where {T<: Real , IType <: Integer }
198+ vals:: Vector{T} , iso:: Real ,
199+ vts:: Dict{IType, Point{3,S }} ,
200+ eps:: Real , vxidx:: VoxelIndices{IType} ) where {T <: Real , S <: Real , IType <: Integer }
202201
203202 vId = vertId (e, x, y, z, nx, ny, vxidx)
204203 if ! haskey (vts, vId)
@@ -222,11 +221,11 @@ end
222221Processes a voxel, adding any new vertices and faces to the given
223222containers as necessary.
224223"""
225- function procVox (vals:: Vector{T} , iso:: T ,
224+ function procVox (vals:: Vector{T} , iso:: Real ,
226225x:: IType , y:: IType , z:: IType ,
227226nx:: IType , ny:: IType ,
228- vts:: Dict{IType, Point{3,T }} , fcs:: Vector{Face{3,IType}} ,
229- eps:: T , vxidx:: VoxelIndices{IType} ) where {T<: Real , IType <: Integer }
227+ vts:: Dict{IType, Point{3,S }} , fcs:: Vector{Face{3,IType}} ,
228+ eps:: Real , vxidx:: VoxelIndices{IType} ) where {T <: Real , S <: Real , IType <: Integer }
230229
231230 # check each sub-tetrahedron in the voxel
232231 for i:: IType = 1 : 6
252251Given a 3D array and an isovalue, extracts a mesh represention of the
253252an approximate isosurface by the method of marching tetrahedra.
254253"""
255- function marchingTetrahedra (lsf:: AbstractArray{T,3} , iso:: T , eps:: T , indextype:: Type{IT} ) where {T<: Real , IT <: Integer }
256- vts = Dict {indextype, Point{3,T}} ()
254+ function marchingTetrahedra (lsf:: AbstractArray{T,3} , iso:: Real , eps:: Real , indextype:: Type{IT} ) where {T<: Real , IT <: Integer }
255+ vertex_eltype = promote_type (T, typeof (iso), typeof (eps))
256+ vts = Dict {indextype, Point{3,vertex_eltype}} ()
257257 fcs = Array {Face{3,indextype}} (0 )
258258 sizehint! (vts, div (length (lsf),8 ))
259259 sizehint! (fcs, div (length (lsf),4 ))
0 commit comments