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