Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs for grabbed self col checking due to asymmetricity and unordered-ness. #1438

Open
wants to merge 32 commits into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2198a21
Fix the incorrect computation of self collision for grabbed bodies.
Sep 25, 2024
0cd3346
reduce the duplicated checking of pointer validity. check it when cre…
Sep 24, 2024
a942ee1
use _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed and _listNon…
Sep 24, 2024
d7b510e
directly return from the function if collision is deteced when bAllLi…
Sep 25, 2024
8fdf9eb
Improve warning message more
Sep 25, 2024
042243f
fix wrong size
Sep 25, 2024
a8839a2
fix typo of pSecondLink. in addition, rename variable to contain 'Ref…
Sep 25, 2024
7841daf
improve comments
Sep 25, 2024
61dc5dc
Resolve conflict while merge production. Conflicts: include/openrave/…
Sep 26, 2024
c3e9253
Merge remote-tracking branch 'origin/production' into fixGrabbedSelfC…
Sep 30, 2024
d8dcfeb
Merge remote-tracking branch 'origin/miscCleanupForGrabbedAPIs' into …
Sep 30, 2024
2bdbdb3
Add missing post processing of check self collision at the very end.
Sep 30, 2024
4645c51
Merge remote-tracking branch 'origin/miscCleanupForGrabbedAPIs' into …
Sep 30, 2024
78088f7
Merge remote-tracking branch 'origin/miscCleanupForGrabbedAPIs' into …
Oct 10, 2024
21b37e5
Merge remote-tracking branch 'origin/miscCleanupForGrabbedAPIs' into …
Oct 17, 2024
bb7cc24
Merge remote-tracking branch 'origin/miscCleanupForGrabbedAPIs' into …
Oct 18, 2024
9270541
Resolve conflict while merge production. Conflicts: src/libopenrave/k…
Oct 19, 2024
2856b8d
Fix compile
Oct 19, 2024
f5a663d
use |
Oct 19, 2024
16bd21f
Merge remote-tracking branch 'origin/production' into fixGrabbedSelfC…
Oct 21, 2024
0ae0e0e
Add kinematics hash checking for map list noncolliding for inter grabbed
Oct 22, 2024
fa2cc0c
No need to check iterator since the code right before already checked it
Oct 22, 2024
e21a2e7
no need of bInvertFirstSecond
Oct 22, 2024
8bf75a0
Swap the order of code, for better readability
Oct 22, 2024
e7cd291
return value from here is unused
Oct 25, 2024
05c9441
Update warning message clearer.
Oct 25, 2024
d9f6275
Introduce the rule of indices pair, which is key of map. the first en…
Oct 25, 2024
d8a7d4f
Bump minor version to fix bug of _listNonColidingLinksWhenGrabbed asy…
Oct 25, 2024
35fc6f9
Merge remote-tracking branch 'origin/production' into fixGrabbedSelfC…
Oct 28, 2024
b1599de
Resolve conflict while merge production. CMakeLists.txt, docs/source/…
Oct 31, 2024
179f48e
Resolve conflict while merge master. Conflict. docs/source/changelog.rst
Nov 3, 2024
f6f4f50
Changes from using macro to range-based for for clarity; Improves log…
Puttichai Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS TRUE )

# Define here the needed parameters
set (OPENRAVE_VERSION_MAJOR 0)
set (OPENRAVE_VERSION_MINOR 157)
set (OPENRAVE_VERSION_MINOR 158)
set (OPENRAVE_VERSION_PATCH 0)
set (OPENRAVE_VERSION ${OPENRAVE_VERSION_MAJOR}.${OPENRAVE_VERSION_MINOR}.${OPENRAVE_VERSION_PATCH})
set (OPENRAVE_SOVERSION ${OPENRAVE_VERSION_MAJOR}.${OPENRAVE_VERSION_MINOR})
Expand Down
7 changes: 7 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
ChangeLog
#########

Version 0.158.0
===============

- Fix bug of `_listNonColidingLinksWhenGrabbed` asymmetricity which might cause false positive/negative self collision checking and might make it less deterministic.
- Store the link pair for grabbed-grabber collision in `Grabbed` class.
- Store the link pair for inter-grabbed collision in `KinBody` class.

Version 0.157.0
===============

Expand Down
37 changes: 35 additions & 2 deletions include/openrave/kinbody.h
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,9 @@ class OPENRAVE_API KinBody : public InterfaceBase
typedef boost::shared_ptr<KinBodyInfo> KinBodyInfoPtr;
typedef boost::shared_ptr<KinBodyInfo const> KinBodyInfoConstPtr;

/// \brief Alias for list of non-colliding link pairs, mostly used for Grabbed checking.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// \brief Alias for list of non-colliding link pairs, mostly used for Grabbed checking.
/// \brief Alias for list of non-colliding link pairs, mainly used for collision checking for Grabbed.

using ListNonCollidingLinkPairs = std::list<std::pair<KinBody::LinkConstPtr, KinBody::LinkConstPtr> >;

/// \brief Saved data for Grabbed used in KinBodyStateSaver and KinBodyStateSaverRef
/// When KinBody::Grab, KinBody::Release, ...etc are called, new Grabbed instance is created in KinBody and the original ptr for the original Grabbed instance is swapped.
/// Thus, the original information of Grabbed instance is unchanged and holding the ptr of it as pGrabbed is enough for the saver.
Expand All @@ -2446,7 +2449,7 @@ class OPENRAVE_API KinBody : public InterfaceBase
struct SavedGrabbedData
{
GrabbedPtr pGrabbed; ///< pointer of original Grabbed instance, which originally in KinBody's _grabbedBodiesByEnvironmentIndex.
std::list<KinBody::LinkConstPtr> listNonCollidingLinksWhenGrabbed; ///< copied values of Grabbed's _listNonCollidingLinksWhenGrabbed. See also the documentation of Grabbed class.
ListNonCollidingLinkPairs listNonCollidingGrabbedGrabberLinkPairsWhenGrabbed; ///< copied values of Grabbed's _listNonCollidingGrabbedGrabberLinkPairsWhenGrabbed. See also the documentation of Grabbed class.
std::set<int> setGrabberLinkIndicesToIgnore; ///< copied values of Grabbed's _setGrabberLinkIndicesToIgnore. See also the documentation of Grabbed class.
bool listNonCollidingIsValid = false; ///< copied values of Grabbed's _listNonCollidingIsValid. See also the documentation of Grabbed class.
};
Expand Down Expand Up @@ -2485,6 +2488,7 @@ class OPENRAVE_API KinBody : public InterfaceBase
std::vector<dReal> _vdoflastsetvalues;
std::vector<dReal> _vMaxVelocities, _vMaxAccelerations, _vMaxJerks, _vDOFWeights, _vDOFLimits[2], _vDOFResolutions;
std::unordered_map<int, SavedGrabbedData> _grabbedDataByEnvironmentIndex;
std::unordered_map<uint64_t, ListNonCollidingLinkPairs> _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed;
bool _bRestoreOnDestructor;
private:
virtual void _RestoreKinBody(boost::shared_ptr<KinBody> body);
Expand Down Expand Up @@ -2531,6 +2535,7 @@ class OPENRAVE_API KinBody : public InterfaceBase
std::vector<dReal> _vdoflastsetvalues;
std::vector<dReal> _vMaxVelocities, _vMaxAccelerations, _vMaxJerks, _vDOFWeights, _vDOFLimits[2], _vDOFResolutions;
std::unordered_map<int, SavedGrabbedData> _grabbedDataByEnvironmentIndex;
std::unordered_map<uint64_t, ListNonCollidingLinkPairs> _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed;
bool _bRestoreOnDestructor;
bool _bReleased; ///< if true, then body should not be restored
private:
Expand Down Expand Up @@ -3716,10 +3721,12 @@ class OPENRAVE_API KinBody : public InterfaceBase
/// \param[in] savedBody : saved KinBody inside of saver.
/// \param[in] options : SaveParameters inside of saver.
/// \param[in] savedGrabbedBodiesByEnvironmentIndex : _grabbedBodiesByEnvironmentIndex held in saver.
/// \param[in] savedMapListNonCollidingInterGrabbedLinkPairsWhenGrabbed : _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed held in saver.
/// \param[in] bCalledFromClone : true this is called from clone, e.g. called from _RestoreGrabbedBodiesForClone. false if Assumes that this is called from _RestoreKinBody of saver classes.
void _RestoreGrabbedBodiesFromSavedData(const KinBody& savedBody,
const int options,
const std::unordered_map<int, SavedGrabbedData>& savedGrabbedDataByEnvironmentIndex,
const std::unordered_map<uint64_t, ListNonCollidingLinkPairs>& savedMapListNonCollidingInterGrabbedLinkPairsWhenGrabbed,
const bool bCalledFromClone = false);

/// \brief Save this kinbody's information.
Expand All @@ -3729,6 +3736,21 @@ class OPENRAVE_API KinBody : public InterfaceBase
/// Ensures that _vAllPairsShortestPaths is initialized if it is not already
void _EnsureAllPairsShortestPaths() const;

/// \brief Check if IsListNonCollidingLinksValid is true for the Grabbed instance with the given envBodyIndex.
/// \param[int] envBodyIndex : env body index.
bool _IsListNonCollidingLinksValidFromEnvironmentBodyIndex(const int envBodyIndex) const;

/// \brief Compute environment body indices pair. pack the two bodies' envBodyIndices (32bit int) into one environment body indices pair (uint64_t).
/// Here, environment body indices pair is uint64_t, which higher 32bits are for body2 envBodyIndex, and which lower 32bits are for body1 envBodyIndex.
/// Note that index1 < index2.
Comment on lines +3743 to +3745
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// \brief Compute environment body indices pair. pack the two bodies' envBodyIndices (32bit int) into one environment body indices pair (uint64_t).
/// Here, environment body indices pair is uint64_t, which higher 32bits are for body2 envBodyIndex, and which lower 32bits are for body1 envBodyIndex.
/// Note that index1 < index2.
/// \brief Returns a uint64_t that encodes the two given environment body indices. Body1's envBodyIndex is the lower
/// 32 bits. Body2's envBodyIndex is the higher 32 bits. This function is used to produce a key to
/// _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed, which is used for managing non-colliding link pairs
/// information between two grabbed bodies.
///
/// The inputs must be such that index1 < index2. Raises an exception if index1 < index2 is not satisfied.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snozawa Are there any particular reasons why you chose to force the caller to give correct ordering of indices instead of letting the function _ComputeEnvironmentBodyIndicesPair take care of ordering?

static uint64_t _ComputeEnvironmentBodyIndicesPair(const uint64_t index1, const uint64_t index2);

/// \brief Extract the first body's environmentBodyIndex from environment body indices pair.
static int _GetFirstEnvironmentBodyIndexFromPair(const uint64_t pair);

/// \brief Extract the first body's environmentBodyIndex from environment body indices pair.
static int _GetSecondEnvironmentBodyIndexFromPair(const uint64_t pair);

std::string _name; ///< name of body

std::vector<JointPtr> _vecjoints; ///< \see GetJoints
Expand Down Expand Up @@ -3798,6 +3820,7 @@ class OPENRAVE_API KinBody : public InterfaceBase
mutable std::string __hashKinematicsGeometryDynamics; ///< hash serializing kinematics, dynamics and geometry properties of the KinBody
int64_t _lastModifiedAtUS=0; ///< us, linux epoch, last modified time of the kinbody when it was originally loaded from the environment.
int64_t _revisionId = 0; ///< the webstack revision for this loaded kinbody
std::unordered_map<uint64_t, ListNonCollidingLinkPairs> _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed; ///< map of list of link pairs. This is computed when grabbed bodies are grabbed, and at taht time, two grabbed bodies are not touching each other. Since these links are not colliding at the time of grabbing, they should remain non-colliding with the grabbed body throughout. If, while grabbing, they collide with the grabbed body at some point, CheckSelfCollision should return true. It is important to note that the enable state of a link does *not* affect its membership of this list. Each pair in the list should be [Grabbed1-link, Grabbed2-link]. Note that this does not contain link pairs of [Grabbed-link, Grabber-link], c.f. Grabbed::_listNonCollidingGrabbedGrabberLinkPairsWhenGrabbed. Note that the key of this map is 'environment body indices pair', which lower 32bits are for the first KinBody's envBodyIndex, and which higher 32bits are for the second KinBody's envBodyIndex. The first envBodyIndex should be always smaller than the second envBodyIndex to simplify searching. Please also see _ComputeEnvironmentBodyIndicesPair.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
std::unordered_map<uint64_t, ListNonCollidingLinkPairs> _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed; ///< map of list of link pairs. This is computed when grabbed bodies are grabbed, and at taht time, two grabbed bodies are not touching each other. Since these links are not colliding at the time of grabbing, they should remain non-colliding with the grabbed body throughout. If, while grabbing, they collide with the grabbed body at some point, CheckSelfCollision should return true. It is important to note that the enable state of a link does *not* affect its membership of this list. Each pair in the list should be [Grabbed1-link, Grabbed2-link]. Note that this does not contain link pairs of [Grabbed-link, Grabber-link], c.f. Grabbed::_listNonCollidingGrabbedGrabberLinkPairsWhenGrabbed. Note that the key of this map is 'environment body indices pair', which lower 32bits are for the first KinBody's envBodyIndex, and which higher 32bits are for the second KinBody's envBodyIndex. The first envBodyIndex should be always smaller than the second envBodyIndex to simplify searching. Please also see _ComputeEnvironmentBodyIndicesPair.
/// _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed maps a pair of envBodyIndices of two grabbed bodies
/// (encoded into one uint64_t via _ComputeEnvironmentBodyIndicesPair) to a list of initially non-colliding link
/// pairs between the two. The ListNonCollidingLinkPairs for body1 and body2 is computed from state when the latest
/// body between body1 and body2 has been grabbed. Since these links in each pair are not colliding with each other
/// at the time of grabbing, they should remain non-colliding throughout (i.e. until either of them is released).
/// Notes:
/// - The enable states of links do *not* affect the membership of this ListNonCollidingLinkPair.
/// - ListNonCollidingLinkPair, which is the values of this map, only contains link pairs of *grabbed* bodies (i.e.
/// not grabber's links).
/// - Each link pair (grabbed1Link, grabbed2Link) in ListNonCollidingLinkPair must be such that the first element
/// corresponds to the grabbed body with lower environment body index.
std::unordered_map<uint64_t, ListNonCollidingLinkPairs> _mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed;


private:
mutable std::vector<dReal> _vTempJoints;
Expand Down Expand Up @@ -3873,11 +3896,21 @@ class OPENRAVE_API Grabbed : public UserData, public boost::enable_shared_from_t
// Member Variables
KinBodyWeakPtr _pGrabbedBody; ///< the body being grabbed
KinBody::LinkPtr _pGrabbingLink; ///< the link used for grabbing _pGrabbedBody. Its transform (as well as the transforms of other links rigidly attached to _pGrabbingLink) relative to the grabbed body remains constant until the grabbed body is released.
std::list<KinBody::LinkConstPtr> _listNonCollidingLinksWhenGrabbed; ///< list of links of the grabber that are not touching the grabbed body *at the time of grabbing*. Since these links are not colliding with the grabbed body at the time of grabbing, they should remain non-colliding with the grabbed body throughout. If, while grabbing, they collide with the grabbed body at some point, CheckSelfCollision should return true. It is important to note that the enable state of a link does *not* affect its membership of this list.
KinBody::ListNonCollidingLinkPairs _listNonCollidingGrabbedGrabberLinkPairsWhenGrabbed; ///< list of link pairs of the grabber that are not touching the grabbed body *at the time of grabbing*. Since these links are not colliding with the grabbed body at the time of grabbing, they should remain non-colliding with the grabbed body throughout. If, while grabbing, they collide with the grabbed body at some point, CheckSelfCollision should return true. It is important to note that the enable state of a link does *not* affect its membership of this list. Each pair in the list should be [Grabbed-link, Grabber-link]. Note that this does not contain link pairs from two grabbed bodies, c.f. KinBody::_mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed.
Transform _tRelative; ///< the relative transform between the grabbed body and the grabbing link. tGrabbingLink*tRelative = tGrabbedBody.
std::set<int> _setGrabberLinkIndicesToIgnore; ///< indices to the links of the grabber whose collisions with the grabbed bodies should be ignored.
rapidjson::Document _rGrabbedUserData; ///< user-defined data to be updated when kinbody grabs and releases objects
private:

/// \brief push inter-grabbed-bodies non colliding link pairs to grabber.
/// \param[out] pGrabber : updated grabber.
/// \param[out] pchecker : collision checker
/// \param[in] grabbedBody, otherGrabbedBody : grabbed body by this class, and other grabbed body to check.
void _PushNonCollidingLinkPairsForGrabbedBodies(KinBodyPtr& pGrabber,
CollisionCheckerBasePtr& pchecker,
const KinBody& grabbedBody,
const KinBody& otherGrabbedBody);

bool _listNonCollidingIsValid = false; ///< a flag indicating whether the current _listNonCollidingLinksWhenGrabbed is valid or not.
std::vector<KinBody::LinkPtr> _vAttachedToGrabbingLink; ///< vector of all links that are rigidly attached to _pGrabbingLink
KinBody::KinBodyStateSaverPtr _pGrabberSaver; ///< statesaver that saves the snapshot of the grabber at the time Grab is called. The saved state will be used (i.e. restored) temporarily when computation of _listNonCollidingLinksWhenGrabbed is necessary.
Expand Down
90 changes: 73 additions & 17 deletions src/libopenrave/kinbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5877,6 +5877,7 @@ void KinBody::Clone(InterfaceBaseConstPtr preference, int cloningoptions)
// clone the grabbed bodies, note that this can fail if the new cloned environment hasn't added the bodies yet (check out Environment::Clone)
_listAttachedBodies.clear(); // will be set in the environment
_grabbedBodiesByEnvironmentIndex.clear();
_mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed.clear();
if ((cloningoptions & Clone_IgnoreGrabbedBodies) != Clone_IgnoreGrabbedBodies) {
for (const MapGrabbedByEnvironmentIndex::value_type& otherGrabPair : r->_grabbedBodiesByEnvironmentIndex) {
const GrabbedPtr& pgrabbedref = otherGrabPair.second;
Expand Down Expand Up @@ -5905,25 +5906,22 @@ void KinBody::Clone(InterfaceBaseConstPtr preference, int cloningoptions)
pgrabbed->_setGrabberLinkIndicesToIgnore = pgrabbedref->_setGrabberLinkIndicesToIgnore; // can do this since link indices are the same
CopyRapidJsonDoc(pgrabbedref->_rGrabbedUserData, pgrabbed->_rGrabbedUserData);
if( pgrabbedref->IsListNonCollidingLinksValid() ) {
FOREACHC(itLinkRef, pgrabbedref->_listNonCollidingLinksWhenGrabbed) {
if( (*itLinkRef)->GetParent() == r ) {
pgrabbed->_listNonCollidingLinksWhenGrabbed.push_back(_veclinks.at((*itLinkRef)->GetIndex()));
FOREACHC(itLinkRef, pgrabbedref->_listNonCollidingGrabbedGrabberLinkPairsWhenGrabbed) {
if( (*itLinkRef).second->GetParent() != r ) {
RAVELOG_WARN_FORMAT("env=%s, could not restore link '%s' since parent in the list is different from cloning reference.", GetEnv()->GetNameId()%(*itLinkRef).second->GetName());
continue;
}
else {
KinBodyPtr pOtherGrabbedBody = GetEnv()->GetKinBody((*itLinkRef)->GetParent()->GetName());
if( !!pOtherGrabbedBody ) {
KinBody::LinkPtr plink = pOtherGrabbedBody->GetLink((*itLinkRef)->GetName());
if( !!plink ) {
pgrabbed->_listNonCollidingLinksWhenGrabbed.push_back(plink);
}
else {
RAVELOG_WARN_FORMAT("env=%s, When cloning body '%s' from env=%s, could not find non-colliding link %s in body %s.", GetEnv()->GetNameId()%GetName()%r->GetEnv()->GetNameId()%(*itLinkRef)->GetName()%(*itLinkRef)->GetParent()->GetName());
}
}
else {
RAVELOG_WARN_FORMAT("env=%s, When cloning body '%s' from env=%s, could not find body %s for non-colliding link %s.", GetEnv()->GetNameId()%GetName()%r->GetEnv()->GetNameId()%(*itLinkRef)->GetParent()->GetName()%(*itLinkRef)->GetName());
}
const int linkIndex = (*itLinkRef).second->GetIndex();
if( linkIndex < 0 || linkIndex >= (int)_veclinks.size()) {
RAVELOG_WARN_FORMAT("env=%s, could not restore link '%s' since its index %d is out of range (body num links is %d)", GetEnv()->GetNameId()%(*itLinkRef).second->GetName()%linkIndex%_veclinks.size());
continue;
}
const KinBody::LinkPtr pGrabbedBodyLink = pgrabbedbody->GetLink((*itLinkRef).first->GetName());
if( !pGrabbedBodyLink ) {
RAVELOG_WARN_FORMAT("env=%s, could not restore link '%s' since it's not in the links of body '%s'.", GetEnv()->GetNameId()%(*itLinkRef).first->GetName()%pgrabbedbody->GetName());
continue;
}
pgrabbed->_listNonCollidingGrabbedGrabberLinkPairsWhenGrabbed.emplace_back(pGrabbedBodyLink, _veclinks[linkIndex]);
}
pgrabbed->SetLinkNonCollidingIsValid(true);
}
Expand All @@ -5941,6 +5939,64 @@ void KinBody::Clone(InterfaceBaseConstPtr preference, int cloningoptions)
_grabbedBodiesByEnvironmentIndex[pgrabbedbody->GetEnvironmentBodyIndex()] = std::move(pgrabbed);
}
} // end for pgrabbedref

// map list of inter grabbed.
FOREACHC(itInfoRef, r->_mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed) {
const ListNonCollidingLinkPairs& pairsRef = itInfoRef->second;
const uint64_t envBodyIndicesPair = itInfoRef->first;
if( pairsRef.empty() ) {
continue;
}
if( !_IsListNonCollidingLinksValidFromEnvironmentBodyIndex(_GetFirstEnvironmentBodyIndexFromPair(envBodyIndicesPair)) ||
!_IsListNonCollidingLinksValidFromEnvironmentBodyIndex(_GetSecondEnvironmentBodyIndexFromPair(envBodyIndicesPair)) ) {
continue;
}
const KinBodyPtr pFirstRef = pairsRef.front().first->GetParent(true);
const KinBodyPtr pSecondRef = pairsRef.front().second->GetParent(true);
if( !pFirstRef || !pSecondRef ) {
continue; // somehow, relevant code in the above does not show warning nor exception. so, follow it for now.
}
const KinBodyPtr pFirst = GetEnv()->GetKinBody(pFirstRef->GetName());
if( !pFirst ) {
RAVELOG_WARN_FORMAT("env=%s, When cloning body '%s' from env=%s, could not find body %s for non-colliding link.", GetEnv()->GetNameId()%GetName()%r->GetEnv()->GetNameId()%pFirstRef->GetName());
continue;
}
const KinBodyPtr pSecond = GetEnv()->GetKinBody(pSecondRef->GetName());
if( !pSecond ) {
RAVELOG_WARN_FORMAT("env=%s, When cloning body '%s' from env=%s, could not find body %s for non-colliding link.", GetEnv()->GetNameId()%GetName()%r->GetEnv()->GetNameId()%pSecondRef->GetName());
continue;
}
ListNonCollidingLinkPairs listNonCollidingLinkPairs;
const int envBodyIndexFirst = pFirst->GetEnvironmentBodyIndex();
const int envBodyIndexSecond = pSecond->GetEnvironmentBodyIndex();
const bool bHasSmallerFirstIndex = envBodyIndexFirst < envBodyIndexSecond;
FOREACHC(itLinkPairRef, itInfoRef->second) {
const KinBody::LinkPtr pFirstLink = pFirst->GetLink((*itLinkPairRef).first->GetName());
if( !pFirstLink ) {
RAVELOG_WARN_FORMAT("env=%s, When cloning body '%s' from env=%s, could not find non-colliding link %s in body %s.", GetEnv()->GetNameId()%GetName()%r->GetEnv()->GetNameId()%(*itLinkPairRef).first->GetName()%pFirst->GetName());
continue;
}
const KinBody::LinkPtr pSecondLink = pSecond->GetLink((*itLinkPairRef).second->GetName());
if( !pSecondLink ) {
RAVELOG_WARN_FORMAT("env=%s, When cloning body '%s' from env=%s, could not find non-colliding link %s in body %s.", GetEnv()->GetNameId()%GetName()%r->GetEnv()->GetNameId()%(*itLinkPairRef).second->GetName()%pSecond->GetName());
continue;
}
if( bHasSmallerFirstIndex ) {
listNonCollidingLinkPairs.emplace_back(pFirstLink, pSecondLink);
}
else {
listNonCollidingLinkPairs.emplace_back(pSecondLink, pFirstLink);
}
}
if( listNonCollidingLinkPairs.size() > 0 ){
if( bHasSmallerFirstIndex ) {
_mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed.emplace(_ComputeEnvironmentBodyIndicesPair(envBodyIndexFirst, envBodyIndexSecond), std::move(listNonCollidingLinkPairs));
}
else {
_mapListNonCollidingInterGrabbedLinkPairsWhenGrabbed.emplace(_ComputeEnvironmentBodyIndicesPair(envBodyIndexSecond, envBodyIndexFirst), std::move(listNonCollidingLinkPairs));
}
}
}
} // end if not Clone_IgnoreGrabbedBodies

// Clone self-collision checker
Expand Down
Loading
Loading