diff --git a/register_selection_tools.cpp b/register_selection_tools.cpp index a998f28..b5dbe2f 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("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 705dc41..714a9ad 100644 --- a/tools/selection_tools.cpp +++ b/tools/selection_tools.cpp @@ -606,6 +606,31 @@ void SelectSubsetEdgesByDirection( maxDeviationAngle, selectFlipped); } +Edge* SelectClosestEdge( + Mesh* m, + const vector3& coord) +{ + Grid& grid = m->grid(); + Mesh::position_accessor_t& aaPos = m->position_accessor(); + + Edge* bestEdge = NULL; + number bestDist; + + for(EdgeIterator eIter = grid.begin(); eIter != grid.end(); ++eIter){ + number dist = DistancePointToLine(coord, aaPos[(*eIter)->vertex(0)], aaPos[(*eIter)->vertex(1)]); + + if(bestEdge == NULL || dist < bestDist){ + bestDist = dist; + bestEdge = *eIter; + } + } + + 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..dfef239 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_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." @@ -334,6 +335,10 @@ void SelectSubsetEdgesByDirection( number maxDeviationAngle, bool selectFlipped); +Edge* SelectClosestEdge( + Mesh* m, + const vector3& coord); + void SelectBoundaryFaces(Mesh* obj); void SelectInnerFaces(Mesh* obj);