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:
parent
8ee09d686e
commit
26b1175924
10
src/main.cc
10
src/main.cc
@ -10,6 +10,7 @@
|
|||||||
#include <vtkOBJReader.h>
|
#include <vtkOBJReader.h>
|
||||||
#include <vtkPolyData.h>
|
#include <vtkPolyData.h>
|
||||||
#include <vtkPolyDataReader.h>
|
#include <vtkPolyDataReader.h>
|
||||||
|
#include <vtkSetGet.h>
|
||||||
#include <vtkUnstructuredGrid.h>
|
#include <vtkUnstructuredGrid.h>
|
||||||
#include <vtkUnstructuredGridReader.h>
|
#include <vtkUnstructuredGridReader.h>
|
||||||
#include <vtkXMLPolyDataReader.h>
|
#include <vtkXMLPolyDataReader.h>
|
||||||
@ -59,14 +60,16 @@ vtkSmartPointer<vtkAlgorithm> readerFromFileName(const char *fileName) {
|
|||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if (argc < 3 || argc > 5) {
|
if (!(argc == 3 || argc == 5)) {
|
||||||
std::cerr << "Usage: " << argv[0] << " tetmesh polydata [radiusScale]" << std::endl;
|
std::cerr << "Usage: " << argv[0] << " tetmesh polydata [radiusScale relaxationIterCount]" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
double radiusScale = 2.;
|
double radiusScale = 2.;
|
||||||
if(argc == 4) {
|
int iterCount = 1;
|
||||||
|
if(argc > 3) {
|
||||||
radiusScale = std::stod(argv[3]);
|
radiusScale = std::stod(argv[3]);
|
||||||
|
iterCount = std::stoi(argv[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto tetMeshReader = readerFromFileName(argv[1]);
|
auto tetMeshReader = readerFromFileName(argv[1]);
|
||||||
@ -88,6 +91,7 @@ int main(int argc, char **argv) {
|
|||||||
project->SetInputConnection(1, polyMeshReader->GetOutputPort());
|
project->SetInputConnection(1, polyMeshReader->GetOutputPort());
|
||||||
|
|
||||||
vtkNew<RelaxationFilter> relaxationFilter;
|
vtkNew<RelaxationFilter> relaxationFilter;
|
||||||
|
relaxationFilter->SetIterCount(iterCount);
|
||||||
relaxationFilter->SetInputConnection(project->GetOutputPort());
|
relaxationFilter->SetInputConnection(project->GetOutputPort());
|
||||||
|
|
||||||
vtkNew<DihedralAnglesFilter> dihedralAnglesFilter;
|
vtkNew<DihedralAnglesFilter> dihedralAnglesFilter;
|
||||||
|
@ -10,6 +10,10 @@
|
|||||||
|
|
||||||
vtkStandardNewMacro(RelaxationFilter);
|
vtkStandardNewMacro(RelaxationFilter);
|
||||||
|
|
||||||
|
RelaxationFilter::RelaxationFilter()
|
||||||
|
:IterCount(1) {
|
||||||
|
}
|
||||||
|
|
||||||
vtkTypeBool RelaxationFilter::RequestData(
|
vtkTypeBool RelaxationFilter::RequestData(
|
||||||
vtkInformation *request,
|
vtkInformation *request,
|
||||||
vtkInformationVector **inputVector,
|
vtkInformationVector **inputVector,
|
||||||
@ -33,43 +37,45 @@ vtkTypeBool RelaxationFilter::RequestData(
|
|||||||
output->BuildLinks();
|
output->BuildLinks();
|
||||||
double avg[3];
|
double avg[3];
|
||||||
|
|
||||||
for (vtkIdType i = 0; i < surfacePoints->GetNumberOfValues(); i++) {
|
for (int iter = 0; iter < IterCount; iter++) {
|
||||||
vtkIdType id = surfacePoints->GetValue(i);
|
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);
|
vtkIdType cellId = neighborCells->GetId(j);
|
||||||
output->GetCellPoints(cellId, cellPoints);
|
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);
|
vtkIdType neighborId = cellPoints->GetId(k);
|
||||||
if (isSurface->GetValue(neighborId)) {
|
if (isSurface->GetValue(neighborId)) {
|
||||||
neighbors.insert(neighborId);
|
neighbors.insert(neighborId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
cellPoints->Reset();
|
||||||
}
|
}
|
||||||
cellPoints->Reset();
|
neighbors.erase(neighbors.find(id));
|
||||||
}
|
if (neighbors.size() != 0) {
|
||||||
neighbors.erase(neighbors.find(id));
|
avg[0] = 0; avg[1] = 0; avg[2] = 0;
|
||||||
if (neighbors.size() != 0) {
|
for (const vtkIdType &j : neighbors) {
|
||||||
avg[0] = 0; avg[1] = 0; avg[2] = 0;
|
double point[3];
|
||||||
for (const vtkIdType &j : neighbors) {
|
output->GetPoints()->GetPoint(j, point);
|
||||||
double point[3];
|
vtkMath::Add(point, avg, avg);
|
||||||
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -9,12 +9,16 @@ class RelaxationFilter : public vtkUnstructuredGridAlgorithm {
|
|||||||
public:
|
public:
|
||||||
static RelaxationFilter *New();
|
static RelaxationFilter *New();
|
||||||
vtkTypeMacro(RelaxationFilter, vtkUnstructuredGridAlgorithm);
|
vtkTypeMacro(RelaxationFilter, vtkUnstructuredGridAlgorithm);
|
||||||
|
RelaxationFilter();
|
||||||
vtkTypeBool RequestData(vtkInformation *request,
|
vtkTypeBool RequestData(vtkInformation *request,
|
||||||
vtkInformationVector **inputVector,
|
vtkInformationVector **inputVector,
|
||||||
vtkInformationVector *outputVector) override;
|
vtkInformationVector *outputVector) override;
|
||||||
|
vtkSetMacro(IterCount, int);
|
||||||
|
vtkGetMacro(IterCount, int);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
~RelaxationFilter() override = default;
|
~RelaxationFilter() override = default;
|
||||||
|
int IterCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user