feat(v3.9): parallel OpenMP boolean + assembly instancing + update notifier
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
#include "vde/brep/assembly.h"
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vde::brep {
|
||||
|
||||
/// Shared geometry instance (for repeated parts)
|
||||
struct GeometryInstance {
|
||||
std::string part_name;
|
||||
BrepModel geometry; ///< shared geometry data
|
||||
size_t use_count = 0; ///< number of references to this geometry
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Instance manager for large assemblies.
|
||||
*
|
||||
* Deduplicates repeated parts by reusing shared geometry.
|
||||
* Reduces memory and improves cache coherence for assemblies
|
||||
* with thousands of identical components (fasteners, links, panels).
|
||||
*
|
||||
* @ingroup brep
|
||||
*/
|
||||
class AssemblyInstancer {
|
||||
public:
|
||||
/**
|
||||
* @brief Register a geometry for instancing.
|
||||
* @param name Part name identifier
|
||||
* @param geom Geometry to register
|
||||
* @return instance ID, reuses existing if same name & geometry matches
|
||||
*/
|
||||
int register_instance(const std::string& name, const BrepModel& geom);
|
||||
|
||||
/**
|
||||
* @brief Create an occurrence of a registered instance.
|
||||
* @param assy Target assembly
|
||||
* @param parent Parent node (nullptr = root)
|
||||
* @param instance_id Instance to place
|
||||
* @param transform Local transform for this occurrence
|
||||
*/
|
||||
void place_instance(Assembly& assy, AssemblyNode* parent,
|
||||
int instance_id, const Transform3D& transform);
|
||||
|
||||
/// Total unique geometries
|
||||
[[nodiscard]] size_t unique_count() const { return instances_.size(); }
|
||||
|
||||
/// Total placed occurrences
|
||||
[[nodiscard]] size_t total_placed() const { return total_placed_; }
|
||||
|
||||
private:
|
||||
std::vector<GeometryInstance> instances_;
|
||||
size_t total_placed_ = 0;
|
||||
};
|
||||
|
||||
} // namespace vde::brep
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include "vde/brep/feature_tree.h"
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace vde::brep {
|
||||
|
||||
/// Callback type for model changes.
|
||||
/// Receives the feature name and the new model after rebuild.
|
||||
using UpdateCallback = std::function<void(const std::string& feature_name, const BrepModel& new_model)>;
|
||||
|
||||
/**
|
||||
* @brief Notifies listeners when features change.
|
||||
*
|
||||
* Integrates with FeatureHistory: after each apply/undo/redo,
|
||||
* call notify() to push the updated model to all registered callbacks.
|
||||
*
|
||||
* @ingroup brep
|
||||
*/
|
||||
class UpdateNotifier {
|
||||
public:
|
||||
/// Register a callback. Called on every notify().
|
||||
void on_update(UpdateCallback cb) { callbacks_.push_back(std::move(cb)); }
|
||||
|
||||
/// Notify all registered listeners.
|
||||
void notify(const std::string& feature, const BrepModel& model) {
|
||||
for (auto& cb : callbacks_) cb(feature, model);
|
||||
}
|
||||
|
||||
/// Remove all callbacks.
|
||||
void clear() { callbacks_.clear(); }
|
||||
|
||||
/// Number of registered callbacks.
|
||||
[[nodiscard]] size_t listener_count() const { return callbacks_.size(); }
|
||||
|
||||
private:
|
||||
std::vector<UpdateCallback> callbacks_;
|
||||
};
|
||||
|
||||
} // namespace vde::brep
|
||||
Reference in New Issue
Block a user