add the ability to control the number of iterations of the algorithm

of relaxation of the tetrahedral mesh of the program of tetrahedral
mesh generation
This commit is contained in:
papush! 2022-03-23 15:25:24 +01:00
parent 8ee09d686e
commit 26b1175924
3 changed files with 43 additions and 29 deletions

View File

@ -10,6 +10,7 @@
#include <vtkOBJReader.h>
#include <vtkPolyData.h>
#include <vtkPolyDataReader.h>
#include <vtkSetGet.h>
#include <vtkUnstructuredGrid.h>
#include <vtkUnstructuredGridReader.h>
#include <vtkXMLPolyDataReader.h>
@ -59,14 +60,16 @@ vtkSmartPointer<vtkAlgorithm> 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;
relaxationFilter->SetIterCount(iterCount);
relaxationFilter->SetInputConnection(project->GetOutputPort());
vtkNew<DihedralAnglesFilter> dihedralAnglesFilter;

View File

@ -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;
}

View File

@ -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;
};