OGS
MeshLib::ElementSearch Class Referencefinal

Detailed Description

Element search class.

Definition at line 27 of file ElementSearch.h.

#include <ElementSearch.h>

Collaboration diagram for MeshLib::ElementSearch:
[legend]

Public Member Functions

 ElementSearch (const MeshLib::Mesh &mesh)
 
const std::vector< std::size_t > & getSearchedElementIDs () const
 return marked elements
 
template<typename PROPERTY_TYPE >
std::size_t searchByPropertyValue (std::string const &property_name, PROPERTY_TYPE const property_value)
 
template<typename PROPERTY_TYPE >
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 searchByElementType (MeshElemType eleType)
 Marks all elements of the given element type.
 
std::size_t searchByContent (double eps=std::numeric_limits< double >::epsilon())
 Marks all elements with a volume smaller than eps.
 
std::size_t searchByBoundingBox (GeoLib::AABB const &aabb, bool const invert=false)
 
std::size_t searchByNodeIDs (const std::vector< std::size_t > &nodes)
 Marks all elements connecting to any of the given nodes.
 

Private Member Functions

void updateUnion (const std::vector< std::size_t > &vec)
 Updates the vector of marked elements with values from vec.
 

Private Attributes

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.
 

Constructor & Destructor Documentation

◆ ElementSearch()

MeshLib::ElementSearch::ElementSearch ( const MeshLib::Mesh & mesh)
explicit

Definition at line 24 of file ElementSearch.cpp.

24: _mesh(mesh) {}
const MeshLib::Mesh & _mesh
The mesh from which elements should be removed.

Member Function Documentation

◆ getSearchedElementIDs()

const std::vector< std::size_t > & MeshLib::ElementSearch::getSearchedElementIDs ( ) const
inline

◆ searchByBoundingBox()

std::size_t MeshLib::ElementSearch::searchByBoundingBox ( GeoLib::AABB const & aabb,
bool const invert = false )

Marks all elements with at least one node outside the bounding box AABB. If the invert-flag is set, all elements with at least one node inside AABB are marked instead.

Definition at line 52 of file ElementSearch.cpp.

54{
55 auto matchedIDs = filter(
57 [&aabb, invert](MeshLib::Element const* e)
58 {
59 // any node of element is in aabb.
60 return ranges::any_of(
61 e->nodes() | ranges::views::take(e->getNumberOfBaseNodes()),
62 [&aabb, invert](auto const* n)
63 { return (aabb.containsPoint(*n, 0) != invert); });
64 });
65
66 this->updateUnion(matchedIDs);
67 return matchedIDs.size();
68}
void updateUnion(const std::vector< std::size_t > &vec)
Updates the vector of marked elements with values from vec.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
std::vector< std::size_t > filter(Container const &container, Predicate const &p)

References _mesh, MeshLib::filter(), and MeshLib::Mesh::getElements().

Referenced by MeshElementRemovalDialog::accept(), and main().

◆ searchByContent()

std::size_t MeshLib::ElementSearch::searchByContent ( double eps = std::numeric_limits<double>::epsilon())

Marks all elements with a volume smaller than eps.

Definition at line 42 of file ElementSearch.cpp.

43{
44 auto matchedIDs =
45 filter(_mesh.getElements(), [&eps](MeshLib::Element const* e)
46 { return e->getContent() < eps; });
47
48 this->updateUnion(matchedIDs);
49 return matchedIDs.size();
50}

References _mesh, MeshLib::filter(), MeshLib::Mesh::getElements(), and updateUnion().

Referenced by MeshElementRemovalDialog::accept(), and main().

◆ searchByElementType()

std::size_t MeshLib::ElementSearch::searchByElementType ( MeshElemType eleType)

Marks all elements of the given element type.

Definition at line 33 of file ElementSearch.cpp.

34{
35 auto matchedIDs = filter(_mesh.getElements(), [&](MeshLib::Element const* e)
36 { return e->getGeomType() == eleType; });
37
38 this->updateUnion(matchedIDs);
39 return matchedIDs.size();
40}

References _mesh, MeshLib::filter(), MeshLib::Mesh::getElements(), and updateUnion().

Referenced by MeshElementRemovalDialog::accept(), LayeredVolume::createRasterLayers(), and main().

◆ searchByNodeIDs()

std::size_t MeshLib::ElementSearch::searchByNodeIDs ( const std::vector< std::size_t > & nodes)

Marks all elements connecting to any of the given nodes.

Definition at line 70 of file ElementSearch.cpp.

72{
73 std::vector<std::size_t> connected_elements;
74 for (std::size_t node_id : nodes)
75 {
76 auto const& elements = _mesh.getElementsConnectedToNode(node_id);
77 std::transform(begin(elements), end(elements),
78 back_inserter(connected_elements),
79 [](Element const* const e) { return e->getID(); });
80 }
81
82 BaseLib::makeVectorUnique(connected_elements);
83
84 this->updateUnion(connected_elements);
85 return connected_elements.size();
86}
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
Definition Mesh.cpp:256
void makeVectorUnique(std::vector< T > &v)
Definition Algorithm.h:176

References MeshLib::Element::getID(), and BaseLib::makeVectorUnique().

Referenced by MeshGeoToolsLib::BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline(), MeshGeoToolsLib::BoundaryElementsOnSurface::BoundaryElementsOnSurface(), and MeshToolsLib::removeNodes().

◆ searchByPropertyValue()

template<typename PROPERTY_TYPE >
std::size_t MeshLib::ElementSearch::searchByPropertyValue ( std::string const & property_name,
PROPERTY_TYPE const property_value )
inline
Template Parameters
PROPERTY_TYPEtype of the property Different properties can be assigned to the elements of the mesh. These properties can be accessed by the name of the property. The method marks all elements of the mesh for the property property_name with a property value equal to property_value.
Parameters
property_namethe name of the property the searching/marking is based on
property_valuevalue required for the element to be marked
Returns
The number of marked elements will be returned. The concrete element ids can be requested by getSearchedElementIDs().

Definition at line 46 of file ElementSearch.h.

48 {
49 return searchByPropertyValueRange<PROPERTY_TYPE>(
50 property_name, property_value, property_value, false);
51 }

Referenced by MeshToolsLib::RasterToMesh::convert(), and searchByPropertyValue().

◆ searchByPropertyValueRange()

template<typename PROPERTY_TYPE >
std::size_t MeshLib::ElementSearch::searchByPropertyValueRange ( std::string const & property_name,
PROPERTY_TYPE const min_property_value,
PROPERTY_TYPE const max_property_value,
bool outside_of )
inline
Template Parameters
PROPERTY_TYPEtype of the property Different properties can be assigned to the elements of the mesh. These properties can be accessed by the name of the property. The method marks all elements of the mesh for the property property_name with a property value outside of the interval [min_property_value, max_property_value].
Parameters
property_namethe name of the property the searching/marking is based on
min_property_valueminimum value of the given property for the element not to be marked
max_property_valuemaximum value of the given property for the element not to be marked
outside_ofif true, all values outside of the given range are marked, if false, all values inside the given range are marked
Returns
The number of marked elements will be returned. The concrete element ids can be requested by getSearchedElementIDs().

Definition at line 70 of file ElementSearch.h.

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 }
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
Properties & getProperties()
Definition Mesh.h:134
PropertyVector< T > const * getPropertyVector(std::string_view name) const
std::size_t getNumberOfTuples() const

References _mesh, MeshLib::Cell, ERR(), MeshLib::PropertyVector< PROP_VAL_TYPE >::getNumberOfTuples(), MeshLib::Mesh::getProperties(), MeshLib::Properties::getPropertyVector(), updateUnion(), and WARN().

Referenced by MeshElementRemovalDialog::accept(), MeshToolsLib::MeshGenerator::VoxelGridFromMesh::removeUnusedGridCells(), and searchByPropertyRange().

◆ updateUnion()

void MeshLib::ElementSearch::updateUnion ( const std::vector< std::size_t > & vec)
private

Updates the vector of marked elements with values from vec.

Definition at line 88 of file ElementSearch.cpp.

89{
90 std::vector<std::size_t> vec_temp(vec.size() + _marked_elements.size());
91 auto it = std::set_union(vec.begin(), vec.end(), _marked_elements.begin(),
92 _marked_elements.end(), vec_temp.begin());
93 vec_temp.resize(it - vec_temp.begin());
94 _marked_elements.assign(vec_temp.begin(), vec_temp.end());
95}

Referenced by searchByContent(), searchByElementType(), and searchByPropertyValueRange().

Member Data Documentation

◆ _marked_elements

std::vector<std::size_t> MeshLib::ElementSearch::_marked_elements
private

The vector of element indices that should be removed.

Definition at line 141 of file ElementSearch.h.

Referenced by getSearchedElementIDs().

◆ _mesh

const MeshLib::Mesh& MeshLib::ElementSearch::_mesh
private

The mesh from which elements should be removed.

Definition at line 139 of file ElementSearch.h.

Referenced by searchByBoundingBox(), searchByContent(), searchByElementType(), and searchByPropertyValueRange().


The documentation for this class was generated from the following files: