Files
IfcOpenShell/src/ifcgeom/kernels/opencascade/OpenCascadeKernel.h
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

169 lines
7.1 KiB
C++
Raw Normal View History

2021-11-05 16:54:16 +01:00
/********************************************************************************
* *
* This file is part of IfcOpenShell. *
* *
* IfcOpenShell is free software: you can redistribute it and/or modify *
* it under the terms of the Lesser GNU General Public License as published by *
* the Free Software Foundation, either version 3.0 of the License, or *
* (at your option) any later version. *
* *
* IfcOpenShell is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* Lesser GNU General Public License for more details. *
* *
* You should have received a copy of the Lesser GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
********************************************************************************/
2011-05-08 11:04:32 +00:00
#ifndef IFCGEOM_H
#define IFCGEOM_H
2015-10-07 17:33:30 +02:00
#include <cmath>
#include <array>
2015-10-07 17:33:30 +02:00
2011-05-08 11:04:32 +00:00
#include <gp_Pnt.hxx>
#include <gp_Vec.hxx>
#include <gp_Mat.hxx>
#include <gp_Mat2d.hxx>
#include <gp_GTrsf.hxx>
#include <gp_GTrsf2d.hxx>
2011-05-08 11:04:32 +00:00
#include <gp_Trsf.hxx>
#include <gp_Trsf2d.hxx>
#include <gp_Quaternion.hxx>
2011-05-08 11:04:32 +00:00
#include <TopoDS.hxx>
#include <TopoDS_Wire.hxx>
#include <TopoDS_Face.hxx>
#include <Geom_Curve.hxx>
#include <gp_Pln.hxx>
#include <TColgp_SequenceOfPnt.hxx>
#include <TopTools_ListOfShape.hxx>
2017-02-16 15:54:34 +01:00
#include <BOPAlgo_Operation.hxx>
#include <BRep_Builder.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
2011-05-08 11:04:32 +00:00
2023-03-21 20:15:01 +01:00
#include "../../../ifcgeom/AbstractKernel.h"
2023-03-21 20:15:01 +01:00
#include "../../../ifcgeom/IfcGeomElement.h"
#include "../../../ifcgeom/IfcGeomRepresentation.h"
#include "../../../ifcgeom/ConversionResult.h"
2023-03-21 20:15:01 +01:00
#include "../../../ifcgeom/kernels/opencascade/OpenCascadeConversionResult.h"
2023-03-21 20:15:01 +01:00
#include "../../../ifcgeom/ifc_geom_api.h"
2023-03-21 20:15:01 +01:00
#include "../../../ifcgeom/taxonomy.h"
#include "../../../ifcgeom/ConversionSettings.h"
namespace IfcGeom {
2023-11-15 10:32:20 +01:00
class IFC_GEOM_API OpenCascadeKernel : public ifcopenshell::geometry::kernels::AbstractKernel {
private:
2016-05-02 15:13:30 +02:00
/*
faceset_helper traverses the forward instance references of IfcConnectedFaceSet and then provides a mapping
M of (IfcCartesianPoint, IfcCartesianPoint) -> TopoDS_Edge, where M(a, b) is a partner of M(b, a), ie share
the same underlying edge but with orientation reversed. This then later speeds op the process of creating a
manifold Shell / Solid from this set of faces. Only IfcPolyLoop instances are used. Points within the tolerance
threshiold are merged, so consider points a, b, c, distance(a, b) < eps then M(a, b) = Null, M(a, b) = M(a, c).
*/
2021-05-11 22:35:46 +02:00
class faceset_helper {
private:
2023-03-21 20:15:01 +01:00
OpenCascadeKernel* kernel_;
std::set<int> duplicates_;
std::map<int, int> vertex_mapping_;
std::map<std::pair<int, int>, TopoDS_Edge> edges_;
double eps_;
bool non_manifold_;
2023-11-15 10:32:20 +01:00
void loop_(const ifcopenshell::geometry::taxonomy::loop::ptr ps, const std::function<void(int, int, bool)>& callback);
2021-05-11 22:35:46 +02:00
2023-03-21 20:15:01 +01:00
/*
2021-05-11 22:35:46 +02:00
bool construct(const IfcSchema::IfcCartesianPoint* cp, gp_Pnt* l);
bool construct(const std::vector<double>& cp, gp_Pnt* l);
const void* get_idx(const IfcSchema::IfcCartesianPoint* cp) {
return cp;
}
const void* get_idx(const std::vector<double>& cp) {
return &cp;
}
std::vector<const void*> get_idxs(const IfcSchema::IfcPolyLoop* lp);
std::vector<const void*> get_idxs(const std::vector<int>& it);
2023-03-21 20:15:01 +01:00
*/
public:
2023-11-15 10:32:20 +01:00
faceset_helper(OpenCascadeKernel* kernel, const ifcopenshell::geometry::taxonomy::shell::ptr l);
~faceset_helper();
bool non_manifold() const { return non_manifold_; }
bool& non_manifold() { return non_manifold_; }
double epsilon() const { return eps_; }
bool edge(int A, int B, TopoDS_Edge& e);
2023-11-15 10:32:20 +01:00
bool wire(const ifcopenshell::geometry::taxonomy::loop::ptr loop, TopoDS_Wire& wire);
bool wires(const ifcopenshell::geometry::taxonomy::loop::ptr loop, TopTools_ListOfShape& wires);
};
2023-03-21 20:15:01 +01:00
faceset_helper* faceset_helper_;
2023-03-21 20:15:01 +01:00
// @todo these should be moved to the mapping
/*
gp_Vec offset = gp_Vec{0.0, 0.0, 0.0};
gp_Quaternion rotation = gp_Quaternion{};
gp_Trsf offset_and_rotation = gp_Trsf();
2023-03-21 20:15:01 +01:00
*/
2015-10-07 17:33:30 +02:00
2023-03-21 20:15:01 +01:00
double precision_;
2017-08-19 17:21:10 +02:00
public:
2023-11-15 10:32:20 +01:00
OpenCascadeKernel(const ifcopenshell::geometry::Settings& settings)
2023-03-21 20:15:01 +01:00
: AbstractKernel("opencascade", settings)
, faceset_helper_(nullptr)
2023-11-15 10:32:20 +01:00
, precision_(settings.get<ifcopenshell::geometry::settings::Precision>().get())
2015-10-07 17:33:30 +02:00
{}
2023-11-15 10:32:20 +01:00
bool convert(const ifcopenshell::geometry::taxonomy::extrusion::ptr, TopoDS_Shape&);
bool convert(const ifcopenshell::geometry::taxonomy::face::ptr, TopoDS_Shape&);
bool convert(const ifcopenshell::geometry::taxonomy::loop::ptr, TopoDS_Wire&);
bool convert(const ifcopenshell::geometry::taxonomy::matrix4::ptr, gp_GTrsf&);
bool convert(const ifcopenshell::geometry::taxonomy::shell::ptr, TopoDS_Shape&);
bool convert(const ifcopenshell::geometry::taxonomy::solid::ptr, TopoDS_Shape&);
bool convert(const ifcopenshell::geometry::taxonomy::loft::ptr, TopoDS_Shape&);
2023-11-15 10:32:20 +01:00
bool convert(const ifcopenshell::geometry::taxonomy::bspline_surface::ptr bs, Handle(Geom_Surface) surf);
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::edge::ptr, IfcGeom::ConversionResults&);
2023-11-15 10:32:20 +01:00
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::loop::ptr, IfcGeom::ConversionResults&);
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::face::ptr, IfcGeom::ConversionResults&);
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::solid::ptr, IfcGeom::ConversionResults&);
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::shell::ptr, IfcGeom::ConversionResults&);
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::extrusion::ptr, IfcGeom::ConversionResults&);
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::boolean_result::ptr, IfcGeom::ConversionResults&);
virtual bool convert_impl(const ifcopenshell::geometry::taxonomy::loft::ptr, IfcGeom::ConversionResults&);
2023-11-15 10:32:20 +01:00
virtual bool convert_openings(const IfcUtil::IfcBaseEntity* entity, const std::vector<std::pair<ifcopenshell::geometry::taxonomy::ptr, ifcopenshell::geometry::taxonomy::matrix4>>& openings,
2023-03-21 20:15:01 +01:00
const IfcGeom::ConversionResults& entity_shapes, const ifcopenshell::geometry::taxonomy::matrix4& entity_trsf, IfcGeom::ConversionResults& cut_shapes);
template <typename T, typename U>
static T convert_xyz(const U& u) {
const auto& vs = u.ccomponents();
return T(vs(0), vs(1), vs(2));
}
2023-03-21 20:15:01 +01:00
// @todo eliminate
template <typename T, typename U>
static T convert_xyz2(const U& vs) {
return T(vs(0), vs(1), vs(2));
2017-12-22 13:51:11 +01:00
}
};
2023-03-21 20:15:01 +01:00
IfcUtil::IfcBaseClass* POSTFIX_SCHEMA(tesselate_)(const TopoDS_Shape& shape, double deflection);
IfcUtil::IfcBaseClass* POSTFIX_SCHEMA(serialise_)(const TopoDS_Shape& shape, bool advanced);
2011-05-08 11:04:32 +00:00
}
#endif