Files
ViewDesignEngine/include/vde/brep/parallel_boolean.h
T
茂之钳 cf38d76fd0
CI / Build & Test (push) Failing after 16m56s
CI / Release Build (push) Failing after 24s
Build & Test / build-and-test (push) Has been cancelled
Build & Test / python-bindings (push) Has been cancelled
feat(v4.6): memory pool + parallel boolean/MC/intersection + GMP exact predicates
M1 — Memory Pool (内存池):
- ObjectPool<T>: O(1) acquire/release with free-list, chunk-based expansion
- ThreadSafeObjectPool<T>: per-thread local pools with global fallback
- CowPtr<T>: copy-on-write smart pointer with shallow/deep copy
- 10 tests: single/multi-thread, CoW detach, reuse rate

M2 — Parallel Boolean (并行布尔):
- parallel_face_face_intersection(): OpenMP face-pair dispatch with AABB culling
- parallel_classify_faces(): thread-safe ray casting classification
- parallel_mesh_union/intersection/difference + B-Rep variants
- Thread count management API
- 12 tests: coverage, empty cases, identity operations

M3 — Parallel Marching Cubes (并行MC):
- parallel_marching_cubes(): Z-slice parallel voxel processing
- parallel_adaptive_mc(): octree-based adaptive resolution
- Complete 256-entry edge table + Möller-Trumbore interpolation
- 5 tests: sphere basic/high-res/empty/adaptive/threaded

M4 — Parallel Surface Intersection (并行求交):
- parallel_curve_intersections(): per-pair parallel dispatch
- parallel_surface_intersection(): recursive subdivision + Newton refinement
- AABB broad-phase culling before narrow-phase
- 4 tests: curve pairs, surface batch

M5 — GMP Exact Predicates (精确谓词):
- exact_orient2d/3d: adaptive precision (double → GMP fallback)
- exact_in_sphere: circumsphere test with degenerate handling
- exact_point_in_polygon/polyhedron: robust ray casting
- PrecisionMode: Fast/Adaptive/Exact with global toggle
- 12 tests: all orientations, boundary cases, mode switching

21 files, +2263 lines
2026-07-26 17:28:15 +08:00

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