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

Get a brief string summary of a contact map #1079

Merged
Merged
Changes from all commits
Commits
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
40 changes: 40 additions & 0 deletions tesseract_collision/core/include/tesseract_collision/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,46 @@ class ContactResultMap
bool operator==(const ContactResultMap& rhs) const;
bool operator!=(const ContactResultMap& rhs) const;

/** @brief Get a brief summary of the most frequently colliding link pair
* @return A string containing the collision summary
*/
std::string getSummary() const
{
std::stringstream ss;
std::map<KeyType, std::size_t> collision_counts;
std::map<KeyType, double> closest_distances;

// Initialize distances map with max values
for (const auto& pair : data_)
{
if (!pair.second.empty())
{
collision_counts[pair.first] = pair.second.size();
closest_distances[pair.first] = std::numeric_limits<double>::max();

// Find closest distance for this pair
for (const auto& result : pair.second)
{
closest_distances[pair.first] = std::min(closest_distances[pair.first], result.distance);
}
}
}

if (collision_counts.empty())
{
return "No collisions detected";
}

auto max_element = std::max_element(collision_counts.begin(),
collision_counts.end(),
[](const auto& p1, const auto& p2) { return p1.second < p2.second; });

ss << max_element->first.first << " - " << max_element->first.second << ": " << max_element->second
<< " collisions, min dist: " << closest_distances[max_element->first];

return ss.str();
}

private:
ContainerType data_;
long count_{ 0 };
Expand Down
Loading