Skip to content

Commit b719e12

Browse files
committed
Provide access to IfcGeomObject geometry as Open Cascade BRep data
1 parent 5ebc236 commit b719e12

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/ifcgeom/IfcGeomObjects.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <Poly_Array1OfTriangle.hxx>
4141
#include <StdFail_NotDone.hxx>
4242
#include <BRepGProp_Face.hxx>
43+
#include <BRepBuilderAPI_GTransform.hxx>
4344

4445
#include "../ifcparse/IfcException.h"
4546
#include "../ifcgeom/IfcGeomObjects.h"
@@ -68,10 +69,32 @@ int IfcGeomObjects::IfcMesh::addvert(const gp_XYZ& p) {
6869
}
6970

7071
bool use_world_coords = false;
72+
bool use_brep_data = false;
7173

7274
IfcGeomObjects::IfcMesh::IfcMesh(int i, const IfcGeom::ShapeList& shapes) {
7375
id = i;
7476

77+
if ( use_brep_data ) {
78+
TopoDS_Compound compound;
79+
BRep_Builder builder;
80+
builder.MakeCompound(compound);
81+
for ( IfcGeom::ShapeList::const_iterator it = shapes.begin(); it != shapes.end(); ++ it ) {
82+
const TopoDS_Shape& s = *(*it).second;
83+
const gp_GTrsf& trsf = *(*it).first;
84+
bool trsf_valid = false;
85+
gp_Trsf _trsf;
86+
try {
87+
_trsf = trsf.Trsf();
88+
trsf_valid = true;
89+
} catch (...) {}
90+
const TopoDS_Shape moved_shape = trsf_valid ? s.Moved(_trsf) :
91+
BRepBuilderAPI_GTransform(s,trsf,true).Shape();
92+
builder.Add(compound,moved_shape);
93+
}
94+
std::stringstream sstream;
95+
BRepTools::Write(compound,sstream);
96+
brep_data = sstream.str();
97+
} else
7598
for ( IfcGeom::ShapeList::const_iterator it = shapes.begin(); it != shapes.end(); ++ it ) {
7699

77100
const TopoDS_Shape& s = *(*it).second;
@@ -491,6 +514,9 @@ void IfcGeomObjects::Settings(int setting, bool value) {
491514
case CONVERT_BACK_UNITS:
492515
convert_back_units = value;
493516
break;
517+
case USE_BREP_DATA:
518+
use_brep_data = value;
519+
break;
494520
}
495521
}
496522
int IfcGeomObjects::Progress() {

src/ifcgeom/IfcGeomObjects.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ namespace IfcGeomObjects {
7272
const int WELD_VERTICES = 1;
7373
const int USE_WORLD_COORDS = 2;
7474
const int CONVERT_BACK_UNITS = 3;
75+
const int USE_BREP_DATA = 4;
7576

7677
typedef std::vector<int>::const_iterator IntIt;
7778
typedef std::vector<float>::const_iterator FltIt;
@@ -86,6 +87,7 @@ namespace IfcGeomObjects {
8687
std::vector<int> faces;
8788
std::vector<int> edges;
8889
std::vector<float> normals;
90+
std::string brep_data;
8991
VertKeyMap welds;
9092

9193
IfcMesh(int i, const IfcGeom::ShapeList& s);

src/ifcwrap/Interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace IfcGeomObjects {
2121

2222
const int WELD_VERTICES = 1;
2323
const int USE_WORLD_COORDS = 2;
24+
const int CONVERT_BACK_UNITS = 3;
25+
const int USE_BREP_DATA = 4;
2426

2527
class IfcMesh {
2628
public:
@@ -29,6 +31,7 @@ namespace IfcGeomObjects {
2931
std::vector<int> faces;
3032
std::vector<int> edges;
3133
std::vector<float> normals;
34+
std::string brep_data;
3235
};
3336

3437
class IfcObject {

0 commit comments

Comments
 (0)