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