diff --git a/src/main.cc b/src/main.cc index 066b498..cd357b8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -59,14 +60,16 @@ vtkSmartPointer readerFromFileName(const char *fileName) { int main(int argc, char **argv) { - if (argc < 3 || argc > 5) { - std::cerr << "Usage: " << argv[0] << " tetmesh polydata [radiusScale]" << std::endl; + if (!(argc == 3 || argc == 5)) { + std::cerr << "Usage: " << argv[0] << " tetmesh polydata [radiusScale relaxationIterCount]" << std::endl; return EXIT_FAILURE; } double radiusScale = 2.; - if(argc == 4) { + int iterCount = 1; + if(argc > 3) { radiusScale = std::stod(argv[3]); + iterCount = std::stoi(argv[4]); } auto tetMeshReader = readerFromFileName(argv[1]); @@ -88,6 +91,7 @@ int main(int argc, char **argv) { project->SetInputConnection(1, polyMeshReader->GetOutputPort()); vtkNew relaxationFilter; + relaxationFilter->SetIterCount(iterCount); relaxationFilter->SetInputConnection(project->GetOutputPort()); vtkNew dihedralAnglesFilter; diff --git a/src/relaxation_filter.cc b/src/relaxation_filter.cc index 19bdf8f..9e48f26 100644 --- a/src/relaxation_filter.cc +++ b/src/relaxation_filter.cc @@ -10,6 +10,10 @@ vtkStandardNewMacro(RelaxationFilter); +RelaxationFilter::RelaxationFilter() + :IterCount(1) { +} + vtkTypeBool RelaxationFilter::RequestData( vtkInformation *request, vtkInformationVector **inputVector, @@ -33,43 +37,45 @@ vtkTypeBool RelaxationFilter::RequestData( output->BuildLinks(); double avg[3]; - for (vtkIdType i = 0; i < surfacePoints->GetNumberOfValues(); i++) { - vtkIdType id = surfacePoints->GetValue(i); + for (int iter = 0; iter < IterCount; iter++) { + for (vtkIdType i = 0; i < surfacePoints->GetNumberOfValues(); i++) { + vtkIdType id = surfacePoints->GetValue(i); - output->GetPointCells(id, neighborCells); + output->GetPointCells(id, neighborCells); - if (neighborCells->GetNumberOfIds() != 0) { + if (neighborCells->GetNumberOfIds() != 0) { - for (vtkIdType j = 0; j < neighborCells->GetNumberOfIds(); j++) { + for (vtkIdType j = 0; j < neighborCells->GetNumberOfIds(); j++) { - vtkIdType cellId = neighborCells->GetId(j); - output->GetCellPoints(cellId, cellPoints); + vtkIdType cellId = neighborCells->GetId(j); + output->GetCellPoints(cellId, cellPoints); - for (vtkIdType k = 0; k < cellPoints->GetNumberOfIds(); k++) { + for (vtkIdType k = 0; k < cellPoints->GetNumberOfIds(); k++) { - vtkIdType neighborId = cellPoints->GetId(k); - if (isSurface->GetValue(neighborId)) { - neighbors.insert(neighborId); + vtkIdType neighborId = cellPoints->GetId(k); + if (isSurface->GetValue(neighborId)) { + neighbors.insert(neighborId); + } } + cellPoints->Reset(); } - cellPoints->Reset(); - } - neighbors.erase(neighbors.find(id)); - 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); + neighbors.erase(neighbors.find(id)); + 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(id, avg); } - vtkMath::MultiplyScalar(avg, 1. / neighbors.size()); - newPoints->SetPoint(id, avg); } + neighborCells->Reset(); + neighbors.clear(); } - neighborCells->Reset(); - neighbors.clear(); - } - output->SetPoints(newPoints); + output->SetPoints(newPoints); + } return true; } diff --git a/src/relaxation_filter.h b/src/relaxation_filter.h index b760f12..bca39d9 100644 --- a/src/relaxation_filter.h +++ b/src/relaxation_filter.h @@ -9,12 +9,16 @@ class RelaxationFilter : public vtkUnstructuredGridAlgorithm { public: static RelaxationFilter *New(); vtkTypeMacro(RelaxationFilter, vtkUnstructuredGridAlgorithm); + RelaxationFilter(); vtkTypeBool RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector) override; + vtkSetMacro(IterCount, int); + vtkGetMacro(IterCount, int); protected: ~RelaxationFilter() override = default; + int IterCount; };