Skip to content

Commit

Permalink
Merge pull request #4 from rdeits/cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
rdeits authored Feb 28, 2018
2 parents 03b5cdd + 956cf86 commit c28b261
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
28 changes: 1 addition & 27 deletions src/animate.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
"""
Interpolations.jl requires that one(::Type{T}) be defined for any data
type we want to interpolate. Rather than defining one(::Type{Vector}) here,
which might have unforeseen consequences in other packages, we'll create
a very simple wrapper type that just knows one() and *
"""
struct InterpolatableArray{A <: AbstractArray}
data::A
end

Base.one(::Type{InterpolatableArray{A}}) where {A} = 1
Base.:*(n::Number, a::InterpolatableArray) = n * a.data

rbd.normalize_configuration!(joint_type::JointType, q) = nothing
function rbd.normalize_configuration!(joint_type::QuaternionFloating, q)
n = norm(q[1:4])
for i = 1:4
q[i] /= n
end
end

"""
animate(vis::MechanismVisualizer,
times::Vector{Float64},
Expand All @@ -36,8 +15,7 @@ function animate(vis::MechanismVisualizer,
@assert 0 < realtimerate < Inf

state = vis.state
interp_values = [InterpolatableArray(c) for c in configurations]
interpolated_configurations = interpolate((times,), interp_values, Gridded(Linear()))
interpolated_configurations = interpolate((times,), configurations, Gridded(Linear()))
t0, tf = first(times), last(times)
framenum = 0
walltime0 = time()
Expand All @@ -51,7 +29,3 @@ function animate(vis::MechanismVisualizer,
t == tf && break
end max_rate = fps
end

animate(mechanism::Mechanism, times::Vector{Float64},
configurations::Vector{Vector{Float64}}) =
animate(Visualizer(mechanism), mechanism, times, configurations)
6 changes: 3 additions & 3 deletions src/visualizer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ function _set_mechanism!(mvis::MechanismVisualizer, frame_to_visuals)
body_ancestors = rbd.Graphs.ancestors(vertex, tree)
for definition in rbd.frame_definitions(body)
frame = definition.from
path = Symbol.(vcat(string.(reverse(body_ancestors)), string(frame)))
path = vcat(string.(reverse(body_ancestors)), string(frame))
frame_vis = vis[path...]
if frame in keys(frame_to_visuals)
settransform!(frame_vis, to_affine_map(definition))
for (i, (object, tform)) in enumerate(frame_to_visuals[frame])
obj_vis = frame_vis[Symbol("geometry_", i)]
obj_vis = frame_vis["geometry_$i"]
setobject!(obj_vis, object)
settransform!(obj_vis, tform)
end
Expand All @@ -58,7 +58,7 @@ function _render_state!(mvis::MechanismVisualizer, state::MechanismState=mvis.st
settransform!(vis, to_affine_map(transform_to_root(state, body)))
else
body_ancestors = rbd.Graphs.ancestors(vertex, tree)
path = Symbol.(string.(reverse(body_ancestors)))
path = string.(reverse(body_ancestors))
tform = relative_transform(state, default_frame(body), default_frame(body_ancestors[2]))
settransform!(vis[path...], to_affine_map(tform))
end
Expand Down

0 comments on commit c28b261

Please sign in to comment.