add the ability to analyze a mesh without fitting it

This commit is contained in:
papush! 2022-03-29 18:00:47 +02:00
parent f67bc4c9d7
commit 44bd8f3b0a

View File

@ -61,21 +61,39 @@ vtkAlgorithm *readerFromFileName(const char *fileName) {
}
static void usage(char **argv) {
std::cerr << "Usage: " << argv[0] << " analyze|fit tetmesh polydata [radiusScale relaxationIterCount]" << std::endl;
}
int main(int argc, char **argv) {
if (!(argc == 3 || argc == 5)) {
std::cerr << "Usage: " << argv[0] << " tetmesh polydata [radiusScale relaxationIterCount]" << std::endl;
if (argc < 4) {
usage(argv);
return EXIT_FAILURE;
}
bool fit = false;
if (std::string(argv[1]) == "fit") {
fit = true;
} else if (std::string(argv[1]) != "analyze") {
usage(argv);
return EXIT_FAILURE;
}
if ((fit && argc > 6) || (!fit && argc != 4)) {
usage(argv);
return EXIT_FAILURE;
}
double radiusScale = 2.;
int iterCount = 1;
if(argc > 3) {
if(argc > 4) {
radiusScale = std::stod(argv[3]);
}
if (argc > 5) {
iterCount = std::stoi(argv[4]);
}
auto tetMeshReader = readerFromFileName(argv[1]);
auto polyMeshReader = readerFromFileName(argv[2]);
auto tetMeshReader = readerFromFileName(argv[2]);
auto polyMeshReader = readerFromFileName(argv[3]);
vtkNew<RemoveExternalCellsFilter> removeExternalCellsFilter;
removeExternalCellsFilter->SetInputConnection(0,
@ -97,8 +115,13 @@ int main(int argc, char **argv) {
relaxationFilter->SetInputConnection(project->GetOutputPort());
vtkNew<DihedralAnglesFilter> dihedralAnglesFilter;
dihedralAnglesFilter->SetInputConnection(
relaxationFilter->GetOutputPort());
if (fit) {
dihedralAnglesFilter->SetInputConnection(
relaxationFilter->GetOutputPort());
} else {
dihedralAnglesFilter->SetInputConnection(
tetMeshReader->GetOutputPort());
}
vtkNew<vtkGeometryFilter> geometryFilter;
geometryFilter->SetInputConnection(dihedralAnglesFilter->GetOutputPort());
@ -107,11 +130,15 @@ int main(int argc, char **argv) {
maxDistanceFilter->SetInputConnection(0, geometryFilter->GetOutputPort());
maxDistanceFilter->SetInputConnection(1, polyMeshReader->GetOutputPort());
vtkNew<vtkXMLUnstructuredGridWriter> writer;
writer->SetInputConnection(dihedralAnglesFilter->GetOutputPort());
writer->SetDataModeToAscii();
writer->SetFileName("out.vtu");
writer->Write();
if (fit) {
vtkNew<vtkXMLUnstructuredGridWriter> writer;
writer->SetInputConnection(dihedralAnglesFilter->GetOutputPort());
writer->SetDataModeToAscii();
writer->SetFileName("out.vtu");
writer->Write();
} else {
dihedralAnglesFilter->Update();
}
maxDistanceFilter->Update();
std::cerr << "Max distance: " << maxDistanceFilter->GetMaxDist() << "\n"