mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-17 14:02:27 +00:00
#1803 Use abstract GeometrySerializer as cache to eliminate cyclic dependencies
This commit is contained in:
@@ -1035,7 +1035,7 @@ namespace IfcGeom {
|
|||||||
gid2 = gid2.substr(0, hyphen);
|
gid2 = gid2.substr(0, hyphen);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto from_cache = cache_->read(*ifc_file, next_shape_model->guid(), boost::lexical_cast<int>(gid2), HdfSerializer::READ_TRIANGULATION);
|
auto from_cache = cache_->read(*ifc_file, next_shape_model->guid(), boost::lexical_cast<int>(gid2), GeometrySerializer::READ_TRIANGULATION);
|
||||||
if (from_cache) {
|
if (from_cache) {
|
||||||
read_from_cache = true;
|
read_from_cache = true;
|
||||||
next_triangulation = (TriangulationElement*)from_cache;
|
next_triangulation = (TriangulationElement*)from_cache;
|
||||||
|
|||||||
+13
-1
@@ -20,7 +20,7 @@
|
|||||||
#ifndef GEOMETRYSERIALIZER_H
|
#ifndef GEOMETRYSERIALIZER_H
|
||||||
#define GEOMETRYSERIALIZER_H
|
#define GEOMETRYSERIALIZER_H
|
||||||
|
|
||||||
#include "../serializers/Serializer.h"
|
#include "../ifcgeom_schema_agnostic/Serializer.h"
|
||||||
#include "../ifcgeom/IfcGeomElement.h"
|
#include "../ifcgeom/IfcGeomElement.h"
|
||||||
|
|
||||||
class SerializerSettings : public IfcGeom::IteratorSettings
|
class SerializerSettings : public IfcGeom::IteratorSettings
|
||||||
@@ -101,6 +101,8 @@ public:
|
|||||||
|
|
||||||
class GeometrySerializer : public Serializer {
|
class GeometrySerializer : public Serializer {
|
||||||
public:
|
public:
|
||||||
|
enum read_type { READ_BREP, READ_TRIANGULATION };
|
||||||
|
|
||||||
GeometrySerializer(const SerializerSettings& settings) : settings_(settings) {}
|
GeometrySerializer(const SerializerSettings& settings) : settings_(settings) {}
|
||||||
virtual ~GeometrySerializer() {}
|
virtual ~GeometrySerializer() {}
|
||||||
|
|
||||||
@@ -108,6 +110,7 @@ public:
|
|||||||
virtual void write(const IfcGeom::TriangulationElement* o) = 0;
|
virtual void write(const IfcGeom::TriangulationElement* o) = 0;
|
||||||
virtual void write(const IfcGeom::BRepElement* o) = 0;
|
virtual void write(const IfcGeom::BRepElement* o) = 0;
|
||||||
virtual void setUnitNameAndMagnitude(const std::string& name, float magnitude) = 0;
|
virtual void setUnitNameAndMagnitude(const std::string& name, float magnitude) = 0;
|
||||||
|
virtual const IfcGeom::Element* read(IfcParse::IfcFile& f, const std::string& guid, unsigned int representation_id, read_type rt = READ_BREP) = 0;
|
||||||
|
|
||||||
const SerializerSettings& settings() const { return settings_; }
|
const SerializerSettings& settings() const { return settings_; }
|
||||||
SerializerSettings& settings() { return settings_; }
|
SerializerSettings& settings() { return settings_; }
|
||||||
@@ -125,4 +128,13 @@ protected:
|
|||||||
SerializerSettings settings_;
|
SerializerSettings settings_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class WriteOnlyGeometrySerializer : public GeometrySerializer {
|
||||||
|
public:
|
||||||
|
WriteOnlyGeometrySerializer(const SerializerSettings& settings) : GeometrySerializer(settings) {}
|
||||||
|
|
||||||
|
virtual const IfcGeom::Element* read(IfcParse::IfcFile&, const std::string&, unsigned int, read_type = READ_BREP) {
|
||||||
|
throw std::runtime_error("Not supported");
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -138,7 +138,7 @@ namespace IfcGeom {
|
|||||||
|
|
||||||
IfcUtil::IfcBaseClass* create() { return implementation_->create(); }
|
IfcUtil::IfcBaseClass* create() { return implementation_->create(); }
|
||||||
|
|
||||||
void set_cache(HdfSerializer* cache) { return implementation_->set_cache(cache); }
|
void set_cache(GeometrySerializer* cache) { return implementation_->set_cache(cache); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,29 @@
|
|||||||
|
/********************************************************************************
|
||||||
|
* *
|
||||||
|
* 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 <http://www.gnu.org/licenses/>. *
|
||||||
|
* *
|
||||||
|
********************************************************************************/
|
||||||
|
|
||||||
#ifndef ITERATOR_IMPLEMENTATION_H
|
#ifndef ITERATOR_IMPLEMENTATION_H
|
||||||
#define ITERATOR_IMPLEMENTATION_H
|
#define ITERATOR_IMPLEMENTATION_H
|
||||||
|
|
||||||
#include "../ifcgeom_schema_agnostic/IfcGeomFilter.h"
|
#include "../ifcgeom_schema_agnostic/IfcGeomFilter.h"
|
||||||
|
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
|
||||||
#include "../ifcparse/IfcFile.h"
|
#include "../ifcparse/IfcFile.h"
|
||||||
#include "../ifcgeom/IfcGeomIteratorSettings.h"
|
#include "../ifcgeom/IfcGeomIteratorSettings.h"
|
||||||
#include "../serializers/HdfSerializer.h"
|
|
||||||
|
|
||||||
#include <gp_XYZ.hxx>
|
#include <gp_XYZ.hxx>
|
||||||
|
|
||||||
@@ -36,9 +55,9 @@ namespace IfcGeom {
|
|||||||
|
|
||||||
class IteratorImplementation {
|
class IteratorImplementation {
|
||||||
protected:
|
protected:
|
||||||
HdfSerializer* cache_ = nullptr;
|
GeometrySerializer* cache_ = nullptr;
|
||||||
public:
|
public:
|
||||||
void set_cache(HdfSerializer* cache) { cache_ = cache; }
|
void set_cache(GeometrySerializer* cache) { cache_ = cache; }
|
||||||
|
|
||||||
virtual bool initialize() = 0;
|
virtual bool initialize() = 0;
|
||||||
virtual void compute_bounds(bool with_geometry) = 0;
|
virtual void compute_bounds(bool with_geometry) = 0;
|
||||||
|
|||||||
@@ -43,13 +43,13 @@
|
|||||||
|
|
||||||
#include "../ifcgeom_schema_agnostic/IfcGeomIterator.h"
|
#include "../ifcgeom_schema_agnostic/IfcGeomIterator.h"
|
||||||
|
|
||||||
#include "../serializers/GeometrySerializer.h"
|
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
|
||||||
|
|
||||||
#include <boost/numeric/ublas/matrix.hpp>
|
#include <boost/numeric/ublas/matrix.hpp>
|
||||||
#include <boost/numeric/ublas/io.hpp>
|
#include <boost/numeric/ublas/io.hpp>
|
||||||
|
|
||||||
|
|
||||||
class ColladaSerializer : public GeometrySerializer
|
class ColladaSerializer : public WriteOnlyGeometrySerializer
|
||||||
{
|
{
|
||||||
// TODO The vast amount of implement details of ColladaSerializer could be hidden to the cpp file.
|
// TODO The vast amount of implement details of ColladaSerializer could be hidden to the cpp file.
|
||||||
private:
|
private:
|
||||||
@@ -219,7 +219,7 @@ private:
|
|||||||
float unit_magnitude;
|
float unit_magnitude;
|
||||||
public:
|
public:
|
||||||
ColladaSerializer(const std::string& dae_filename, const SerializerSettings& settings)
|
ColladaSerializer(const std::string& dae_filename, const SerializerSettings& settings)
|
||||||
: GeometrySerializer(settings)
|
: WriteOnlyGeometrySerializer(settings)
|
||||||
, exporter("IfcOpenShell", dae_filename, this, settings.precision >= 15)
|
, exporter("IfcOpenShell", dae_filename, this, settings.precision >= 15)
|
||||||
{
|
{
|
||||||
exporter.serializer = this;
|
exporter.serializer = this;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ static const uint32_t PRIM_TRIANGLE_STRIP = 5;
|
|||||||
static const uint32_t PRIM_TRIANGLE_FAN = 6;
|
static const uint32_t PRIM_TRIANGLE_FAN = 6;
|
||||||
|
|
||||||
GltfSerializer::GltfSerializer(const std::string& filename, const SerializerSettings& settings)
|
GltfSerializer::GltfSerializer(const std::string& filename, const SerializerSettings& settings)
|
||||||
: GeometrySerializer(settings)
|
: WriteOnlyGeometrySerializer(settings)
|
||||||
, filename_(filename)
|
, filename_(filename)
|
||||||
, tmp_filename1_(filename + ".indices.tmp")
|
, tmp_filename1_(filename + ".indices.tmp")
|
||||||
, tmp_filename2_(filename + ".vertices.tmp")
|
, tmp_filename2_(filename + ".vertices.tmp")
|
||||||
|
|||||||
@@ -22,14 +22,14 @@
|
|||||||
|
|
||||||
#ifdef WITH_GLTF
|
#ifdef WITH_GLTF
|
||||||
|
|
||||||
#include "../serializers/GeometrySerializer.h"
|
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class GltfSerializer : public GeometrySerializer {
|
class GltfSerializer : public WriteOnlyGeometrySerializer {
|
||||||
private:
|
private:
|
||||||
std::string filename_, tmp_filename1_, tmp_filename2_;
|
std::string filename_, tmp_filename1_, tmp_filename2_;
|
||||||
std::ofstream fstream_, tmp_fstream1_, tmp_fstream2_;
|
std::ofstream fstream_, tmp_fstream1_, tmp_fstream2_;
|
||||||
|
|||||||
@@ -28,14 +28,11 @@
|
|||||||
|
|
||||||
#include "H5Cpp.h"
|
#include "H5Cpp.h"
|
||||||
|
|
||||||
#include "../serializers/GeometrySerializer.h"
|
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
|
||||||
|
|
||||||
#define USE_BINARY
|
#define USE_BINARY
|
||||||
|
|
||||||
class HdfSerializer : public GeometrySerializer {
|
class HdfSerializer : public GeometrySerializer {
|
||||||
public:
|
|
||||||
enum read_type { READ_BREP, READ_TRIANGULATION };
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string hdf_filename;
|
const std::string hdf_filename;
|
||||||
unsigned int vcount_total;
|
unsigned int vcount_total;
|
||||||
|
|||||||
@@ -22,9 +22,9 @@
|
|||||||
|
|
||||||
#include "../ifcgeom_schema_agnostic/IfcGeomIterator.h"
|
#include "../ifcgeom_schema_agnostic/IfcGeomIterator.h"
|
||||||
|
|
||||||
#include "../serializers/GeometrySerializer.h"
|
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
|
||||||
|
|
||||||
class OpenCascadeBasedSerializer : public GeometrySerializer {
|
class OpenCascadeBasedSerializer : public WriteOnlyGeometrySerializer {
|
||||||
OpenCascadeBasedSerializer(const OpenCascadeBasedSerializer&); //N/A
|
OpenCascadeBasedSerializer(const OpenCascadeBasedSerializer&); //N/A
|
||||||
OpenCascadeBasedSerializer& operator =(const OpenCascadeBasedSerializer&); //N/A
|
OpenCascadeBasedSerializer& operator =(const OpenCascadeBasedSerializer&); //N/A
|
||||||
protected:
|
protected:
|
||||||
@@ -32,7 +32,7 @@ protected:
|
|||||||
const char* getSymbolForUnitMagnitude(float mag);
|
const char* getSymbolForUnitMagnitude(float mag);
|
||||||
public:
|
public:
|
||||||
explicit OpenCascadeBasedSerializer(const std::string& out_filename, const SerializerSettings& settings)
|
explicit OpenCascadeBasedSerializer(const std::string& out_filename, const SerializerSettings& settings)
|
||||||
: GeometrySerializer(settings)
|
: WriteOnlyGeometrySerializer(settings)
|
||||||
, out_filename(out_filename)
|
, out_filename(out_filename)
|
||||||
{}
|
{}
|
||||||
virtual ~OpenCascadeBasedSerializer() {}
|
virtual ~OpenCascadeBasedSerializer() {}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
#ifndef SVGSERIALIZER_H
|
#ifndef SVGSERIALIZER_H
|
||||||
#define SVGSERIALIZER_H
|
#define SVGSERIALIZER_H
|
||||||
|
|
||||||
#include "../serializers/GeometrySerializer.h"
|
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
|
||||||
#include "../serializers/util.h"
|
#include "../serializers/util.h"
|
||||||
|
|
||||||
#include "../ifcparse/utils.h"
|
#include "../ifcparse/utils.h"
|
||||||
@@ -129,7 +129,7 @@ typedef boost::variant<
|
|||||||
Handle(HLRBRep_PolyAlgo)
|
Handle(HLRBRep_PolyAlgo)
|
||||||
> hlr_t;
|
> hlr_t;
|
||||||
|
|
||||||
class SvgSerializer : public GeometrySerializer {
|
class SvgSerializer : public WriteOnlyGeometrySerializer {
|
||||||
public:
|
public:
|
||||||
typedef std::pair<std::string, std::vector<util::string_buffer> > path_object;
|
typedef std::pair<std::string, std::vector<util::string_buffer> > path_object;
|
||||||
typedef std::vector< boost::shared_ptr<util::string_buffer::float_item> > float_item_list;
|
typedef std::vector< boost::shared_ptr<util::string_buffer::float_item> > float_item_list;
|
||||||
@@ -184,7 +184,7 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
SvgSerializer(const stream_or_filename& out_filename, const SerializerSettings& settings)
|
SvgSerializer(const stream_or_filename& out_filename, const SerializerSettings& settings)
|
||||||
: GeometrySerializer(settings)
|
: WriteOnlyGeometrySerializer(settings)
|
||||||
, svg_file(out_filename)
|
, svg_file(out_filename)
|
||||||
, xmin(+std::numeric_limits<double>::infinity())
|
, xmin(+std::numeric_limits<double>::infinity())
|
||||||
, ymin(+std::numeric_limits<double>::infinity())
|
, ymin(+std::numeric_limits<double>::infinity())
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
WaveFrontOBJSerializer::WaveFrontOBJSerializer(const stream_or_filename& obj_filename, const stream_or_filename& mtl_filename, const SerializerSettings& settings)
|
WaveFrontOBJSerializer::WaveFrontOBJSerializer(const stream_or_filename& obj_filename, const stream_or_filename& mtl_filename, const SerializerSettings& settings)
|
||||||
: GeometrySerializer(settings)
|
: WriteOnlyGeometrySerializer(settings)
|
||||||
, obj_stream(obj_filename)
|
, obj_stream(obj_filename)
|
||||||
, mtl_stream(mtl_filename)
|
, mtl_stream(mtl_filename)
|
||||||
, vcount_total(1)
|
, vcount_total(1)
|
||||||
|
|||||||
@@ -24,10 +24,10 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include "../serializers/GeometrySerializer.h"
|
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
|
||||||
|
|
||||||
// http://people.sc.fsu.edu/~jburkardt/txt/obj_format.txt
|
// http://people.sc.fsu.edu/~jburkardt/txt/obj_format.txt
|
||||||
class WaveFrontOBJSerializer : public GeometrySerializer {
|
class WaveFrontOBJSerializer : public WriteOnlyGeometrySerializer {
|
||||||
private:
|
private:
|
||||||
stream_or_filename obj_stream;
|
stream_or_filename obj_stream;
|
||||||
stream_or_filename mtl_stream;
|
stream_or_filename mtl_stream;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#define SCHEMA_METHOD
|
#define SCHEMA_METHOD
|
||||||
|
|
||||||
#include "../serializers/Serializer.h"
|
#include "../ifcgeom_schema_agnostic/Serializer.h"
|
||||||
#include "../ifcparse/IfcFile.h"
|
#include "../ifcparse/IfcFile.h"
|
||||||
|
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
|||||||
Reference in New Issue
Block a user