Kernel SDK Developer's Guide > Working with the Ge Library > Working with Bounding Blocks
Working with Bounding Blocks

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:

  • OdGeBoundBlock3d() — Creates a parallelepiped bounding block reduced to the coordinate origin.
  • OdGeBoundBlock3d(const OdGePoint3d& base, const OdGeVector3d& side1, const OdGeVector3d& side2, const OdGeVector3d& side3) — Creates a parallelepiped bounding block by a given parallelepiped vertex and three sides defined by side1, side2 and side3 vectors.
  • OdGeBoundBlock3d(const OdGePoint3d& point1, const OdGePoint3d& point2) — Creates a coordinate-aligned block by two given points.
  • OdGeBoundBlock3d(const OdGeBoundBlock3d& source) — Creates a block cloned from the source object.

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:

  • OdGeBoundBlock3d& set(const OdGePoint3d& p1, const OdGePoint3d& p2) — Sets the bounding block to a coordinate-aligned box between the specified points.
  • OdGeBoundBlock3d& set(const OdGePoint3d& base, const OdGeVector3d& side1, const OdGeVector3d& side2, const OdGeVector3d& side3)) — Sets the bounding block to a parallelepiped box with the specified vertex and three sides.

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.