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
20namespace MeshLib {
21
22// forward declarations
23class Mesh;
24class Element;
25
27class ElementSearch final
28{
29public:
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 {
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 {
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
128 std::size_t searchByBoundingBox(GeoLib::AABB const& aabb,
129 bool const invert = false);
130
132 std::size_t searchByNodeIDs(const std::vector<std::size_t>& nodes);
133
134private:
136 void updateUnion(const std::vector<std::size_t> &vec);
137
141 std::vector<std::size_t> _marked_elements;
142};
143
144} // end namespace MeshLib
Definition of the AABB class.
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
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:56
Element search class.
void updateUnion(const std::vector< std::size_t > &vec)
Updates the vector of marked elements with values from vec.
std::size_t searchByBoundingBox(GeoLib::AABB const &aabb, bool const invert=false)
const std::vector< std::size_t > & getSearchedElementIDs() const
return marked elements
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)
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 searchByPropertyValue(std::string const &property_name, PROPERTY_TYPE const property_value)
const MeshLib::Mesh & _mesh
The mesh from which elements should be removed.
std::vector< std::size_t > _marked_elements
The vector of element indices that should be removed.
Properties & getProperties()
Definition Mesh.h:134
PropertyVector< T > const * getPropertyVector(std::string_view name) const
std::size_t getNumberOfTuples() const
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
Definition MeshEnums.h:27