@@ -174,15 +174,28 @@ 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.
177+ // are fixed to World. Do nothing if the serial number hasn't changed.
178178 void PrecomputeWorldComposite (
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+ }
185+ ComputeWorldComposite (forest, frame_body_pose_cache);
186+ world_composite_serial_number_ = frame_body_pose_cache_serial_number;
187+ }
181188
182189 private:
183190 // Allocates resources for this position kinematics cache.
184191 void Allocate ();
185192
193+ // Called when we know we have to recompute the parameter-dependent
194+ // world composite kinematics.
195+ void ComputeWorldComposite (
196+ const SpanningForest& forest,
197+ const FrameBodyPoseCache<T>& frame_body_pose_cache);
198+
186199 // Helper method to initialize poses to garbage values including NaNs.
187200 // This allow us to quickly verify some of the values stored in the pools are
188201 // never used (however we store them anyway to simplify the indexing).
@@ -201,6 +214,12 @@ class PositionKinematicsCache {
201214 // (including the World link) and possibly some ephemeral links.
202215 int num_links_{0 };
203216
217+ // The serial number of the last FrameBodyPoseCache that was used to update
218+ // the state-independent quantities in this cache (such as the X_WL for links
219+ // fixed to World). This is used to determine whether we need to recompute
220+ // those quantities when PrecomputeWorldComposite() is called.
221+ int64_t world_composite_serial_number_{-1 };
222+
204223 // These are indexed by MobodIndex so are in depth-first order.
205224 std::vector<RigidTransform<T>> X_WB_pool_;
206225 std::vector<RigidTransform<T>> X_PB_pool_;
0 commit comments