Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

last fixes for tagging + glvisualize #100

Merged
merged 8 commits into from
Jun 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ julia 0.6.0-pre
StaticArrays
ColorTypes
FixedPointNumbers 0.3
Iterators
2 changes: 2 additions & 0 deletions src/GeometryTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ using ColorTypes

import FixedPointNumbers # U8

using Iterators.partition

import Base: ==,
*,
contains,
Expand Down
9 changes: 5 additions & 4 deletions src/decompose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ primitive.
function decompose{SV <: StaticVector, N, T}(::Type{SV},
r::AbstractGeometry{N, T}, args...
)
vectype = similar_type(SV, eltype_or(SV, T), size_or(SV, Size{(N,)}()))
sz = size_or(SV, (N,))
vectype = similar_type(SV, eltype_or(SV, T), Size{sz}())
# since we have not triangular dispatch, we can't define a function with the
# signature for a fully specified Vector type. But we need to check for it
# as it means that decompose is not implemented for that version
Expand Down Expand Up @@ -38,8 +39,8 @@ isdecomposable{T<:Face, HR<:SimpleRectangle}(::Type{T}, ::Type{HR}) = true
isdecomposable{T<:TextureCoordinate, HR<:SimpleRectangle}(::Type{T}, ::Type{HR}) = true
isdecomposable{T<:Normal, HR<:SimpleRectangle}(::Type{T}, ::Type{HR}) = true

isdecomposable{T<:Point, HR<:HyperSphere}(::Type{T}, ::Type{HR}) = true
isdecomposable{T<:Face, HR<:HyperSphere}(::Type{T}, ::Type{HR}) = true
isdecomposable{T<:Point, HR <: HyperSphere}(::Type{T}, ::Type{HR}) = true
isdecomposable{T<:Face, HR <: HyperSphere}(::Type{T}, ::Type{HR}) = true

"""
```
Expand Down Expand Up @@ -368,7 +369,7 @@ function decompose{N,T}(PT::Type{Point{N,T}}, s::Sphere, facets=12)
end
vertices
end
function decompose{FT<:Face}(::Type{FT}, s::Sphere, facets=12)
function decompose{FT <: Face}(::Type{FT}, s::Sphere, facets=12)
indexes = Vector{FT}(facets*facets*2)
FTE = eltype(FT)
psydo_triangle_i = facets*facets+1
Expand Down
69 changes: 0 additions & 69 deletions src/lines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,75 +56,6 @@ function simple_concat{P}(vec, range, endpoint::P)
result
end


# Taken from Iterators.jl, since it's not possible to use Iterators.jl on 0.6 with precompilation

struct Partition{I, N}
xs::I
step::Int
end
iteratorsize{T<:Partition}(::Type{T}) = SizeUnknown()

Base.eltype{I, N}(::Type{Partition{I, N}}) = NTuple{N, eltype(I)}
function partition{I}(xs::I, n::Int)
Partition{I, n}(xs, n)
end

function partition{I}(xs::I, n::Int, step::Int)
if step < 1
throw(ArgumentError("Partition step must be at least 1."))
end

Partition{I, n}(xs, step)
end

function Base.start{I, N}(it::Partition{I, N})
p = Vector{eltype(I)}(N)
s = start(it.xs)
for i in 1:(N - 1)
if done(it.xs, s)
break
end
(p[i], s) = next(it.xs, s)
end
(s, p)
end

function Base.next{I, N}(it::Partition{I, N}, state)
(s, p0) = state
(x, s) = next(it.xs, s)
ans = p0; ans[end] = x

p = similar(p0)
overlap = max(0, N - it.step)
for i in 1:overlap
p[i] = ans[it.step + i]
end

# when step > n, skip over some elements
for i in 1:max(0, it.step - N)
if done(it.xs, s)
break
end
(x, s) = next(it.xs, s)
end

for i in (overlap + 1):(N - 1)
if done(it.xs, s)
break
end

(x, s) = next(it.xs, s)
p[i] = x
end

(tuple(ans...), (s, p))
end

Base.done(it::Partition, state) = done(it.xs, state[1])



"""
Finds all self intersections of polygon `points`
"""
Expand Down
23 changes: 0 additions & 23 deletions src/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,6 @@ convert{M <: AbstractMesh}(::Type{M}, mesh::Union{AbstractGeometry, AbstractMesh
convert(::Type{T}, mesh::T) where T <: AbstractMesh = mesh
# (::Type{HM1}){HM1 <: AbstractMesh}(mesh::HM1) = mesh

"""
Uses decompose to get all the converted attributes from the meshtype and
creates a new mesh with the desired attributes from the converted attributs
Getindex can be defined for any arbitrary geometric type or exotic mesh type.
This way, we can make sure, that you can convert most of the meshes from one type to the other
with minimal code.
"""
function (::Type{HM1}){HM1 <: AbstractMesh}(primitive::GeometryPrimitive)
result = Dict{Symbol, Any}()
for (field, target_type) in zip(fieldnames(HM1), HM1.parameters)
if target_type != Void
if field == :attribute_id
if !isa(primitive, HomogenousMesh)
error("Primitive $primitive doesn't hold attribute indexes")
end
result[field] = primitive.attribute_id
else
result[field] = decompose(target_type, primitive)
end
end
end
HM1(result)
end

isvoid{T}(::Type{T}) = false
isvoid(::Type{Void}) = true
Expand Down
4 changes: 2 additions & 2 deletions src/primitives.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

function (meshtype::Type{T}){T <: AbstractMesh}(c::Pyramid)
T(decompose(vertextype(T), c), decompose(facetype(T), c))
T(vertices = decompose(vertextype(T), c), faces = decompose(facetype(T), c))
end


Expand All @@ -18,7 +18,7 @@ function (meshtype::Type{T}){T <: AbstractMesh}(c::GeometryPrimitive, args...)
newattribs[fieldname] = decompose(eltype(typ), c, args...)
end
end
T(homogenousmesh(newattribs))
T(newattribs)
end


Expand Down
4 changes: 2 additions & 2 deletions src/simplices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ end
# function StaticArrays.similar_type{SV <: Simplex}(::Union{SV, Type{SV}}, s::Tuple{Int})
# Simplex{s[1], eltype(SV)}
# end
function StaticArrays.similar_type{T}(::Union{Simplex, Type{Simplex}}, ::Type{T}, s::Tuple{Int})
Simplex{s[1], T}
function StaticArrays.similar_type{T, S}(::Union{Simplex, Type{Simplex}}, ::Type{T}, s::Size{S})
Simplex{S[1], T}
end

# (::Type{S}){S <: Simplex}(fs::FlexibleSimplex) = convert(S, fs)
Expand Down
34 changes: 13 additions & 21 deletions test/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ end
end

@testset "Primitives" begin
# issue #16
#m = HomogenousMesh{Point{3,Float64},Face{3, Int}}(Sphere(Point(0,0,0), 1))
#@fact length(vertices(m)) --> 145
#@fact length(faces(m)) --> 288
m = GLNormalMesh(Sphere(Point3f0(0), 1f0))
@test length(vertices(m)) == 145
@test length(faces(m)) == 288

end


Expand Down Expand Up @@ -173,23 +173,15 @@ end
mesh = PlainMesh{eltype(VT), FT}(vertices=vs, faces=fs)
@test convert(GLNormalMesh, mesh) == GLNormalMesh(vs, fs)
end
@testset "construction" begin
VT = vertextype(GLNormalMesh)
FT = facetype(GLNormalMesh)
vs = [VT(0., 0, 0), VT(1., 0, 0), VT(0., 1, 0)]
fs = [FT(1, 2, 3)]

# test for https://github.com/JuliaGeometry/GeometryTypes.jl/issues/92
m = HomogenousMesh(vs, fs)
@test HomogenousMesh(m) == m
end


using GeometryTypes
attributes = Dict{Symbol, Any}()
attributes[:faces] = GLTriangle[(1,2,3), (3, 2, 1)]
attributes[:vertices] = rand(Point3f0, 3)
attributes[:normals] = rand(Normal{3, Float32}, 3)
@which HomogenousMesh(attributes)
# M = HomogenousMesh
# attribs = attributes
# newfields = map(fieldnames(HomogenousMesh)) do field
# target_type = fieldtype(M, field)
# default = fieldtype(HomogenousMesh, field) <: Vector ? Void[] : nothing
# get(attribs, field, default)
# end

x = GeometryTypes.homogenousmesh(attributes)
GLNormalMesh(x)
end