1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "GeomAlgoAPI_PointBuilder.h"
23 #include <GeomAPI_Edge.h>
24 #include <GeomAPI_Face.h>
25 #include <GeomAPI_Lin.h>
26 #include <GeomAPI_Pln.h>
27 #include <GeomAPI_Pnt.h>
28 #include <GeomAPI_Shape.h>
29 #include <GeomAPI_Vertex.h>
31 #include <BRep_Tool.hxx>
32 #include <BRepBuilderAPI_MakeVertex.hxx>
33 #include <GCPnts_AbscissaPoint.hxx>
34 #include <Geom_Line.hxx>
35 #include <GeomAdaptor_Curve.hxx>
36 #include <GeomAPI_ExtremaCurveCurve.hxx>
40 #include <TopoDS_Vertex.hxx>
42 //==================================================================================================
43 std::shared_ptr<GeomAPI_Vertex>
44 GeomAlgoAPI_PointBuilder::vertex(const std::shared_ptr<GeomAPI_Pnt> thePoint)
46 const gp_Pnt& aPnt = thePoint->impl<gp_Pnt>();
47 BRepBuilderAPI_MakeVertex aMaker(aPnt);
48 TopoDS_Vertex aVertex = aMaker.Vertex();
49 std::shared_ptr<GeomAPI_Vertex> aRes(new GeomAPI_Vertex);
50 aRes->setImpl(new TopoDS_Shape(aVertex));
54 //==================================================================================================
55 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertex(const double theX,
59 const gp_Pnt aPnt(theX, theY, theZ);
60 BRepBuilderAPI_MakeVertex aMaker(aPnt);
61 TopoDS_Vertex aVertex = aMaker.Vertex();
62 std::shared_ptr<GeomAPI_Vertex> aRes(new GeomAPI_Vertex);
63 aRes->setImpl(new TopoDS_Shape(aVertex));
67 //==================================================================================================
68 std::shared_ptr<GeomAPI_Pnt>
69 GeomAlgoAPI_PointBuilder::point(const std::shared_ptr<GeomAPI_Shape> theVertex)
71 TopoDS_Shape aShape = theVertex->impl<TopoDS_Shape>();
72 if ((!aShape.IsNull()) && (aShape.ShapeType() == TopAbs_VERTEX)) {
73 TopoDS_Vertex aVertex = TopoDS::Vertex(aShape);
74 gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
75 std::shared_ptr<GeomAPI_Pnt> aPnt(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
78 return std::shared_ptr<GeomAPI_Pnt>();
81 //==================================================================================================
82 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexOnEdge(
83 const std::shared_ptr<GeomAPI_Edge> theEdge,
84 const double theValue,
85 const bool theIsPercent,
86 const bool theIsReverse)
88 std::shared_ptr<GeomAPI_Vertex> aVertex;
94 double aValue = theValue;
96 aValue = theEdge->length() / 100.0 * aValue;
99 const TopoDS_Edge& anEdge = TopoDS::Edge(theEdge->impl<TopoDS_Shape>());
100 Standard_Real aUFirst, aULast;
101 Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, aUFirst, aULast);
103 if(!anEdgeCurve.IsNull() ) {
104 Handle(Geom_Curve) aReOrientedCurve = anEdgeCurve;
107 aReOrientedCurve = anEdgeCurve->Reversed();
108 aUFirst = anEdgeCurve->ReversedParameter(aULast);
111 // Get the point by length
112 GeomAdaptor_Curve anAdapCurve = GeomAdaptor_Curve(aReOrientedCurve);
113 GCPnts_AbscissaPoint anAbsPnt(anAdapCurve, aValue, aUFirst);
114 Standard_Real aParam = anAbsPnt.Parameter();
115 gp_Pnt aPnt = anAdapCurve.Value(aParam);
116 BRepBuilderAPI_MakeVertex aMkVertex(aPnt);
117 const TopoDS_Vertex& aShape = aMkVertex.Vertex();
118 aVertex.reset(new GeomAPI_Vertex());
119 aVertex->setImpl(new TopoDS_Vertex(aShape));
125 //==================================================================================================
126 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByProjection(
127 const std::shared_ptr<GeomAPI_Vertex> theVertex,
128 const std::shared_ptr<GeomAPI_Face> thePlane)
130 std::shared_ptr<GeomAPI_Vertex> aVertex;
132 if(!theVertex.get() || !thePlane.get() || !thePlane->isPlanar()) {
136 std::shared_ptr<GeomAPI_Pnt> aProjPnt = theVertex->point();
137 std::shared_ptr<GeomAPI_Pln> aProjPln = thePlane->getPlane();
139 std::shared_ptr<GeomAPI_Pnt> aPnt = aProjPln->project(aProjPnt);
145 aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));
150 //==================================================================================================
151 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByIntersection(
152 const std::shared_ptr<GeomAPI_Edge> theEdge1,
153 const std::shared_ptr<GeomAPI_Edge> theEdge2)
155 std::shared_ptr<GeomAPI_Vertex> aVertex;
157 if(!theEdge1.get() || !theEdge2.get() || !theEdge1->isLine() || !theEdge2->isLine()) {
161 std::shared_ptr<GeomAPI_Lin> aLin1 = theEdge1->line();
162 std::shared_ptr<GeomAPI_Lin> aLin2 = theEdge2->line();
164 std::shared_ptr<GeomAPI_Pnt> aPnt = aLin1->intersect(aLin2);
170 aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));
175 //==================================================================================================
176 std::shared_ptr<GeomAPI_Vertex> GeomAlgoAPI_PointBuilder::vertexByIntersection(
177 const std::shared_ptr<GeomAPI_Edge> theEdge,
178 const std::shared_ptr<GeomAPI_Face> theFace)
180 std::shared_ptr<GeomAPI_Vertex> aVertex;
182 if(!theEdge.get() || !theFace.get() || !theEdge->isLine() || !theFace->isPlanar()) {
186 std::shared_ptr<GeomAPI_Lin> aLin = theEdge->line();
187 std::shared_ptr<GeomAPI_Pln> aPln = theFace->getPlane();
189 std::shared_ptr<GeomAPI_Pnt> aPnt = aPln->intersect(aLin);
195 aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z()));