1 // File: GeomAPI_Face.cpp
3 // Author: Artem ZHIDKOV
5 #include <GeomAPI_Face.h>
6 #include <GeomAPI_Dir.h>
7 #include <GeomAPI_Pln.h>
8 #include <GeomAPI_Pnt.h>
10 #include <TopoDS_Shape.hxx>
11 #include <TopoDS_Face.hxx>
13 #include <BRep_Tool.hxx>
14 #include <Geom_Surface.hxx>
15 #include <Geom_Plane.hxx>
17 GeomAPI_Face::GeomAPI_Face()
22 GeomAPI_Face::GeomAPI_Face(const std::shared_ptr<GeomAPI_Shape>& theShape)
24 if (!theShape->isNull() && theShape->isFace()) {
25 setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
29 bool GeomAPI_Face::isEqual(std::shared_ptr<GeomAPI_Shape> theFace) const
31 if (!theFace->isFace())
34 const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
35 const TopoDS_Shape& aInShape = theFace->impl<TopoDS_Shape>();
37 Handle(Geom_Surface) aMySurf = BRep_Tool::Surface(TopoDS::Face(aMyShape));
38 Handle(Geom_Surface) aInSurf = BRep_Tool::Surface(TopoDS::Face(aInShape));
40 // Check that surfaces a the same type
41 if (aMySurf->DynamicType() != aInSurf->DynamicType())
44 // Get parameters of surfaces
45 double aMyUMin, aMyUMax, aMyVMin, aMyVMax;
46 aMySurf->Bounds(aMyUMin, aMyUMax, aMyVMin, aMyVMax);
47 double aInUMin, aInUMax, aInVMin, aInVMax;
48 aInSurf->Bounds(aInUMin, aInUMax, aInVMin, aInVMax);
50 // Check that parameters are the same
51 if (fabs(aMyUMin - aInUMin) > Precision::PConfusion() ||
52 fabs(aMyUMax - aInUMax) > Precision::PConfusion() ||
53 fabs(aMyVMin - aInVMin) > Precision::PConfusion() ||
54 fabs(aMyVMax - aInVMax) > Precision::PConfusion())
60 bool GeomAPI_Face::isPlanar() const
62 const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
63 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
64 if (aSurf->IsKind(STANDARD_TYPE(Geom_Plane)))
69 std::shared_ptr<GeomAPI_Pln> GeomAPI_Face::getPlane() const
71 const TopoDS_Shape& aShape = const_cast<GeomAPI_Face*>(this)->impl<TopoDS_Shape>();
72 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aShape));
74 if (!aSurf->IsKind(STANDARD_TYPE(Geom_Plane)))
75 return std::shared_ptr<GeomAPI_Pln>();
77 // Obtain central point
78 double aUMin, aUMax, aVMin, aVMax;
79 aSurf->Bounds(aUMin, aUMax, aVMin, aVMax);
82 aSurf->D1((aUMin+aUMax)*0.5, (aVMin+aVMax)*0.5, aCentralPnt, aDU, aDV);
83 std::shared_ptr<GeomAPI_Pnt> aCenter(
84 new GeomAPI_Pnt(aCentralPnt.X(), aCentralPnt.Y(), aCentralPnt.Z()));
86 // Obtain plane direction
87 gp_XYZ aNormalVec = aDU.XYZ().Crossed(aDV.XYZ());
88 if (aNormalVec.SquareModulus() < Precision::Confusion() * Precision::Confusion())
89 return std::shared_ptr<GeomAPI_Pln>();
90 std::shared_ptr<GeomAPI_Dir> aNormal(
91 new GeomAPI_Dir(aNormalVec.X(), aNormalVec.Y(), aNormalVec.Z()));
93 std::shared_ptr<GeomAPI_Pln> aResult(new GeomAPI_Pln(aCenter, aNormal));