26{
27 TCLAP::CmdLine cmd(
28 "Converts an ASCII raster file (*.asc) into a 2D triangle- or "
29 "quad-mesh. Pixel values can be interpreted as elevation of mesh nodes "
30 "or as scalar values for mesh elements.\nIt is highly recommended to "
31 "create triangle meshes when interpreting pixel values as elevation, "
32 "as it is likely that the resulting mesh will otherwise contain "
33 "deformed (i.e. non-planar) quad-elements.\n\n"
34 "OpenGeoSys-6 software, version " +
36 ".\n"
37 "Copyright (c) 2012-2024, OpenGeoSys Community "
38 "(http://www.opengeosys.org)",
40 TCLAP::ValueArg<std::string> array_name_arg(
41 "n", "arrayname",
42 "Name of the scalar array. Only required if assigning pixel values to "
43 "cell data has been selected (default name is 'Values').",
44 false, "", "name of data array");
45 cmd.add(array_name_arg);
46 std::vector<std::string> pixel_vals{"elevation", "materials", "scalar"};
47 TCLAP::ValuesConstraint<std::string> pixel_val_options(pixel_vals);
48 TCLAP::ValueArg<std::string> arg_pixel_type(
49 "p", "pixel-type",
50 "The choice how pixel values should be interpreted by the software: "
51 "'elevation' adjusts z-coordinates; 'materials' sets (integer) "
52 "material IDs; 'scalar' creates a (floating-point) array associated "
53 "with mesh elements.",
54 true, "", &pixel_val_options);
55 cmd.add(arg_pixel_type);
56 std::vector<std::string> allowed_elems{"tri", "quad"};
57 TCLAP::ValuesConstraint<std::string> allowed_elem_vals(allowed_elems);
58 TCLAP::ValueArg<std::string> arg_elem_type(
59 "e", "elem-type", "The element type used in the resulting OGS mesh.",
60 true, "", &allowed_elem_vals);
61 cmd.add(arg_elem_type);
62 TCLAP::ValueArg<std::string> output_arg("o", "output",
63 "Name of the output mesh (*.vtu)",
64 true, "", "output file name");
65 cmd.add(output_arg);
66 TCLAP::ValueArg<std::string> input_arg("i", "input",
67 "Name of the input raster (*.asc)",
68 true, "", "input file name");
69 cmd.add(input_arg);
70 cmd.parse(argc, argv);
71
73
74 std::string const input_name = input_arg.getValue().c_str();
75 std::string const output_name = output_arg.getValue().c_str();
76
77 std::unique_ptr<GeoLib::Raster> const raster(
79
84 if (arg_pixel_type.getValue() == "elevation")
86 else if (arg_pixel_type.getValue() == "materials")
88 else
90
91 std::string array_name = "Values";
93 array_name_arg.isSet())
94 array_name = array_name_arg.getValue().c_str();
96 array_name = "MaterialIDs";
97
98 std::unique_ptr<MeshLib::Mesh> const mesh(
100 array_name));
101
102 if (mesh == nullptr)
103 {
104 ERR(
"Conversion failed.");
105 return EXIT_FAILURE;
106 }
107
109 vtu.writeToFile(output_name);
110 return EXIT_SUCCESS;
111}
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.