From: azv Date: Thu, 29 May 2014 13:57:56 +0000 (+0400) Subject: Added new geometrical objects X-Git-Tag: V_0.4.4~338^2~1^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8f2fef811ec343cd840bef38e56f3658178f442c;p=modules%2Fshaper.git Added new geometrical objects --- diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index 142a02bb4..cf21d319f 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -9,6 +9,9 @@ SET(PROJECT_HEADERS GeomAPI_Interface.h GeomAPI_XYZ.h GeomAPI_Pnt.h + GeomAPI_Pnt2d.h + GeomAPI_Lin.h + GeomAPI_Lin2d.h GeomAPI_Dir.h GeomAPI_Pln.h GeomAPI_Shape.h @@ -18,6 +21,9 @@ SET(PROJECT_SOURCES GeomAPI_Interface.cpp GeomAPI_XYZ.cpp GeomAPI_Pnt.cpp + GeomAPI_Pnt2d.cpp + GeomAPI_Lin.cpp + GeomAPI_Lin2d.cpp GeomAPI_Dir.cpp GeomAPI_Pln.cpp GeomAPI_Shape.cpp @@ -35,7 +41,7 @@ INCLUDE_DIRECTORIES( ${CAS_INCLUDE_DIRS} ) -TARGET_LINK_LIBRARIES(GeomAPI ${PROJECT_LIBRARIES} ${CAS_KERNEL}) +TARGET_LINK_LIBRARIES(GeomAPI ${PROJECT_LIBRARIES} ${CAS_KERNEL} ${CAS_MODELER}) SET(SWIG_SCRIPTS ${CMAKE_CURRENT_BINARY_DIR}/GeomAPI.py diff --git a/src/GeomAPI/GeomAPI_Dir.cpp b/src/GeomAPI/GeomAPI_Dir.cpp index 6e8ea2429..c3ad12fb9 100644 --- a/src/GeomAPI/GeomAPI_Dir.cpp +++ b/src/GeomAPI/GeomAPI_Dir.cpp @@ -7,12 +7,16 @@ #include -#define MY_DIR static_cast(myImpl) +#define MY_DIR static_cast(myImpl) GeomAPI_Dir::GeomAPI_Dir(const double theX, const double theY, const double theZ) : GeomAPI_Interface(new gp_Dir(theX, theY, theZ)) {} +GeomAPI_Dir::GeomAPI_Dir(const boost::shared_ptr& theCoords) + : GeomAPI_Interface(new gp_Dir(theCoords->x(), theCoords->y(), theCoords->z())) +{} + double GeomAPI_Dir::x() const { return MY_DIR->X(); diff --git a/src/GeomAPI/GeomAPI_Dir.h b/src/GeomAPI/GeomAPI_Dir.h index afdab1c09..a8b4022ce 100644 --- a/src/GeomAPI/GeomAPI_Dir.h +++ b/src/GeomAPI/GeomAPI_Dir.h @@ -20,6 +20,8 @@ class GEOMAPI_EXPORT GeomAPI_Dir: public GeomAPI_Interface public: /// Creation of direction by coordinates GeomAPI_Dir(const double theX, const double theY, const double theZ); + /// Creation of direction by coordinates + GeomAPI_Dir(const boost::shared_ptr& theCoords); /// returns X coordinate double x() const; diff --git a/src/GeomAPI/GeomAPI_Lin.cpp b/src/GeomAPI/GeomAPI_Lin.cpp new file mode 100644 index 000000000..9d0407024 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Lin.cpp @@ -0,0 +1,81 @@ +// File: GeomAPI_Lin.cpp +// Created: 29 May 2014 +// Author: Artem ZHIDKOV + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define MY_LIN static_cast(myImpl) + +static gp_Lin* newLine(const double theStartX, const double theStartY, const double theStartZ, + 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)) +{} + +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())) +{} + +double GeomAPI_Lin::distance(const boost::shared_ptr& thePoint) const +{ + return MY_LIN->Distance(thePoint->impl()); +} + +const boost::shared_ptr GeomAPI_Lin::intersect( + const boost::shared_ptr& theLine) const +{ + if (MY_LIN->SquareDistance(theLine->impl()) > Precision::Confusion()) + return boost::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_Lin2d aPrjLine1 = ProjLib::Project(aPlane, *MY_LIN); + gp_Lin2d aPrjLine2 = ProjLib::Project(aPlane, theLine->impl()); + + IntAna2d_AnaIntersection anInter(aPrjLine1, aPrjLine1); + if (!anInter.IsDone() || anInter.IsEmpty()) + return boost::shared_ptr(); + const gp_Pnt2d& anIntPnt2d = anInter.Point(0).Value(); + gp_Pnt aResult = ElSLib::Value(anIntPnt2d.X(), anIntPnt2d.Y(), aPlane); + + return boost::shared_ptr( + new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z())); +} + +const boost::shared_ptr GeomAPI_Lin::project(const boost::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); + + gp_XYZ aResult = aPnt + aDir * aParam; + return boost::shared_ptr(new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z())); +} + diff --git a/src/GeomAPI/GeomAPI_Lin.h b/src/GeomAPI/GeomAPI_Lin.h new file mode 100644 index 000000000..260b5ffee --- /dev/null +++ b/src/GeomAPI/GeomAPI_Lin.h @@ -0,0 +1,37 @@ +// File: GeomAPI_Lin.h +// Created: 29 May 2014 +// Author: Artem ZHIDKOV + +#ifndef GeomAPI_Lin_HeaderFile +#define GeomAPI_Lin_HeaderFile + +#include +#include + +class GeomAPI_Pnt; + +/**\class GeomAPI_Lin + * \ingroup DataModel + * \brief Line in 3D + */ + +class GEOMAPI_EXPORT GeomAPI_Lin: public GeomAPI_Interface +{ +public: + /// Creation of line defined by cordinates of start and end points + GeomAPI_Lin(const double theStartX, const double theStartY, const double theStartZ, + const double theEndX, const double theEndY, const double theEndZ); + /// Creation of line defined by start and end points + GeomAPI_Lin(const boost::shared_ptr& theStart, + const boost::shared_ptr& theEnd); + + /// Distance between two points + double distance(const boost::shared_ptr& thePoint) const; + /// Intersection of two lines + const boost::shared_ptr intersect(const boost::shared_ptr& theLine) const; + /// Project point on line + const boost::shared_ptr project(const boost::shared_ptr& thePoint) const; +}; + +#endif + diff --git a/src/GeomAPI/GeomAPI_Lin2d.cpp b/src/GeomAPI/GeomAPI_Lin2d.cpp new file mode 100644 index 000000000..2d698c089 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Lin2d.cpp @@ -0,0 +1,62 @@ +// File: GeomAPI_Lin2d.cpp +// Created: 29 May 2014 +// Author: Artem ZHIDKOV + +#include +#include + +#include +#include +#include +#include + +#include + +#define MY_LIN2D static_cast(myImpl) + +static gp_Lin2d* newLine2d(const double theStartX, const double theStartY, + const double theEndX, const double theEndY) +{ + gp_XY aDir(theEndX - theStartX, theEndY - theStartY); + gp_Pnt2d aStart(theStartX, theStartY); + return new gp_Lin2d(aStart, gp_Dir2d(aDir)); +} + + +GeomAPI_Lin2d::GeomAPI_Lin2d(const double theStartX, const double theStartY, + const double theEndX, const double theEndY) + : GeomAPI_Interface(newLine2d(theStartX, theStartY, theEndX, theEndY)) +{} + +GeomAPI_Lin2d::GeomAPI_Lin2d(const boost::shared_ptr& theStart, + const boost::shared_ptr& theEnd) + : GeomAPI_Interface(newLine2d(theStart->x(), theStart->y(), + theEnd->x(), theEnd->y())) +{} + +double GeomAPI_Lin2d::distance(const boost::shared_ptr& theOther) const +{ + return MY_LIN2D->Distance(theOther->impl()); +} + +const boost::shared_ptr GeomAPI_Lin2d::intersect( + const boost::shared_ptr& theLine) const +{ + IntAna2d_AnaIntersection anInter(*MY_LIN2D, theLine->impl()); + if (!anInter.IsDone() || anInter.IsEmpty()) + return boost::shared_ptr(); + const gp_Pnt2d& aResult = anInter.Point(0).Value(); + return boost::shared_ptr(new GeomAPI_Pnt2d(aResult.X(), aResult.Y())); +} + +const boost::shared_ptr GeomAPI_Lin2d::project(const boost::shared_ptr& thePoint) const +{ + const gp_XY& aDir = MY_LIN2D->Direction().XY(); + const gp_XY& aLoc = MY_LIN2D->Location().XY(); + const gp_XY& aPnt = thePoint->impl().XY(); + double aParam = aDir.Dot(aPnt - aLoc); + + gp_XY aResult = aPnt + aDir * aParam; + return boost::shared_ptr(new GeomAPI_Pnt2d(aResult.X(), aResult.Y())); +} + diff --git a/src/GeomAPI/GeomAPI_Lin2d.h b/src/GeomAPI/GeomAPI_Lin2d.h new file mode 100644 index 000000000..32f55d3ed --- /dev/null +++ b/src/GeomAPI/GeomAPI_Lin2d.h @@ -0,0 +1,37 @@ +// File: GeomAPI_Lin2d.h +// Created: 29 May 2014 +// Author: Artem ZHIDKOV + +#ifndef GeomAPI_Lin2d_HeaderFile +#define GeomAPI_Lin2d_HeaderFile + +#include +#include + +class GeomAPI_Pnt2d; + +/**\class GeomAPI_Lin2d + * \ingroup DataModel + * \brief Line in 2D + */ + +class GEOMAPI_EXPORT GeomAPI_Lin2d: public GeomAPI_Interface +{ +public: + /// Creation of line defined by cordinates of start and end points + GeomAPI_Lin2d(const double theStartX, const double theStartY, + const double theEndX, const double theEndY); + /// Creation of line defined by start and end points + GeomAPI_Lin2d(const boost::shared_ptr& theStart, + const boost::shared_ptr& theEnd); + + /// Distance between two points + double distance(const boost::shared_ptr& theOther) const; + /// Intersection of two lines + const boost::shared_ptr intersect(const boost::shared_ptr& theLine) const; + /// Project point on line + const boost::shared_ptr project(const boost::shared_ptr& thePoint) const; +}; + +#endif + diff --git a/src/GeomAPI/GeomAPI_Pnt.cpp b/src/GeomAPI/GeomAPI_Pnt.cpp index 83d1dddf9..abf73f07b 100644 --- a/src/GeomAPI/GeomAPI_Pnt.cpp +++ b/src/GeomAPI/GeomAPI_Pnt.cpp @@ -51,3 +51,8 @@ const boost::shared_ptr GeomAPI_Pnt::xyz() { return boost::shared_ptr(new GeomAPI_XYZ(MY_PNT->X(), MY_PNT->Y(), MY_PNT->Z())); } + +double GeomAPI_Pnt::distance(const boost::shared_ptr& theOther) const +{ + return MY_PNT->Distance(theOther->impl()); +} diff --git a/src/GeomAPI/GeomAPI_Pnt.h b/src/GeomAPI/GeomAPI_Pnt.h index a63974d98..9be8ad0ec 100644 --- a/src/GeomAPI/GeomAPI_Pnt.h +++ b/src/GeomAPI/GeomAPI_Pnt.h @@ -39,6 +39,9 @@ public: /// returns coordinates of the point const boost::shared_ptr xyz(); + + /// Distance between two points + double distance(const boost::shared_ptr& theOther) const; }; #endif diff --git a/src/GeomAPI/GeomAPI_Pnt2d.cpp b/src/GeomAPI/GeomAPI_Pnt2d.cpp new file mode 100644 index 000000000..f1cbb8e22 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Pnt2d.cpp @@ -0,0 +1,39 @@ +// File: GeomAPI_Pnt2d.cpp +// Created: 29 May 2014 +// Author: Artem ZHIDKOV + +#include +#include + +#include + +#define MY_PNT2D static_cast(myImpl) + +GeomAPI_Pnt2d::GeomAPI_Pnt2d(const double theX, const double theY) + : GeomAPI_Interface(new gp_Pnt2d(theX, theY)) +{} + +double GeomAPI_Pnt2d::x() const +{ + return MY_PNT2D->X(); +} + +double GeomAPI_Pnt2d::y() const +{ + return MY_PNT2D->Y(); +} + +void GeomAPI_Pnt2d::setX(const double theX) +{ + return MY_PNT2D->SetX(theX); +} + +void GeomAPI_Pnt2d::setY(const double theY) +{ + return MY_PNT2D->SetY(theY); +} + +double GeomAPI_Pnt2d::distance(const boost::shared_ptr& theOther) const +{ + return MY_PNT2D->Distance(theOther->impl()); +} diff --git a/src/GeomAPI/GeomAPI_Pnt2d.h b/src/GeomAPI/GeomAPI_Pnt2d.h new file mode 100644 index 000000000..097e8786e --- /dev/null +++ b/src/GeomAPI/GeomAPI_Pnt2d.h @@ -0,0 +1,39 @@ +// File: GeomAPI_Pnt2d.h +// Created: 29 May 2014 +// Author: Artem ZHIDKOV + +#ifndef GeomAPI_Pnt2d_HeaderFile +#define GeomAPI_Pnt2d_HeaderFile + +#include +#include + +class GeomAPI_XYZ; + +/**\class GeomAPI_Pnt2d + * \ingroup DataModel + * \brief 2D point defined by two coordinates + */ + +class GEOMAPI_EXPORT GeomAPI_Pnt2d: public GeomAPI_Interface +{ +public: + /// Creation of point by coordinates + GeomAPI_Pnt2d(const double theX, const double theY); + + /// returns X coordinate + double x() const; + /// returns Y coordinate + double y() const; + + /// sets X coordinate + void setX(const double theX); + /// sets Y coordinate + void setY(const double theY); + + /// Distance between two points + double distance(const boost::shared_ptr& theOther) const; +}; + +#endif + diff --git a/src/GeomAPI/GeomAPI_XYZ.cpp b/src/GeomAPI/GeomAPI_XYZ.cpp index 30c246323..3cc18eeb1 100644 --- a/src/GeomAPI/GeomAPI_XYZ.cpp +++ b/src/GeomAPI/GeomAPI_XYZ.cpp @@ -56,3 +56,21 @@ const boost::shared_ptr GeomAPI_XYZ::multiplied(const double theArg MY_XYZ->Y() * theArg, MY_XYZ->Z() * theArg)); return aResult; } + +double GeomAPI_XYZ::dot(const boost::shared_ptr& theArg) const +{ + return MY_XYZ->Dot(theArg->impl()); +} + +const boost::shared_ptr GeomAPI_XYZ::cross(const boost::shared_ptr& theArg) const +{ + gp_XYZ aResult = MY_XYZ->Crossed(theArg->impl()); + return boost::shared_ptr(new GeomAPI_XYZ(aResult.X(), aResult.Y(), aResult.Z())); +} + +double GeomAPI_XYZ::distance(const boost::shared_ptr& theOther) const +{ + gp_XYZ aResult(theOther->x() - x(), theOther->y() - y(), theOther->z() - z()); + return aResult.Modulus(); +} + diff --git a/src/GeomAPI/GeomAPI_XYZ.h b/src/GeomAPI/GeomAPI_XYZ.h index 6042428e5..85c60779e 100644 --- a/src/GeomAPI/GeomAPI_XYZ.h +++ b/src/GeomAPI/GeomAPI_XYZ.h @@ -37,6 +37,14 @@ public: const boost::shared_ptr added(const boost::shared_ptr& theArg); /// result is coordinates multiplied by the argument const boost::shared_ptr multiplied(const double theArg); + + /// result is a scalar product of two triplets + double dot(const boost::shared_ptr& theArg) const; + /// result is a cross product of two triplets + const boost::shared_ptr cross(const boost::shared_ptr& theArg) const; + + /// Distance between two triplets + double distance(const boost::shared_ptr& theOther) const; }; #endif