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 More...
 
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. More...
 
std::size_t searchByContent (double eps=std::numeric_limits< double >::epsilon())
 Marks all elements with a volume smaller than eps. More...
 
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;. More...
 
std::size_t searchByNodeIDs (const std::vector< std::size_t > &nodes)
 Marks all elements connecting to any of the given nodes. More...
 

Private Member Functions

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

Private Attributes

const MeshLib::Mesh_mesh
 The mesh from which elements should be removed. More...
 
std::vector< std::size_t > _marked_elements
 The vector of element indices that should be removed. More...
 

Constructor & Destructor Documentation

◆ ElementSearch()

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

Definition at line 19 of file ElementSearch.cpp.

19 : _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)

Marks all elements with at least one node outside the bounding box spanned by x1 and x2;.

Definition at line 55 of file ElementSearch.cpp.

56 {
57  auto matchedIDs =
59  [&aabb](MeshLib::Element* e)
60  {
61  std::size_t const nElemNodes(e->getNumberOfBaseNodes());
62  for (std::size_t n = 0; n < nElemNodes; ++n)
63  {
64  if (aabb.containsPoint(*e->getNode(n), 0))
65  {
66  return true; // any node of element is in aabb.
67  }
68  }
69  return false; // no nodes of element are in aabb.
70  });
71 
72  this->updateUnion(matchedIDs);
73  return matchedIDs.size();
74 }
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:98
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 46 of file ElementSearch.cpp.

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

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 37 of file ElementSearch.cpp.

38 {
39  auto matchedIDs = filter(_mesh.getElements(), [&](MeshLib::Element* e)
40  { return e->getGeomType() == eleType; });
41 
42  this->updateUnion(matchedIDs);
43  return matchedIDs.size();
44 }

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 76 of file ElementSearch.cpp.

78 {
79  std::vector<std::size_t> connected_elements;
80  for (std::size_t node_id : nodes)
81  {
82  auto const& elements = _mesh.getElementsConnectedToNode(node_id);
83  std::transform(begin(elements), end(elements),
84  back_inserter(connected_elements),
85  [](Element const* const e) { return e->getID(); });
86  }
87 
88  BaseLib::makeVectorUnique(connected_elements);
89 
90  this->updateUnion(connected_elements);
91  return connected_elements.size();
92 }
std::vector< Element const * > const & getElementsConnectedToNode(std::size_t node_id) const
Definition: Mesh.cpp:232
void makeVectorUnique(std::vector< T > &v)
Definition: Algorithm.h:209

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

Referenced by MeshGeoToolsLib::BoundaryElementsAlongPolyline::BoundaryElementsAlongPolyline(), MeshGeoToolsLib::BoundaryElementsOnSurface::BoundaryElementsOnSurface(), and MeshLib::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 MeshLib::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  {
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  }
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
void WARN(char const *fmt, Args const &... args)
Definition: Logging.h:37
Properties & getProperties()
Definition: Mesh.h:123
PropertyVector< T > const * getPropertyVector(std::string const &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(), 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 94 of file ElementSearch.cpp.

95 {
96  std::vector<std::size_t> vec_temp(vec.size() + _marked_elements.size());
97  auto it = std::set_union(vec.begin(), vec.end(), _marked_elements.begin(),
98  _marked_elements.end(), vec_temp.begin());
99  vec_temp.resize(it - vec_temp.begin());
100  _marked_elements.assign(vec_temp.begin(), vec_temp.end());
101 }

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 138 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 136 of file ElementSearch.h.

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


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