mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-18 11:20:21 +00:00
More work on enabling cgal kernel
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#include "CgalKernel.h"
|
||||
#include "CgalConversionResult.h"
|
||||
|
||||
#define CgalKernel MAKE_TYPE_NAME(CgalKernel)
|
||||
|
||||
bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcRepresentation* l, ConversionResults& shapes) {
|
||||
IfcSchema::IfcRepresentationItem::list::ptr items = l->Items();
|
||||
bool part_succes = false;
|
||||
@@ -12,7 +14,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcRepresentation* l, Convers
|
||||
} else {
|
||||
cgal_shape_t s;
|
||||
if (convert_shape(representation_item, s)) {
|
||||
shapes.push_back(ConversionResult(new CgalShape(s), get_style(representation_item)));
|
||||
shapes.push_back(ConversionResult(representation_item->data().id(), new CgalShape(s)));
|
||||
part_succes |= true;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +23,6 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcRepresentation* l, Convers
|
||||
return part_succes;
|
||||
}
|
||||
|
||||
bool IfcGeom::CgalKernel::convert(const Ifc2x3::IfcExtrudedAreaSolid*, cgal_shape_t&) {
|
||||
bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcExtrudedAreaSolid*, cgal_shape_t&) {
|
||||
throw std::runtime_error("Not implemented IfcExtrudedAreaSolid");
|
||||
}
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
#include "CgalKernel.h"
|
||||
#include "CgalConversionResult.h"
|
||||
|
||||
void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<double>* t, int surface_style_id) const {
|
||||
template <typename Precision>
|
||||
void triangulate_helper(const cgal_shape_t, const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<Precision>* t, int surface_style_id) {
|
||||
throw std::runtime_error("Not implemented Triangulate()");
|
||||
}
|
||||
|
||||
void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<float>* t, int surface_style_id) const {
|
||||
triangulate_helper(shape_, settings, place, t, surface_style_id);
|
||||
}
|
||||
|
||||
void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<double>* t, int surface_style_id) const {
|
||||
triangulate_helper(shape_, settings, place, t, surface_style_id);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#ifndef CGALCONVERSIONRESULT_H
|
||||
#define CGALCONVERSIONRESULT_H
|
||||
|
||||
#include "../../../ifcgeom/ConversionResult.h"
|
||||
#include "../../../ifcgeom_schema_agnostic/ConversionResult.h"
|
||||
|
||||
namespace IfcGeom {
|
||||
|
||||
@@ -37,17 +37,28 @@ namespace IfcGeom {
|
||||
// Get cell from placement as 4x3 matrix as implemented in OCCT. We'll have to check exact semantics.
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
virtual void Multiply(const ConversionResultPlacement* other) {
|
||||
// Multiply matrix as implemented in OCCT. We'll have to check exact semantics.
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
virtual void PreMultiply(const ConversionResultPlacement* other) {
|
||||
// PreMultiply matrix as implemented in OCCT. We'll have to check exact semantics.
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
virtual ConversionResultPlacement* clone() const {
|
||||
return new CgalPlacement(trsf_);
|
||||
}
|
||||
|
||||
virtual ConversionResultPlacement* inverted() const {
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
virtual ConversionResultPlacement* multiplied(const ConversionResultPlacement*) const {
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
private:
|
||||
cgal_placement_t trsf_;
|
||||
};
|
||||
@@ -61,13 +72,21 @@ namespace IfcGeom {
|
||||
const cgal_shape_t& shape() const { return shape_; }
|
||||
operator const cgal_shape_t& () { return shape_; }
|
||||
|
||||
virtual void Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<float> * t, int surface_style_id) const;
|
||||
|
||||
virtual void Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<double>* t, int surface_style_id) const;
|
||||
|
||||
virtual void Serialize(std::string&) const {
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
|
||||
virtual ConversionResultShape* clone() const {
|
||||
return new CgalShape(shape_);
|
||||
}
|
||||
|
||||
virtual int surface_genus() const {
|
||||
throw std::runtime_error("Not implemented");
|
||||
}
|
||||
private:
|
||||
cgal_shape_t shape_;
|
||||
};
|
||||
|
||||
@@ -23,22 +23,22 @@
|
||||
#include "CgalKernel.h"
|
||||
#include "CgalConversionResult.h"
|
||||
|
||||
using namespace IfcSchema;
|
||||
using namespace IfcUtil;
|
||||
#define CgalKernel MAKE_TYPE_NAME(CgalKernel)
|
||||
|
||||
using namespace IfcUtil;
|
||||
|
||||
bool IfcGeom::CgalKernel::convert_shapes(const IfcBaseClass* l, ConversionResults& r) {
|
||||
if (shape_type(l) != ST_SHAPELIST) {
|
||||
cgal_shape_t shp;
|
||||
if (convert_shape(l, shp)) {
|
||||
r.push_back(IfcGeom::ConversionResult(new CgalShape(shp), get_style(l->as<IfcSchema::IfcRepresentationItem>())));
|
||||
r.push_back(IfcGeom::ConversionResult(l->data().id(), new CgalShape(shp)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#include "CgalEntityMappingShapes.h"
|
||||
Logger::Message(Logger::LOG_ERROR,"No operation defined for:",l->entity);
|
||||
Logger::Message(Logger::LOG_ERROR,"No operation defined for:", l);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ IfcGeom::ShapeType IfcGeom::CgalKernel::shape_type(const IfcBaseClass* l) {
|
||||
}
|
||||
|
||||
bool IfcGeom::CgalKernel::convert_shape(const IfcBaseClass* l, cgal_shape_t& r) {
|
||||
const unsigned int id = l->entity->id();
|
||||
const unsigned int id = l->data().id();
|
||||
bool success = false;
|
||||
bool processed = false;
|
||||
bool ignored = false;
|
||||
@@ -76,25 +76,25 @@ bool IfcGeom::CgalKernel::convert_shape(const IfcBaseClass* l, cgal_shape_t& r)
|
||||
const char* const msg = processed
|
||||
? "Failed to convert:"
|
||||
: "No operation defined for:";
|
||||
Logger::Message(Logger::LOG_ERROR, msg, l->entity);
|
||||
Logger::Message(Logger::LOG_ERROR, msg, l);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool IfcGeom::CgalKernel::convert_wire(const IfcBaseClass* l, cgal_wire_t& r) {
|
||||
#include "CgalEntityMappingWire.h"
|
||||
Logger::Message(Logger::LOG_ERROR,"No operation defined for:",l->entity);
|
||||
Logger::Message(Logger::LOG_ERROR,"No operation defined for:", l);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IfcGeom::CgalKernel::convert_face(const IfcBaseClass* l, cgal_face_t& r) {
|
||||
#include "CgalEntityMappingFace.h"
|
||||
Logger::Message(Logger::LOG_ERROR,"No operation defined for:",l->entity);
|
||||
Logger::Message(Logger::LOG_ERROR,"No operation defined for:", l);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IfcGeom::CgalKernel::convert_curve(const IfcBaseClass* l, cgal_curve_t& r) {
|
||||
#include "CgalEntityMappingCurve.h"
|
||||
Logger::Message(Logger::LOG_ERROR,"No operation defined for:",l->entity);
|
||||
Logger::Message(Logger::LOG_ERROR,"No operation defined for:", l);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
* *
|
||||
********************************************************************************/
|
||||
|
||||
#include "../../../ifcparse/IfcUtil.h"
|
||||
#include "../../../ifcparse/IfcParse.h"
|
||||
|
||||
SHAPES(IfcRepresentation);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "CgalEntityMappingUndefine.h"
|
||||
#define CURVE(T) \
|
||||
if ( l->is(T::Class()) ) return convert((T*)l,r);
|
||||
if (l->declaration().is(IfcSchema::T::Class())) return convert((IfcSchema::T*)l,r);
|
||||
#include "CgalEntityMappingDefine.h"
|
||||
|
||||
#include "CgalEntityMapping.h"
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "CgalEntityMappingUndefine.h"
|
||||
#define FACE(T) \
|
||||
if ( l->is(T::Class()) ) return convert((T*)l,r);
|
||||
if (l->declaration().is(IfcSchema::T::Class())) return convert((IfcSchema::T*)l,r);
|
||||
#include "CgalEntityMappingDefine.h"
|
||||
|
||||
#include "CgalEntityMapping.h"
|
||||
@@ -1,17 +1,17 @@
|
||||
#include "CgalEntityMappingUndefine.h"
|
||||
#define SHAPE(T) \
|
||||
if ( !processed && l->is(T::Class()) ) { \
|
||||
if ( !processed && l->declaration().is(IfcSchema::T::Class()) ) { \
|
||||
processed = true; \
|
||||
try { \
|
||||
if ( convert((T*)l,r) ) { \
|
||||
if (convert((IfcSchema::T*)l, r) ) { \
|
||||
success = true; \
|
||||
} \
|
||||
} catch (const std::exception& e) { \
|
||||
Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", l->entity); \
|
||||
Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", l); \
|
||||
return false; \
|
||||
} \
|
||||
if (!success) { \
|
||||
Logger::Message(Logger::LOG_ERROR,"Failed to convert:",l->entity); \
|
||||
Logger::Message(Logger::LOG_ERROR,"Failed to convert:", l); \
|
||||
return false; \
|
||||
} \
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#include "CgalEntityMappingUndefine.h"
|
||||
#define SHAPES(T) \
|
||||
if ( l->is(T::Class()) ) return ST_SHAPELIST;
|
||||
if (l->declaration().is(IfcSchema::T::Class())) return ST_SHAPELIST;
|
||||
#define SHAPE(T) \
|
||||
if ( l->is(T::Class()) ) return ST_SHAPE;
|
||||
if (l->declaration().is(IfcSchema::T::Class())) return ST_SHAPE;
|
||||
#define WIRE(T) \
|
||||
if ( l->is(T::Class()) ) return ST_WIRE;
|
||||
if (l->declaration().is(IfcSchema::T::Class())) return ST_WIRE;
|
||||
#define FACE(T) \
|
||||
if ( l->is(T::Class()) ) return ST_FACE;
|
||||
if (l->declaration().is(IfcSchema::T::Class())) return ST_FACE;
|
||||
#define CURVE(T) \
|
||||
if ( l->is(T::Class()) ) return ST_CURVE;
|
||||
if (l->declaration().is(IfcSchema::T::Class())) return ST_CURVE;
|
||||
#include "CgalEntityMappingDefine.h"
|
||||
|
||||
#include "CgalEntityMapping.h"
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "CgalEntityMappingUndefine.h"
|
||||
#define SHAPES(T) \
|
||||
if ( l->is(T::Class()) ) { \
|
||||
if (l->declaration().is(IfcSchema::T::Class())) { \
|
||||
try { \
|
||||
return convert((T*)l,r); \
|
||||
return convert((IfcSchema::T*)l,r); \
|
||||
} catch (const std::exception& e) { \
|
||||
Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", l->entity); \
|
||||
Logger::Message(Logger::LOG_ERROR, std::string(e.what()) + "\nFailed to convert:", l); \
|
||||
} \
|
||||
return false; \
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "CgalEntityMappingUndefine.h"
|
||||
#define WIRE(T) \
|
||||
if ( l->is(T::Class()) ) return convert((T*)l,r);
|
||||
if (l->declaration().is(IfcSchema::T::Class())) return convert((IfcSchema::T*)l,r);
|
||||
#include "CgalEntityMappingDefine.h"
|
||||
|
||||
#include "CgalEntityMapping.h"
|
||||
|
||||
@@ -23,6 +23,23 @@
|
||||
#include "CgalKernel.h"
|
||||
#include "CgalConversionResult.h"
|
||||
|
||||
namespace {
|
||||
struct MAKE_TYPE_NAME(factory_t) {
|
||||
IfcGeom::Kernel* operator()(IfcParse::IfcFile* file) const {
|
||||
IfcGeom::MAKE_TYPE_NAME(Kernel)* k = new IfcGeom::MAKE_TYPE_NAME(Kernel);
|
||||
return k;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void MAKE_INIT_FN(KernelImplementation_cgal_)(IfcGeom::impl::KernelFactoryImplementation* mapping) {
|
||||
static const std::string schema_name = STRINGIFY(IfcSchema);
|
||||
MAKE_TYPE_NAME(factory_t) factory;
|
||||
mapping->bind(schema_name, "cgal", factory);
|
||||
}
|
||||
|
||||
#define CgalKernel MAKE_TYPE_NAME(CgalKernel)
|
||||
|
||||
bool IfcGeom::CgalKernel::is_identity_transform(IfcUtil::IfcBaseClass* l) {
|
||||
Logger::Message(Logger::LOG_ERROR, "Not implemented is_identity_transform()");
|
||||
return false;
|
||||
@@ -70,7 +87,7 @@ bool IfcGeom::CgalKernel::is_identity_transform(IfcUtil::IfcBaseClass* l) {
|
||||
IfcGeom::NativeElement<double>* IfcGeom::CgalKernel::create_brep_for_representation_and_product(
|
||||
const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product)
|
||||
{
|
||||
IfcGeom::Representation::Native* shape;
|
||||
IfcGeom::Representation::BRep* shape;
|
||||
IfcGeom::ConversionResults shapes, shapes2;
|
||||
|
||||
if (!convert_shapes(representation, shapes)) {
|
||||
@@ -83,11 +100,13 @@ IfcGeom::NativeElement<double>* IfcGeom::CgalKernel::create_brep_for_representat
|
||||
|
||||
int parent_id = -1;
|
||||
try {
|
||||
IfcSchema::IfcObjectDefinition* parent_object = get_decomposing_entity(product);
|
||||
if (parent_object) {
|
||||
parent_id = parent_object->entity->id();
|
||||
IfcUtil::IfcBaseEntity* parent_object = get_decomposing_entity(product);
|
||||
if (parent_object && parent_object->as<IfcSchema::IfcObjectDefinition>()) {
|
||||
parent_id = parent_object->data().id();
|
||||
}
|
||||
} catch (...) {}
|
||||
} catch (const std::exception& e) {
|
||||
Logger::Error(e);
|
||||
}
|
||||
|
||||
const std::string name = product->hasName() ? product->Name() : "";
|
||||
const std::string guid = product->GlobalId();
|
||||
@@ -97,18 +116,21 @@ IfcGeom::NativeElement<double>* IfcGeom::CgalKernel::create_brep_for_representat
|
||||
// convert(product->ObjectPlacement(), trsf);
|
||||
} catch (...) {}
|
||||
|
||||
std::stringstream representation_id_builder;
|
||||
representation_id_builder << representation->data().id();
|
||||
|
||||
// Does the IfcElement have any IfcOpenings?
|
||||
// Note that openings for IfcOpeningElements are not processed
|
||||
IfcSchema::IfcRelVoidsElement::list::ptr openings = find_openings(product);
|
||||
IfcSchema::IfcRelVoidsElement::list::ptr openings = find_openings(product)->as<IfcSchema::IfcRelVoidsElement>();
|
||||
|
||||
const std::string product_type = IfcSchema::Type::ToString(product->type());
|
||||
const std::string product_type = product->declaration().name();
|
||||
ElementSettings element_settings(settings, getValue(GV_LENGTH_UNIT), product_type);
|
||||
|
||||
if (!settings.get(IfcGeom::IteratorSettings::DISABLE_OPENING_SUBTRACTIONS) && openings && openings->size()) {
|
||||
Logger::Message(Logger::LOG_ERROR, "Not implemented opening subtractions");
|
||||
}
|
||||
|
||||
shape = new IfcGeom::Representation::Native(element_settings, representation->entity->id(), shapes);
|
||||
shape = new IfcGeom::Representation::BRep(element_settings, representation_id_builder.str(), shapes);
|
||||
|
||||
std::string context_string = "";
|
||||
if (representation->hasRepresentationIdentifier()) {
|
||||
@@ -118,14 +140,15 @@ IfcGeom::NativeElement<double>* IfcGeom::CgalKernel::create_brep_for_representat
|
||||
}
|
||||
|
||||
return new NativeElement<double>(
|
||||
product->entity->id(),
|
||||
product->data().id(),
|
||||
parent_id,
|
||||
name,
|
||||
product_type,
|
||||
guid,
|
||||
context_string,
|
||||
new CgalPlacement(trsf),
|
||||
boost::shared_ptr<IfcGeom::Representation::Native>(shape)
|
||||
boost::shared_ptr<IfcGeom::Representation::BRep>(shape),
|
||||
product
|
||||
);
|
||||
}
|
||||
|
||||
@@ -135,11 +158,13 @@ IfcGeom::NativeElement<double>* IfcGeom::CgalKernel::create_brep_for_processed_r
|
||||
{
|
||||
int parent_id = -1;
|
||||
try {
|
||||
IfcSchema::IfcObjectDefinition* parent_object = get_decomposing_entity(product);
|
||||
if (parent_object) {
|
||||
parent_id = parent_object->entity->id();
|
||||
IfcUtil::IfcBaseEntity* parent_object = get_decomposing_entity(product);
|
||||
if (parent_object && parent_object->as<IfcSchema::IfcObjectDefinition>()) {
|
||||
parent_id = parent_object->data().id();
|
||||
}
|
||||
} catch (...) {}
|
||||
} catch (const std::exception& e) {
|
||||
Logger::Error(e);
|
||||
}
|
||||
|
||||
const std::string name = product->hasName() ? product->Name() : "";
|
||||
const std::string guid = product->GlobalId();
|
||||
@@ -156,16 +181,17 @@ IfcGeom::NativeElement<double>* IfcGeom::CgalKernel::create_brep_for_processed_r
|
||||
context_string = representation->ContextOfItems()->ContextType();
|
||||
}
|
||||
|
||||
const std::string product_type = IfcSchema::Type::ToString(product->type());
|
||||
const std::string product_type = product->declaration().name();
|
||||
|
||||
return new NativeElement<double>(
|
||||
product->entity->id(),
|
||||
product->data().id(),
|
||||
parent_id,
|
||||
name,
|
||||
product_type,
|
||||
guid,
|
||||
context_string,
|
||||
new CgalPlacement(trsf),
|
||||
brep->geometry_pointer()
|
||||
brep->geometry_pointer(),
|
||||
product
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace IfcGeom {
|
||||
std::map<int, cgal_shape_t> Shape;
|
||||
};
|
||||
|
||||
class IFC_GEOM_API CgalKernel : public AbstractKernel {
|
||||
class IFC_GEOM_API MAKE_TYPE_NAME(CgalKernel) : public Kernel {
|
||||
public:
|
||||
|
||||
#ifndef NO_CACHE
|
||||
|
||||
Reference in New Issue
Block a user