mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-29 16:22:53 +00:00
167 lines
6.6 KiB
C++
167 lines
6.6 KiB
C++
#include "CgalKernel.h"
|
|
#include "../../../ifcgeom/schema_agnostic/cgal/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;
|
|
if (items->size()) {
|
|
for (IfcSchema::IfcRepresentationItem::list::it it = items->begin(); it != items->end(); ++it) {
|
|
IfcSchema::IfcRepresentationItem* representation_item = *it;
|
|
if (shape_type(representation_item) == ST_SHAPELIST) {
|
|
part_succes |= convert_shapes(*it, shapes);
|
|
} else {
|
|
cgal_shape_t s;
|
|
if (convert_shape(representation_item, s)) {
|
|
shapes.push_back(ConversionResult(representation_item->data().id(), new CgalShape(s), get_style(representation_item)));
|
|
part_succes |= true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return part_succes;
|
|
}
|
|
|
|
bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcGeometricSet* l, ConversionResults& shapes) {
|
|
IfcEntityList::ptr elements = l->Elements();
|
|
if ( !elements->size() ) return false;
|
|
bool part_succes = false;
|
|
const IfcGeom::SurfaceStyle* parent_style = get_style(l);
|
|
for ( IfcEntityList::it it = elements->begin(); it != elements->end(); ++ it ) {
|
|
IfcSchema::IfcGeometricSetSelect* element = *it;
|
|
cgal_shape_t s;
|
|
if (convert_shape(element, s)) {
|
|
part_succes = true;
|
|
const IfcGeom::SurfaceStyle* style = 0;
|
|
if (element->as<IfcSchema::IfcPoint>()) {
|
|
style = get_style((IfcSchema::IfcPoint*) element);
|
|
} else if (element->as<IfcSchema::IfcCurve>()) {
|
|
style = get_style((IfcSchema::IfcCurve*) element);
|
|
} else if (element->as<IfcSchema::IfcSurface>()) {
|
|
style = get_style((IfcSchema::IfcSurface*) element);
|
|
}
|
|
shapes.push_back(ConversionResult(element->data().id(), new CgalShape(s), style ? style : parent_style));
|
|
}
|
|
}
|
|
return part_succes;
|
|
}
|
|
|
|
bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcShellBasedSurfaceModel* l, ConversionResults& shapes) {
|
|
IfcEntityList::ptr shells = l->SbsmBoundary();
|
|
const SurfaceStyle* collective_style = get_style(l);
|
|
for( IfcEntityList::it it = shells->begin(); it != shells->end(); ++ it ) {
|
|
cgal_shape_t s;
|
|
const SurfaceStyle* shell_style = 0;
|
|
if ((*it)->as<IfcSchema::IfcRepresentationItem>()) {
|
|
shell_style = get_style((IfcSchema::IfcRepresentationItem*)*it);
|
|
}
|
|
if (convert_shape(*it,s)) {
|
|
shapes.push_back(ConversionResult((*it)->data().id(), new CgalShape(s), shell_style ? shell_style : collective_style));
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcManifoldSolidBrep* l, ConversionResults& shape) {
|
|
cgal_shape_t s;
|
|
const SurfaceStyle* collective_style = get_style(l);
|
|
const SurfaceStyle* indiv_style = get_style(l->Outer());
|
|
|
|
if (convert_shape(l->Outer(),s) ) {
|
|
IfcSchema::IfcClosedShell::list::ptr voids(new IfcSchema::IfcClosedShell::list);
|
|
if (l->as<IfcSchema::IfcFacetedBrepWithVoids>()) {
|
|
voids = l->as<IfcSchema::IfcFacetedBrepWithVoids>()->Voids();
|
|
}
|
|
#ifdef USE_IFC4
|
|
if (l->as<IfcSchema::IfcAdvancedBrepWithVoids>()) {
|
|
voids = l->as<IfcSchema::IfcAdvancedBrepWithVoids>()->Voids();
|
|
}
|
|
#endif
|
|
|
|
if (voids->size()) {
|
|
CGAL::Nef_polyhedron_3<Kernel_> nef_s = create_nef_polyhedron(s);
|
|
|
|
for (IfcSchema::IfcClosedShell::list::it it = voids->begin(); it != voids->end(); ++it) {
|
|
cgal_shape_t s2;
|
|
if (convert_shape(*it, s2)) {
|
|
nef_s -= CGAL::Nef_polyhedron_3<Kernel_>(s2);
|
|
}
|
|
}
|
|
|
|
s = create_polyhedron(nef_s);
|
|
}
|
|
|
|
shape.push_back(ConversionResult(l->data().id(), new CgalShape(s), indiv_style ? indiv_style : collective_style));
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcMappedItem* l, ConversionResults& shapes) {
|
|
cgal_placement_t gtrsf;
|
|
IfcSchema::IfcCartesianTransformationOperator* transform = l->MappingTarget();
|
|
if ( transform->as<IfcSchema::IfcCartesianTransformationOperator3DnonUniform>() ) {
|
|
IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator3DnonUniform*)transform,gtrsf);
|
|
} else if ( transform->as<IfcSchema::IfcCartesianTransformationOperator2DnonUniform>() ) {
|
|
IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator2DnonUniform*)transform,gtrsf);
|
|
} else if ( transform->as<IfcSchema::IfcCartesianTransformationOperator3D>() ) {
|
|
IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator3D*)transform,gtrsf);
|
|
} else if ( transform->as<IfcSchema::IfcCartesianTransformationOperator2D>() ) {
|
|
IfcGeom::CgalKernel::convert((IfcSchema::IfcCartesianTransformationOperator2D*)transform,gtrsf);
|
|
}
|
|
IfcSchema::IfcRepresentationMap* map = l->MappingSource();
|
|
IfcSchema::IfcAxis2Placement* placement = map->MappingOrigin();
|
|
cgal_placement_t trsf;
|
|
if (placement->as<IfcSchema::IfcAxis2Placement3D>()) {
|
|
IfcGeom::CgalKernel::convert((IfcSchema::IfcAxis2Placement3D*)placement,trsf);
|
|
} else {
|
|
cgal_placement_t trsf_2d;
|
|
IfcGeom::CgalKernel::convert((IfcSchema::IfcAxis2Placement2D*)placement,trsf_2d);
|
|
trsf = trsf_2d;
|
|
}
|
|
|
|
// TODO: Check
|
|
gtrsf = trsf * gtrsf;
|
|
|
|
// std::cout << std::endl;
|
|
// for (int i = 0; i < 3; ++i) {
|
|
// for (int j = 0; j < 4; ++j) {
|
|
// std::cout << gtrsf.cartesian(i, j) << " ";
|
|
// } std::cout << std::endl;
|
|
// }
|
|
|
|
const IfcGeom::SurfaceStyle* mapped_item_style = get_style(l);
|
|
|
|
const size_t previous_size = shapes.size();
|
|
bool b = convert_shapes(map->MappedRepresentation(), shapes);
|
|
|
|
for (size_t i = previous_size; i < shapes.size(); ++ i ) {
|
|
IfcGeom::CgalPlacement place(gtrsf);
|
|
shapes[i].prepend(&place);
|
|
|
|
// Apply styles assigned to the mapped item only if on
|
|
// a more granular level no styles have been applied
|
|
if (!shapes[i].hasStyle()) {
|
|
shapes[i].setStyle(mapped_item_style);
|
|
}
|
|
}
|
|
|
|
return b;
|
|
}
|
|
|
|
bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcFaceBasedSurfaceModel* l, ConversionResults& shapes) {
|
|
bool part_success = false;
|
|
IfcSchema::IfcConnectedFaceSet::list::ptr facesets = l->FbsmFaces();
|
|
const SurfaceStyle* collective_style = get_style(l);
|
|
for( IfcSchema::IfcConnectedFaceSet::list::it it = facesets->begin(); it != facesets->end(); ++ it ) {
|
|
cgal_shape_t s;
|
|
const SurfaceStyle* shell_style = get_style(*it);
|
|
if (convert_shape(*it,s)) {
|
|
shapes.push_back(ConversionResult((*it)->data().id(), new CgalShape(s), shell_style ? shell_style : collective_style));
|
|
part_success |= true;
|
|
}
|
|
}
|
|
return part_success;
|
|
}
|