From fed947b298034a58d117a073c76de8ad29c349c6 Mon Sep 17 00:00:00 2001 From: Felix Gerick Date: Wed, 8 Mar 2017 12:23:42 +0100 Subject: [PATCH 1/7] add other fields --- src/QHull.jl | 35 +++++++++++++++++++---------------- src/polyhedron.jl | 6 +++--- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/QHull.jl b/src/QHull.jl index ac7d866..7f3bfdf 100644 --- a/src/QHull.jl +++ b/src/QHull.jl @@ -18,28 +18,31 @@ function __init__() end type Chull{T<:Real} + area::T + equations::Matrix{T} + ndim::Int + max_bound::Vector{T} + min_bound::Vector{T} + neighbours::Matrix{T} + npoints::Int + nsimplex::Int points::Matrix{T} - vertices::Vector{Int} simplices::Vector{Vector{Int}} - facets::Matrix{T} + vertices::Vector{Int} + volume::T end -## helper for base-0 / base-1 difference -incone(x) = for i in 1:length(x) - x[i] += 1 -end function chull{T<:Real}(x::Matrix{T}) - py = spatial[:ConvexHull](x) - points = convert(Matrix{T}, py["points"]) - vertices = convert(Vector{Int}, py["vertices"]) - incone(vertices) - simplices = convert(Vector{Vector{Int}}, py["simplices"]) - for simplex in simplices - incone(simplex) - end - facets = convert(Matrix{T}, py["equations"]) - Chull(points, vertices, simplices, facets) + + hull = spatial[:ConvexHull](x) + + ch = Chull([hull[field] for field in fieldnames(Chull)]...) + + # fix base-0 / base-1 difference + ch.vertices += 1 + ch.simplices += 1 + return ch end include("polyhedron.jl") diff --git a/src/polyhedron.jl b/src/polyhedron.jl index 9a677e2..5fc2190 100644 --- a/src/polyhedron.jl +++ b/src/polyhedron.jl @@ -73,8 +73,8 @@ function qhull{N, T}(h::SimpleVRepresentation{N, T}) ch = chull(V) V = ch.points[ch.vertices, :] vnored = SimpleVRepresentation(V) - A = ch.facets[:, 1:N] - b = ch.facets[:, N+1] + A = ch.equations[:, 1:N] + b = ch.equations[:, N+1] h = SimpleHRepresentation(A, b) vnored, h end @@ -97,7 +97,7 @@ function qhull{N, T<:Real}(h::SimpleHRepresentation{N, T}) ch = chull(B) C = ch.points[ch.vertices, :] hnored = SimpleHRepresentation(C, ones(size(C, 1))) - Vlift = ch.facets + Vlift = ch.equations nvreps = size(Vlift, 1) irays = IntSet() ipoints = IntSet() From 3345c996b1fb3a6920be354f6a9e84c44273460e Mon Sep 17 00:00:00 2001 From: Felix Gerick Date: Wed, 8 Mar 2017 12:25:52 +0100 Subject: [PATCH 2/7] neighboUrs --- src/QHull.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QHull.jl b/src/QHull.jl index 7f3bfdf..14be8e8 100644 --- a/src/QHull.jl +++ b/src/QHull.jl @@ -23,7 +23,7 @@ type Chull{T<:Real} ndim::Int max_bound::Vector{T} min_bound::Vector{T} - neighbours::Matrix{T} + neighbors::Matrix{T} npoints::Int nsimplex::Int points::Matrix{T} From 1fa50999f3d7c297f3e1a73f3442e5aae1a75970 Mon Sep 17 00:00:00 2001 From: Felix Gerick Date: Wed, 8 Mar 2017 12:33:34 +0100 Subject: [PATCH 3/7] change types Chull --- src/QHull.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/QHull.jl b/src/QHull.jl index 14be8e8..d3cc93d 100644 --- a/src/QHull.jl +++ b/src/QHull.jl @@ -17,18 +17,18 @@ function __init__() copy!(spatial, pyimport_conda("scipy.spatial", "scipy")) end -type Chull{T<:Real} +type Chull{T<:Real,U<:Int} area::T equations::Matrix{T} - ndim::Int + ndim::U max_bound::Vector{T} min_bound::Vector{T} - neighbors::Matrix{T} - npoints::Int - nsimplex::Int + neighbors::Matrix{U} + npoints::U + nsimplex::U points::Matrix{T} - simplices::Vector{Vector{Int}} - vertices::Vector{Int} + simplices::Vector{Vector{U}} + vertices::Vector{U} volume::T end From e9ab3c08662ab2cd1091bcf1cc80e10ebdb4d100 Mon Sep 17 00:00:00 2001 From: Felix Gerick Date: Wed, 8 Mar 2017 12:43:57 +0100 Subject: [PATCH 4/7] change types Chull --- src/QHull.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/QHull.jl b/src/QHull.jl index d3cc93d..6ff392f 100644 --- a/src/QHull.jl +++ b/src/QHull.jl @@ -17,18 +17,18 @@ function __init__() copy!(spatial, pyimport_conda("scipy.spatial", "scipy")) end -type Chull{T<:Real,U<:Int} +type Chull{T<:Real} area::T equations::Matrix{T} - ndim::U + ndim::Int64 max_bound::Vector{T} min_bound::Vector{T} - neighbors::Matrix{U} - npoints::U - nsimplex::U + neighbors::Matrix{Int32} + npoints::Int64 + nsimplex::Int64 points::Matrix{T} - simplices::Vector{Vector{U}} - vertices::Vector{U} + simplices::Vector{Vector{Int32}} + vertices::Vector{Int32} volume::T end From a15ccf3bbd408037225faeea1fe1a32d4d915c63 Mon Sep 17 00:00:00 2001 From: Felix Gerick Date: Wed, 8 Mar 2017 12:46:32 +0100 Subject: [PATCH 5/7] change simplices to matrix --- src/QHull.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/QHull.jl b/src/QHull.jl index 6ff392f..b51eba1 100644 --- a/src/QHull.jl +++ b/src/QHull.jl @@ -27,7 +27,7 @@ type Chull{T<:Real} npoints::Int64 nsimplex::Int64 points::Matrix{T} - simplices::Vector{Vector{Int32}} + simplices::Matrix{Int32} vertices::Vector{Int32} volume::T end From dfac7c012040718966cbef2afccc585c7385729c Mon Sep 17 00:00:00 2001 From: Felix Gerick Date: Wed, 8 Mar 2017 12:59:56 +0100 Subject: [PATCH 6/7] fix indices neighbors, test change (simplices now matrix) --- src/QHull.jl | 1 + test/runtests.jl | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/QHull.jl b/src/QHull.jl index b51eba1..2d598bc 100644 --- a/src/QHull.jl +++ b/src/QHull.jl @@ -42,6 +42,7 @@ function chull{T<:Real}(x::Matrix{T}) # fix base-0 / base-1 difference ch.vertices += 1 ch.simplices += 1 + ch.neighbors += 1 return ch end diff --git a/test/runtests.jl b/test/runtests.jl index cdd81f5..2bd6b96 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -12,7 +12,7 @@ pts = [-1.0 0; hull = QHull.chull(pts) @test hull.vertices == [1, 3, 4, 6, 7] @test size(hull.points) == size(pts) -@test hull.simplices == Array{Int,1}[[3,1], [4,3], [6,4], [7,1], [7,6]] +@test hull.simplices == Array{Int32,2}[3 1; 4 3; 6 4; 7 1; 7 6] ## multi-dim x = randn(1000, 5) From a76848ec59f46ec4dc36d445aa209848d44b05f2 Mon Sep 17 00:00:00 2001 From: Felix Gerick Date: Wed, 8 Mar 2017 13:07:16 +0100 Subject: [PATCH 7/7] test change (simplices now int32 matrix) --- test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 2bd6b96..2790ae9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,9 +10,9 @@ pts = [-1.0 0; -1 2] hull = QHull.chull(pts) -@test hull.vertices == [1, 3, 4, 6, 7] +@test hull.vertices == Int32[1, 3, 4, 6, 7] @test size(hull.points) == size(pts) -@test hull.simplices == Array{Int32,2}[3 1; 4 3; 6 4; 7 1; 7 6] +@test hull.simplices == Int32[3 1; 4 3; 6 4; 7 1; 7 6] ## multi-dim x = randn(1000, 5)