| 1357 | } |
| 1358 | |
| 1359 | void vtkGenerateStatistics::GenerateSubset(std::unordered_map<vtkIdType, vtkIdType>& subset, |
| 1360 | vtkIdType numberOfSamples, double trainingFraction, vtkUnsignedCharArray* ghostData, |
| 1361 | unsigned char ghostMask) |
| 1362 | { |
| 1363 | if (!ghostData) |
| 1364 | { |
| 1365 | vtkReservoirSampler<vtkIdType, /* monotonic output */ false> sampler; |
| 1366 | std::vector<vtkIdType> ids = sampler(numberOfSamples * trainingFraction, numberOfSamples); |
| 1367 | vtkIdType out = 0; |
| 1368 | for (const auto& id : ids) |
| 1369 | { |
| 1370 | subset[id] = out; |
| 1371 | ++out; |
| 1372 | } |
| 1373 | } |
| 1374 | else |
| 1375 | { |
| 1376 | vtkIdType actualNumberOfSamples = 0; |
| 1377 | // Count non-ghost values: |
| 1378 | for (vtkIdType ii = 0; ii < ghostData->GetNumberOfValues(); ++ii) |
| 1379 | { |
| 1380 | if ((ghostData->GetValue(ii) & ghostMask) == 0) |
| 1381 | { |
| 1382 | ++actualNumberOfSamples; |
| 1383 | } |
| 1384 | } |
| 1385 | // Compute indices as if ghost values were not present: |
| 1386 | vtkReservoirSampler<vtkIdType, /* monotonic output */ true> sampler; |
| 1387 | std::vector<vtkIdType> ids = |
| 1388 | sampler(actualNumberOfSamples * trainingFraction, actualNumberOfSamples); |
| 1389 | // Compute actual sample indices by skipping ghosts: |
| 1390 | vtkIdType virtualIndex = 0; |
| 1391 | auto idIt = ids.begin(); |
| 1392 | vtkIdType out = 0; |
| 1393 | for (vtkIdType ii = 0; ii < ghostData->GetNumberOfValues(); ++ii) |
| 1394 | { |
| 1395 | if ((ghostData->GetValue(ii) & ghostMask) == 0) |
| 1396 | { |
| 1397 | if (*idIt == virtualIndex) |
| 1398 | { |
| 1399 | subset[ii] = out++; |
| 1400 | ++idIt; |
| 1401 | if (idIt == ids.end()) |
| 1402 | { |
| 1403 | // Terminate early; we have all our samples. |
| 1404 | break; |
| 1405 | } |
| 1406 | } |
| 1407 | ++virtualIndex; |
| 1408 | } |
| 1409 | } |
| 1410 | } |
| 1411 | } |
| 1412 | |
| 1413 | void vtkGenerateStatistics::ComputeCellToPointWeights( |
| 1414 | PointsOfCellsWeightMap& cellsToPointsToWeights, vtkDataSet* dataSet, |
no test coverage detected