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