Skip to content

Commit 7a7aab0

Browse files
committed
IfcGeomServer matrices in double precision
1 parent d105292 commit 7a7aab0

10 files changed

Lines changed: 144 additions & 129 deletions

src/ifcgeom/IfcGeom.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ class IFC_GEOM_API MAKE_TYPE_NAME(Kernel) : public IfcGeom::Kernel {
221221

222222
static IfcSchema::IfcObjectDefinition* get_decomposing_entity(IfcSchema::IfcProduct*);
223223

224-
template <typename P>
225-
IfcGeom::BRepElement<P>* create_brep_for_representation_and_product(
224+
template <typename P, typename PP>
225+
IfcGeom::BRepElement<P, PP>* create_brep_for_representation_and_product(
226226
const IteratorSettings&, IfcSchema::IfcRepresentation*, IfcSchema::IfcProduct*);
227227

228-
template <typename P>
229-
IfcGeom::BRepElement<P>* create_brep_for_processed_representation(
230-
const IteratorSettings&, IfcSchema::IfcRepresentation*, IfcSchema::IfcProduct*, IfcGeom::BRepElement<P>*);
228+
template <typename P, typename PP>
229+
IfcGeom::BRepElement<P, PP>* create_brep_for_processed_representation(
230+
const IteratorSettings&, IfcSchema::IfcRepresentation*, IfcSchema::IfcProduct*, IfcGeom::BRepElement<P, PP>*);
231231

232232
const IfcSchema::IfcMaterial* get_single_material_association(const IfcSchema::IfcProduct*);
233233
IfcSchema::IfcRepresentation* representation_mapped_to(const IfcSchema::IfcRepresentation* representation);
@@ -304,7 +304,7 @@ class IFC_GEOM_API MAKE_TYPE_NAME(Kernel) : public IfcGeom::Kernel {
304304
const IteratorSettings& settings, IfcUtil::IfcBaseClass* representation,
305305
IfcUtil::IfcBaseClass* product)
306306
{
307-
return create_brep_for_representation_and_product<double>(settings, (IfcSchema::IfcRepresentation*) representation, (IfcSchema::IfcProduct*) product);
307+
return create_brep_for_representation_and_product<double, double>(settings, (IfcSchema::IfcRepresentation*) representation, (IfcSchema::IfcProduct*) product);
308308
}
309309

310310
virtual IfcRepresentationShapeItems convert(IfcUtil::IfcBaseClass* item) {

src/ifcgeom/IfcGeomElement.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ namespace IfcGeom {
7979
}
8080
};
8181

82-
template <typename P>
82+
template <typename P = double, typename PP = P>
8383
class Element {
8484
private:
8585
int _id;
@@ -89,17 +89,17 @@ namespace IfcGeom {
8989
std::string _guid;
9090
std::string _context;
9191
std::string _unique_id;
92-
Transformation<P> _transformation;
92+
Transformation<PP> _transformation;
9393
IfcUtil::IfcBaseEntity* product_;
94-
std::vector<const IfcGeom::Element<P>*> _parents;
94+
std::vector<const IfcGeom::Element<P, PP>*> _parents;
9595
public:
9696

97-
friend bool operator == (const Element<P> & element1, const Element<P> & element2) {
97+
friend bool operator == (const Element<P, PP> & element1, const Element<P, PP> & element2) {
9898
return element1.id() == element2.id();
9999
}
100100

101101
// Use the id to compare, or the elevation is the elements are IfcBuildingStoreys and the elevation is set
102-
friend bool operator < (const Element<P> & element1, const Element<P> & element2) {
102+
friend bool operator < (const Element<P, PP> & element1, const Element<P, PP> & element2) {
103103
if (element1.type() == "IfcBuildingStorey" && element2.type() == "IfcBuildingStorey") {
104104
size_t attr_index = element1.product()->declaration().attribute_index("Elevation");
105105
Argument* elev_attr1 = element1.product()->data().getArgument(attr_index);
@@ -123,10 +123,10 @@ namespace IfcGeom {
123123
const std::string& guid() const { return _guid; }
124124
const std::string& context() const { return _context; }
125125
const std::string& unique_id() const { return _unique_id; }
126-
const Transformation<P>& transformation() const { return _transformation; }
126+
const Transformation<PP>& transformation() const { return _transformation; }
127127
IfcUtil::IfcBaseEntity* product() const { return product_; }
128-
const std::vector<const IfcGeom::Element<P>*> parents() const { return _parents; }
129-
void SetParents(std::vector<const IfcGeom::Element<P>*> newparents) { _parents = newparents; }
128+
const std::vector<const IfcGeom::Element<P, PP>*> parents() const { return _parents; }
129+
void SetParents(std::vector<const IfcGeom::Element<P, PP>*> newparents) { _parents = newparents; }
130130

131131
Element(const ElementSettings& settings, int id, int parent_id, const std::string& name, const std::string& type,
132132
const std::string& guid, const std::string& context, const gp_Trsf& trsf, IfcUtil::IfcBaseEntity* product)
@@ -158,8 +158,8 @@ namespace IfcGeom {
158158
virtual ~Element() {}
159159
};
160160

161-
template <typename P>
162-
class BRepElement : public Element<P> {
161+
template <typename P = double, typename PP = P>
162+
class BRepElement : public Element<P, PP> {
163163
private:
164164
boost::shared_ptr<Representation::BRep> _geometry;
165165
public:
@@ -168,42 +168,42 @@ namespace IfcGeom {
168168
BRepElement(int id, int parent_id, const std::string& name, const std::string& type, const std::string& guid,
169169
const std::string& context, const gp_Trsf& trsf, const boost::shared_ptr<Representation::BRep>& geometry,
170170
IfcUtil::IfcBaseEntity* product)
171-
: Element<P>(geometry->settings() ,id, parent_id, name, type, guid, context, trsf, product)
171+
: Element<P, PP>(geometry->settings() ,id, parent_id, name, type, guid, context, trsf, product)
172172
, _geometry(geometry)
173173
{}
174174
private:
175175
BRepElement(const BRepElement& other);
176176
BRepElement& operator=(const BRepElement& other);
177177
};
178178

179-
template <typename P>
180-
class TriangulationElement : public Element<P> {
179+
template <typename P = double, typename PP = P>
180+
class TriangulationElement : public Element<P, PP> {
181181
private:
182182
boost::shared_ptr< Representation::Triangulation<P> > _geometry;
183183
public:
184184
const Representation::Triangulation<P>& geometry() const { return *_geometry; }
185185
const boost::shared_ptr< Representation::Triangulation<P> >& geometry_pointer() const { return _geometry; }
186-
TriangulationElement(const BRepElement<P>& shape_model)
187-
: Element<P>(shape_model)
186+
TriangulationElement(const BRepElement<P, PP>& shape_model)
187+
: Element<P, PP>(shape_model)
188188
, _geometry(boost::shared_ptr<Representation::Triangulation<P> >(new Representation::Triangulation<P>(shape_model.geometry())))
189189
{}
190-
TriangulationElement(const Element<P>& element, const boost::shared_ptr<Representation::Triangulation<P> >& geometry)
191-
: Element<P>(element)
190+
TriangulationElement(const Element<P, PP>& element, const boost::shared_ptr<Representation::Triangulation<P> >& geometry)
191+
: Element<P, PP>(element)
192192
, _geometry(geometry)
193193
{}
194194
private:
195195
TriangulationElement(const TriangulationElement& other);
196196
TriangulationElement& operator=(const TriangulationElement& other);
197197
};
198198

199-
template <typename P>
200-
class SerializedElement : public Element<P> {
199+
template <typename P = double, typename PP = P>
200+
class SerializedElement : public Element<P, PP> {
201201
private:
202202
Representation::Serialization* _geometry;
203203
public:
204204
const Representation::Serialization& geometry() const { return *_geometry; }
205-
SerializedElement(const BRepElement<P>& shape_model)
206-
: Element<P>(shape_model)
205+
SerializedElement(const BRepElement<P, PP>& shape_model)
206+
: Element<P, PP>(shape_model)
207207
, _geometry(new Representation::Serialization(shape_model.geometry()))
208208
{}
209209
virtual ~SerializedElement() {

src/ifcgeom/IfcGeomFunctions.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,8 +1242,8 @@ const IfcSchema::IfcMaterial* IfcGeom::Kernel::get_single_material_association(c
12421242
return single_material;
12431243
}
12441244

1245-
template <typename P>
1246-
IfcGeom::BRepElement<P>* IfcGeom::Kernel::create_brep_for_representation_and_product(
1245+
template <typename P, typename PP>
1246+
IfcGeom::BRepElement<P, PP>* IfcGeom::Kernel::create_brep_for_representation_and_product(
12471247
const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product)
12481248
{
12491249
std::stringstream representation_id_builder;
@@ -1392,7 +1392,7 @@ IfcGeom::BRepElement<P>* IfcGeom::Kernel::create_brep_for_representation_and_pro
13921392
context_string = representation->ContextOfItems()->ContextType();
13931393
}
13941394

1395-
return new BRepElement<P>(
1395+
return new BRepElement<P, PP>(
13961396
product->data().id(),
13971397
parent_id,
13981398
name,
@@ -1470,10 +1470,10 @@ IfcSchema::IfcProduct::list::ptr IfcGeom::Kernel::products_represented_by(const
14701470
return products;
14711471
}
14721472

1473-
template <typename P>
1474-
IfcGeom::BRepElement<P>* IfcGeom::Kernel::create_brep_for_processed_representation(
1473+
template <typename P, typename PP>
1474+
IfcGeom::BRepElement<P, PP>* IfcGeom::Kernel::create_brep_for_processed_representation(
14751475
const IteratorSettings& /*settings*/, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product,
1476-
IfcGeom::BRepElement<P>* brep)
1476+
IfcGeom::BRepElement<P, PP>* brep)
14771477
{
14781478
int parent_id = -1;
14791479
try {
@@ -1506,7 +1506,7 @@ IfcGeom::BRepElement<P>* IfcGeom::Kernel::create_brep_for_processed_representati
15061506

15071507
const std::string product_type = product->declaration().name();
15081508

1509-
return new BRepElement<P>(
1509+
return new BRepElement<P, PP>(
15101510
product->data().id(),
15111511
parent_id,
15121512
name,
@@ -1574,15 +1574,19 @@ IfcSchema::IfcObjectDefinition* IfcGeom::Kernel::get_decomposing_entity(IfcSchem
15741574
return parent;
15751575
}
15761576

1577-
template IFC_GEOM_API IfcGeom::BRepElement<float>* IfcGeom::Kernel::create_brep_for_representation_and_product<float>(
1577+
template IFC_GEOM_API IfcGeom::BRepElement<float, float>* IfcGeom::Kernel::create_brep_for_representation_and_product<float, float>(
15781578
const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product);
1579-
template IFC_GEOM_API IfcGeom::BRepElement<double>* IfcGeom::Kernel::create_brep_for_representation_and_product<double>(
1579+
template IFC_GEOM_API IfcGeom::BRepElement<float, double>* IfcGeom::Kernel::create_brep_for_representation_and_product<float, double>(
15801580
const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product);
1581-
1582-
template IFC_GEOM_API IfcGeom::BRepElement<float>* IfcGeom::Kernel::create_brep_for_processed_representation<float>(
1583-
const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product, IfcGeom::BRepElement<float>* brep);
1584-
template IFC_GEOM_API IfcGeom::BRepElement<double>* IfcGeom::Kernel::create_brep_for_processed_representation<double>(
1585-
const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product, IfcGeom::BRepElement<double>* brep);
1581+
template IFC_GEOM_API IfcGeom::BRepElement<double, double>* IfcGeom::Kernel::create_brep_for_representation_and_product<double, double>(
1582+
const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product);
1583+
1584+
template IFC_GEOM_API IfcGeom::BRepElement<float, float>* IfcGeom::Kernel::create_brep_for_processed_representation<float, float>(
1585+
const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product, IfcGeom::BRepElement<float, float>* brep);
1586+
template IFC_GEOM_API IfcGeom::BRepElement<float, double>* IfcGeom::Kernel::create_brep_for_processed_representation<float, double>(
1587+
const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product, IfcGeom::BRepElement<float, double>* brep);
1588+
template IFC_GEOM_API IfcGeom::BRepElement<double, double>* IfcGeom::Kernel::create_brep_for_processed_representation<double, double>(
1589+
const IteratorSettings& settings, IfcSchema::IfcRepresentation* representation, IfcSchema::IfcProduct* product, IfcGeom::BRepElement<double, double>* brep);
15861590

15871591
std::pair<std::string, double> IfcGeom::Kernel::initializeUnits(IfcSchema::IfcUnitAssignment* unit_assignment) {
15881592
// Set default units, set length to meters, angles to undefined

src/ifcgeom/IfcGeomIteratorImplementation.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,31 @@
22
#include "../ifcgeom_schema_agnostic/IteratorImplementation.h"
33

44
namespace IfcGeom {
5-
template class MAKE_TYPE_NAME(IteratorImplementation_)<float>;
6-
template class MAKE_TYPE_NAME(IteratorImplementation_)<double>;
5+
template class MAKE_TYPE_NAME(IteratorImplementation_)<float, float>;
6+
template class MAKE_TYPE_NAME(IteratorImplementation_)<float, double>;
7+
template class MAKE_TYPE_NAME(IteratorImplementation_)<double, double>;
78
}
89

910
#define MAKE_INIT_FN__(a, b) init_ ## a ## b
1011
#define MAKE_INIT_FN_(a, b) MAKE_INIT_FN__(a, b)
1112
#define MAKE_INIT_FN(t) MAKE_INIT_FN_(t, IfcSchema)
1213

1314
namespace {
14-
template <typename P>
15+
template <typename P, typename PP>
1516
struct factory_t {
16-
IfcGeom::IteratorImplementation<P>* operator()(const IfcGeom::IteratorSettings& settings, IfcParse::IfcFile* file) const {
17-
return new IfcGeom::MAKE_TYPE_NAME(IteratorImplementation_)<P>(settings, file);
17+
IfcGeom::IteratorImplementation<P, PP>* operator()(const IfcGeom::IteratorSettings& settings, IfcParse::IfcFile* file) const {
18+
return new IfcGeom::MAKE_TYPE_NAME(IteratorImplementation_)<P, PP>(settings, file);
1819
}
1920
};
2021
}
2122

22-
template <typename P>
23-
void MAKE_INIT_FN(IteratorImplementation_)(IteratorFactoryImplementation<P>* mapping) {
23+
template <typename P, typename PP>
24+
void MAKE_INIT_FN(IteratorImplementation_)(IteratorFactoryImplementation<P, PP>* mapping) {
2425
static const std::string schema_name = STRINGIFY(IfcSchema);
25-
factory_t<P> factory;
26+
factory_t<P, PP> factory;
2627
mapping->bind(schema_name, factory);
2728
}
2829

29-
template void MAKE_INIT_FN(IteratorImplementation_)<float>(IteratorFactoryImplementation<float>*);
30-
template void MAKE_INIT_FN(IteratorImplementation_)<double>(IteratorFactoryImplementation<double>*);
30+
template void MAKE_INIT_FN(IteratorImplementation_)<float, float>(IteratorFactoryImplementation<float, float>*);
31+
template void MAKE_INIT_FN(IteratorImplementation_)<float, double>(IteratorFactoryImplementation<float, double>*);
32+
template void MAKE_INIT_FN(IteratorImplementation_)<double, double>(IteratorFactoryImplementation<double, double>*);

src/ifcgeom/IfcGeomIteratorImplementation.h

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@
9494

9595
namespace IfcGeom {
9696

97-
template <typename P>
98-
class MAKE_TYPE_NAME(IteratorImplementation_) : public IteratorImplementation<P> {
97+
template <typename P, typename PP>
98+
class MAKE_TYPE_NAME(IteratorImplementation_) : public IteratorImplementation<P, PP> {
9999
private:
100100

101101
MAKE_TYPE_NAME(IteratorImplementation_)(const MAKE_TYPE_NAME(IteratorImplementation_)&); // N/I
@@ -111,9 +111,9 @@ namespace IfcGeom {
111111
IfcSchema::IfcRepresentation::list::it representation_iterator;
112112

113113
// The object is fetched beforehand to be sure that get() returns a valid element
114-
TriangulationElement<P>* current_triangulation;
115-
BRepElement<P>* current_shape_model;
116-
SerializedElement<P>* current_serialization;
114+
TriangulationElement<P, PP>* current_triangulation;
115+
BRepElement<P, PP>* current_shape_model;
116+
SerializedElement<P, PP>* current_serialization;
117117

118118
// A container and iterator for IfcBuildingElements for the current IfcRepresentation referenced by *representation_iterator
119119
IfcSchema::IfcProduct::list::ptr ifcproducts;
@@ -154,6 +154,7 @@ namespace IfcGeom {
154154
/// @todo public/private sections all over the place: move all public to the beginning of the class
155155
public:
156156
typedef P Precision;
157+
typedef PP PlacementPrecision;
157158

158159
MAKE_TYPE_NAME(IteratorImplementation_)(const IteratorSettings& settings, IfcParse::IfcFile* file, std::vector<IfcGeom::filter_t>& filters)
159160
: settings(settings)
@@ -399,7 +400,7 @@ namespace IfcGeom {
399400
return associated_single_materials.size() == 1;
400401
}
401402

402-
BRepElement<P>* create_shape_model_for_next_entity() {
403+
BRepElement<P, PP>* create_shape_model_for_next_entity() {
403404
for (;;) {
404405
IfcSchema::IfcRepresentation* representation;
405406

@@ -468,9 +469,9 @@ namespace IfcGeom {
468469
IfcSchema::IfcProduct* product = *ifcproduct_iterator;
469470
Logger::SetProduct(product);
470471

471-
BRepElement<P>* element;
472+
BRepElement<P, PP>* element;
472473
if (ifcproduct_iterator == ifcproducts->begin() || !geometry_reuse_ok_for_current_representation_) {
473-
element = kernel.create_brep_for_representation_and_product<P>(settings, representation, product);
474+
element = kernel.create_brep_for_representation_and_product<P, PP>(settings, representation, product);
474475
} else {
475476
element = kernel.create_brep_for_processed_representation(settings, representation, product, current_shape_model);
476477
}
@@ -524,10 +525,10 @@ namespace IfcGeom {
524525
}
525526

526527
/// Gets the representation of the current geometrical entity.
527-
Element<P>* get()
528+
Element<P, PP>* get()
528529
{
529530
// TODO: Test settings and throw
530-
Element<P>* ret = 0;
531+
Element<P, PP>* ret = 0;
531532
if (current_triangulation) { ret = current_triangulation; }
532533
else if (current_serialization) { ret = current_serialization; }
533534
else if (current_shape_model) { ret = current_shape_model; }
@@ -537,12 +538,12 @@ namespace IfcGeom {
537538
{
538539
// We are going to build a vector with the element parents.
539540
// First, create the parent vector
540-
std::vector<const IfcGeom::Element<P>*> parents;
541+
std::vector<const IfcGeom::Element<P, PP>*> parents;
541542

542543
// if the element has a parent
543544
if (ret->parent_id() != -1)
544545
{
545-
const IfcGeom::Element<P>* parent_object = NULL;
546+
const IfcGeom::Element<P, PP>* parent_object = NULL;
546547
bool hasParent = true;
547548

548549
// get the parent
@@ -582,13 +583,13 @@ namespace IfcGeom {
582583
}
583584

584585
/// Gets the native (Open Cascade) representation of the current geometrical entity.
585-
BRepElement<P>* get_native()
586+
BRepElement<P, PP>* get_native()
586587
{
587588
// TODO: Test settings and throw
588589
return current_shape_model;
589590
}
590591

591-
const Element<P>* get_object(int id) {
592+
const Element<P, PP>* get_object(int id) {
592593
gp_Trsf trsf;
593594
int parent_id = -1;
594595
std::string instance_type, product_name, product_guid;
@@ -640,14 +641,14 @@ namespace IfcGeom {
640641

641642
ElementSettings element_settings(settings, unit_magnitude, instance_type);
642643

643-
Element<P>* ifc_object = new Element<P>(element_settings, id, parent_id, product_name, instance_type, product_guid, "", trsf, ifc_product);
644+
Element<P, PP>* ifc_object = new Element<P, PP>(element_settings, id, parent_id, product_name, instance_type, product_guid, "", trsf, ifc_product);
644645
return ifc_object;
645646
}
646647

647648
IfcUtil::IfcBaseClass* create() {
648-
IfcGeom::BRepElement<P>* next_shape_model = 0;
649-
IfcGeom::SerializedElement<P>* next_serialization = 0;
650-
IfcGeom::TriangulationElement<P>* next_triangulation = 0;
649+
IfcGeom::BRepElement<P, PP>* next_shape_model = 0;
650+
IfcGeom::SerializedElement<P, PP>* next_serialization = 0;
651+
IfcGeom::TriangulationElement<P, PP>* next_triangulation = 0;
651652

652653
try {
653654
next_shape_model = create_shape_model_for_next_entity();
@@ -666,16 +667,16 @@ namespace IfcGeom {
666667
if (next_shape_model) {
667668
if (settings.get(IteratorSettings::USE_BREP_DATA)) {
668669
try {
669-
next_serialization = new SerializedElement<P>(*next_shape_model);
670+
next_serialization = new SerializedElement<P, PP>(*next_shape_model);
670671
} catch (...) {
671672
Logger::Message(Logger::LOG_ERROR, "Getting a serialized element from model failed.");
672673
}
673674
} else if (!settings.get(IteratorSettings::DISABLE_TRIANGULATION)) {
674675
try {
675676
if (ifcproduct_iterator == ifcproducts->begin() || !geometry_reuse_ok_for_current_representation_) {
676-
next_triangulation = new TriangulationElement<P>(*next_shape_model);
677+
next_triangulation = new TriangulationElement<P, PP>(*next_shape_model);
677678
} else {
678-
next_triangulation = new TriangulationElement<P>(*next_shape_model, current_triangulation->geometry_pointer());
679+
next_triangulation = new TriangulationElement<P, PP>(*next_shape_model, current_triangulation->geometry_pointer());
679680
}
680681
} catch (...) {
681682
Logger::Message(Logger::LOG_ERROR, "Getting a triangulation element from model failed.");

0 commit comments

Comments
 (0)