refactor some stuff
This commit is contained in:
parent
36194f715e
commit
1782687e9a
@ -15,6 +15,7 @@ vtkIdType findClosestPoint(const double *point, vtkPointSet *pointSet) {
|
||||
minPoint = i;
|
||||
}
|
||||
}
|
||||
std::cerr << "closest: " << minPoint << "\n";
|
||||
return minPoint;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
vtkIdType pointId,
|
||||
std::vector<double> &motionVectors,
|
||||
@ -60,11 +75,11 @@ void ProjectSurfacePointsOnPoly::moveSurfacePoint(vtkUnstructuredGrid *tetMesh,
|
||||
tetMesh->GetPoint(pointId, point);
|
||||
double direction[3];
|
||||
double distance;
|
||||
|
||||
closestPolyMeshPoint(
|
||||
polyMesh, point, polyMeshKdTree, links, direction, &distance);
|
||||
vtkNew<vtkIdList> affectedPoints;
|
||||
findPointsWithinRadius(distance * RadiusScale, tetMesh, point, affectedPoints);
|
||||
vtkNew<vtkIdList> pointsInRadius;
|
||||
findPointsWithinRadius(distance * RadiusScale, tetMesh, point, pointsInRadius);
|
||||
auto affectedPoints = removeSurfacePoints(pointsInRadius, isSurface);
|
||||
// tetMeshKdTree->FindPointsWithinRadius(distance * RadiusScale, point, affectedPoints);
|
||||
|
||||
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,
|
||||
vtkIdTypeArray *surfacePoints,
|
||||
std::vector<double> &motionVectors,
|
||||
const std::vector<unsigned> &numberOfAffectors) {
|
||||
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;
|
||||
double point[3];
|
||||
tetMesh->GetPoint(i, point);
|
||||
double *motion = motionVectors.data() + (i * 3);
|
||||
|
||||
vtkMath::MultiplyScalar(motion, 1. / numberOfAffectors[i]);
|
||||
vtkMath::Subtract(point, motion, point);
|
||||
tetMesh->GetPoints()->SetPoint(i, point);
|
||||
@ -142,7 +150,9 @@ vtkTypeBool ProjectSurfacePointsOnPoly::RequestData(
|
||||
tetMeshKdTree->BuildLocatorFromPoints(vtkPointSet::SafeDownCast(tetMesh));
|
||||
|
||||
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<unsigned> numberOfAffectors(tetMesh->GetNumberOfPoints(), 0);
|
||||
for (vtkIdType i = 0; i < surfacePoints->GetNumberOfTuples(); i++) {
|
||||
@ -153,8 +163,7 @@ vtkTypeBool ProjectSurfacePointsOnPoly::RequestData(
|
||||
polyMeshKdTree, tetMeshKdTree,
|
||||
links);
|
||||
}
|
||||
applyMotionVectors(tetMesh, surfacePoints,
|
||||
motionVectors, numberOfAffectors);
|
||||
applyMotionVectors(tetMesh, motionVectors, numberOfAffectors);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -25,6 +25,8 @@ public:
|
||||
protected:
|
||||
int affectedNeighborsCount = 0;
|
||||
double RadiusScale;
|
||||
vtkIntArray *isSurface = nullptr;
|
||||
|
||||
~ProjectSurfacePointsOnPoly() override = default;
|
||||
|
||||
void moveSurfacePoint(vtkUnstructuredGrid *tetMesh,
|
||||
|
@ -30,7 +30,7 @@ vtkTypeBool RelaxationFilter::RequestData(
|
||||
vtkNew<vtkIdList> neighborCells;
|
||||
vtkNew<vtkIdList> cellPoints;
|
||||
vtkIdTypeArray *surfacePoints = vtkIdTypeArray::SafeDownCast(
|
||||
output->GetFieldData()->GetArray("surface_points"));
|
||||
output->GetFieldData()->GetArray("surfacePoints"));
|
||||
vtkIntArray *isSurface = vtkIntArray::SafeDownCast(
|
||||
output->GetPointData()->GetArray("isSurface"));
|
||||
std::set<vtkIdType> neighbors;
|
||||
|
@ -32,7 +32,7 @@ vtkTypeBool SurfacePointsFilter::RequestData(
|
||||
|
||||
/* Create an array to store the IDs of surface points. */
|
||||
vtkNew<vtkIdTypeArray> surfacePoints;
|
||||
surfacePoints->SetName("surface_points");
|
||||
surfacePoints->SetName("surfacePoints");
|
||||
surfacePoints->SetNumberOfComponents(1);
|
||||
vtkNew<vtkIntArray> isSurface;
|
||||
isSurface->SetName("isSurface");
|
||||
|
Loading…
Reference in New Issue
Block a user