OGS
createMeshElemPropertiesFromASCRaster.cpp
Go to the documentation of this file.
1
13#include <tclap/CmdLine.h>
14
15#include <algorithm>
16#include <cmath>
17#include <memory>
18#include <numeric>
19
20#include "BaseLib/FileTools.h"
21#include "BaseLib/MPI.h"
22#include "BaseLib/quicksort.h"
24#include "GeoLib/Raster.h"
25#include "InfoLib/GitInfo.h"
26#include "MathLib/MathTools.h"
31#include "MeshLib/Mesh.h"
32#include "MeshLib/MeshEnums.h"
35
36int main(int argc, char* argv[])
37{
38 TCLAP::CmdLine cmd(
39 "Generates properties for mesh elements of an input mesh deploying a "
40 "ASC raster file.\n\n"
41 "OpenGeoSys-6 software, version " +
43 ".\n"
44 "Copyright (c) 2012-2024, OpenGeoSys Community "
45 "(http://www.opengeosys.org)",
47
48 TCLAP::ValueArg<std::string> out_mesh_arg(
49 "o",
50 "out-mesh",
51 "the mesh is stored to a file of this name",
52 false,
53 "",
54 "filename for mesh output");
55 cmd.add(out_mesh_arg);
56
57 TCLAP::SwitchArg refinement_raster_output_arg(
58 "", "output-refined-raster",
59 "Write refined raster to an additional, new ASC file.");
60 cmd.add(refinement_raster_output_arg);
61
62 TCLAP::ValueArg<unsigned> refinement_arg(
63 "r",
64 "refine",
65 "refinement factor that raises the resolution of the raster data",
66 false,
67 1,
68 "factor (default = 1)");
69 cmd.add(refinement_arg);
70
71 TCLAP::ValueArg<std::string> raster_arg("",
72 "raster-file",
73 "the name of the ASC raster file",
74 true,
75 "",
76 "file name");
77 cmd.add(raster_arg);
78
79 TCLAP::ValueArg<std::string> property_arg(
80 "p",
81 "property-name",
82 "the name of the property the values are stored for",
83 true,
84 "",
85 "property name as string");
86 cmd.add(property_arg);
87
88 TCLAP::ValueArg<std::string> mesh_arg(
89 "m", "mesh", "the mesh is read from this file", true, "", "file name");
90 cmd.add(mesh_arg);
91
92 cmd.parse(argc, argv);
93
94 BaseLib::MPI::Setup mpi_setup(argc, argv);
95
96 // read mesh
97 std::unique_ptr<MeshLib::Mesh> dest_mesh(
98 MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
99
100 // read raster and if required manipulate it
101 auto raster = std::unique_ptr<GeoLib::Raster>(
103 raster_arg.getValue()));
104 GeoLib::RasterHeader header(raster->getHeader());
105 if (refinement_arg.getValue() > 1)
106 {
107 raster->refineRaster(refinement_arg.getValue());
108 if (refinement_raster_output_arg.getValue())
109 {
110 // write new asc file
111 std::string new_raster_fname(
112 BaseLib::dropFileExtension(raster_arg.getValue()));
113 new_raster_fname += "-" + std::to_string(header.n_rows) + "x" +
114 std::to_string(header.n_cols) + ".asc";
116 new_raster_fname);
117 }
118 }
119
120 std::unique_ptr<MeshLib::Mesh> src_mesh(
124 property_arg.getValue()));
125
126 // do the interpolation
128 *src_mesh, property_arg.getValue());
129 mesh_interpolation.setPropertiesForMesh(*dest_mesh);
130
131 if (!out_mesh_arg.getValue().empty())
132 {
133 MeshLib::IO::writeMeshToFile(*dest_mesh, out_mesh_arg.getValue());
134 }
135
136 return EXIT_SUCCESS;
137}
Definition of the AsciiRasterInterface class.
Definition of the Element class.
Filename manipulation routines.
Git information.
Implementation of the Mesh2MeshPropertyInterpolation class.
Definition of mesh-related Enumerations.
Definition of the Mesh class.
Definition of the GeoLib::Raster class.
Definition of the VtkMeshConverter class.
static void writeRasterAsASC(GeoLib::Raster const &raster, std::string const &file_name)
Writes an Esri asc-file.
static GeoLib::Raster * getRasterFromASCFile(std::string const &fname)
Reads an ArcGis ASC raster file.
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")
int main(int argc, char *argv[])
std::string dropFileExtension(std::string const &filename)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)
Definition of the quicksort function.
Definition of readMeshFromFile function.
Contains the relevant information when storing a geoscientific raster data.
Definition Raster.h:28
std::size_t n_cols
Definition Raster.h:29
std::size_t n_rows
Definition Raster.h:30