Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
beachtom committed Sep 1, 2023
1 parent 311d395 commit fe54989
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 86 deletions.
14 changes: 7 additions & 7 deletions benchmark.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# System informations
{"gpu":"","cpuName":"Apple M1","freeRam":446.859375,"totalRam":8192}
{"gpu":"","cpuName":"Apple M1","freeRam":85.890625,"totalRam":8192}
_________
| filename | Size (mb) | Time to open model (ms) | Time to execute all (ms) | Total ifc entities | Total meshes | Total geometries | total errors |
|-------|-------|-------|-------|-------|-------|-------|-------|
| ifcfiles/advanced_model.ifc.test | 33.67 | 256 | 2010 | 594374 | 6401 | 14120 | 0 |
ifcfiles/dental_clinic.ifc.test | 12.4 | 107 | 953 | 209259 | 2586 | 2626 | 176 |
ifcfiles/example.ifc.test | 0.39 | 8 | 17 | 6487 | 115 | 119 | 0 |
ifcfiles/large.ifc.test | 251.25 | 1482 | 5628 | 2153923 | 8701 | 9875 | 182 |
ifcfiles/schependomlaan.ifc.test | 47 | 385 | 1064 | 714485 | 3569 | 3643 | 7296 |
ifcfiles/tested_sample_project.ifc.test | 0.68 | 6 | 97 | 14119 | 93 | 98 | 0 |
| ifcfiles/advanced_model.ifc.test | 33.67 | 279 | 2328 | 594374 | 6401 | 14120 | 0 |
ifcfiles/dental_clinic.ifc.test | 12.4 | 97 | 1128 | 209259 | 2586 | 2626 | 176 |
ifcfiles/example.ifc.test | 0.39 | 5 | 9 | 6487 | 115 | 119 | 0 |
ifcfiles/large.ifc.test | 251.25 | 1562 | 5605 | 2153923 | 8701 | 9875 | 182 |
ifcfiles/schependomlaan.ifc.test | 47 | 399 | 1045 | 714485 | 3569 | 3643 | 7296 |
ifcfiles/tested_sample_project.ifc.test | 0.68 | 6 | 115 | 14119 | 93 | 98 | 0 |
103 changes: 40 additions & 63 deletions src/wasm/parsing/IfcLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cmath>
#include <algorithm>
#include <format>
#include <fast_float/fast_float.h>
#include "IfcLoader.h"
#include "../utility/LoaderError.h"
#include "../utility/Logging.h"
Expand Down Expand Up @@ -153,33 +154,17 @@ namespace webifc::parsing {
output << "." << _tokenStream->ReadString() << ".";
break;
}
case IfcTokenType::LABEL:
{
output << _tokenStream->ReadString();
break;
}
case IfcTokenType::REF:
{
output << "#" << _tokenStream->Read<uint32_t>();
if (newLine) output << "=";
break;
}
case IfcTokenType::LABEL:
case IfcTokenType::REAL:
{
double number = _tokenStream->Read<double>();
if (std::floor(number) == number) output << (long)number << ".";
else {
//decimal
std::string numberString = std::format("{}", number);
size_t eLoc = numberString.find_first_of('e');
if (eLoc != std::string::npos) numberString[eLoc]='E';
output << numberString;
}
break;
}
case IfcTokenType::INTEGER:
{
output << std::to_string(_tokenStream->Read<int>());
output << _tokenStream->ReadString();
break;
}
default:
Expand Down Expand Up @@ -260,9 +245,12 @@ namespace webifc::parsing {
case IfcTokenType::SET_END:
break;
case IfcTokenType::STRING:
case IfcTokenType::REAL:
case IfcTokenType::INTEGER:
case IfcTokenType::ENUM:
{
_tokenStream->ReadString();
auto size = _tokenStream->Read<uint16_t>();
_tokenStream->Forward(size);
break;
}
case IfcTokenType::LABEL:
Expand All @@ -277,16 +265,6 @@ namespace webifc::parsing {
if (currentExpressID == 0) currentExpressID = ref;
break;
}
case IfcTokenType::REAL:
{
_tokenStream->Forward(sizeof(double));
break;
}
case IfcTokenType::INTEGER:
{
_tokenStream->Forward(sizeof(int));
break;
}
default:
break;
}
Expand Down Expand Up @@ -341,17 +319,40 @@ namespace webifc::parsing {
std::string_view str = GetStringArgument();
return p21decode(str);
}

void IfcLoader::PushDouble(double input)
{
std::string numberString = std::format("{}", input);
uint16_t length = numberString.size();
Push<uint16_t>((uint16_t)length);
Push((void*)numberString.c_str(), numberString.size());
}

void IfcLoader::PushInt(int input)
{
std::string numberString = std::to_string(input);
uint16_t length = numberString.size();
Push<uint16_t>((uint16_t)length);
Push((void*)numberString.c_str(), numberString.size());
}

double IfcLoader::GetDoubleArgument() const
{
_tokenStream->Read<char>(); // real type
return _tokenStream->Read<double>();
std::string_view str = GetStringArgument();
double number_value;
fast_float::from_chars(str.data(), str.data() +str.size(), number_value);
return number_value;
}

std::string_view IfcLoader::GetDoubleArgumentAsString() const
{
return GetStringArgument();
}

int IfcLoader::GetIntArgument() const
{
_tokenStream->Read<char>();
return _tokenStream->Read<int>();
std::string_view str = GetStringArgument();
return std::stoi(std::string(str));
}

int IfcLoader::GetIntArgument(const uint32_t tapeOffset) const
Expand Down Expand Up @@ -489,19 +490,11 @@ namespace webifc::parsing {
{
tapeOffsets.push_back(offset);

if (t == IfcTokenType::REAL)
{
_tokenStream->Read<double>();
}
else if (t == IfcTokenType::INTEGER)
{
_tokenStream->Read<int>();
}
else if (t == IfcTokenType::REF)
if (t == IfcTokenType::REF)
{
_tokenStream->Read<uint32_t>();
}
else if (t == IfcTokenType::STRING)
else if (t == IfcTokenType::STRING || t == IfcTokenType::INTEGER || t == IfcTokenType::REAL)
{
uint16_t length = _tokenStream->Read<uint16_t>();
_tokenStream->Forward(length);
Expand Down Expand Up @@ -556,19 +549,11 @@ namespace webifc::parsing {
{
tempSet.push_back(offset);

if (t == IfcTokenType::REAL)
{
_tokenStream->Read<double>();
}
else if (t == IfcTokenType::INTEGER)
{
_tokenStream->Read<int>();
}
else if (t == IfcTokenType::REF)
if (t == IfcTokenType::REF)
{
_tokenStream->Read<uint32_t>();
}
else if (t == IfcTokenType::STRING)
else if (t == IfcTokenType::STRING || t == IfcTokenType::INTEGER || t == IfcTokenType::REAL)
{
uint16_t length = _tokenStream->Read<uint16_t>();
_tokenStream->Forward(length);
Expand Down Expand Up @@ -634,6 +619,8 @@ namespace webifc::parsing {
case IfcTokenType::STRING:
case IfcTokenType::ENUM:
case IfcTokenType::LABEL:
case IfcTokenType::INTEGER:
case IfcTokenType::REAL:
{
uint16_t length = _tokenStream->Read<uint16_t>();
_tokenStream->Forward(length);
Expand All @@ -644,16 +631,6 @@ namespace webifc::parsing {
_tokenStream->Read<uint32_t>();
break;
}
case IfcTokenType::REAL:
{
_tokenStream->Read<double>();
break;
}
case IfcTokenType::INTEGER:
{
_tokenStream->Read<int>();
break;
}
default:
break;
}
Expand Down
3 changes: 3 additions & 0 deletions src/wasm/parsing/IfcLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace webifc::parsing
int GetIntArgument() const;
int GetIntArgument(const uint32_t tapeOffset) const;
double GetDoubleArgument(const uint32_t tapeOffset) const;
std::string_view GetDoubleArgumentAsString() const;
double GetOptionalDoubleParam(double defaultValue) const;
uint32_t GetRefArgument() const;
uint32_t GetRefArgument(const uint32_t tapeOffset) const;
Expand All @@ -58,6 +59,8 @@ namespace webifc::parsing
void AddHeaderLineTape(const uint32_t type, const uint32_t start);
uint32_t GetCurrentLineExpressID() const;
void RemoveLine(const uint32_t expressID);
void PushDouble(double input);
void PushInt(int input);
template <typename T> void Push(T input)
{
_tokenStream->Push(input);
Expand Down
14 changes: 4 additions & 10 deletions src/wasm/parsing/IfcTokenChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


#include "IfcTokenStream.h"
#include <fast_float/fast_float.h>

namespace webifc::parsing
{
Expand Down Expand Up @@ -158,15 +157,10 @@ namespace webifc::parsing
_fileStream->Forward();
c = _fileStream->Get();
}
double number_value;
fast_float::from_chars(temp.data(), temp.data() +temp.size(), number_value);
if (!isFrac) {
Push<uint8_t>(IfcTokenType::INTEGER);
Push<int>((int)number_value);
} else {
Push<uint8_t>(IfcTokenType::REAL);
Push<double>(number_value);
}
if (isFrac) Push<uint8_t>(IfcTokenType::REAL);
else Push<uint8_t>(IfcTokenType::INTEGER);
Push<uint16_t>(temp.size());
Push(temp.data(), temp.size());

// skip next advance
continue;
Expand Down
12 changes: 6 additions & 6 deletions src/wasm/web-ifc-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,13 @@ bool WriteValue(uint32_t modelID, webifc::parsing::IfcTokenType t, emscripten::v
case webifc::parsing::IfcTokenType::REAL:
{
double val = value.as<double>();
loader->Push<double>(val);
loader->PushDouble(val);
break;
}
case webifc::parsing::IfcTokenType::INTEGER:
{
int val = value.as<int>();
loader->Push<int>(val);
loader->PushInt(val);
break;
}
default:
Expand Down Expand Up @@ -580,10 +580,10 @@ bool WriteSet(uint32_t modelID, emscripten::val& val)
loader->Push<uint8_t>(type);
if (type == webifc::parsing::IfcTokenType::INTEGER) {
int value = innerVal[std::to_string(z)].as<int>();
loader->Push<int>(value);
loader->PushInt(value);
} else {
double value = innerVal[std::to_string(z)].as<double>();
loader->Push<double>(value);
loader->PushDouble(value);
}
}
loader->Push(webifc::parsing::IfcTokenType::SET_END);
Expand Down Expand Up @@ -745,8 +745,8 @@ emscripten::val ReadValue(uint32_t modelID, webifc::parsing::IfcTokenType t)
}
case webifc::parsing::IfcTokenType::REAL:
{
double d = loader->GetDoubleArgument();
return emscripten::val(std::to_string(d));
std::string_view s = loader->GetDoubleArgumentAsString();
return emscripten::val(std::string(s));
}
case webifc::parsing::IfcTokenType::INTEGER:
{
Expand Down

0 comments on commit fe54989

Please sign in to comment.