#1803 Use abstract GeometrySerializer as cache to eliminate cyclic dependencies

This commit is contained in:
Thomas Krijnen
2021-10-18 11:38:01 +02:00
parent 4577b7bf60
commit bdc6fcb66f
14 changed files with 54 additions and 26 deletions
+1 -1
View File
@@ -1035,7 +1035,7 @@ namespace IfcGeom {
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) {
read_from_cache = true;
next_triangulation = (TriangulationElement*)from_cache;
@@ -20,7 +20,7 @@
#ifndef GEOMETRYSERIALIZER_H
#define GEOMETRYSERIALIZER_H
#include "../serializers/Serializer.h"
#include "../ifcgeom_schema_agnostic/Serializer.h"
#include "../ifcgeom/IfcGeomElement.h"
class SerializerSettings : public IfcGeom::IteratorSettings
@@ -101,6 +101,8 @@ public:
class GeometrySerializer : public Serializer {
public:
enum read_type { READ_BREP, READ_TRIANGULATION };
GeometrySerializer(const SerializerSettings& settings) : settings_(settings) {}
virtual ~GeometrySerializer() {}
@@ -108,6 +110,7 @@ public:
virtual void write(const IfcGeom::TriangulationElement* o) = 0;
virtual void write(const IfcGeom::BRepElement* o) = 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_; }
SerializerSettings& settings() { return settings_; }
@@ -125,4 +128,13 @@ protected:
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
@@ -138,7 +138,7 @@ namespace IfcGeom {
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
#define ITERATOR_IMPLEMENTATION_H
#include "../ifcgeom_schema_agnostic/IfcGeomFilter.h"
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
#include "../ifcparse/IfcFile.h"
#include "../ifcgeom/IfcGeomIteratorSettings.h"
#include "../serializers/HdfSerializer.h"
#include <gp_XYZ.hxx>
@@ -36,9 +55,9 @@ namespace IfcGeom {
class IteratorImplementation {
protected:
HdfSerializer* cache_ = nullptr;
GeometrySerializer* cache_ = nullptr;
public:
void set_cache(HdfSerializer* cache) { cache_ = cache; }
void set_cache(GeometrySerializer* cache) { cache_ = cache; }
virtual bool initialize() = 0;
virtual void compute_bounds(bool with_geometry) = 0;
+3 -3
View File
@@ -43,13 +43,13 @@
#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/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.
private:
@@ -219,7 +219,7 @@ private:
float unit_magnitude;
public:
ColladaSerializer(const std::string& dae_filename, const SerializerSettings& settings)
: GeometrySerializer(settings)
: WriteOnlyGeometrySerializer(settings)
, exporter("IfcOpenShell", dae_filename, this, settings.precision >= 15)
{
exporter.serializer = this;
+1 -1
View File
@@ -45,7 +45,7 @@ static const uint32_t PRIM_TRIANGLE_STRIP = 5;
static const uint32_t PRIM_TRIANGLE_FAN = 6;
GltfSerializer::GltfSerializer(const std::string& filename, const SerializerSettings& settings)
: GeometrySerializer(settings)
: WriteOnlyGeometrySerializer(settings)
, filename_(filename)
, tmp_filename1_(filename + ".indices.tmp")
, tmp_filename2_(filename + ".vertices.tmp")
+2 -2
View File
@@ -22,14 +22,14 @@
#ifdef WITH_GLTF
#include "../serializers/GeometrySerializer.h"
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
#include <nlohmann/json.hpp>
using json = nlohmann::json;
#include <map>
class GltfSerializer : public GeometrySerializer {
class GltfSerializer : public WriteOnlyGeometrySerializer {
private:
std::string filename_, tmp_filename1_, tmp_filename2_;
std::ofstream fstream_, tmp_fstream1_, tmp_fstream2_;
+1 -4
View File
@@ -28,14 +28,11 @@
#include "H5Cpp.h"
#include "../serializers/GeometrySerializer.h"
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
#define USE_BINARY
class HdfSerializer : public GeometrySerializer {
public:
enum read_type { READ_BREP, READ_TRIANGULATION };
private:
const std::string hdf_filename;
unsigned int vcount_total;
+3 -3
View File
@@ -22,9 +22,9 @@
#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& operator =(const OpenCascadeBasedSerializer&); //N/A
protected:
@@ -32,7 +32,7 @@ protected:
const char* getSymbolForUnitMagnitude(float mag);
public:
explicit OpenCascadeBasedSerializer(const std::string& out_filename, const SerializerSettings& settings)
: GeometrySerializer(settings)
: WriteOnlyGeometrySerializer(settings)
, out_filename(out_filename)
{}
virtual ~OpenCascadeBasedSerializer() {}
+3 -3
View File
@@ -22,7 +22,7 @@
#ifndef SVGSERIALIZER_H
#define SVGSERIALIZER_H
#include "../serializers/GeometrySerializer.h"
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
#include "../serializers/util.h"
#include "../ifcparse/utils.h"
@@ -129,7 +129,7 @@ typedef boost::variant<
Handle(HLRBRep_PolyAlgo)
> hlr_t;
class SvgSerializer : public GeometrySerializer {
class SvgSerializer : public WriteOnlyGeometrySerializer {
public:
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;
@@ -184,7 +184,7 @@ protected:
public:
SvgSerializer(const stream_or_filename& out_filename, const SerializerSettings& settings)
: GeometrySerializer(settings)
: WriteOnlyGeometrySerializer(settings)
, svg_file(out_filename)
, xmin(+std::numeric_limits<double>::infinity())
, ymin(+std::numeric_limits<double>::infinity())
+1 -1
View File
@@ -28,7 +28,7 @@
#include <iomanip>
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)
, mtl_stream(mtl_filename)
, vcount_total(1)
+2 -2
View File
@@ -24,10 +24,10 @@
#include <string>
#include <fstream>
#include "../serializers/GeometrySerializer.h"
#include "../ifcgeom_schema_agnostic/GeometrySerializer.h"
// http://people.sc.fsu.edu/~jburkardt/txt/obj_format.txt
class WaveFrontOBJSerializer : public GeometrySerializer {
class WaveFrontOBJSerializer : public WriteOnlyGeometrySerializer {
private:
stream_or_filename obj_stream;
stream_or_filename mtl_stream;
+1 -1
View File
@@ -1,6 +1,6 @@
#define SCHEMA_METHOD
#include "../serializers/Serializer.h"
#include "../ifcgeom_schema_agnostic/Serializer.h"
#include "../ifcparse/IfcFile.h"
#include <boost/function.hpp>