Skip to content
Snippets Groups Projects
Commit 2c88301a authored by Tom Fischer's avatar Tom Fischer
Browse files

[A/U/ME] Add switch arg to tool.

A part of an element is inside of a polygon if at
least one node is in the (convex) polygon. Sometimes
it is useful to forster that all nodes of an
element have to be in the polygon. With the new
implemented switch argument the user can choose the
behaviour of the algorithm.
parent 1ec62b97
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment