add relaxation (not very relaxing)

This commit is contained in:
papush! 2022-03-15 14:55:36 +01:00
parent 3467f8593d
commit d31d9629f0
3 changed files with 57 additions and 6 deletions

View File

@ -2,6 +2,7 @@
#include "remove_external_cells_filter.h"
#include "surface_points_filter.h"
#include "project_surface_points_on_poly.h"
#include "relaxation_filter.h"
#include <vtkCellArrayIterator.h>
#include <vtkCellData.h>
@ -79,8 +80,12 @@ int main(int argc, char **argv) {
project->SetInputConnection(0, surfacePointsFilter->GetOutputPort());
project->SetInputConnection(1, polyMeshReader->GetOutputPort());
vtkNew<RelaxationFilter> relaxationFilter;
relaxationFilter->SetInputConnection(project->GetOutputPort());
vtkNew<DihedralAnglesFilter> dihedralAnglesFilter;
dihedralAnglesFilter->SetInputConnection(project->GetOutputPort());
dihedralAnglesFilter->SetInputConnection(
relaxationFilter->GetOutputPort());
vtkNew<vtkXMLUnstructuredGridWriter> writer;
writer->SetInputConnection(dihedralAnglesFilter->GetOutputPort());

View File

@ -154,10 +154,10 @@ vtkTypeBool ProjectSurfacePointsOnPoly::RequestData(
vtkInformationVector **inputVector,
vtkInformationVector *outputVector) {
(void) request;
vtkUnstructuredGrid* tetMesh = vtkUnstructuredGrid::GetData(inputVector[0]);
vtkUnstructuredGrid* tetMesh =
vtkUnstructuredGrid::GetData(inputVector[0]);
vtkPolyData* polyMesh = vtkPolyData::GetData(inputVector[1]);
vtkUnstructuredGrid* output =
vtkUnstructuredGrid::GetData(outputVector);
vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector);
output->CopyStructure(tetMesh);
output->GetPointData()->PassData(tetMesh->GetPointData());

View File

@ -6,13 +6,59 @@
#include <vtkDoubleArray.h>
#include <vtkCellIterator.h>
#include <set>
vtkStandardNewMacro(RelaxationFilter);
vtkTypeBool RelaxationFilter::RequestData(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector) {
(void) request;
vtkUnstructuredGrid* input =
vtkUnstructuredGrid::GetData(inputVector[0]);
vtkUnstructuredGrid* output = vtkUnstructuredGrid::GetData(outputVector);
output->CopyStructure(input);
output->GetPointData()->PassData(input->GetPointData());
output->GetCellData()->PassData(input->GetCellData());
vtkNew<vtkPoints> newPoints;
newPoints->DeepCopy(output->GetPoints());
vtkNew<vtkIdList> neighborCells;
vtkNew<vtkIdList> cellPoints;
vtkIntArray *isSurface = vtkIntArray::SafeDownCast(
output->GetPointData()->GetArray("isSurface"));
std::set<vtkIdType> neighbors;
output->BuildLinks();
double avg[3];
for (vtkIdType i = 0; i < output->GetNumberOfPoints(); i++) {
output->GetPointCells(i, neighborCells);
if (neighborCells->GetNumberOfIds() != 0) {
for (vtkIdType j = 0; j < neighborCells->GetNumberOfIds(); j++) {
vtkIdType cellId = neighborCells->GetId(j);
output->GetCellPoints(cellId, cellPoints);
for (vtkIdType k = 0; k < cellPoints->GetNumberOfIds(); k++) {
vtkIdType neighborId = cellPoints->GetId(k);
if (isSurface->GetValue(neighborId)) {
neighbors.insert(neighborId);
}
}
cellPoints->Reset();
}
neighbors.erase(neighbors.find(i));
if (neighbors.size() != 0) {
avg[0] = 0; avg[1] = 0; avg[2] = 0;
for (const vtkIdType &j : neighbors) {
double point[3];
output->GetPoints()->GetPoint(j, point);
vtkMath::Add(point, avg, avg);
}
vtkMath::MultiplyScalar(avg, 1. / neighbors.size());
newPoints->SetPoint(i, avg);
}
}
neighborCells->Reset();
neighbors.clear();
}
output->SetPoints(newPoints);
return true;
}