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 for (std::size_t k = 0; k < header.n_depth; k++)
90 {
91 std::size_t const layer_idx = (k * header.n_rows * header.n_cols);
92 for (std::size_t i = 0; i < header.n_cols; i++)
93 {
94 std::size_t idx(i * header.n_rows + layer_idx);
95 for (std::size_t j = 0; j < header.n_rows; j++)
96 {
97 auto val(static_cast<T>(img[idx + j]));
98 prop_vec.push_back(val);
99 if (elem_type == MeshLib::MeshElemType::TRIANGLE ||
100 elem_type == MeshLib::MeshElemType::PRISM)
101 {
102 prop_vec.push_back(val); // because each pixel is
103 // represented by two cells
104 }
105 }
106 }
107 }
108 }
109};
110
111} // namespace MeshToolsLib
Class Raster is used for managing raster data.
Definition Raster.h:39
constexpr void push_back(const PROP_VAL_TYPE &value)
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")
UseIntensityAs
Selection of possible interpretations for intensities.
Definition MeshEnums.h:93
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:37
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