@@ -21,7 +21,7 @@ Voxel corner and edge indexing conventions
21
21
/
22
22
X
23
23
"""
24
- immutable VoxelIndices{T <: Integer }
24
+ struct VoxelIndices{T <: Integer }
25
25
voxCrnrPos:: NTuple{8,NTuple{3,T}}
26
26
voxEdgeCrnrs:: NTuple{19, NTuple{2,T}}
27
27
voxEdgeDir:: NTuple{19,T}
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 {T<:Real} (vals:: Vector{T} , iso:: T )
127
+ function hasFaces (vals:: Vector{T} , iso:: T ) where T <: 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 {T<:Real, IType <: Integer} (tIx:: IType , vals:: Vector{T} , iso:: T , vxidx:: VoxelIndices{IType} )
144
+ function tetIx (tIx:: IType , vals:: Vector{T} , iso:: T , vxidx:: VoxelIndices{IType} ) where {T <: Real , 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 ]]
@@ -159,8 +159,8 @@ two edges get the same index) and unique (every edge gets the same ID
159
159
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
- function vertId {IType <: Integer} (e:: IType , x:: IType , y:: IType , z:: IType ,
163
- nx:: IType , ny:: IType , vxidx:: VoxelIndices{IType} )
162
+ function vertId (e:: IType , x:: IType , y:: IType , z:: IType ,
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
@@ -171,8 +171,8 @@ occurs.
171
171
eps represents the "bump" factor to keep vertices away from voxel
172
172
corners (thereby preventing degeneracies).
173
173
"""
174
- function vertPos {T<:Real, IType <: Integer} (e:: IType , x:: IType , y:: IType , z:: IType ,
175
- vals:: Vector{T} , iso:: T , eps:: T , vxidx:: VoxelIndices{IType} )
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 }
176
176
177
177
@inbounds ixs = vxidx. voxEdgeCrnrs[e]
178
178
@inbounds srcVal = vals[ixs[1 ]]
@@ -194,11 +194,11 @@ end
194
194
Gets the vertex ID, adding it to the vertex dictionary if not already
195
195
present.
196
196
"""
197
- function getVertId {T<:Real, IType <: Integer} (e:: IType , x:: IType , y:: IType , z:: IType ,
198
- nx:: IType , ny:: IType ,
199
- vals:: Vector{T} , iso:: T ,
200
- vts:: Dict{IType, Point{3,T}} ,
201
- eps:: T , vxidx:: VoxelIndices{IType} )
197
+ function getVertId (e:: IType , x:: IType , y:: IType , z:: IType ,
198
+ 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 }
202
202
203
203
vId = vertId (e, x, y, z, nx, ny, vxidx)
204
204
if ! haskey (vts, vId)
211
211
Given a sub-tetrahedron case and a tetrahedron edge ID, determines the
212
212
corresponding voxel edge ID.
213
213
"""
214
- function voxEdgeId {IType <: Integer} (subTetIx:: IType , tetEdgeIx:: IType , vxidx:: VoxelIndices{IType} )
214
+ function voxEdgeId (subTetIx:: IType , tetEdgeIx:: IType , vxidx:: VoxelIndices{IType} ) where IType <: Integer
215
215
@inbounds srcVoxCrnr:: IType = vxidx. subTets[subTetIx][vxidx. tetEdgeCrnrs[tetEdgeIx][1 ]]
216
216
@inbounds tgtVoxCrnr:: IType = vxidx. subTets[subTetIx][vxidx. tetEdgeCrnrs[tetEdgeIx][2 ]]
217
217
@inbounds v = vxidx. voxEdgeIx[srcVoxCrnr][tgtVoxCrnr]
@@ -222,11 +222,11 @@ end
222
222
Processes a voxel, adding any new vertices and faces to the given
223
223
containers as necessary.
224
224
"""
225
- function procVox {T<:Real, IType <: Integer} (vals:: Vector{T} , iso:: T ,
226
- x:: IType , y:: IType , z:: IType ,
227
- nx:: IType , ny:: IType ,
228
- vts:: Dict{IType, Point{3,T}} , fcs:: Vector{Face{3,IType}} ,
229
- eps:: T , vxidx:: VoxelIndices{IType} )
225
+ function procVox (vals:: Vector{T} , iso:: T ,
226
+ x:: IType , y:: IType , z:: IType ,
227
+ 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 }
230
230
231
231
# check each sub-tetrahedron in the voxel
232
232
for i:: IType = 1 : 6
252
252
Given a 3D array and an isovalue, extracts a mesh represention of the
253
253
an approximate isosurface by the method of marching tetrahedra.
254
254
"""
255
- function marchingTetrahedra {T<:Real, IT <: Integer} (lsf:: AbstractArray{T,3} , iso:: T , eps:: T , indextype:: Type{IT} )
255
+ function marchingTetrahedra (lsf:: AbstractArray{T,3} , iso:: T , eps:: T , indextype:: Type{IT} ) where {T <: Real , IT <: Integer }
256
256
vts = Dict {indextype, Point{3,T}} ()
257
257
fcs = Array {Face{3,indextype}} (0 )
258
258
sizehint! (vts, div (length (lsf),8 ))
@@ -293,14 +293,14 @@ end
293
293
isosurface (lsf,isoval) = isosurface (lsf,isoval, convert (eltype (lsf), 0.001 ))
294
294
295
295
296
- function (:: Type{MT} ){MT <: AbstractMesh , T} (volume:: Array{T, 3} , iso_val:: Real , eps_val= 0.001 )
296
+ function (:: Type{MT} )(volume:: Array{T, 3} , iso_val:: Real , eps_val= 0.001 ) where {MT <: AbstractMesh , T}
297
297
iso_val = convert (T, iso_val)
298
298
eps_val = convert (T, eps_val)
299
299
vts, fcs = isosurface (volume, iso_val, eps_val)
300
300
MT (vts, fcs)
301
301
end
302
302
303
- function (:: Type{MT} ){MT <: AbstractMesh } (df:: SignedDistanceField , eps_val= 0.001 )
303
+ function (:: Type{MT} )(df:: SignedDistanceField , eps_val= 0.001 ) where MT <: AbstractMesh
304
304
vts, fcs = isosurface (df. data, 0.0 , eps_val)
305
305
MT (vts, fcs)
306
306
end
0 commit comments