OGS
createMeshElemPropertiesFromASCRaster.cpp File Reference

Detailed Description

Implementation of the createMeshElemPropertiesFromASCRaster tool.

Definition in file createMeshElemPropertiesFromASCRaster.cpp.

#include <tclap/CmdLine.h>
#include <algorithm>
#include <cmath>
#include <memory>
#include <numeric>
#include "BaseLib/FileTools.h"
#include "BaseLib/Logging.h"
#include "BaseLib/MPI.h"
#include "BaseLib/TCLAPArguments.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 38 of file createMeshElemPropertiesFromASCRaster.cpp.

39{
40 TCLAP::CmdLine cmd(
41 "Generates properties for mesh elements of an input mesh deploying a "
42 "ASC raster file.\n\n"
43 "OpenGeoSys-6 software, version " +
45 ".\n"
46 "Copyright (c) 2012-2025, OpenGeoSys Community "
47 "(http://www.opengeosys.org)",
49
50 TCLAP::ValueArg<std::string> out_mesh_arg(
51 "o",
52 "out-mesh",
53 "Output (.vtu). The output mesh is stored to a file of this name",
54 false,
55 "",
56 "OUTPUT_FILE");
57 cmd.add(out_mesh_arg);
58
59 TCLAP::SwitchArg refinement_raster_output_arg(
60 "", "output-refined-raster",
61 "Write refined raster to an additional, new ASC file.");
62 cmd.add(refinement_raster_output_arg);
63
64 TCLAP::ValueArg<unsigned> refinement_arg(
65 "r",
66 "refine",
67 "refinement factor that raises the resolution of the raster data",
68 false,
69 1,
70 "REFINEMENT_FACTOR");
71 cmd.add(refinement_arg);
72
73 TCLAP::ValueArg<std::string> raster_arg(
74 "",
75 "raster-file",
76 "Input (.asc). The name of the input "
77 "ASC raster file",
78 true,
79 "",
80 "INPUT_FILE");
81 cmd.add(raster_arg);
82
83 TCLAP::ValueArg<std::string> property_arg(
84 "p",
85 "property-name",
86 "the name of the property the values are stored for",
87 true,
88 "",
89 "PROPERTY_NAME");
90 cmd.add(property_arg);
91
92 TCLAP::ValueArg<std::string> mesh_arg(
93 "m", "mesh", "Input (.vtu). The input mesh is read from this file",
94 true, "", "INPUT_FILE");
95 cmd.add(mesh_arg);
96
97 auto log_level_arg = BaseLib::makeLogLevelArg();
98 cmd.add(log_level_arg);
99 cmd.parse(argc, argv);
100
101 BaseLib::MPI::Setup mpi_setup(argc, argv);
102 BaseLib::initOGSLogger(log_level_arg.getValue());
103
104 // read mesh
105 std::unique_ptr<MeshLib::Mesh> dest_mesh(
106 MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
107
108 // read raster and if required manipulate it
109 auto raster = std::unique_ptr<GeoLib::Raster>(
111 raster_arg.getValue()));
112 GeoLib::RasterHeader header(raster->getHeader());
113 if (refinement_arg.getValue() > 1)
114 {
115 raster->refineRaster(refinement_arg.getValue());
116 if (refinement_raster_output_arg.getValue())
117 {
118 // write new asc file
119 std::string new_raster_fname(
120 BaseLib::dropFileExtension(raster_arg.getValue()));
121 new_raster_fname += "-" + std::to_string(header.n_rows) + "x" +
122 std::to_string(header.n_cols) + ".asc";
124 new_raster_fname);
125 }
126 }
127
128 std::unique_ptr<MeshLib::Mesh> src_mesh(
132 property_arg.getValue()));
133
134 // do the interpolation
136 *src_mesh, property_arg.getValue());
137 mesh_interpolation.setPropertiesForMesh(*dest_mesh);
138
139 if (!out_mesh_arg.getValue().empty())
140 {
141 MeshLib::IO::writeMeshToFile(*dest_mesh, out_mesh_arg.getValue());
142 }
143
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")
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
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(), BaseLib::initOGSLogger(), BaseLib::makeLogLevelArg(), 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().