1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomAlgoAPI_PointBuilder.cpp
4 // Created: 02 Jun 2014
5 // Author: Mikhail PONIKAROV
7 #include "GeomAlgoAPI_PointBuilder.h"
9 #include <GeomAPI_Edge.h>
10 #include <GeomAPI_Face.h>
11 #include <GeomAPI_Pln.h>
12 #include <GeomAPI_Pnt.h>
13 #include <GeomAPI_Shape.h>
14 #include <GeomAPI_Vertex.h>
16 #include <BRep_Tool.hxx>
17 #include <BRepBuilderAPI_MakeVertex.hxx>
18 #include <GCPnts_AbscissaPoint.hxx>
19 #include <GeomAdaptor_Curve.hxx>
23 #include <TopoDS_Vertex.hxx>
25 //==================================================================================================
26 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertex(const std::shared_ptr<GeomAPI_Pnt> thePoint)
28 const gp_Pnt& aPnt = thePoint->impl<gp_Pnt>();
29 BRepBuilderAPI_MakeVertex aMaker(aPnt);
30 TopoDS_Vertex aVertex = aMaker.Vertex();
31 std::shared_ptr<GeomAPI_Vertex> aRes(new GeomAPI_Vertex);
32 aRes->setImpl(new TopoDS_Shape(aVertex));
36 //==================================================================================================
37 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertex(const double theX,
41 const gp_Pnt aPnt(theX, theY, theZ);
42 BRepBuilderAPI_MakeVertex aMaker(aPnt);
43 TopoDS_Vertex aVertex = aMaker.Vertex();
44 std::shared_ptr<GeomAPI_Vertex> aRes(new GeomAPI_Vertex);
45 aRes->setImpl(new TopoDS_Shape(aVertex));
49 //==================================================================================================
50 std::shared_ptr<GeomAPI_Pnt> GeomAlgoAPI_PointBuilder::point(const std::shared_ptr<GeomAPI_Shape> theVertex)
52 TopoDS_Shape aShape = theVertex->impl<TopoDS_Shape>();
53 if ((!aShape.IsNull()) && (aShape.ShapeType() == TopAbs_VERTEX)) {
54 TopoDS_Vertex aVertex = TopoDS::Vertex(aShape);
55 gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
56 std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
59 return std::shared_ptr<GeomAPI_Pnt>();
62 //==================================================================================================
63 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexOnEdge(const std::shared_ptr<GeomAPI_Edge> theEdge,
64 const double theValue,
65 const bool theIsPercent,
66 const bool theIsReverse)
72 double aValue = theValue;
74 aValue = theEdge->length() / 100.0 * aValue;
77 const TopoDS_Edge& anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
78 Standard_Real aUFirst, aULast;
79 Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, aUFirst, aULast);
81 std::shared_ptr<GeomAPI_Vertex> aVertex;
82 if(!anEdgeCurve.IsNull() ) {
83 Handle(Geom_Curve) aReOrientedCurve = anEdgeCurve;
86 aReOrientedCurve = anEdgeCurve->Reversed();
87 aUFirst = anEdgeCurve->ReversedParameter(aULast);
90 // Get the point by length
91 GeomAdaptor_Curve anAdapCurve = GeomAdaptor_Curve(aReOrientedCurve);
92 GCPnts_AbscissaPoint anAbsPnt(anAdapCurve, aValue, aUFirst);
93 Standard_Real aParam = anAbsPnt.Parameter();
94 gp_Pnt aPnt = anAdapCurve.Value(aParam);
95 BRepBuilderAPI_MakeVertex aMkVertex(aPnt);
96 const TopoDS_Vertex& aShape = aMkVertex.Vertex();
97 aVertex.reset(new GeomAPI_Vertex());
98 aVertex->setImpl(new TopoDS_Vertex(aShape));
104 //==================================================================================================
105 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByProjection(
106 const std::shared_ptr<GeomAPI_Vertex> theVertex,
107 const std::shared_ptr<GeomAPI_Face> thePlane)
109 if(!theVertex.get() || !thePlane.get() || !thePlane->isPlanar()) {
113 std::shared_ptr<GeomAPI_Pnt> aGeomPnt = theVertex->point();
114 gp_Pnt aPnt = aGeomPnt->impl<gp_Pnt>();
116 std::shared_ptr<GeomAPI_Pln> aGeomPln = thePlane->getPlane();
117 gp_Pln aPln = aGeomPln->impl<gp_Pln>();
119 gp_Dir aPntAxis = aPnt.XYZ() - aPln.Location().XYZ();
120 gp_Dir aPlnNorm = aPln.Axis().Direction();
122 if(aPntAxis * aPlnNorm > 0) {
126 double aDistance = aPln.Distance(aPnt);
127 aPnt.Translate(gp_Vec(aPlnNorm) * aDistance);
129 return std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex(aPnt.X(), aPnt.Y(), aPnt.Z()));