+ rework BoundingBox class and its Python binding

This commit is contained in:
wmayer 2015-10-11 00:18:53 +02:00
parent 716130c39e
commit a4d1dbe5f0
39 changed files with 1167 additions and 842 deletions

View File

@ -47,6 +47,7 @@
#ifdef FC_OS_WIN32
#include <direct.h>
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <crtdbg.h>
#endif

File diff suppressed because it is too large Load Diff

View File

@ -27,22 +27,68 @@ App.BoundBox(Vector, Vector)
App.BoundBox(BoundBox)
</UserDocu>
</Documentation>
<Methode Name="setVoid">
<Documentation>
<UserDocu>method setVoid()
Invalidate the bounding box</UserDocu>
</Documentation>
</Methode>
<Methode Name="isValid">
<Documentation>
<UserDocu>method isValid()
Checks if the bounding box is valid</UserDocu>
</Documentation>
</Methode>
<Methode Name="add">
<Documentation>
<UserDocu>method add(BoundBox)
Add (enlarge) the given BoundBox</UserDocu>
</Documentation>
</Methode>
<Methode Name="isIntersection">
<Methode Name="getPoint">
<Documentation>
<UserDocu>method isIntersection(Vector|BoundBox|Vector Base, Vector Dir)
<UserDocu>method getPoint(Int)
Get the point of the given index. The index must be in the range of [0,7]
</UserDocu>
</Documentation>
</Methode>
<Methode Name="getEdge">
<Documentation>
<UserDocu>method getEdge(Int)
Get the edge points of the given index. The index must be in the range of [0,11]
</UserDocu>
</Documentation>
</Methode>
<Methode Name="closestPoint">
<Documentation>
<UserDocu>method closestPoint(Vector)
Get the closest point of the bounding box to the given point
</UserDocu>
</Documentation>
</Methode>
<Methode Name="intersect">
<Documentation>
<UserDocu>method intersect(BoundBox|Vector Base, Vector Dir)
Checks if the given object intersects with the BoundBox. That can be:
- A Vector (Point)
- Another BoundBox
- A line, specified by Base and Dir
</UserDocu>
</Documentation>
</Methode>
<Methode Name="intersected">
<Documentation>
<UserDocu>method intersected(BoundBox)
Returns the intersection of this and the given bounding box.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="united">
<Documentation>
<UserDocu>method united(BoundBox)
Returns the union of this and the given bounding box.
</UserDocu>
</Documentation>
</Methode>
<Methode Name="enlarge">
<Documentation>
<UserDocu>method enlarge(Float)
@ -62,11 +108,25 @@ exception is thrown.
</Methode>
<Methode Name="move">
<Documentation>
<UserDocu> method getIntersectionPoint(Vector)
<UserDocu> method move(Vector)
Move the BoundBox by the given vector
</UserDocu>
</Documentation>
</Methode>
<Methode Name="scale">
<Documentation>
<UserDocu> method scale(x,y,z)
Scale the BoundBox by the given values in x, y and z
</UserDocu>
</Documentation>
</Methode>
<Methode Name="transformed">
<Documentation>
<UserDocu> method transformed(Matrix)
Return a new bounding box with the transformed corner of this bounding box
</UserDocu>
</Documentation>
</Methode>
<Methode Name="isCutPlane">
<Documentation>
<UserDocu>method bool isCutPlane(Vector Base, Vector Normal)

View File

@ -26,6 +26,7 @@
#include "Base/BoundBox.h"
// inclusion of the generated files (generated out of BoundBoxPy.xml)
#include "MatrixPy.h"
#include "VectorPy.h"
#include "GeometryPyCXX.h"
#include "BoundBoxPy.h"
@ -104,6 +105,23 @@ int BoundBoxPy::PyInit(PyObject* args, PyObject* /*kwd*/)
return -1;
}
PyObject* BoundBoxPy::setVoid(PyObject *args)
{
if (!PyArg_ParseTuple(args,""))
return 0;
getBoundBoxPtr()->SetVoid();
Py_Return;
}
PyObject* BoundBoxPy::isValid(PyObject *args)
{
if (!PyArg_ParseTuple(args,""))
return 0;
return PyBool_FromLong(getBoundBoxPtr()->IsValid() ? 1 : 0);
}
PyObject* BoundBoxPy::add(PyObject *args)
{
double x,y,z;
@ -135,42 +153,150 @@ PyObject* BoundBoxPy::add(PyObject *args)
return 0;
}
PyObject* BoundBoxPy::isIntersection(PyObject *args)
PyObject* BoundBoxPy::getPoint(PyObject *args)
{
double x,y,z;
PyObject *object,*object2;
Py::Boolean retVal;
if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) {
retVal = getBoundBoxPtr()->IsInBox(Vector3d(x,y,z));
}
else if (PyArg_ParseTuple(args,"O!",&PyTuple_Type, &object)) {
PyErr_Clear();
retVal = getBoundBoxPtr()->IsInBox(getVectorFromTuple<double>(object));
}
else if (PyArg_ParseTuple(args,"O!",&(Base::VectorPy::Type), &object)) {
PyErr_Clear();
retVal = getBoundBoxPtr()->IsInBox(*(static_cast<Base::VectorPy*>(object)->getVectorPtr()));
}
else if (PyArg_ParseTuple(args,"O!O!",&(Base::VectorPy::Type), &object,
&(Base::VectorPy::Type), &object2)) {
PyErr_Clear();
retVal = getBoundBoxPtr()->IsCutLine(
*(static_cast<Base::VectorPy*>(object )->getVectorPtr()),
*(static_cast<Base::VectorPy*>(object2)->getVectorPtr()));
}
else if (PyArg_ParseTuple(args,"O!;Need vector, bounding box or three floats as argument",
&(Base::BoundBoxPy::Type), &object)) {
PyErr_Clear();
retVal = getBoundBoxPtr()->IsInBox(*(static_cast<Base::BoundBoxPy*>(object)->getBoundBoxPtr()));
}
else {
PyErr_SetString(PyExc_TypeError, "Either three floats, Vector(s) or BoundBox expected");
int index;
if (!PyArg_ParseTuple(args,"i",&index))
return 0;
if (index < 0 || index > 7) {
PyErr_SetString (PyExc_IndexError, "Invalid bounding box");
return 0;
}
Base::Vector3d pnt = getBoundBoxPtr()->CalcPoint(index);
return new Base::VectorPy(new Base::Vector3d(pnt));
}
PyObject* BoundBoxPy::getEdge(PyObject *args)
{
int index;
if (!PyArg_ParseTuple(args,"i",&index))
return 0;
if (index < 0 || index > 11) {
PyErr_SetString (PyExc_IndexError, "Invalid bounding box");
return 0;
}
Base::Vector3d pnt1, pnt2;
getBoundBoxPtr()->CalcEdge(index, pnt1, pnt2);
Py::Tuple tuple(2);
tuple.setItem(0, Py::Vector(pnt1));
tuple.setItem(1, Py::Vector(pnt2));
return Py::new_reference_to(tuple);
}
PyObject* BoundBoxPy::closestPoint(PyObject *args)
{
double x,y,z;
PyObject *object;
Base::Vector3d vec;
do {
if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) {
vec = Vector3d(x,y,z);
break;
}
PyErr_Clear();
if (PyArg_ParseTuple(args,"O!",&PyTuple_Type, &object)) {
vec = getVectorFromTuple<double>(object);
break;
}
PyErr_Clear();
if (PyArg_ParseTuple(args,"O!",&(Base::VectorPy::Type), &object)) {
vec = *(static_cast<Base::VectorPy*>(object)->getVectorPtr());
break;
}
else {
PyErr_SetString(PyExc_TypeError, "Either three floats or vector expected");
return 0;
}
}
while(false);
Base::Vector3d point = getBoundBoxPtr()->ClosestPoint(vec);
return new Base::VectorPy(new Base::Vector3d(point));
}
PyObject* BoundBoxPy::intersect(PyObject *args)
{
PyObject *object,*object2;
Py::Boolean retVal;
if (!getBoundBoxPtr()->IsValid()) {
PyErr_SetString (PyExc_FloatingPointError, "Invalid bounding box");
return 0;
}
do {
if (PyArg_ParseTuple(args,"O!O!",&(Base::VectorPy::Type), &object,
&(Base::VectorPy::Type), &object2)) {
retVal = getBoundBoxPtr()->IsCutLine(
*(static_cast<Base::VectorPy*>(object )->getVectorPtr()),
*(static_cast<Base::VectorPy*>(object2)->getVectorPtr()));
break;
}
PyErr_Clear();
if (PyArg_ParseTuple(args,"O!",&(Base::BoundBoxPy::Type), &object)) {
if (!static_cast<Base::BoundBoxPy*>(object)->getBoundBoxPtr()->IsValid()) {
PyErr_SetString (PyExc_FloatingPointError, "Invalid bounding box argument");
return 0;
}
retVal = getBoundBoxPtr()->Intersect(*(static_cast<Base::BoundBoxPy*>(object)->getBoundBoxPtr()));
break;
}
PyErr_SetString(PyExc_TypeError, "Either BoundBox or two Vectors expected");
return 0;
}
while(false);
return Py::new_reference_to(retVal);
}
PyObject* BoundBoxPy::intersected(PyObject *args)
{
if (!getBoundBoxPtr()->IsValid()) {
PyErr_SetString (PyExc_FloatingPointError, "Invalid bounding box");
return 0;
}
PyObject *object;
if (!PyArg_ParseTuple(args,"O!",&(Base::BoundBoxPy::Type), &object))
return 0;
if (!static_cast<Base::BoundBoxPy*>(object)->getBoundBoxPtr()->IsValid()) {
PyErr_SetString (PyExc_FloatingPointError, "Invalid bounding box argument");
return 0;
}
Base::BoundBox3d bbox = getBoundBoxPtr()->Intersected(*static_cast<Base::BoundBoxPy*>(object)->getBoundBoxPtr());
return new Base::BoundBoxPy(new Base::BoundBox3d(bbox));
}
PyObject* BoundBoxPy::united(PyObject *args)
{
if (!getBoundBoxPtr()->IsValid()) {
PyErr_SetString (PyExc_FloatingPointError, "Invalid bounding box");
return 0;
}
PyObject *object;
if (!PyArg_ParseTuple(args,"O!",&(Base::BoundBoxPy::Type), &object))
return 0;
if (!static_cast<Base::BoundBoxPy*>(object)->getBoundBoxPtr()->IsValid()) {
PyErr_SetString (PyExc_FloatingPointError, "Invalid bounding box argument");
return 0;
}
Base::BoundBox3d bbox = getBoundBoxPtr()->United(*static_cast<Base::BoundBoxPy*>(object)->getBoundBoxPtr());
return new Base::BoundBoxPy(new Base::BoundBox3d(bbox));
}
PyObject* BoundBoxPy::enlarge(PyObject *args)
{
double s;
@ -191,7 +317,6 @@ PyObject* BoundBoxPy::getIntersectionPoint(PyObject *args)
*(static_cast<Base::VectorPy*>(object)->getVectorPtr()),
*(static_cast<Base::VectorPy*>(object2)->getVectorPtr()),
point, epsilon);
// IsInBox() doesn't handle border points correctly
if (ok) {
return new VectorPy(point);
}
@ -206,26 +331,34 @@ PyObject* BoundBoxPy::getIntersectionPoint(PyObject *args)
PyObject* BoundBoxPy::move(PyObject *args)
{
double x,y,z;
double x,y,z;
PyObject *object;
Base::Vector3d vec;
if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) {
vec = Vector3d(x,y,z);
}
else if (PyArg_ParseTuple(args,"O!:Need vector to move",&PyTuple_Type, &object)) {
do {
if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) {
vec = Vector3d(x,y,z);
break;
}
PyErr_Clear();
vec = getVectorFromTuple<double>(object);
}
else if (PyArg_ParseTuple(args,"O!:Need vector to move",&(Base::VectorPy::Type), &object)) {
if (PyArg_ParseTuple(args,"O!:Need vector to move",&PyTuple_Type, &object)) {
vec = getVectorFromTuple<double>(object);
break;
}
PyErr_Clear();
vec = *(static_cast<Base::VectorPy*>(object)->getVectorPtr());
}
else {
PyErr_SetString(PyExc_TypeError, "Either three floats or vector expected");
return 0;
if (PyArg_ParseTuple(args,"O!:Need vector to move",&(Base::VectorPy::Type), &object)) {
vec = *(static_cast<Base::VectorPy*>(object)->getVectorPtr());
break;
}
else {
PyErr_SetString(PyExc_TypeError, "Either three floats or vector expected");
return 0;
}
}
while(false);
getBoundBoxPtr()->MoveX(vec.x);
getBoundBoxPtr()->MoveY(vec.y);
@ -234,11 +367,67 @@ PyObject* BoundBoxPy::move(PyObject *args)
Py_Return;
}
PyObject* BoundBoxPy::scale(PyObject *args)
{
double x,y,z;
PyObject *object;
Base::Vector3d vec;
do {
if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) {
vec = Vector3d(x,y,z);
break;
}
PyErr_Clear();
if (PyArg_ParseTuple(args,"O!:Need vector to scale",&PyTuple_Type, &object)) {
vec = getVectorFromTuple<double>(object);
break;
}
PyErr_Clear();
if (PyArg_ParseTuple(args,"O!:Need vector to scale",&(Base::VectorPy::Type), &object)) {
vec = *(static_cast<Base::VectorPy*>(object)->getVectorPtr());
break;
}
else {
PyErr_SetString(PyExc_TypeError, "Either three floats or vector expected");
return 0;
}
}
while(false);
getBoundBoxPtr()->ScaleX(vec.x);
getBoundBoxPtr()->ScaleY(vec.y);
getBoundBoxPtr()->ScaleZ(vec.z);
Py_Return;
}
PyObject* BoundBoxPy::transformed(PyObject *args)
{
PyObject *mat;
if (!PyArg_ParseTuple(args,"O!", &(Base::MatrixPy::Type), &mat))
return 0;
if (!getBoundBoxPtr()->IsValid())
throw Py::FloatingPointError("Cannot transform invalid bounding box");
Base::BoundBox3d bbox = getBoundBoxPtr()->Transformed(*static_cast<Base::MatrixPy*>(mat)->getMatrixPtr());
return new Base::BoundBoxPy(new Base::BoundBox3d(bbox));
}
PyObject* BoundBoxPy::isCutPlane(PyObject *args)
{
PyObject *object,*object2;
Py::Boolean retVal;
if (!getBoundBoxPtr()->IsValid()) {
PyErr_SetString (PyExc_FloatingPointError, "Invalid bounding box");
return 0;
}
if (PyArg_ParseTuple(args,"O!O!:Need base and normal vector of a plane",
&(Base::VectorPy::Type), &object,&(Base::VectorPy::Type), &object2))
retVal = getBoundBoxPtr()->IsCutPlane(
@ -252,30 +441,54 @@ PyObject* BoundBoxPy::isCutPlane(PyObject *args)
PyObject* BoundBoxPy::isInside(PyObject *args)
{
double x,y,z;
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");
if (!getBoundBoxPtr()->IsValid()) {
PyErr_SetString (PyExc_FloatingPointError, "Invalid bounding box");
return 0;
}
do {
if (PyArg_ParseTuple(args, "ddd", &x,&y,&z)) {
retVal = getBoundBoxPtr()->IsInBox(Vector3d(x,y,z));
break;
}
PyErr_Clear();
if (PyArg_ParseTuple(args,"O!",&PyTuple_Type, &object)) {
retVal = getBoundBoxPtr()->IsInBox(getVectorFromTuple<double>(object));
break;
}
PyErr_Clear();
if (PyArg_ParseTuple(args,"O!",&(Base::VectorPy::Type), &object)) {
retVal = getBoundBoxPtr()->IsInBox(*(static_cast<Base::VectorPy*>(object)->getVectorPtr()));
break;
}
PyErr_Clear();
if (PyArg_ParseTuple(args,"O!",&(Base::BoundBoxPy::Type), &object)) {
if (!static_cast<Base::BoundBoxPy*>(object)->getBoundBoxPtr()->IsValid()) {
PyErr_SetString (PyExc_FloatingPointError, "Invalid bounding box argument");
return 0;
}
retVal = getBoundBoxPtr()->IsInBox(*(static_cast<Base::BoundBoxPy*>(object)->getBoundBoxPtr()));
break;
}
PyErr_SetString(PyExc_TypeError, "Either three floats, Vector(s) or BoundBox expected");
return 0;
}
while(false);
return Py::new_reference_to(retVal);
}
Py::Object BoundBoxPy::getCenter(void) const
{
return Py::Vector(getBoundBoxPtr()->CalcCenter());
return Py::Vector(getBoundBoxPtr()->GetCenter());
}
Py::Float BoundBoxPy::getXMax(void) const
@ -355,6 +568,8 @@ Py::Float BoundBoxPy::getZLength(void) const
Py::Float BoundBoxPy::getDiagonalLength(void) const
{
if (!getBoundBoxPtr()->IsValid())
throw Py::FloatingPointError("Cannot deterine diagonal length of invalid bounding box");
return Py::Float(getBoundBoxPtr()->CalcDiagonalLength());
}

View File

@ -46,6 +46,7 @@
#ifdef FC_OS_WIN32
#include <direct.h>
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <crtdbg.h>
#include <shellapi.h>

View File

@ -92,7 +92,7 @@ public:
bool operator|| (const Line2D &rclLine) const;
bool operator|| (const BoundBox2D &rclBB) const;
bool operator|| (const Polygon2D &rclPoly) const;
inline void operator &= (const Vector2D &rclVct);
inline void Add(const Vector2D &rclVct);
void SetVoid (void) { fMinX = fMinY = DOUBLE_MAX; fMaxX = fMaxY = -DOUBLE_MAX; }
@ -164,14 +164,6 @@ private:
/** INLINES ********************************************/
inline void BoundBox2D::operator &= (const Vector2D &rclVct)
{
fMinX = std::min<double>(fMinX, rclVct.fX);
fMinY = std::min<double>(fMinY, rclVct.fY);
fMaxX = std::max<double>(fMaxX, rclVct.fX);
fMaxY = std::max<double>(fMaxY, rclVct.fY);
}
inline Vector2D::Vector2D (void)
: fX(0.0), fY(0.0)
{
@ -380,6 +372,14 @@ inline bool BoundBox2D::operator== (const BoundBox2D& rclBB) const
(fMaxY == rclBB.fMaxY);
}
inline void BoundBox2D::Add(const Vector2D &rclVct)
{
fMinX = std::min<double>(fMinX, rclVct.fX);
fMinY = std::min<double>(fMinY, rclVct.fY);
fMaxX = std::max<double>(fMaxX, rclVct.fX);
fMaxY = std::max<double>(fMaxY, rclVct.fY);
}
} // namespace Base
#endif // BASE_TOOLS2D_H

View File

@ -2182,7 +2182,7 @@ static void selectionCallback(void * ud, SoEventCallback * cb)
App::PropertyGeometry* prop = static_cast<App::PropertyGeometry*>(*jt);
Base::BoundBox3d bbox = prop->getBoundingBox();
Base::Vector3d pt2d;
pt2d = proj(bbox.CalcCenter());
pt2d = proj(bbox.GetCenter());
if (polygon.Contains(Base::Vector2D(pt2d.x, pt2d.y))) {
Gui::Selection().addSelection(doc->getName(), (*it)->getNameInDocument());
}

View File

@ -25,6 +25,7 @@
#define GUI_GLPAINTER_H
#ifdef FC_OS_WIN32
#define NOMINMAX
#include <windows.h>
#endif
#ifdef FC_OS_MACOSX

View File

@ -27,6 +27,7 @@
# include <OpenGL/gl.h>
# else
# ifdef FC_OS_WIN32
# define NOMINMAX
# include <windows.h>
# endif
# include <GL/gl.h>

View File

@ -27,6 +27,7 @@
# include <OpenGL/gl.h>
# else
# ifdef FC_OS_WIN32
# define NOMINMAX
# include <windows.h>
# endif
# include <GL/gl.h>

View File

@ -4624,7 +4624,7 @@ class _Shape2DView(_DraftObject):
if cutv:
if sh.Volume < 0:
sh.reverse()
#if cutv.BoundBox.isIntersection(sh.BoundBox):
#if cutv.BoundBox.intersect(sh.BoundBox):
# c = sh.cut(cutv)
#else:
# c = sh.copy()

View File

@ -284,7 +284,7 @@ def findIntersection(edge1,edge2,infinite1=False,infinite2=False,ex1=False,ex2=F
# First, try to use distToShape if possible
if dts and isinstance(edge1,Part.Edge) and isinstance(edge2,Part.Edge) \
and (not infinite1) and (not infinite2) and \
edge1.BoundBox.isIntersection(edge2.BoundBox):
edge1.BoundBox.intersect(edge2.BoundBox):
dist, pts, geom = edge1.distToShape(edge2)
sol = []
for p in pts:

View File

@ -142,9 +142,9 @@ orthoview::orthoview(App::Document * parent, App::DocumentObject * part, App::Do
parent_doc = parent;
myname = parent_doc->getUniqueObjectName("Ortho");
cx = partbox->CalcCenter().x;
cy = partbox->CalcCenter().y;
cz = partbox->CalcCenter().z;
cx = partbox->GetCenter().x;
cy = partbox->GetCenter().y;
cz = partbox->GetCenter().z;
this_view = static_cast<Drawing::FeatureViewPart *> (parent_doc->addObject("Drawing::FeatureViewPart", myname.c_str()));
static_cast<App::DocumentObjectGroup *>(page)->addObject(this_view);

View File

@ -24,9 +24,6 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# ifdef FC_OS_WIN32
# include <windows.h>
# endif
# include <QAction>
# include <QMenu>
# include <QTimer>

View File

@ -24,9 +24,6 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# ifdef FC_OS_WIN32
# include <windows.h>
# endif
#endif
/// Here the FreeCAD includes sorted by Base,App,Gui......

View File

@ -182,9 +182,9 @@ namespace Inspection {
unsigned long ulX1, ulY1, ulZ1, ulX2, ulY2, ulZ2;
Base::BoundBox3f clBB;
clBB &= rclFacet._aclPoints[0];
clBB &= rclFacet._aclPoints[1];
clBB &= rclFacet._aclPoints[2];
clBB.Add(rclFacet._aclPoints[0]);
clBB.Add(rclFacet._aclPoints[1]);
clBB.Add(rclFacet._aclPoints[2]);
Pos(Base::Vector3f(clBB.MinX,clBB.MinY,clBB.MinZ), ulX1, ulY1, ulZ1);
Pos(Base::Vector3f(clBB.MaxX,clBB.MaxY,clBB.MaxZ), ulX2, ulY2, ulZ2);

View File

@ -39,6 +39,10 @@
# define InspectionGuiExport
#endif
#ifdef FC_OS_WIN32
# define NOMINMAX
#endif
#ifdef _PreComp_
// standard

View File

@ -1237,7 +1237,7 @@ void MeshAlgorithm::SearchFacetsFromPolyline (const std::vector<Base::Vector3f>
// BB eines Polyline-Segments
BoundBox3f clSegmBB(rclP0.x, rclP0.y, rclP0.z, rclP0.x, rclP0.y, rclP0.z);
clSegmBB &= rclP1;
clSegmBB.Add(rclP1);
clSegmBB.Enlarge(fRadius); // BB um Suchradius vergroessern
std::vector<unsigned long> aclBBFacets;
@ -1663,9 +1663,9 @@ bool MeshAlgorithm::Distance (const Base::Vector3f &rclPt, unsigned long ulFacet
const unsigned long *pulIdx = rclFAry[ulFacetIdx]._aulPoints;
BoundBox3f clBB;
clBB &= rclPAry[*(pulIdx++)];
clBB &= rclPAry[*(pulIdx++)];
clBB &= rclPAry[*pulIdx];
clBB.Add(rclPAry[*(pulIdx++)]);
clBB.Add(rclPAry[*(pulIdx++)]);
clBB.Add(rclPAry[*pulIdx]);
clBB.Enlarge(fMaxDistance);
if (clBB.IsInBox(rclPt) == false)

View File

@ -204,7 +204,7 @@ bool MeshGeomEdge::IntersectBoundingBox (const Base::BoundBox3f &rclBB) const
Segment3<float> akSeg(p, n, 0.5f*len);
Base::Vector3f clCenter = rclBB.CalcCenter();
Base::Vector3f clCenter = rclBB.GetCenter();
Vector3<float> center(clCenter.x, clCenter.y, clCenter.z);
Vector3<float> axis0(1.0f, 0.0f, 0.0f);
Vector3<float> axis1(0.0f, 1.0f, 0.0f);
@ -473,7 +473,7 @@ bool MeshGeomFacet::IntersectBoundingBox ( const Base::BoundBox3f &rclBB ) const
Segment3<float> akSeg2(p2, d2, len2/2.0f);
// Build up the box
Base::Vector3f clCenter = rclBB.CalcCenter();
Base::Vector3f clCenter = rclBB.GetCenter();
Vector3<float> center(clCenter.x, clCenter.y, clCenter.z);
Vector3<float> axis0(1.0f, 0.0f, 0.0f);
Vector3<float> axis1(0.0f, 1.0f, 0.0f);

View File

@ -189,7 +189,7 @@ unsigned long MeshGrid::Inside (const Base::BoundBox3f &rclBB, std::vector<unsig
{
for (k = ulMinZ; k <= ulMaxZ; k++)
{
if (Base::DistanceP2(GetBoundBox(i, j, k).CalcCenter(), rclOrg) < fMinDistP2)
if (Base::DistanceP2(GetBoundBox(i, j, k).GetCenter(), rclOrg) < fMinDistP2)
raulElements.insert(raulElements.end(), _aulGrid[i][j][k].begin(), _aulGrid[i][j][k].end());
}
}
@ -440,7 +440,7 @@ void MeshGrid::SearchNearestFromPoint (const Base::Vector3f &rclPt, std::set<uns
}
else
{ // Punkt ausserhalb
Base::BoundBox3f::SIDE tSide = clBB.GetSideFromRay(rclPt, clBB.CalcCenter() - rclPt);
Base::BoundBox3f::SIDE tSide = clBB.GetSideFromRay(rclPt, clBB.GetCenter() - rclPt);
switch (tSide)
{
case Base::BoundBox3f::RIGHT:
@ -742,7 +742,7 @@ unsigned long MeshFacetGrid::SearchNearestFromPoint (const Base::Vector3f &rclPt
}
else
{ // Punkt ausserhalb
Base::BoundBox3f::SIDE tSide = clBB.GetSideFromRay(rclPt, clBB.CalcCenter() - rclPt);
Base::BoundBox3f::SIDE tSide = clBB.GetSideFromRay(rclPt, clBB.GetCenter() - rclPt);
switch (tSide)
{
case Base::BoundBox3f::RIGHT:

View File

@ -472,9 +472,9 @@ inline void MeshFacetGrid::AddFacet (const MeshGeomFacet &rclFacet, unsigned lon
Base::BoundBox3f clBB;
clBB &= rclFacet._aclPoints[0];
clBB &= rclFacet._aclPoints[1];
clBB &= rclFacet._aclPoints[2];
clBB.Add(rclFacet._aclPoints[0]);
clBB.Add(rclFacet._aclPoints[1]);
clBB.Add(rclFacet._aclPoints[2]);
//float fDiagonalLength = clBB.CalcDiagonalLength();

View File

@ -49,7 +49,7 @@ using namespace MeshCore;
MeshKernel::MeshKernel (void)
: _bValid(true)
{
_clBoundBox.Flush();
_clBoundBox.SetVoid();
}
MeshKernel::MeshKernel (const MeshKernel &rclMesh)
@ -119,7 +119,7 @@ void MeshKernel::AddFacet(const MeshGeomFacet &rclSFacet)
// set corner points
for (i = 0; i < 3; i++) {
_clBoundBox &= rclSFacet._aclPoints[i];
_clBoundBox.Add(rclSFacet._aclPoints[i]);
clFacet._aulPoints[i] = _aclPointArray.GetOrAddIndex(rclSFacet._aclPoints[i]);
}
@ -318,7 +318,7 @@ unsigned long MeshKernel::AddFacets(const std::vector<MeshFacet> &rclFAry)
unsigned long MeshKernel::AddFacets(const std::vector<MeshFacet> &rclFAry, const std::vector<Base::Vector3f>& rclPAry)
{
for (std::vector<Base::Vector3f>::const_iterator it = rclPAry.begin(); it != rclPAry.end(); ++it)
_clBoundBox &= *it;
_clBoundBox.Add(*it);
this->_aclPointArray.insert(this->_aclPointArray.end(), rclPAry.begin(), rclPAry.end());
return this->AddFacets(rclFAry);
}
@ -367,7 +367,7 @@ void MeshKernel::Merge(const MeshPointArray& rPoints, const MeshFacetArray& rFac
*it = index++;
const MeshPoint& rPt = rPoints[it-increments.begin()];
this->_aclPointArray.push_back(rPt);
_clBoundBox &= rPt;
_clBoundBox.Add(rPt);
}
}
@ -394,7 +394,7 @@ void MeshKernel::Clear (void)
MeshPointArray().swap(_aclPointArray);
MeshFacetArray().swap(_aclFacetArray);
_clBoundBox.Flush();
_clBoundBox.SetVoid();
}
bool MeshKernel::DeleteFacet (const MeshFacetIterator &rclIter)
@ -908,10 +908,10 @@ void MeshKernel::Transform (const Base::Matrix4D &rclMat)
MeshPointArray::_TIterator clPIter = _aclPointArray.begin(), clPEIter = _aclPointArray.end();
Base::Matrix4D clMatrix(rclMat);
_clBoundBox.Flush();
_clBoundBox.SetVoid();
while (clPIter < clPEIter) {
*clPIter *= clMatrix;
_clBoundBox &= *clPIter;
_clBoundBox.Add(*clPIter);
clPIter++;
}
}
@ -923,9 +923,9 @@ void MeshKernel::Smooth(int iterations, float stepsize)
void MeshKernel::RecalcBoundBox (void)
{
_clBoundBox.Flush();
_clBoundBox.SetVoid();
for (MeshPointArray::_TConstIterator pI = _aclPointArray.begin(); pI != _aclPointArray.end(); pI++)
_clBoundBox &= *pI;
_clBoundBox.Add(*pI);
}
std::vector<Base::Vector3f> MeshKernel::CalcVertexNormals() const

View File

@ -287,7 +287,7 @@ bool MeshProjection::bboxInsideRectangle(const Base::BoundBox3f& bbox,
if (bbox.IsCutPlane(base, normal)) {
dir.Normalize();
Base::Vector3f cnt(bbox.CalcCenter());
Base::Vector3f cnt(bbox.GetCenter());
return (fabs(cnt.DistanceToPlane(p1, dir)) + fabs(cnt.DistanceToPlane(p2, dir))) <=
(bbox.CalcDiagonalLength() + (p2 - p1).Length());

View File

@ -1324,7 +1324,7 @@ void MeshTopoAlgorithm::FillupHoles(int level, AbstractPolygonTriangulator& cTri
// insert new points and faces into the mesh structure
_rclMesh._aclPointArray.insert(_rclMesh._aclPointArray.end(), newPoints.begin(), newPoints.end());
for (MeshPointArray::_TIterator it = newPoints.begin(); it != newPoints.end(); ++it)
_rclMesh._clBoundBox &= *it;
_rclMesh._clBoundBox.Add(*it);
if (!newFacets.empty()) {
// Do some checks for invalid point indices
MeshFacetArray addFacets;

View File

@ -973,7 +973,7 @@ void CmdMeshTrimByPlane::activated(int iMsg)
Base::BoundBox3d bbox = mesh->getBoundBox();
double len = bbox.CalcDiagonalLength();
// project center of bbox onto plane and use this as base point
Base::Vector3d cnt = bbox.CalcCenter();
Base::Vector3d cnt = bbox.GetCenter();
double dist = (cnt-base)*normal;
base = cnt - normal * dist;

View File

@ -1096,7 +1096,7 @@ void SoFCMeshObjectShape::computeBBox(SoAction *action, SbBox3f &box, SbVec3f &c
Base::BoundBox3f cBox = mesh->getKernel().GetBoundBox();
box.setBounds(SbVec3f(cBox.MinX,cBox.MinY,cBox.MinZ),
SbVec3f(cBox.MaxX,cBox.MaxY,cBox.MaxZ));
Base::Vector3f mid = cBox.CalcCenter();
Base::Vector3f mid = cBox.GetCenter();
center.setValue(mid.x,mid.y,mid.z);
}
else {
@ -1503,14 +1503,14 @@ void SoFCMeshSegmentShape::computeBBox(SoAction *action, SbBox3f &box, SbVec3f &
for (std::vector<unsigned long>::const_iterator it = indices.begin();
it != indices.end(); ++it) {
const MeshCore::MeshFacet& face = rFaces[*it];
cBox &= rPoint[face._aulPoints[0]];
cBox &= rPoint[face._aulPoints[1]];
cBox &= rPoint[face._aulPoints[2]];
cBox.Add(rPoint[face._aulPoints[0]]);
cBox.Add(rPoint[face._aulPoints[1]]);
cBox.Add(rPoint[face._aulPoints[2]]);
}
box.setBounds(SbVec3f(cBox.MinX,cBox.MinY,cBox.MinZ),
SbVec3f(cBox.MaxX,cBox.MaxY,cBox.MaxZ));
Base::Vector3f mid = cBox.CalcCenter();
Base::Vector3f mid = cBox.GetCenter();
center.setValue(mid.x,mid.y,mid.z);
}
}
@ -1653,10 +1653,10 @@ void SoFCMeshObjectBoundary::computeBBox(SoAction *action, SbBox3f &box, SbVec3f
if (rPoints.size() > 0) {
Base::BoundBox3f cBox;
for (MeshCore::MeshPointArray::_TConstIterator it = rPoints.begin(); it != rPoints.end(); ++it)
cBox &= (*it);
cBox.Add(*it);
box.setBounds(SbVec3f(cBox.MinX,cBox.MinY,cBox.MinZ),
SbVec3f(cBox.MaxX,cBox.MaxY,cBox.MaxZ));
Base::Vector3f mid = cBox.CalcCenter();
Base::Vector3f mid = cBox.GetCenter();
center.setValue(mid.x,mid.y,mid.z);
}
else {

View File

@ -122,7 +122,7 @@ void ViewProviderMeshTransformDemolding::attach(App::DocumentObject *pcFeat)
calcNormalVector();
calcMaterialIndex(SbRotation());
// geting center point
center = dynamic_cast<Feature*>(pcObject)->Mesh.getValue().getKernel().GetBoundBox().CalcCenter();
center = dynamic_cast<Feature*>(pcObject)->Mesh.getValue().getKernel().GetBoundBox().GetCenter();
//SoGetBoundingBoxAction boxAction;
//pcHighlight->getBoundingBox(&boxAction);

View File

@ -77,6 +77,8 @@
#include "OpenCascadeAll.h"
#elif defined(FC_OS_WIN32)
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#endif //_PreComp_

View File

@ -129,7 +129,7 @@ CrossSections::CrossSections(const Base::BoundBox3d& bb, QWidget* parent, Qt::WF
ui->distance->setDecimals(Base::UnitsApi::getDecimals());
vp = new ViewProviderCrossSections();
Base::Vector3d c = bbox.CalcCenter();
Base::Vector3d c = bbox.GetCenter();
calcPlane(CrossSections::XY, c.z);
ui->position->setValue(c.z);
@ -269,7 +269,7 @@ void CrossSections::apply()
void CrossSections::on_xyPlane_clicked()
{
Base::Vector3d c = bbox.CalcCenter();
Base::Vector3d c = bbox.GetCenter();
ui->position->setValue(c.z);
if (!ui->sectionsBox->isChecked()) {
calcPlane(CrossSections::XY, c.z);
@ -285,7 +285,7 @@ void CrossSections::on_xyPlane_clicked()
void CrossSections::on_xzPlane_clicked()
{
Base::Vector3d c = bbox.CalcCenter();
Base::Vector3d c = bbox.GetCenter();
ui->position->setValue(c.y);
if (!ui->sectionsBox->isChecked()) {
calcPlane(CrossSections::XZ, c.y);
@ -301,7 +301,7 @@ void CrossSections::on_xzPlane_clicked()
void CrossSections::on_yzPlane_clicked()
{
Base::Vector3d c = bbox.CalcCenter();
Base::Vector3d c = bbox.GetCenter();
ui->position->setValue(c.x);
if (!ui->sectionsBox->isChecked()) {
calcPlane(CrossSections::YZ, c.x);
@ -332,7 +332,7 @@ void CrossSections::on_sectionsBox_toggled(bool b)
}
else {
CrossSections::Plane type = plane();
Base::Vector3d c = bbox.CalcCenter();
Base::Vector3d c = bbox.GetCenter();
double value = 0;
switch (type) {
case CrossSections::XY:

View File

@ -35,6 +35,11 @@
# define PartGuiExport
#endif
#ifdef FC_OS_WIN32
# define NOMINMAX
#endif
#ifdef _PreComp_
// here get the warnings of too long specifiers disabled (needed for VC6)
#ifdef _MSC_VER
@ -43,9 +48,6 @@
# pragma warning( disable : 4786 ) // specifier longer then 255 chars
#endif
// standard
#include <iostream>
//#include <stdio.h>

View File

@ -88,7 +88,7 @@ bool ViewProviderMirror::setEdit(int ModNum)
float len = (float)bbox.CalcDiagonalLength();
Base::Vector3d base = mf->Base.getValue();
Base::Vector3d norm = mf->Normal.getValue();
Base::Vector3d cent = bbox.CalcCenter();
Base::Vector3d cent = bbox.GetCenter();
base = cent.ProjToPlane(base, norm);
// setup the graph for editing the mirror plane

View File

@ -81,7 +81,7 @@ PointsGrid::PointsGrid (const PointKernel &rclM, double fGridLen)
{
Base::BoundBox3d clBBPts;// = _pclPoints->GetBoundBox();
for (PointKernel::const_iterator it = _pclPoints->begin(); it != _pclPoints->end(); ++it )
clBBPts &= (*it);
clBBPts.Add(*it);
Rebuild(std::max<unsigned long>((unsigned long)(clBBPts.LengthX() / fGridLen), 1),
std::max<unsigned long>((unsigned long)(clBBPts.LengthY() / fGridLen), 1),
std::max<unsigned long>((unsigned long)(clBBPts.LengthZ() / fGridLen), 1));
@ -138,7 +138,7 @@ void PointsGrid::InitGrid (void)
{
Base::BoundBox3d clBBPts;// = _pclPoints->GetBoundBox();
for (PointKernel::const_iterator it = _pclPoints->begin(); it != _pclPoints->end(); ++it )
clBBPts &= (*it);
clBBPts.Add(*it);
double fLengthX = clBBPts.LengthX();
double fLengthY = clBBPts.LengthY();
@ -222,7 +222,7 @@ unsigned long PointsGrid::InSide (const Base::BoundBox3d &rclBB, std::vector<uns
{
for (k = ulMinZ; k <= ulMaxZ; k++)
{
if (Base::DistanceP2(GetBoundBox(i, j, k).CalcCenter(), rclOrg) < fMinDistP2)
if (Base::DistanceP2(GetBoundBox(i, j, k).GetCenter(), rclOrg) < fMinDistP2)
raulElements.insert(raulElements.end(), _aulGrid[i][j][k].begin(), _aulGrid[i][j][k].end());
}
}
@ -287,7 +287,7 @@ void PointsGrid::CalculateGridLength (unsigned long ulCtGrid, unsigned long ulMa
// bzw. max Grids sollten 10000 nicht ueberschreiten
Base::BoundBox3d clBBPtsEnlarged;// = _pclPoints->GetBoundBox();
for (PointKernel::const_iterator it = _pclPoints->begin(); it != _pclPoints->end(); ++it )
clBBPtsEnlarged &= (*it);
clBBPtsEnlarged.Add(*it);
double fVolElem;
if (_ulCtElements > (ulMaxGrids * ulCtGrid))
@ -316,7 +316,7 @@ void PointsGrid::CalculateGridLength (int iCtGridPerAxis)
// bzw. max Grids sollten 10000 nicht ueberschreiten
Base::BoundBox3d clBBPts;// = _pclPoints->GetBoundBox();
for (PointKernel::const_iterator it = _pclPoints->begin(); it != _pclPoints->end(); ++it )
clBBPts &= (*it);
clBBPts.Add(*it);
double fLenghtX = clBBPts.LengthX();
double fLenghtY = clBBPts.LengthY();
@ -464,7 +464,7 @@ void PointsGrid::SearchNearestFromPoint (const Base::Vector3d &rclPt, std::set<u
}
else
{ // Punkt ausserhalb
Base::BoundBox3d::SIDE tSide = clBB.GetSideFromRay(rclPt, clBB.CalcCenter() - rclPt);
Base::BoundBox3d::SIDE tSide = clBB.GetSideFromRay(rclPt, clBB.GetCenter() - rclPt);
switch (tSide)
{
case Base::BoundBox3d::RIGHT:

View File

@ -35,6 +35,10 @@
# define PointsGuiExport
#endif
#ifdef FC_OS_WIN32
# define NOMINMAX
#endif
#ifdef _PreComp_
// standard

View File

@ -24,9 +24,6 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# ifdef FC_OS_WIN32
# include <windows.h>
# endif
# include <Inventor/nodes/SoCamera.h>
# include <Inventor/nodes/SoCoordinate3.h>
# include <Inventor/nodes/SoDrawStyle.h>

View File

@ -682,7 +682,7 @@ bool ParameterCorrection::GetUVParameters(double fSizeFactor)
(*_pvcPoints)(ii).Y(),
(*_pvcPoints)(ii).Z()));
vcProjPts.push_back(Base::Vector2D(clProjPnt.X(), clProjPnt.Y()));
clBBox &= (Base::Vector2D(clProjPnt.X(), clProjPnt.Y()));
clBBox.Add(Base::Vector2D(clProjPnt.X(), clProjPnt.Y()));
}
if ((clBBox.fMaxX == clBBox.fMinX) || (clBBox.fMaxY == clBBox.fMinY))

View File

@ -24,6 +24,8 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# ifdef FC_OS_WIN32
# define WIN32_LEAN_AND_MEAN
# define NOMINMAX
# include <windows.h>
# endif
# include <QApplication>

View File

@ -54,6 +54,7 @@
#include <Python.h>
#elif defined(FC_OS_WIN32)
#define NOMINMAX
#include <windows.h>
#endif // _PreComp_
#endif

View File

@ -40,6 +40,7 @@
// here get the warnings of too long specifiers disabled (needed for VC6)
#ifdef _MSC_VER
# pragma warning( disable : 4251 )
# pragma warning( disable : 4275 )
# pragma warning( disable : 4503 )
# pragma warning( disable : 4786 ) // specifier longer then 255 chars
#endif

View File

@ -170,6 +170,16 @@ class ParameterTestCase(unittest.TestCase):
self.failUnless(m2==m3*m4 ,"Wrong multiplication order")
self.failUnless(not m2==m4*m3,"Wrong multiplication order")
def testBounding(self):
b=FreeCAD.BoundBox()
b.setVoid()
self.failUnless(not b.isValid(),"Bbox is not invalid")
b.add(0,0,0)
self.failUnless(b.isValid(),"Bbox is invalid")
self.failUnless(b.XLength==0,"X length > 0")
self.failUnless(b.YLength==0,"Y length > 0")
self.failUnless(b.ZLength==0,"Z length > 0")
def testNesting(self):
# Parameter testing
#FreeCAD.Console.PrintLog("Base::ParameterTestCase::testNesting\n")