OGS
ElementSearch.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <limits>
14 #include <vector>
15 
16 #include "GeoLib/AABB.h"
17 #include "MeshLib/Mesh.h"
18 #include "MeshLib/MeshEnums.h"
19 
20 namespace MeshLib {
21 
22 // forward declarations
23 class Mesh;
24 class Element;
25 
27 class ElementSearch final
28 {
29 public:
30  explicit ElementSearch(const MeshLib::Mesh &mesh);
31 
33  const std::vector<std::size_t>& getSearchedElementIDs() const { return _marked_elements; }
34 
45  template <typename PROPERTY_TYPE>
46  std::size_t searchByPropertyValue(std::string const& property_name,
47  PROPERTY_TYPE const property_value)
48  {
49  return searchByPropertyValueRange<PROPERTY_TYPE>(
50  property_name, property_value, property_value, false);
51  }
52 
69  template <typename PROPERTY_TYPE>
71  std::string const& property_name,
72  PROPERTY_TYPE const min_property_value,
73  PROPERTY_TYPE const max_property_value,
74  bool outside_of)
75  {
76  MeshLib::PropertyVector<PROPERTY_TYPE> const* pv = nullptr;
77  try
78  {
79  pv = _mesh.getProperties().getPropertyVector<PROPERTY_TYPE>(
80  property_name, MeshLib::MeshItemType::Cell, 1);
81  }
82  catch (std::runtime_error const& e)
83  {
84  ERR("{:s}", e.what());
85  WARN(
86  "Value-based element removal currently only works for "
87  "scalars.");
88  return 0;
89  }
90 
91  std::vector<std::size_t> matchedIDs;
92 
93  if (outside_of)
94  {
95  for (std::size_t i(0); i < pv->getNumberOfTuples(); ++i)
96  {
97  if ((*pv)[i] < min_property_value ||
98  (*pv)[i] > max_property_value)
99  {
100  matchedIDs.push_back(i);
101  }
102  }
103  }
104  else
105  {
106  for (std::size_t i(0); i < pv->getNumberOfTuples(); ++i)
107  {
108  if ((*pv)[i] >= min_property_value &&
109  (*pv)[i] <= max_property_value)
110  {
111  matchedIDs.push_back(i);
112  }
113  }
114  }
115  updateUnion(matchedIDs);
116  return matchedIDs.size();
117  }
118 
120  std::size_t searchByElementType(MeshElemType eleType);
121 
123  std::size_t searchByContent(double eps = std::numeric_limits<double>::epsilon());
124 
126  std::size_t searchByBoundingBox(GeoLib::AABB const& aabb);
127 
129  std::size_t searchByNodeIDs(const std::vector<std::size_t>& nodes);
130 
131 private:
133  void updateUnion(const std::vector<std::size_t> &vec);
134 
138  std::vector<std::size_t> _marked_elements;
139 };
140 
141 } // end namespace MeshLib
Definition of the AABB class.
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
Definition of mesh-related Enumerations.
Definition of the Mesh class.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
Definition: AABB.h:49
Element search class.
Definition: ElementSearch.h:28
void updateUnion(const std::vector< std::size_t > &vec)
Updates the vector of marked elements with values from vec.
std::size_t searchByElementType(MeshElemType eleType)
Marks all elements of the given element type.
std::size_t searchByNodeIDs(const std::vector< std::size_t > &nodes)
Marks all elements connecting to any of the given nodes.
std::size_t searchByPropertyValueRange(std::string const &property_name, PROPERTY_TYPE const min_property_value, PROPERTY_TYPE const max_property_value, bool outside_of)
Definition: ElementSearch.h:70
std::size_t searchByContent(double eps=std::numeric_limits< double >::epsilon())
Marks all elements with a volume smaller than eps.
ElementSearch(const MeshLib::Mesh &mesh)
std::size_t searchByBoundingBox(GeoLib::AABB const &aabb)
Marks all elements with at least one node outside the bounding box spanned by x1 and x2;.
std::size_t searchByPropertyValue(std::string const &property_name, PROPERTY_TYPE const property_value)
Definition: ElementSearch.h:46
const MeshLib::Mesh & _mesh
The mesh from which elements should be removed.
const std::vector< std::size_t > & getSearchedElementIDs() const
return marked elements
Definition: ElementSearch.h:33
std::vector< std::size_t > _marked_elements
The vector of element indices that should be removed.
Properties & getProperties()
Definition: Mesh.h:123
PropertyVector< T > const * getPropertyVector(std::string const &name) const
std::size_t getNumberOfTuples() const
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition: MeshEnums.h:27