| 1411 | } |
| 1412 | |
| 1413 | void vtkGenerateStatistics::ComputeCellToPointWeights( |
| 1414 | PointsOfCellsWeightMap& cellsToPointsToWeights, vtkDataSet* dataSet, |
| 1415 | const std::unordered_map<vtkIdType, vtkIdType>& subset) |
| 1416 | { |
| 1417 | vtkNew<vtkIdList> stupid; |
| 1418 | vtkSmartPointer<vtkDataArray> weights; |
| 1419 | if (this->WeightByCellMeasure) |
| 1420 | { |
| 1421 | vtkNew<vtkCellSizeFilter> computeMeasure; |
| 1422 | computeMeasure->SetInputDataObject(0, dataSet); |
| 1423 | computeMeasure->ComputeLengthOn(); |
| 1424 | computeMeasure->ComputeAreaOn(); |
| 1425 | computeMeasure->ComputeVolumeOn(); |
| 1426 | computeMeasure->SetLengthArrayName("measure"); |
| 1427 | computeMeasure->SetAreaArrayName("measure"); |
| 1428 | computeMeasure->SetVolumeArrayName("measure"); |
| 1429 | computeMeasure->Update(); |
| 1430 | weights = |
| 1431 | vtkDataSet::SafeDownCast(computeMeasure->GetOutput(0))->GetCellData()->GetArray("measure"); |
| 1432 | } |
| 1433 | if (subset.empty()) |
| 1434 | { |
| 1435 | // Compute all cell-to-point weights |
| 1436 | vtkIdType numberOfCells = dataSet->GetNumberOfCells(); |
| 1437 | vtkIdType npts; |
| 1438 | vtkIdType const* conn; |
| 1439 | for (vtkIdType cc = 0; cc < numberOfCells; ++cc) |
| 1440 | { |
| 1441 | dataSet->GetCellPoints(cc, npts, conn, stupid); |
| 1442 | double weight = 1. / npts; |
| 1443 | if (this->WeightByCellMeasure) |
| 1444 | { |
| 1445 | weights->GetTuple(cc, &weight); |
| 1446 | weight = weight / npts; |
| 1447 | } |
| 1448 | for (vtkIdType jj = 0; jj < npts; ++jj) |
| 1449 | { |
| 1450 | cellsToPointsToWeights[cc][conn[jj]] = weight; |
| 1451 | } |
| 1452 | } |
| 1453 | } |
| 1454 | else |
| 1455 | { |
| 1456 | // Compute only weights for point IDs listed in subset. |
| 1457 | double weight; |
| 1458 | for (const auto& entry : subset) |
| 1459 | { |
| 1460 | auto pointId = entry.first; |
| 1461 | dataSet->GetPointCells(pointId, stupid); |
| 1462 | for (const auto& cellId : *stupid) |
| 1463 | { |
| 1464 | auto npts = dataSet->GetCellSize(cellId); |
| 1465 | if (this->WeightByCellMeasure) |
| 1466 | { |
| 1467 | weights->GetTuple(cellId, &weight); |
| 1468 | weight = weight / npts; |
| 1469 | } |
| 1470 | else |
no test coverage detected