OGS
Raster2Mesh.cpp File Reference

Detailed Description

Definition in file Raster2Mesh.cpp.

#include <memory>
#include <string>
#include <tclap/CmdLine.h>
#include "Applications/FileIO/AsciiRasterInterface.h"
#include "GeoLib/Raster.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/MeshEnums.h"
#include "MeshLib/MeshGenerators/RasterToMesh.h"
Include dependency graph for Raster2Mesh.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 24 of file Raster2Mesh.cpp.

25 {
26  TCLAP::CmdLine cmd(
27  "Converts an ASCII raster file (*.asc) into a 2D triangle- or "
28  "quad-mesh. Pixel values can be interpreted as elevation of mesh nodes "
29  "or as scalar values for mesh elements.\nIt is highly recommended to "
30  "create triangle meshes when interpreting pixel values as elevation, "
31  "as it is likely that the resulting mesh will otherwise contain "
32  "deformed (i.e. non-planar) quad-elements.\n\n"
33  "OpenGeoSys-6 software, version " +
35  ".\n"
36  "Copyright (c) 2012-2021, OpenGeoSys Community "
37  "(http://www.opengeosys.org)",
39  TCLAP::ValueArg<std::string> array_name_arg(
40  "n", "arrayname",
41  "Name of the scalar array. Only required if assigning pixel values to "
42  "cell data has been selected (default name is 'Values').",
43  false, "", "name of data array");
44  cmd.add(array_name_arg);
45  std::vector<std::string> pixel_vals{"elevation", "materials", "scalar"};
46  TCLAP::ValuesConstraint<std::string> pixel_val_options(pixel_vals);
47  TCLAP::ValueArg<std::string> arg_pixel_type(
48  "p", "pixel-type",
49  "The choice how pixel values should be interpreted by the software: "
50  "'elevation' adjusts z-coordinates; 'materials' sets (integer) "
51  "material IDs; 'scalar' creates a (floating-point) array associated "
52  "with mesh elements.",
53  true, "", &pixel_val_options);
54  cmd.add(arg_pixel_type);
55  std::vector<std::string> allowed_elems{"tri", "quad"};
56  TCLAP::ValuesConstraint<std::string> allowed_elem_vals(allowed_elems);
57  TCLAP::ValueArg<std::string> arg_elem_type(
58  "e", "elem-type", "The element type used in the resulting OGS mesh.",
59  true, "", &allowed_elem_vals);
60  cmd.add(arg_elem_type);
61  TCLAP::ValueArg<std::string> output_arg("o", "output",
62  "Name of the output mesh (*.vtu)",
63  true, "", "output file name");
64  cmd.add(output_arg);
65  TCLAP::ValueArg<std::string> input_arg("i", "input",
66  "Name of the input raster (*.asc)",
67  true, "", "input file name");
68  cmd.add(input_arg);
69  cmd.parse(argc, argv);
70 
71  std::string const input_name = input_arg.getValue().c_str();
72  std::string const output_name = output_arg.getValue().c_str();
73 
74  std::unique_ptr<GeoLib::Raster> const raster(
76 
77  MeshLib::MeshElemType const elem_type =
78  (arg_elem_type.getValue() == "tri") ? MeshLib::MeshElemType::TRIANGLE
80  MeshLib::UseIntensityAs intensity_type;
81  if (arg_pixel_type.getValue() == "elevation")
82  intensity_type = MeshLib::UseIntensityAs::ELEVATION;
83  else if (arg_pixel_type.getValue() == "materials")
84  intensity_type = MeshLib::UseIntensityAs::MATERIALS;
85  else
86  intensity_type = MeshLib::UseIntensityAs::DATAVECTOR;
87 
88  std::string array_name = "Values";
89  if (intensity_type == MeshLib::UseIntensityAs::DATAVECTOR &&
90  array_name_arg.isSet())
91  array_name = array_name_arg.getValue().c_str();
92  else if (intensity_type == MeshLib::UseIntensityAs::MATERIALS)
93  array_name = "MaterialIDs";
94 
95  std::unique_ptr<MeshLib::Mesh> const mesh(MeshLib::RasterToMesh::convert(
96  *raster, elem_type, intensity_type, array_name));
97 
98  if (mesh == nullptr)
99  {
100  ERR("Conversion failed.");
101  return EXIT_FAILURE;
102  }
103 
104  MeshLib::IO::VtuInterface vtu(mesh.get());
105  vtu.writeToFile(output_name);
106  return EXIT_SUCCESS;
107 }
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
static GeoLib::Raster * getRasterFromASCFile(std::string const &fname)
Reads an ArcGis ASC raster file.
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
Definition: VtuInterface.h:38
static std::unique_ptr< MeshLib::Mesh > convert(GeoLib::Raster const &raster, MeshElemType elem_type, UseIntensityAs intensity_type, std::string const &array_name="Colour")
GITINFOLIB_EXPORT const std::string ogs_version
UseIntensityAs
Selection of possible interpretations for intensities.
Definition: MeshEnums.h:83
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition: MeshEnums.h:27

References MeshLib::RasterToMesh::convert(), MeshLib::DATAVECTOR, MeshLib::ELEVATION, ERR(), FileIO::AsciiRasterInterface::getRasterFromASCFile(), MeshLib::MATERIALS, GitInfoLib::GitInfo::ogs_version, MeshLib::QUAD, MeshLib::TRIANGLE, and MeshLib::IO::VtuInterface::writeToFile().