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 
18 class vtkImageData; // For conversion from Image to QuadMesh
19 
20 namespace MeshLib {
21 
22 class Mesh;
23 class Node;
24 class Element;
25 template <typename T>
26 class PropertyVector;
27 
32 {
33 public:
43  static std::unique_ptr<MeshLib::Mesh> convert(
44  GeoLib::Raster const& raster,
45  MeshElemType elem_type,
46  UseIntensityAs intensity_type,
47  std::string const& array_name = "Colour");
48 
60  static std::unique_ptr<MeshLib::Mesh> convert(
61  vtkImageData* img,
62  const double origin[3],
63  const double scalingFactor,
64  MeshElemType elem_type,
65  UseIntensityAs intensity_type,
66  std::string const& array_name = "Colour");
67 
78  static std::unique_ptr<MeshLib::Mesh> convert(
79  const double* const img,
80  GeoLib::RasterHeader const& header,
81  MeshElemType elem_type,
82  UseIntensityAs intensity_type,
83  std::string const& array_name = "Colour");
84 
85 private:
86  template<typename T>
87  static void fillPropertyVector(
89  double const*const img,
90  GeoLib::RasterHeader const& header,
91  MeshElemType elem_type)
92  {
93  for (std::size_t k = 0; k < header.n_depth; k++)
94  {
95  std::size_t const layer_idx = (k*header.n_rows*header.n_cols);
96  for (std::size_t i = 0; i < header.n_cols; i++)
97  {
98  std::size_t idx(i * header.n_rows + layer_idx);
99  for (std::size_t j = 0; j < header.n_rows; j++)
100  {
101  auto val(static_cast<T>(img[idx + j]));
102  prop_vec.push_back(val);
103  if (elem_type == MeshElemType::TRIANGLE ||
104  elem_type == MeshElemType::PRISM)
105  {
106  prop_vec.push_back(val); // because each pixel is represented by two cells
107  }
108  }
109  }
110  }
111  }
112 };
113 
114 } // end namespace MeshLib
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:42
Converts raster data into an OGS mesh.
Definition: RasterToMesh.h:32
static void fillPropertyVector(MeshLib::PropertyVector< T > &prop_vec, double const *const img, GeoLib::RasterHeader const &header, MeshElemType elem_type)
Definition: RasterToMesh.h:87
static std::unique_ptr< MeshLib::Mesh > convert(GeoLib::Raster const &raster, MeshElemType elem_type, 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:25
std::size_t n_depth
Definition: Raster.h:28
std::size_t n_cols
Definition: Raster.h:26
std::size_t n_rows
Definition: Raster.h:27