Make new method in Vector3 accesible from Python

This commit is contained in:
wmayer 2012-02-24 19:43:44 +01:00
parent d4899667bc
commit d102002bdf
6 changed files with 47 additions and 3 deletions

View File

@ -426,6 +426,17 @@ void InventorBuilder::endPoints(void)
result << Base::blanks(indent) << "]" << std::endl;
indent -= 2;
result << Base::blanks(indent) << "}" << std::endl;
}
/**
* Adds an SoPointSet node after creating an SoCordinate3 node with
* beginPoints() and endPoints().
* @see startPoints()
* @see beginPoints()
* @see endPoints()
*/
void InventorBuilder::addPointSet(void)
{
result << Base::blanks(indent) << "PointSet { } " << std::endl;
}

View File

@ -164,6 +164,8 @@ public:
void addPoint(const Vector3f &vec);
/// ends the points set operation
void endPoints(void);
/// add an SoPointSet node
void addPointSet(void);
//@}
/** @name Line/Direction handling */

View File

@ -194,7 +194,7 @@ Vector3<_Precision>& Vector3<_Precision>::ProjToPlane (const Vector3<_Precision>
const Vector3<_Precision> &rclNorm)
{
Vector3<_Precision> clTemp(rclNorm);
*this = *this - (clTemp *= ((*this - rclBase) * clTemp));
*this = *this - (clTemp *= ((*this - rclBase) * clTemp) / clTemp.Sqr());
return *this;
}
@ -202,7 +202,7 @@ template <class _Precision>
_Precision Vector3<_Precision>::DistanceToPlane (const Vector3<_Precision> &rclBase,
const Vector3<_Precision> &rclNorm) const
{
return (*this - rclBase) * rclNorm;
return ((*this - rclBase) * rclNorm) / rclNorm.Length();
}
template <class _Precision>
@ -361,7 +361,7 @@ template <class _Precision>
Vector3<_Precision> & Vector3<_Precision>::Normalize (void)
{
_Precision fLen = Length ();
if (fLen != 0.0f) {
if (fLen != (_Precision)0.0 && fLen != (_Precision)1.0) {
x /= fLen;
y /= fLen;
z /= fLen;

View File

@ -73,6 +73,11 @@
<UserDocu>Deliver the distance of the point to a given line</UserDocu>
</Documentation>
</Methode>
<Methode Name="distanceToLineSegment" Const="true">
<Documentation>
<UserDocu>Deliver the distance of the point to a given line segment</UserDocu>
</Documentation>
</Methode>
<Methode Name="distanceToPlane" Const="true">
<Documentation>
<UserDocu>Deliver the distance of the point to a given plane</UserDocu>

View File

@ -401,6 +401,31 @@ PyObject* VectorPy::distanceToLine(PyObject *args)
return Py::new_reference_to(dist);
}
PyObject* VectorPy::distanceToLineSegment(PyObject *args)
{
PyObject *base, *line;
if (!PyArg_ParseTuple(args, "OO",&base, &line))
return 0;
if (!PyObject_TypeCheck(base, &(VectorPy::Type))) {
PyErr_SetString(PyExc_TypeError, "First arg must be Vector");
return 0;
}
if (!PyObject_TypeCheck(line, &(VectorPy::Type))) {
PyErr_SetString(PyExc_TypeError, "Second arg must be Vector");
return 0;
}
VectorPy* base_vec = static_cast<VectorPy*>(base);
VectorPy* line_vec = static_cast<VectorPy*>(line);
VectorPy::PointerType this_ptr = reinterpret_cast<VectorPy::PointerType>(_pcTwinPointer);
VectorPy::PointerType base_ptr = reinterpret_cast<VectorPy::PointerType>(base_vec->_pcTwinPointer);
VectorPy::PointerType line_ptr = reinterpret_cast<VectorPy::PointerType>(line_vec->_pcTwinPointer);
Vector3d v = this_ptr->DistanceToLineSegment(*base_ptr, *line_ptr);
return new VectorPy(v);
}
PyObject* VectorPy::distanceToPlane(PyObject *args)
{
PyObject *base, *line;

View File

@ -120,6 +120,7 @@ PyObject* PointsPy::writeInventor(PyObject * args)
for (Points::PointKernel::const_iterator it = kernel->begin(); it != kernel->end(); ++it)
builder.addPoint((float)it->x,(float)it->y,(float)it->z);
builder.endPoints();
builder.addPointSet();
builder.close();
return Py::new_reference_to(Py::String(result.str()));