iterate over surface points directly in the relaxation

This commit is contained in:
papush! 2022-03-16 13:00:49 +01:00
parent ffe5a68504
commit dacb2ffa04

View File

@ -25,16 +25,18 @@ vtkTypeBool RelaxationFilter::RequestData(
newPoints->DeepCopy(output->GetPoints()); newPoints->DeepCopy(output->GetPoints());
vtkNew<vtkIdList> neighborCells; vtkNew<vtkIdList> neighborCells;
vtkNew<vtkIdList> cellPoints; vtkNew<vtkIdList> cellPoints;
vtkIdTypeArray *surfacePoints = vtkIdTypeArray::SafeDownCast(
output->GetFieldData()->GetArray("surface_points"));
vtkIntArray *isSurface = vtkIntArray::SafeDownCast( vtkIntArray *isSurface = vtkIntArray::SafeDownCast(
output->GetPointData()->GetArray("isSurface")); output->GetPointData()->GetArray("isSurface"));
std::set<vtkIdType> neighbors; std::set<vtkIdType> neighbors;
output->BuildLinks(); output->BuildLinks();
double avg[3]; double avg[3];
for (vtkIdType i = 0; i < output->GetNumberOfPoints(); i++) { for (vtkIdType i = 0; i < surfacePoints->GetNumberOfValues(); i++) {
if (!isSurface->GetValue(i)) continue; vtkIdType id = surfacePoints->GetValue(i);
output->GetPointCells(i, neighborCells); output->GetPointCells(id, neighborCells);
if (neighborCells->GetNumberOfIds() != 0) { if (neighborCells->GetNumberOfIds() != 0) {
@ -52,10 +54,7 @@ vtkTypeBool RelaxationFilter::RequestData(
} }
cellPoints->Reset(); cellPoints->Reset();
} }
neighbors.erase(neighbors.find(id));
if (neighbors.find(i) != neighbors.end()) {
neighbors.erase(neighbors.find(i));
}
if (neighbors.size() != 0) { if (neighbors.size() != 0) {
avg[0] = 0; avg[1] = 0; avg[2] = 0; avg[0] = 0; avg[1] = 0; avg[2] = 0;
for (const vtkIdType &j : neighbors) { for (const vtkIdType &j : neighbors) {
@ -64,7 +63,7 @@ vtkTypeBool RelaxationFilter::RequestData(
vtkMath::Add(point, avg, avg); vtkMath::Add(point, avg, avg);
} }
vtkMath::MultiplyScalar(avg, 1. / neighbors.size()); vtkMath::MultiplyScalar(avg, 1. / neighbors.size());
newPoints->SetPoint(i, avg); newPoints->SetPoint(id, avg);
} }
} }
neighborCells->Reset(); neighborCells->Reset();