Skip to content

Commit

Permalink
[bullet] Add find or construct link (#175)
Browse files Browse the repository at this point in the history
* Add Find or Construct Link function
* Change function to return entity instead of identity
* Remove loop creating links inside model

Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
Signed-off-by: Tomas Lorente <jtlorente@ekumenlabs.com>
  • Loading branch information
Blast545 authored and Lobotuerk committed May 19, 2021
1 parent 1dfc2e7 commit 24041d8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
27 changes: 21 additions & 6 deletions bullet/src/SDFFeatures.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ Identity SDFFeatures::ConstructSdfModel(
// const auto &world = this->worlds.at(_worldID)->world;
const auto modelIdentity = this->AddModel({name, _worldID, isStatic, pose});

// Build links
for (std::size_t i = 0; i < _sdfModel.LinkCount(); ++i)
{
this->ConstructSdfLink(modelIdentity, *_sdfModel.LinkByIndex(i));
}

return modelIdentity;
}

Expand Down Expand Up @@ -172,6 +166,27 @@ Identity SDFFeatures::ConstructSdfCollision(
return this->GenerateInvalidId();
}

/////////////////////////////////////////////////
std::size_t SDFFeatures::FindOrConstructSdfLink(
const Identity &_modelID,
const ::sdf::Link &_sdfLink)
{
// Check if there is a model with the requested name
const std::string linkName = _sdfLink.Name();

for (const auto &link : this->links)
{
const auto &linkInfo = link.second;
if (linkInfo->name == linkName)
{
// A link was previously created with that name,
// Return its entity value
return link.first;
}
}
return this->ConstructSdfLink(_modelID, _sdfLink);
}

}
}
}
3 changes: 3 additions & 0 deletions bullet/src/SDFFeatures.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class SDFFeatures :
private: Identity ConstructSdfCollision(
const Identity &_linkID,
const ::sdf::Collision &_collision) override;
private: std::size_t FindOrConstructSdfLink(
const Identity &_modelID,
const ::sdf::Link &_sdfLink);
};

}
Expand Down

0 comments on commit 24041d8

Please sign in to comment.