Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IFCTOPOLOGYREPRESENTATION. Add IFCFACESURFACE, IFCEDGE and IFCCAR… #1300

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
26 changes: 23 additions & 3 deletions src/cpp/web-ifc/geometry/IfcGeometryLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -902,9 +902,15 @@ namespace webifc::geometry
case schema::IFCCURVESTYLE:
{
_loader.MoveToArgumentOffset(expressID, 3);
auto foundColor = GetColor(_loader.GetRefArgument());
if (foundColor)
return foundColor;
// argument 3 (CurveColour) is optional, so check if it is set
auto tt = _loader.GetTokenType();
if (tt == parsing::REF)
{
_loader.StepBack();
auto foundColor = GetColor(_loader.GetRefArgument());
if (foundColor)
return foundColor;
}
return {};
}
case schema::IFCFILLAREASTYLEHATCHING:
Expand Down Expand Up @@ -1315,6 +1321,20 @@ namespace webifc::geometry

switch (lineType)
{

case schema::IFCEDGE:
{
_loader.MoveToArgumentOffset(expressID, 0);
glm::dvec3 p1 = GetVertexPoint(_loader.GetRefArgument());
_loader.MoveToArgumentOffset(expressID, 1);
glm::dvec3 p2 = GetVertexPoint(_loader.GetRefArgument());

IfcCurve curve;
curve.points.push_back(p1);
curve.points.push_back(p2);

return curve;
}
case schema::IFCEDGECURVE:
{
IfcTrimmingArguments ts;
Expand Down
132 changes: 130 additions & 2 deletions src/cpp/web-ifc/geometry/IfcGeometryProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,8 +620,10 @@ namespace webifc::geometry

return mesh;
}
case schema::IFCTOPOLOGYREPRESENTATION:
case schema::IFCSHAPEREPRESENTATION:
{
// IFCTOPOLOGYREPRESENTATION and IFCSHAPEREPRESENTATION are identical in attributes layout
_loader.MoveToArgumentOffset(expressID, 1);
auto type = _loader.GetStringArgument();

Expand Down Expand Up @@ -674,6 +676,54 @@ namespace webifc::geometry

return mesh;
}
case schema::IFCFACESURFACE:
{
IfcGeometry geometry;
_loader.MoveToArgumentOffset(expressID, 0);
auto bounds = _loader.GetSetArgument();

std::vector<IfcBound3D> bounds3D(bounds.size());

for (size_t i = 0; i < bounds.size(); i++)
{
uint32_t boundID = _loader.GetRefArgument(bounds[i]);
bounds3D[i] = _geometryLoader.GetBound(boundID);
}

TriangulateBounds(geometry, bounds3D, expressID);

_loader.MoveToArgumentOffset(expressID, 1);
auto surfRef = _loader.GetRefArgument();

auto surface = GetSurface(surfRef);

if (surface.BSplineSurface.Active)
{
TriangulateBspline(geometry, bounds3D, surface, _geometryLoader.GetLinearScalingFactor());
}
else if (surface.CylinderSurface.Active)
{
TriangulateCylindricalSurface(geometry, bounds3D, surface, _circleSegments);
}
else if (surface.RevolutionSurface.Active)
{
TriangulateRevolution(geometry, bounds3D, surface, _circleSegments);
}
else if (surface.ExtrusionSurface.Active)
{
TriangulateExtrusion(geometry, bounds3D, surface);
}
else
{
TriangulateBounds(geometry, bounds3D, expressID);
}

_expressIDToGeometry[expressID] = geometry;
mesh.expressID = expressID;
mesh.hasGeometry = true;

break;
}
case schema::IFCTRIANGULATEDIRREGULARNETWORK:
case schema::IFCTRIANGULATEDFACESET:
{
Expand Down Expand Up @@ -1006,11 +1056,89 @@ namespace webifc::geometry

return mesh;
}
case schema::IFCBOUNDINGBOX:
// ignore bounding box
return mesh;

case schema::IFCCARTESIANPOINT:
{
// IfcCartesianPoint is derived from IfcRepresentationItem and can be used as representation item directly
IfcGeometry geom;
auto point = _geometryLoader.GetCartesianPoint3D(expressID);
geom.vertexData.push_back(point.x);
geom.vertexData.push_back(point.y);
geom.vertexData.push_back(point.z);
geom.vertexData.push_back(0); // needs to be 6 values per vertex
geom.vertexData.push_back(0);
geom.vertexData.push_back(1);
geom.indexData.push_back(0);

geom.numPoints = 1;
geom.isPolygon = true;
mesh.hasGeometry = true;
_expressIDToGeometry[expressID] = geom;

return mesh;
}
case schema::IFCEDGE:
{
// IfcEdge is derived from IfcRepresentationItem and can be used as representation item directly
IfcCurve edge = _geometryLoader.GetEdge(expressID);
IfcGeometry geom;

for (uint32_t i = 0; i < edge.points.size(); i++)
{
auto vert = edge.points[i];
geom.vertexData.push_back(vert.x);
geom.vertexData.push_back(vert.y);
geom.vertexData.push_back(vert.z);
geom.vertexData.push_back(0); // needs to be 6 values per vertex
geom.vertexData.push_back(0);
geom.vertexData.push_back(1);
geom.indexData.push_back(i);
}
geom.numPoints = edge.points.size();
geom.isPolygon = true;
mesh.hasGeometry = true;
_expressIDToGeometry[expressID] = geom;

return mesh;
}
case schema::IFCCIRCLE:
case schema::IFCPOLYLINE:
case schema::IFCINDEXEDPOLYCURVE:
case schema::IFCTRIMMEDCURVE:
// ignore polylines as meshes
return mesh;
{
auto lineProfileType = _loader.GetLineType(expressID);
IfcCurve curve = _geometryLoader.GetCurve(expressID, 3, false);

if (curve.points.size() > 0) {
IfcGeometry geom;

for (uint32_t i = 0; i < curve.points.size(); i++)
{
auto vert = curve.points[i];
geom.vertexData.push_back(vert.x);
geom.vertexData.push_back(vert.y);
geom.vertexData.push_back(vert.z);
geom.vertexData.push_back(0); // needs to be 6 values per vertex
geom.vertexData.push_back(0);
geom.vertexData.push_back(1);
geom.indexData.push_back(i);
}
geom.numPoints = curve.points.size();
geom.isPolygon = true;
mesh.hasGeometry = true;
_expressIDToGeometry[expressID] = geom;
}

return mesh;
}
case schema::IFCTEXTLITERAL:
case schema::IFCTEXTLITERALWITHEXTENT:
// TODO: save string of the text literal in IfcComposedMesh
return mesh;

default:
spdlog::error("[GetMesh()] unexpected mesh type {}", expressID, lineType);
break;
Expand Down
1 change: 1 addition & 0 deletions src/cpp/web-ifc/geometry/representation/IfcGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ namespace webifc::geometry {
std::vector<Plane> planes;

bool hasPlanes = false;
bool isPolygon = false;
uint32_t numPoints = 0;
uint32_t numFaces = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/cpp/web-ifc/parsing/IfcLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ namespace webifc::parsing {
StepBack();
GetSetArgument();
noArguments++;
continue;
continue;
}
if (t == IfcTokenType::STRING || t == IfcTokenType::INTEGER || t == IfcTokenType::REAL || t == IfcTokenType::LABEL || t == IfcTokenType::ENUM) {
uint16_t length = _tokenStream->Read<uint16_t>();
Expand Down
Loading