Skip to content

Commit

Permalink
Merge pull request #8 from rdeits/v0.6-compat
Browse files Browse the repository at this point in the history
fix compatibility with geometrytypes and julia v0.6
  • Loading branch information
SimonDanisch authored Jun 20, 2017
2 parents 5c4be5b + 04f280e commit 2ed69bf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ language: julia
os:
- linux
julia:
- 0.4
- 0.5
- 0.6
- nightly
notifications:
email: false
Expand Down
5 changes: 2 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
julia 0.4
GeometryTypes 0.1.6
Compat 0.8.6
julia 0.6
GeometryTypes 0.4
1 change: 0 additions & 1 deletion src/Meshing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ VERSION >= v"0.4.0-dev+6521" && __precompile__()
module Meshing

using GeometryTypes
using Compat

include("marching_tetrahedra.jl")
include("marching_cubes.jl")
Expand Down
8 changes: 4 additions & 4 deletions src/marching_cubes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ const tri_table = ((-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1),
(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1))

"""
`marching_cubes(sdf::SignedDistanceField, [iso = 0.0,] [MT = HomogenousMesh{Point{3,Float64},Face{3,Int,0}}])`
`marching_cubes(sdf::SignedDistanceField, [iso = 0.0,] [MT = HomogenousMesh{Point{3,Float64},Face{3,Int}}])`
Construct a `HomogenousMesh` from a `SignedDistanceField` using the
marching cubes algorithm. This method is faster than Marching Tetrahedra
Expand All @@ -288,15 +288,15 @@ Tetrahedra guarentees a manifold mesh.
"""
function marching_cubes{ST,FT,M<:AbstractMesh}(sdf::SignedDistanceField{3,ST,FT},
iso=0.0,
MT::Type{M}=SimpleMesh{Point{3,Float64},Face{3,Int,0}})
MT::Type{M}=SimpleMesh{Point{3,Float64},Face{3,Int}})
nx, ny, nz = size(sdf)
h = HyperRectangle(sdf)
w = widths(h)
s = Point{3,Float64}(w[1]/nx, w[2]/ny, w[3]/nz)

# arrays for vertices and faces
vts = Point{3,Float64}[]
fcs = Face{3,Int,0}[]
fcs = Face{3,Int}[]
vertlist = Vector{Point{3,Float64}}(12)
@inbounds for xi = 1:nx-1, yi = 1:ny-1, zi = 1:nz-1

Expand Down Expand Up @@ -381,7 +381,7 @@ function marching_cubes{ST,FT,M<:AbstractMesh}(sdf::SignedDistanceField{3,ST,FT}
push!(vts, vertlist[tri_table[cubeindex][i+1]])
push!(vts, vertlist[tri_table[cubeindex][i+2]])
fct = length(vts)
push!(fcs, Face{3,Int,0}(fct, fct-1, fct-2))
push!(fcs, Face{3,Int}(fct, fct-1, fct-2))
end
end
MT(vts,fcs)
Expand Down
16 changes: 8 additions & 8 deletions src/marching_tetrahedra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ immutable VoxelIndices{T <: Integer}
tetEdgeCrnrs::NTuple{6,NTuple{2,T}}
tetTri::NTuple{16,NTuple{6,T}}

function VoxelIndices()
function VoxelIndices{T}() where {T <: Integer}
voxCrnrPos = ((0, 0, 0),
(0, 1, 0),
(1, 1, 0),
Expand Down Expand Up @@ -109,7 +109,7 @@ immutable VoxelIndices{T <: Integer}
(1,4,3,0,0,0),
(0,0,0,0,0,0))

new(voxCrnrPos,
new{T}(voxCrnrPos,
voxEdgeCrnrs,
voxEdgeDir,
voxEdgeIx,
Expand Down Expand Up @@ -225,7 +225,7 @@ containers as necessary.
function procVox{T<:Real, IType <: Integer}(vals::Vector{T}, iso::T,
x::IType, y::IType, z::IType,
nx::IType, ny::IType,
vts::Dict{IType, Point{3,T}}, fcs::Vector{Face{3,IType,0}},
vts::Dict{IType, Point{3,T}}, fcs::Vector{Face{3,IType}},
eps::T, vxidx::VoxelIndices{IType})

# check each sub-tetrahedron in the voxel
Expand All @@ -239,7 +239,7 @@ function procVox{T<:Real, IType <: Integer}(vals::Vector{T}, iso::T,
@inbounds e3 = vxidx.tetTri[tIx][j+2]

# add the face to the list
push!(fcs, Face{3,IType,0}(
push!(fcs, Face{3,IType}(
getVertId(voxEdgeId(i, e1, vxidx), x, y, z, nx, ny, vals, iso, vts, eps, vxidx),
getVertId(voxEdgeId(i, e2, vxidx), x, y, z, nx, ny, vals, iso, vts, eps, vxidx),
getVertId(voxEdgeId(i, e3, vxidx), x, y, z, nx, ny, vals, iso, vts, eps, vxidx)))
Expand All @@ -254,7 +254,7 @@ an approximate isosurface by the method of marching tetrahedra.
"""
function marchingTetrahedra{T<:Real, IT <: Integer}(lsf::AbstractArray{T,3}, iso::T, eps::T, indextype::Type{IT})
vts = Dict{indextype, Point{3,T}}()
fcs = Array(Face{3,indextype,0}, 0)
fcs = Array{Face{3,indextype}}(0)
sizehint!(vts, div(length(lsf),8))
sizehint!(fcs, div(length(lsf),4))
const vxidx = VoxelIndices{indextype}()
Expand Down Expand Up @@ -284,7 +284,7 @@ function isosurface(lsf, isoval, eps, indextype=Int, index_start=one(Int))
vtD[x] = k
k += one(indextype)
end
fcAry = Face{3,indextype, index_start-1}[Face{3,indextype, index_start-1}(vtD[f[1]], vtD[f[2]], vtD[f[3]]) for f in fcs]
fcAry = Face{3,indextype}[Face{3,indextype}(vtD[f[1]], vtD[f[2]], vtD[f[3]]) for f in fcs]
vtAry = collect(values(vts))

(vtAry, fcAry)
Expand All @@ -293,14 +293,14 @@ end
isosurface(lsf,isoval) = isosurface(lsf,isoval, convert(eltype(lsf), 0.001))


@compat function (::Type{MT}){MT <: AbstractMesh, T}(volume::Array{T, 3}, iso_val::Real, eps_val=0.001)
function (::Type{MT}){MT <: AbstractMesh, T}(volume::Array{T, 3}, iso_val::Real, eps_val=0.001)
iso_val = convert(T, iso_val)
eps_val = convert(T, eps_val)
vts, fcs = isosurface(volume, iso_val, eps_val)
MT(vts, fcs)
end

@compat function (::Type{MT}){MT <: AbstractMesh}(df::SignedDistanceField, eps_val=0.001)
function (::Type{MT}){MT <: AbstractMesh}(df::SignedDistanceField, eps_val=0.001)
vts, fcs = isosurface(df.data, 0.0, eps_val)
MT(vts, fcs)
end
Expand Down

0 comments on commit 2ed69bf

Please sign in to comment.