OGS
createMeshElemPropertiesFromASCRaster.cpp File Reference

Detailed Description

Implementation of the createMeshElemPropertiesFromASCRaster tool.

Definition in file createMeshElemPropertiesFromASCRaster.cpp.

#include <tclap/CmdLine.h>
#include <mpi.h>
#include <algorithm>
#include <cmath>
#include <memory>
#include <numeric>
#include "BaseLib/FileTools.h"
#include "BaseLib/quicksort.h"
#include "GeoLib/IO/AsciiRasterInterface.h"
#include "GeoLib/Raster.h"
#include "InfoLib/GitInfo.h"
#include "MathLib/MathTools.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/IO/VtkIO/VtkMeshConverter.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/MeshEnums.h"
#include "MeshToolsLib/MeshEditing/Mesh2MeshPropertyInterpolation.h"
#include "MeshToolsLib/MeshGenerators/RasterToMesh.h"
Include dependency graph for createMeshElemPropertiesFromASCRaster.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 39 of file createMeshElemPropertiesFromASCRaster.cpp.

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}
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")
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)
Contains the relevant information when storing a geoscientific raster data.
Definition Raster.h:28

References MeshToolsLib::RasterToMesh::convert(), MeshLib::DATAVECTOR, BaseLib::dropFileExtension(), FileIO::AsciiRasterInterface::getRasterFromASCFile(), GeoLib::RasterHeader::n_cols, GeoLib::RasterHeader::n_rows, GitInfoLib::GitInfo::ogs_version, MeshLib::QUAD, MeshLib::IO::readMeshFromFile(), MeshToolsLib::Mesh2MeshPropertyInterpolation::setPropertiesForMesh(), MeshLib::IO::writeMeshToFile(), and FileIO::AsciiRasterInterface::writeRasterAsASC().