+ 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:
parent
5797b412df
commit
54a4c04ef5
|
@ -133,7 +133,7 @@ public:
|
||||||
* the base \a rcVct and the direction \a rcVctDir. \a rcVct must lie inside the
|
* the base \a rcVct and the direction \a rcVctDir. \a rcVct must lie inside the
|
||||||
* bounding box.
|
* 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. */
|
/** Checks for intersection with line incl. search tolerance. */
|
||||||
bool IsCutLine ( const Vector3<_Precision>& rcBase, const Vector3<_Precision>& rcDir, _Precision fTolerance = 0.0f) const;
|
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. */
|
/** 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>
|
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=false;
|
||||||
bool rc;
|
BoundBox3<_Precision> cCmpBound(*this);
|
||||||
unsigned short i;
|
unsigned short i;
|
||||||
Vector3<_Precision> cVctRes;
|
|
||||||
|
|
||||||
// Vergleichs-BB um REEN_EPS vergroessern
|
// enlarge bounding box by epsilon
|
||||||
cCmpBound.MaxX += traits_type::epsilon();
|
cCmpBound.Enlarge(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();
|
|
||||||
|
|
||||||
// Liegt Punkt innerhalb ?
|
// Is point inside?
|
||||||
if (cCmpBound.IsInBox (rcVct))
|
if (cCmpBound.IsInBox (rcVct)) {
|
||||||
{
|
// test sides
|
||||||
// Seitenebenen testen
|
for (i = 0; (i < 6) && (!rc); i++) {
|
||||||
for (i = 0, rc = false; (i < 6) && (!rc); i++)
|
rc = IntersectPlaneWithLine(i, rcVct, rcVctDir, cVctRes);
|
||||||
{
|
if (!cCmpBound.IsInBox(cVctRes))
|
||||||
rc = IntersectPlaneWithLine( i, rcVct, rcVctDir, cVctRes );
|
rc = false;
|
||||||
if(!cCmpBound.IsInBox(cVctRes))
|
if (rc == true) {
|
||||||
rc = false;
|
// does intersection point lie in desired direction
|
||||||
if (rc == true )
|
// or was found the opposing side?
|
||||||
{
|
// -> scalar product of both direction vectors > 0 (angle < 90)
|
||||||
// Liegt Schnittpunkt in gesuchter Richtung
|
rc = ((cVctRes - rcVct) * rcVctDir) >= (_Precision)0.0;
|
||||||
// oder wurde gegenueberliegende Seite gefunden ?
|
}
|
||||||
// -> Skalarprodukt beider Richtungsvektoren > 0 (Winkel < 90)
|
}
|
||||||
rc = ((cVctRes - rcVct) * rcVctDir) > 0.0F;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
rc = false;
|
|
||||||
|
|
||||||
// Schnittpunkt zurueckgeben
|
return rc;
|
||||||
return cVctRes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class _Precision>
|
template <class _Precision>
|
||||||
|
|
|
@ -53,8 +53,10 @@ A negative value shrinks the box.</UserDocu>
|
||||||
|
|
||||||
<Methode Name="getIntersectionPoint">
|
<Methode Name="getIntersectionPoint">
|
||||||
<Documentation>
|
<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
|
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>
|
</UserDocu>
|
||||||
</Documentation>
|
</Documentation>
|
||||||
</Methode>
|
</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>
|
Check if the plane specified by Base and Normal intersects (cuts) the BoundBox</UserDocu>
|
||||||
</Documentation>
|
</Documentation>
|
||||||
</Methode>
|
</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>
|
<Documentation>
|
||||||
<UserDocu>Center point of the bounding box</UserDocu>
|
<UserDocu>Center point of the bounding box</UserDocu>
|
||||||
</Documentation>
|
</Documentation>
|
||||||
|
|
|
@ -183,16 +183,17 @@ PyObject* BoundBoxPy::enlarge(PyObject *args)
|
||||||
PyObject* BoundBoxPy::getIntersectionPoint(PyObject *args)
|
PyObject* BoundBoxPy::getIntersectionPoint(PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *object,*object2;
|
PyObject *object,*object2;
|
||||||
if (PyArg_ParseTuple(args,"O!O!:Need base and direction vector",
|
double epsilon=0.0001;
|
||||||
&(Base::VectorPy::Type), &object,&(Base::VectorPy::Type), &object2)) {
|
if (PyArg_ParseTuple(args,"O!O!|d:Need base and direction vector",
|
||||||
Base::Vector3d point = getBoundBoxPtr()->IntersectionPoint(
|
&(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*>(object)->getVectorPtr()),
|
||||||
*(static_cast<Base::VectorPy*>(object2)->getVectorPtr()));
|
*(static_cast<Base::VectorPy*>(object2)->getVectorPtr()),
|
||||||
|
point, epsilon);
|
||||||
// IsInBox() doesn't handle border points correctly
|
// IsInBox() doesn't handle border points correctly
|
||||||
BoundBoxPy::PointerType bb = getBoundBoxPtr();
|
BoundBoxPy::PointerType bb = getBoundBoxPtr();
|
||||||
if ((bb->MinX <= point.x && bb->MaxX >= point.x) &&
|
if (ok) {
|
||||||
(bb->MinY <= point.y && bb->MaxY >= point.y) &&
|
|
||||||
(bb->MinZ <= point.z && bb->MaxZ >= point.z)) {
|
|
||||||
return new VectorPy(point);
|
return new VectorPy(point);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -249,6 +250,29 @@ PyObject* BoundBoxPy::isCutPlane(PyObject *args)
|
||||||
return Py::new_reference_to(retVal);
|
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
|
Py::Object BoundBoxPy::getCenter(void) const
|
||||||
{
|
{
|
||||||
return Py::Vector(getBoundBoxPtr()->CalcCenter());
|
return Py::Vector(getBoundBoxPtr()->CalcCenter());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user