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-2025, OpenGeoSys Community "
45 "(http://www.opengeosys.org)",
47
48 TCLAP::ValueArg<std::string> out_mesh_arg(
49 "o",
50 "out-mesh",
51 "Output (.vtu). The output mesh is stored to a file of this name",
52 false,
53 "",
54 "OUTPUT_FILE");
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 "REFINEMENT_FACTOR");
69 cmd.add(refinement_arg);
70
71 TCLAP::ValueArg<std::string> raster_arg(
72 "",
73 "raster-file",
74 "Input (.asc). The name of the input "
75 "ASC raster file",
76 true,
77 "",
78 "INPUT_FILE");
79 cmd.add(raster_arg);
80
81 TCLAP::ValueArg<std::string> property_arg(
82 "p",
83 "property-name",
84 "the name of the property the values are stored for",
85 true,
86 "",
87 "PROPERTY_NAME");
88 cmd.add(property_arg);
89
90 TCLAP::ValueArg<std::string> mesh_arg(
91 "m", "mesh", "Input (.vtu). The input mesh is read from this file",
92 true, "", "INPUT_FILE");
93 cmd.add(mesh_arg);
94
95 cmd.parse(argc, argv);
96
97 BaseLib::MPI::Setup mpi_setup(argc, argv);
98
99 // read mesh
100 std::unique_ptr<MeshLib::Mesh> dest_mesh(
101 MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
102
103 // read raster and if required manipulate it
104 auto raster = std::unique_ptr<GeoLib::Raster>(
106 raster_arg.getValue()));
107 GeoLib::RasterHeader header(raster->getHeader());
108 if (refinement_arg.getValue() > 1)
109 {
110 raster->refineRaster(refinement_arg.getValue());
111 if (refinement_raster_output_arg.getValue())
112 {
113 // write new asc file
114 std::string new_raster_fname(
115 BaseLib::dropFileExtension(raster_arg.getValue()));
116 new_raster_fname += "-" + std::to_string(header.n_rows) + "x" +
117 std::to_string(header.n_cols) + ".asc";
119 new_raster_fname);
120 }
121 }
122
123 std::unique_ptr<MeshLib::Mesh> src_mesh(
127 property_arg.getValue()));
128
129 // do the interpolation
131 *src_mesh, property_arg.getValue());
132 mesh_interpolation.setPropertiesForMesh(*dest_mesh);
133
134 if (!out_mesh_arg.getValue().empty())
135 {
136 MeshLib::IO::writeMeshToFile(*dest_mesh, out_mesh_arg.getValue());
137 }
138
139 return EXIT_SUCCESS;
140}
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