Fix compilation of serializers and convert

This commit is contained in:
Thomas Krijnen
2019-08-17 09:47:07 +02:00
parent ddeaf5a375
commit 585b89be87
14 changed files with 119 additions and 97 deletions
+31 -31
View File
@@ -633,24 +633,24 @@ int main(int argc, char** argv) {
SerializerSettings settings; SerializerSettings settings;
/// @todo Make APPLY_DEFAULT_MATERIALS configurable? Quickly tested setting this to false and using obj exporter caused the program to crash and burn. /// @todo Make APPLY_DEFAULT_MATERIALS configurable? Quickly tested setting this to false and using obj exporter caused the program to crash and burn.
settings.set(IfcGeom::IteratorSettings::APPLY_DEFAULT_MATERIALS, true); settings.set(ifcopenshell::geometry::settings::APPLY_DEFAULT_MATERIALS, true);
settings.set(IfcGeom::IteratorSettings::USE_WORLD_COORDS, use_world_coords || output_extension == SVG || output_extension == OBJ); settings.set(ifcopenshell::geometry::settings::USE_WORLD_COORDS, use_world_coords || output_extension == SVG || output_extension == OBJ);
settings.set(IfcGeom::IteratorSettings::WELD_VERTICES, weld_vertices); settings.set(ifcopenshell::geometry::settings::WELD_VERTICES, weld_vertices);
settings.set(IfcGeom::IteratorSettings::SEW_SHELLS, orient_shells); settings.set(ifcopenshell::geometry::settings::SEW_SHELLS, orient_shells);
settings.set(IfcGeom::IteratorSettings::CONVERT_BACK_UNITS, convert_back_units); settings.set(ifcopenshell::geometry::settings::CONVERT_BACK_UNITS, convert_back_units);
#if OCC_VERSION_HEX < 0x60900 #if OCC_VERSION_HEX < 0x60900
settings.set(IfcGeom::IteratorSettings::FASTER_BOOLEANS, merge_boolean_operands); settings.set(ifcopenshell::geometry::settings::FASTER_BOOLEANS, merge_boolean_operands);
#endif #endif
settings.set(IfcGeom::IteratorSettings::DISABLE_OPENING_SUBTRACTIONS, disable_opening_subtractions); settings.set(ifcopenshell::geometry::settings::DISABLE_OPENING_SUBTRACTIONS, disable_opening_subtractions);
settings.set(IfcGeom::IteratorSettings::INCLUDE_CURVES, include_plan); settings.set(ifcopenshell::geometry::settings::INCLUDE_CURVES, include_plan);
settings.set(IfcGeom::IteratorSettings::EXCLUDE_SOLIDS_AND_SURFACES, !include_model); settings.set(ifcopenshell::geometry::settings::EXCLUDE_SOLIDS_AND_SURFACES, !include_model);
settings.set(IfcGeom::IteratorSettings::APPLY_LAYERSETS, enable_layerset_slicing); settings.set(ifcopenshell::geometry::settings::APPLY_LAYERSETS, enable_layerset_slicing);
settings.set(IfcGeom::IteratorSettings::NO_NORMALS, no_normals); settings.set(ifcopenshell::geometry::settings::NO_NORMALS, no_normals);
settings.set(IfcGeom::IteratorSettings::GENERATE_UVS, generate_uvs); settings.set(ifcopenshell::geometry::settings::GENERATE_UVS, generate_uvs);
settings.set(IfcGeom::IteratorSettings::SEARCH_FLOOR, use_element_hierarchy || output_extension == SVG); settings.set(ifcopenshell::geometry::settings::SEARCH_FLOOR, use_element_hierarchy || output_extension == SVG);
settings.set(IfcGeom::IteratorSettings::SITE_LOCAL_PLACEMENT, site_local_placement); settings.set(ifcopenshell::geometry::settings::SITE_LOCAL_PLACEMENT, site_local_placement);
settings.set(IfcGeom::IteratorSettings::BUILDING_LOCAL_PLACEMENT, building_local_placement); settings.set(ifcopenshell::geometry::settings::BUILDING_LOCAL_PLACEMENT, building_local_placement);
settings.set(IfcGeom::IteratorSettings::VALIDATE_QUANTITIES, validate); settings.set(ifcopenshell::geometry::settings::VALIDATE_QUANTITIES, validate);
settings.set(SerializerSettings::USE_ELEMENT_NAMES, use_element_names); settings.set(SerializerSettings::USE_ELEMENT_NAMES, use_element_names);
settings.set(SerializerSettings::USE_ELEMENT_GUIDS, use_element_guids); settings.set(SerializerSettings::USE_ELEMENT_GUIDS, use_element_guids);
@@ -682,7 +682,7 @@ int main(int argc, char** argv) {
#endif #endif
serializer = boost::make_shared<IgesSerializer>(IfcUtil::path::to_utf8(output_temp_filename), settings); serializer = boost::make_shared<IgesSerializer>(IfcUtil::path::to_utf8(output_temp_filename), settings);
} else if (output_extension == SVG) { } else if (output_extension == SVG) {
settings.set(IfcGeom::IteratorSettings::DISABLE_TRIANGULATION, true); settings.set(ifcopenshell::geometry::settings::DISABLE_TRIANGULATION, true);
serializer = boost::make_shared<SvgSerializer>(IfcUtil::path::to_utf8(output_temp_filename), settings); serializer = boost::make_shared<SvgSerializer>(IfcUtil::path::to_utf8(output_temp_filename), settings);
if (vmap.count("section-height") != 0) { if (vmap.count("section-height") != 0) {
Logger::Notice("Overriding section height"); Logger::Notice("Overriding section height");
@@ -719,7 +719,7 @@ int main(int argc, char** argv) {
Logger::Notice("Centering/offsetting model setting ignored when writing non-tesselated output"); Logger::Notice("Centering/offsetting model setting ignored when writing non-tesselated output");
} }
settings.set(IfcGeom::IteratorSettings::DISABLE_TRIANGULATION, true); settings.set(ifcopenshell::geometry::settings::DISABLE_TRIANGULATION, true);
} }
if (!serializer->ready()) { if (!serializer->ready()) {
@@ -749,7 +749,7 @@ int main(int argc, char** argv) {
Logger::SetOutput(quiet ? nullptr : &cout_, &log_stream); Logger::SetOutput(quiet ? nullptr : &cout_, &log_stream);
IfcGeom::Iterator<real_t> context_iterator(settings, ifc_file, filter_funcs, geometry_kernel, num_threads); ifcopenshell::geometry::Iterator context_iterator(geometry_kernel, settings, ifc_file, filter_funcs, num_threads);
if (!context_iterator.initialize()) { if (!context_iterator.initialize()) {
/// @todo It would be nice to know and print separate error prints for a case where we found no entities /// @todo It would be nice to know and print separate error prints for a case where we found no entities
/// and for a case we found no entities that satisfy our filtering criteria. /// and for a case we found no entities that satisfy our filtering criteria.
@@ -823,15 +823,15 @@ int main(int argc, char** argv) {
size_t num_created = 0; size_t num_created = 0;
do { do {
IfcGeom::Element<real_t> *geom_object = context_iterator.get(); ifcopenshell::geometry::Element* geom_object = context_iterator.get();
if (is_tesselated) if (is_tesselated)
{ {
serializer->write(static_cast<const IfcGeom::TriangulationElement<real_t>*>(geom_object)); serializer->write(static_cast<const ifcopenshell::geometry::TriangulationElement*>(geom_object));
} }
else else
{ {
serializer->write(static_cast<const IfcGeom::NativeElement<real_t>*>(geom_object)); serializer->write(static_cast<const ifcopenshell::geometry::NativeElement*>(geom_object));
} }
if (!no_progress) { if (!no_progress) {
@@ -1219,14 +1219,14 @@ void fix_quantities(IfcParse::IfcFile& f, bool no_progress, bool quiet, bool std
} }
} }
IfcGeom::IteratorSettings settings; ifcopenshell::geometry::settings settings;
settings.set(IfcGeom::IteratorSettings::USE_WORLD_COORDS, false); settings.set(ifcopenshell::geometry::settings::USE_WORLD_COORDS, false);
settings.set(IfcGeom::IteratorSettings::WELD_VERTICES, false); settings.set(ifcopenshell::geometry::settings::WELD_VERTICES, false);
settings.set(IfcGeom::IteratorSettings::SEW_SHELLS, true); settings.set(ifcopenshell::geometry::settings::SEW_SHELLS, true);
settings.set(IfcGeom::IteratorSettings::CONVERT_BACK_UNITS, true); settings.set(ifcopenshell::geometry::settings::CONVERT_BACK_UNITS, true);
settings.set(IfcGeom::IteratorSettings::DISABLE_TRIANGULATION, true); settings.set(ifcopenshell::geometry::settings::DISABLE_TRIANGULATION, true);
IfcGeom::Iterator<double> context_iterator(settings, &f); ifcopenshell::geometry::Iterator context_iterator(settings, &f);
if (!context_iterator.initialize()) { if (!context_iterator.initialize()) {
return; return;
@@ -1260,14 +1260,14 @@ void fix_quantities(IfcParse::IfcFile& f, bool no_progress, bool quiet, bool std
IfcUtil::IfcBaseClass* quantity = nullptr; IfcUtil::IfcBaseClass* quantity = nullptr;
IfcEntityList::ptr objects; IfcEntityList::ptr objects;
boost::shared_ptr<IfcGeom::Representation::BRep> previous_geometry_pointer; boost::shared_ptr<ifcopenshell::geometry::Representation::BRep> previous_geometry_pointer;
for (;; ++num_created) { for (;; ++num_created) {
bool has_more = true; bool has_more = true;
if (num_created) { if (num_created) {
has_more = context_iterator.next(); has_more = context_iterator.next();
} }
IfcGeom::NativeElement<double>* geom_object = nullptr; ifcopenshell::geometry::NativeElement* geom_object = nullptr;
if (has_more) { if (has_more) {
geom_object = context_iterator.get_native(); geom_object = context_iterator.get_native();
} }
@@ -30,6 +30,9 @@ namespace ifcopenshell { namespace geometry {
class IFC_GEOM_API Triangulation; class IFC_GEOM_API Triangulation;
} }
// @todo, this class is no longer necessary, we can directly use
// taxonomy::matrix4, which does not need to be implemented specifically
// in the respective kernels
class IFC_GEOM_API ConversionResultPlacement { class IFC_GEOM_API ConversionResultPlacement {
public: public:
virtual void Multiply(const ConversionResultPlacement*) = 0; virtual void Multiply(const ConversionResultPlacement*) = 0;
@@ -194,8 +194,8 @@ namespace ifcopenshell { namespace geometry {
int done; int done;
int total; int total;
std::string unit_name; std::string unit_name_;
double unit_magnitude; double unit_magnitude_;
gp_XYZ bounds_min_; gp_XYZ bounds_min_;
gp_XYZ bounds_max_; gp_XYZ bounds_max_;
@@ -205,6 +205,9 @@ namespace ifcopenshell { namespace geometry {
/// @todo public/private sections all over the place: move all public to the beginning of the class /// @todo public/private sections all over the place: move all public to the beginning of the class
public: public:
const std::string& unit_name() const { return unit_name_; }
const double unit_magnitude() const { return unit_magnitude_; }
bool initialize() { bool initialize() {
converter_->mapping()->get_representations(tasks_, filters_, settings_); converter_->mapping()->get_representations(tasks_, filters_, settings_);
@@ -357,10 +360,10 @@ namespace ifcopenshell { namespace geometry {
} }
} }
const std::string& getUnitName() const { return unit_name; } const std::string& getUnitName() const { return unit_name_; }
/// @note Double always as per IFC specification. /// @note Double always as per IFC specification.
double getUnitMagnitude() const { return unit_magnitude; } double getUnitMagnitude() const { return unit_magnitude_; }
std::string getLog() const { return Logger::GetLog(); } std::string getLog() const { return Logger::GetLog(); }
@@ -418,6 +421,10 @@ namespace ifcopenshell { namespace geometry {
if (task_result_index_ == all_processed_elements_.size()) { if (task_result_index_ == all_processed_elements_.size()) {
return create(); return create();
} }
if (task_result_index_ == all_processed_elements_.size()) {
return nullptr;
}
return all_processed_elements_[task_result_index_]->product();
} }
} }
@@ -563,8 +570,8 @@ namespace ifcopenshell { namespace geometry {
} }
private: private:
void _initialize() { void _initialize() {
unit_name = "METER"; unit_name_ = "METER";
unit_magnitude = 1.f; unit_magnitude_ = 1.f;
// @todo // @todo
@@ -585,7 +592,7 @@ namespace ifcopenshell { namespace geometry {
bool owns_ifc_file; bool owns_ifc_file;
public: public:
Iterator(const std::string& geometry_library, const settings& settings, IfcParse::IfcFile* file, const std::vector<ifcopenshell::geometry::filter_t>& filters, int num_threads) Iterator(const std::string& geometry_library, const settings& settings, IfcParse::IfcFile* file, const std::vector<ifcopenshell::geometry::filter_t>& filters, int num_threads = 1)
: settings_(settings) : settings_(settings)
, ifc_file(file) , ifc_file(file)
, filters_(filters) , filters_(filters)
@@ -596,6 +603,16 @@ namespace ifcopenshell { namespace geometry {
_initialize(); _initialize();
} }
Iterator(const settings& settings, IfcParse::IfcFile* file, int num_threads = 1)
: settings_(settings)
, ifc_file(file)
, owns_ifc_file(false)
, num_threads_(num_threads)
, geometry_library_("opencascade")
{
_initialize();
}
~Iterator() { ~Iterator() {
if (owns_ifc_file) { if (owns_ifc_file) {
delete ifc_file; delete ifc_file;
@@ -1 +0,0 @@
#include "IfcGeomIteratorImplementation.h"
@@ -88,9 +88,7 @@ namespace ifcopenshell {
const TopoDS_Shape& shape() const { return shape_; } const TopoDS_Shape& shape() const { return shape_; }
operator const TopoDS_Shape& () { return shape_; } operator const TopoDS_Shape& () { return shape_; }
virtual void Triangulate(const settings & settings, const ConversionResultPlacement * place, Representation::Triangulation<float>* t, int surface_style_id) const; virtual void Triangulate(const settings & settings, const ConversionResultPlacement * place, Representation::Triangulation* t, int surface_style_id) const;
virtual void Triangulate(const settings & settings, const ConversionResultPlacement * place, Representation::Triangulation<double>* t, int surface_style_id) const;
virtual void Serialize(std::string&) const { virtual void Serialize(std::string&) const {
throw std::runtime_error("Not implemented"); throw std::runtime_error("Not implemented");
+2 -2
View File
@@ -42,8 +42,8 @@ public:
: OpenCascadeBasedSerializer(out_filename, settings) : OpenCascadeBasedSerializer(out_filename, settings)
{} {}
virtual ~IgesSerializer() {} virtual ~IgesSerializer() {}
void writeShape(const IfcGeom::ConversionResultShape* shape) { void writeShape(const ifcopenshell::geometry::ConversionResultShape* shape) {
writer.AddShape(*(IfcGeom::OpenCascadeShape*)shape); writer.AddShape(*(ifcopenshell::geometry::OpenCascadeShape*)shape);
} }
void finalize() { void finalize() {
writer.Write(out_filename.c_str()); writer.Write(out_filename.c_str());
@@ -36,19 +36,19 @@ bool OpenCascadeBasedSerializer::ready() {
return succeeded; return succeeded;
} }
void OpenCascadeBasedSerializer::write(const IfcGeom::NativeElement<real_t>* o) { void OpenCascadeBasedSerializer::write(const ifcopenshell::geometry::NativeElement* o) {
IfcGeom::OpenCascadeShape* occt_shape = ((IfcGeom::OpenCascadeShape*) o->geometry().as_compound()); ifcopenshell::geometry::OpenCascadeShape* occt_shape = ((ifcopenshell::geometry::OpenCascadeShape*) o->geometry().as_compound());
TopoDS_Shape compound = occt_shape->shape(); TopoDS_Shape compound = occt_shape->shape();
delete occt_shape; delete occt_shape;
if (o->geometry().settings().get(IfcGeom::IteratorSettings::CONVERT_BACK_UNITS)) { if (o->geometry().settings().get(ifcopenshell::geometry::settings::CONVERT_BACK_UNITS)) {
gp_Trsf scale; gp_Trsf scale;
scale.SetScaleFactor(1.0 / o->geometry().settings().unit_magnitude()); scale.SetScaleFactor(1.0 / o->geometry().settings().unit_magnitude());
compound = BRepBuilderAPI_Transform(compound, scale, true).Shape(); compound = BRepBuilderAPI_Transform(compound, scale, true).Shape();
} }
IfcGeom::OpenCascadeShape s(compound); ifcopenshell::geometry::OpenCascadeShape s(compound);
writeShape(&s); writeShape(&s);
} }
+3 -3
View File
@@ -37,9 +37,9 @@ public:
virtual ~OpenCascadeBasedSerializer() {} virtual ~OpenCascadeBasedSerializer() {}
void writeHeader() {} void writeHeader() {}
bool ready(); bool ready();
virtual void writeShape(const IfcGeom::ConversionResultShape* shape) = 0; virtual void writeShape(const ifcopenshell::geometry::ConversionResultShape* shape) = 0;
void write(const IfcGeom::TriangulationElement<real_t>* /*o*/) {} void write(const ifcopenshell::geometry::TriangulationElement* /*o*/) {}
void write(const IfcGeom::NativeElement<real_t>* o); void write(const ifcopenshell::geometry::NativeElement* o);
bool isTesselated() const { return false; } bool isTesselated() const { return false; }
void setFile(IfcParse::IfcFile*) {} void setFile(IfcParse::IfcFile*) {}
}; };
+2 -4
View File
@@ -23,8 +23,6 @@
#include <STEPControl_Writer.hxx> #include <STEPControl_Writer.hxx>
#include <Interface_Static.hxx> #include <Interface_Static.hxx>
#include "../ifcgeom/schema_agnostic/IfcGeomIterator.h"
#include "../serializers/OpenCascadeBasedSerializer.h" #include "../serializers/OpenCascadeBasedSerializer.h"
class StepSerializer : public OpenCascadeBasedSerializer class StepSerializer : public OpenCascadeBasedSerializer
@@ -36,10 +34,10 @@ public:
: OpenCascadeBasedSerializer(out_filename, settings) : OpenCascadeBasedSerializer(out_filename, settings)
{} {}
virtual ~StepSerializer() {} virtual ~StepSerializer() {}
void writeShape(const IfcGeom::ConversionResultShape* shape) { void writeShape(const ifcopenshell::geometry::ConversionResultShape* shape) {
std::stringstream ss; std::stringstream ss;
std::streambuf *sb = std::cout.rdbuf(ss.rdbuf()); std::streambuf *sb = std::cout.rdbuf(ss.rdbuf());
writer.Transfer(((IfcGeom::OpenCascadeShape*)shape)->shape(), STEPControl_AsIs); writer.Transfer(((ifcopenshell::geometry::OpenCascadeShape*)shape)->shape(), STEPControl_AsIs);
std::cout.rdbuf(sb); std::cout.rdbuf(sb);
} }
void finalize() { void finalize() {
+11 -11
View File
@@ -285,7 +285,7 @@ SvgSerializer::path_object& SvgSerializer::start_path(IfcUtil::IfcBaseEntity* st
return p; return p;
} }
void SvgSerializer::write(const IfcGeom::NativeElement<real_t>* o) void SvgSerializer::write(const ifcopenshell::geometry::NativeElement* o)
{ {
IfcUtil::IfcBaseEntity* storey = storey_; IfcUtil::IfcBaseEntity* storey = storey_;
boost::optional<double> storey_elevation = boost::none; boost::optional<double> storey_elevation = boost::none;
@@ -293,7 +293,7 @@ void SvgSerializer::write(const IfcGeom::NativeElement<real_t>* o)
for (const auto& p : o->parents()) { for (const auto& p : o->parents()) {
if (p->type() == "IfcBuildingStorey") { if (p->type() == "IfcBuildingStorey") {
try { try {
const IfcGeom::ElementSettings& settings = o->geometry().settings(); const ifcopenshell::geometry::element_settings& settings = o->geometry().settings();
double e = *p->product()->get("Elevation"); double e = *p->product()->get("Elevation");
storey_elevation = e * settings.unit_magnitude(); storey_elevation = e * settings.unit_magnitude();
} catch (...) { } catch (...) {
@@ -312,7 +312,8 @@ void SvgSerializer::write(const IfcGeom::NativeElement<real_t>* o)
path_object& p = start_path(storey, nameElement(o)); path_object& p = start_path(storey, nameElement(o));
IfcGeom::OpenCascadeShape* occt_shape = ((IfcGeom::OpenCascadeShape*) o->geometry().as_compound()); // @todo check whether correct kernel is used
ifcopenshell::geometry::OpenCascadeShape* occt_shape = ((ifcopenshell::geometry::OpenCascadeShape*) o->geometry().as_compound());
TopoDS_Shape compound = occt_shape->shape(); TopoDS_Shape compound = occt_shape->shape();
delete occt_shape; delete occt_shape;
@@ -443,7 +444,7 @@ void SvgSerializer::writeHeader() {
svg_file << "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n"; svg_file << "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n";
} }
std::string SvgSerializer::nameElement(const IfcGeom::Element<real_t>* elem) std::string SvgSerializer::nameElement(const ifcopenshell::geometry::Element* elem)
{ {
std::ostringstream oss; std::ostringstream oss;
const std::string type = "product"; const std::string type = "product";
@@ -471,11 +472,10 @@ std::string SvgSerializer::nameElement(const IfcUtil::IfcBaseEntity* elem) {
void SvgSerializer::setFile(IfcParse::IfcFile* f) { void SvgSerializer::setFile(IfcParse::IfcFile* f) {
file = f; file = f;
mapping_ = ifcopenshell::geometry::impl::mapping_implementations().construct(f);
auto storeys = f->instances_by_type("IfcBuildingStorey"); auto storeys = f->instances_by_type("IfcBuildingStorey");
if (!storeys || storeys->size() == 0) { if (!storeys || storeys->size() == 0) {
IfcGeom::Kernel kernel("opencascade", f);
std::vector<const IfcParse::declaration*> to_derive_from; std::vector<const IfcParse::declaration*> to_derive_from;
to_derive_from.push_back(f->schema()->declaration_by_name("IfcBuilding")); to_derive_from.push_back(f->schema()->declaration_by_name("IfcBuilding"));
to_derive_from.push_back(f->schema()->declaration_by_name("IfcSite")); to_derive_from.push_back(f->schema()->declaration_by_name("IfcSite"));
@@ -485,10 +485,10 @@ void SvgSerializer::setFile(IfcParse::IfcFile* f) {
for (auto jt = insts->begin(); jt != insts->end(); ++jt) { for (auto jt = insts->begin(); jt != insts->end(); ++jt) {
IfcUtil::IfcBaseEntity* product = (IfcUtil::IfcBaseEntity*) *jt; IfcUtil::IfcBaseEntity* product = (IfcUtil::IfcBaseEntity*) *jt;
if (!product->get("ObjectPlacement")->isNull()) { if (!product->get("ObjectPlacement")->isNull()) {
IfcGeom::ConversionResultPlacement* trsf; auto item = mapping_->map(*product->get("ObjectPlacement"));
if (kernel.convert_placement(*product->get("ObjectPlacement"), trsf)) { if (item) {
double X, Y, Z; auto matrix = (ifcopenshell::geometry::taxonomy::matrix4*) item;
trsf->TranslationPart(X, Y, Z); const double& Z = matrix->components(3, 2);
setSectionHeight(Z + 1.); setSectionHeight(Z + 1.);
Logger::Warning("No building storeys encountered, used for reference:", product); Logger::Warning("No building storeys encountered, used for reference:", product);
return; return;
+5 -3
View File
@@ -26,6 +26,7 @@
#include "../serializers/util.h" #include "../serializers/util.h"
#include "../ifcparse/utils.h" #include "../ifcparse/utils.h"
#include "../ifcgeom/abstract_mapping.h"
#include <sstream> #include <sstream>
#include <string> #include <string>
@@ -45,6 +46,7 @@ protected:
std::vector< boost::shared_ptr<util::string_buffer::float_item> > radii; std::vector< boost::shared_ptr<util::string_buffer::float_item> > radii;
IfcParse::IfcFile* file; IfcParse::IfcFile* file;
IfcUtil::IfcBaseEntity* storey_; IfcUtil::IfcBaseEntity* storey_;
ifcopenshell::geometry::abstract_mapping* mapping_;
public: public:
SvgSerializer(const std::string& out_filename, const SerializerSettings& settings) SvgSerializer(const std::string& out_filename, const SerializerSettings& settings)
: GeometrySerializer(settings) : GeometrySerializer(settings)
@@ -63,8 +65,8 @@ public:
void growBoundingBox(double x, double y) { if (x < xmin) xmin = x; if (x > xmax) xmax = x; if (y < ymin) ymin = y; if (y > ymax) ymax = y; } void growBoundingBox(double x, double y) { if (x < xmin) xmin = x; if (x > xmax) xmax = x; if (y < ymin) ymin = y; if (y > ymax) ymax = y; }
void writeHeader(); void writeHeader();
bool ready(); bool ready();
void write(const IfcGeom::TriangulationElement<real_t>* /*o*/) {} void write(const ifcopenshell::geometry::TriangulationElement* /*o*/) {}
void write(const IfcGeom::NativeElement<real_t>* o); void write(const ifcopenshell::geometry::NativeElement* o);
void write(path_object& p, const TopoDS_Wire& wire); void write(path_object& p, const TopoDS_Wire& wire);
path_object& start_path(IfcUtil::IfcBaseEntity* storey, const std::string& id); path_object& start_path(IfcUtil::IfcBaseEntity* storey, const std::string& id);
bool isTesselated() const { return false; } bool isTesselated() const { return false; }
@@ -73,7 +75,7 @@ public:
void setFile(IfcParse::IfcFile* f); void setFile(IfcParse::IfcFile* f);
void setBoundingRectangle(double width, double height); void setBoundingRectangle(double width, double height);
void setSectionHeight(double h, IfcUtil::IfcBaseEntity* storey = 0) { section_height = h; storey_ = storey; } void setSectionHeight(double h, IfcUtil::IfcBaseEntity* storey = 0) { section_height = h; storey_ = storey; }
std::string nameElement(const IfcGeom::Element<real_t>* elem); std::string nameElement(const ifcopenshell::geometry::Element* elem);
std::string nameElement(const IfcUtil::IfcBaseEntity* elem); std::string nameElement(const IfcUtil::IfcBaseEntity* elem);
}; };
+22 -19
View File
@@ -58,38 +58,39 @@ void WaveFrontOBJSerializer::writeHeader() {
mtl_stream << "# File generated by IfcOpenShell " << IFCOPENSHELL_VERSION << "\n"; mtl_stream << "# File generated by IfcOpenShell " << IFCOPENSHELL_VERSION << "\n";
} }
void WaveFrontOBJSerializer::writeMaterial(const IfcGeom::Material& style) void WaveFrontOBJSerializer::writeMaterial(const ifcopenshell::geometry::taxonomy::style& style)
{ {
std::string material_name = (settings().get(SerializerSettings::USE_MATERIAL_NAMES) // @todo original_name
? style.original_name() : style.name()); std::string material_name = *(settings().get(SerializerSettings::USE_MATERIAL_NAMES)
? style.name : style.name);
IfcUtil::sanitate_material_name(material_name); IfcUtil::sanitate_material_name(material_name);
mtl_stream << "newmtl " << material_name << "\n"; mtl_stream << "newmtl " << material_name << "\n";
if (style.hasDiffuse()) { if (style.diffuse) {
const double* diffuse = style.diffuse(); auto diffuse = style.diffuse->components;
mtl_stream << "Kd " << diffuse[0] << " " << diffuse[1] << " " << diffuse[2] << "\n"; mtl_stream << "Kd " << diffuse[0] << " " << diffuse[1] << " " << diffuse[2] << "\n";
} }
if (style.hasSpecular()) { if (style.specular) {
const double* specular = style.specular(); auto specular = style.specular->components;
mtl_stream << "Ks " << specular[0] << " " << specular[1] << " " << specular[2] << "\n"; mtl_stream << "Ks " << specular[0] << " " << specular[1] << " " << specular[2] << "\n";
} }
if (style.hasSpecularity()) { if (style.specularity) {
mtl_stream << "Ns " << style.specularity() << "\n"; mtl_stream << "Ns " << *style.specularity << "\n";
} }
if (style.hasTransparency()) { if (style.transparency) {
const double transparency = 1.0 - style.transparency(); const double transparency = 1.0 - *style.transparency;
if (transparency < 1) { if (transparency < 1) {
mtl_stream << "d " << transparency << "\n"; mtl_stream << "d " << transparency << "\n";
} }
} }
} }
void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>* o) void WaveFrontOBJSerializer::write(const ifcopenshell::geometry::TriangulationElement* o)
{ {
obj_stream << "g " << object_id(o) << "\n"; obj_stream << "g " << object_id(o) << "\n";
obj_stream << "s 1" << "\n"; obj_stream << "s 1" << "\n";
const IfcGeom::Representation::Triangulation<real_t>& mesh = o->geometry(); const ifcopenshell::geometry::Representation::Triangulation& mesh = o->geometry();
const int vcount = (int)mesh.verts().size() / 3; const int vcount = (int)mesh.verts().size() / 3;
for ( std::vector<real_t>::const_iterator it = mesh.verts().begin(); it != mesh.verts().end(); ) { for ( std::vector<real_t>::const_iterator it = mesh.verts().begin(); it != mesh.verts().end(); ) {
@@ -121,9 +122,10 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>*
const int material_id = *(material_it++); const int material_id = *(material_it++);
if (material_id != previous_material_id) { if (material_id != previous_material_id) {
const IfcGeom::Material& material = mesh.materials()[material_id]; const ifcopenshell::geometry::taxonomy::style& material = mesh.materials()[material_id];
std::string material_name = (settings().get(SerializerSettings::USE_MATERIAL_NAMES) // @todo original_name
? material.original_name() : material.name()); std::string material_name = *(settings().get(SerializerSettings::USE_MATERIAL_NAMES)
? material.name : material.name);
IfcUtil::sanitate_material_name(material_name); IfcUtil::sanitate_material_name(material_name);
obj_stream << "usemtl " << material_name << "\n"; obj_stream << "usemtl " << material_name << "\n";
if (materials.find(material_name) == materials.end()) { if (materials.find(material_name) == materials.end()) {
@@ -165,9 +167,10 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>*
const int material_id = *(material_it++); const int material_id = *(material_it++);
if (material_id != previous_material_id) { if (material_id != previous_material_id) {
const IfcGeom::Material& material = mesh.materials()[material_id]; const ifcopenshell::geometry::taxonomy::style& material = mesh.materials()[material_id];
std::string material_name = (settings().get(SerializerSettings::USE_MATERIAL_NAMES) // @todo original_name
? material.original_name() : material.name()); std::string material_name = *(settings().get(SerializerSettings::USE_MATERIAL_NAMES)
? material.name : material.name);
IfcUtil::sanitate_material_name(material_name); IfcUtil::sanitate_material_name(material_name);
obj_stream << "usemtl " << material_name << "\n"; obj_stream << "usemtl " << material_name << "\n";
if (materials.find(material_name) == materials.end()) { if (materials.find(material_name) == materials.end()) {
+3 -3
View File
@@ -39,9 +39,9 @@ public:
virtual ~WaveFrontOBJSerializer() {} virtual ~WaveFrontOBJSerializer() {}
bool ready(); bool ready();
void writeHeader(); void writeHeader();
void writeMaterial(const IfcGeom::Material& style); void writeMaterial(const ifcopenshell::geometry::taxonomy::style& style);
void write(const IfcGeom::TriangulationElement<real_t>* o); void write(const ifcopenshell::geometry::TriangulationElement* o);
void write(const IfcGeom::NativeElement<real_t>* /*o*/) {} void write(const ifcopenshell::geometry::NativeElement* /*o*/) {}
void finalize() {} void finalize() {}
bool isTesselated() const { return true; } bool isTesselated() const { return true; }
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {} void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
@@ -129,11 +129,13 @@ boost::optional<std::string> format_attribute(ifcopenshell::geometry::abstract_m
auto matrix = (ifcopenshell::geometry::taxonomy::matrix4*) placement; auto matrix = (ifcopenshell::geometry::taxonomy::matrix4*) placement;
std::stringstream stream; std::stringstream stream;
for (int i = 0; i < 16; ++i) { for (int i = 0; i < 4; ++i) {
const double trsf_value = matrix->components[i]; for (int j = 0; j < 4; ++j) {
stream << trsf_value; const double trsf_value = matrix->components(j, i);
if (i != 15) { stream << trsf_value;
stream << " "; if (i < 3 && j < 3) {
stream << " ";
}
} }
} }
value = stream.str(); value = stream.str();
@@ -475,7 +477,7 @@ void POSTFIX_SCHEMA(XmlSerializer)::finalize() {
for (IfcEntityList::it it = unit_assignments->begin(); it != unit_assignments->end(); ++it) { for (IfcEntityList::it it = unit_assignments->begin(); it != unit_assignments->end(); ++it) {
if ((*it)->declaration().is(IfcSchema::IfcNamedUnit::Class())) { if ((*it)->declaration().is(IfcSchema::IfcNamedUnit::Class())) {
IfcSchema::IfcNamedUnit* named_unit = (*it)->as<IfcSchema::IfcNamedUnit>(); IfcSchema::IfcNamedUnit* named_unit = (*it)->as<IfcSchema::IfcNamedUnit>();
ptree& node = format_entity_instance(mapping, named_unit, units); ptree& node = format_entity_instance(mapping_, named_unit, units);
node.put("<xmlattr>.SI_equivalent", IfcParse::get_SI_equivalent<IfcSchema>(named_unit)); node.put("<xmlattr>.SI_equivalent", IfcParse::get_SI_equivalent<IfcSchema>(named_unit));
} else if ((*it)->declaration().is(IfcSchema::IfcMonetaryUnit::Class())) { } else if ((*it)->declaration().is(IfcSchema::IfcMonetaryUnit::Class())) {
format_entity_instance(mapping_, (*it)->as<IfcSchema::IfcMonetaryUnit>(), units); format_entity_instance(mapping_, (*it)->as<IfcSchema::IfcMonetaryUnit>(), units);