feature (WIP) : retrieve full hierarchy

Bug : the element are not at the right location
This commit is contained in:
Balleux Benjamin
2017-05-15 17:45:05 +02:00
parent 4f6e8a7d56
commit be3dbce9f4
5 changed files with 345 additions and 84 deletions
+36 -31
View File
@@ -45,10 +45,16 @@
#include "../ifcconvert/GeometrySerializer.h"
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
class ColladaSerializer : public GeometrySerializer
{
// TODO The vast amount of implement details of ColladaSerializer could be hidden to the cpp file.
private:
std::stack<int> parentStackId;
class ColladaExporter
{
private:
@@ -79,7 +85,8 @@ private:
const std::string scene_id;
bool scene_opened;
COLLADASW::Node *current_node;
std::stack<COLLADASW::Node*> parentNodes;
std::stack<boost::numeric::ublas::matrix<double>> matrixStack;
public:
ColladaScene(const std::string& scene_id, COLLADASW::StreamWriter& stream, ColladaSerializer *_serializer)
: COLLADASW::LibraryVisualScenes(&stream)
@@ -91,6 +98,7 @@ private:
const std::vector<std::string>& material_ids, const std::vector<real_t>& matrix);
void addParent(const IfcGeom::Element<real_t>& parent);
void closeParent();
COLLADASW::Node* GetDirectParent();
void write();
ColladaSerializer *serializer;
};
@@ -125,39 +133,37 @@ private:
ColladaEffects effects;
};
class DeferredObject {
friend bool operator < (const DeferredObject & def_obj1, const DeferredObject & def_obj2)
{
// Retrieve the parents of the objects to compare
const IfcGeom::Element<real_t>* parent1 = def_obj1.parent;
const IfcGeom::Element<real_t>* parent2 = def_obj2.parent;
// If a parent is null
if (parent1 == NULL || parent2 == NULL)
/*
std::cout << "*************** COMPARE ***************\n";
std::cout << "range 1 : " << def_obj1.unique_id << "\n";
for (unsigned i = 0; i < def_obj1.parents.size(); i++)
{
bool res = (parent1 == NULL) ? true : false;
return res;
std::cout << "=== " << def_obj1.parents.at(i)->name() << " | " << def_obj1.parents.at(i)->id() << " ===\n";
}
// If both parent are not null
std::cout << "range 2 : " << def_obj2.unique_id << "\n";
for (unsigned i = 0; i < def_obj2.parents.size(); i++)
{
std::cout << "=== " << def_obj2.parents.at(i)->name() << " | " << def_obj2.parents.at(i)->id() << " ===\n";
}
*/
unsigned size = (def_obj1.parents.size() < def_obj2.parents.size() ? def_obj1.parents.size() : def_obj2.parents.size());
int cpt = 0;
// Skip the shared parents
while (cpt < size && *(def_obj1.parents.at(cpt)) == *(def_obj2.parents.at(cpt))) { cpt++; }
// If a parent list container the other one
if (cpt >= size) { return (def_obj1.parents.size() < def_obj2.parents.size() ? true : false); }
else
{
// Retrieve the IfcBuildingStorey
IfcSchema::IfcBuildingStorey* storey1 = (IfcSchema::IfcBuildingStorey*)parent1->product();
IfcSchema::IfcBuildingStorey* storey2 = (IfcSchema::IfcBuildingStorey*)parent2->product();
bool res = true;
// Check if the storeys both have an elevation value
if (storey1->hasElevation() && storey2->hasElevation())
{
// Use the elevation in order to sort
res = storey1->Elevation() > storey2->Elevation() ? true : false;
}
// If the evelations are not set, use the names to sort
else { res = parent1->name().compare(parent2->name()) > 0 ? true : false; }
return res;
return *(def_obj1.parents.at(cpt)) < *(def_obj2.parents.at(cpt));
}
}
public:
std::string unique_id, representation_id, type;
std::vector<real_t> matrix;
@@ -169,11 +175,11 @@ private:
std::vector<IfcGeom::Material> materials;
std::vector<std::string> material_references;
std::vector<real_t> uvs;
const IfcGeom::Element<real_t>* parent;
std::vector<const IfcGeom::Element<real_t>*> parents;
DeferredObject(const std::string& unique_id, const std::string& representation_id, const std::string& type, const std::vector<real_t>& matrix,
const std::vector<real_t>& vertices, const std::vector<real_t>& normals, const std::vector<int>& faces,
const std::vector<int>& edges, const std::vector<int>& material_ids, const std::vector<IfcGeom::Material>& materials,
const std::vector<std::string>& material_references, const std::vector<real_t>& uvs, const IfcGeom::Element<real_t>& _parent)
const std::vector<std::string>& material_references, const std::vector<real_t>& uvs, const std::vector<const IfcGeom::Element<real_t>*>& parent)
: unique_id(unique_id)
, representation_id(representation_id)
, type(type)
@@ -186,7 +192,7 @@ private:
, materials(materials)
, material_references(material_references)
, uvs(uvs)
, parent(&_parent)
, parents(parent)
{
}
@@ -207,9 +213,8 @@ private:
, materials(materials)
, material_references(material_references)
, uvs(uvs)
, parent(NULL)
{
parents.clear();
}
};
COLLADABU::NativeString filename;