1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAPI_Face.cpp
5 // Author: Artem ZHIDKOV
7 #include <GeomAPI_Face.h>
8 #include <GeomAPI_Dir.h>
9 #include <GeomAPI_Pln.h>
10 #include <GeomAPI_Pnt.h>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Face.hxx>
15 #include <BRep_Tool.hxx>
16 #include <BRepAdaptor_Surface.hxx>
17 #include <Geom_Surface.hxx>
18 #include <Geom_Plane.hxx>
19 #include <Geom_CylindricalSurface.hxx>
20 #include <GeomLib_IsPlanarSurface.hxx>
22 GeomAPI_Face::GeomAPI_Face()
27 GeomAPI_Face::GeomAPI_Face(const std::shared_ptr<GeomAPI_Shape>& theShape)
29 if (!theShape->isNull() && theShape->isFace()) {
30 setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
34 bool GeomAPI_Face::isEqual(std::shared_ptr<GeomAPI_Shape> theFace) const
36 if (!theFace->isFace())
39 const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
40 const TopoDS_Shape& aInShape = theFace->impl<TopoDS_Shape>();
42 Handle(Geom_Surface) aMySurf = BRep_Tool::Surface(TopoDS::Face(aMyShape));
43 Handle(Geom_Surface) aInSurf = BRep_Tool::Surface(TopoDS::Face(aInShape));
45 // Check that surfaces a the same type
46 if (aMySurf->DynamicType() != aInSurf->DynamicType())
49 // Get parameters of surfaces
50 double aMyUMin, aMyUMax, aMyVMin, aMyVMax;
51 aMySurf->Bounds(aMyUMin, aMyUMax, aMyVMin, aMyVMax);
52 double aInUMin, aInUMax, aInVMin, aInVMax;
53 aInSurf->Bounds(aInUMin, aInUMax, aInVMin, aInVMax);
55 // Check that parameters are the same
56 if (fabs(aMyUMin - aInUMin) > Precision::PConfusion() ||
57 fabs(aMyUMax - aInUMax) > Precision::PConfusion() ||
58 fabs(aMyVMin - aInVMin) > Precision::PConfusion() ||
59 fabs(aMyVMax - aInVMax) > Precision::PConfusion())
65 bool GeomAPI_Face::isPlanar() const
67 const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
68 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
69 GeomLib_IsPlanarSurface isPlanar(aSurf);
70 return isPlanar.IsPlanar() == Standard_True;
73 bool GeomAPI_Face::isCylindrical() const
75 const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
76 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
77 return aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface)) == Standard_True;
80 std::shared_ptr<GeomAPI_Pln> GeomAPI_Face::getPlane() const
82 const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
83 BRepAdaptor_Surface aSurfAdapt(TopoDS::Face(aShape));
85 if (aSurfAdapt.GetType() != GeomAbs_Plane)
86 return std::shared_ptr<GeomAPI_Pln>();
88 // Obtain central point
89 double aUMin, aUMax, aVMin, aVMax;
90 aUMin = aSurfAdapt.FirstUParameter();
91 aUMax = aSurfAdapt.LastUParameter();
92 aVMin = aSurfAdapt.FirstVParameter();
93 aVMax = aSurfAdapt.LastVParameter();
96 aSurfAdapt.D1((aUMin+aUMax)*0.5, (aVMin+aVMax)*0.5, aCentralPnt, aDU, aDV);
97 std::shared_ptr<GeomAPI_Pnt> aCenter(
98 new GeomAPI_Pnt(aCentralPnt.X(), aCentralPnt.Y(), aCentralPnt.Z()));
100 // Obtain plane direction
101 gp_XYZ aNormalVec = aDU.XYZ().Crossed(aDV.XYZ());
102 if (aNormalVec.SquareModulus() < Precision::Confusion() * Precision::Confusion())
103 return std::shared_ptr<GeomAPI_Pln>();
104 std::shared_ptr<GeomAPI_Dir> aNormal(
105 new GeomAPI_Dir(aNormalVec.X(), aNormalVec.Y(), aNormalVec.Z()));
107 std::shared_ptr<GeomAPI_Pln> aResult(new GeomAPI_Pln(aCenter, aNormal));