Skip to content

Commit

Permalink
Merge pull request #20 from rdeits/decompose
Browse files Browse the repository at this point in the history
handle arbitrary geometry primitives and test with Polyhedra.jl
  • Loading branch information
rdeits authored Mar 12, 2018
2 parents fed2a10 + f828f70 commit 26293ec
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ setobject!(vis, PointCloud(verts, colors))

![demo-points](https://user-images.githubusercontent.com/591886/36703986-3d18e232-1b2c-11e8-8c40-a73e55cc93b6.png)

### Complex Geometries
### Contours

```julia
# Visualize a mesh from the level set of a function
Expand All @@ -83,6 +83,28 @@ setobject!(vis, mesh,

![demo-contour](https://user-images.githubusercontent.com/591886/36703981-37b62ba6-1b2c-11e8-90aa-4c38486732e7.png)

### Polyhedra

```
# Visualize a polyhedron from Polyhedra.jl
using Polyhedra
using CDDLib
# Construct a polyhedron in 4 dimensions
ext1 = SimpleVRepresentation([0 1 2 3;0 2 1 3; 1 0 2 3; 1 2 0 3; 2 0 1 3; 2 1 0 3;
0 1 3 2;0 3 1 2; 1 0 3 2; 1 3 0 2; 3 0 1 2; 3 1 0 2;
0 3 2 1;0 2 3 1; 3 0 2 1; 3 2 0 1; 2 0 3 1; 2 3 0 1;
3 1 2 0;3 2 1 0; 1 3 2 0; 1 2 3 0; 2 3 1 0; 2 1 3 0])
poly1 = CDDPolyhedron{4,Rational{BigInt}}(ext1)
# Project that polyhedron down to 3 dimensions for visualization
poly2 = project(poly1, [1 1 1; -1 1 1; 0 -2 1; 0 0 -3])
# Show the result
setobject!(vis, poly2)
```

![polyhedron](https://user-images.githubusercontent.com/591886/37313984-fa3b20c2-2627-11e8-8238-71607a7f16e7.png)

### Mechanisms

Using https://github.com/rdeits/MeshCatMechanisms.jl
Expand Down
2 changes: 2 additions & 0 deletions src/lowering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ function lower(mesh::AbstractMesh)
)
end

lower(g::GeometryPrimitive) = lower(GLNormalMesh(g)) # Fallback for everything else (like Polyhedra.jl's Polyhedron types)

function lower(cloud::PointCloud)
attributes = Dict{String, Any}(
"position" => lower(convert(Vector{Point3f0}, cloud.position)),
Expand Down
2 changes: 2 additions & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ FileIO 0.4
Meshing 0.3
NBInclude 1.0
DandelionWebSockets 0.1
Polyhedra 0.2.0
CDDLib 0.2.0
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ using GeometryTypes
using CoordinateTransformations
using Colors
using MeshIO, FileIO
using Polyhedra
using CDDLib


@testset "MeshCat" begin
include("server_client.jl")
Expand Down
14 changes: 14 additions & 0 deletions test/visualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ delete!(vis)
settransform!(v[:random], Translation(-0.5, -0.5, 0))
end
end


@testset "Polyhedra" begin
ext1 = SimpleVRepresentation([0 1 2 3;0 2 1 3; 1 0 2 3; 1 2 0 3; 2 0 1 3; 2 1 0 3;
0 1 3 2;0 3 1 2; 1 0 3 2; 1 3 0 2; 3 0 1 2; 3 1 0 2;
0 3 2 1;0 2 3 1; 3 0 2 1; 3 2 0 1; 2 0 3 1; 2 3 0 1;
3 1 2 0;3 2 1 0; 1 3 2 0; 1 2 3 0; 2 3 1 0; 2 1 3 0])
poly1 = CDDPolyhedron{4,Rational{BigInt}}(ext1)

poly2 = project(poly1, [1 1 1; -1 1 1; 0 -2 1; 0 0 -3])
setobject!(vis[:polyhedron], poly2)
settransform!(vis[:polyhedron], Translation(-0.5, 1.0, 0) LinearMap(UniformScaling(0.1)))
end

end

close(vis)
Expand Down

0 comments on commit 26293ec

Please sign in to comment.