2012-07-19 18:26:47 +00:00
|
|
|
/********************************************************************************
|
2011-07-25 14:56:40 +00: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
|
|
|
|
|
|
2011-10-12 16:43:29 +00:00
|
|
|
#define ALMOST_ZERO (1e-9)
|
|
|
|
|
#define ALMOST_THE_SAME(a,b) (fabs(a-b) < ALMOST_ZERO)
|
|
|
|
|
|
2011-05-08 11:04:32 +00:00
|
|
|
#include <gp_Pnt.hxx>
|
|
|
|
|
#include <gp_Vec.hxx>
|
2011-10-23 17:11:06 +00:00
|
|
|
#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 <TopoDS.hxx>
|
|
|
|
|
#include <TopoDS_Wire.hxx>
|
|
|
|
|
#include <TopoDS_Face.hxx>
|
2011-07-25 14:56:40 +00:00
|
|
|
#include <Geom_Curve.hxx>
|
|
|
|
|
#include <gp_Pln.hxx>
|
2014-07-28 20:03:53 +00:00
|
|
|
#include <TColgp_SequenceOfPnt.hxx>
|
2011-05-08 11:04:32 +00:00
|
|
|
|
2011-07-25 14:56:40 +00:00
|
|
|
#include "../ifcparse/IfcParse.h"
|
|
|
|
|
#include "../ifcparse/IfcUtil.h"
|
|
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
#include "../ifcgeom/IfcGeomElement.h"
|
|
|
|
|
#include "../ifcgeom/IfcGeomRepresentation.h"
|
2013-05-05 08:49:25 +00:00
|
|
|
#include "../ifcgeom/IfcRepresentationShapeItem.h"
|
2015-04-22 09:15:48 +00:00
|
|
|
#include "../ifcgeom/IfcGeomShapeType.h"
|
2011-10-23 17:11:06 +00:00
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
#define IN_CACHE(T,E,t,e) std::map<int,t>::const_iterator it = cache.T.find(E->entity->id());\
|
|
|
|
|
if ( it != cache.T.end() ) { e = it->second; return true; }
|
|
|
|
|
#define CACHE(T,E,e) cache.T[E->entity->id()] = e;
|
|
|
|
|
|
2012-06-25 15:08:58 +00:00
|
|
|
namespace IfcGeom {
|
2012-03-20 09:32:51 +00:00
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
class Cache {
|
|
|
|
|
public:
|
|
|
|
|
#include "IfcRegisterCreateCache.h"
|
|
|
|
|
std::map<int, SurfaceStyle> Style;
|
|
|
|
|
std::map<int, TopoDS_Shape> Shape;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Kernel {
|
|
|
|
|
private:
|
|
|
|
|
Cache cache;
|
|
|
|
|
public:
|
2012-06-25 15:08:58 +00:00
|
|
|
// Tolerances and settings for various geometrical operations:
|
|
|
|
|
enum GeomValue {
|
|
|
|
|
// Specifies the deflection of the mesher
|
2012-08-11 13:24:08 +00:00
|
|
|
// Default: 0.001m / 1mm
|
2012-06-25 15:08:58 +00:00
|
|
|
GV_DEFLECTION_TOLERANCE,
|
|
|
|
|
// Specifies the tolerance of the wire builder, most notably for trimmed curves
|
2012-08-11 13:24:08 +00:00
|
|
|
// Defailt: 0.0001m / 0.1mm
|
2012-06-25 15:08:58 +00:00
|
|
|
GV_WIRE_CREATION_TOLERANCE,
|
|
|
|
|
// Specifies the minimal area of a face to be included in an IfcConnectedFaceset
|
2012-08-11 13:24:08 +00:00
|
|
|
// Default: 0.000001m 0.01cm2
|
2012-06-25 15:08:58 +00:00
|
|
|
GV_MINIMAL_FACE_AREA,
|
|
|
|
|
// Specifies the treshold distance under which cartesian points are deemed equal
|
2012-08-11 13:24:08 +00:00
|
|
|
// Default: 0.00001m / 0.01mm
|
2012-06-25 15:08:58 +00:00
|
|
|
GV_POINT_EQUALITY_TOLERANCE,
|
|
|
|
|
// Specifies maximum number of faces for a shell to be sewed. Sewing shells
|
|
|
|
|
// that consist of many faces is really detrimental for the performance.
|
2012-08-11 13:24:08 +00:00
|
|
|
// Default: 1000
|
|
|
|
|
GV_MAX_FACES_TO_SEW,
|
|
|
|
|
// The length unit used the creation of TopoDS_Shapes, primarily affects the
|
|
|
|
|
// interpretation of IfcCartesianPoints and IfcVector magnitudes
|
|
|
|
|
// DefaultL 1.0
|
|
|
|
|
GV_LENGTH_UNIT,
|
|
|
|
|
// The plane angle unit used for the creation of TopoDS_Shapes, primarily affects
|
|
|
|
|
// the interpretation of IfcParamaterValues of IfcTrimmedCurves
|
|
|
|
|
// Default: -1.0 (= not set, fist try degrees, then radians)
|
|
|
|
|
GV_PLANEANGLE_UNIT,
|
2013-11-24 15:44:27 +00:00
|
|
|
// The precision used in boolean operations, setting this value too low results
|
|
|
|
|
// in artefacts and potentially modelling failures
|
|
|
|
|
// Default: 0.00001 (obtained from IfcGeometricRepresentationContext if available)
|
2015-04-22 09:15:48 +00:00
|
|
|
GV_PRECISION,
|
|
|
|
|
// Whether to process shapes of type Face or higher (1) Wire or lower (-1) or all (0)
|
|
|
|
|
GV_DIMENSIONALITY
|
2012-06-25 15:08:58 +00:00
|
|
|
};
|
2012-03-01 21:17:06 +00:00
|
|
|
|
2011-07-25 14:56:40 +00:00
|
|
|
bool convert_wire_to_face(const TopoDS_Wire& wire, TopoDS_Face& face);
|
2014-03-15 11:51:23 +00:00
|
|
|
bool convert_curve_to_wire(const Handle(Geom_Curve)& curve, TopoDS_Wire& wire);
|
2013-05-05 08:49:25 +00:00
|
|
|
bool convert_shapes(const IfcUtil::IfcBaseClass* L, IfcRepresentationShapeItems& result);
|
2015-04-22 09:15:48 +00:00
|
|
|
IfcGeom::ShapeType shape_type(const IfcUtil::IfcBaseClass* L);
|
2013-05-05 08:49:25 +00:00
|
|
|
bool convert_shape(const IfcUtil::IfcBaseClass* L, TopoDS_Shape& result);
|
2014-07-06 14:21:56 +00:00
|
|
|
bool flatten_shape_list(const IfcGeom::IfcRepresentationShapeItems& shapes, TopoDS_Shape& result, bool fuse);
|
2011-09-03 13:58:59 +00:00
|
|
|
bool convert_wire(const IfcUtil::IfcBaseClass* L, TopoDS_Wire& result);
|
|
|
|
|
bool convert_curve(const IfcUtil::IfcBaseClass* L, Handle(Geom_Curve)& result);
|
2014-03-16 13:34:01 +00:00
|
|
|
bool convert_face(const IfcUtil::IfcBaseClass* L, TopoDS_Shape& result);
|
2014-05-04 14:42:55 +00:00
|
|
|
bool convert_openings(const IfcSchema::IfcProduct* entity, const IfcSchema::IfcRelVoidsElement::list::ptr& openings, const IfcRepresentationShapeItems& entity_shapes, const gp_Trsf& entity_trsf, IfcRepresentationShapeItems& cut_shapes);
|
|
|
|
|
bool convert_openings_fast(const IfcSchema::IfcProduct* entity, const IfcSchema::IfcRelVoidsElement::list::ptr& openings, const IfcRepresentationShapeItems& entity_shapes, const gp_Trsf& entity_trsf, IfcRepresentationShapeItems& cut_shapes);
|
2014-02-17 22:13:55 +00:00
|
|
|
IfcSchema::IfcSurfaceStyleShading* get_surface_style(IfcSchema::IfcRepresentationItem* item);
|
2016-01-22 17:27:28 +01:00
|
|
|
const IfcSchema::IfcRepresentationItem* find_item_carrying_style(const IfcSchema::IfcRepresentationItem* item);
|
2012-03-01 21:17:06 +00:00
|
|
|
bool create_solid_from_compound(const TopoDS_Shape& compound, TopoDS_Shape& solid);
|
|
|
|
|
bool is_compound(const TopoDS_Shape& shape);
|
2012-03-13 11:56:52 +00:00
|
|
|
bool is_convex(const TopoDS_Wire& wire);
|
|
|
|
|
TopoDS_Shape halfspace_from_plane(const gp_Pln& pln,const gp_Pnt& cent);
|
|
|
|
|
gp_Pln plane_from_face(const TopoDS_Face& face);
|
|
|
|
|
gp_Pnt point_above_plane(const gp_Pln& pln, bool agree=true);
|
2012-03-01 21:17:06 +00:00
|
|
|
const TopoDS_Shape& ensure_fit_for_subtraction(const TopoDS_Shape& shape, TopoDS_Shape& solid);
|
2014-03-16 13:34:01 +00:00
|
|
|
bool profile_helper(int numVerts, double* verts, int numFillets, int* filletIndices, double* filletRadii, gp_Trsf2d trsf, TopoDS_Shape& face);
|
2012-03-13 11:56:52 +00:00
|
|
|
double shape_volume(const TopoDS_Shape& s);
|
2012-04-07 14:34:44 +00:00
|
|
|
double face_area(const TopoDS_Face& f);
|
2013-11-24 15:44:27 +00:00
|
|
|
void apply_tolerance(TopoDS_Shape& s, double t);
|
2014-12-19 12:14:36 +00:00
|
|
|
void setValue(GeomValue var, double value);
|
2015-10-07 16:13:25 +02:00
|
|
|
double getValue(GeomValue var) const;
|
Add support for IfcBooleanResult, IfcBlock, IfcRectangularPyramid, IfcRightCircularCylinder, IfcRightCircularCone, IfcSphere, IfcCsgSolid, IfcCurveBoundedPlane, IfcRectangularTrimmedSurface, IfcSurfaceCurveSweptAreaSolid, IfcCylindricalSurface.
2014-03-22 10:31:51 +00:00
|
|
|
bool fill_nonmanifold_wires_with_planar_faces(TopoDS_Shape& shape);
|
2016-01-22 17:27:28 +01:00
|
|
|
void remove_duplicate_points_from_loop(TColgp_SequenceOfPnt& polygon, bool closed, double tol=-1.);
|
|
|
|
|
void remove_collinear_points_from_loop(TColgp_SequenceOfPnt& polygon, bool closed, double tol=-1.);
|
|
|
|
|
bool wire_to_sequence_of_point(const TopoDS_Wire&, TColgp_SequenceOfPnt&);
|
|
|
|
|
void sequence_of_point_to_wire(const TColgp_SequenceOfPnt&, TopoDS_Wire&, bool closed);
|
2014-12-19 12:14:36 +00:00
|
|
|
|
2015-01-05 14:11:42 +00:00
|
|
|
std::pair<std::string, double> initializeUnits(IfcSchema::IfcUnitAssignment*);
|
|
|
|
|
|
|
|
|
|
IfcSchema::IfcObjectDefinition* get_decomposing_entity(IfcSchema::IfcProduct*);
|
|
|
|
|
|
|
|
|
|
template <typename P>
|
|
|
|
|
IfcGeom::BRepElement<P>* create_brep_for_representation_and_product(const IteratorSettings&, IfcSchema::IfcRepresentation*, IfcSchema::IfcProduct*);
|
|
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
const SurfaceStyle* get_style(const IfcSchema::IfcRepresentationItem* representation_item);
|
2013-05-05 08:49:25 +00:00
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
template <typename T> std::pair<IfcSchema::IfcSurfaceStyle*, T*> get_surface_style(const IfcSchema::IfcRepresentationItem* representation_item) {
|
2016-01-22 17:27:28 +01:00
|
|
|
// For certain representation items, most notably boolean operands,
|
|
|
|
|
// a style definition might reside on one of its operands.
|
|
|
|
|
representation_item = find_item_carrying_style(representation_item);
|
|
|
|
|
|
2014-12-19 12:14:36 +00:00
|
|
|
IfcSchema::IfcStyledItem::list::ptr styled_items = representation_item->StyledByItem();
|
|
|
|
|
for (IfcSchema::IfcStyledItem::list::it jt = styled_items->begin(); jt != styled_items->end(); ++jt) {
|
|
|
|
|
#ifdef USE_IFC4
|
2015-05-21 12:55:54 +00:00
|
|
|
IfcEntityList::ptr style_assignments = (*jt)->Styles();
|
|
|
|
|
for (IfcEntityList::it kt = style_assignments->begin(); kt != style_assignments->end(); ++kt) {
|
2014-12-19 12:14:36 +00:00
|
|
|
if (!(*kt)->is(IfcSchema::Type::IfcPresentationStyleAssignment)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
IfcSchema::IfcPresentationStyleAssignment* style_assignment = (IfcSchema::IfcPresentationStyleAssignment*) *kt;
|
|
|
|
|
#else
|
|
|
|
|
IfcSchema::IfcPresentationStyleAssignment::list::ptr style_assignments = (*jt)->Styles();
|
|
|
|
|
for (IfcSchema::IfcPresentationStyleAssignment::list::it kt = style_assignments->begin(); kt != style_assignments->end(); ++kt) {
|
|
|
|
|
IfcSchema::IfcPresentationStyleAssignment* style_assignment = *kt;
|
|
|
|
|
#endif
|
2015-01-05 14:11:42 +00:00
|
|
|
IfcEntityList::ptr styles = style_assignment->Styles();
|
|
|
|
|
for (IfcEntityList::it lt = styles->begin(); lt != styles->end(); ++lt) {
|
|
|
|
|
IfcUtil::IfcBaseClass* style = *lt;
|
2014-12-19 12:14:36 +00:00
|
|
|
if (style->is(IfcSchema::Type::IfcSurfaceStyle)) {
|
|
|
|
|
IfcSchema::IfcSurfaceStyle* surface_style = (IfcSchema::IfcSurfaceStyle*) style;
|
|
|
|
|
if (surface_style->Side() != IfcSchema::IfcSurfaceSide::IfcSurfaceSide_NEGATIVE) {
|
2015-01-05 14:11:42 +00:00
|
|
|
IfcEntityList::ptr styles_elements = surface_style->Styles();
|
|
|
|
|
for (IfcEntityList::it mt = styles_elements->begin(); mt != styles_elements->end(); ++mt) {
|
2014-12-19 12:14:36 +00:00
|
|
|
if ((*mt)->is(T::Class())) {
|
|
|
|
|
return std::make_pair(surface_style, (T*) *mt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// StyledByItem is a SET [0:1] OF IfcStyledItem, so we
|
|
|
|
|
// break after encountering the first IfcStyledItem
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return std::make_pair<IfcSchema::IfcSurfaceStyle*, T*>(0,0);
|
2011-07-25 14:56:40 +00:00
|
|
|
}
|
2014-12-19 12:14:36 +00:00
|
|
|
|
2011-07-25 14:56:40 +00:00
|
|
|
#include "IfcRegisterGeomHeader.h"
|
2014-12-19 12:14:36 +00:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
2015-01-06 10:19:24 +00:00
|
|
|
IfcSchema::IfcProductDefinitionShape* tesselate(TopoDS_Shape& shape, double deflection, IfcEntityList::ptr es);
|
|
|
|
|
|
2011-05-08 11:04:32 +00:00
|
|
|
}
|
2011-07-25 14:56:40 +00:00
|
|
|
#endif
|