3434#include < algorithm>
3535#include < cassert>
3636#include < exception>
37- #include < limits>
3837#include < map>
3938#include < stdexcept>
4039#include < vector>
4140
42- #ifdef __cpp_lib_execution
43- #ifdef __GNUC__ // both TBB and Qt define emit keyword: undef
44- #undef emit
45- #endif
46- #include < execution>
47- #ifdef __GNUC__ // both TBB and Qt define emit keyword: def again
48- #define emit
49- #endif
50- #ifdef NDEBUG
51- #define MV_SCATTER_PARALLEL_EXECUTION std::execution::par,
52- #else
53- #define MV_SCATTER_PARALLEL_EXECUTION std::execution::seq,
54- #endif
55- #else
56- #define MV_SCATTER_PARALLEL_EXECUTION
57- #endif
58-
5941#define VIEW_SAMPLING_HTML
6042// #define VIEW_SAMPLING_WIDGET
6143
@@ -69,7 +51,6 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
6951 _dropWidget(nullptr ),
7052 _scatterPlotWidget(new ScatterplotWidget(this )),
7153 _numPoints(0 ),
72- _numTotalPoints(0 ),
7354 _settingsAction(new SettingsAction(this , " Settings" )),
7455 _primaryToolbarAction(new HorizontalToolbarAction(this , " Primary Toolbar" ))
7556{
@@ -264,39 +245,19 @@ ScatterplotPlugin::ScatterplotPlugin(const PluginFactory* factory) :
264245 {
265246 // Check to set whether the number of data points comprised throughout all clusters is the same number
266247 // as the number of data points in the dataset we are trying to color
267- // std::uint64_t totalNumIndices = 0;
268- // for (const Cluster& cluster : candidateDataset->getClusters())
269- // {
270- // totalNumIndices += cluster.getIndices().size();
271- // }
272-
273- auto getMaxIndex = [](const QVector<Cluster>& clusters) -> std::uint32_t
274- {
275- if (clusters.empty ())
276- return std::numeric_limits<std::uint32_t >::lowest ();
277-
278- std::vector<std::uint32_t > clusterIndicesMax (clusters.size ());
279-
280- std::transform (
281- MV_SCATTER_PARALLEL_EXECUTION
282- clusters.cbegin (), clusters.cend (),
283- clusterIndicesMax.begin (),
284- [](const Cluster& cluster) -> std::uint32_t {
285- const std::vector<std::uint32_t >& indices = cluster.getIndices ();
286- if (indices.empty ())
287- return std::numeric_limits<std::uint32_t >::lowest ();
288-
289- return *std::ranges::max_element (indices);
290- });
291-
292- return *std::max_element (
293- MV_SCATTER_PARALLEL_EXECUTION
294- clusterIndicesMax.cbegin (), clusterIndicesMax.cend ());
295- };
296-
297- const auto maxIndex = getMaxIndex (candidateDataset->getClusters ());
298-
299- if (maxIndex < _numTotalPoints)
248+ std::uint64_t totalNumIndices = 0 ;
249+ for (const Cluster& cluster : candidateDataset->getClusters ())
250+ {
251+ totalNumIndices += cluster.getIndices ().size ();
252+ }
253+
254+ std::uint64_t totalNumPoints = 0 ;
255+ if (_positionDataset->isDerivedData ())
256+ totalNumPoints = _positionSourceDataset->getFullDataset <Points>()->getNumPoints ();
257+ else
258+ totalNumPoints = _positionDataset->getFullDataset <Points>()->getNumPoints ();
259+
260+ if (totalNumIndices == totalNumPoints)
300261 {
301262 // Use the clusters set for points color
302263 dropRegions << new DropWidget::DropRegion (this , " Color" , description, " palette" , true , [this , candidateDataset]() {
@@ -746,10 +707,6 @@ void ScatterplotPlugin::positionDatasetChanged()
746707
747708 _numPoints = _positionDataset->getNumPoints ();
748709
749- _numTotalPoints = _positionDataset->isDerivedData ()
750- ? _positionSourceDataset->getFullDataset <Points>()->getNumPoints ()
751- : _positionDataset->getFullDataset <Points>()->getNumPoints ();
752-
753710 _scatterPlotWidget->getPointRendererNavigator ().resetView (true );
754711 _scatterPlotWidget->getDensityRendererNavigator ().resetView (true );
755712
@@ -942,27 +899,35 @@ void ScatterplotPlugin::loadColors(const Dataset<Clusters>& clusters)
942899 if (!clusters.isValid () || !_positionDataset.isValid ())
943900 return ;
944901
902+ // Get global indices from the position dataset
903+ std::uint64_t totalNumPoints = 0 ;
904+ if (_positionDataset->isDerivedData ())
905+ totalNumPoints = _positionSourceDataset->getFullDataset <Points>()->getNumPoints ();
906+ else
907+ totalNumPoints = _positionDataset->getFullDataset <Points>()->getNumPoints ();
908+
945909 // Mapping from local to global indices
946910 std::vector<std::uint32_t > globalIndices;
947911 _positionDataset->getGlobalIndices (globalIndices);
948912
949913 // Generate color buffer for global and local colors
950- std::vector<Vector3f> globalColors (_numTotalPoints );
914+ std::vector<Vector3f> globalColors (totalNumPoints );
951915 std::vector<Vector3f> localColors (_numPoints);
952916
953917 const auto & clusterVec = clusters->getClusters ();
954918
955- if (_numTotalPoints == _numPoints && static_cast < uint64_t >( clusterVec.size ()) == _numTotalPoints )
919+ if (totalNumPoints == _numPoints && clusterVec.size () == totalNumPoints )
956920 {
957- // Each cluster corresponds to one point
958- for (const auto & cluster : clusterVec)
921+ for (size_t i = 0 ; i < static_cast <size_t >(clusterVec.size ()); i++)
959922 {
923+ const auto & cluster = clusterVec[i];
960924 const auto color = cluster.getColor ();
925+
961926 localColors[cluster.getIndices ()[0 ]] = Vector3f (color.redF (), color.greenF (), color.blueF ());
962927 }
963928
964929 }
965- else
930+ else if (globalIndices. size () == _numPoints)
966931 {
967932 // Loop over all clusters and populate global colors
968933 for (const auto & cluster : clusterVec)
0 commit comments