57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
#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
|