Skip to content

Commit

Permalink
Mesh: overload MeshAlgorithm::NearestFacetOnRay to set a max. angle b…
Browse files Browse the repository at this point in the history
…etween facet and ray
  • Loading branch information
wwmayer committed Feb 13, 2022
1 parent 2a79ce4 commit a6f0f69
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/Mod/Mesh/App/Core/Algorithm.cpp
Expand Up @@ -68,6 +68,12 @@ bool MeshAlgorithm::IsVertexVisible (const Base::Vector3f &rcVertex, const Base:

bool MeshAlgorithm::NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, Base::Vector3f &rclRes,
FacetIndex &rulFacet) const
{
return NearestFacetOnRay(rclPt, rclDir, Mathf::PI, rclRes, rulFacet);
}

bool MeshAlgorithm::NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, float fMaxAngle,
Base::Vector3f &rclRes, FacetIndex &rulFacet) const
{
Base::Vector3f clProj, clRes;
bool bSol = false;
Expand All @@ -76,13 +82,15 @@ bool MeshAlgorithm::NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::
// slow execution with no grid
MeshFacetIterator clFIter(_rclMesh);
for (clFIter.Init(); clFIter.More(); clFIter.Next()) {
if (clFIter->Foraminate( rclPt, rclDir, clRes ) == true) {
if (bSol == false) { // first solution
if (clFIter->Foraminate(rclPt, rclDir, clRes, fMaxAngle)) {
if (bSol == false) {
// first solution
bSol = true;
clProj = clRes;
ulInd = clFIter.Position();
}
else { // is closer to the point
else {
// is closer to the point
if ((clRes - rclPt).Length() < (clProj - rclPt).Length()) {
clProj = clRes;
ulInd = clFIter.Position();
Expand Down
11 changes: 11 additions & 0 deletions src/Mod/Mesh/App/Core/Algorithm.h
Expand Up @@ -71,6 +71,17 @@ class MeshExport MeshAlgorithm
*/
bool NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, Base::Vector3f &rclRes,
FacetIndex &rulFacet) const;
/**
* Searches for the nearest facet to the ray defined by
* (\a rclPt, \a rclDir).
* The point \a rclRes holds the intersection point with the ray and the
* nearest facet with index \a rulFacet. The angle between the ray and the normal of the triangle
* must be less than or equal to \a fMaxAngle.
* \note This method tests all facets so it should only be used
* occasionally.
*/
bool NearestFacetOnRay (const Base::Vector3f &rclPt, const Base::Vector3f &rclDir, float fMaxAngle, Base::Vector3f &rclRes,
FacetIndex &rulFacet) const;
/**
* Searches for the nearest facet to the ray defined by
* (\a rclPt, \a rclDir).
Expand Down
5 changes: 3 additions & 2 deletions src/Mod/Mesh/App/MeshPyImp.cpp
Expand Up @@ -1830,7 +1830,8 @@ PyObject* MeshPy::nearestFacetOnRay(PyObject *args)
{
PyObject* pnt_p;
PyObject* dir_p;
if (!PyArg_ParseTuple(args, "OO", &pnt_p, &dir_p))
double maxAngle = MeshCore::Mathd::PI;
if (!PyArg_ParseTuple(args, "OO|d", &pnt_p, &dir_p, &maxAngle))
return nullptr;

try {
Expand All @@ -1854,7 +1855,7 @@ PyObject* MeshPy::nearestFacetOnRay(PyObject *args)
if (alg.NearestFacetOnRay(pnt, dir, grid, res, index) ||
alg.NearestFacetOnRay(pnt, -dir, grid, res, index)) {
#else
if (alg.NearestFacetOnRay(pnt, dir, res, index)) {
if (alg.NearestFacetOnRay(pnt, dir, static_cast<float>(maxAngle), res, index)) {
#endif
Py::Tuple tuple(3);
tuple.setItem(0, Py::Float(res.x));
Expand Down

0 comments on commit a6f0f69

Please sign in to comment.