diff --git a/src/ifcgeomserver/IfcGeomServer.cpp b/src/ifcgeomserver/IfcGeomServer.cpp index dfa041f05b..3c737dacba 100644 --- a/src/ifcgeomserver/IfcGeomServer.cpp +++ b/src/ifcgeomserver/IfcGeomServer.cpp @@ -108,6 +108,20 @@ void swrite(std::ostream& s, std::string t) { while (len++ % 4) s.put(0); } +template +void swrite_array(std::ostream& s, const std::vector& us) { + if (std::is_same::value) { + swrite(s, std::string((char*)us.data(), us.size() * sizeof(U))); + } else { + std::vector ts; + ts.reserve(us.size()); + for (auto& u : us) { + ts.push_back((T)u); + } + swrite_array(s, ts); + } +} + class Command { protected: virtual void read_content(std::istream& s) = 0; @@ -258,7 +272,7 @@ public: class Entity : public Command { private: - const IfcGeom::TriangulationElement* geom; + const IfcGeom::TriangulationElement* geom; bool append_line_data; EntityExtension* eext_; protected: @@ -283,8 +297,9 @@ protected: const int integer_representation_id = atoi(representation_id.c_str()); swrite(s, (int32_t)integer_representation_id); - swrite(s, std::string((char*)geom->geometry().verts().data(), geom->geometry().verts().size() * sizeof(float))); - swrite(s, std::string((char*)geom->geometry().normals().data(), geom->geometry().normals().size() * sizeof(float))); + swrite_array(s, geom->geometry().verts()); + swrite_array(s, geom->geometry().normals()); + { std::vector indices; const std::vector& faces = geom->geometry().faces(); @@ -292,7 +307,7 @@ protected: for (std::vector::const_iterator it = faces.begin(); it != faces.end(); ++it) { indices.push_back(*it); } - swrite(s, std::string((char*) indices.data(), indices.size() * sizeof(int32_t))); + swrite_array(s, indices); if (append_line_data) { std::vector lines; @@ -311,7 +326,7 @@ protected: lines.push_back(i2); } - swrite(s, std::string((char*) lines.data(), lines.size() * sizeof(int32_t))); + swrite_array(s, lines); } } { std::vector diffuse_color_array; @@ -344,7 +359,7 @@ protected: } } public: - Entity(const IfcGeom::TriangulationElement* geom, EntityExtension* eext = 0) : Command(ENTITY), geom(geom), append_line_data(false), eext_(eext) {}; + Entity(const IfcGeom::TriangulationElement* geom, EntityExtension* eext = 0) : Command(ENTITY), geom(geom), append_line_data(false), eext_(eext) {}; }; class Next : public Command { @@ -409,9 +424,9 @@ static const std::array XYZ = { "X", "Y", "Z" }; class QuantityWriter_v0 : public EntityExtension { private: - const IfcGeom::BRepElement* elem_; + const IfcGeom::BRepElement* elem_; public: - QuantityWriter_v0(const IfcGeom::BRepElement* elem) : + QuantityWriter_v0(const IfcGeom::BRepElement* elem) : elem_(elem) { put_json(TOTAL_SURFACE_AREA, 0.); @@ -424,9 +439,9 @@ public: class QuantityWriter_v1 : public EntityExtension { private: - const IfcGeom::BRepElement* elem_; + const IfcGeom::BRepElement* elem_; public: - QuantityWriter_v1(const IfcGeom::BRepElement* elem) : + QuantityWriter_v1(const IfcGeom::BRepElement* elem) : elem_(elem) { double a, b, c, largest_face_area = 0.; @@ -499,7 +514,7 @@ int main () { double deflection = 1.e-3; bool has_more = false; - IfcGeom::Iterator* iterator = 0; + IfcGeom::Iterator* iterator = 0; IfcParse::IfcFile* file = 0; std::vector< std::pair > setting_pairs; @@ -534,7 +549,7 @@ int main () { settings.set_deflection_tolerance(deflection); file = new IfcParse::IfcFile(data, (int)len); - iterator = new IfcGeom::Iterator(settings, file); + iterator = new IfcGeom::Iterator(settings, file); has_more = iterator->initialize(); More(has_more).write(std::cout); @@ -546,7 +561,7 @@ int main () { exit_code = 1; break; } - const IfcGeom::TriangulationElement* geom = static_cast*>(iterator->get()); + const IfcGeom::TriangulationElement* geom = static_cast*>(iterator->get()); std::unique_ptr eext; if (emit_quantities) { eext.reset(new QuantityWriter_v1(iterator->get_native()));