Skip to content

Commit

Permalink
Fix the inverted selection better, so it only inverts within the subset
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianThijssen committed Nov 20, 2024
1 parent 15ea0ad commit a136e05
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions ManiVault/src/plugins/PointData/src/PointData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,20 +889,30 @@ void Points::selectNone()

void Points::selectInvert()
{
std::vector<unsigned int> selectionIndices;

auto selection = getSelection<Points>();

std::set<std::uint32_t> selectionSet(selection->indices.begin(), selection->indices.end());
// Get the locally selected indices (the points in the subset that are selected)
std::vector<unsigned int> localSelectionIndices;
getLocalSelectionIndices(localSelectionIndices);

const auto numberOfPoints = getFullDataset<Points>()->getNumPoints();
// Compute the inverse of this
const auto numberOfPoints = getNumPoints();
std::set<std::uint32_t> selectionSet(localSelectionIndices.begin(), localSelectionIndices.end());

std::vector<unsigned int> selectionIndices;
selectionIndices.reserve(numberOfPoints - selectionSet.size());

for (std::uint32_t i = 0; i < numberOfPoints; i++)
if (selectionSet.find(i) == selectionSet.end())
selectionIndices.push_back(i);

// Convert the inverted indices back to global indices
std::vector<unsigned int> globalIndices;
getGlobalIndices(globalIndices);

for (unsigned int& index : selectionIndices)
{
index = globalIndices[index];
}

setSelectionIndices(selectionIndices);

events().notifyDatasetDataSelectionChanged(this);
Expand Down

0 comments on commit a136e05

Please sign in to comment.