Fixes for compilation of cgal kernel

This commit is contained in:
Thomas Krijnen
2019-01-23 12:34:21 +01:00
parent a7a1ad129e
commit 30479ca0a6
15 changed files with 171 additions and 99 deletions
@@ -21,6 +21,7 @@
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Compound.hxx>
#include <Geom_Plane.hxx>
#include <GProp_GProps.hxx>
@@ -34,7 +35,10 @@ IfcGeom::Representation::Serialization::Serialization(const BRep& brep)
: Representation(brep.settings())
, id_(brep.id())
{
TopoDS_Compound compound = brep.as_compound();
IfcGeom::ConversionResultShape* shape = brep.as_compound();
TopoDS_Compound compound = TopoDS::Compound(((OpenCascadeShape*) shape)->shape());
delete shape;
for (IfcGeom::ConversionResults::const_iterator it = brep.begin(); it != brep.end(); ++ it) {
if (it->hasStyle() && it->Style().Diffuse()) {
const IfcGeom::SurfaceStyle::ColorComponent& clr = *it->Style().Diffuse();
@@ -82,7 +86,7 @@ TopoDS_Shape apply_transformation(const TopoDS_Shape& s, const gp_GTrsf& t) {
}
}
TopoDS_Compound IfcGeom::Representation::BRep::as_compound() const {
IfcGeom::ConversionResultShape* IfcGeom::Representation::BRep::as_compound() const {
TopoDS_Compound compound;
BRep_Builder builder;
builder.MakeCompound(compound);
@@ -103,7 +107,8 @@ TopoDS_Compound IfcGeom::Representation::BRep::as_compound() const {
const TopoDS_Shape moved_shape = apply_transformation(s, trsf);
builder.Add(compound, moved_shape);
}
return compound;
return new OpenCascadeShape(compound);
}
namespace {
@@ -212,7 +217,7 @@ bool IfcGeom::Representation::BRep::calculate_volume(double& volume) const {
volume = 0.;
for (IfcGeom::ConversionResults::const_iterator it = begin(); it != end(); ++it) {
if (Kernel::is_manifold(*(OpenCascadeShape*)it->Shape())) {
if (Kernel::is_manifold(it->Shape())) {
GProp_GProps prop;
BRepGProp::VolumeProperties(*(OpenCascadeShape*)it->Shape(), prop);
volume += prop.Mass();
@@ -240,7 +245,7 @@ bool IfcGeom::Representation::BRep::calculate_projected_surface_area(const Conve
double x, y, z;
surface_area_along_direction(settings().deflection_tolerance(), *(OpenCascadeShape*)it->Shape(), ax, x, y, z);
if (Kernel::is_manifold(*(OpenCascadeShape*)it->Shape())) {
if (Kernel::is_manifold(it->Shape())) {
x /= 2.;
y /= 2.;
z /= 2.;
@@ -20,27 +20,10 @@
#ifndef IFCGEOMREPRESENTATION_H
#define IFCGEOMREPRESENTATION_H
#include <BRepMesh_IncrementalMesh.hxx>
#include <BRepGProp_Face.hxx>
#include <Poly_Triangulation.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <TopoDS.hxx>
#include <BRepTools.hxx>
#include <TopExp_Explorer.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <GCPnts_QuasiUniformDeflection.hxx>
#include <Geom_SphericalSurface.hxx>
#include "../../ifcgeom/schema_agnostic/IfcGeomIteratorSettings.h"
#include "../../ifcgeom/schema_agnostic/IfcGeomMaterial.h"
#include "../../ifcgeom/schema_agnostic/ConversionResult.h"
#include <TopoDS_Compound.hxx>
#include <map>
namespace IfcGeom {
@@ -77,7 +60,7 @@ namespace IfcGeom {
IfcGeom::ConversionResults::const_iterator end() const { return shapes_.end(); }
const IfcGeom::ConversionResults& shapes() const { return shapes_; }
const std::string& id() const { return id_; }
TopoDS_Compound as_compound() const;
ConversionResultShape* as_compound() const;
bool calculate_volume(double&) const;
bool calculate_surface_area(double&) const;
+22 -7
View File
@@ -3,6 +3,9 @@
#include "../../ifcparse/Ifc2x3.h"
#include "../../ifcparse/Ifc4.h"
// @todo remove
#include "../../ifcgeom/schema_agnostic/opencascade/OpenCascadeConversionResult.h"
#include <TopExp.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
@@ -19,7 +22,11 @@ IfcGeom::Kernel::Kernel(const std::string& geometry_library, IfcParse::IfcFile*
}
}
int IfcGeom::Kernel::count(const TopoDS_Shape& s, TopAbs_ShapeEnum t, bool unique) {
int IfcGeom::Kernel::count(const ConversionResultShape* s_, int t_, bool unique) {
// @todo make kernel agnostic
const TopoDS_Shape& s = ((OpenCascadeShape*) s_)->shape();
TopAbs_ShapeEnum t = (TopAbs_ShapeEnum) t_;
if (unique) {
TopTools_IndexedMapOfShape map;
TopExp::MapShapes(s, t, map);
@@ -35,10 +42,14 @@ int IfcGeom::Kernel::count(const TopoDS_Shape& s, TopAbs_ShapeEnum t, bool uniqu
}
int IfcGeom::Kernel::surface_genus(const TopoDS_Shape& s) {
int nv = count(s, TopAbs_VERTEX, true);
int ne = count(s, TopAbs_EDGE, true);
int nf = count(s, TopAbs_FACE, true);
int IfcGeom::Kernel::surface_genus(const ConversionResultShape* s_) {
// @todo make kernel agnostic
const TopoDS_Shape& s = ((OpenCascadeShape*) s_)->shape();
OpenCascadeShape Ss(s);
int nv = count(&Ss, (int) TopAbs_VERTEX, true);
int ne = count(&Ss, (int) TopAbs_EDGE, true);
int nf = count(&Ss, (int) TopAbs_FACE, true);
const int euler = nv - ne + nf;
const int genus = (2 - euler) / 2;
@@ -202,11 +213,15 @@ std::map<std::string, IfcUtil::IfcBaseEntity*> IfcGeom::Kernel::get_layers(IfcUt
}
}
bool IfcGeom::Kernel::is_manifold(const TopoDS_Shape& a) {
bool IfcGeom::Kernel::is_manifold(const ConversionResultShape* s_) {
// @todo make kernel agnostic
const TopoDS_Shape& a = ((OpenCascadeShape*) s_)->shape();
if (a.ShapeType() == TopAbs_COMPOUND || a.ShapeType() == TopAbs_SOLID) {
TopoDS_Iterator it(a);
for (; it.More(); it.Next()) {
if (!is_manifold(it.Value())) {
OpenCascadeShape s(it.Value());
if (!is_manifold(&s)) {
return false;
}
}
+3 -5
View File
@@ -7,8 +7,6 @@
#include <boost/function.hpp>
#include <TopExp_Explorer.hxx>
namespace IfcGeom {
template <typename P, typename PP>
@@ -76,10 +74,10 @@ namespace IfcGeom {
return implementation_->convert_placement(item, trsf);
}
static int count(const TopoDS_Shape&, TopAbs_ShapeEnum, bool unique=false);
static int surface_genus(const TopoDS_Shape&);
static int count(const ConversionResultShape*, int, bool unique=false);
static int surface_genus(const ConversionResultShape*);
static bool is_manifold(const TopoDS_Shape& a);
static bool is_manifold(const ConversionResultShape*);
static IfcUtil::IfcBaseEntity* get_decomposing_entity(IfcUtil::IfcBaseEntity*);
static std::map<std::string, IfcUtil::IfcBaseEntity*> get_layers(IfcUtil::IfcBaseEntity*);
static IfcEntityList::ptr find_openings(IfcUtil::IfcBaseEntity* product);
@@ -1,9 +1,14 @@
#include "CgalConversionResult.h"
#include "../../../ifcparse/IfcLogger.h"
#include "../../../ifcgeom/schema_agnostic/IfcGeomRepresentation.h"
template <typename Precision>
void triangulate_helper(const cgal_shape_t, const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<Precision>* t, int surface_style_id) {
cgal_shape_t s = shape_;
const cgal_placement_t& trsf = dynamic_cast<const CgalPlacement*>(place)->trsf();
void triangulate_helper(const cgal_shape_t& shape_const, const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<Precision>* t, int surface_style_id) {
// Copy is made because triangulate_faces() does not accept a const argument
cgal_shape_t s = shape_const;
const cgal_placement_t& trsf = dynamic_cast<const IfcGeom::CgalPlacement*>(place)->trsf();
// std::cout << "Model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl;
// std::cout << "Valid: " << s.is_valid() << std::endl;
@@ -17,6 +22,7 @@ void triangulate_helper(const cgal_shape_t, const IfcGeom::IteratorSettings & se
boost::associative_property_map<std::map<cgal_vertex_descriptor_t, Kernel::Vector_3>> vertex_normals_map(vertex_normals);
std::map<cgal_face_descriptor_t, Kernel::Vector_3> face_normals;
boost::associative_property_map<std::map<cgal_face_descriptor_t, Kernel::Vector_3>> face_normals_map(face_normals);
if (CGAL::Polygon_mesh_processing::triangulate_faces(s)) {
// std::cout << "Triangulated model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl;
} else {
@@ -35,14 +41,21 @@ void triangulate_helper(const cgal_shape_t, const IfcGeom::IteratorSettings & se
CGAL::to_double(current_halfedge->vertex()->point().cartesian(0)),
CGAL::to_double(current_halfedge->vertex()->point().cartesian(1)),
CGAL::to_double(current_halfedge->vertex()->point().cartesian(2)));
for (int i = 0; i < 3; ++i) t->normals().push_back(CGAL::to_double(face_normals_map[face].cartesian(i)));
t->faces().push_back(num_vertices);
const double nx = CGAL::to_double(face_normals_map[face].cartesian(0));
const double ny = CGAL::to_double(face_normals_map[face].cartesian(1));
const double nz = CGAL::to_double(face_normals_map[face].cartesian(2));
t->addNormal(nx, ny, nz);
++num_vertices;
++current_halfedge;
} while (current_halfedge != face->facet_begin());
t->material_ids().push_back(surface_style_id);
t->addFace(surface_style_id, num_vertices-3, num_vertices-2, num_vertices-1);
++num_faces;
}
}
void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<float>* t, int surface_style_id) const {