Loading [MathJax]/extensions/tex2jax.js
OGS
RasterToMesh.h
Go to the documentation of this file.
1
11#pragma once
12
13#include "GeoLib/Raster.h"
14#include "MeshLib/MeshEnums.h"
15#include "MeshLib/Properties.h"
16
17class vtkImageData; // For conversion from Image to QuadMesh
18
19namespace MeshLib
20{
21
22class Mesh;
23class Node;
24class Element;
25template <typename T>
26class PropertyVector;
27} // namespace MeshLib
28
29namespace MeshToolsLib
30{
31
36{
37public:
47 static std::unique_ptr<MeshLib::Mesh> convert(
48 GeoLib::Raster const& raster,
49 MeshLib::MeshElemType elem_type,
50 MeshLib::UseIntensityAs intensity_type,
51 std::string const& array_name = "Colour");
52
64 static std::unique_ptr<MeshLib::Mesh> convert(
65 vtkImageData* img,
66 const double origin[3],
67 const double scalingFactor,
68 MeshLib::MeshElemType elem_type,
69 MeshLib::UseIntensityAs intensity_type,
70 std::string const& array_name = "Colour");
71
82 static std::unique_ptr<MeshLib::Mesh> convert(
83 const double* const img,
84 GeoLib::RasterHeader const& header,
85 MeshLib::MeshElemType elem_type,
86 MeshLib::UseIntensityAs intensity_type,
87 std::string const& array_name = "Colour");
88
89private:
90 template <typename T>
92 double const* const img,
93 GeoLib::RasterHeader const& header,
94 MeshLib::MeshElemType elem_type)
95 {
96 for (std::size_t k = 0; k < header.n_depth; k++)
97 {
98 std::size_t const layer_idx = (k * header.n_rows * header.n_cols);
99 for (std::size_t i = 0; i < header.n_cols; i++)
100 {
101 std::size_t idx(i * header.n_rows + layer_idx);
102 for (std::size_t j = 0; j < header.n_rows; j++)
103 {
104 auto val(static_cast<T>(img[idx + j]));
105 prop_vec.push_back(val);
106 if (elem_type == MeshLib::MeshElemType::TRIANGLE ||
107 elem_type == MeshLib::MeshElemType::PRISM)
108 {
109 prop_vec.push_back(val); // because each pixel is
110 // represented by two cells
111 }
112 }
113 }
114 }
115 }
116};
117
118} // namespace MeshToolsLib
Definition of mesh-related Enumerations.
Definition of the class Properties that implements a container of properties.
Definition of the GeoLib::Raster class.
Class Raster is used for managing raster data.
Definition Raster.h:49
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:104
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:48
Contains the relevant information when storing a geoscientific raster data.
Definition Raster.h:28
std::size_t n_depth
Definition Raster.h:31
std::size_t n_cols
Definition Raster.h:29
std::size_t n_rows
Definition Raster.h:30