Make new method in Vector3 accesible from Python
This commit is contained in:
parent
d4899667bc
commit
d102002bdf
|
@ -426,6 +426,17 @@ void InventorBuilder::endPoints(void)
|
||||||
result << Base::blanks(indent) << "]" << std::endl;
|
result << Base::blanks(indent) << "]" << std::endl;
|
||||||
indent -= 2;
|
indent -= 2;
|
||||||
result << Base::blanks(indent) << "}" << std::endl;
|
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;
|
result << Base::blanks(indent) << "PointSet { } " << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,6 +164,8 @@ public:
|
||||||
void addPoint(const Vector3f &vec);
|
void addPoint(const Vector3f &vec);
|
||||||
/// ends the points set operation
|
/// ends the points set operation
|
||||||
void endPoints(void);
|
void endPoints(void);
|
||||||
|
/// add an SoPointSet node
|
||||||
|
void addPointSet(void);
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
/** @name Line/Direction handling */
|
/** @name Line/Direction handling */
|
||||||
|
|
|
@ -194,7 +194,7 @@ Vector3<_Precision>& Vector3<_Precision>::ProjToPlane (const Vector3<_Precision>
|
||||||
const Vector3<_Precision> &rclNorm)
|
const Vector3<_Precision> &rclNorm)
|
||||||
{
|
{
|
||||||
Vector3<_Precision> clTemp(rclNorm);
|
Vector3<_Precision> clTemp(rclNorm);
|
||||||
*this = *this - (clTemp *= ((*this - rclBase) * clTemp));
|
*this = *this - (clTemp *= ((*this - rclBase) * clTemp) / clTemp.Sqr());
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ template <class _Precision>
|
||||||
_Precision Vector3<_Precision>::DistanceToPlane (const Vector3<_Precision> &rclBase,
|
_Precision Vector3<_Precision>::DistanceToPlane (const Vector3<_Precision> &rclBase,
|
||||||
const Vector3<_Precision> &rclNorm) const
|
const Vector3<_Precision> &rclNorm) const
|
||||||
{
|
{
|
||||||
return (*this - rclBase) * rclNorm;
|
return ((*this - rclBase) * rclNorm) / rclNorm.Length();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class _Precision>
|
template <class _Precision>
|
||||||
|
@ -361,7 +361,7 @@ template <class _Precision>
|
||||||
Vector3<_Precision> & Vector3<_Precision>::Normalize (void)
|
Vector3<_Precision> & Vector3<_Precision>::Normalize (void)
|
||||||
{
|
{
|
||||||
_Precision fLen = Length ();
|
_Precision fLen = Length ();
|
||||||
if (fLen != 0.0f) {
|
if (fLen != (_Precision)0.0 && fLen != (_Precision)1.0) {
|
||||||
x /= fLen;
|
x /= fLen;
|
||||||
y /= fLen;
|
y /= fLen;
|
||||||
z /= fLen;
|
z /= fLen;
|
||||||
|
|
|
@ -73,6 +73,11 @@
|
||||||
<UserDocu>Deliver the distance of the point to a given line</UserDocu>
|
<UserDocu>Deliver the distance of the point to a given line</UserDocu>
|
||||||
</Documentation>
|
</Documentation>
|
||||||
</Methode>
|
</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">
|
<Methode Name="distanceToPlane" Const="true">
|
||||||
<Documentation>
|
<Documentation>
|
||||||
<UserDocu>Deliver the distance of the point to a given plane</UserDocu>
|
<UserDocu>Deliver the distance of the point to a given plane</UserDocu>
|
||||||
|
|
|
@ -401,6 +401,31 @@ PyObject* VectorPy::distanceToLine(PyObject *args)
|
||||||
return Py::new_reference_to(dist);
|
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* VectorPy::distanceToPlane(PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *base, *line;
|
PyObject *base, *line;
|
||||||
|
|
|
@ -120,6 +120,7 @@ PyObject* PointsPy::writeInventor(PyObject * args)
|
||||||
for (Points::PointKernel::const_iterator it = kernel->begin(); it != kernel->end(); ++it)
|
for (Points::PointKernel::const_iterator it = kernel->begin(); it != kernel->end(); ++it)
|
||||||
builder.addPoint((float)it->x,(float)it->y,(float)it->z);
|
builder.addPoint((float)it->x,(float)it->y,(float)it->z);
|
||||||
builder.endPoints();
|
builder.endPoints();
|
||||||
|
builder.addPointSet();
|
||||||
builder.close();
|
builder.close();
|
||||||
|
|
||||||
return Py::new_reference_to(Py::String(result.str()));
|
return Py::new_reference_to(Py::String(result.str()));
|
||||||
|
|
Loading…
Reference in New Issue
Block a user