124
124
Checks if a voxel has faces. Should be false for most voxels.
125
125
This function should be made as fast as possible.
126
126
"""
127
- function hasFaces (vals:: Vector{T } , iso:: T ) where T <: Real
127
+ function hasFaces (vals:: Vector{<:Real } , iso:: Real )
128
128
@inbounds v = vals[1 ]
129
129
if v < iso
130
130
@inbounds for i= 2 : 8
141
141
"""
142
142
Determines which case in the triangle table we are dealing with
143
143
"""
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 }
145
145
@inbounds v1 = vals[vxidx. subTets[tIx][1 ]]
146
146
@inbounds v2 = vals[vxidx. subTets[tIx][2 ]]
147
147
@inbounds v3 = vals[vxidx. subTets[tIx][3 ]]
@@ -160,7 +160,7 @@ regardless of which of its neighboring voxels is asking for it) in order
160
160
for vertex sharing to be implemented properly.
161
161
"""
162
162
function 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 }
164
164
@inbounds dx, dy, dz = vxidx. voxCrnrPos[vxidx. voxEdgeCrnrs[e][1 ]]
165
165
vxidx. voxEdgeDir[e]+ 7 * (x- 1 + dx+ nx* (y- 1 + dy+ ny* (z- 1 + dz)))
166
166
end
@@ -172,18 +172,17 @@ eps represents the "bump" factor to keep vertices away from voxel
172
172
corners (thereby preventing degeneracies).
173
173
"""
174
174
function 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 }
176
176
177
177
@inbounds ixs = vxidx. voxEdgeCrnrs[e]
178
178
@inbounds srcVal = vals[ixs[1 ]]
179
179
@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)
182
181
b = one (T)- a
183
182
@inbounds c1x,c1y,c1z = vxidx. voxCrnrPos[ixs[1 ]]
184
183
@inbounds c2x,c2y,c2z = vxidx. voxCrnrPos[ixs[2 ]]
185
184
186
- Point {3,T} (
185
+ Point (
187
186
x+ b* c1x+ a* c2x,
188
187
y+ b* c1y+ a* c2y,
189
188
z+ b* c1z+ a* c2z
@@ -196,9 +195,9 @@ present.
196
195
"""
197
196
function getVertId (e:: IType , x:: IType , y:: IType , z:: IType ,
198
197
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 }
202
201
203
202
vId = vertId (e, x, y, z, nx, ny, vxidx)
204
203
if ! haskey (vts, vId)
@@ -222,11 +221,11 @@ end
222
221
Processes a voxel, adding any new vertices and faces to the given
223
222
containers as necessary.
224
223
"""
225
- function procVox (vals:: Vector{T} , iso:: T ,
224
+ function procVox (vals:: Vector{T} , iso:: Real ,
226
225
x:: IType , y:: IType , z:: IType ,
227
226
nx:: 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 }
230
229
231
230
# check each sub-tetrahedron in the voxel
232
231
for i:: IType = 1 : 6
252
251
Given a 3D array and an isovalue, extracts a mesh represention of the
253
252
an approximate isosurface by the method of marching tetrahedra.
254
253
"""
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}} ()
257
257
fcs = Array {Face{3,indextype}} (0 )
258
258
sizehint! (vts, div (length (lsf),8 ))
259
259
sizehint! (fcs, div (length (lsf),4 ))
0 commit comments