Skip to content

Commit

Permalink
Remove dependency of output port allocation on context in GeometrySys…
Browse files Browse the repository at this point in the history
…tem (RobotLocomotion#8579)

* Remove dependency of output port allocation on context.
  • Loading branch information
sherm1 authored and SeanCurtis-TRI committed Apr 12, 2018
1 parent f6e88d9 commit c4f9de7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
13 changes: 5 additions & 8 deletions geometry/geometry_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ GeometrySystem<T>::GeometrySystem(const GeometrySystem<U>& other)
// system to persist the same state.
if (other.initial_state_ != nullptr) {
*initial_state_ = *(other.initial_state_->ToAutoDiffXd());
} else {
initial_state_ = nullptr;
}
context_has_been_allocated_ = other.context_has_been_allocated_;

// We need to guarantee that the same source ids map to the same port indexes.
// We'll do this by processing the source ids in monotonically increasing
Expand Down Expand Up @@ -240,10 +239,8 @@ void GeometrySystem<T>::CalcQueryObject(const Context<T>& context,
}

template <typename T>
PoseBundle<T> GeometrySystem<T>::MakePoseBundle(
const Context<T>& context) const {
const auto& g_context = static_cast<const GeometryContext<T>&>(context);
const auto& g_state = g_context.get_geometry_state();
PoseBundle<T> GeometrySystem<T>::MakePoseBundle() const {
const auto& g_state = *initial_state_;
PoseBundle<T> bundle(g_state.get_num_frames());
int i = 0;
for (FrameId f_id : g_state.get_frame_ids()) {
Expand Down Expand Up @@ -337,15 +334,15 @@ void GeometrySystem<T>::FullPoseUpdate(
template <typename T>
std::unique_ptr<LeafContext<T>> GeometrySystem<T>::DoMakeLeafContext() const {
// Disallow further geometry source additions.
initial_state_ = nullptr;
context_has_been_allocated_ = true;
DRAKE_ASSERT(geometry_state_index_ >= 0);
return make_unique<GeometryContext<T>>(geometry_state_index_);
}

template <typename T>
void GeometrySystem<T>::ThrowIfContextAllocated(
const char* source_method) const {
if (initial_state_ == nullptr) {
if (context_has_been_allocated_) {
throw std::logic_error(
"The call to " + std::string(source_method) + " is invalid; a "
"context has already been allocated.");
Expand Down
8 changes: 5 additions & 3 deletions geometry/geometry_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@ class GeometrySystem final : public systems::LeafSystem<T> {

// Constructs a PoseBundle of length equal to the concatenation of all inputs.
// This is the method used by the allocator for the output port.
systems::rendering::PoseBundle<T> MakePoseBundle(
const systems::Context<T>& context) const;
systems::rendering::PoseBundle<T> MakePoseBundle() const;

// Aggregates the input poses into the output PoseBundle, in the same order as
// was used in allocation. Aborts if any inputs have a _different_ size than
Expand Down Expand Up @@ -468,7 +467,10 @@ class GeometrySystem final : public systems::LeafSystem<T> {
// property that source ids can only be added prior to context allocation.
// This is mutable so that it can be cleared in the const method
// AllocateContext().
mutable GeometryState<T>* initial_state_;
GeometryState<T>* initial_state_{};

// TODO(SeanCurtis-TRI): Get rid of this.
mutable bool context_has_been_allocated_{false};

// The index of the geometry state in the context's abstract state.
int geometry_state_index_{-1};
Expand Down

0 comments on commit c4f9de7

Please sign in to comment.