Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add other fields from python function to julia #12

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
38 changes: 21 additions & 17 deletions src/QHull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,32 @@ function __init__()
end

type Chull{T<:Real}
area::T
equations::Matrix{T}
ndim::Int64
max_bound::Vector{T}
min_bound::Vector{T}
neighbors::Matrix{Int32}
npoints::Int64
nsimplex::Int64
points::Matrix{T}
vertices::Vector{Int}
simplices::Vector{Vector{Int}}
facets::Matrix{T}
simplices::Matrix{Int32}
vertices::Vector{Int32}
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
ch.neighbors += 1
return ch
end

include("polyhedron.jl")
Expand Down
6 changes: 3 additions & 3 deletions src/polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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{Int,1}[[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)
Expand Down