Skip to content

Commit 43009a6

Browse files
authored
Merge pull request #1850 from ThatOpen/Sweep
Sweep Circular
2 parents ef09df6 + 7623f3c commit 43009a6

4 files changed

Lines changed: 190 additions & 388 deletions

File tree

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cpp/web-ifc/geometry/operations/bim-geometry/geometry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace bimGeometry {
2727
void buildPlanes();
2828
size_t AddPlane(const glm::dvec3 &normal, double d);
2929
void AddFace(glm::dvec3 a, glm::dvec3 b, glm::dvec3 c, uint32_t pId = UINT32_MAX);
30-
void AddFace(uint32_t a, uint32_t b, uint32_t c, uint32_t pId);
30+
void AddFace(uint32_t a, uint32_t b, uint32_t c, uint32_t pId = UINT32_MAX);
3131
void AddPoint(glm::dvec4& pt, glm::dvec3& n);
3232
void AddPoint(const glm::dvec3& pt, const glm::dvec3& n);
3333
void AddGeometry(Geometry geom);

src/cpp/web-ifc/geometry/operations/bim-geometry/utils.h

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,27 +1197,38 @@ namespace bimGeometry
11971197
dpts.erase(dpts.begin());
11981198
}
11991199

1200-
// connect the curves
1201-
for (size_t i = 1; i < dpts.size(); i++)
1200+
std::vector<std::vector<uint32_t>> curvePointIndices;
1201+
curvePointIndices.reserve(curves.size());
1202+
for (size_t i = 0; i < curves.size(); ++i)
12021203
{
1203-
glm::dvec3 p1 = dpts[i - 1];
1204-
glm::dvec3 p2 = dpts[i];
1205-
glm::dvec3 dir = p1 - p2;
1206-
glm::dvec4 ddir = glm::dvec4(dir, 0);
1207-
const double di = glm::distance(p1, p2);
1204+
auto& pts = curves[i];
1205+
std::vector<uint32_t>& indices = curvePointIndices.emplace_back();
1206+
indices.reserve(pts.size());
1207+
const glm::dvec3 center = dpts[i];
12081208

1209-
// Only segments smaller than 10 cm will be represented, those that are bigger will be standardized
1210-
1211-
const auto &c1 = curves[i - 1];
1212-
const auto &c2 = curves[i];
1209+
for (glm::dvec3& p : pts)
1210+
{
1211+
// Radially outward normals
1212+
glm::dvec3 n = p - center;
1213+
const double len2 = glm::dot(n, n);
1214+
n = (len2 > 0.0) ? n / std::sqrt(len2) : glm::dvec3(0.0, 0.0, 1.0);
1215+
geom.AddPoint(p, n);
1216+
indices.push_back(geom.numPoints - 1);
1217+
}
1218+
}
1219+
// connect consecutive circles with faces
1220+
for (size_t i = 1; i < dpts.size(); i++)
1221+
{
1222+
const auto& idx1 = curvePointIndices[i - 1];
1223+
const auto& idx2 = curvePointIndices[i];
12131224

1214-
uint32_t capSize = c1.size();
1225+
const uint32_t capSize = static_cast<uint32_t>(idx1.size());
12151226
for (size_t j = 1; j < capSize; j++)
12161227
{
1217-
glm::dvec3 bl = c1[j - 1];
1218-
glm::dvec3 br = c1[j - 0];
1219-
glm::dvec3 tl = c2[j - 1];
1220-
glm::dvec3 tr = c2[j - 0];
1228+
const uint32_t bl = idx1[j - 1];
1229+
const uint32_t br = idx1[j - 0];
1230+
const uint32_t tl = idx2[j - 1];
1231+
const uint32_t tr = idx2[j - 0];
12211232

12221233
geom.AddFace(tl, br, bl);
12231234
geom.AddFace(tl, tr, br);

0 commit comments

Comments
 (0)