/** * Performs a deep copy of an entire multi-body system. * <p> * The clone of the multi-body system has its own root body which reference frame shares the same * parent as {@code originalRootBody.getBodyFixedFrame()}. * </p> * * @param originalRootBody the root of the multi-body system to clone. Not modified. * @param cloneStationaryFrame the reference frame to which the cloned system is attached to. The * given frame is expected to be stationary. * @param cloneSuffix suffix to append to the cloned joints and rigid-bodies. * @return the clone multi-body system. * @throws IllegalArgumentException if the given {@code originalRootBody} is not the root body of * its system. */ public static RigidBodyBasics cloneMultiBodySystem(RigidBodyReadOnly originalRootBody, ReferenceFrame cloneStationaryFrame, String cloneSuffix) { return cloneMultiBodySystem(originalRootBody, cloneStationaryFrame, cloneSuffix, null, null); }
/** * Performs a deep copy of {@code original}, preserving naming, root body, and the joints to ignore. * The clone is attached to the given {@code clonerootFrame}. * * @param original the multi-body system to clone. Not modified. * @param cloneRootFrame the root frame to which the clone system is attached. * @return the clone. */ public static MultiBodySystemBasics clone(MultiBodySystemReadOnly original, ReferenceFrame cloneRootFrame) { RigidBodyBasics cloneRootBody = MultiBodySystemFactories.cloneMultiBodySystem(original.getRootBody(), cloneRootFrame, ""); Set<String> namesOfJointsToConsider = SubtreeStreams.fromChildren(original.getRootBody()).map(JointReadOnly::getName).collect(Collectors.toSet()); List<? extends JointBasics> jointsToConsider = SubtreeStreams.fromChildren(cloneRootBody) .filter(joint -> namesOfJointsToConsider.contains(joint.getName())) .collect(Collectors.toList()); return toMultiBodySystemBasics(jointsToConsider); } }
List<OneDoFJoint> joints = MultiBodySystemRandomTools.nextOneDoFJointTree(random, numberOfJoints); RigidBodyBasics rootBody = MultiBodySystemTools.getRootBody(joints.get(0).getPredecessor()); RigidBodyBasics rootBodyInFuture = MultiBodySystemFactories.cloneMultiBodySystem(rootBody, worldFrame, "Test"); List<OneDoFJointBasics> jointsInFuture = SubtreeStreams.fromChildren(OneDoFJointBasics.class, rootBodyInFuture).collect(Collectors.toList());