Skip to content

Commit

Permalink
Merge pull request #1130 from ThatOpen/Fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
beachtom authored Nov 12, 2024
2 parents a762005 + 2c76b8b commit f3f98a4
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 135 deletions.
55 changes: 27 additions & 28 deletions benchmark.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
# System informations
{"cpuName":"Apple M1","freeRam":76.6875,"totalRam":8192}
{"cpuName":"Apple M1","freeRam":127.1875,"totalRam":8192}
_________
| filename | Size (mb) | Time to open model (ms) | Time to execute all (ms) | Total ifc entities | Total meshes | Total geometries | total errors |
|-------|-------|-------|-------|-------|-------|-------|-------|
| tests/ifcfiles/public/AC20-FZK-Haus.ifc | 2.45 | 48 | 294 | 44249 | 83 | 103 | undefined |
tests/ifcfiles/public/C20-Institute-Var-2.ifc | 10.43 | 93 | 597 | 147712 | 702 | 821 | undefined |
tests/ifcfiles/public/Element3D.ifc | 2.02 | 16 | 844 | 32875 | 1 | 5 | undefined |
tests/ifcfiles/public/FM_ARC_DigitalHub.ifc | 13.66 | 102 | 1113 | 266483 | 705 | 725 | undefined |
tests/ifcfiles/public/ISSUE_005_haus.ifc | 2.41 | 22 | 156 | 44249 | 83 | 103 | undefined |
tests/ifcfiles/public/ISSUE_021_Mini Project.ifc | 3.2 | 24 | 632 | 49044 | 2636 | 3697 | undefined |
tests/ifcfiles/public/ISSUE_034_HouseZ.ifc | 4.92 | 36 | 189 | 81806 | 228 | 239 | undefined |
| tests/ifcfiles/public/AC20-FZK-Haus.ifc | 2.45 | 32 | 317 | 44249 | 83 | 103 | undefined |
tests/ifcfiles/public/C20-Institute-Var-2.ifc | 10.43 | 88 | 1134 | 147712 | 702 | 821 | undefined |
tests/ifcfiles/public/FM_ARC_DigitalHub.ifc | 13.66 | 200 | 1407 | 266483 | 705 | 725 | undefined |
tests/ifcfiles/public/ISSUE_005_haus.ifc | 2.41 | 23 | 239 | 44249 | 83 | 103 | undefined |
tests/ifcfiles/public/ISSUE_021_Mini Project.ifc | 3.2 | 25 | 691 | 49044 | 2636 | 3697 | undefined |
tests/ifcfiles/public/ISSUE_034_HouseZ.ifc | 4.92 | 37 | 191 | 81806 | 228 | 239 | undefined |
tests/ifcfiles/public/ISSUE_044_test_IFCCOMPOSITEPROFILEDEF.ifc | 0.03 | 0 | 0 | 435 | 7 | 11 | undefined |
tests/ifcfiles/public/ISSUE_053_20181220Holter_Tower_10.ifczip | 29.38 | 1452 | 11189 | 2807815 | 60285 | 60847 | undefined |
tests/ifcfiles/public/ISSUE_068_ARK_NUS_skolebygg.ifc | 54.65 | 460 | 4372 | 945194 | 4459 | 4542 | undefined |
tests/ifcfiles/public/ISSUE_102_M3D-CON-CD.ifc | 26.11 | 211 | 3052 | 503608 | 1616 | 1635 | undefined |
tests/ifcfiles/public/ISSUE_102_M3D-CON.ifc | 6.1 | 102 | 300 | 123282 | 138 | 143 | undefined |
tests/ifcfiles/public/ISSUE_126_model.ifc | 4.32 | 35 | 112 | 88876 | 257 | 288 | undefined |
tests/ifcfiles/public/ISSUE_129_N1540_17_EXE_MOD_448200_02_09_11SMC_IGC_V17.ifc | 11.67 | 88 | 711 | 202661 | 959 | 981 | undefined |
tests/ifcfiles/public/ISSUE_159_kleine_Wohnung_R22.ifc | 9.73 | 76 | 667 | 189788 | 425 | 457 | undefined |
tests/ifcfiles/public/ISSUE_171_IfcSurfaceCurveSweptAreaSolid.ifc | 0.24 | 3 | 17 | 4327 | 60 | 141 | undefined |
tests/ifcfiles/public/IfcOpenHouse_IFC4.ifc | 0.11 | 1 | 6 | 2885 | 35 | 43 | undefined |
tests/ifcfiles/public/KIT-Simple-Road-Test-Web-IFC4x3_RC2.ifc | 0.38 | 390 | 163 | 6500 | 66 | 119 | undefined |
tests/ifcfiles/public/Office_A_20110811.ifc | 3.91 | 48 | 275 | 62930 | 803 | 810 | undefined |
tests/ifcfiles/public/S_Office_Integrated Design Archi.ifc | 29.62 | 274 | 5349 | 551442 | 3418 | 3873 | undefined |
tests/ifcfiles/public/Sample_entities.ifc | 0.03 | 0 | 0 | 466 | 2 | 10 | undefined |
tests/ifcfiles/public/advanced_model.ifc | 33.67 | 310 | 2348 | 594374 | 6401 | 14120 | undefined |
tests/ifcfiles/public/dental_clinic.ifc | 12.4 | 91 | 855 | 209259 | 2586 | 2626 | undefined |
tests/ifcfiles/public/duplex.ifc | 2.27 | 18 | 67 | 38898 | 216 | 224 | undefined |
tests/ifcfiles/public/example.ifc | 0.39 | 3 | 8 | 6488 | 115 | 119 | undefined |
tests/ifcfiles/public/ifcbridge-model01.ifc | 14.47 | 180 | 281 | 296968 | 165 | 168 | undefined |
tests/ifcfiles/public/schependomlaan.ifc | 47 | 435 | 760 | 714485 | 3569 | 3643 | undefined |
tests/ifcfiles/public/tested_sample_project.ifc | 0.68 | 6 | 117 | 14119 | 93 | 98 | undefined |
tests/ifcfiles/public/ISSUE_053_20181220Holter_Tower_10.ifczip | 29.38 | 1453 | 11592 | 2807815 | 60285 | 60847 | undefined |
tests/ifcfiles/public/ISSUE_068_ARK_NUS_skolebygg.ifc | 54.65 | 644 | 4520 | 945194 | 4459 | 4542 | undefined |
tests/ifcfiles/public/ISSUE_102_M3D-CON-CD.ifc | 26.11 | 210 | 3205 | 503608 | 1616 | 1635 | undefined |
tests/ifcfiles/public/ISSUE_102_M3D-CON.ifc | 6.1 | 51 | 283 | 123282 | 138 | 143 | undefined |
tests/ifcfiles/public/ISSUE_126_model.ifc | 4.32 | 34 | 125 | 88876 | 257 | 288 | undefined |
tests/ifcfiles/public/ISSUE_129_N1540_17_EXE_MOD_448200_02_09_11SMC_IGC_V17.ifc | 11.67 | 92 | 727 | 202661 | 959 | 981 | undefined |
tests/ifcfiles/public/ISSUE_159_kleine_Wohnung_R22.ifc | 9.73 | 78 | 738 | 189788 | 425 | 457 | undefined |
tests/ifcfiles/public/ISSUE_171_IfcSurfaceCurveSweptAreaSolid.ifc | 0.24 | 2 | 20 | 4327 | 60 | 141 | undefined |
tests/ifcfiles/public/IfcOpenHouse_IFC4.ifc | 0.11 | 1 | 7 | 2885 | 35 | 43 | undefined |
tests/ifcfiles/public/KIT-Simple-Road-Test-Web-IFC4x3_RC2.ifc | 0.38 | 573 | 165 | 6500 | 66 | 119 | undefined |
tests/ifcfiles/public/Office_A_20110811.ifc | 3.91 | 44 | 459 | 62930 | 803 | 810 | undefined |
tests/ifcfiles/public/S_Office_Integrated Design Archi.ifc | 29.62 | 373 | 6904 | 551442 | 3422 | 3873 | undefined |
tests/ifcfiles/public/Sample_entities.ifc | 0.03 | 0 | 1 | 466 | 2 | 10 | undefined |
tests/ifcfiles/public/advanced_model.ifc | 33.67 | 304 | 2373 | 594374 | 6401 | 14120 | undefined |
tests/ifcfiles/public/dental_clinic.ifc | 12.4 | 93 | 886 | 209259 | 2586 | 2626 | undefined |
tests/ifcfiles/public/duplex.ifc | 2.27 | 17 | 73 | 38898 | 216 | 224 | undefined |
tests/ifcfiles/public/example.ifc | 0.39 | 4 | 8 | 6488 | 115 | 119 | undefined |
tests/ifcfiles/public/ifcbridge-model01.ifc | 14.47 | 166 | 283 | 296968 | 165 | 168 | undefined |
tests/ifcfiles/public/schependomlaan.ifc | 47 | 426 | 869 | 714485 | 3569 | 3643 | undefined |
tests/ifcfiles/public/tested_sample_project.ifc | 0.68 | 6 | 123 | 14119 | 93 | 98 | undefined |
2 changes: 1 addition & 1 deletion examples/viewer/web-ifc-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as ts from "typescript";
import { exampleCode } from './example';

let ifcAPI = new IfcAPI();
ifcAPI.SetWasmPath("")
ifcAPI.SetWasmPath("./",true)
let ifcThree = new IfcThree(ifcAPI);

let timeout = undefined;
Expand Down
97 changes: 36 additions & 61 deletions src/cpp/parsing/IfcLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ namespace webifc::parsing {
IfcLoader::IfcLoader(uint32_t tapeSize, uint32_t memoryLimit,uint32_t lineWriterBuffer, const schema::IfcSchemaManager &schemaManager) :_lineWriterBuffer(lineWriterBuffer), _schemaManager(schemaManager)
{
_tokenStream = new IfcTokenStream(tapeSize,memoryLimit/tapeSize);
_nullLine = new IfcLine();
_nullLine->ifcType=0;
_nullLine->tapeOffset=0;
_maxExpressId=0;
}

const std::vector<uint32_t> IfcLoader::GetExpressIDsWithType(const uint32_t type) const
Expand Down Expand Up @@ -87,16 +85,21 @@ namespace webifc::parsing {
output << "* Issues: https://github.com/ThatOpen/engine_web-ifc/issues" << std::endl;
output << "******************************************************/" << std::endl;

const std::vector<IfcLine*> *totalLines[2] = {&_headerLines, &_lines};
uint32_t linesWritten = 0;
for (uint8_t z=0; z < 2; z++)
{
const std::vector<IfcLine*>* currentLines = totalLines[z];
std::vector<IfcLine*>* currentLines;
if(z==0) currentLines= (std::vector<IfcLine*>*) &_headerLines;
else {
currentLines = new std::vector<IfcLine*>();
std::transform( _lines.begin(), _lines.end(), std::back_inserter( *currentLines ), [](auto &kv){ return kv.second;} );
}
for(uint32_t i=0; i < currentLines->size();i++)
{

IfcLine * line = (*currentLines)[i];

if (line == _nullLine || line->ifcType == 0) continue;
if (line->ifcType == 0) continue;
_tokenStream->MoveTo(line->tapeOffset);
bool newLine = true;
bool insideSet = false;
Expand Down Expand Up @@ -216,7 +219,6 @@ namespace webifc::parsing {

void IfcLoader::ParseLines()
{
uint32_t maxExpressId = 0;
uint32_t currentIfcType = 0;
uint32_t currentExpressID = 0;
uint32_t currentTapeOffset = 0;
Expand All @@ -239,9 +241,8 @@ namespace webifc::parsing {
else if (currentExpressID != 0)
{
_ifcTypeToExpressID[currentIfcType].push_back(currentExpressID);
maxExpressId = std::max(maxExpressId, currentExpressID);
_lines.resize(maxExpressId,_nullLine);
_lines[currentExpressID-1]=l;
_maxExpressId = std::max(_maxExpressId, currentExpressID);
_lines[currentExpressID]=l;
currentExpressID = 0;
}
currentIfcType = 0;
Expand Down Expand Up @@ -283,42 +284,37 @@ namespace webifc::parsing {

uint32_t IfcLoader::GetMaxExpressId() const
{
return _lines.size();
return _maxExpressId;
}

bool IfcLoader::IsValidExpressID(const uint32_t expressID) const
{
if (expressID == 0 || expressID > _lines.size() || _lines[expressID-1]==_nullLine) return false;
if (expressID == 0 || expressID > _maxExpressId || !_lines.contains(expressID)) return false;
else return true;
}

uint32_t IfcLoader::GetLineType(const uint32_t expressID) const
{
if (expressID == 0 || expressID > _lines.size()) {
if (expressID == 0 || expressID > _maxExpressId || !_lines.contains(expressID)) {
spdlog::error("[GetLineType()] Attempt to Access Invalid ExpressID {}", expressID);
return 0;
}
return _lines[expressID-1]->ifcType;
return _lines.at(expressID)->ifcType;
}

IfcLoader::~IfcLoader()
{
delete _tokenStream;
for (size_t i=0; i < _lines.size();i++) {
if (_lines[i] == _nullLine) {
continue;
}
delete _lines[i];
}
for (const auto & [key, value] : _lines) delete value;
for (size_t i=0; i < _headerLines.size();i++) delete _headerLines[i];
_lines.clear();
_headerLines.clear();
delete _nullLine;
}

void IfcLoader::MoveToLineArgument(const uint32_t expressID, const uint32_t argumentIndex) const
{
_tokenStream->MoveTo(_lines[expressID-1]->tapeOffset);
if (!_lines.contains(expressID)) return;
_tokenStream->MoveTo(_lines.at(expressID)->tapeOffset);
ArgumentOffset(argumentIndex);
}

Expand Down Expand Up @@ -387,15 +383,13 @@ namespace webifc::parsing {
uint32_t IfcLoader::GetCurrentLineExpressID() const
{
if (_lines.size()==0) return 0;
uint32_t pos = _tokenStream->GetReadOffset();
uint32_t prevLine = 0;
for (size_t i=0; i < _lines.size();i++)
{
if (_lines[i] == _nullLine) continue;
if (_lines[i]->tapeOffset > pos) break;
prevLine = i;
uint32_t pos = _tokenStream->GetReadOffset();
for (const auto & [key, value] : _lines) {
if (value->tapeOffset > pos) break;
prevLine = key;
}
return prevLine+1;
return prevLine;
}

uint32_t IfcLoader::GetRefArgument() const
Expand All @@ -422,29 +416,24 @@ namespace webifc::parsing {

void IfcLoader::RemoveLine(const uint32_t expressID)
{
_lines[expressID-1]->ifcType = 0;
}

void IfcLoader::ExtendLineStorage(uint32_t lineStorageSize)
{
_lines.reserve(_lines.size()+lineStorageSize);
_lines.erase(expressID);
}

void IfcLoader::UpdateLineTape(const uint32_t expressID, const uint32_t type, const uint32_t start)
{
if (expressID > _lines.size())
if (!_lines.contains(expressID))
{
// create line object
IfcLine * line = new IfcLine();
// fill line data
line->ifcType = type;
line->tapeOffset = start;
//place in vector
_lines.resize(expressID,_nullLine);
_lines[expressID-1]=line;
_lines[expressID]=line;
_ifcTypeToExpressID[type].push_back(expressID);
if (expressID > _maxExpressId) _maxExpressId=expressID;

} else _lines[expressID-1]->tapeOffset = start;
} else _lines[expressID]->tapeOffset = start;
}

void IfcLoader::AddHeaderLineTape(const uint32_t type, const uint32_t start)
Expand Down Expand Up @@ -656,8 +645,10 @@ namespace webifc::parsing {

void IfcLoader::MoveToArgumentOffset(const uint32_t expressID, const uint32_t argumentIndex) const
{
_tokenStream->MoveTo(_lines[expressID-1]->tapeOffset);
ArgumentOffset(argumentIndex);
if (_lines.contains(expressID)) {
_tokenStream->MoveTo(_lines.at(expressID)->tapeOffset);
ArgumentOffset(argumentIndex);
}
}

void IfcLoader::StepBack() const {
Expand All @@ -683,30 +674,14 @@ namespace webifc::parsing {

std::vector<uint32_t> IfcLoader::GetAllLines() const {
std::vector<uint32_t> expressIDs;
auto numLines = GetMaxExpressId();
for (uint32_t i = 1; i <= numLines; i++)
{
if (!IsValidExpressID(i)) continue;
expressIDs.push_back(i);
}
std::transform( _lines.begin(), _lines.end(), std::back_inserter( expressIDs ), [](auto &kv){ return kv.first;} );
return expressIDs;
}

uint32_t IfcLoader::GetNextExpressID(uint32_t expressId) const {
uint32_t currentId = expressId;
bool cont = true;
uint32_t maxId = GetMaxExpressId();

while(cont)
{
if(currentId > maxId)
{
cont = false;
continue;
}
currentId++;
cont = !(IsValidExpressID(currentId));
}
uint32_t currentId = expressId+1;
while(!_lines.contains(currentId)) currentId++;
return currentId;
}

}
5 changes: 2 additions & 3 deletions src/cpp/parsing/IfcLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ namespace webifc::parsing
void RemoveLine(const uint32_t expressID);
void PushDouble(double input);
void PushInt(int input);
void ExtendLineStorage(uint32_t lineStorageSize);
uint32_t GetNextExpressID(uint32_t expressId) const;
template <typename T> void Push(T input)
{
Expand All @@ -74,11 +73,11 @@ namespace webifc::parsing
uint32_t ifcType;
uint32_t tapeOffset;
};
uint32_t _maxExpressId;
const uint32_t _lineWriterBuffer;
const schema::IfcSchemaManager &_schemaManager;
IfcTokenStream * _tokenStream;
IfcLine * _nullLine;
std::vector<IfcLine*> _lines;
std::unordered_map<uint32_t,IfcLine*> _lines;
std::vector<IfcLine*> _headerLines;
std::unordered_map<uint32_t, std::vector<uint32_t>> _ifcTypeToExpressID;
void ParseLines();
Expand Down
7 changes: 1 addition & 6 deletions src/cpp/web-ifc-wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,6 @@ bool ValidateExpressID(uint32_t modelID, uint32_t expressId) {
return manager.IsModelOpen(modelID) ? manager.GetIfcLoader(modelID)->IsValidExpressID(expressId) : false;
}

void ExtendLineStorage(uint32_t modelID, uint32_t lineStorageSize) {
if (manager.IsModelOpen(modelID)) manager.GetIfcLoader(modelID)->ExtendLineStorage(lineStorageSize);
}

uint32_t GetNextExpressID(uint32_t modelID, uint32_t expressId) {
return manager.IsModelOpen(modelID) ? manager.GetIfcLoader(modelID)->GetNextExpressID(expressId) : 0;
}
Expand Down Expand Up @@ -392,7 +388,7 @@ bool WriteSet(uint32_t modelID, emscripten::val& val)
{
emscripten::val child = val[std::to_string(i)];
if (child.isNull()) loader->Push<uint8_t>(webifc::parsing::IfcTokenType::EMPTY);
else if (child.isUndefined()) loader->Push<uint8_t>(webifc::parsing::IfcTokenType::EMPTY);
else if (child.isUndefined()) loader->Push<uint8_t>(webifc::parsing::IfcTokenType::UNKNOWN);
else if (child.isArray()) WriteSet(modelID,child);
else if (child["value"].isArray())
{
Expand Down Expand Up @@ -824,7 +820,6 @@ EMSCRIPTEN_BINDINGS(my_module) {

emscripten::register_vector<double>("DoubleVector");

emscripten::function("ExtendLineStorage", &ExtendLineStorage);
emscripten::function("LoadAllGeometry", &LoadAllGeometry);
emscripten::function("GetAllCrossSections", &GetAllCrossSections);
emscripten::function("GetAllAlignments", &GetAllAlignments);
Expand Down
2 changes: 1 addition & 1 deletion src/schema-generator/gen_functional_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ for (var i = 0; i < files.length; i++) {

//generate ToRawLineData
tsSchema.push(`ToRawLineData[${i}]={`)
for (var x=0; x < entities.length; x++) tsSchema.push(`${crc32(entities[x].name.toUpperCase(),crcTable)}:(${entities[x].derivedProps.length==0?'_:any': `i:${schemaNameClean}.${entities[x].name}`}):unknown[]=>[${entities[x].derivedProps.map((p) => generateTapeAssignment(p,types)).join(", ")}],`);
for (var x=0; x < entities.length; x++) tsSchema.push(`${crc32(entities[x].name.toUpperCase(),crcTable)}:(${entities[x].derivedProps.length==0?'_:any': `i:${schemaNameClean}.${entities[x].name}`}):unknown[]=>[${entities[x].derivedProps.map((p) => generateTapeAssignment(p,entities[x].ifcDerivedProps,types)).join(", ")}],`);
tsSchema.push('}');

//initialisers
Expand Down
8 changes: 6 additions & 2 deletions src/schema-generator/gen_functional_types_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ export function sortEntities(entities: Array<Entity>) {
return sortedEntities;
}

export function generateTapeAssignment(p: Prop, types:Type[])
export function generateTapeAssignment(p: Prop, ifcDerivedProps: string[],types:Type[])
{
let type = types.find( (x:Type) => x.name == p.type);
if (p.set && type?.isSelect)
if (ifcDerivedProps.includes(p.name))
{
return "undefined";
}
else if (p.set && type?.isSelect)
{
let isEntitySelect = type?.values.some(refType => types.findIndex( t => t.name==refType)==-1);
if (isEntitySelect) return `i.${p.name}`;
Expand Down
Loading

0 comments on commit f3f98a4

Please sign in to comment.