opencascade Bnd_B3d源码学习 包围盒

opencascade Bnd_B3d 包围盒
在这里插入图片描述

方法

1

Bnd_B3d();
// 空构造函数。

2

Bnd_B3d(const gp_XYZ& theCenter, const gp_XYZ& theHSize);
// 构造函数。

3

Standard_Boolean IsVoid() const;
// 如果盒子是空的(未初始化),则返回 True。

4

void Clear();
// 重置盒子的数据。

5

Standard_EXPORT void Add (const gp_XYZ& thePnt);
// 通过一个点更新盒子。

6

void Add (const gp_Pnt& thePnt);
// 通过一个点更新盒子。

7

void Add (const Bnd_B3d& theBox);
// 通过另一个盒子更新当前盒子。

8

gp_XYZ CornerMin() const;
// 查询下角点:(中心 - 半对角线)。你必须确保
// 盒子不是 VOID(参见 IsVoid()),否则方法将返回
// 无效结果。

9

gp_XYZ CornerMax() const;
// 查询上角点:(中心 + 半对角线)。你必须确保
// 盒子不是 VOID(参见 IsVoid()),否则方法将返回
// 无效结果。

10

Standard_Real SquareExtent() const;
// 查询平方对角线。如果盒子是 VOID(参见方法 IsVoid()),
// 则返回一个非常大的实值。

11

void Enlarge (const Standard_Real theDiff);
// 通过 theDiff 的绝对值扩展盒子。

12

Standard_EXPORT Standard_Boolean Limit (const Bnd_B3d& theOtherBox);
// 限制盒子在另一个盒子的内部。
// 如果限制发生,则返回 True,否则返回 False
// 表示两个盒子没有交集。

13

Standard_NODISCARD Standard_EXPORT Bnd_B3d Transformed (const gp_Trsf& theTrsf) const;
// 使用给定的变换变换边界盒。
// 如果 theTrsf 包含旋转,结果盒子将会更大。

14

Standard_Boolean IsOut (const gp_XYZ& thePnt) const;
// 检查给定点是否在盒子内。
// 如果点在外部,则返回 True。

15

Standard_EXPORT Standard_Boolean IsOut (const gp_XYZ& theCenter, const Standard_Real theRadius, const Standard_Boolean isSphereHollow = Standard_False) const;
// 检查一个球体是否与当前盒子有交集。
// 如果两个盒子之间没有交集,则返回 True。如果
// 参数 ‘IsSphereHollow’ 为 True,则如果盒子完全在球体内,则不会报告交集
// (否则此方法会报告交集)。

16

Standard_Boolean IsOut (const Bnd_B3d& theOtherBox) const;
// 检查给定的盒子是否与当前盒子有交集。
// 如果两个盒子之间没有交集,则返回 True。

17

Standard_EXPORT Standard_Boolean IsOut (const Bnd_B3d& theOtherBox, const gp_Trsf& theTrsf) const;
// 检查通过给定变换变换的盒子是否与当前盒子有交集。
// 如果两个盒子之间没有交集,则返回 True。

18

Standard_EXPORT Standard_Boolean IsOut (const gp_Ax1& theLine, const Standard_Boolean isRay = Standard_False, const Standard_Real theOverthickness = 0.0) const;
// 检查给定的直线是否与当前盒子有交集。
// 如果没有交集,则返回 True。
// isRay==True 表示检查与正半线的交集
// theOverthickness 是对当前盒子的大小的附加
// (可以是负值)。如果为正值,可以将其视为直线 ‘theLine’
// 的厚度或沿着 ‘theLine’ 的圆柱半径。

19

Standard_EXPORT Standard_Boolean IsOut (const gp_Ax3& thePlane) const;
// 检查给定的平面是否与当前盒子有交集。
// 如果没有交集,则返回 True。

20

Standard_Boolean IsIn (const Bnd_B3d& theBox) const;
// 检查盒子 ‘this’ 是否在给定的盒子 ‘theBox’ 内。返回
// True 如果 ‘this’ 盒子完全在 ‘theBox’ 内。

21

Standard_EXPORT Standard_Boolean IsIn (const Bnd_B3d& theBox, const gp_Trsf& theTrsf) const;
// 检查盒子 ‘this’ 是否在通过 ‘theTrsf’ 变换的给定盒子 ‘theBox’ 内。
// 返回 True 如果 ‘this’ 盒子完全在变换后的 ‘theBox’ 内。

22

void SetCenter (const gp_XYZ& theCenter);
// 设置中心坐标。

23

void SetHSize (const gp_XYZ& theHSize);
// 设置半对角线(HSize)坐标。
// 所有 theHSize 的分量必须是非负的。
下面是 Bnd_B3d 类的使用示例代码,这些示例演示了如何创建、操作和查询 Bnd_B3d 对象。Bnd_B3d 是一个用于定义和操作三维边界盒的类。以下示例展示了如何使用该类的主要功能。

#include <Bnd_B3d.hxx>
#include <gp_XYZ.hxx>
#include <gp_Trsf.hxx>
#include <gp_Pnt.hxx>
#include <Standard_Real.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_EXPORT.hxx>
#include <iostream>

int main() {
    // 创建一个空的 Bnd_B3d 对象
    Bnd_B3d boundingBox1;

    // 创建一个 Bnd_B3d 对象,指定中心和半对角线
    gp_XYZ center1(1.0, 2.0, 3.0);
    gp_XYZ hSize1(4.0, 5.0, 6.0);
    Bnd_B3d boundingBox2(center1, hSize1);

    // 更新盒子,通过一个点
    gp_XYZ newPoint(7.0, 8.0, 9.0);
    boundingBox2.Add(newPoint);

    // 更新盒子,通过另一个 Bnd_B3d 对象
    gp_XYZ center2(2.0, 3.0, 4.0);
    gp_XYZ hSize2(1.0, 1.0, 1.0);
    Bnd_B3d boundingBox3(center2, hSize2);
    boundingBox2.Add(boundingBox3);

    // 查询盒子的下角点和上角点
    gp_XYZ minCorner = boundingBox2.CornerMin();
    gp_XYZ maxCorner = boundingBox2.CornerMax();
    std::cout << "Min Corner: (" << minCorner.X() << ", " << minCorner.Y() << ", " << minCorner.Z() << ")" << std::endl;
    std::cout << "Max Corner: (" << maxCorner.X() << ", " << maxCorner.Y() << ", " << maxCorner.Z() << ")" << std::endl;

    // 检查盒子是否为空
    if (boundingBox2.IsVoid()) {
        std::cout << "BoundingBox is void." << std::endl;
    } else {
        std::cout << "BoundingBox is not void." << std::endl;
    }

    // 扩展盒子
    boundingBox2.Enlarge(2.0);

    // 检查一个点是否在盒子内
    gp_XYZ testPoint(5.0, 6.0, 7.0);
    if (boundingBox2.IsOut(testPoint)) {
        std::cout << "Point is outside the bounding box." << std::endl;
    } else {
        std::cout << "Point is inside the bounding box." << std::endl;
    }

    // 使用变换变换盒子
    gp_Trsf transform;
    transform.SetRotation(gp_Ax1(gp_Pnt(0, 0, 0), gp_Vec(1, 0, 0)), M_PI / 4); // 旋转 45 度
    Bnd_B3d transformedBox = boundingBox2.Transformed(transform);

    // 检查变换后的盒子是否与另一个盒子相交
    if (boundingBox2.IsOut(transformedBox)) {
        std::cout << "Transformed bounding box is outside the original bounding box." << std::endl;
    } else {
        std::cout << "Transformed bounding box intersects with the original bounding box." << std::endl;
    }

    // 设置新的中心和半对角线
    gp_XYZ newCenter(10.0, 10.0, 10.0);
    gp_XYZ newHSize(5.0, 5.0, 5.0);
    boundingBox2.SetCenter(newCenter);
    boundingBox2.SetHSize(newHSize);

    return 0;
}

示例说明:

  1. 创建空的 Bnd_B3d 对象Bnd_B3d boundingBox1; 创建一个默认的、空的边界盒。

  2. 通过中心和半对角线创建 Bnd_B3d 对象Bnd_B3d boundingBox2(center1, hSize1); 使用中心点和半对角线初始化边界盒。

  3. 更新边界盒

    • boundingBox2.Add(newPoint); 通过新点更新边界盒。
    • boundingBox2.Add(boundingBox3); 使用另一个边界盒更新当前边界盒。
  4. 查询边界盒的下角点和上角点:通过 CornerMin()CornerMax() 方法获取。

  5. 检查边界盒是否为空boundingBox2.IsVoid() 判断边界盒是否未初始化。

  6. 扩展边界盒boundingBox2.Enlarge(2.0); 通过指定的差值扩展边界盒的大小。

  7. 检查点是否在边界盒内boundingBox2.IsOut(testPoint) 检查点是否在边界盒外部。

  8. 使用变换变换边界盒boundingBox2.Transformed(transform); 对边界盒应用变换。

  9. 检查变换后的边界盒是否与原边界盒相交boundingBox2.IsOut(transformedBox) 判断两个边界盒是否相交。

  10. 设置新的中心和半对角线:通过 SetCenter()SetHSize() 方法更新边界盒的中心和半对角线尺寸。

这些示例代码展示了 Bnd_B3d 类的基本操作,可以帮助你在实际应用中利用该类处理三维边界盒。

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值