refactor some stuff

This commit is contained in:
papush! 2022-03-24 13:24:04 +01:00
parent 36194f715e
commit 1782687e9a
5 changed files with 35 additions and 23 deletions

View File

@ -15,6 +15,7 @@ vtkIdType findClosestPoint(const double *point, vtkPointSet *pointSet) {
minPoint = i; minPoint = i;
} }
} }
std::cerr << "closest: " << minPoint << "\n";
return minPoint; return minPoint;
} }

View File

@ -48,7 +48,22 @@ void findPointsWithinRadius(double radius, vtkPointSet *pointSet,
} }
void ProjectSurfacePointsOnPoly::moveSurfacePoint(vtkUnstructuredGrid *tetMesh, vtkSmartPointer<vtkIdList> removeSurfacePoints(vtkIdList *list,
vtkIntArray *isSurface) {
vtkNew<vtkIdList> affectedPoints;
affectedPoints->Allocate(list->GetNumberOfIds());
for (vtkIdType i = 0; i < list->GetNumberOfIds(); i++) {
vtkIdType id = list->GetId(i);
if (!isSurface->GetValue(id)) {
affectedPoints->InsertNextId(id);
}
}
return affectedPoints;
}
void ProjectSurfacePointsOnPoly::moveSurfacePoint(
vtkUnstructuredGrid *tetMesh,
vtkPolyData *polyMesh, vtkPolyData *polyMesh,
vtkIdType pointId, vtkIdType pointId,
std::vector<double> &motionVectors, std::vector<double> &motionVectors,
@ -60,11 +75,11 @@ void ProjectSurfacePointsOnPoly::moveSurfacePoint(vtkUnstructuredGrid *tetMesh,
tetMesh->GetPoint(pointId, point); tetMesh->GetPoint(pointId, point);
double direction[3]; double direction[3];
double distance; double distance;
closestPolyMeshPoint( closestPolyMeshPoint(
polyMesh, point, polyMeshKdTree, links, direction, &distance); polyMesh, point, polyMeshKdTree, links, direction, &distance);
vtkNew<vtkIdList> affectedPoints; vtkNew<vtkIdList> pointsInRadius;
findPointsWithinRadius(distance * RadiusScale, tetMesh, point, affectedPoints); findPointsWithinRadius(distance * RadiusScale, tetMesh, point, pointsInRadius);
auto affectedPoints = removeSurfacePoints(pointsInRadius, isSurface);
// tetMeshKdTree->FindPointsWithinRadius(distance * RadiusScale, point, affectedPoints); // tetMeshKdTree->FindPointsWithinRadius(distance * RadiusScale, point, affectedPoints);
if(distance > 0) for (vtkIdType j = 0; j < affectedPoints->GetNumberOfIds(); j++) { if(distance > 0) for (vtkIdType j = 0; j < affectedPoints->GetNumberOfIds(); j++) {
@ -96,20 +111,13 @@ void ProjectSurfacePointsOnPoly::moveSurfacePoint(vtkUnstructuredGrid *tetMesh,
static void applyMotionVectors(vtkUnstructuredGrid *tetMesh, static void applyMotionVectors(vtkUnstructuredGrid *tetMesh,
vtkIdTypeArray *surfacePoints,
std::vector<double> &motionVectors, std::vector<double> &motionVectors,
const std::vector<unsigned> &numberOfAffectors) { const std::vector<unsigned> &numberOfAffectors) {
for (vtkIdType i = 0; i < tetMesh->GetNumberOfPoints(); i++) { for (vtkIdType i = 0; i < tetMesh->GetNumberOfPoints(); i++) {
bool skip = false;
for (vtkIdType j = 0; j < surfacePoints->GetNumberOfTuples(); j++) {
if (i == surfacePoints->GetValue(j)) skip = true;
}
if (skip) continue;
if(numberOfAffectors[i] == 0) continue; if(numberOfAffectors[i] == 0) continue;
double point[3]; double point[3];
tetMesh->GetPoint(i, point); tetMesh->GetPoint(i, point);
double *motion = motionVectors.data() + (i * 3); double *motion = motionVectors.data() + (i * 3);
vtkMath::MultiplyScalar(motion, 1. / numberOfAffectors[i]); vtkMath::MultiplyScalar(motion, 1. / numberOfAffectors[i]);
vtkMath::Subtract(point, motion, point); vtkMath::Subtract(point, motion, point);
tetMesh->GetPoints()->SetPoint(i, point); tetMesh->GetPoints()->SetPoint(i, point);
@ -142,7 +150,9 @@ vtkTypeBool ProjectSurfacePointsOnPoly::RequestData(
tetMeshKdTree->BuildLocatorFromPoints(vtkPointSet::SafeDownCast(tetMesh)); tetMeshKdTree->BuildLocatorFromPoints(vtkPointSet::SafeDownCast(tetMesh));
vtkIdTypeArray *surfacePoints = vtkIdTypeArray *surfacePoints =
vtkIdTypeArray::SafeDownCast(tetMesh->GetFieldData()->GetArray("surface_points")); vtkIdTypeArray::SafeDownCast(tetMesh->GetFieldData()->GetArray("surfacePoints"));
isSurface = vtkIntArray::SafeDownCast(
output->GetPointData()->GetArray("isSurface"));
std::vector<double> motionVectors(3 * tetMesh->GetNumberOfPoints(), 0); std::vector<double> motionVectors(3 * tetMesh->GetNumberOfPoints(), 0);
std::vector<unsigned> numberOfAffectors(tetMesh->GetNumberOfPoints(), 0); std::vector<unsigned> numberOfAffectors(tetMesh->GetNumberOfPoints(), 0);
for (vtkIdType i = 0; i < surfacePoints->GetNumberOfTuples(); i++) { for (vtkIdType i = 0; i < surfacePoints->GetNumberOfTuples(); i++) {
@ -153,8 +163,7 @@ vtkTypeBool ProjectSurfacePointsOnPoly::RequestData(
polyMeshKdTree, tetMeshKdTree, polyMeshKdTree, tetMeshKdTree,
links); links);
} }
applyMotionVectors(tetMesh, surfacePoints, applyMotionVectors(tetMesh, motionVectors, numberOfAffectors);
motionVectors, numberOfAffectors);
return true; return true;
} }

View File

@ -25,6 +25,8 @@ public:
protected: protected:
int affectedNeighborsCount = 0; int affectedNeighborsCount = 0;
double RadiusScale; double RadiusScale;
vtkIntArray *isSurface = nullptr;
~ProjectSurfacePointsOnPoly() override = default; ~ProjectSurfacePointsOnPoly() override = default;
void moveSurfacePoint(vtkUnstructuredGrid *tetMesh, void moveSurfacePoint(vtkUnstructuredGrid *tetMesh,

View File

@ -30,7 +30,7 @@ vtkTypeBool RelaxationFilter::RequestData(
vtkNew<vtkIdList> neighborCells; vtkNew<vtkIdList> neighborCells;
vtkNew<vtkIdList> cellPoints; vtkNew<vtkIdList> cellPoints;
vtkIdTypeArray *surfacePoints = vtkIdTypeArray::SafeDownCast( vtkIdTypeArray *surfacePoints = vtkIdTypeArray::SafeDownCast(
output->GetFieldData()->GetArray("surface_points")); output->GetFieldData()->GetArray("surfacePoints"));
vtkIntArray *isSurface = vtkIntArray::SafeDownCast( vtkIntArray *isSurface = vtkIntArray::SafeDownCast(
output->GetPointData()->GetArray("isSurface")); output->GetPointData()->GetArray("isSurface"));
std::set<vtkIdType> neighbors; std::set<vtkIdType> neighbors;

View File

@ -32,7 +32,7 @@ vtkTypeBool SurfacePointsFilter::RequestData(
/* Create an array to store the IDs of surface points. */ /* Create an array to store the IDs of surface points. */
vtkNew<vtkIdTypeArray> surfacePoints; vtkNew<vtkIdTypeArray> surfacePoints;
surfacePoints->SetName("surface_points"); surfacePoints->SetName("surfacePoints");
surfacePoints->SetNumberOfComponents(1); surfacePoints->SetNumberOfComponents(1);
vtkNew<vtkIntArray> isSurface; vtkNew<vtkIntArray> isSurface;
isSurface->SetName("isSurface"); isSurface->SetName("isSurface");