shared_ptr styles all over #4833

This commit is contained in:
Thomas Krijnen
2024-06-10 20:11:24 +02:00
parent f2074d95fd
commit c01263d721
13 changed files with 97 additions and 93 deletions
+2 -2
View File
@@ -31,9 +31,9 @@
#include <memory>
namespace IfcGeom {
IFC_GEOM_API const ifcopenshell::geometry::taxonomy::style& get_default_style(const std::string& ifc_type);
IFC_GEOM_API const ifcopenshell::geometry::taxonomy::style::ptr& get_default_style(const std::string& ifc_type);
IFC_GEOM_API ifcopenshell::geometry::taxonomy::style& update_default_style(const std::string& ifc_type);
IFC_GEOM_API ifcopenshell::geometry::taxonomy::style::ptr& update_default_style(const std::string& ifc_type);
IFC_GEOM_API void set_default_style_file(const std::string& json_file);
}
+2 -2
View File
@@ -334,10 +334,10 @@ IfcGeom::Representation::Triangulation::Triangulation(const BRep& shape_model)
int surface_style_id = -1;
if (iit->hasStyle()) {
auto jt = std::find(_materials.begin(), _materials.end(), iit->Style());
auto jt = std::find(_materials.begin(), _materials.end(), iit->StylePtr());
if (jt == _materials.end()) {
surface_style_id = (int)_materials.size();
_materials.push_back(iit->Style());
_materials.push_back(iit->StylePtr());
} else {
surface_style_id = (int)(jt - _materials.begin());
}
+3 -3
View File
@@ -108,7 +108,7 @@ namespace IfcGeom {
std::vector<double> _normals;
std::vector<double> uvs_;
std::vector<int> _material_ids;
std::vector<ifcopenshell::geometry::taxonomy::style> _materials;
std::vector<ifcopenshell::geometry::taxonomy::style::ptr> _materials;
std::vector<int> _item_ids;
size_t weld_offset_;
VertexKeyMap welds;
@@ -127,7 +127,7 @@ namespace IfcGeom {
std::vector<double>& uvs() { return uvs_; }
const std::vector<double>& uvs() const { return uvs_; }
const std::vector<int>& material_ids() const { return _material_ids; }
const std::vector<ifcopenshell::geometry::taxonomy::style>& materials() const { return _materials; }
const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>& materials() const { return _materials; }
const std::vector<int>& item_ids() const { return _item_ids; }
Triangulation(const BRep& shape_model);
@@ -142,7 +142,7 @@ namespace IfcGeom {
const std::vector<double>& normals,
const std::vector<double>& uvs,
const std::vector<int>& material_ids,
const std::vector<ifcopenshell::geometry::taxonomy::style>& materials,
const std::vector<ifcopenshell::geometry::taxonomy::style::ptr>& materials,
const std::vector<int>& item_ids
)
: Representation(settings, entity)
+35 -35
View File
@@ -8,48 +8,48 @@
namespace pt = boost::property_tree;
static std::map<std::string, ifcopenshell::geometry::taxonomy::style> default_materials;
static ifcopenshell::geometry::taxonomy::style default_material;
static std::map<std::string, ifcopenshell::geometry::taxonomy::style::ptr> default_materials;
static ifcopenshell::geometry::taxonomy::style::ptr default_material;
static bool default_materials_initialized = false;
void InitDefaultMaterials() {
default_materials.insert(std::make_pair("IfcSite", ifcopenshell::geometry::taxonomy::style("IfcSite")));
default_materials["IfcSite"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.75, 0.8, 0.65);
default_materials.insert(std::make_pair("IfcSite", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcSite")));
default_materials["IfcSite"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.75, 0.8, 0.65);
default_materials.insert(std::make_pair("IfcSlab", ifcopenshell::geometry::taxonomy::style("IfcSlab")));
default_materials["IfcSlab"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.4, 0.4, 0.4);
default_materials.insert(std::make_pair("IfcSlab", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcSlab")));
default_materials["IfcSlab"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.4, 0.4, 0.4);
default_materials.insert(std::make_pair("IfcWallStandardCase", ifcopenshell::geometry::taxonomy::style("IfcWallStandardCase")));
default_materials["IfcWallStandardCase"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.9, 0.9, 0.9);
default_materials.insert(std::make_pair("IfcWallStandardCase", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcWallStandardCase")));
default_materials["IfcWallStandardCase"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.9, 0.9, 0.9);
default_materials.insert(std::make_pair("IfcWall", ifcopenshell::geometry::taxonomy::style("IfcWall")));
default_materials["IfcWall"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.9, 0.9, 0.9);
default_materials.insert(std::make_pair("IfcWall", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcWall")));
default_materials["IfcWall"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.9, 0.9, 0.9);
default_materials.insert(std::make_pair("IfcWindow", ifcopenshell::geometry::taxonomy::style("IfcWindow")));
default_materials["IfcWindow"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.75, 0.8, 0.75);
default_materials["IfcWindow"].transparency = 0.3;
default_materials.insert(std::make_pair("IfcWindow", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcWindow")));
default_materials["IfcWindow"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.75, 0.8, 0.75);
default_materials["IfcWindow"]->transparency = 0.3;
default_materials.insert(std::make_pair("IfcDoor", ifcopenshell::geometry::taxonomy::style("IfcDoor")));
default_materials["IfcDoor"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.55, 0.3, 0.15);
default_materials.insert(std::make_pair("IfcDoor", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcDoor")));
default_materials["IfcDoor"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.55, 0.3, 0.15);
default_materials.insert(std::make_pair("IfcBeam", ifcopenshell::geometry::taxonomy::style("IfcBeam")));
default_materials["IfcBeam"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.75, 0.7, 0.7);
default_materials.insert(std::make_pair("IfcBeam", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcBeam")));
default_materials["IfcBeam"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.75, 0.7, 0.7);
default_materials.insert(std::make_pair("IfcRailing", ifcopenshell::geometry::taxonomy::style("IfcRailing")));
default_materials["IfcRailing"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.65, 0.6, 0.6);
default_materials.insert(std::make_pair("IfcRailing", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcRailing")));
default_materials["IfcRailing"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.65, 0.6, 0.6);
default_materials.insert(std::make_pair("IfcMember", ifcopenshell::geometry::taxonomy::style("IfcMember")));
default_materials["IfcMember"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.65, 0.6, 0.6);
default_materials.insert(std::make_pair("IfcMember", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcMember")));
default_materials["IfcMember"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.65, 0.6, 0.6);
default_materials.insert(std::make_pair("IfcPlate", ifcopenshell::geometry::taxonomy::style("IfcPlate")));
default_materials["IfcPlate"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.8, 0.8, 0.8);
default_materials.insert(std::make_pair("IfcPlate", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcPlate")));
default_materials["IfcPlate"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.8, 0.8, 0.8);
default_materials.insert(std::make_pair("IfcSpace", ifcopenshell::geometry::taxonomy::style("IfcSpace")));
default_materials["IfcSpace"].diffuse = ifcopenshell::geometry::taxonomy::colour(0.65, 0.75, 0.8);
default_materials["IfcSpace"].transparency = 0.8;
default_materials.insert(std::make_pair("IfcSpace", std::make_shared<ifcopenshell::geometry::taxonomy::style>("IfcSpace")));
default_materials["IfcSpace"]->diffuse = ifcopenshell::geometry::taxonomy::colour(0.65, 0.75, 0.8);
default_materials["IfcSpace"]->transparency = 0.8;
default_material = ifcopenshell::geometry::taxonomy::style("DefaultMaterial");
default_material.diffuse = ifcopenshell::geometry::taxonomy::colour(0.7, 0.7, 0.7);
default_material = std::make_shared<ifcopenshell::geometry::taxonomy::style>("DefaultMaterial");
default_material->diffuse = ifcopenshell::geometry::taxonomy::colour(0.7, 0.7, 0.7);
default_materials_initialized = true;
}
@@ -83,20 +83,20 @@ void IfcGeom::set_default_style_file(const std::string& json_file) {
for (pt::ptree::value_type &material_pair : root) {
std::string name = material_pair.first;
default_materials.insert(std::make_pair(name, ifcopenshell::geometry::taxonomy::style(name)));
default_materials.insert(std::make_pair(name, std::make_shared<ifcopenshell::geometry::taxonomy::style>(name)));
pt::ptree material = material_pair.second;
boost::optional<pt::ptree&> diffuse = material.get_child_optional("diffuse");
default_materials[name].diffuse = read_colour_component(diffuse);
default_materials[name]->diffuse = read_colour_component(diffuse);
boost::optional<pt::ptree&> specular = material.get_child_optional("specular");
default_materials[name].specular = read_colour_component(specular);
default_materials[name]->specular = read_colour_component(specular);
if (material.get_child_optional("specular-roughness")) {
default_materials[name].specularity = 1.0 / material.get<double>("specular-roughness");
default_materials[name]->specularity = 1.0 / material.get<double>("specular-roughness");
}
if (material.get_child_optional("transparency")) {
default_materials[name].transparency = material.get<double>("transparency");
default_materials[name]->transparency = material.get<double>("transparency");
}
}
@@ -108,7 +108,7 @@ void IfcGeom::set_default_style_file(const std::string& json_file) {
}
}
const ifcopenshell::geometry::taxonomy::style& IfcGeom::get_default_style(const std::string& s) {
const ifcopenshell::geometry::taxonomy::style::ptr& IfcGeom::get_default_style(const std::string& s) {
static std::mutex m;
std::lock_guard<std::mutex> lk(m);
@@ -121,7 +121,7 @@ const ifcopenshell::geometry::taxonomy::style& IfcGeom::get_default_style(const
return it->second;
}
ifcopenshell::geometry::taxonomy::style& IfcGeom::update_default_style(const std::string& s) {
ifcopenshell::geometry::taxonomy::style::ptr& IfcGeom::update_default_style(const std::string& s) {
if (!default_materials_initialized) InitDefaultMaterials();
auto it = default_materials.find(s);
if (it == default_materials.end()) {