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 malformed clusters crash #725

Merged
merged 3 commits into from
Nov 26, 2024
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
9 changes: 6 additions & 3 deletions ManiVault/src/util/MeanShift.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,18 @@ void MeanShift::cluster(const std::vector<Vector2f>& points, std::vector<std::ve
}

// Check if clusters contain their own cluster center.
// If not it is likely that the center is just a variation of an exisiting cluster and those should be merged
// If not it is likely that the center is just a variation of an existing cluster and those should be merged
#pragma omp parallel for
for (int i = 0; i < _clusterIds.size(); i++) {

Vector2f currentCenter = _meanshiftPixels[i];
int x = (int)(currentCenter.x * (RESOLUTION - 1) + 0.5);
int y = (int)(currentCenter.y * (RESOLUTION - 1) + 0.5);
int x = static_cast<int>(currentCenter.x * (RESOLUTION - 1) + 0.5);
int y = static_cast<int>(currentCenter.y * (RESOLUTION - 1) + 0.5);
int centerIdx = (x + y * RESOLUTION);

if (centerIdx < 0 || centerIdx >= _clusterIds.size())
continue;

if (_clusterIds[i] != _clusterIds[centerIdx] && _clusterIds[i] >= 0 && _clusterIds[centerIdx] >= 0)
{
//qDebug() << "Assigned from cluster " << _clusterIds[i] << " to " << _clusterIds[centerIdx] << "index: " << i << ", pos(" << currentCenter.x << ", " << currentCenter.y << ")";
Expand Down