Last active
July 12, 2024 03:21
-
-
Save cdiggins/250d02e93c195ae17463ecb8913094e8 to your computer and use it in GitHub Desktop.
Using Web IFC C++ to parse IFC files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Modified from https://github.com/ThatOpen/engine_web-ifc/blob/main/src/cpp/web-ifc-test.cpp | |
This is a snippet of code used to properly benchmark Web IFC in C++ | |
https://github.com/ThatOpen/engine_web-ifc for loading files and counting doors. | |
Unlike the previous code, we count the entire file load process. | |
*/ | |
int main(int argc, char* argv[]) | |
{ | |
std::cout << "Web IFC test" << std::endl; | |
std::cout << "# args = " << argc << std::endl; | |
if (argc != 3) | |
{ | |
std::cout << "Incorrect number of arguments " << argc << std::endl; | |
return 1; | |
} | |
std::cout << "Type = " << argv[1] << std::endl; | |
std::cout << "File = " << std::filesystem::path(argv[2]).filename() << std::endl; | |
auto start = ms(); | |
std::string content = ReadFile(argv[2]); | |
auto time = ms() - start; | |
std::cout << "Loading file took " << time << "ms" << std::endl; | |
std::cout << "File is " << content.size() << "bytes" << std::endl; | |
struct LoaderSettings { | |
bool COORDINATE_TO_ORIGIN = false; | |
uint16_t CIRCLE_SEGMENTS = 12; | |
uint32_t TAPE_SIZE = 67108864 ; | |
uint32_t MEMORY_LIMIT = 2147483648; | |
uint16_t LINEWRITER_BUFFER = 10000; | |
}; | |
LoaderSettings set; | |
set.COORDINATE_TO_ORIGIN = true; | |
webifc::schema::IfcSchemaManager schemaManager; | |
webifc::parsing::IfcLoader loader(set.TAPE_SIZE, set.MEMORY_LIMIT, set.LINEWRITER_BUFFER, schemaManager); | |
auto last = ms(); | |
loader.LoadFile([&](char *dest, size_t sourceOffset, size_t destSize) { | |
uint32_t length = std::min(content.size() - sourceOffset, destSize); | |
memcpy(dest, &content[sourceOffset], length); | |
return length; }); | |
time = ms() - last; | |
std::cout << "Parsing took " << time << "ms" << std::endl; | |
last = ms(); | |
auto typeCode = schemaManager.IfcTypeToTypeCode(argv[1]); | |
auto recs = loader.GetExpressIDsWithType(typeCode); | |
time = ms() - last; | |
std::cout << "Found " << recs.size() << " entities in " << time << "ms" << std::endl; | |
time = ms() - start; | |
std::cout << "Total time is " << time << "ms" << std::endl; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment