@@ -174,15 +174,27 @@ class PositionKinematicsCache {
174174 // in X_WL for those links once and for all. X_WL₀ (≜ X_WL[link₀]) and
175175 // X_WB₀ (≜ X_WB[mobod₀]) are identity transforms (set during allocation).
176176 // Consequently, X_WLᵢ = X_WB₀ * X_B₀Lᵢ = X_B₀Lᵢ for each of the links Lᵢ that
177- // are fixed to World.
178- void PrecomputeWorldComposite (
177+ // are fixed to World. Do nothing if the serial number hasn't changed.
178+ void PrecomputeWorldCompositeIfNeeded (
179179 const SpanningForest& forest,
180- const FrameBodyPoseCache<T>& frame_body_pose_cache);
180+ const FrameBodyPoseCache<T>& frame_body_pose_cache,
181+ int64_t frame_body_pose_cache_serial_number) {
182+ if (world_composite_serial_number_ == frame_body_pose_cache_serial_number)
183+ return ;
184+ ComputeWorldComposite (forest, frame_body_pose_cache);
185+ world_composite_serial_number_ = frame_body_pose_cache_serial_number;
186+ }
181187
182188 private:
183189 // Allocates resources for this position kinematics cache.
184190 void Allocate ();
185191
192+ // Called when we know we have to recompute the parameter-dependent
193+ // world composite kinematics.
194+ void ComputeWorldComposite (
195+ const SpanningForest& forest,
196+ const FrameBodyPoseCache<T>& frame_body_pose_cache);
197+
186198 // Helper method to initialize poses to garbage values including NaNs.
187199 // This allow us to quickly verify some of the values stored in the pools are
188200 // never used (however we store them anyway to simplify the indexing).
@@ -201,6 +213,12 @@ class PositionKinematicsCache {
201213 // (including the World link) and possibly some ephemeral links.
202214 int num_links_{0 };
203215
216+ // The serial number of the last FrameBodyPoseCache that was used to update
217+ // the state-independent quantities in this cache (such as the X_WL for links
218+ // fixed to World). This is used to determine whether we need to recompute
219+ // those quantities when PrecomputeWorldComposite() is called.
220+ int64_t world_composite_serial_number_{-1 };
221+
204222 // These are indexed by MobodIndex so are in depth-first order.
205223 std::vector<RigidTransform<T>> X_WB_pool_;
206224 std::vector<RigidTransform<T>> X_PB_pool_;
0 commit comments