mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 02:31:09 +00:00
Compile-time options to manipulate caching behaviour
This commit is contained in:
+23
-1
@@ -46,22 +46,35 @@
|
|||||||
#include "../ifcgeom/IfcRepresentationShapeItem.h"
|
#include "../ifcgeom/IfcRepresentationShapeItem.h"
|
||||||
#include "../ifcgeom/IfcGeomShapeType.h"
|
#include "../ifcgeom/IfcGeomShapeType.h"
|
||||||
|
|
||||||
|
#define NO_CACHE
|
||||||
|
|
||||||
|
#ifdef NO_CACHE
|
||||||
|
|
||||||
|
#define IN_CACHE(T,E,t,e)
|
||||||
|
#define CACHE(T,E,e)
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
#define IN_CACHE(T,E,t,e) std::map<int,t>::const_iterator it = cache.T.find(E->entity->id());\
|
#define IN_CACHE(T,E,t,e) std::map<int,t>::const_iterator it = cache.T.find(E->entity->id());\
|
||||||
if ( it != cache.T.end() ) { e = it->second; return true; }
|
if ( it != cache.T.end() ) { e = it->second; return true; }
|
||||||
#define CACHE(T,E,e) cache.T[E->entity->id()] = e;
|
#define CACHE(T,E,e) cache.T[E->entity->id()] = e;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace IfcGeom {
|
namespace IfcGeom {
|
||||||
|
|
||||||
class Cache {
|
class Cache {
|
||||||
public:
|
public:
|
||||||
#include "IfcRegisterCreateCache.h"
|
#include "IfcRegisterCreateCache.h"
|
||||||
std::map<int, SurfaceStyle> Style;
|
|
||||||
std::map<int, TopoDS_Shape> Shape;
|
std::map<int, TopoDS_Shape> Shape;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Kernel {
|
class Kernel {
|
||||||
private:
|
private:
|
||||||
|
#ifndef NO_CACHE
|
||||||
Cache cache;
|
Cache cache;
|
||||||
|
#endif
|
||||||
|
std::map<int, SurfaceStyle> style_cache;
|
||||||
public:
|
public:
|
||||||
// Tolerances and settings for various geometrical operations:
|
// Tolerances and settings for various geometrical operations:
|
||||||
enum GeomValue {
|
enum GeomValue {
|
||||||
@@ -182,6 +195,15 @@ public:
|
|||||||
return std::make_pair<IfcSchema::IfcSurfaceStyle*, T*>(0,0);
|
return std::make_pair<IfcSchema::IfcSurfaceStyle*, T*>(0,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void purge_cache() {
|
||||||
|
// Rather hack-ish, but a stopgap solution to keep memory under control
|
||||||
|
// for large files. SurfaceStyles need to be kept at all costs, as they
|
||||||
|
// are read later on when serializing Collada files.
|
||||||
|
#ifndef NO_CACHE
|
||||||
|
cache = Cache();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#include "IfcRegisterGeomHeader.h"
|
#include "IfcRegisterGeomHeader.h"
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -283,6 +283,9 @@ namespace IfcGeom {
|
|||||||
private:
|
private:
|
||||||
// Move to the next IfcRepresentation
|
// Move to the next IfcRepresentation
|
||||||
void _nextShape() {
|
void _nextShape() {
|
||||||
|
if (done % 100 == 99) {
|
||||||
|
// kernel.purge_cache();
|
||||||
|
}
|
||||||
ifcproducts.reset();
|
ifcproducts.reset();
|
||||||
++ representation_iterator;
|
++ representation_iterator;
|
||||||
++ done;
|
++ done;
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ const IfcGeom::SurfaceStyle* IfcGeom::Kernel::get_style(const IfcSchema::IfcRepr
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int surface_style_id = shading_styles.first->entity->id();
|
int surface_style_id = shading_styles.first->entity->id();
|
||||||
std::map<int,SurfaceStyle>::const_iterator it = cache.Style.find(surface_style_id);
|
std::map<int,SurfaceStyle>::const_iterator it = style_cache.find(surface_style_id);
|
||||||
if (it != cache.Style.end()) {
|
if (it != style_cache.end()) {
|
||||||
return &(it->second);
|
return &(it->second);
|
||||||
}
|
}
|
||||||
SurfaceStyle surface_style;
|
SurfaceStyle surface_style;
|
||||||
@@ -104,7 +104,7 @@ const IfcGeom::SurfaceStyle* IfcGeom::Kernel::get_style(const IfcSchema::IfcRepr
|
|||||||
surface_style.Transparency().reset(d);
|
surface_style.Transparency().reset(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &(cache.Style[surface_style_id] = surface_style);
|
return &(style_cache[surface_style_id] = surface_style);
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::map<std::string, IfcGeom::SurfaceStyle> default_materials;
|
static std::map<std::string, IfcGeom::SurfaceStyle> default_materials;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace IfcGeom {
|
|||||||
double& B() { return data[2]; }
|
double& B() { return data[2]; }
|
||||||
};
|
};
|
||||||
private:
|
private:
|
||||||
boost::optional<std::string> name;
|
std::string name;
|
||||||
boost::optional<int> id;
|
boost::optional<int> id;
|
||||||
boost::optional<ColorComponent> diffuse, specular;
|
boost::optional<ColorComponent> diffuse, specular;
|
||||||
boost::optional<double> transparency;
|
boost::optional<double> transparency;
|
||||||
@@ -73,16 +73,10 @@ namespace IfcGeom {
|
|||||||
// pointer addresses of the styles, as they are always referenced
|
// pointer addresses of the styles, as they are always referenced
|
||||||
// from out of a global map of some sort.
|
// from out of a global map of some sort.
|
||||||
bool operator==(const SurfaceStyle& other) {
|
bool operator==(const SurfaceStyle& other) {
|
||||||
if (name && other.name) {
|
return name == other.name;
|
||||||
return *name == *other.name;
|
|
||||||
} else if (id && other.id) {
|
|
||||||
return *id == *other.id;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& Name() const { return *name; }
|
const std::string& Name() const { return name; }
|
||||||
|
|
||||||
const boost::optional<ColorComponent>& Diffuse() const { return diffuse; }
|
const boost::optional<ColorComponent>& Diffuse() const { return diffuse; }
|
||||||
const boost::optional<ColorComponent>& Specular() const { return specular; }
|
const boost::optional<ColorComponent>& Specular() const { return specular; }
|
||||||
|
|||||||
@@ -49,8 +49,10 @@ bool IfcGeom::Kernel::convert_shape(const IfcBaseClass* l, TopoDS_Shape& r) {
|
|||||||
bool processed = false;
|
bool processed = false;
|
||||||
bool ignored = false;
|
bool ignored = false;
|
||||||
|
|
||||||
|
#ifndef NO_CACHE
|
||||||
std::map<int,TopoDS_Shape>::const_iterator it = cache.Shape.find(id);
|
std::map<int,TopoDS_Shape>::const_iterator it = cache.Shape.find(id);
|
||||||
if ( it != cache.Shape.end() ) { r = it->second; return true; }
|
if ( it != cache.Shape.end() ) { r = it->second; return true; }
|
||||||
|
#endif
|
||||||
const bool include_curves = getValue(GV_DIMENSIONALITY) != +1;
|
const bool include_curves = getValue(GV_DIMENSIONALITY) != +1;
|
||||||
const bool include_solids_and_surfaces = getValue(GV_DIMENSIONALITY) != -1;
|
const bool include_solids_and_surfaces = getValue(GV_DIMENSIONALITY) != -1;
|
||||||
|
|
||||||
@@ -85,7 +87,9 @@ bool IfcGeom::Kernel::convert_shape(const IfcBaseClass* l, TopoDS_Shape& r) {
|
|||||||
if ( processed && success ) {
|
if ( processed && success ) {
|
||||||
const double precision = getValue(GV_PRECISION);
|
const double precision = getValue(GV_PRECISION);
|
||||||
apply_tolerance(r, precision);
|
apply_tolerance(r, precision);
|
||||||
|
#ifndef NO_CACHE
|
||||||
cache.Shape[id] = r;
|
cache.Shape[id] = r;
|
||||||
|
#endif
|
||||||
} else if (!ignored) {
|
} else if (!ignored) {
|
||||||
const char* const msg = processed
|
const char* const msg = processed
|
||||||
? "Failed to convert:"
|
? "Failed to convert:"
|
||||||
|
|||||||
Reference in New Issue
Block a user