Skip to content

Commit

Permalink
Method to prevent crash in #540
Browse files Browse the repository at this point in the history
  • Loading branch information
QuimMoya committed Jan 9, 2024
1 parent 8f15891 commit 4853783
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/wasm/geometry/IfcGeometryLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ namespace webifc::geometry
if (sg.type == "IFCARCINDEX")
{
auto pts = ReadIfcCartesianPointList3D(ptsRef);
IfcCurve arc = Build3DArc3Pt(pts[sg.indexs[0] - 1], pts[sg.indexs[1] - 1], pts[sg.indexs[2] - 1],_circleSegments, EPS_MINISCULE);
IfcCurve arc = Build3DArc3Pt(pts[sg.indexs[0] - 1], pts[sg.indexs[1] - 1], pts[sg.indexs[2] - 1],_circleSegments, EPS_MINISCULE());
for (auto &pt : arc.points)
{
curve.Add(pt);
Expand Down
20 changes: 13 additions & 7 deletions src/wasm/geometry/IfcGeometryProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ namespace webifc::geometry
return _coordinationMatrix;
}

IfcComposedMesh IfcGeometryProcessor::GetMesh(uint32_t expressID)
IfcComposedMesh IfcGeometryProcessor::GetMesh(uint32_t expressID, uint32_t _nestLevel)
{
spdlog::debug("[GetMesh({})]",expressID);
auto lineType = _loader.GetLineType(expressID);

std::optional<glm::dvec4> styledItemColor;
auto &styledItems = _geometryLoader.GetStyledItems();
auto &relMaterials = _geometryLoader.GetRelMaterials();
auto &materialDefinitions = _geometryLoader.GetMaterialDefinitions();
auto relVoids = _geometryLoader.GetRelVoids();
auto &relVoids = _geometryLoader.GetRelVoids();
auto &relElementAggregates = _geometryLoader.GetRelElementAggregates();

auto styledItem = styledItems.find(expressID);
Expand Down Expand Up @@ -160,7 +159,7 @@ namespace webifc::geometry
{
if (relVoidsIt != relVoids.end() && !relVoidsIt->second.empty())
{
relVoidsIt->second.insert(relVoidsIt->second.end(), relVoidsIt2->second.begin(), relVoidsIt2->second.end());
// relVoidsIt->second.insert(relVoidsIt->second.end(), relVoidsIt2->second.begin(), relVoidsIt2->second.end());
}
else
{
Expand Down Expand Up @@ -307,8 +306,15 @@ namespace webifc::geometry
uint32_t firstOperandID = _loader.GetRefArgument();
uint32_t secondOperandID = _loader.GetRefArgument();

auto firstMesh = GetMesh(firstOperandID);
auto secondMesh = GetMesh(secondOperandID);
uint32_t nestLevel = _nestLevel + 1;

if(nestLevel > 17)
{
return mesh;
}

auto firstMesh = GetMesh(firstOperandID, nestLevel);
auto secondMesh = GetMesh(secondOperandID, nestLevel);

auto origin = GetOrigin(firstMesh, _expressIDToGeometry);
auto normalizeMat = glm::translate(-origin);
Expand Down Expand Up @@ -762,7 +768,7 @@ namespace webifc::geometry
glm::dvec3 pos = _geometryLoader.GetAxis1Placement(axis1PlacementID)[1];

IfcCurve directrix = BuildArc(_geometryLoader.GetLinearScalingFactor(), pos, axis, angle, _circleSegments);
if(glm::distance(directrix.points[0], directrix.points[directrix.points.size() - 1]) < EPS_BIG)
if(glm::distance(directrix.points[0], directrix.points[directrix.points.size() - 1]) < EPS_BIG())
{
closed = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/geometry/IfcGeometryProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace webifc::geometry
IfcGeometry &GetGeometry(uint32_t expressID);
IfcGeometryLoader GetLoader() const;
IfcFlatMesh GetFlatMesh(uint32_t expressID);
IfcComposedMesh GetMesh(uint32_t expressID);
IfcComposedMesh GetMesh(uint32_t expressID, uint32_t nestLevel = 0);
void SetTransformation(const glm::dmat4 &val);
glm::dmat4 GetCoordinationMatrix();
void Clear();
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/geometry/operations/curve-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ inline IfcCurve Build3DArc3Pt(const glm::dvec3 &p1, const glm::dvec3 &p2, const

if(glm::length(right) == 0)
{
right = glm::dvec3(EPS_BIG2, 0, 0);
right = glm::dvec3(EPS_BIG2(), 0, 0);
glm::dvec3 up = glm::cross(axis, right);

auto curve2D = GetEllipseCurve(1, 1, _circleSegments, glm::dmat3(1), 0, angleRad, true, true);
Expand Down
6 changes: 3 additions & 3 deletions src/wasm/geometry/operations/geometryutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace webifc::geometry
{
if (i < directrix.points.size() - 1)
{
if (glm::distance(directrix.points[i], directrix.points[i + 1]) > EPS_BIG2 / scaling || !optimize)
if (glm::distance(directrix.points[i], directrix.points[i + 1]) > EPS_BIG2() / scaling || !optimize)
{
dpts.push_back(directrix.points[i]);
}
Expand Down Expand Up @@ -281,7 +281,7 @@ namespace webifc::geometry
{
if (i < directrix.points.size() - 1)
{
if (glm::distance(directrix.points[i], directrix.points[i + 1]) > EPS_BIG2 / scaling)
if (glm::distance(directrix.points[i], directrix.points[i + 1]) > EPS_BIG2() / scaling)
{
dpts.push_back(directrix.points[i]);
}
Expand Down Expand Up @@ -383,7 +383,7 @@ namespace webifc::geometry

double parallelZ = glm::abs(glm::dot(dz, glm::dvec3(0, 0, 1)));

if (parallelZ > 1 - EPS_BIG2)
if (parallelZ > 1 - EPS_BIG2())
{
dx = glm::normalize(glm::cross(dz, glm::dvec3(0, 1, 0)));
}
Expand Down
6 changes: 3 additions & 3 deletions src/wasm/geometry/representation/IfcGeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ namespace webifc::geometry {
for (uint32_t j = i + 1; j < vertexSize; j++)
{
glm::dvec3 p2 = GetPoint(j);
if (glm::abs(p1.x - p2.x) < EPS_BIG &&
glm::abs(p1.y - p2.y) < EPS_BIG &&
glm::abs(p1.z - p2.z) < EPS_BIG)
if (glm::abs(p1.x - p2.x) < EPS_BIG() &&
glm::abs(p1.y - p2.y) < EPS_BIG() &&
glm::abs(p1.z - p2.z) < EPS_BIG())
{
if (team[i] < team[j])
{
Expand Down
7 changes: 4 additions & 3 deletions src/wasm/web-ifc-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ int main()
// return 0;
// std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#512/512.ifc");
// std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#520/520B.ifc");
std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#515/Spacewell_Wall.ifc");
// std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#ALLPLAN/#515/Spacewell_Wall.ifc");
std::string content = ReadFile("C:/Users/qmoya/Desktop/PROGRAMES/VSCODE/IFC.JS/issues/#ALLPLAN/#540/540.ifc");

struct LoaderSettings
{
Expand Down Expand Up @@ -334,10 +335,10 @@ int main()
// SpecificLoadTest(loader, geometryLoader, 181); //520A
// SpecificLoadTest(loader, geometryLoader, 213); //520B
// SpecificLoadTest(loader, geometryLoader, 4787); //515
SpecificLoadTest(loader, geometryLoader, 4616); //515
// SpecificLoadTest(loader, geometryLoader, 4616); //515
// SpecificLoadTest(loader, geometryLoader, 4610); //515

// auto meshes = LoadAllTest(loader, geometryLoader);
auto meshes = LoadAllTest(loader, geometryLoader);
// auto alignments = GetAlignments(loader, geometryLoader);

time = ms() - start;
Expand Down

0 comments on commit 4853783

Please sign in to comment.