Skip to content

Commit 94c3261

Browse files
committed
Geomserver positions in 64bit
1 parent 68151b9 commit 94c3261

1 file changed

Lines changed: 28 additions & 13 deletions

File tree

src/ifcgeomserver/IfcGeomServer.cpp

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ void swrite(std::ostream& s, std::string t) {
108108
while (len++ % 4) s.put(0);
109109
}
110110

111+
template <typename T, typename U>
112+
void swrite_array(std::ostream& s, const std::vector<U>& us) {
113+
if (std::is_same<T, U>::value) {
114+
swrite(s, std::string((char*)us.data(), us.size() * sizeof(U)));
115+
} else {
116+
std::vector<T> ts;
117+
ts.reserve(us.size());
118+
for (auto& u : us) {
119+
ts.push_back((T)u);
120+
}
121+
swrite_array<T, T>(s, ts);
122+
}
123+
}
124+
111125
class Command {
112126
protected:
113127
virtual void read_content(std::istream& s) = 0;
@@ -258,7 +272,7 @@ class EntityExtension {
258272

259273
class Entity : public Command {
260274
private:
261-
const IfcGeom::TriangulationElement<float, double>* geom;
275+
const IfcGeom::TriangulationElement<double, double>* geom;
262276
bool append_line_data;
263277
EntityExtension* eext_;
264278
protected:
@@ -283,16 +297,17 @@ class Entity : public Command {
283297
const int integer_representation_id = atoi(representation_id.c_str());
284298
swrite<int32_t>(s, (int32_t)integer_representation_id);
285299

286-
swrite(s, std::string((char*)geom->geometry().verts().data(), geom->geometry().verts().size() * sizeof(float)));
287-
swrite(s, std::string((char*)geom->geometry().normals().data(), geom->geometry().normals().size() * sizeof(float)));
300+
swrite_array<double>(s, geom->geometry().verts());
301+
swrite_array<float>(s, geom->geometry().normals());
302+
288303
{
289304
std::vector<int32_t> indices;
290305
const std::vector<int>& faces = geom->geometry().faces();
291306
indices.reserve(faces.size());
292307
for (std::vector<int>::const_iterator it = faces.begin(); it != faces.end(); ++it) {
293308
indices.push_back(*it);
294309
}
295-
swrite(s, std::string((char*) indices.data(), indices.size() * sizeof(int32_t)));
310+
swrite_array<int32_t>(s, indices);
296311

297312
if (append_line_data) {
298313
std::vector<int32_t> lines;
@@ -311,7 +326,7 @@ class Entity : public Command {
311326
lines.push_back(i2);
312327
}
313328

314-
swrite(s, std::string((char*) lines.data(), lines.size() * sizeof(int32_t)));
329+
swrite_array<int32_t>(s, lines);
315330
}
316331
}
317332
{ std::vector<float> diffuse_color_array;
@@ -344,7 +359,7 @@ class Entity : public Command {
344359
}
345360
}
346361
public:
347-
Entity(const IfcGeom::TriangulationElement<float, double>* geom, EntityExtension* eext = 0) : Command(ENTITY), geom(geom), append_line_data(false), eext_(eext) {};
362+
Entity(const IfcGeom::TriangulationElement<double, double>* geom, EntityExtension* eext = 0) : Command(ENTITY), geom(geom), append_line_data(false), eext_(eext) {};
348363
};
349364

350365
class Next : public Command {
@@ -409,9 +424,9 @@ static const std::array<std::string, 3> XYZ = { "X", "Y", "Z" };
409424

410425
class QuantityWriter_v0 : public EntityExtension {
411426
private:
412-
const IfcGeom::BRepElement<float, double>* elem_;
427+
const IfcGeom::BRepElement<double, double>* elem_;
413428
public:
414-
QuantityWriter_v0(const IfcGeom::BRepElement<float, double>* elem) :
429+
QuantityWriter_v0(const IfcGeom::BRepElement<double, double>* elem) :
415430
elem_(elem)
416431
{
417432
put_json(TOTAL_SURFACE_AREA, 0.);
@@ -424,9 +439,9 @@ class QuantityWriter_v0 : public EntityExtension {
424439

425440
class QuantityWriter_v1 : public EntityExtension {
426441
private:
427-
const IfcGeom::BRepElement<float, double>* elem_;
442+
const IfcGeom::BRepElement<double, double>* elem_;
428443
public:
429-
QuantityWriter_v1(const IfcGeom::BRepElement<float, double>* elem) :
444+
QuantityWriter_v1(const IfcGeom::BRepElement<double, double>* elem) :
430445
elem_(elem)
431446
{
432447
double a, b, c, largest_face_area = 0.;
@@ -499,7 +514,7 @@ int main () {
499514
double deflection = 1.e-3;
500515
bool has_more = false;
501516

502-
IfcGeom::Iterator<float, double>* iterator = 0;
517+
IfcGeom::Iterator<double, double>* iterator = 0;
503518
IfcParse::IfcFile* file = 0;
504519
std::vector< std::pair<uint32_t, uint32_t> > setting_pairs;
505520

@@ -534,7 +549,7 @@ int main () {
534549
settings.set_deflection_tolerance(deflection);
535550

536551
file = new IfcParse::IfcFile(data, (int)len);
537-
iterator = new IfcGeom::Iterator<float, double>(settings, file);
552+
iterator = new IfcGeom::Iterator<double, double>(settings, file);
538553
has_more = iterator->initialize();
539554

540555
More(has_more).write(std::cout);
@@ -546,7 +561,7 @@ int main () {
546561
exit_code = 1;
547562
break;
548563
}
549-
const IfcGeom::TriangulationElement<float, double>* geom = static_cast<const IfcGeom::TriangulationElement<float, double>*>(iterator->get());
564+
const IfcGeom::TriangulationElement<double, double>* geom = static_cast<const IfcGeom::TriangulationElement<double, double>*>(iterator->get());
550565
std::unique_ptr<EntityExtension> eext;
551566
if (emit_quantities) {
552567
eext.reset(new QuantityWriter_v1(iterator->get_native()));

0 commit comments

Comments
 (0)