118 lines
4.1 KiB
C++
118 lines
4.1 KiB
C++
|
|
#pragma once
|
||
|
|
/**
|
||
|
|
* @file parallel_boolean.h
|
||
|
|
* @brief 并行布尔运算
|
||
|
|
*
|
||
|
|
* OpenMP 并行化:面-面求交、射线分类、网格构建。
|
||
|
|
* 串行兼容(OpenMP 不可用时退化到串行)。
|
||
|
|
*
|
||
|
|
* @ingroup brep
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include "vde/brep/brep.h"
|
||
|
|
#include "vde/mesh/halfedge_mesh.h"
|
||
|
|
#include <vector>
|
||
|
|
#include <functional>
|
||
|
|
|
||
|
|
namespace vde::brep {
|
||
|
|
|
||
|
|
// ═══════════════════════════════════════════════════════════
|
||
|
|
// Parallel Face-Face Intersection
|
||
|
|
// ═══════════════════════════════════════════════════════════
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief 并行计算两实体所有面对的交线
|
||
|
|
*
|
||
|
|
* 外层循环用 OpenMP parallel for 分发面对,内层为单对求交。
|
||
|
|
* 结果线程安全合并。
|
||
|
|
*
|
||
|
|
* @param a 实体 A
|
||
|
|
* @param b 实体 B
|
||
|
|
* @return 所有交线段的集合(每条交线段为 {起点, 终点})
|
||
|
|
*/
|
||
|
|
[[nodiscard]] std::vector<std::pair<core::Point3D, core::Point3D>>
|
||
|
|
parallel_face_face_intersection(const BrepModel& a, const BrepModel& b);
|
||
|
|
|
||
|
|
// ═══════════════════════════════════════════════════════════
|
||
|
|
// Parallel Classification
|
||
|
|
// ═══════════════════════════════════════════════════════════
|
||
|
|
|
||
|
|
/// 面分类结果
|
||
|
|
enum class FaceClassification {
|
||
|
|
Inside, ///< 面在另一实体内部
|
||
|
|
Outside, ///< 面在另一实体外部
|
||
|
|
OnBoundary, ///< 面在边界上
|
||
|
|
Unknown, ///< 无法确定
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief 并行对面进行分类(IN/OUT/ON 判定)
|
||
|
|
*
|
||
|
|
* 每个面独立射线投射测试,线程安全。
|
||
|
|
*
|
||
|
|
* @param faces 待分类的面ID列表
|
||
|
|
* @param body 目标实体
|
||
|
|
* @return face_id → 分类结果
|
||
|
|
*/
|
||
|
|
[[nodiscard]] std::vector<FaceClassification>
|
||
|
|
parallel_classify_faces(const BrepModel& body,
|
||
|
|
const std::vector<int>& face_ids);
|
||
|
|
|
||
|
|
// ═══════════════════════════════════════════════════════════
|
||
|
|
// Parallel Boolean Operations
|
||
|
|
// ═══════════════════════════════════════════════════════════
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief 并行网格布尔并集
|
||
|
|
*
|
||
|
|
* @param a 实体 A 的网格
|
||
|
|
* @param b 实体 B 的网格
|
||
|
|
* @return 并集网格
|
||
|
|
*/
|
||
|
|
[[nodiscard]] mesh::HalfedgeMesh parallel_mesh_union(
|
||
|
|
const mesh::HalfedgeMesh& a, const mesh::HalfedgeMesh& b);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief 并行网格布尔交集
|
||
|
|
*/
|
||
|
|
[[nodiscard]] mesh::HalfedgeMesh parallel_mesh_intersection(
|
||
|
|
const mesh::HalfedgeMesh& a, const mesh::HalfedgeMesh& b);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief 并行网格布尔差集 (A - B)
|
||
|
|
*/
|
||
|
|
[[nodiscard]] mesh::HalfedgeMesh parallel_mesh_difference(
|
||
|
|
const mesh::HalfedgeMesh& a, const mesh::HalfedgeMesh& b);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief 并行 B-Rep 布尔并集
|
||
|
|
*
|
||
|
|
* 完整管线:平行面-面求交 → 平行分类 → 缝合
|
||
|
|
*/
|
||
|
|
[[nodiscard]] BrepModel parallel_brep_union(
|
||
|
|
const BrepModel& a, const BrepModel& b);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief 并行 B-Rep 布尔交集
|
||
|
|
*/
|
||
|
|
[[nodiscard]] BrepModel parallel_brep_intersection(
|
||
|
|
const BrepModel& a, const BrepModel& b);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief 并行 B-Rep 布尔差集 (A - B)
|
||
|
|
*/
|
||
|
|
[[nodiscard]] BrepModel parallel_brep_difference(
|
||
|
|
const BrepModel& a, const BrepModel& b);
|
||
|
|
|
||
|
|
// ═══════════════════════════════════════════════════════════
|
||
|
|
// Performance helpers
|
||
|
|
// ═══════════════════════════════════════════════════════════
|
||
|
|
|
||
|
|
/// 获取可用线程数
|
||
|
|
[[nodiscard]] int parallel_thread_count();
|
||
|
|
|
||
|
|
/// 设置并行线程数(0 = 自动)
|
||
|
|
void set_parallel_threads(int n);
|
||
|
|
|
||
|
|
} // namespace vde::brep
|