Merge remote-tracking branch 'origin/v0.6.0' into v0.7.0

This commit is contained in:
Thomas Krijnen
2019-08-02 13:23:41 +02:00
60 changed files with 180390 additions and 1723 deletions
+17 -8
View File
@@ -54,6 +54,13 @@ GltfSerializer::GltfSerializer(const std::string& filename, const SerializerSett
, tmp_fstream2_(IfcUtil::path::from_utf8(tmp_filename2_).c_str(), std::ios_base::binary)
{}
GltfSerializer::~GltfSerializer() {
tmp_fstream1_.close();
tmp_fstream2_.close();
IfcUtil::path::delete_file(tmp_filename1_);
IfcUtil::path::delete_file(tmp_filename2_);
}
bool GltfSerializer::ready() {
return fstream_.is_open() && tmp_fstream1_.is_open() && tmp_fstream2_.is_open();
}
@@ -127,7 +134,7 @@ size_t write_accessor(json& j, std::ofstream& ofs, It begin, It end) {
std::array<typename It::value_type, N> min, max;
min.fill(std::numeric_limits<typename It::value_type>::max());
max.fill(std::numeric_limits<typename It::value_type>::min());
max.fill(std::numeric_limits<typename It::value_type>::lowest());
for (auto it = begin; it != end; it += N) {
for (size_t i = 0; i < N; ++i) {
const float& v = *(it + i);
@@ -151,15 +158,19 @@ size_t write_accessor(json& j, std::ofstream& ofs, It begin, It end) {
}
void GltfSerializer::write(const IfcGeom::TriangulationElement<real_t>* o) {
if (o->geometry().material_ids().empty()) {
return;
}
node_array_.push_back(json_["nodes"].size());
const std::vector<double>& m = o->transformation().matrix().data();
// nb: note that this contains the Y-UP transform as well.
const std::array<double, 16> matrix_flat = {
m[0], m[ 2], m[ 1], 0,
m[3], m[ 5], m[ 4], 0,
m[6], m[ 8], m[ 7], 0,
m[9], m[11], m[10], 1
m[0], m[ 2], -m[ 1], 0,
m[3], m[ 5], -m[ 4], 0,
m[6], m[ 8], -m[ 7], 0,
m[9], m[11], -m[10], 1
};
static const std::array<double, 16> identity_matrix = {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
@@ -168,6 +179,7 @@ void GltfSerializer::write(const IfcGeom::TriangulationElement<real_t>* o) {
// glTF validator complains about identity matrices
node["matrix"] = matrix_flat;
}
node["name"] = object_id(o);
int current_mesh_index;
@@ -319,9 +331,6 @@ void GltfSerializer::finalize() {
fstream_ << ifs.rdbuf();
}
write_padding<BIN>(fstream_, binary_length);
IfcUtil::path::delete_file(tmp_filename1_);
IfcUtil::path::delete_file(tmp_filename2_);
}
#endif
+1 -1
View File
@@ -39,7 +39,7 @@ private:
int writeMaterial(const IfcGeom::Material& style);
public:
GltfSerializer(const std::string& filename, const SerializerSettings& settings);
virtual ~GltfSerializer() {}
virtual ~GltfSerializer();
bool ready();
void writeHeader();
void write(const IfcGeom::TriangulationElement<real_t>* o);
+12 -44
View File
@@ -290,57 +290,25 @@ void SvgSerializer::write(const IfcGeom::NativeElement<real_t>* o)
IfcUtil::IfcBaseEntity* storey = storey_;
boost::optional<double> storey_elevation = boost::none;
/*
TODO: based on NativeElement::parent()
IfcSchema::IfcObjectDefinition* obdef = static_cast<IfcSchema::IfcObjectDefinition*>(file->entityById(o->id()));
#ifndef USE_IFC4
typedef IfcSchema::IfcRelDecomposes decomposition_element;
#else
typedef IfcSchema::IfcRelAggregates decomposition_element;
#endif
for (; storey == 0;) {
// Iterate over the decomposing element to find the parent IfcBuildingStorey
decomposition_element::list::ptr decomposes = obdef->Decomposes();
if (!decomposes->size()) {
if (obdef->declaration().is(IfcSchema::Type::IfcElement)) {
IfcSchema::IfcRelContainedInSpatialStructure::list::ptr containment = ((IfcSchema::IfcElement*)obdef)->ContainedInStructure();
if (!containment->size()) {
break;
}
for (IfcSchema::IfcRelContainedInSpatialStructure::list::it it = containment->begin(); it != containment->end(); ++it) {
IfcSchema::IfcRelContainedInSpatialStructure* container = *it;
if (container->RelatingStructure() != obdef) {
obdef = container->RelatingStructure();
}
}
} else {
break;
}
} else {
for (decomposition_element::list::it it = decomposes->begin(); it != decomposes->end(); ++it) {
decomposition_element* decompose = *it;
if (decompose->RelatingObject() != obdef) {
obdef = decompose->RelatingObject();
}
}
}
if (obdef->declaration().is(IfcSchema::Type::IfcBuildingStorey)) {
storey = static_cast<IfcSchema::IfcBuildingStorey*>(obdef);
if (storey->hasElevation()) {
for (const auto& p : o->parents()) {
if (p->type() == "IfcBuildingStorey") {
try {
const IfcGeom::ElementSettings& settings = o->geometry().settings();
storey_elevation = storey->Elevation() * settings.unit_magnitude();
double e = *p->product()->get("Elevation");
storey_elevation = e * settings.unit_magnitude();
} catch (...) {
continue;
}
storey = p->product();
break;
}
}
*/
// With a global section height, building storeys are not a requirement.
if (!storey && !section_height) return;
if (!storey && !section_height) {
Logger::Warning("No global section height and unable to determine building storey for:", o->product());
return;
}
path_object& p = start_path(storey, nameElement(o));
@@ -175,6 +175,8 @@ ptree& format_entity_instance(IfcUtil::IfcBaseEntity* instance, ptree& child, pt
value = format_attribute(argument, argument_type, qualified_name);
} catch (const std::exception& e) {
Logger::Error(e);
} catch (const Standard_ConstructionError& e) {
Logger::Error(e.GetMessageString(), instance);
}
if (value) {
@@ -255,7 +257,7 @@ ptree& descend(IfcSchema::IfcObjectDefinition* product, ptree& tree) {
}
}
#ifndef USE_IFC4
#ifdef SCHEMA_IfcRelDecomposes_HAS_RelatedObjects
IfcSchema::IfcObjectDefinition::list::ptr structures = get_related
<IfcSchema::IfcObjectDefinition, IfcSchema::IfcRelDecomposes, IfcSchema::IfcObjectDefinition>
(product, &IfcSchema::IfcObjectDefinition::IsDecomposedBy, &IfcSchema::IfcRelDecomposes::RelatedObjects);