/******************************************************************************** * * * This file is part of IfcOpenShell. * * * * IfcOpenShell is free software: you can redistribute it and/or modify * * it under the terms of the Lesser GNU General Public License as published by * * the Free Software Foundation, either version 3.0 of the License, or * * (at your option) any later version. * * * * IfcOpenShell is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * Lesser GNU General Public License for more details. * * * * You should have received a copy of the Lesser GNU General Public License * * along with this program. If not, see . * * * ********************************************************************************/ #ifndef IFCGEOMREPRESENTATION_H #define IFCGEOMREPRESENTATION_H #include #include #include #include #include #include #include #include #include #include #include #include "../ifcgeom_schema_agnostic/IfcGeomIteratorSettings.h" #include "../ifcgeom_schema_agnostic/IfcGeomMaterial.h" #include "../ifcgeom_schema_agnostic/IfcRepresentationShapeItem.h" #include #include namespace IfcGeom { namespace Representation { class IFC_GEOM_API Representation { Representation(const Representation&); //N/A Representation& operator =(const Representation&); //N/A protected: const ElementSettings settings_; public: explicit Representation(const ElementSettings& settings) : settings_(settings) {} const ElementSettings& settings() const { return settings_; } virtual ~Representation() {} }; class IFC_GEOM_API BRep : public Representation { private: std::string id_; const IfcGeom::IfcRepresentationShapeItems shapes_; BRep(const BRep& other); BRep& operator=(const BRep& other); public: BRep(const ElementSettings& settings, const std::string& id, const IfcGeom::IfcRepresentationShapeItems& shapes) : Representation(settings) , id_(id) , shapes_(shapes) {} virtual ~BRep() {} IfcGeom::IfcRepresentationShapeItems::const_iterator begin() const { return shapes_.begin(); } IfcGeom::IfcRepresentationShapeItems::const_iterator end() const { return shapes_.end(); } const IfcGeom::IfcRepresentationShapeItems& shapes() const { return shapes_; } const std::string& id() const { return id_; } TopoDS_Compound as_compound(bool force_meters = false) const; bool calculate_volume(double&) const; bool calculate_surface_area(double&) const; bool calculate_projected_surface_area(const gp_Ax3& ax, double& along_x, double& along_y, double& along_z) const; }; class IFC_GEOM_API Serialization : public Representation { private: std::string id_; std::string brep_data_; std::vector surface_styles_; std::vector surface_style_ids_; public: const std::string& brep_data() const { return brep_data_; } const std::vector& surface_styles() const { return surface_styles_; } const std::vector& surface_style_ids() const { return surface_style_ids_; } Serialization(const BRep& brep); virtual ~Serialization() {} const std::string& id() const { return id_; } private: Serialization(); Serialization(const Serialization&); Serialization& operator=(const Serialization&); }; class Triangulation : public Representation { private: // A tuple of to store as a key in a map. typedef typename std::tuple VertexKey; typedef std::map VertexKeyMap; typedef std::pair Edge; std::string id_; std::vector _verts; std::vector _faces; std::vector _edges; std::vector _normals; std::vector uvs_; std::vector _material_ids; std::vector _materials; std::vector _item_ids; size_t weld_offset_; VertexKeyMap welds; // when read from serialization, the element needs to take ownership of the styles, // the material vector is constructor off of this. // @todo this can be improved std::vector> styles_; public: const std::string& id() const { return id_; } const std::vector& verts() const { return _verts; } const std::vector& faces() const { return _faces; } const std::vector& edges() const { return _edges; } const std::vector& normals() const { return _normals; } const std::vector& uvs() const { return uvs_; } const std::vector& material_ids() const { return _material_ids; } const std::vector& materials() const { return _materials; } const std::vector& item_ids() const { return _item_ids; } Triangulation(const BRep& shape_model); Triangulation( ElementSettings settings, const std::string& id, const std::vector& verts, const std::vector& faces, const std::vector& edges, const std::vector& normals, const std::vector& uvs, const std::vector& material_ids, const std::vector>& styles, const std::vector& item_ids) : Representation(settings) , id_(id) , _verts(verts) , _faces(faces) , _edges(edges) , _normals(normals) , uvs_(uvs) , _material_ids(material_ids) , _item_ids(item_ids) , styles_(styles) { for (auto& s : styles_) { _materials.push_back(IfcGeom::Material(s)); } } virtual ~Triangulation() {} /// Generates UVs for a single mesh using box projection. /// @todo Very simple impl. Assumes that input vertices and normals match 1:1. static std::vector box_project_uvs(const std::vector &vertices, const std::vector &normals); private: /// Welds vertices that belong to different faces int addVertex(int item_index, int material_index, const gp_XYZ& p); void addEdge(int n1, int n2, std::map, int>& edgecount); Triangulation(); Triangulation(const Triangulation&); Triangulation& operator=(const Triangulation&); }; } } #endif