Skip to content

Commit

Permalink
Merge branch 'RemoveMeshElementsInvertBoundingBox' into 'master'
Browse files Browse the repository at this point in the history
[utils] Invert bounding box for RemoveMeshElements

Closes #3414

See merge request ogs/ogs!4759
  • Loading branch information
bilke committed Nov 7, 2023
2 parents 007ad47 + 80f3038 commit ac5a1f8
Show file tree
Hide file tree
Showing 12 changed files with 88,349 additions and 19 deletions.
21 changes: 14 additions & 7 deletions Applications/DataExplorer/DataView/MeshElementRemoval.ui
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,6 @@
</property>
</spacer>
</item>
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="boundingBoxCheckBox">
<property name="text">
<string>Bounding Box, Nodes with</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QRadioButton" name="insideButton">
<property name="enabled">
Expand Down Expand Up @@ -354,6 +347,20 @@
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="boundingBoxCheckBox">
<property name="text">
<string>Bounding Box, Nodes with</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QCheckBox" name="invertBoundingBoxCheckBox">
<property name="text">
<string>Invert Bounding Box</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
21 changes: 20 additions & 1 deletion Applications/DataExplorer/DataView/MeshElementRemovalDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ void MeshElementRemovalDialog::accept()
std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>
extent{minAABB, maxAABB};
const GeoLib::AABB updated_aabb(extent.begin(), extent.end());
ex.searchByBoundingBox(updated_aabb);
ex.searchByBoundingBox(updated_aabb,
this->invertBoundingBoxCheckBox->isChecked());
anything_checked = true;
}

Expand Down Expand Up @@ -234,6 +235,7 @@ void MeshElementRemovalDialog::on_insideButton_toggled(bool /*is_checked*/)

void MeshElementRemovalDialog::on_boundingBoxCheckBox_toggled(bool is_checked)
{
this->invertBoundingBoxCheckBox->setEnabled(is_checked);
this->xMinEdit->setEnabled(is_checked);
this->xMaxEdit->setEnabled(is_checked);
this->yMinEdit->setEnabled(is_checked);
Expand Down Expand Up @@ -261,6 +263,23 @@ void MeshElementRemovalDialog::on_boundingBoxCheckBox_toggled(bool is_checked)
}
}

void MeshElementRemovalDialog::on_invertBoundingBoxCheckBox_toggled(
bool const is_checked)
{
if (is_checked == true)
{
this->xOutsideLabel->setText("X between");
this->yOutsideLabel->setText("Y between");
this->zOutsideLabel->setText("Z between");
}
else
{
this->xOutsideLabel->setText("X outside of");
this->yOutsideLabel->setText("Y outside of");
this->zOutsideLabel->setText("Z outside of");
}
}

void MeshElementRemovalDialog::on_elementTypeCheckBox_toggled(bool is_checked)
{
this->elementTypeListWidget->setEnabled(is_checked);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MeshElementRemovalDialog : public QDialog, private Ui_MeshElementRemoval

private slots:
void on_boundingBoxCheckBox_toggled(bool is_checked);
void on_invertBoundingBoxCheckBox_toggled(bool const is_checked);
void on_elementTypeCheckBox_toggled(bool is_checked);
void on_scalarArrayCheckBox_toggled(bool is_checked);
void on_insideButton_toggled(bool is_checked);
Expand Down
19 changes: 18 additions & 1 deletion Applications/Utils/MeshEdit/removeMeshElements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "MeshLib/MeshSearch/ElementSearch.h"
#include "MeshLib/Node.h"
#include "MeshToolsLib/MeshEditing/RemoveMeshComponents.h"
#include "MeshToolsLib/MeshInformation.h"

template <typename PROPERTY_TYPE>
void searchByPropertyValue(std::string const& property_name,
Expand Down Expand Up @@ -70,6 +71,17 @@ void searchByPropertyRange(std::string const& property_name,
std::to_string(min_value), std::to_string(max_value));
}

void outputAABB(MeshLib::Mesh const& mesh)
{
const auto aabb(MeshToolsLib::MeshInformation::getBoundingBox(mesh));
auto const [min, max] = aabb.getMinMaxPoints();

INFO(
"Bounding box of \"{:s}\" is\nx = [{:f},{:f}]\ny = [{:f},{:f}]\nz = "
"[{:f},{:f}]",
mesh.getName(), min.x(), max.x(), min.y(), max.y(), min.z(), max.z());
}

int main(int argc, char* argv[])
{
TCLAP::CmdLine cmd(
Expand All @@ -85,6 +97,9 @@ int main(int argc, char* argv[])
' ', GitInfoLib::GitInfo::ogs_version);

// Bounding box params
TCLAP::SwitchArg invert_bounding_box_arg(
"", "invert", "inverts the specified bounding box", false);
cmd.add(invert_bounding_box_arg);
TCLAP::ValueArg<double> zLargeArg(
"", "z-max", "largest allowed extent in z-dimension", false,
std::numeric_limits<double>::max(), "value");
Expand Down Expand Up @@ -265,6 +280,7 @@ int main(int argc, char* argv[])
if (xSmallArg.isSet() || xLargeArg.isSet() || ySmallArg.isSet() ||
yLargeArg.isSet() || zSmallArg.isSet() || zLargeArg.isSet())
{
outputAABB(*mesh);
bool aabb_error(false);
if (xSmallArg.getValue() >= xLargeArg.getValue())
{
Expand Down Expand Up @@ -298,7 +314,8 @@ int main(int argc, char* argv[])
zLargeArg.getValue()}})}});
INFO("{:d} elements found.",
searcher.searchByBoundingBox(
GeoLib::AABB(extent.begin(), extent.end())));
GeoLib::AABB(extent.begin(), extent.end()),
invert_bounding_box_arg.getValue()));
}

// remove the elements and create a new mesh object.
Expand Down
52 changes: 52 additions & 0 deletions Applications/Utils/Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,58 @@ if(NOT OGS_USE_PETSC)
RUNTIME 10)
endif()

AddTest(
NAME RemoveMeshElements_AABB_2D_regular
PATH MeshLib
WORKING_DIRECTORY ${Data_SOURCE_DIR}/MeshLib
EXECUTABLE removeMeshElements
EXECUTABLE_ARGS -i AREHS_Layer17.vtu
-o ${Data_BINARY_DIR}/MeshLib/AREHS_2D_AABB_regular.vtu
--x-min 12000 --x-max 15000 --y-min 12000
REQUIREMENTS NOT (OGS_USE_MPI)
TESTER vtkdiff-mesh
DIFF_DATA AREHS_2D_AABB_regular.vtu AREHS_2D_AABB_regular.vtu 1.e-16
)

AddTest(
NAME RemoveMeshElements_AABB_2D_inverted
PATH MeshLib
WORKING_DIRECTORY ${Data_SOURCE_DIR}/MeshLib
EXECUTABLE removeMeshElements
EXECUTABLE_ARGS -i AREHS_Layer17.vtu
-o ${Data_BINARY_DIR}/MeshLib/AREHS_2D_AABB_inverted.vtu
--x-min 12000 --x-max 15000 --y-min 12000 --invert
REQUIREMENTS NOT (OGS_USE_MPI)
TESTER vtkdiff-mesh
DIFF_DATA AREHS_2D_AABB_inverted.vtu AREHS_2D_AABB_inverted.vtu 1.e-16
)

AddTest(
NAME RemoveMeshElements_AABB_3D_regular
PATH MeshLib
WORKING_DIRECTORY ${Data_SOURCE_DIR}/MeshLib
EXECUTABLE removeMeshElements
EXECUTABLE_ARGS -i AREHS_test.vtu
-o ${Data_BINARY_DIR}/MeshLib/AREHS_3D_AABB_regular.vtu
--x-min 12000 --x-max 15000 --y-min 12000 --z-min -3000 --z-max -2000
REQUIREMENTS NOT (OGS_USE_MPI)
TESTER vtkdiff-mesh
DIFF_DATA AREHS_3D_AABB_regular.vtu AREHS_3D_AABB_regular.vtu 1.e-16
)

AddTest(
NAME RemoveMeshElements_AABB_3D_inverted
PATH MeshLib
WORKING_DIRECTORY ${Data_SOURCE_DIR}/MeshLib
EXECUTABLE removeMeshElements
EXECUTABLE_ARGS -i AREHS_test.vtu
-o ${Data_BINARY_DIR}/MeshLib/AREHS_3D_AABB_inverted.vtu
--x-min 12000 --x-max 15000 --y-min 12000 --z-min -3000 --z-max -2000 --invert
REQUIREMENTS NOT (OGS_USE_MPI)
TESTER vtkdiff-mesh
DIFF_DATA AREHS_3D_AABB_inverted.vtu AREHS_3D_AABB_inverted.vtu 1.e-16
)

if(OGS_USE_PETSC)
NotebookTest(NOTEBOOKFILE Utils/partmesh/partmesh_roundtrip.md RUNTIME 10 SKIP_WEB)
endif()
8 changes: 5 additions & 3 deletions MeshLib/MeshSearch/ElementSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ std::size_t ElementSearch::searchByContent(double eps)
return matchedIDs.size();
}

std::size_t ElementSearch::searchByBoundingBox(GeoLib::AABB const& aabb)
std::size_t ElementSearch::searchByBoundingBox(GeoLib::AABB const& aabb,
bool const invert)
{
auto matchedIDs = filter(
_mesh.getElements(),
[&aabb](MeshLib::Element const* e)
[&aabb, invert](MeshLib::Element const* e)
{
// any node of element is in aabb.
return ranges::any_of(
e->nodes() | ranges::views::take(e->getNumberOfBaseNodes()),
[&aabb](auto const* n) { return aabb.containsPoint(*n, 0); });
[&aabb, invert](auto const* n)
{ return (aabb.containsPoint(*n, 0) != invert); });
});

this->updateUnion(matchedIDs);
Expand Down
7 changes: 5 additions & 2 deletions MeshLib/MeshSearch/ElementSearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ class ElementSearch final
/// Marks all elements with a volume smaller than eps.
std::size_t searchByContent(double eps = std::numeric_limits<double>::epsilon());

/// Marks all elements with at least one node outside the bounding box spanned by x1 and x2;
std::size_t searchByBoundingBox(GeoLib::AABB const& aabb);
/// 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.
std::size_t searchByBoundingBox(GeoLib::AABB const& aabb,
bool const invert = false);

/// Marks all elements connecting to any of the given nodes
std::size_t searchByNodeIDs(const std::vector<std::size_t>& nodes);
Expand Down
Loading

0 comments on commit ac5a1f8

Please sign in to comment.