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_Lin.h>
12 #include <GeomAPI_Pln.h>
13 #include <GeomAPI_Pnt.h>
14 #include <GeomAPI_Shape.h>
15 #include <GeomAPI_Vertex.h>
17 #include <BRep_Tool.hxx>
18 #include <BRepBuilderAPI_MakeVertex.hxx>
19 #include <GCPnts_AbscissaPoint.hxx>
20 #include <Geom_Line.hxx>
21 #include <GeomAdaptor_Curve.hxx>
22 #include <GeomAPI_ExtremaCurveCurve.hxx>
26 #include <TopoDS_Vertex.hxx>
28 //==================================================================================================
29 std::shared_ptr<GeomAPI_Vertex>
30 GeomAlgoAPI_PointBuilder::vertex(const std::shared_ptr<GeomAPI_Pnt> thePoint)
32 const gp_Pnt& aPnt = thePoint->impl<gp_Pnt>();
33 BRepBuilderAPI_MakeVertex aMaker(aPnt);
34 TopoDS_Vertex aVertex = aMaker.Vertex();
35 std::shared_ptr<GeomAPI_Vertex> aRes(new GeomAPI_Vertex);
36 aRes->setImpl(new TopoDS_Shape(aVertex));
40 //==================================================================================================
41 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertex(const double theX,
45 const gp_Pnt aPnt(theX, theY, theZ);
46 BRepBuilderAPI_MakeVertex aMaker(aPnt);
47 TopoDS_Vertex aVertex = aMaker.Vertex();
48 std::shared_ptr<GeomAPI_Vertex> aRes(new GeomAPI_Vertex);
49 aRes->setImpl(new TopoDS_Shape(aVertex));
53 //==================================================================================================
54 std::shared_ptr<GeomAPI_Pnt>
55 GeomAlgoAPI_PointBuilder::point(const std::shared_ptr<GeomAPI_Shape> theVertex)
57 TopoDS_Shape aShape = theVertex->impl<TopoDS_Shape>();
58 if ((!aShape.IsNull()) && (aShape.ShapeType() == TopAbs_VERTEX)) {
59 TopoDS_Vertex aVertex = TopoDS::Vertex(aShape);
60 gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
61 std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
64 return std::shared_ptr<GeomAPI_Pnt>();
67 //==================================================================================================
68 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexOnEdge(
69 const std::shared_ptr<GeomAPI_Edge> theEdge,
70 const double theValue,
71 const bool theIsPercent,
72 const bool theIsReverse)
74 std::shared_ptr<GeomAPI_Vertex> aVertex;
80 double aValue = theValue;
82 aValue = theEdge->length() / 100.0 * aValue;
85 const TopoDS_Edge& anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
86 Standard_Real aUFirst, aULast;
87 Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, aUFirst, aULast);
89 if(!anEdgeCurve.IsNull() ) {
90 Handle(Geom_Curve) aReOrientedCurve = anEdgeCurve;
93 aReOrientedCurve = anEdgeCurve->Reversed();
94 aUFirst = anEdgeCurve->ReversedParameter(aULast);
97 // Get the point by length
98 GeomAdaptor_Curve anAdapCurve = GeomAdaptor_Curve(aReOrientedCurve);
99 GCPnts_AbscissaPoint anAbsPnt(anAdapCurve, aValue, aUFirst);
100 Standard_Real aParam = anAbsPnt.Parameter();
101 gp_Pnt aPnt = anAdapCurve.Value(aParam);
102 BRepBuilderAPI_MakeVertex aMkVertex(aPnt);
103 const TopoDS_Vertex& aShape = aMkVertex.Vertex();
104 aVertex.reset(new GeomAPI_Vertex());
105 aVertex->setImpl(new TopoDS_Vertex(aShape));
111 //==================================================================================================
112 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByProjection(
113 const std::shared_ptr<GeomAPI_Vertex> theVertex,
114 const std::shared_ptr<GeomAPI_Face> thePlane)
116 std::shared_ptr<GeomAPI_Vertex> aVertex;
118 if(!theVertex.get() || !thePlane.get() || !thePlane->isPlanar()) {
122 std::shared_ptr<GeomAPI_Pnt> aProjPnt = theVertex->point();
123 std::shared_ptr<GeomAPI_Pln> aProjPln = thePlane->getPlane();
125 std::shared_ptr<GeomAPI_Pnt> aPnt = aProjPln->project(aProjPnt);
131 aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));
136 //==================================================================================================
137 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByIntersection(
138 const std::shared_ptr<GeomAPI_Edge> theEdge1,
139 const std::shared_ptr<GeomAPI_Edge> theEdge2)
141 std::shared_ptr<GeomAPI_Vertex> aVertex;
143 if(!theEdge1.get() || !theEdge2.get() || !theEdge1->isLine() || !theEdge2->isLine()) {
147 std::shared_ptr<GeomAPI_Lin> aLin1 = theEdge1->line();
148 std::shared_ptr<GeomAPI_Lin> aLin2 = theEdge2->line();
150 std::shared_ptr<GeomAPI_Pnt> aPnt = aLin1->intersect(aLin2);
156 aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));
161 //==================================================================================================
162 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByIntersection(
163 const std::shared_ptr<GeomAPI_Edge> theEdge,
164 const std::shared_ptr<GeomAPI_Face> theFace)
166 std::shared_ptr<GeomAPI_Vertex> aVertex;
168 if(!theEdge.get() || !theFace.get() || !theEdge->isLine() || !theFace->isPlanar()) {
172 std::shared_ptr<GeomAPI_Lin> aLin = theEdge->line();
173 std::shared_ptr<GeomAPI_Pln> aPln = theFace->getPlane();
175 std::shared_ptr<GeomAPI_Pnt> aPnt = aPln->intersect(aLin);
181 aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));