OGS
RasterToMesh.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6#include "GeoLib/Raster.h"
7#include "MeshLib/MeshEnums.h"
9
10class vtkImageData; // For conversion from Image to QuadMesh
11
12namespace MeshLib
13{
14
15class Mesh;
16class Node;
17class Element;
18template <typename T>
19class PropertyVector;
20} // namespace MeshLib
21
22namespace MeshToolsLib
23{
24
29{
30public:
40 static std::unique_ptr<MeshLib::Mesh> convert(
41 GeoLib::Raster const& raster,
42 MeshLib::MeshElemType elem_type,
43 MeshLib::UseIntensityAs intensity_type,
44 std::string const& array_name = "Colour");
45
57 static std::unique_ptr<MeshLib::Mesh> convert(
58 vtkImageData* img,
59 const double origin[3],
60 const double scalingFactor,
61 MeshLib::MeshElemType elem_type,
62 MeshLib::UseIntensityAs intensity_type,
63 std::string const& array_name = "Colour");
64
75 static std::unique_ptr<MeshLib::Mesh> convert(
76 const double* const img,
77 GeoLib::RasterHeader const& header,
78 MeshLib::MeshElemType elem_type,
79 MeshLib::UseIntensityAs intensity_type,
80 std::string const& array_name = "Colour");
81
82private:
83 template <typename T>
85 double const* const img,
86 GeoLib::RasterHeader const& header,
87 MeshLib::MeshElemType elem_type)
88 {
89 // each pixel is represented by two cells for triangles and prisms
90 bool const two_elements_per_cell =
91 (elem_type == MeshLib::MeshElemType::TRIANGLE) ||
92 (elem_type == MeshLib::MeshElemType::PRISM);
93 std::size_t const elements_per_cell = two_elements_per_cell ? 2 : 1;
94
95 // The iterator is filled below without growing prop_vec again.
96 auto out = MeshLib::extend(
97 prop_vec,
98 header.n_depth * header.n_cols * header.n_rows * elements_per_cell);
99
100 for (std::size_t k = 0; k < header.n_depth; k++)
101 {
102 std::size_t const layer_idx = (k * header.n_rows * header.n_cols);
103 for (std::size_t i = 0; i < header.n_cols; i++)
104 {
105 std::size_t idx(i * header.n_rows + layer_idx);
106 for (std::size_t j = 0; j < header.n_rows; j++)
107 {
108 auto val(static_cast<T>(img[idx + j]));
109 *out++ = val;
110 if (two_elements_per_cell)
111 {
112 *out++ = val;
113 }
114 }
115 }
116 }
117 }
118};
119
120} // namespace MeshToolsLib
Class Raster is used for managing raster data.
Definition Raster.h:39
Converts raster data into an OGS mesh.
static void fillPropertyVector(MeshLib::PropertyVector< T > &prop_vec, double const *const img, GeoLib::RasterHeader const &header, MeshLib::MeshElemType elem_type)
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")
static std::unique_ptr< MeshLib::Mesh > convert(vtkImageData *img, const double origin[3], const double scalingFactor, MeshLib::MeshElemType elem_type, MeshLib::UseIntensityAs intensity_type, std::string const &array_name="Colour")
constexpr auto extend(PropertyVector< T > &property, std::size_t const count)
UseIntensityAs
Selection of possible interpretations for intensities.
Definition MeshEnums.h:98
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:42
Contains the relevant information when storing a geoscientific raster data.
Definition Raster.h:18
std::size_t n_depth
Definition Raster.h:21
std::size_t n_cols
Definition Raster.h:19
std::size_t n_rows
Definition Raster.h:20