Mesh: overload MeshAlgorithm::NearestFacetOnRay to set a max. angle between facet and ray
This commit is contained in:
@@ -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;
|
||||
@@ -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();
|
||||
|
||||
@@ -71,6 +71,17 @@ public:
|
||||
*/
|
||||
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).
|
||||
|
||||
@@ -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 {
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user