]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Added new geometrical objects GeomAPI
authorazv <azv@opencascade.com>
Thu, 29 May 2014 13:57:56 +0000 (17:57 +0400)
committerazv <azv@opencascade.com>
Thu, 29 May 2014 13:57:56 +0000 (17:57 +0400)
13 files changed:
src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_Dir.cpp
src/GeomAPI/GeomAPI_Dir.h
src/GeomAPI/GeomAPI_Lin.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_Lin.h [new file with mode: 0644]
src/GeomAPI/GeomAPI_Lin2d.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_Lin2d.h [new file with mode: 0644]
src/GeomAPI/GeomAPI_Pnt.cpp
src/GeomAPI/GeomAPI_Pnt.h
src/GeomAPI/GeomAPI_Pnt2d.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_Pnt2d.h [new file with mode: 0644]
src/GeomAPI/GeomAPI_XYZ.cpp
src/GeomAPI/GeomAPI_XYZ.h

index 142a02bb44b1fd336663c5fb9bd773481d7b6cb4..cf21d319f0efbac8e85a7886ae2655c29c50daa2 100644 (file)
@@ -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
index 6e8ea2429f790687cc5047a80efe94f2742e310a..c3ad12fb97a2421cee00f8ce53f44045cfbd1146 100644 (file)
@@ -7,12 +7,16 @@
 
 #include <gp_Dir.hxx>
 
-#define MY_DIR static_cast<gp_Pnt*>(myImpl)
+#define MY_DIR static_cast<gp_Dir*>(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<GeomAPI_XYZ>& theCoords)
+  : GeomAPI_Interface(new gp_Dir(theCoords->x(), theCoords->y(), theCoords->z()))
+{}
+
 double GeomAPI_Dir::x() const
 {
   return MY_DIR->X();
index afdab1c090ccb2e7bbce10e42e98ff26bf4d4898..a8b4022cea38af190a50f745a09adce9ca972432 100644 (file)
@@ -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<GeomAPI_XYZ>& 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 (file)
index 0000000..9d04070
--- /dev/null
@@ -0,0 +1,81 @@
+// File:        GeomAPI_Lin.cpp
+// Created:     29 May 2014
+// Author:      Artem ZHIDKOV
+
+#include <GeomAPI_Lin.h>
+#include <GeomAPI_Pnt.h>
+
+#include <gp_Dir.hxx>
+#include <gp_Lin.hxx>
+#include <gp_Lin2d.hxx>
+#include <gp_Pln.hxx>
+#include <gp_Pnt.hxx>
+#include <gp_XYZ.hxx>
+
+#include <ElSLib.hxx>
+#include <IntAna2d_AnaIntersection.hxx>
+#include <Precision.hxx>
+#include <ProjLib.hxx>
+
+#define MY_LIN static_cast<gp_Lin*>(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<GeomAPI_Pnt>& theStart,
+                         const boost::shared_ptr<GeomAPI_Pnt>& theEnd)
+  : GeomAPI_Interface(newLine(theStart->x(), theStart->y(), theStart->z(), 
+                              theEnd->x(),   theEnd->y(),   theEnd->z()))
+{}
+
+double GeomAPI_Lin::distance(const boost::shared_ptr<GeomAPI_Pnt>& thePoint) const
+{
+  return MY_LIN->Distance(thePoint->impl<gp_Pnt>());
+}
+
+const boost::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::intersect(
+                const boost::shared_ptr<GeomAPI_Lin>& theLine) const
+{
+  if (MY_LIN->SquareDistance(theLine->impl<gp_Lin>()) > Precision::Confusion())
+    return boost::shared_ptr<GeomAPI_Pnt>();
+
+  const gp_Dir& aDir1 = MY_LIN->Direction();
+  const gp_Dir& aDir2 = theLine->impl<gp_Lin>().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<gp_Lin>());
+
+  IntAna2d_AnaIntersection anInter(aPrjLine1, aPrjLine1);
+  if (!anInter.IsDone() || anInter.IsEmpty())
+    return boost::shared_ptr<GeomAPI_Pnt>();
+  const gp_Pnt2d& anIntPnt2d = anInter.Point(0).Value();
+  gp_Pnt aResult = ElSLib::Value(anIntPnt2d.X(), anIntPnt2d.Y(), aPlane);
+
+  return boost::shared_ptr<GeomAPI_Pnt>(
+    new GeomAPI_Pnt(aResult.X(), aResult.Y(), aResult.Z()));
+}
+
+const boost::shared_ptr<GeomAPI_Pnt> GeomAPI_Lin::project(const boost::shared_ptr<GeomAPI_Pnt>& thePoint) const
+{
+  const gp_XYZ& aDir = MY_LIN->Direction().XYZ();
+  const gp_XYZ& aLoc = MY_LIN->Location().XYZ();
+  const gp_XYZ& aPnt = thePoint->impl<gp_Pnt>().XYZ();
+  double aParam = aDir.Dot(aPnt - aLoc);
+
+  gp_XYZ aResult = aPnt + aDir * aParam;
+  return boost::shared_ptr<GeomAPI_Pnt>(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 (file)
index 0000000..260b5ff
--- /dev/null
@@ -0,0 +1,37 @@
+// File:        GeomAPI_Lin.h
+// Created:     29 May 2014
+// Author:      Artem ZHIDKOV
+
+#ifndef GeomAPI_Lin_HeaderFile
+#define GeomAPI_Lin_HeaderFile
+
+#include <GeomAPI_Interface.h>
+#include <boost/shared_ptr.hpp>
+
+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<GeomAPI_Pnt>& theStart,
+              const boost::shared_ptr<GeomAPI_Pnt>& theEnd);
+
+  /// Distance between two points
+  double distance(const boost::shared_ptr<GeomAPI_Pnt>& thePoint) const;
+  /// Intersection of two lines
+  const boost::shared_ptr<GeomAPI_Pnt> intersect(const boost::shared_ptr<GeomAPI_Lin>& theLine) const;
+  /// Project point on line
+  const boost::shared_ptr<GeomAPI_Pnt> project(const boost::shared_ptr<GeomAPI_Pnt>& thePoint) const;
+};
+
+#endif
+
diff --git a/src/GeomAPI/GeomAPI_Lin2d.cpp b/src/GeomAPI/GeomAPI_Lin2d.cpp
new file mode 100644 (file)
index 0000000..2d698c0
--- /dev/null
@@ -0,0 +1,62 @@
+// File:        GeomAPI_Lin2d.cpp
+// Created:     29 May 2014
+// Author:      Artem ZHIDKOV
+
+#include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pnt2d.h>
+
+#include <gp_Dir2d.hxx>
+#include <gp_Lin2d.hxx>
+#include <gp_Pnt2d.hxx>
+#include <gp_XY.hxx>
+
+#include <IntAna2d_AnaIntersection.hxx>
+
+#define MY_LIN2D static_cast<gp_Lin2d*>(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<GeomAPI_Pnt2d>& theStart,
+                         const boost::shared_ptr<GeomAPI_Pnt2d>& theEnd)
+  : GeomAPI_Interface(newLine2d(theStart->x(), theStart->y(),
+                                theEnd->x(),   theEnd->y()))
+{}
+
+double GeomAPI_Lin2d::distance(const boost::shared_ptr<GeomAPI_Pnt2d>& theOther) const
+{
+  return MY_LIN2D->Distance(theOther->impl<gp_Pnt2d>());
+}
+
+const boost::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Lin2d::intersect(
+                const boost::shared_ptr<GeomAPI_Lin2d>& theLine) const
+{
+  IntAna2d_AnaIntersection anInter(*MY_LIN2D, theLine->impl<gp_Lin2d>());
+  if (!anInter.IsDone() || anInter.IsEmpty())
+    return boost::shared_ptr<GeomAPI_Pnt2d>();
+  const gp_Pnt2d& aResult = anInter.Point(0).Value();
+  return boost::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(aResult.X(), aResult.Y()));
+}
+
+const boost::shared_ptr<GeomAPI_Pnt2d> GeomAPI_Lin2d::project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const
+{
+  const gp_XY& aDir = MY_LIN2D->Direction().XY();
+  const gp_XY& aLoc = MY_LIN2D->Location().XY();
+  const gp_XY& aPnt = thePoint->impl<gp_Pnt2d>().XY();
+  double aParam = aDir.Dot(aPnt - aLoc);
+
+  gp_XY aResult = aPnt + aDir * aParam;
+  return boost::shared_ptr<GeomAPI_Pnt2d>(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 (file)
index 0000000..32f55d3
--- /dev/null
@@ -0,0 +1,37 @@
+// File:        GeomAPI_Lin2d.h
+// Created:     29 May 2014
+// Author:      Artem ZHIDKOV
+
+#ifndef GeomAPI_Lin2d_HeaderFile
+#define GeomAPI_Lin2d_HeaderFile
+
+#include <GeomAPI_Interface.h>
+#include <boost/shared_ptr.hpp>
+
+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<GeomAPI_Pnt2d>& theStart,
+                const boost::shared_ptr<GeomAPI_Pnt2d>& theEnd);
+
+  /// Distance between two points
+  double distance(const boost::shared_ptr<GeomAPI_Pnt2d>& theOther) const;
+  /// Intersection of two lines
+  const boost::shared_ptr<GeomAPI_Pnt2d> intersect(const boost::shared_ptr<GeomAPI_Lin2d>& theLine) const;
+  /// Project point on line
+  const boost::shared_ptr<GeomAPI_Pnt2d> project(const boost::shared_ptr<GeomAPI_Pnt2d>& thePoint) const;
+};
+
+#endif
+
index 83d1dddf9adad8bc90bbff2829df19c80238f8e3..abf73f07bad436622fbc36819131fdc4f994cbde 100644 (file)
@@ -51,3 +51,8 @@ const boost::shared_ptr<GeomAPI_XYZ> GeomAPI_Pnt::xyz()
 {
   return boost::shared_ptr<GeomAPI_XYZ>(new GeomAPI_XYZ(MY_PNT->X(), MY_PNT->Y(), MY_PNT->Z()));
 }
+
+double GeomAPI_Pnt::distance(const boost::shared_ptr<GeomAPI_Pnt>& theOther) const
+{
+  return MY_PNT->Distance(theOther->impl<gp_Pnt>());
+}
index a63974d98c597c088c4e98037a3a0d1d19e57989..9be8ad0ec3d5a876f9664a55751f35fb2da60e6d 100644 (file)
@@ -39,6 +39,9 @@ public:
 
   /// returns coordinates of the point
   const boost::shared_ptr<GeomAPI_XYZ> xyz();
+
+  /// Distance between two points
+  double distance(const boost::shared_ptr<GeomAPI_Pnt>& theOther) const;
 };
 
 #endif
diff --git a/src/GeomAPI/GeomAPI_Pnt2d.cpp b/src/GeomAPI/GeomAPI_Pnt2d.cpp
new file mode 100644 (file)
index 0000000..f1cbb8e
--- /dev/null
@@ -0,0 +1,39 @@
+// File:        GeomAPI_Pnt2d.cpp
+// Created:     29 May 2014
+// Author:      Artem ZHIDKOV
+
+#include<GeomAPI_Pnt2d.h>
+#include<GeomAPI_XYZ.h>
+
+#include<gp_Pnt2d.hxx>
+
+#define MY_PNT2D static_cast<gp_Pnt2d*>(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<GeomAPI_Pnt2d>& theOther) const
+{
+  return MY_PNT2D->Distance(theOther->impl<gp_Pnt2d>());
+}
diff --git a/src/GeomAPI/GeomAPI_Pnt2d.h b/src/GeomAPI/GeomAPI_Pnt2d.h
new file mode 100644 (file)
index 0000000..097e878
--- /dev/null
@@ -0,0 +1,39 @@
+// File:        GeomAPI_Pnt2d.h
+// Created:     29 May 2014
+// Author:      Artem ZHIDKOV
+
+#ifndef GeomAPI_Pnt2d_HeaderFile
+#define GeomAPI_Pnt2d_HeaderFile
+
+#include <GeomAPI_Interface.h>
+#include <boost/shared_ptr.hpp>
+
+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<GeomAPI_Pnt2d>& theOther) const;
+};
+
+#endif
+
index 30c246323a26d18feb7e9e8b9117816852c4b5b9..3cc18eeb166de29e93f99f67f330ef3928eaf620 100644 (file)
@@ -56,3 +56,21 @@ const boost::shared_ptr<GeomAPI_XYZ> GeomAPI_XYZ::multiplied(const double theArg
     MY_XYZ->Y() * theArg, MY_XYZ->Z() * theArg));
   return aResult;
 }
+
+double GeomAPI_XYZ::dot(const boost::shared_ptr<GeomAPI_XYZ>& theArg) const
+{
+  return MY_XYZ->Dot(theArg->impl<gp_XYZ>());
+}
+
+const boost::shared_ptr<GeomAPI_XYZ> GeomAPI_XYZ::cross(const boost::shared_ptr<GeomAPI_XYZ>& theArg) const
+{
+  gp_XYZ aResult = MY_XYZ->Crossed(theArg->impl<gp_XYZ>());
+  return boost::shared_ptr<GeomAPI_XYZ>(new GeomAPI_XYZ(aResult.X(), aResult.Y(), aResult.Z()));
+}
+
+double GeomAPI_XYZ::distance(const boost::shared_ptr<GeomAPI_XYZ>& theOther) const
+{
+  gp_XYZ aResult(theOther->x() - x(), theOther->y() - y(), theOther->z() - z());
+  return aResult.Modulus();
+}
+
index 6042428e5e15c068ae2e83e6578ea97ed944cfca..85c60779ef8cb7fa3cbd9168973e1d81c7394cde 100644 (file)
@@ -37,6 +37,14 @@ public:
   const boost::shared_ptr<GeomAPI_XYZ> added(const boost::shared_ptr<GeomAPI_XYZ>& theArg);
   /// result is coordinates multiplied by the argument
   const boost::shared_ptr<GeomAPI_XYZ> multiplied(const double theArg);
+
+  /// result is a scalar product of two triplets
+  double dot(const boost::shared_ptr<GeomAPI_XYZ>& theArg) const;
+  /// result is a cross product of two triplets
+  const boost::shared_ptr<GeomAPI_XYZ> cross(const boost::shared_ptr<GeomAPI_XYZ>& theArg) const;
+
+  /// Distance between two triplets
+  double distance(const boost::shared_ptr<GeomAPI_XYZ>& theOther) const;
 };
 
 #endif