OGS
createMeshElemPropertiesFromASCRaster.cpp
Go to the documentation of this file.
1
13#include <tclap/CmdLine.h>
14
15#ifdef USE_PETSC
16#include <mpi.h>
17#endif
18
19#include <algorithm>
20#include <cmath>
21#include <memory>
22#include <numeric>
23
24#include "BaseLib/FileTools.h"
25#include "BaseLib/quicksort.h"
27#include "GeoLib/Raster.h"
28#include "InfoLib/GitInfo.h"
29#include "MathLib/MathTools.h"
34#include "MeshLib/Mesh.h"
35#include "MeshLib/MeshEnums.h"
38
39int main(int argc, char* argv[])
40{
41 TCLAP::CmdLine cmd(
42 "Generates properties for mesh elements of an input mesh deploying a "
43 "ASC raster file.\n\n"
44 "OpenGeoSys-6 software, version " +
46 ".\n"
47 "Copyright (c) 2012-2024, OpenGeoSys Community "
48 "(http://www.opengeosys.org)",
50
51 TCLAP::ValueArg<std::string> out_mesh_arg(
52 "o",
53 "out-mesh",
54 "the mesh is stored to a file of this name",
55 false,
56 "",
57 "filename for mesh output");
58 cmd.add(out_mesh_arg);
59
60 TCLAP::SwitchArg refinement_raster_output_arg(
61 "", "output-refined-raster",
62 "Write refined raster to an additional, new ASC file.");
63 cmd.add(refinement_raster_output_arg);
64
65 TCLAP::ValueArg<unsigned> refinement_arg(
66 "r",
67 "refine",
68 "refinement factor that raises the resolution of the raster data",
69 false,
70 1,
71 "factor (default = 1)");
72 cmd.add(refinement_arg);
73
74 TCLAP::ValueArg<std::string> raster_arg("",
75 "raster-file",
76 "the name of the ASC raster file",
77 true,
78 "",
79 "file name");
80 cmd.add(raster_arg);
81
82 TCLAP::ValueArg<std::string> property_arg(
83 "p",
84 "property-name",
85 "the name of the property the values are stored for",
86 true,
87 "",
88 "property name as string");
89 cmd.add(property_arg);
90
91 TCLAP::ValueArg<std::string> mesh_arg(
92 "m", "mesh", "the mesh is read from this file", true, "", "file name");
93 cmd.add(mesh_arg);
94
95 cmd.parse(argc, argv);
96
97#ifdef USE_PETSC
98 MPI_Init(&argc, &argv);
99#endif
100
101 // read mesh
102 std::unique_ptr<MeshLib::Mesh> dest_mesh(
103 MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
104
105 // read raster and if required manipulate it
106 auto raster = std::unique_ptr<GeoLib::Raster>(
108 raster_arg.getValue()));
109 GeoLib::RasterHeader header(raster->getHeader());
110 if (refinement_arg.getValue() > 1)
111 {
112 raster->refineRaster(refinement_arg.getValue());
113 if (refinement_raster_output_arg.getValue())
114 {
115 // write new asc file
116 std::string new_raster_fname(
117 BaseLib::dropFileExtension(raster_arg.getValue()));
118 new_raster_fname += "-" + std::to_string(header.n_rows) + "x" +
119 std::to_string(header.n_cols) + ".asc";
121 new_raster_fname);
122 }
123 }
124
125 std::unique_ptr<MeshLib::Mesh> src_mesh(
129 property_arg.getValue()));
130
131 // do the interpolation
133 *src_mesh, property_arg.getValue());
134 mesh_interpolation.setPropertiesForMesh(*dest_mesh);
135
136 if (!out_mesh_arg.getValue().empty())
137 {
138 MeshLib::IO::writeMeshToFile(*dest_mesh, out_mesh_arg.getValue());
139 }
140
141#ifdef USE_PETSC
142 MPI_Finalize();
143#endif
144 return EXIT_SUCCESS;
145}
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