The Ge library contains special classes that represent bounding block entities for 2D and 3D geometrical objects — the OdGeBoundBlock2d and OdGeBoundBlock3d classes respectively provide a set of methods for creating and modifying bounding blocks. This topic describes the common usage of the OdGeBoundBlock3d class as a general case but it can be applied to OdGeBoundBlock2d as well because their interfaces are very similar.
Bounding blocks can be one of two types: coordinate-aligned bounding box or a parallelepiped (a parallelogram in 2D).
A coordinate-aligned bounding box has edges parallel to coordinate axes and is independent of object orientation. A parallelepiped bounding box has the same orientation as the geometrical object and is calculated to have the least volume as possible.
To create a bounding block of a specific type, use the appropriate OdGeBoundBlock3d() constructor:
There is a set of methods for getting the parameters of the block. The get() method is used to get the vertex and sides of the block. The center() method calculates the center of the bounding block (provided for 3D blocks only). To get the extents of the bounding block, use the getMinMaxPoints() method which calculates the opposite vertices of the minimal box that contains the bounding block.
OdGePoint3d point, minPoint, maxPoint;
OdGeVector3d side1, side2, side3;
bBlock1.get(point, side1, side2, side3);
OdGePoint3d center = bBlock1.center();
bBlock1.getMinMaxPoints(minPoint, maxPoint);
To set the block to a new one of specific type, use the appropriate set() method:
To check the type of a bounding block, use the isBox() method, which returns true if the block is a
coordinate-aligned box and false if the block is parallelepiped. The method setToBox() converts the block
to a coordinate-aligned box if its input parameter is true
and to a parallelepiped block if
it's false
. However, if the current block type is equal to desired, the method just returns a
reference to the block.
if (bBlock1.isBox())
bBlock1.setToBox(false);
else
bBlock1.setToBox(true);
You can check whether a point is contained (with a specified tolerance) in the block using the contains() method. The block can be extended to contain a specified point using the extend() method. For example:
if (!bBlock1.contains(point1))
bBlock1.extend(point1);
Another way to extend the block is to use the swell() method, which moves the edges of the block a specified distance. Positive argument values expand the block and negative values narrow it.
bBlock1.swell(1.2);
To find the relative position of two bounding blocks, use the isDisjoint() method. The method returns true if the input block does not intersect with the block and false otherwise:
if (bBlock1.isDisjoint(bBlock2))
bBlock1.rotateBy(OdaPI, side1.crossProduct(side2), point);
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|