Isolate geometry processing code into separate opencascade kernel

This commit is contained in:
Thomas Krijnen
2017-01-13 17:59:05 +01:00
parent 4fa7f293d6
commit d17f714dc5
52 changed files with 1369 additions and 1099 deletions
+1 -1
View File
@@ -188,7 +188,7 @@ public:
bool ready();
void writeHeader();
void write(const IfcGeom::TriangulationElement<real_t>* o);
void write(const IfcGeom::BRepElement<real_t>* /*o*/) {}
void write(const IfcGeom::NativeElement<real_t>* /*o*/) {}
void finalize();
bool isTesselated() const { return true; }
void setUnitNameAndMagnitude(const std::string& name, float magnitude) {
+1 -1
View File
@@ -36,7 +36,7 @@ public:
virtual bool isTesselated() const = 0;
virtual void write(const IfcGeom::TriangulationElement<real_t>* o) = 0;
virtual void write(const IfcGeom::BRepElement<real_t>* o) = 0;
virtual void write(const IfcGeom::NativeElement<real_t>* o) = 0;
virtual void setUnitNameAndMagnitude(const std::string& name, float magnitude) = 0;
const IfcGeom::IteratorSettings& settings() const { return settings_; }
+5 -2
View File
@@ -483,6 +483,8 @@ int main(int argc, char** argv) {
int old_progress = -1;
if (center_model) {
throw std::runtime_error("Not implemented");
/*
double* offset = serializer->settings().offset;
gp_XYZ center = (context_iterator.bounds_min() + context_iterator.bounds_max()) * 0.5;
offset[0] = -center.X();
@@ -491,6 +493,7 @@ int main(int argc, char** argv) {
std::stringstream msg;
msg << "Using model offset (" << offset[0] << "," << offset[1] << "," << offset[2] << ")";
Logger::Message(Logger::LOG_NOTICE, msg.str());
*/
}
Logger::Status("Creating geometry...");
@@ -498,7 +501,7 @@ int main(int argc, char** argv) {
// The functions IfcGeom::Iterator::get() and IfcGeom::Iterator::next()
// wrap an iterator of all geometrical products in the Ifc file.
// IfcGeom::Iterator::get() returns an IfcGeom::TriangulationElement or
// -BRepElement pointer, based on current settings. (see IfcGeomIterator.h
// -NativeElement pointer, based on current settings. (see IfcGeomIterator.h
// for definition) IfcGeom::Iterator::next() is used to poll whether more
// geometrical entities are available. None of these functions throw
// exceptions, neither for parsing errors or geometrical errors. Upon
@@ -512,7 +515,7 @@ int main(int argc, char** argv) {
if (is_tesselated) {
serializer->write(static_cast<const IfcGeom::TriangulationElement<real_t>*>(geom_object));
} else {
serializer->write(static_cast<const IfcGeom::BRepElement<real_t>*>(geom_object));
serializer->write(static_cast<const IfcGeom::NativeElement<real_t>*>(geom_object));
}
const int progress = context_iterator.progress() / 2;
if (old_progress != progress) Logger::ProgressBar(progress);
+4 -2
View File
@@ -25,6 +25,8 @@
#include <IGESControl_Writer.hxx>
#include <Interface_Static.hxx>
#include "../ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h"
class IgesSerializer : public OpenCascadeBasedSerializer
{
private:
@@ -36,8 +38,8 @@ public:
: OpenCascadeBasedSerializer(out_filename, settings)
{}
virtual ~IgesSerializer() {}
void writeShape(const TopoDS_Shape& shape) {
writer.AddShape(shape);
void writeShape(const IfcGeom::ConversionResultShape* shape) {
writer.AddShape(*(IfcGeom::OpenCascadeShape*)shape);
}
void finalize() {
writer.Write(out_filename.c_str());
+12 -8
View File
@@ -22,8 +22,11 @@
#include <cstdio>
#include <Standard_Version.hxx>
#include <gp_GTrsf.hxx>
#include "OpenCascadeBasedSerializer.h"
#include "../ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h"
#include "../ifcgeom/kernels/opencascade/OpenCascadeKernel.h"
bool OpenCascadeBasedSerializer::ready() {
std::ofstream test_file(out_filename.c_str(), std::ios_base::binary);
@@ -33,11 +36,11 @@ bool OpenCascadeBasedSerializer::ready() {
return succeeded;
}
void OpenCascadeBasedSerializer::write(const IfcGeom::BRepElement<real_t>* o) {
for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) {
gp_GTrsf gtrsf = it->Placement();
void OpenCascadeBasedSerializer::write(const IfcGeom::NativeElement<real_t>* o) {
for (IfcGeom::ConversionResults::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) {
gp_GTrsf gtrsf = *(IfcGeom::OpenCascadePlacement*) it->Placement();
const gp_Trsf& o_trsf = o->transformation().data();
const gp_GTrsf& o_trsf = *(IfcGeom::OpenCascadePlacement*) o->transformation().data();
gtrsf.PreMultiply(o_trsf);
if (o->geometry().settings().get(IfcGeom::IteratorSettings::CONVERT_BACK_UNITS)) {
@@ -46,10 +49,11 @@ void OpenCascadeBasedSerializer::write(const IfcGeom::BRepElement<real_t>* o) {
gtrsf.PreMultiply(scale);
}
const TopoDS_Shape& s = it->Shape();
const TopoDS_Shape moved_shape = IfcGeom::Kernel::apply_transformation(s, gtrsf);
writeShape(moved_shape);
const TopoDS_Shape& s = *(IfcGeom::OpenCascadeShape*) it->Shape();
const TopoDS_Shape moved_shape = IfcGeom::OpenCascadeKernel::apply_transformation(s, gtrsf);
IfcGeom::OpenCascadeShape shp(moved_shape);
writeShape(&shp);
}
}
+2 -2
View File
@@ -38,9 +38,9 @@ public:
virtual ~OpenCascadeBasedSerializer() {}
void writeHeader() {}
bool ready();
virtual void writeShape(const TopoDS_Shape& shape) = 0;
virtual void writeShape(const IfcGeom::ConversionResultShape* shape) = 0;
void write(const IfcGeom::TriangulationElement<real_t>* /*o*/) {}
void write(const IfcGeom::BRepElement<real_t>* o);
void write(const IfcGeom::NativeElement<real_t>* o);
bool isTesselated() const { return false; }
void setFile(IfcParse::IfcFile*) {}
};
+3 -2
View File
@@ -26,6 +26,7 @@
#include "../ifcgeom/IfcGeomIterator.h"
#include "../ifcconvert/OpenCascadeBasedSerializer.h"
#include "../ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h"
class StepSerializer : public OpenCascadeBasedSerializer
{
@@ -36,10 +37,10 @@ public:
: OpenCascadeBasedSerializer(out_filename, settings)
{}
virtual ~StepSerializer() {}
void writeShape(const TopoDS_Shape& shape) {
void writeShape(const IfcGeom::ConversionResultShape* shape) {
std::stringstream ss;
std::streambuf *sb = std::cout.rdbuf(ss.rdbuf());
writer.Transfer(shape, STEPControl_AsIs);
writer.Transfer(*(IfcGeom::OpenCascadeShape*)shape, STEPControl_AsIs);
std::cout.rdbuf(sb);
}
void finalize() {
+11 -6
View File
@@ -26,8 +26,10 @@
#include <algorithm>
#include <gp_Pln.hxx>
#include <gp_GTrsf.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS_Wire.hxx>
#include <TopExp_Explorer.hxx>
#include <BRep_Tool.hxx>
#include <BRepAlgo_Section.hxx>
@@ -46,6 +48,9 @@
#include "SvgSerializer.h"
#include "../ifcgeom/kernels/opencascade/OpenCascadeKernel.h"
#include "../ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h"
const double PI2 = M_PI * 2.;
bool SvgSerializer::ready() {
@@ -166,7 +171,7 @@ SvgSerializer::path_object& SvgSerializer::start_path(IfcSchema::IfcBuildingStor
return p;
}
void SvgSerializer::write(const IfcGeom::BRepElement<real_t>* o)
void SvgSerializer::write(const IfcGeom::NativeElement<real_t>* o)
{
IfcSchema::IfcBuildingStorey* storey = 0;
IfcSchema::IfcObjectDefinition* obdef = static_cast<IfcSchema::IfcObjectDefinition*>(file->entityById(o->id()));
@@ -213,14 +218,14 @@ void SvgSerializer::write(const IfcGeom::BRepElement<real_t>* o)
path_object& p = start_path(storey, nameElement(o));
for (IfcGeom::IfcRepresentationShapeItems::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) {
gp_GTrsf gtrsf = it->Placement();
for (IfcGeom::ConversionResults::const_iterator it = o->geometry().begin(); it != o->geometry().end(); ++ it) {
gp_GTrsf gtrsf = *(IfcGeom::OpenCascadePlacement*) it->Placement();
const gp_Trsf& o_trsf = o->transformation().data();
const gp_GTrsf& o_trsf = *(IfcGeom::OpenCascadePlacement*) o->transformation().data();
gtrsf.PreMultiply(o_trsf);
const TopoDS_Shape& s = it->Shape();
const TopoDS_Shape moved_shape = IfcGeom::Kernel::apply_transformation(s, gtrsf);
const TopoDS_Shape& s = *(IfcGeom::OpenCascadeShape*) it->Shape();
const TopoDS_Shape moved_shape = IfcGeom::OpenCascadeKernel::apply_transformation(s, gtrsf);
const double inf = std::numeric_limits<double>::infinity();
double zmin = inf;
+1 -1
View File
@@ -60,7 +60,7 @@ public:
void writeHeader();
bool ready();
void write(const IfcGeom::TriangulationElement<real_t>* /*o*/) {}
void write(const IfcGeom::BRepElement<real_t>* o);
void write(const IfcGeom::NativeElement<real_t>* o);
void write(path_object& p, const TopoDS_Wire& wire);
path_object& start_path(IfcSchema::IfcBuildingStorey* storey, const std::string& id);
bool isTesselated() const { return false; }
+1 -1
View File
@@ -47,7 +47,7 @@ public:
void writeHeader();
void writeMaterial(const IfcGeom::Material& style);
void write(const IfcGeom::TriangulationElement<real_t>* o);
void write(const IfcGeom::BRepElement<real_t>* /*o*/) {}
void write(const IfcGeom::NativeElement<real_t>* /*o*/) {}
void finalize() {}
bool isTesselated() const { return true; }
void setUnitNameAndMagnitude(const std::string& /*name*/, float /*magnitude*/) {}
+3 -1
View File
@@ -30,6 +30,8 @@
#include "../ifcparse/IfcSIPrefix.h"
#include "../ifcgeom/IfcGeom.h"
#include "../ifcgeom/kernels/opencascade/OpenCascadeKernel.h"
using boost::property_tree::ptree;
using namespace IfcSchema;
@@ -109,7 +111,7 @@ boost::optional<std::string> format_attribute(const Argument* argument, IfcUtil:
} else if (e->is(IfcSchema::Type::IfcLocalPlacement)) {
IfcSchema::IfcLocalPlacement* placement = e->as<IfcSchema::IfcLocalPlacement>();
gp_Trsf trsf;
IfcGeom::Kernel kernel;
IfcGeom::OpenCascadeKernel kernel;
if (kernel.convert(placement, trsf)) {
std::stringstream stream;
for (int i = 1; i < 5; ++i) {