Skip to content

Bim geometry #1412

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

Merged
merged 5 commits into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cpp/test/web-ifc-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ int main()
// std::string content = ReadFile("C:/Users/qmoya/Desktop/MODELS/15.ifc");
// std::string content = ReadFile("C:/Users/qmoya/Desktop/MODELS/F_MA_160_ALT3.ifc");
// std::string content = ReadFile("C:/Users/qmoya/Desktop/MODELS/1256.ifc");
std::string content = ReadFile("C:/Users/qmoya/Desktop/MODELS/15.ifc");
std::string content = ReadFile("C:/Users/qmoya/Desktop/MODELS/muysimple.ifc");

struct LoaderSettings
{
Expand Down Expand Up @@ -501,7 +501,7 @@ int main()

start = ms();

SpecificLoadTest(loader, geometryLoader, 211736);
SpecificLoadTest(loader, geometryLoader, 3994);
// auto meshes = LoadAllTest(loader, geometryLoader, -1);
// auto rebars = GetAllRebars(loader, geometryLoader);
// std::cout << GetLine(loader, 225) << std::endl;
Expand Down
19 changes: 16 additions & 3 deletions src/cpp/wasm/web-ifc-wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "../version.h"
#include "../web-ifc/geometry/operations/bim-geometry/extrusion.h"
#include "../web-ifc/geometry/operations/bim-geometry/sweep.h"
#include "../web-ifc/geometry/operations/bim-geometry/circularSweep.h"
#include "../web-ifc/geometry/operations/bim-geometry/revolution.h"
#include "../web-ifc/geometry/operations/bim-geometry/cylindricalRevolution.h"
#include "../web-ifc/geometry/operations/bim-geometry/parabola.h"
Expand Down Expand Up @@ -800,6 +801,12 @@ bimGeometry::Sweep CreateSweep()
return bimGeometry::Sweep();
}

bimGeometry::CircularSweep CreateCircularSweep()
{
return bimGeometry::CircularSweep();
}


bimGeometry::Revolve CreateRevolution()
{
return bimGeometry::Revolve();
Expand Down Expand Up @@ -842,8 +849,6 @@ EMSCRIPTEN_BINDINGS(my_module) {
.function("GetSweptDiskSolid", &webifc::geometry::IfcGeometry::GetSweptDiskSolid)
;



emscripten::value_object<glm::dvec4>("dvec4")
.field("x", &glm::dvec4::x)
.field("y", &glm::dvec4::y)
Expand Down Expand Up @@ -962,19 +967,26 @@ EMSCRIPTEN_BINDINGS(my_module) {
.function("GetBuffers", &bimGeometry::AABB::GetBuffers)
.function("SetValues", &bimGeometry::AABB::SetValues)
;


emscripten::class_<bimGeometry::Extrusion>("Extrusion")
.constructor<>()
.function("GetBuffers", &bimGeometry::Extrusion::GetBuffers)
.function("SetValues", &bimGeometry::Extrusion::SetValues)
.function("SetHoles", &bimGeometry::Extrusion::SetHoles)
.function("ClearHoles", &bimGeometry::Extrusion::ClearHoles)
;

emscripten::class_<bimGeometry::Sweep>("Sweep")
.constructor<>()
.function("GetBuffers", &bimGeometry::Sweep::GetBuffers)
.function("SetValues", &bimGeometry::Sweep::SetValues)
;

emscripten::class_<bimGeometry::CircularSweep>("CircularSweep")
.constructor<>()
.function("GetBuffers", &bimGeometry::CircularSweep::GetBuffers)
.function("SetValues", &bimGeometry::CircularSweep::SetValues)
;

emscripten::class_<bimGeometry::Revolve>("Revolution")
.constructor<>()
Expand Down Expand Up @@ -1015,6 +1027,7 @@ EMSCRIPTEN_BINDINGS(my_module) {
emscripten::function("CreateAABB", &CreateAABB);
emscripten::function("CreateExtrusion", &CreateExtrusion);
emscripten::function("CreateSweep", &CreateSweep);
emscripten::function("CreateCircularSweep", &CreateCircularSweep);
emscripten::function("CreateRevolution", &CreateRevolution);
emscripten::function("CreateCylindricalRevolution", &CreateCylindricalRevolution);
emscripten::function("CreateParabola", &CreateParabola);
Expand Down
44 changes: 44 additions & 0 deletions src/cpp/web-ifc/geometry/operations/bim-geometry/circularSweep.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <vector>
#include <algorithm>
#include <glm/glm.hpp>
#include "circularSweep.h"
#include "epsilons.h"
#include "geometry.h"
#include "utils.h"

using Vec = glm::dvec3;

namespace bimGeometry {

Buffers CircularSweep::GetBuffers()
{
Buffers buffers;

// Canviar la funcio revolution
Geometry geom = SweepCircular(scaling, closed, profilePoints, radius, directrix, initialDirectrixNormal, rotate90);

for (int r = 0; r < geom.numFaces; r++)
{
bimGeometry::Face f = geom.GetFace(r);
buffers.AddTri(geom.GetPoint(f.i0), geom.GetPoint(f.i1), geom.GetPoint(f.i2));
}

return buffers;
}

void CircularSweep::SetValues(double scaling_, bool closed_, std::vector<double> profilePoints_, double radius_, std::vector<double> directrix_, std::vector<double> initialDirectrixNormal_, bool rotate90_) {
profilePoints.clear();
for (size_t i = 0; i + 2 < profilePoints_.size(); i += 3) {
profilePoints.emplace_back(profilePoints_[i], profilePoints_[i + 1], profilePoints_[i + 2]);
}
directrix.clear();
for (size_t i = 0; i + 2 < directrix_.size(); i += 3) {
directrix.emplace_back(directrix_[i], directrix_[i + 1], directrix_[i + 2]);
}
initialDirectrixNormal = glm::dvec3(initialDirectrixNormal_[0], initialDirectrixNormal_[1], initialDirectrixNormal_[2]);
scaling = scaling_;
closed = closed_;
radius = radius_;
rotate90 = rotate90_;
}
}
26 changes: 26 additions & 0 deletions src/cpp/web-ifc/geometry/operations/bim-geometry/circularSweep.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <vector>
#include <algorithm>
#include <glm/glm.hpp>
#include "buffers.h"

using Vec = glm::dvec3;

#pragma once

namespace bimGeometry {

struct CircularSweep
{
double scaling;
bool closed;
std::vector<glm::dvec3> profilePoints;
double radius;
std::vector<glm::dvec3> directrix;
glm::dvec3 initialDirectrixNormal;
bool rotate90;


void SetValues(double scaling_, bool closed_, std::vector<double> profilePoints_, double radius_, std::vector<double> directrix_, std::vector<double> initialDirectrixNormal_, bool rotate90_);
Buffers GetBuffers();
};
}
40 changes: 38 additions & 2 deletions src/cpp/web-ifc/geometry/operations/bim-geometry/extrusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,28 @@ namespace bimGeometry {
{
Buffers buffers;

Geometry geom = Extrude(profile, dir, len);
Geometry geom;
if(!cap)
{
geom = Extrude(profile, dir, len);
}
else
{
uint32_t profileNumber = 1 + holes.size();
std::vector<std::vector<glm::dvec3>> profiles(profileNumber);

for (size_t i = 0; i < profile.size(); i++) {
profiles[0].emplace_back(profile[i].x, profile[i].y, profile[i].z);
}

for (size_t i = 0; i < holes.size(); i++) {
for (size_t j = 0; j < holes[i].size(); j++) {
profiles[i + 1].emplace_back(holes[i][j].x, holes[i][j].y, holes[i][j].z);
}
}

geom = Extrude(profiles, dir, len, cuttingPlaneNormal, cuttingPlanePos);
}

for (int r = 0; r < geom.numFaces; r++)
{
Expand All @@ -25,7 +46,7 @@ namespace bimGeometry {
return buffers;
}

void Extrusion::SetValues(std::vector<double> profile_, std::vector<double> dir_, double len_) {
void Extrusion::SetValues(std::vector<double> profile_, std::vector<double> dir_, double len_, std::vector<double> cuttingPlaneNormal_, std::vector<double> cuttingPlanePos_, bool cap_) {
profile.clear();
for (size_t i = 0; i + 2 < profile_.size(); i += 3) {
profile.emplace_back(profile_[i], profile_[i + 1], profile_[i + 2]);
Expand All @@ -34,5 +55,20 @@ namespace bimGeometry {
dir = glm::dvec3(dir_[0], dir_[1], dir_[2]);
}
len = len_;
cap = cap_;
cuttingPlanePos = glm::dvec3(cuttingPlanePos_[0], cuttingPlanePos_[1], cuttingPlanePos_[2]);
cuttingPlaneNormal = glm::dvec3(cuttingPlaneNormal_[0], cuttingPlaneNormal_[1], cuttingPlaneNormal_[2]);
}

void Extrusion::SetHoles(std::vector<double> hole_) {
std::vector<glm::dvec3> hole;
for (size_t i = 0; i + 2 < hole_.size(); i += 3) {
hole.emplace_back(hole_[i], hole_[i + 1], hole_[i + 2]);
}
holes.push_back(hole);
}

void Extrusion::ClearHoles() {
holes.clear();
}
}
10 changes: 8 additions & 2 deletions src/cpp/web-ifc/geometry/operations/bim-geometry/extrusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ namespace bimGeometry {

struct Extrusion
{
bool cap;
double len;
glm::dvec3 dir;
glm::dvec3 dir;
glm::dvec3 cuttingPlanePos;
glm::dvec3 cuttingPlaneNormal;
std::vector<glm::dvec3> profile;
std::vector<std::vector<glm::dvec3>> holes;

void SetValues(std::vector<double> profile_, std::vector<double> dir_, double len_);
void SetValues(std::vector<double> profile_, std::vector<double> dir_, double len_, std::vector<double> cuttingPlaneNormal_, std::vector<double> cuttingPlanePos_, bool cap_);
void SetHoles(std::vector<double> hole_);
void ClearHoles();
Buffers GetBuffers();
};
}
Loading