|
31 | 31 |
|
32 | 32 | #include <algorithm> |
33 | 33 | #include <cassert> |
| 34 | +#include <exception> |
34 | 35 | #include <map> |
35 | 36 | #include <optional> |
36 | 37 | #include <ranges> |
@@ -738,44 +739,56 @@ void ScatterplotPlugin::loadColors(const Dataset<Points>& pointsColor, const std |
738 | 739 | // If number of points do not match, prefer checking for derived data over selection mapping |
739 | 740 | if (numColorPoints != _numPoints) { |
740 | 741 |
|
741 | | - const bool hasSameNumPointsAsFull = |
742 | | - /*if*/ _positionDataset->isDerivedData() ? |
743 | | - /*then*/ _positionSourceDataset->getFullDataset<Points>()->getNumPoints() == numColorPoints : |
744 | | - /*else*/ false; |
| 742 | + try { |
745 | 743 |
|
746 | | - if (hasSameNumPointsAsFull) { |
747 | | - std::vector<std::uint32_t> globalIndices; |
748 | | - _positionDataset->getGlobalIndices(globalIndices); |
| 744 | + const bool hasSameNumPointsAsFull = |
| 745 | + /*if*/ _positionDataset->isDerivedData() ? |
| 746 | + /*then*/ _positionSourceDataset->getFullDataset<Points>()->getNumPoints() == numColorPoints : |
| 747 | + /*else*/ false; |
749 | 748 |
|
750 | | - std::vector<float> localScalars(_numPoints, 0); |
751 | | - std::int32_t localColorIndex = 0; |
| 749 | + if (hasSameNumPointsAsFull) { |
| 750 | + std::vector<std::uint32_t> globalIndices; |
| 751 | + _positionDataset->getGlobalIndices(globalIndices); |
752 | 752 |
|
753 | | - for (const auto& globalIndex : globalIndices) |
754 | | - localScalars[localColorIndex++] = scalars[globalIndex]; |
| 753 | + std::vector<float> localScalars(_numPoints, 0); |
| 754 | + std::int32_t localColorIndex = 0; |
755 | 755 |
|
756 | | - std::swap(localScalars, scalars); |
757 | | - } |
758 | | - else if ( // only get map if derived check failed |
759 | | - const auto selectionMapping = getSelectionMapping(pointsColor, _positionDataset); |
760 | | - /* check if valid */ selectionMapping.has_value() && selectionMapping.value() != nullptr |
761 | | - ) |
762 | | - { |
763 | | - std::vector<float> localScalars(_numPoints, 0); |
| 756 | + for (const auto& globalIndex : globalIndices) |
| 757 | + localScalars[localColorIndex++] = scalars[globalIndex]; |
| 758 | + |
| 759 | + std::swap(localScalars, scalars); |
| 760 | + } |
| 761 | + else if ( // only get map if derived check failed |
| 762 | + const auto selectionMapping = getSelectionMapping(pointsColor, _positionDataset); |
| 763 | + /* check if valid */ selectionMapping.has_value() && selectionMapping.value() != nullptr |
| 764 | + ) |
| 765 | + { |
| 766 | + std::vector<float> localScalars(_numPoints, 0); |
764 | 767 |
|
765 | | - // Map values like selection |
766 | | - const mv::SelectionMap::Map& linkedMap = selectionMapping.value()->getMapping().getMap(); |
767 | | - const std::uint32_t numPointsInTarget = _positionDataset->getNumPoints(); |
| 768 | + // Map values like selection |
| 769 | + const mv::SelectionMap::Map& linkedMap = selectionMapping.value()->getMapping().getMap(); |
| 770 | + const std::uint32_t numPointsInTarget = _positionDataset->getNumPoints(); |
768 | 771 |
|
769 | | - for (const auto& [fromID, vecOfIDs] : linkedMap) { |
770 | | - for (std::uint32_t toID : vecOfIDs) { |
771 | | - localScalars[toID] = scalars[fromID]; |
| 772 | + for (const auto& [fromID, vecOfIDs] : linkedMap) { |
| 773 | + for (std::uint32_t toID : vecOfIDs) { |
| 774 | + localScalars[toID] = scalars[fromID]; |
| 775 | + } |
772 | 776 | } |
| 777 | + |
| 778 | + std::swap(localScalars, scalars); |
| 779 | + } |
| 780 | + else { |
| 781 | + qWarning("Number of points used for coloring does not match number of points in data, aborting attempt to color plot"); |
| 782 | + return; |
773 | 783 | } |
774 | 784 |
|
775 | | - std::swap(localScalars, scalars); |
776 | 785 | } |
777 | | - else { |
778 | | - qWarning("Number of points used for coloring does not match number of points in data, aborting attempt to color plot"); |
| 786 | + catch (const std::exception& e) { |
| 787 | + qDebug() << "ScatterplotPlugin::loadColors: mapping failed -> " << e.what(); |
| 788 | + return; |
| 789 | + } |
| 790 | + catch (...) { |
| 791 | + qDebug() << "ScatterplotPlugin::loadColors: mapping failed for an unknown reason."; |
779 | 792 | return; |
780 | 793 | } |
781 | 794 | } |
|
0 commit comments