X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FGeomAPI%2FGeomAPI_Lin.cpp;h=d3f44a404aedef61c6d26e1c8625bf2a247f79d6;hb=31a11bcc6eb89d2f4eab7b6b782f16bb0b6f754b;hp=9d040702438eb7018cd74c4e77938f55fe3c11a9;hpb=81dad1acf409fa5e71090501bc1aa7e0b7d80cde;p=modules%2Fshaper.git diff --git a/src/GeomAPI/GeomAPI_Lin.cpp b/src/GeomAPI/GeomAPI_Lin.cpp index 9d0407024..d3f44a404 100644 --- a/src/GeomAPI/GeomAPI_Lin.cpp +++ b/src/GeomAPI/GeomAPI_Lin.cpp @@ -1,9 +1,26 @@ -// File: GeomAPI_Lin.cpp -// Created: 29 May 2014 -// Author: Artem ZHIDKOV +// Copyright (C) 2014-2017 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or +// email : webmaster.salome@opencascade.com +// #include #include +#include #include #include @@ -17,65 +34,119 @@ #include #include -#define MY_LIN static_cast(myImpl) +#define MY_LIN implPtr() static gp_Lin* newLine(const double theStartX, const double theStartY, const double theStartZ, - const double theEndX, const double theEndY, const double theEndZ) + const double theEndX, const double theEndY, const double theEndZ) { gp_XYZ aDir(theEndX - theStartX, theEndY - theStartY, theEndZ - theStartZ); gp_Pnt aStart(theStartX, theStartY, theStartZ); return new gp_Lin(aStart, gp_Dir(aDir)); } - GeomAPI_Lin::GeomAPI_Lin(const double theStartX, const double theStartY, const double theStartZ, - const double theEndX, const double theEndY, const double theEndZ) - : GeomAPI_Interface(newLine(theStartX, theStartY, theStartZ, theEndX, theEndY, theEndZ)) -{} + const double theEndX, const double theEndY, const double theEndZ) + : GeomAPI_Interface(newLine(theStartX, theStartY, theStartZ, theEndX, theEndY, theEndZ)) +{ +} + +GeomAPI_Lin::GeomAPI_Lin(const std::shared_ptr& theStart, + const std::shared_ptr& theEnd) + : GeomAPI_Interface( + newLine(theStart->x(), theStart->y(), theStart->z(), theEnd->x(), theEnd->y(), theEnd->z())) +{ +} + +GeomAPI_Lin::GeomAPI_Lin(const std::shared_ptr& theOrigin, + const std::shared_ptr& theDirection) + : GeomAPI_Interface(newLine(theOrigin->x(), theOrigin->y(), theOrigin->z(), + theOrigin->x() + theDirection->x(), + theOrigin->y() + theDirection->y(), + theOrigin->z() + theDirection->z())) +{ +} -GeomAPI_Lin::GeomAPI_Lin(const boost::shared_ptr& theStart, - const boost::shared_ptr& theEnd) - : GeomAPI_Interface(newLine(theStart->x(), theStart->y(), theStart->z(), - theEnd->x(), theEnd->y(), theEnd->z())) -{} +std::shared_ptr GeomAPI_Lin::location() +{ + gp_Pnt aLoc = impl().Location(); + return std::shared_ptr(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z())); +} + +std::shared_ptr GeomAPI_Lin::direction() +{ + const gp_Dir& aDir = impl().Direction(); + return std::shared_ptr(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z())); +} -double GeomAPI_Lin::distance(const boost::shared_ptr& thePoint) const +double GeomAPI_Lin::distance(const std::shared_ptr& thePoint) const { return MY_LIN->Distance(thePoint->impl()); } -const boost::shared_ptr GeomAPI_Lin::intersect( - const boost::shared_ptr& theLine) const +const std::shared_ptr GeomAPI_Lin::intersect( + const std::shared_ptr& theLine) const { if (MY_LIN->SquareDistance(theLine->impl()) > Precision::Confusion()) - return boost::shared_ptr(); + return std::shared_ptr(); const gp_Dir& aDir1 = MY_LIN->Direction(); const gp_Dir& aDir2 = theLine->impl().Direction(); gp_Dir aCross = aDir1.Crossed(aDir2); - gp_Pln aPlane(MY_LIN->Location(), aCross); // plane containing both lines + gp_Pln aPlane(MY_LIN->Location(), aCross); // plane containing both lines gp_Lin2d aPrjLine1 = ProjLib::Project(aPlane, *MY_LIN); gp_Lin2d aPrjLine2 = ProjLib::Project(aPlane, theLine->impl()); - IntAna2d_AnaIntersection anInter(aPrjLine1, aPrjLine1); + IntAna2d_AnaIntersection anInter(aPrjLine1, aPrjLine2); if (!anInter.IsDone() || anInter.IsEmpty()) - return boost::shared_ptr(); - const gp_Pnt2d& anIntPnt2d = anInter.Point(0).Value(); + return std::shared_ptr(); + const gp_Pnt2d& anIntPnt2d = anInter.Point(1).Value(); gp_Pnt aResult = ElSLib::Value(anIntPnt2d.X(), anIntPnt2d.Y(), aPlane); - return boost::shared_ptr( - new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z())); + return std::shared_ptr( + new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z())); } -const boost::shared_ptr GeomAPI_Lin::project(const boost::shared_ptr& thePoint) const +double GeomAPI_Lin::projParam( + const std::shared_ptr& thePoint) const { const gp_XYZ& aDir = MY_LIN->Direction().XYZ(); const gp_XYZ& aLoc = MY_LIN->Location().XYZ(); const gp_XYZ& aPnt = thePoint->impl().XYZ(); - double aParam = aDir.Dot(aPnt - aLoc); + return aDir.Dot(aPnt - aLoc); +} + +const std::shared_ptr GeomAPI_Lin::project( + const std::shared_ptr& thePoint) const +{ + const gp_XYZ& aDir = MY_LIN->Direction().XYZ(); + const gp_XYZ& aLoc = MY_LIN->Location().XYZ(); + double aParam = projParam(thePoint); + gp_XYZ aResult = aLoc + aDir * aParam; + return std::shared_ptr(new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z())); +} + +bool GeomAPI_Lin::contains(const std::shared_ptr thePoint, + const double theLinearTolerance) const +{ + if(!thePoint.get()) { + return false; + } + + return MY_LIN->Contains(thePoint->impl(), theLinearTolerance) == Standard_True; +} - gp_XYZ aResult = aPnt + aDir * aParam; - return boost::shared_ptr(new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z())); +bool GeomAPI_Lin::isParallel(const std::shared_ptr theLin) const +{ + return MY_LIN->Direction().IsParallel(theLin->impl().Direction(), + Precision::Confusion()) == Standard_True; } +bool GeomAPI_Lin::isCoplanar(const std::shared_ptr theLin) const +{ + if(MY_LIN->SquareDistance(theLin->impl()) > Precision::Confusion()) { + return false; + } + + return true; +}