OGS
createMeshElemPropertiesFromASCRaster.cpp File Reference
#include <tclap/CmdLine.h>
#include <algorithm>
#include <cmath>
#include <memory>
#include <numeric>
#include "Applications/FileIO/AsciiRasterInterface.h"
#include "BaseLib/FileTools.h"
#include "BaseLib/quicksort.h"
#include "GeoLib/Raster.h"
#include "InfoLib/GitInfo.h"
#include "MathLib/MathTools.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/MeshEditing/Mesh2MeshPropertyInterpolation.h"
#include "MeshLib/MeshEnums.h"
#include "MeshLib/MeshGenerators/RasterToMesh.h"
#include "MeshLib/MeshGenerators/VtkMeshConverter.h"
Include dependency graph for createMeshElemPropertiesFromASCRaster.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 Implementation of the createMeshElemPropertiesFromASCRaster tool. More...
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Implementation of the createMeshElemPropertiesFromASCRaster tool.

Definition at line 34 of file createMeshElemPropertiesFromASCRaster.cpp.

35 {
36  TCLAP::CmdLine cmd(
37  "Generates properties for mesh elements of an input mesh deploying a "
38  "ASC raster file.\n\n"
39  "OpenGeoSys-6 software, version " +
41  ".\n"
42  "Copyright (c) 2012-2021, OpenGeoSys Community "
43  "(http://www.opengeosys.org)",
45 
46  TCLAP::ValueArg<std::string> out_mesh_arg(
47  "o",
48  "out-mesh",
49  "the mesh is stored to a file of this name",
50  false,
51  "",
52  "filename for mesh output");
53  cmd.add(out_mesh_arg);
54 
55  TCLAP::SwitchArg refinement_raster_output_arg(
56  "", "output-refined-raster",
57  "Write refined raster to an additional, new ASC file.");
58  cmd.add(refinement_raster_output_arg);
59 
60  TCLAP::ValueArg<unsigned> refinement_arg(
61  "r",
62  "refine",
63  "refinement factor that raises the resolution of the raster data",
64  false,
65  1,
66  "factor (default = 1)");
67  cmd.add(refinement_arg);
68 
69  TCLAP::ValueArg<std::string> raster_arg("",
70  "raster-file",
71  "the name of the ASC raster file",
72  true,
73  "",
74  "file name");
75  cmd.add(raster_arg);
76 
77  TCLAP::ValueArg<std::string> property_arg(
78  "p",
79  "property-name",
80  "the name of the property the values are stored for",
81  true,
82  "",
83  "property name as string");
84  cmd.add(property_arg);
85 
86  TCLAP::ValueArg<std::string> mesh_arg(
87  "m", "mesh", "the mesh is read from this file", true, "", "file name");
88  cmd.add(mesh_arg);
89 
90  cmd.parse(argc, argv);
91 
92  // read mesh
93  std::unique_ptr<MeshLib::Mesh> dest_mesh(
94  MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
95 
96  // read raster and if required manipulate it
97  auto raster = std::unique_ptr<GeoLib::Raster>(
99  raster_arg.getValue()));
100  GeoLib::RasterHeader header(raster->getHeader());
101  if (refinement_arg.getValue() > 1)
102  {
103  raster->refineRaster(refinement_arg.getValue());
104  if (refinement_raster_output_arg.getValue())
105  {
106  // write new asc file
107  std::string new_raster_fname(
108  BaseLib::dropFileExtension(raster_arg.getValue()));
109  new_raster_fname += "-" + std::to_string(header.n_rows) + "x" +
110  std::to_string(header.n_cols) + ".asc";
112  new_raster_fname);
113  }
114  }
115 
116  std::unique_ptr<MeshLib::Mesh> src_mesh(
120  property_arg.getValue()));
121 
122  // do the interpolation
123  MeshLib::Mesh2MeshPropertyInterpolation mesh_interpolation(
124  *src_mesh, property_arg.getValue());
125  mesh_interpolation.setPropertiesForMesh(*dest_mesh);
126 
127  if (!out_mesh_arg.getValue().empty())
128  {
129  MeshLib::IO::writeMeshToFile(*dest_mesh, out_mesh_arg.getValue());
130  }
131 
132  return EXIT_SUCCESS;
133 }
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, MeshElemType elem_type, UseIntensityAs intensity_type, std::string const &array_name="Colour")
std::string dropFileExtension(std::string const &filename)
Definition: FileTools.cpp:169
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, [[maybe_unused]] std::set< std::string > variable_output_names)
Contains the relevant information when storing a geoscientific raster data.
Definition: Raster.h:25

References MeshLib::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(), MeshLib::Mesh2MeshPropertyInterpolation::setPropertiesForMesh(), MeshLib::IO::writeMeshToFile(), and FileIO::AsciiRasterInterface::writeRasterAsASC().