1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0029311: Implementation of the Oriented Bounding Boxes (OBB) functionality

1. The class Bnd_OBB has been created to describe the Oriented Bounding Box.

2. Several key methods have been implemented: Bnd_OBB::IsOut(...), Bnd_OBB::Add(...) and Bnd_OBB::Enlarge(...).

3. Interface of Bnd_Box class has changed. New methods have been created. See Bnd_Box.hxx for detailed information.

4. BRepBndLib and Draw_Box classes have been amended in order to provide correct work with Bnd_OBB class.

5. Interface of "bounding" DRAW-command has been changed. Please see help for detailed information.

6. New DRAW-command "isbbinterf" has been created. Please see help for detailed information.

7. "boundingstr" and "optbounding" DRAW-commands have been eliminated because their function can be made by "bounding" DRAW-command (e.g. see tests/bugs/vis/buc60857 or samples/tcl/snowflake.tcl test cases).

8. Documentation has been updated.
This commit is contained in:
nbv
2017-11-08 15:47:09 +03:00
committed by bugmaster
parent 8d1a539c4a
commit 1a0339b464
83 changed files with 3204 additions and 1087 deletions

View File

@@ -24,116 +24,111 @@
IMPLEMENT_STANDARD_RTTIEXT(Draw_Box,Draw_Drawable3D)
//=======================================================================
//function : Draw_Box
//function : Constructor
//purpose :
//=======================================================================
Draw_Box::Draw_Box(const gp_Pnt& p1, const gp_Pnt& p2, const Draw_Color& col) :
myFirst(p1), myLast(p2),myColor(col)
Draw_Box::Draw_Box(const Bnd_OBB& theOBB,
const Draw_Color& theColor) :myOBB(theOBB), myColor(theColor)
{
Standard_Real t;
if (myLast.X() < myFirst.X()) {
t = myFirst.X();
myFirst.SetX(myLast.X());
myLast.SetX(t);
}
if (myLast.Y() < myFirst.Y()) {
t = myFirst.Y();
myFirst.SetY(myLast.Y());
myLast.SetY(t);
}
if (myLast.Z() < myFirst.Z()) {
t = myFirst.Z();
myFirst.SetZ(myLast.Z());
myLast.SetZ(t);
}
}
//=======================================================================
//function : ToWCS
//purpose :
//=======================================================================
void Draw_Box::ToWCS(const Standard_Real theX,
const Standard_Real theY,
const Standard_Real theZ,
gp_Pnt& theP) const
{
const gp_XYZ & aC = myOBB.Center();
const gp_XYZ aXDir = myOBB.XDirection(),
aYDir = myOBB.YDirection(),
aZDir = myOBB.ZDirection();
theP.SetXYZ(aC + theX*aXDir + theY*aYDir + theZ*aZDir);
}
//=======================================================================
//function : MoveX
//purpose :
//=======================================================================
void Draw_Box::MoveX(const Standard_Real theShift, gp_Pnt& thePt) const
{
const gp_XYZ aXDir = myOBB.XDirection();
thePt.SetXYZ(thePt.XYZ() + theShift*aXDir);
}
//=======================================================================
//function : MoveY
//purpose :
//=======================================================================
void Draw_Box::MoveY(const Standard_Real theShift, gp_Pnt& thePt) const
{
const gp_XYZ aYDir = myOBB.YDirection();
thePt.SetXYZ(thePt.XYZ() + theShift*aYDir);
}
//=======================================================================
//function : MoveZ
//purpose :
//=======================================================================
void Draw_Box::MoveZ(const Standard_Real theShift, gp_Pnt& thePt) const
{
const gp_XYZ aZDir = myOBB.ZDirection();
thePt.SetXYZ(thePt.XYZ() + theShift*aZDir);
}
//=======================================================================
//function : DrawOn
//purpose :
//=======================================================================
void Draw_Box::DrawOn(Draw_Display& dis) const
void Draw_Box::DrawOn(Draw_Display& theDIS) const
{
dis.SetColor(myColor);
gp_Pnt P = myFirst;
if(myOBB.IsVoid())
{
return;
}
dis.MoveTo(P);
P.SetX(myLast.X());
dis.DrawTo(P);
P.SetY(myLast.Y());
dis.DrawTo(P);
P.SetZ(myLast.Z());
dis.DrawTo(P);
P.SetX(myFirst.X());
dis.DrawTo(P);
P.SetY(myFirst.Y());
dis.DrawTo(P);
P.SetZ(myFirst.Z());
dis.DrawTo(P);
P.SetX(myLast.X());
dis.MoveTo(P);
P.SetZ(myLast.Z());
dis.DrawTo(P);
P.SetX(myFirst.X());
dis.DrawTo(P);
theDIS.SetColor(myColor);
P.SetX(myLast.X());
dis.MoveTo(P);
P.SetY(myLast.Y());
dis.DrawTo(P);
const Standard_Real aHx = myOBB.XHSize(),
aHy = myOBB.YHSize(),
aHz = myOBB.ZHSize();
gp_Pnt aP;
ToWCS(-aHx, -aHy, -aHz, aP);
theDIS.MoveTo(aP);
for(Standard_Integer i = 0; i<2; i++)
{
MoveX(2.0*aHx, aP);
theDIS.DrawTo(aP);
MoveY(2.0*aHy, aP);
theDIS.DrawTo(aP);
MoveX(-2.0*aHx, aP);
theDIS.DrawTo(aP);
MoveY(-2.0*aHy, aP);
theDIS.DrawTo(aP);
ToWCS(-aHx, -aHy, aHz, aP);
theDIS.MoveTo(aP);
}
P.SetX(myFirst.X());
dis.MoveTo(P);
P.SetZ(myFirst.Z());
dis.DrawTo(P);
P.SetY(myFirst.Y());
dis.DrawTo(P);
P.SetY(myLast.Y());
dis.MoveTo(P);
P.SetX(myLast.X());
dis.DrawTo(P);
}
//=======================================================================
//function : First
//purpose :
//=======================================================================
const gp_Pnt& Draw_Box::First() const
{
return myFirst;
}
//=======================================================================
//function : First
//purpose :
//=======================================================================
void Draw_Box::First(const gp_Pnt& P)
{
myFirst = P;
}
//=======================================================================
//function : Last
//purpose :
//=======================================================================
const gp_Pnt& Draw_Box::Last() const
{
return myLast;
}
//=======================================================================
//function : Last
//purpose :
//=======================================================================
void Draw_Box::Last(const gp_Pnt& P)
{
myLast = P;
for(Standard_Integer i = 0; i < 4; i++)
{
switch(i)
{
case 0: ToWCS(-aHx, -aHy, -aHz, aP); break;
case 1: ToWCS(aHx, -aHy, -aHz, aP); break;
case 2: ToWCS(aHx, aHy, -aHz, aP); break;
case 3: ToWCS(-aHx, aHy, -aHz, aP); break;
default: break;
}
theDIS.MoveTo(aP);
MoveZ(2.0*aHz, aP);
theDIS.DrawTo(aP);
}
}

View File

@@ -20,10 +20,9 @@
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <gp_Pnt.hxx>
#include <Bnd_OBB.hxx>
#include <Draw_Color.hxx>
#include <Draw_Drawable3D.hxx>
class gp_Pnt;
class Draw_Color;
class Draw_Display;
@@ -34,46 +33,41 @@ DEFINE_STANDARD_HANDLE(Draw_Box, Draw_Drawable3D)
//! a 3d box
class Draw_Box : public Draw_Drawable3D
{
public:
//! Constructor
Standard_EXPORT Draw_Box(const Bnd_OBB& theOBB,
const Draw_Color& theColor);
//! Draws myOBB
Standard_EXPORT void DrawOn (Draw_Display& theDis) const Standard_OVERRIDE;
Standard_EXPORT Draw_Box(const gp_Pnt& p1, const gp_Pnt& p2, const Draw_Color& col);
Standard_EXPORT void DrawOn (Draw_Display& dis) const Standard_OVERRIDE;
Standard_EXPORT const gp_Pnt& First() const;
Standard_EXPORT void First (const gp_Pnt& P);
Standard_EXPORT const gp_Pnt& Last() const;
Standard_EXPORT void Last (const gp_Pnt& P);
DEFINE_STANDARD_RTTIEXT(Draw_Box,Draw_Drawable3D)
protected:
//! Converts the point (theX, theY, theZ) in local coordinate system to WCS.
void ToWCS(const Standard_Real theX,
const Standard_Real theY,
const Standard_Real theZ,
gp_Pnt& theP) const;
//! Moves the point thePt along X-direction of myOBB on the distance theShift.
void MoveX(const Standard_Real theShift, gp_Pnt& thePt) const;
//! Moves the point thePt along Y-direction of myOBB on the distance theShift.
void MoveY(const Standard_Real theShift, gp_Pnt& thePt) const;
//! Moves the point thePt along Z-direction of myOBB on the distance theShift.
void MoveZ(const Standard_Real theShift, gp_Pnt& thePt) const;
private:
//! Oriented bounding box
Bnd_OBB myOBB;
gp_Pnt myFirst;
gp_Pnt myLast;
//! Color value
Draw_Color myColor;
};
#endif // _Draw_Box_HeaderFile