Skip to content

Commit 6eaf022

Browse files
authored
Don't crash when color cluster size == number of points (#150)
1 parent b07f1b6 commit 6eaf022

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/ScatterplotPlugin.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -605,15 +605,33 @@ void ScatterplotPlugin::loadColors(const Dataset<Clusters>& clusters)
605605
std::vector<Vector3f> globalColors(totalNumPoints);
606606
std::vector<Vector3f> localColors(_positions.size());
607607

608-
// Loop over all clusters and populate global colors
609-
for (const auto& cluster : clusters->getClusters())
610-
for (const auto& index : cluster.getIndices())
611-
globalColors[index] = Vector3f(cluster.getColor().redF(), cluster.getColor().greenF(), cluster.getColor().blueF());
612-
std::int32_t localColorIndex = 0;
613-
614-
// Loop over all global indices and find the corresponding local color
615-
for (const auto& globalIndex : globalIndices)
616-
localColors[localColorIndex++] = globalColors[globalIndex];
608+
const auto& clusterVec = clusters->getClusters();
609+
610+
if (totalNumPoints == _positions.size() && clusterVec.size() == totalNumPoints)
611+
{
612+
for (size_t i = 0; i < static_cast<size_t>(clusterVec.size()); i++)
613+
{
614+
const auto color = clusterVec[i].getColor();
615+
localColors[i] = Vector3f(color.redF(), color.greenF(), color.blueF());
616+
}
617+
618+
}
619+
else
620+
{
621+
// Loop over all clusters and populate global colors
622+
for (const auto& cluster : clusterVec)
623+
{
624+
const auto color = cluster.getColor();
625+
for (const auto& index : cluster.getIndices())
626+
globalColors[index] = Vector3f(color.redF(), color.greenF(), color.blueF());
627+
628+
}
629+
630+
// Loop over all global indices and find the corresponding local color
631+
std::int32_t localColorIndex = 0;
632+
for (const auto& globalIndex : globalIndices)
633+
localColors[localColorIndex++] = globalColors[globalIndex];
634+
}
617635

618636
// Apply colors to scatter plot widget without modification
619637
_scatterPlotWidget->setColors(localColors);

0 commit comments

Comments
 (0)