From c5486614b1cd17978e1eca1e2937c725c733e78c Mon Sep 17 00:00:00 2001 From: Martin Stepniewski Date: Mon, 21 Dec 2020 20:54:30 +0100 Subject: [PATCH 1/3] Added function 'SelectEdgeByProjectedCoordinate' selecting the edge for which the specified coordinate is closest to its perpendicular projection onto this edge. --- register_selection_tools.cpp | 2 ++ tools/selection_tools.cpp | 30 ++++++++++++++++++++++++++++++ tools/selection_tools.h | 5 +++++ 3 files changed, 37 insertions(+) diff --git a/register_selection_tools.cpp b/register_selection_tools.cpp index a998f28..c18a508 100644 --- a/register_selection_tools.cpp +++ b/register_selection_tools.cpp @@ -169,6 +169,8 @@ void RegisterSelectionTools(ProMeshRegistry& reg, string baseGrp) grp = baseGrp + "/Edges/Coordinate Based"; reg.add_function("SelectEdgeByCoordinate", &SelectElemByCoordinate, grp, "", "mesh # coordinate", TOOLTIP_SELECT_EDGE_BY_COORDINATE) + .add_function("SelectEdgeByProjectedCoordinate", &SelectEdgeByProjectedCoordinate, grp, "", + "mesh # coordinate", TOOLTIP_SELECT_EDGE_BY_PROJECTED_COORDINATE) .add_function("SelectEdgeByCylindricalCoordinate", &SelectElemByCylindricalCoordinate, grp, "", "mesh # rho # phi # z", TOOLTIP_SELECT_EDGE_BY_CYL_COORDINATE) .add_function("SelectEdgesInBox", &SelectElementsInBox, grp, "", diff --git a/tools/selection_tools.cpp b/tools/selection_tools.cpp index 705dc41..ee5cfc6 100644 --- a/tools/selection_tools.cpp +++ b/tools/selection_tools.cpp @@ -606,6 +606,36 @@ void SelectSubsetEdgesByDirection( maxDeviationAngle, selectFlipped); } +Edge* SelectEdgeByProjectedCoordinate( + Mesh* m, + const vector3& coord) +{ + Grid& grid = m->grid(); + Mesh::position_accessor_t& aaPos = m->position_accessor(); + + EdgeIterator iter = grid.begin(); + Edge* bestEdge = *iter; + number bestDist = DistancePointToLine(coord, aaPos[bestEdge->vertex(0)], aaPos[bestEdge->vertex(1)]); + iter++; + + while(iter != grid.end()) + { + number dist = DistancePointToLine(coord, aaPos[(*iter)->vertex(0)], aaPos[(*iter)->vertex(1)]); + if(dist < bestDist) + { + bestDist = dist; + bestEdge = *iter; + } + + ++iter; + } + + if(bestEdge) + m->selector().select(bestEdge); + + return bestEdge; +} + //////////////////////////////////////////////////////////////////////////////// // FACES void SelectBoundaryFaces(Mesh* obj) diff --git a/tools/selection_tools.h b/tools/selection_tools.h index b9f2230..e9d7f6f 100644 --- a/tools/selection_tools.h +++ b/tools/selection_tools.h @@ -92,6 +92,7 @@ #define TOOLTIP_SELECT_VOLUMES_BY_TYPE "Selects all volumes of a given type." #define TOOLTIP_SELECT_VERTEX_BY_COORDINATE "Selects a vertex given a coordinate." #define TOOLTIP_SELECT_EDGE_BY_COORDINATE "Selects the edge whose center is closest to the specified coordinate." +#define TOOLTIP_SELECT_EDGE_BY_PROJECTED_COORDINATE "Selects the edge for which the specified coordinate is closest to its perpendicular projection onto this edge." #define TOOLTIP_SELECT_FACE_BY_COORDINATE "Selects the face whose center is closest to the specified coordinate." #define TOOLTIP_SELECT_VOLUME_BY_COORDINATE "Selects the volume whose center is closest to the specified coordinate." #define TOOLTIP_SELECT_VERTEX_BY_CYL_COORDINATE "Selects a vertex given a cylindrical coordinate." @@ -334,6 +335,10 @@ void SelectSubsetEdgesByDirection( number maxDeviationAngle, bool selectFlipped); +Edge* SelectEdgeByProjectedCoordinate( + Mesh* m, + const vector3& coord); + void SelectBoundaryFaces(Mesh* obj); void SelectInnerFaces(Mesh* obj); From d7392ab9d7da8f19934a7b699e76b35b5342c303 Mon Sep 17 00:00:00 2001 From: Martin Stepniewski Date: Tue, 22 Dec 2020 10:33:01 +0100 Subject: [PATCH 2/3] Rendered naming more precisely. Added fail safe. --- register_selection_tools.cpp | 4 ++-- tools/selection_tools.cpp | 5 ++++- tools/selection_tools.h | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/register_selection_tools.cpp b/register_selection_tools.cpp index c18a508..39f9603 100644 --- a/register_selection_tools.cpp +++ b/register_selection_tools.cpp @@ -169,8 +169,8 @@ void RegisterSelectionTools(ProMeshRegistry& reg, string baseGrp) grp = baseGrp + "/Edges/Coordinate Based"; reg.add_function("SelectEdgeByCoordinate", &SelectElemByCoordinate, grp, "", "mesh # coordinate", TOOLTIP_SELECT_EDGE_BY_COORDINATE) - .add_function("SelectEdgeByProjectedCoordinate", &SelectEdgeByProjectedCoordinate, grp, "", - "mesh # coordinate", TOOLTIP_SELECT_EDGE_BY_PROJECTED_COORDINATE) + .add_function("SelectEdgeByMinPerpendicularDistance", &SelectEdgeByMinPerpendicularDistance, grp, "", + "mesh # coordinate", TOOLTIP_SELECT_EDGE_BY_MIN_PERPENDICULAR_DISTANCE) .add_function("SelectEdgeByCylindricalCoordinate", &SelectElemByCylindricalCoordinate, grp, "", "mesh # rho # phi # z", TOOLTIP_SELECT_EDGE_BY_CYL_COORDINATE) .add_function("SelectEdgesInBox", &SelectElementsInBox, grp, "", diff --git a/tools/selection_tools.cpp b/tools/selection_tools.cpp index ee5cfc6..db423d8 100644 --- a/tools/selection_tools.cpp +++ b/tools/selection_tools.cpp @@ -606,13 +606,16 @@ void SelectSubsetEdgesByDirection( maxDeviationAngle, selectFlipped); } -Edge* SelectEdgeByProjectedCoordinate( +Edge* SelectEdgeByMinPerpendicularDistance( Mesh* m, const vector3& coord) { Grid& grid = m->grid(); Mesh::position_accessor_t& aaPos = m->position_accessor(); + if(grid.begin() == grid.end()) + return NULL; + EdgeIterator iter = grid.begin(); Edge* bestEdge = *iter; number bestDist = DistancePointToLine(coord, aaPos[bestEdge->vertex(0)], aaPos[bestEdge->vertex(1)]); diff --git a/tools/selection_tools.h b/tools/selection_tools.h index e9d7f6f..dbb8e02 100644 --- a/tools/selection_tools.h +++ b/tools/selection_tools.h @@ -92,7 +92,7 @@ #define TOOLTIP_SELECT_VOLUMES_BY_TYPE "Selects all volumes of a given type." #define TOOLTIP_SELECT_VERTEX_BY_COORDINATE "Selects a vertex given a coordinate." #define TOOLTIP_SELECT_EDGE_BY_COORDINATE "Selects the edge whose center is closest to the specified coordinate." -#define TOOLTIP_SELECT_EDGE_BY_PROJECTED_COORDINATE "Selects the edge for which the specified coordinate is closest to its perpendicular projection onto this edge." +#define TOOLTIP_SELECT_EDGE_BY_MIN_PERPENDICULAR_DISTANCE "Selects the edge for which the specified coordinate is closest to its perpendicular projection onto this edge." #define TOOLTIP_SELECT_FACE_BY_COORDINATE "Selects the face whose center is closest to the specified coordinate." #define TOOLTIP_SELECT_VOLUME_BY_COORDINATE "Selects the volume whose center is closest to the specified coordinate." #define TOOLTIP_SELECT_VERTEX_BY_CYL_COORDINATE "Selects a vertex given a cylindrical coordinate." @@ -335,7 +335,7 @@ void SelectSubsetEdgesByDirection( number maxDeviationAngle, bool selectFlipped); -Edge* SelectEdgeByProjectedCoordinate( +Edge* SelectEdgeByMinPerpendicularDistance( Mesh* m, const vector3& coord); From 7a70c0ce50cc76ca8bca1935d5d6a72f8413ff2a Mon Sep 17 00:00:00 2001 From: Martin Stepniewski Date: Tue, 5 Jan 2021 16:40:02 +0100 Subject: [PATCH 3/3] Adressed comments in code review by renaming functionality to 'SelectClosestEdge' and streamlining the code according to the suggestions made. --- register_selection_tools.cpp | 4 ++-- tools/selection_tools.cpp | 22 +++++++--------------- tools/selection_tools.h | 4 ++-- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/register_selection_tools.cpp b/register_selection_tools.cpp index 39f9603..b5dbe2f 100644 --- a/register_selection_tools.cpp +++ b/register_selection_tools.cpp @@ -169,8 +169,8 @@ void RegisterSelectionTools(ProMeshRegistry& reg, string baseGrp) grp = baseGrp + "/Edges/Coordinate Based"; reg.add_function("SelectEdgeByCoordinate", &SelectElemByCoordinate, grp, "", "mesh # coordinate", TOOLTIP_SELECT_EDGE_BY_COORDINATE) - .add_function("SelectEdgeByMinPerpendicularDistance", &SelectEdgeByMinPerpendicularDistance, grp, "", - "mesh # coordinate", TOOLTIP_SELECT_EDGE_BY_MIN_PERPENDICULAR_DISTANCE) + .add_function("SelectClosestEdge", &SelectClosestEdge, grp, "", + "mesh # coordinate", TOOLTIP_SELECT_CLOSEST_EDGE) .add_function("SelectEdgeByCylindricalCoordinate", &SelectElemByCylindricalCoordinate, grp, "", "mesh # rho # phi # z", TOOLTIP_SELECT_EDGE_BY_CYL_COORDINATE) .add_function("SelectEdgesInBox", &SelectElementsInBox, grp, "", diff --git a/tools/selection_tools.cpp b/tools/selection_tools.cpp index db423d8..714a9ad 100644 --- a/tools/selection_tools.cpp +++ b/tools/selection_tools.cpp @@ -606,31 +606,23 @@ void SelectSubsetEdgesByDirection( maxDeviationAngle, selectFlipped); } -Edge* SelectEdgeByMinPerpendicularDistance( +Edge* SelectClosestEdge( Mesh* m, const vector3& coord) { Grid& grid = m->grid(); Mesh::position_accessor_t& aaPos = m->position_accessor(); - if(grid.begin() == grid.end()) - return NULL; + Edge* bestEdge = NULL; + number bestDist; - EdgeIterator iter = grid.begin(); - Edge* bestEdge = *iter; - number bestDist = DistancePointToLine(coord, aaPos[bestEdge->vertex(0)], aaPos[bestEdge->vertex(1)]); - iter++; + for(EdgeIterator eIter = grid.begin(); eIter != grid.end(); ++eIter){ + number dist = DistancePointToLine(coord, aaPos[(*eIter)->vertex(0)], aaPos[(*eIter)->vertex(1)]); - while(iter != grid.end()) - { - number dist = DistancePointToLine(coord, aaPos[(*iter)->vertex(0)], aaPos[(*iter)->vertex(1)]); - if(dist < bestDist) - { + if(bestEdge == NULL || dist < bestDist){ bestDist = dist; - bestEdge = *iter; + bestEdge = *eIter; } - - ++iter; } if(bestEdge) diff --git a/tools/selection_tools.h b/tools/selection_tools.h index dbb8e02..dfef239 100644 --- a/tools/selection_tools.h +++ b/tools/selection_tools.h @@ -92,7 +92,7 @@ #define TOOLTIP_SELECT_VOLUMES_BY_TYPE "Selects all volumes of a given type." #define TOOLTIP_SELECT_VERTEX_BY_COORDINATE "Selects a vertex given a coordinate." #define TOOLTIP_SELECT_EDGE_BY_COORDINATE "Selects the edge whose center is closest to the specified coordinate." -#define TOOLTIP_SELECT_EDGE_BY_MIN_PERPENDICULAR_DISTANCE "Selects the edge for which the specified coordinate is closest to its perpendicular projection onto this edge." +#define TOOLTIP_SELECT_CLOSEST_EDGE "Selects the edge closest to the specified coordinate with respect to its perpendicular distance (or distance to the closest edge vertex resp., if the projection lies outside of the line segment)." #define TOOLTIP_SELECT_FACE_BY_COORDINATE "Selects the face whose center is closest to the specified coordinate." #define TOOLTIP_SELECT_VOLUME_BY_COORDINATE "Selects the volume whose center is closest to the specified coordinate." #define TOOLTIP_SELECT_VERTEX_BY_CYL_COORDINATE "Selects a vertex given a cylindrical coordinate." @@ -335,7 +335,7 @@ void SelectSubsetEdgesByDirection( number maxDeviationAngle, bool selectFlipped); -Edge* SelectEdgeByMinPerpendicularDistance( +Edge* SelectClosestEdge( Mesh* m, const vector3& coord);