diff --git a/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp b/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp index 6bed6f4e44faf8e4c7fe6e39774359a6a00ad138..3cff11e9fce40565afa61e298683bba705f03477 100644 --- a/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp +++ b/Applications/Utils/MeshEdit/ResetPropertiesInPolygonalRegion.cpp @@ -55,6 +55,13 @@ int main(int argc, char* argv[]) "format)", true, "", "file name"); cmd.add(geometry_fname); + TCLAP::SwitchArg any_of_arg( + "", "any_of", + "all nodes of an element has to be inside the polygon (default " + "behaviour without switch) or any node of an element has to be inside " + "(switch is given)", + false); + cmd.add(any_of_arg); TCLAP::ValueArg<char> char_property_arg( "c", "char-property-value", "new property value (data type char)", false, 'A', "character"); @@ -135,23 +142,23 @@ int main(int argc, char* argv[]) if (char_property_arg.isSet()) { - MeshGeoToolsLib::resetMeshElementProperty(*mesh, polygon, property_name, - char_property_arg.getValue(), - restrict_arg.getValue()); + MeshGeoToolsLib::resetMeshElementProperty( + *mesh, polygon, property_name, char_property_arg.getValue(), + restrict_arg.getValue(), any_of_arg.getValue()); } if (int_property_arg.isSet()) { - MeshGeoToolsLib::resetMeshElementProperty(*mesh, polygon, property_name, - int_property_arg.getValue(), - restrict_arg.getValue()); + MeshGeoToolsLib::resetMeshElementProperty( + *mesh, polygon, property_name, int_property_arg.getValue(), + restrict_arg.getValue(), any_of_arg.getValue()); } if (bool_property_arg.isSet()) { - MeshGeoToolsLib::resetMeshElementProperty(*mesh, polygon, property_name, - bool_property_arg.getValue(), - restrict_arg.getValue()); + MeshGeoToolsLib::resetMeshElementProperty( + *mesh, polygon, property_name, bool_property_arg.getValue(), + restrict_arg.getValue(), any_of_arg.getValue()); } MeshLib::MeshInformation::writePropertyVectorInformation(*mesh); diff --git a/MeshGeoToolsLib/MeshEditing/ResetMeshElementProperty.h b/MeshGeoToolsLib/MeshEditing/ResetMeshElementProperty.h index ed9fab401e5693fde1f29e3fd7fc1b1d088e8a7b..f526a681ade5b0a01423b5abd129443bcd55ead1 100644 --- a/MeshGeoToolsLib/MeshEditing/ResetMeshElementProperty.h +++ b/MeshGeoToolsLib/MeshEditing/ResetMeshElementProperty.h @@ -14,17 +14,14 @@ #include <cstdlib> #include <vector> -#include "MeshLib/IO/readMeshFromFile.h" -#include "MeshLib/IO/writeMeshToFile.h" - #include "GeoLib/GEOObjects.h" #include "GeoLib/Polygon.h" - #include "MeshGeoToolsLib/MeshEditing/MarkNodesOutsideOfPolygon.h" - +#include "MeshLib/Elements/Element.h" +#include "MeshLib/IO/readMeshFromFile.h" +#include "MeshLib/IO/writeMeshToFile.h" #include "MeshLib/Mesh.h" #include "MeshLib/Node.h" -#include "MeshLib/Elements/Element.h" namespace MeshGeoToolsLib { @@ -33,7 +30,8 @@ void resetMeshElementProperty(MeshLib::Mesh& mesh, GeoLib::Polygon const& polygon, std::string const& property_name, PT new_property_value, - int restrict_to_material_id) + int restrict_to_material_id, + bool const any_of) { auto* const pv = MeshLib::getOrCreateMeshProperty<PT>( mesh, property_name, MeshLib::MeshItemType::Cell, 1); @@ -44,9 +42,10 @@ void resetMeshElementProperty(MeshLib::Mesh& mesh, return; } - auto is_node_outside = - [outside = markNodesOutSideOfPolygon(mesh.getNodes(), polygon)]( - auto const* node_ptr) { return outside[node_ptr->getID()]; }; + auto const outside = markNodesOutSideOfPolygon(mesh.getNodes(), polygon); + + auto is_node_outside = [&outside](auto const* node_ptr) + { return outside[node_ptr->getID()]; }; auto const* material_ids = mesh.getProperties().getPropertyVector<int>("MaterialIDs"); @@ -59,17 +58,22 @@ void resetMeshElementProperty(MeshLib::Mesh& mesh, "mesh."); } - auto has_element_required_material_id = [&](int const element_id) { + auto has_element_required_material_id = [&](int const element_id) + { return restrict_to_material_id == -1 || (*material_ids)[element_id] == restrict_to_material_id; }; + auto is_element_outside = + any_of ? std::all_of<MeshLib::Node* const*, decltype(is_node_outside)> + : std::any_of<MeshLib::Node* const*, decltype(is_node_outside)>; + for (std::size_t j(0); j < mesh.getElements().size(); ++j) { MeshLib::Element const* const elem(mesh.getElements()[j]); - if (std::all_of(elem->getNodes(), - elem->getNodes() + elem->getNumberOfNodes(), - is_node_outside)) + if (is_element_outside(elem->getNodes(), + elem->getNodes() + elem->getNumberOfNodes(), + is_node_outside)) { continue; }