8686
8787#include < BRepGProp_Face.hxx>
8888
89+ #include < BRepMesh.hxx>
90+ #include < BRepTools.hxx>
91+
92+ #include < Poly_Triangulation.hxx>
93+ #include < Poly_Array1OfTriangle.hxx>
94+
8995#include " ../ifcgeom/IfcGeom.h"
9096
9197bool IfcGeom::create_solid_from_compound (const TopoDS_Shape& compound, TopoDS_Shape& shape) {
@@ -489,4 +495,68 @@ double IfcGeom::GetValue(GeomValue var) {
489495 }
490496 assert (!" never reach here" );
491497 return 0 ;
498+ }
499+
500+ Ifc2x3::IfcProductDefinitionShape* IfcGeom::tesselate (TopoDS_Shape& shape, double deflection, IfcEntities es) {
501+ BRepMesh::Mesh (shape, deflection);
502+
503+ Ifc2x3::IfcFace::list faces (new IfcTemplatedEntityList<Ifc2x3::IfcFace>());
504+
505+ for (TopExp_Explorer exp (shape, TopAbs_FACE); exp.More (); exp.Next ()) {
506+ const TopoDS_Face& face = TopoDS::Face (exp.Current ());
507+ TopLoc_Location loc;
508+ Handle (Poly_Triangulation) tri = BRep_Tool::Triangulation (face, loc);
509+
510+ if (! tri.IsNull ()) {
511+ const TColgp_Array1OfPnt& nodes = tri->Nodes ();
512+ std::vector<Ifc2x3::IfcCartesianPoint*> vertices;
513+ for (int i = 1 ; i <= nodes.Length (); ++i) {
514+ const gp_Pnt& pnt = nodes (i);
515+ std::vector<double > xyz; xyz.push_back (pnt.X ()); xyz.push_back (pnt.Y ()); xyz.push_back (pnt.Z ());
516+ Ifc2x3::IfcCartesianPoint* cpnt = new Ifc2x3::IfcCartesianPoint (xyz);
517+ vertices.push_back (cpnt);
518+ es->push (cpnt);
519+ }
520+ const Poly_Array1OfTriangle& triangles = tri->Triangles ();
521+ for (int i = 1 ; i <= triangles.Length (); ++ i) {
522+ int n1, n2, n3;
523+ triangles (i).Get (n1, n2, n3);
524+ Ifc2x3::IfcCartesianPoint::list points (new IfcTemplatedEntityList<Ifc2x3::IfcCartesianPoint>());
525+ points->push (vertices[n1-1 ]);
526+ points->push (vertices[n2-1 ]);
527+ points->push (vertices[n3-1 ]);
528+ Ifc2x3::IfcPolyLoop* loop = new Ifc2x3::IfcPolyLoop (points);
529+ Ifc2x3::IfcFaceOuterBound* bound = new Ifc2x3::IfcFaceOuterBound (loop, face.Orientation () != TopAbs_REVERSED);
530+ Ifc2x3::IfcFaceBound::list bounds (new IfcTemplatedEntityList<Ifc2x3::IfcFaceBound>());
531+ bounds->push (bound);
532+ Ifc2x3::IfcFace* face = new Ifc2x3::IfcFace (bounds);
533+ es->push (loop);
534+ es->push (bound);
535+ es->push (face);
536+ faces->push (face);
537+ }
538+ }
539+ }
540+ Ifc2x3::IfcOpenShell* shell = new Ifc2x3::IfcOpenShell (faces);
541+ Ifc2x3::IfcConnectedFaceSet::list shells (new IfcTemplatedEntityList<Ifc2x3::IfcConnectedFaceSet>());
542+ shells->push (shell);
543+ Ifc2x3::IfcFaceBasedSurfaceModel* surface_model = new Ifc2x3::IfcFaceBasedSurfaceModel (shells);
544+
545+ Ifc2x3::IfcRepresentation::list reps (new IfcTemplatedEntityList<Ifc2x3::IfcRepresentation>());
546+ Ifc2x3::IfcRepresentationItem::list items (new IfcTemplatedEntityList<Ifc2x3::IfcRepresentationItem>());
547+
548+ items->push (surface_model);
549+
550+ Ifc2x3::IfcShapeRepresentation* rep = new Ifc2x3::IfcShapeRepresentation (
551+ 0 , std::string (" Facetation" ), std::string (" SurfaceModel" ), items);
552+
553+ reps->push (rep);
554+ Ifc2x3::IfcProductDefinitionShape* shapedef = new Ifc2x3::IfcProductDefinitionShape (0 , 0 , reps);
555+
556+ es->push (shell);
557+ es->push (surface_model);
558+ es->push (rep);
559+ es->push (shapedef);
560+
561+ return shapedef;
492562}
0 commit comments