OGS
Raster2Mesh.cpp File Reference

Detailed Description

Definition in file Raster2Mesh.cpp.

#include <memory>
#include <string>
#include <tclap/CmdLine.h>
#include "BaseLib/MPI.h"
#include "GeoLib/IO/AsciiRasterInterface.h"
#include "GeoLib/Raster.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/MeshEnums.h"
#include "MeshToolsLib/MeshGenerators/RasterToMesh.h"
Include dependency graph for Raster2Mesh.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 25 of file Raster2Mesh.cpp.

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
72 BaseLib::MPI::Setup mpi_setup(argc, argv);
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
80 MeshLib::MeshElemType const elem_type =
81 (arg_elem_type.getValue() == "tri") ? MeshLib::MeshElemType::TRIANGLE
83 MeshLib::UseIntensityAs intensity_type;
84 if (arg_pixel_type.getValue() == "elevation")
86 else if (arg_pixel_type.getValue() == "materials")
88 else
90
91 std::string array_name = "Values";
92 if (intensity_type == MeshLib::UseIntensityAs::DATAVECTOR &&
93 array_name_arg.isSet())
94 array_name = array_name_arg.getValue().c_str();
95 else if (intensity_type == MeshLib::UseIntensityAs::MATERIALS)
96 array_name = "MaterialIDs";
97
98 std::unique_ptr<MeshLib::Mesh> const mesh(
99 MeshToolsLib::RasterToMesh::convert(*raster, elem_type, intensity_type,
100 array_name));
101
102 if (mesh == nullptr)
103 {
104 ERR("Conversion failed.");
105 return EXIT_FAILURE;
106 }
107
108 MeshLib::IO::VtuInterface vtu(mesh.get());
109 vtu.writeToFile(output_name);
110 return EXIT_SUCCESS;
111}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
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....
static std::unique_ptr< MeshLib::Mesh > convert(GeoLib::Raster const &raster, MeshLib::MeshElemType elem_type, MeshLib::UseIntensityAs intensity_type, std::string const &array_name="Colour")
GITINFOLIB_EXPORT const std::string ogs_version
UseIntensityAs
Selection of possible interpretations for intensities.
Definition MeshEnums.h:83
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:27

References MeshToolsLib::RasterToMesh::convert(), MeshLib::DATAVECTOR, MeshLib::ELEVATION, ERR(), FileIO::AsciiRasterInterface::getRasterFromASCFile(), MeshLib::MATERIALS, GitInfoLib::GitInfo::ogs_version, MeshLib::QUAD, MeshLib::TRIANGLE, and MeshLib::IO::VtuInterface::writeToFile().