Skip to content

Commit

Permalink
improved various mesh & plotting methods
Browse files Browse the repository at this point in the history
  • Loading branch information
chakravala committed Jul 2, 2020
1 parent 6d52e45 commit 8738f50
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Project.toml
@@ -1,7 +1,7 @@
name = "Grassmann"
uuid = "4df31cd9-4c27-5bea-88d0-e6a7146666d8"
authors = ["Michael Reed"]
version = "0.5.15"
version = "0.5.16"

[deps]
AbstractTensors = "a8e43f4a-99b7-5565-8bf1-0165161caaea"
Expand All @@ -17,7 +17,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
[compat]
julia = "1"
Leibniz = "0.0.5"
DirectSum = "0.5.8"
DirectSum = "0.5.11"
AbstractTensors = "0.4.9"
ComputedFieldTypes = "0.1"
StaticArrays = "0"
Expand Down
29 changes: 21 additions & 8 deletions src/Grassmann.jl
Expand Up @@ -167,7 +167,7 @@ end

## skeleton / subcomplex

export skeleton, 𝒫, collapse, subcomplex, chain, path
export skeleton, 𝒫, collapse, subcomplex, chain, path, pointset, column, columns

absym(t) = abs(t)
absym(t::SubManifold) = t
Expand Down Expand Up @@ -241,7 +241,7 @@ columns(t,i=1,j=ndims(t)) = column.(Ref(value(t)),list(i,j))
function edges(t,cols=columns(t))
ndims(t) == 2 && (return t)
np,N = length(points(t)),ndims(Manifold(t))
A = spzeros(np,np),points(t)(list(N-1,N)...)
A,M = spzeros(np,np),points(t)(list(N-1,N)...)
for c combo(N,2)
A += sparse(cols[c[1]],cols[c[2]],1,np,np)
end
Expand Down Expand Up @@ -401,22 +401,35 @@ function __init__()
AbstractPlotting.arrows(p::Vector{<:Chain{V}},v;args...) where V = AbstractPlotting.arrows(GeometryBasics.Point.((V).(p)),GeometryBasics.Point.(value(v));args...)
AbstractPlotting.arrows!(p::Vector{<:Chain{V}},v;args...) where V = AbstractPlotting.arrows!(GeometryBasics.Point.((V).(p)),GeometryBasics.Point.(value(v));args...)
AbstractPlotting.scatter(p::ChainBundle,x,;args...) = AbstractPlotting.scatter(submesh(p)[:,1],x;args...)
AbstractPlotting.scatter!(p::Vector{<:Chain},x,;args...) = AbstractPlotting.scatter!(submesh(p)[:,1],x;args...)
AbstractPlotting.scatter(p::Vector{<:Chain},x,;args...) = AbstractPlotting.scatter(submesh(p)[:,1],x;args...)
AbstractPlotting.scatter!(p::ChainBundle,x,;args...) = AbstractPlotting.scatter!(submesh(p)[:,1],x;args...)
AbstractPlotting.mesh(t::ChainBundle;args...) = AbstractPlotting.mesh(points(t),t;args...)
AbstractPlotting.scatter(p::Vector{<:Chain},x,;args...) = AbstractPlotting.scatter(submesh(p)[:,1],x;args...)
AbstractPlotting.scatter!(p::Vector{<:Chain},x,;args...) = AbstractPlotting.scatter!(submesh(p)[:,1],x;args...)
AbstractPlotting.lines(p::ChainBundle,args...) = AbstractPlotting.lines(value(p),args...)
AbstractPlotting.lines!(p::ChainBundle,args...) = AbstractPlotting.lines!(value(p),args...)
AbstractPlotting.lines(p::Vector{<:TensorAlgebra},args...) = AbstractPlotting.lines(GeometryBasics.Point.(p),args...)
AbstractPlotting.linesegments(e::Vector{<:Chain},args...) = (p=points(e); AbstractPlotting.linesegments(pointpair.(p[e],(Manifold(p))),args...))
AbstractPlotting.linesegments!(e::Vector{<:Chain},args...) = (p=points(e); AbstractPlotting.linesegments!(pointpair.(p[e],(Manifold(p))),args...))
AbstractPlotting.lines!(p::Vector{<:TensorAlgebra},args...) = AbstractPlotting.lines!(GeometryBasics.Point.(p),args...)
AbstractPlotting.linesegments(e::ChainBundle,args...) = AbstractPlotting.linesegments(value(e),args...)
AbstractPlotting.linesegments!(e::ChainBundle,args...) = AbstractPlotting.linesegments!(value(e),args...)
function AbstractPlotting.mesh(p::ChainBundle,t::ChainBundle;args...)
AbstractPlotting.linesegments(e::Vector{<:Chain},args...) = (p=points(e); AbstractPlotting.linesegments(pointpair.(p[e],(Manifold(p))),args...))
AbstractPlotting.linesegments!(e::Vector{<:Chain},args...) = (p=points(e); AbstractPlotting.linesegments!(pointpair.(p[e],(Manifold(p))),args...))
AbstractPlotting.mesh(t::ChainBundle;args...) = AbstractPlotting.mesh(points(t),t;args...)
AbstractPlotting.mesh!(t::ChainBundle;args...) = AbstractPlotting.mesh!(points(t),t;args...)
AbstractPlotting.mesh(t::Vector{<:Chain};args...) = AbstractPlotting.mesh(points(t),t;args...)
AbstractPlotting.mesh!(t::Vector{<:Chain};args...) = AbstractPlotting.mesh!(points(t),t;args...)
function AbstractPlotting.mesh(p::ChainBundle,t;args...)
if ndims(p) == 2
AbstractPlotting.plot(submesh(p)[:,1],args[:color])
else
AbstractPlotting.mesh(submesh(p),array(t);args...)
end
end
function AbstractPlotting.mesh!(p::ChainBundle,t;args...)
if ndims(p) == 2
AbstractPlotting.plot!(submesh(p)[:,1],args[:color])
else
AbstractPlotting.mesh!(submesh(p),array(t);args...)
end
end
end
#@require Makie="ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" nothing
@require MiniQhull="978d7f02-9e05-4691-894f-ae31a51d76ca" begin
Expand Down
2 changes: 2 additions & 0 deletions src/algebra.jl
Expand Up @@ -348,6 +348,8 @@ Exterior product as defined by the anti-symmetric quotient Λ≡⊗/~
@inline (a::UniformScaling{T},b::TensorAlgebra{V}) where {V,T<:Field} = V(a)b
@generated (t::T) where T<:SVector = Expr(:call,:,[:(t[$k]) for k 1:length(t)]...)
@generated (t::T) where T<:SizedVector = Expr(:call,:,[:(t[$k]) for k 1:length(t)]...)
(::SVector{0,<:Chain{V}}) where V = one(V) # ∧() = 1
(::SizedVector{0,<:Chain{V}}) where V = one(V)
(t::Chain{V,1,<:Chain} where V) = (value(t))
(a::X,b::Y,c::Z...) where {X<:TensorAlgebra,Y<:TensorAlgebra,Z<:TensorAlgebra} = (ab,c...)

Expand Down
14 changes: 11 additions & 3 deletions src/composite.jl
Expand Up @@ -392,7 +392,7 @@ INV(m::Chain{V,1,<:Chain{V,1}}) where V = Chain{V,1,Chain{V,1}}(inv(SMatrix(m)))
Chain{M,1}.($(Expr(:.,:SVector,v)))
end
end
@pure list(a,b) = SVector(a:b...)
@pure list(a::Int,b::Int) = SVector{max(0,b-a+1),Int}(a:b...)
vectors(x::SVector{N,<:Chain{V}},y=x[1]) where {N,V} = (V).(x[list(2,N)].-y)
vectors(x::Chain{V,1},y=x[1]) where V = vectors(value(x),y)
#point(x,y=x[1]) = y∧∧(vectors(x))
Expand Down Expand Up @@ -451,8 +451,15 @@ curl(m::T) where T<:TensorAlgebra = Manifold(m)(∇)×m
LinearAlgebra.det(t::Chain{V,1,<:Chain} where V) = (t)
LinearAlgebra.det(m::Vector{<:Chain{V}}) where V = (m)
LinearAlgebra.det(m::ChainBundle) = (m)
(m::Vector{<:Chain{V}}) where V = .∧(points(m)[m])
(m::ChainBundle) = (value(m))
function (m::Vector{<:Chain{V}}) where V
p = points(m); pm = p[m]
if ndims(p)>ndims(V)
.∧(vectors.(pm))
else
Chain{↓(Manifold(V)),ndims(V)-1}.(value.(.∧(pm)))
end
end
for op (:mean,:barycenter,:curl)
ops = Symbol(op,:s)
@eval begin
Expand Down Expand Up @@ -488,11 +495,12 @@ function refinemesh!(::R,p::ChainBundle{W},e,t,η,_=nothing) where {W,R<:Abstrac
end

const array_cache = (Array{T,2} where T)[]
array(m::Vector{<:Chain}) = [m[i][j] for i1:length(m),j1:ndims(Manifold(m))]
function array(m::ChainBundle{V,G,T,B} where {V,G,T}) where B
for k length(array_cache):B
push!(array_cache,Array{Any,2}(undef,0,0))
end
isempty(array_cache[B]) && (array_cache[B] = [m[i][j] for i1:length(m),j1:ndims(m)])
isempty(array_cache[B]) && (array_cache[B] = array(value(m)))
return array_cache[B]
end
function array!(m::ChainBundle{V,G,T,B} where {V,G,T}) where B
Expand Down
2 changes: 1 addition & 1 deletion src/forms.jl
Expand Up @@ -44,7 +44,7 @@
:(@inbounds Chain{w,1,T}(b.v[$ind]))
else quote
out,N = zeros(choicevec(M,G,valuetype(b))),ndims(V)
ib,S = indexbasis(N,G),bits(W)
ib,S = indexbasis(N,G),bits(w)
for k 1:length(ib)
@inbounds if b[k] 0
@inbounds if count_ones(ib[k]&S) == G
Expand Down

0 comments on commit 8738f50

Please sign in to comment.