X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomAlgoAPI%2FGeomAlgoAPI_PointBuilder.cpp;h=e7414346d08c7f64a1aa29025c088ba04a39a8e0;hb=f0cec241aae9ca16d86e166f45cb5c4987d2c792;hp=a76850441fe1e14021b5613d75f9b57d5b76bd9d;hpb=98d0d390dac05b7764af10c723fd33f23665c207;p=modules%2Fshaper.git diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp index a76850441..e7414346d 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_PointBuilder.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -16,7 +17,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -65,8 +68,10 @@ std::shared_ptr GeomAlgoAPI_PointBuilder::vertexOnEdge(const std const bool theIsPercent, const bool theIsReverse) { + std::shared_ptr aVertex; + if(!theEdge.get()) { - return NULL; + return aVertex; } double aValue = theValue; @@ -78,7 +83,6 @@ std::shared_ptr GeomAlgoAPI_PointBuilder::vertexOnEdge(const std Standard_Real aUFirst, aULast; Handle(Geom_Curve) anEdgeCurve = BRep_Tool::Curve(anEdge, aUFirst, aULast); - std::shared_ptr aVertex; if(!anEdgeCurve.IsNull() ) { Handle(Geom_Curve) aReOrientedCurve = anEdgeCurve; @@ -106,25 +110,72 @@ 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 NULL; + return aVertex; } - std::shared_ptr aGeomPnt = theVertex->point(); - gp_Pnt aPnt = aGeomPnt->impl(); + std::shared_ptr aProjPnt = theVertex->point(); + std::shared_ptr aProjPln = thePlane->getPlane(); - std::shared_ptr aGeomPln = thePlane->getPlane(); - gp_Pln aPln = aGeomPln->impl(); + std::shared_ptr aPnt = aProjPln->project(aProjPnt); - gp_Dir aPntAxis = aPnt.XYZ() - aPln.Location().XYZ(); - gp_Dir aPlnNorm = aPln.Axis().Direction(); + if(!aPnt.get()) { + return aVertex; + } + + aVertex.reset(new GeomAPI_Vertex(aPnt->x(), aPnt->y(), aPnt->z())); - if(aPntAxis * aPlnNorm > 0) { - aPlnNorm.Reverse(); + 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; } - double aDistance = aPln.Distance(aPnt); - aPnt.Translate(gp_Vec(aPlnNorm) * aDistance); + std::shared_ptr aLin1 = theEdge1->line(); + std::shared_ptr aLin2 = theEdge2->line(); + + std::shared_ptr aPnt = aLin1->intersect(aLin2); + + if(!aPnt.get()) { + return aVertex; + } - return std::shared_ptr(new GeomAPI_Vertex(aPnt.X(), aPnt.Y(), aPnt.Z())); + 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; }