diff --git a/src/main.cc b/src/main.cc index baaaa5e..eccb986 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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->SetInputConnection(0, @@ -97,8 +115,13 @@ int main(int argc, char **argv) { relaxationFilter->SetInputConnection(project->GetOutputPort()); vtkNew dihedralAnglesFilter; - dihedralAnglesFilter->SetInputConnection( - relaxationFilter->GetOutputPort()); + if (fit) { + dihedralAnglesFilter->SetInputConnection( + relaxationFilter->GetOutputPort()); + } else { + dihedralAnglesFilter->SetInputConnection( + tetMeshReader->GetOutputPort()); + } vtkNew 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 writer; - writer->SetInputConnection(dihedralAnglesFilter->GetOutputPort()); - writer->SetDataModeToAscii(); - writer->SetFileName("out.vtu"); - writer->Write(); + if (fit) { + vtkNew 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"