29{
30 TCLAP::CmdLine cmd(
31 "Converts an ASCII raster file (*.asc) into a 2D triangle- or "
32 "quad-mesh. Pixel values can be interpreted as elevation of mesh nodes "
33 "or as scalar values for mesh elements.\nIt is highly recommended to "
34 "create triangle meshes when interpreting pixel values as elevation, "
35 "as it is likely that the resulting mesh will otherwise contain "
36 "deformed (i.e. non-planar) quad-elements.\n\n"
37 "OpenGeoSys-6 software, version " +
39 ".\n"
40 "Copyright (c) 2012-2024, OpenGeoSys Community "
41 "(http://www.opengeosys.org)",
43 TCLAP::ValueArg<std::string> array_name_arg(
44 "n", "arrayname",
45 "Name of the scalar array. Only required if assigning pixel values to "
46 "cell data has been selected (default name is 'Values').",
47 false, "", "name of data array");
48 cmd.add(array_name_arg);
49 std::vector<std::string> pixel_vals{"elevation", "materials", "scalar"};
50 TCLAP::ValuesConstraint<std::string> pixel_val_options(pixel_vals);
51 TCLAP::ValueArg<std::string> arg_pixel_type(
52 "p", "pixel-type",
53 "The choice how pixel values should be interpreted by the software: "
54 "'elevation' adjusts z-coordinates; 'materials' sets (integer) "
55 "material IDs; 'scalar' creates a (floating-point) array associated "
56 "with mesh elements.",
57 true, "", &pixel_val_options);
58 cmd.add(arg_pixel_type);
59 std::vector<std::string> allowed_elems{"tri", "quad"};
60 TCLAP::ValuesConstraint<std::string> allowed_elem_vals(allowed_elems);
61 TCLAP::ValueArg<std::string> arg_elem_type(
62 "e", "elem-type", "The element type used in the resulting OGS mesh.",
63 true, "", &allowed_elem_vals);
64 cmd.add(arg_elem_type);
65 TCLAP::ValueArg<std::string> output_arg("o", "output",
66 "Name of the output mesh (*.vtu)",
67 true, "", "output file name");
68 cmd.add(output_arg);
69 TCLAP::ValueArg<std::string> input_arg("i", "input",
70 "Name of the input raster (*.asc)",
71 true, "", "input file name");
72 cmd.add(input_arg);
73 cmd.parse(argc, argv);
74
75#ifdef USE_PETSC
76 MPI_Init(&argc, &argv);
77#endif
78
79 std::string const input_name = input_arg.getValue().c_str();
80 std::string const output_name = output_arg.getValue().c_str();
81
82 std::unique_ptr<GeoLib::Raster> const raster(
84
89 if (arg_pixel_type.getValue() == "elevation")
91 else if (arg_pixel_type.getValue() == "materials")
93 else
95
96 std::string array_name = "Values";
98 array_name_arg.isSet())
99 array_name = array_name_arg.getValue().c_str();
101 array_name = "MaterialIDs";
102
103 std::unique_ptr<MeshLib::Mesh> const mesh(
105 array_name));
106
107 if (mesh == nullptr)
108 {
109 ERR(
"Conversion failed.");
110#ifdef USE_PETSC
111 MPI_Finalize();
112#endif
113 return EXIT_FAILURE;
114 }
115
117 vtu.writeToFile(output_name);
118#ifdef USE_PETSC
119 MPI_Finalize();
120#endif
121 return EXIT_SUCCESS;
122}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
static GeoLib::Raster * getRasterFromASCFile(std::string const &fname)
Reads an ArcGis ASC raster file.
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
GITINFOLIB_EXPORT const std::string ogs_version
UseIntensityAs
Selection of possible interpretations for intensities.
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.