Hide menu
Loading...
Searching...
No Matches
Basic Measurements

MTK supports computation of basic geometric measurements for 3D objects:

See the corresponding sections and class references for usage details and limitations.

Bounding Box

A bounding box is a box that fully contains a 3D model or one of its components.

MTK supports two kinds of bounding boxes:

  • axis-aligned bounding box (AABB), whose axes are aligned with the global coordinate axes;
  • oriented bounding box (OBB), whose axes may be rotated to better fit the input geometry.

Axis-Aligned Bounding Box

Measurements::BoundingBox::Compute() computes an axis-aligned bounding box. Axis-aligned bounding boxes can be computed for an entire model, a model graph element, a body, a B-Rep shape, or a mesh shape.

The following example demonstrates computation of a shape axis-aligned bounding box:

using namespace cadex;
ModelData::Shape aShape = ...;
Measurements::BoundingBox::Compute (aShape, aTrsf, aBox);
Defines a transformation matrix.
Definition Transformation.hxx:31
static void Compute(const ModelData::Model &theModel, ModelData::Box &theBox)
Computes an axis-aligned bounding box (AABB) of the model.
Definition BoundingBox.cxx:437
Defines a 3D axis-aligned bounding box.
Definition ModelData/Box.hxx:28
Base class of topological shapes.
Definition ModelData/Shape.hxx:37
Contains classes, namespaces, enums, types, and global functions related to Manufacturing Toolkit.
Definition LicenseError.hxx:27

Oriented Bounding Box

Measurements::BoundingBox::ComputeMin() and Measurements::BoundingBox::ComputeOptimal() compute oriented bounding boxes. Although these methods compute an oriented bounding box, the ModelData::Box class itself can only store axis-aligned data. To bridge this gap, the method calculates the box in its own local coordinate system and returns an output transformation. This transformation defines how to rotate and position the shape to fit inside this box.

These methods use different algorithms. Measurements::BoundingBox::ComputeMin() estimates the box orientation from the principal axes of inertia. Measurements::BoundingBox::ComputeOptimal() attemps to determinate the optimal box orientation from the planar faces and linear edges of the shape. and falls back to Measurements::BoundingBox::ComputeMin() if no suitable orientation is found.

Measurements::BoundingBox::ComputeMin() can be computed for a B-Rep shape. Measurements::BoundingBox::ComputeOptimal() can be computed for an entire model, a part representation, a body, a B-Rep shape, or a mesh shape.

The following example demonstrates how to compute an oriented bounding box for a shape using Measurements::BoundingBox::ComputeMin() :

using namespace cadex;
ModelData::Shape aShape = ...;
static void ComputeMin(const ModelData::Shape &theShape, ModelData::Box &theBox, Geom::Transformation &theOutTransformation)
Computes an oriented bounding box (OBB) of the shape.
Definition BoundingBox.cxx:487

Bounding Cylinder

Bounding cylinder is the smallest oriented cylinder that fully contains a component of a 3D model. This can be used to find the dimensions of a cylindrical workpiece for a given part. Bounding cylinders can be computed for a part representation, a B-Rep or mesh body, a B-Rep shape, or a mesh shape.

The following example demonstrates computation of a shape bounding cylinder:

using namespace cadex;
ModelData::Shape aShape = ...;
Measurements::Cylinder aCylinder = Measurements::BoundingCylinder::ComputeOrientedCylinder (aShape);
static Geom::Cylinder ComputeOrientedCylinder(const ModelData::Part &thePart)
Computes an oriented bounding cylinder of the part.
Definition BoundingCylinder.cxx:218

Surface Area

Surface area can be computed for an entire model, a model graph element, a solid or sheet body, or a shape.

The following example demonstrates computation of a shape surface area:

using namespace cadex;
ModelData::Shape aShape = ...;
double aSurfaceArea = Measurements::SurfaceArea::Compute (aShape);
static double Compute(const ModelData::Model &theModel)
Computes the surface area of the model.
Definition SurfaceArea.cxx:55

Volume

Volume can be computed for an entire model, a model graph element, a solid body, a shape, or an indexed triangle set.

Measurements::Volume::Compute() also provides overloads for selected manufacturing features, such as machining holes, countersinks and pockets, as well as sheet metal holes and cutouts in the context of a flat pattern. For feature overloads, the returned value represents the removed material volume in mm^3, or -1.0 if the computation fails.

The following example demonstrates computation of a shape volume:

using namespace cadex;
ModelData::Shape aShape = ...;
double aVolume = Measurements::Volume::Compute (aShape);
static double Compute(const ModelData::Model &theModel)
Computes the volume of the model.
Definition Volume.cxx:678

Distance

Distance can be computed between two shapes. In addition to the distance value, MTK can also return the closest point on each shape.

The following example demonstrates the computation of the distance between two shapes:

using namespace cadex;
ModelData::Shape aFirstShape = ...;
ModelData::Shape aSecondShape = ...;
double aDistance = Measurements::Distance::Compute (aFirstShape, aSecondShape);
static double Compute(const ModelData::Shape &theFirstShape, const ModelData::Shape &theSecondShape)
Computes the distance between theFirstShape and theSecondShape.
Definition Distance.cxx:37

Angle

Angle can be computed between two planar faces, between two edges, or from three vertices.

The following example demonstrates the computation of the angle between two planar faces:

using namespace cadex;
ModelData::Face aFirstFace = ...;
ModelData::Face aSecondFace = ...;
double anAngle = Measurements::Angle::Compute (aFirstFace, aSecondFace);
static double Compute(const ModelData::Face &theFirstFace, const ModelData::Face &theSecondFace)
Computes the angle between two faces.
Definition Angle.cxx:53
Defines a topological face.
Definition ModelData/Face.hxx:31

Validation Properties

Some measurements are also available through Measurements::ValidationProperties . This API computes a set of validation properties for an object and returns them as Measurements::ValidationPropertyData .

Validation properties include surface area, volume, centroid, and axes of inertia. Computing them together is more efficient than computing each value separately.

Measurements::ValidationPropertyData also provides \morph_{Measurements,ValidationPropertyData,IsValid()} to check whether the computed values are valid.

The following example demonstrates computation of validation properties for a shape:

using namespace cadex;
ModelData::Shape aShape = ...;
double aSurfaceArea = aProperties.SurfaceArea();
double aVolume = aProperties.Volume();
Geom::Point aCentroid = aProperties.Centroid();
Geom::Direction aFirstAxis = aProperties.FirstAxisOfInertia();
Geom::Direction aSecondAxis = aProperties.SecondAxisOfInertia();
Geom::Direction aThirdAxis = aProperties.ThirdAxisOfInertia();
Defines a 3D Direction.
Definition Direction.hxx:32
Defines a 3D point.
Definition Point.hxx:34
static ValidationPropertyData Compute(const ModelData::Model &theModel)
Computes the validation properties of the model.
Definition ValidationProperties.cxx:161
Aggregates validation properties computed for an object.
Definition ValidationPropertyData.hxx:35
double Volume() const
Returns a volume.
Definition ValidationPropertyData.cxx:62
const Geom::Point & Centroid() const
Returns a center of mass.
Definition ValidationPropertyData.cxx:74
const Geom::Direction & FirstAxisOfInertia() const
Returns a first axis of inertia.
Definition ValidationPropertyData.cxx:80
const Geom::Direction & ThirdAxisOfInertia() const
Returns a third axis of inertia.
Definition ValidationPropertyData.cxx:92
double SurfaceArea() const
Returns a surface area.
Definition ValidationPropertyData.cxx:68
const Geom::Direction & SecondAxisOfInertia() const
Returns a second axis of inertia.
Definition ValidationPropertyData.cxx:86

Centroid

A centroid, or center of mass, can be computed for an entire model, a model graph element, a B-Rep body, or a shape.

In MTK, centroid computation is exposed through Measurements::ValidationProperties .

The following example demonstrates computation of a shape centroid:

using namespace cadex;
ModelData::Shape aShape = ...;
static Geom::Point ComputeCentroid(const ModelData::Model &theModel)
Computes the center of mass of the model.
Definition ValidationProperties.cxx:63