X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_PointBuilder.cpp;h=e7414346d08c7f64a1aa29025c088ba04a39a8e0;hb=f0cec241aae9ca16d86e166f45cb5c4987d2c792;hp=f57605c8c4fe2ee37f078ab46f0ea545f8d7d5e5;hpb=7bf19255421b34594c7b0a76d0ce28166d0ce895;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp index f57605c8c..e7414346d 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp @@ -4,28 +4,53 @@ // Created: 02 Jun 2014 // Author: Mikhail PONIKAROV -#include +#include "GeomAlgoAPI_PointBuilder.h" + +#include +#include +#include +#include #include #include -#include +#include + #include -#include -#include +#include +#include +#include +#include +#include +#include #include +#include +#include -std::shared_ptr GeomAlgoAPI_PointBuilder::point( - std::shared_ptr thePoint) +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::vertex(const std::shared_ptr thePoint) { const gp_Pnt& aPnt = thePoint->impl(); BRepBuilderAPI_MakeVertex aMaker(aPnt); TopoDS_Vertex aVertex = aMaker.Vertex(); - std::shared_ptr aRes(new GeomAPI_Shape); + std::shared_ptr aRes(new GeomAPI_Vertex); aRes->setImpl(new TopoDS_Shape(aVertex)); return aRes; } +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::vertex(const double theX, + const double theY, + const double theZ) +{ + const gp_Pnt aPnt(theX, theY, theZ); + BRepBuilderAPI_MakeVertex aMaker(aPnt); + TopoDS_Vertex aVertex = aMaker.Vertex(); + std::shared_ptr aRes(new GeomAPI_Vertex); + aRes->setImpl(new TopoDS_Shape(aVertex)); + return aRes; +} -std::shared_ptr GeomAlgoAPI_PointBuilder::point(std::shared_ptr theVertex) +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::point(const std::shared_ptr theVertex) { TopoDS_Shape aShape = theVertex->impl(); if ((!aShape.IsNull()) && (aShape.ShapeType() == TopAbs_VERTEX)) { @@ -36,3 +61,121 @@ std::shared_ptr GeomAlgoAPI_PointBuilder::point(std::shared_ptr(); } + +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::vertexOnEdge(const std::shared_ptr theEdge, + const double theValue, + const bool theIsPercent, + const bool theIsReverse) +{ + std::shared_ptr aVertex; + + if(!theEdge.get()) { + return aVertex; + } + + double aValue = theValue; + if(theIsPercent) { + aValue = theEdge->length() / 100.0 * aValue; + } + + const TopoDS_Edge& anEdge = TopoDS::Edge(theEdge->impl()); + Standard_Real aUFirst, aULast; + Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, aUFirst, aULast); + + if(!anEdgeCurve.IsNull() ) { + Handle(Geom_Curve) aReOrientedCurve = anEdgeCurve; + + if(theIsReverse) { + aReOrientedCurve = anEdgeCurve->Reversed(); + aUFirst = anEdgeCurve->ReversedParameter(aULast); + } + + // Get the point by length + GeomAdaptor_Curve anAdapCurve = GeomAdaptor_Curve(aReOrientedCurve); + GCPnts_AbscissaPoint anAbsPnt(anAdapCurve, aValue, aUFirst); + Standard_Real aParam = anAbsPnt.Parameter(); + gp_Pnt aPnt = anAdapCurve.Value(aParam); + BRepBuilderAPI_MakeVertex aMkVertex(aPnt); + const TopoDS_Vertex& aShape = aMkVertex.Vertex(); + aVertex.reset(new GeomAPI_Vertex()); + aVertex->setImpl(new TopoDS_Vertex(aShape)); + } + + return aVertex; +} + +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::vertexByProjection( + const std::shared_ptr theVertex, + const std::shared_ptr thePlane) +{ + std::shared_ptr aVertex; + + if(!theVertex.get() || !thePlane.get() || !thePlane->isPlanar()) { + return aVertex; + } + + std::shared_ptr aProjPnt = theVertex->point(); + std::shared_ptr aProjPln = thePlane->getPlane(); + + std::shared_ptr aPnt = aProjPln->project(aProjPnt); + + if(!aPnt.get()) { + return aVertex; + } + + aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); + + return aVertex; +} + +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::vertexByIntersection( + const std::shared_ptr theEdge1, + const std::shared_ptr theEdge2) +{ + std::shared_ptr aVertex; + + if(!theEdge1.get() || !theEdge2.get() || !theEdge1->isLine() || !theEdge2->isLine()) { + return aVertex; + } + + std::shared_ptr aLin1 = theEdge1->line(); + std::shared_ptr aLin2 = theEdge2->line(); + + std::shared_ptr aPnt = aLin1->intersect(aLin2); + + if(!aPnt.get()) { + return aVertex; + } + + aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); + + return aVertex; +} + +//================================================================================================== +std::shared_ptr GeomAlgoAPI_PointBuilder::vertexByIntersection( + const std::shared_ptr theEdge, + const std::shared_ptr theFace) +{ + std::shared_ptr aVertex; + + if(!theEdge.get() || !theFace.get() || !theEdge->isLine() || !theFace->isPlanar()) { + return aVertex; + } + + std::shared_ptr aLin = theEdge->line(); + std::shared_ptr aPln = theFace->getPlane(); + + std::shared_ptr aPnt = aPln->intersect(aLin); + + if(!aPnt.get()) { + return aVertex; + } + + aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); + + return aVertex; +}