+ rework BoundingBox class and its Python binding

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

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")