+ fix python documentation of BoundBox.getIntersectionPoint()

+ add new method BoundBox.isInside()


git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5004 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
wmayer 2011-10-11 10:27:07 +00:00
parent 5797b412df
commit 54a4c04ef5
3 changed files with 65 additions and 43 deletions

View File

@ -133,7 +133,7 @@ public:
* the base \a rcVct and the direction \a rcVctDir. \a rcVct must lie inside the
* bounding box.
*/
Vector3<_Precision> IntersectionPoint (const Vector3<_Precision> &rcVct, const Vector3<_Precision> &rcVctDir) const;
bool IntersectionPoint (const Vector3<_Precision> &rcVct, const Vector3<_Precision> &rcVctDir, Vector3<_Precision>& cVctRes, _Precision epsilon) const;
/** Checks for intersection with line incl. search tolerance. */
bool IsCutLine ( const Vector3<_Precision>& rcBase, const Vector3<_Precision>& rcDir, _Precision fTolerance = 0.0f) const;
/** Checks if this plane specified by (point,normal) cuts this box. */
@ -503,44 +503,32 @@ inline bool BoundBox3<_Precision>::CalcDistance (unsigned short usEdge, Vector3<
}
template <class _Precision>
inline Vector3<_Precision> BoundBox3<_Precision>::IntersectionPoint (const Vector3<_Precision> &rcVct, const Vector3<_Precision> &rcVctDir) const
inline bool BoundBox3<_Precision>::IntersectionPoint (const Vector3<_Precision> &rcVct, const Vector3<_Precision> &rcVctDir, Vector3<_Precision>& cVctRes, _Precision epsilon) const
{
BoundBox3<_Precision> cCmpBound(*this);
bool rc;
unsigned short i;
Vector3<_Precision> cVctRes;
bool rc=false;
BoundBox3<_Precision> cCmpBound(*this);
unsigned short i;
// Vergleichs-BB um REEN_EPS vergroessern
cCmpBound.MaxX += traits_type::epsilon();
cCmpBound.MaxY += traits_type::epsilon();
cCmpBound.MaxZ += traits_type::epsilon();
cCmpBound.MinX -= traits_type::epsilon();
cCmpBound.MinY -= traits_type::epsilon();
cCmpBound.MinZ -= traits_type::epsilon();
// enlarge bounding box by epsilon
cCmpBound.Enlarge(epsilon);
// Liegt Punkt innerhalb ?
if (cCmpBound.IsInBox (rcVct))
{
// Seitenebenen testen
for (i = 0, rc = false; (i < 6) && (!rc); i++)
{
rc = IntersectPlaneWithLine( i, rcVct, rcVctDir, cVctRes );
if(!cCmpBound.IsInBox(cVctRes))
rc = false;
if (rc == true )
{
// Liegt Schnittpunkt in gesuchter Richtung
// oder wurde gegenueberliegende Seite gefunden ?
// -> Skalarprodukt beider Richtungsvektoren > 0 (Winkel < 90)
rc = ((cVctRes - rcVct) * rcVctDir) > 0.0F;
}
// Is point inside?
if (cCmpBound.IsInBox (rcVct)) {
// test sides
for (i = 0; (i < 6) && (!rc); i++) {
rc = IntersectPlaneWithLine(i, rcVct, rcVctDir, cVctRes);
if (!cCmpBound.IsInBox(cVctRes))
rc = false;
if (rc == true) {
// does intersection point lie in desired direction
// or was found the opposing side?
// -> scalar product of both direction vectors > 0 (angle < 90)
rc = ((cVctRes - rcVct) * rcVctDir) >= (_Precision)0.0;
}
}
}
}
else
rc = false;
// Schnittpunkt zurueckgeben
return cVctRes;
return rc;
}
template <class _Precision>

View File

@ -53,8 +53,10 @@ A negative value shrinks the box.</UserDocu>
<Methode Name="getIntersectionPoint">
<Documentation>
<UserDocu>method Vector getIntersectionPoint(Vector Base, Vector Dir)
<UserDocu>method Vector getIntersectionPoint(Vector Base, Vector Dir, [float epsilon=0.0001])
Calculate the intersection point of a line with the BoundBox
The Base point must lie inside the bounding box, if not an
exception is thrown.
</UserDocu>
</Documentation>
</Methode>
@ -71,7 +73,15 @@ Move the BoundBox by the given vector
Check if the plane specified by Base and Normal intersects (cuts) the BoundBox</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Center" ReadOnly="true">
<Methode Name="isInside">
<Documentation>
<UserDocu>
method bool isInside(Vector Base|BoundBox box)
Check if the point or bounding box is inside this bounding box
</UserDocu>
</Documentation>
</Methode>
<Attribute Name="Center" ReadOnly="true">
<Documentation>
<UserDocu>Center point of the bounding box</UserDocu>
</Documentation>

View File

@ -183,16 +183,17 @@ PyObject* BoundBoxPy::enlarge(PyObject *args)
PyObject* BoundBoxPy::getIntersectionPoint(PyObject *args)
{
PyObject *object,*object2;
if (PyArg_ParseTuple(args,"O!O!:Need base and direction vector",
&(Base::VectorPy::Type), &object,&(Base::VectorPy::Type), &object2)) {
Base::Vector3d point = getBoundBoxPtr()->IntersectionPoint(
double epsilon=0.0001;
if (PyArg_ParseTuple(args,"O!O!|d:Need base and direction vector",
&(Base::VectorPy::Type), &object,&(Base::VectorPy::Type), &object2, &epsilon)) {
Base::Vector3d point;
bool ok = getBoundBoxPtr()->IntersectionPoint(
*(static_cast<Base::VectorPy*>(object)->getVectorPtr()),
*(static_cast<Base::VectorPy*>(object2)->getVectorPtr()));
*(static_cast<Base::VectorPy*>(object2)->getVectorPtr()),
point, epsilon);
// IsInBox() doesn't handle border points correctly
BoundBoxPy::PointerType bb = getBoundBoxPtr();
if ((bb->MinX <= point.x && bb->MaxX >= point.x) &&
(bb->MinY <= point.y && bb->MaxY >= point.y) &&
(bb->MinZ <= point.z && bb->MaxZ >= point.z)) {
if (ok) {
return new VectorPy(point);
}
else {
@ -249,6 +250,29 @@ PyObject* BoundBoxPy::isCutPlane(PyObject *args)
return Py::new_reference_to(retVal);
}
PyObject* BoundBoxPy::isInside(PyObject *args)
{
PyObject *object;
Py::Boolean retVal;
if (!PyArg_ParseTuple(args,"O", &object))
return 0;
if (PyObject_TypeCheck(object, &(Base::VectorPy::Type))) {
Base::VectorPy *vec = static_cast<Base::VectorPy*>(object);
retVal = getBoundBoxPtr()->IsInBox(*vec->getVectorPtr());
}
else if (PyObject_TypeCheck(object, &(Base::BoundBoxPy::Type))) {
Base::BoundBoxPy *box = static_cast<Base::BoundBoxPy*>(object);
retVal = getBoundBoxPtr()->IsInBox(*box->getBoundBoxPtr());
}
else {
PyErr_SetString(PyExc_TypeError, "Either a Vector or BoundBox object expected");
return 0;
}
return Py::new_reference_to(retVal);
}
Py::Object BoundBoxPy::getCenter(void) const
{
return Py::Vector(getBoundBoxPtr()->CalcCenter());