]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
add distance coordinates to measurement for distances and linear edges
authorrraphael <raphael.raphael@c-s.fr>
Wed, 25 Nov 2020 17:26:09 +0000 (18:26 +0100)
committerrraphael <raphael.raphael@c-s.fr>
Fri, 15 Jan 2021 11:00:49 +0000 (12:00 +0100)
src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h

index dfde5d61071ac7d24fba80d99278196bf1c1551d..a7ade701c14e40867c774daa286bc2c33221ca58 100644 (file)
@@ -125,6 +125,15 @@ void FeaturesPlugin_Measurement::computeLength()
 
   std::ostringstream anOutput;
   anOutput << "Length = " << std::setprecision(10) << anEdge->length();
+  if(anEdge->isLine())
+  {
+    auto point1 = anEdge->firstPoint();
+    auto point2 = anEdge->lastPoint();
+
+    anOutput <<"\n|dx| = " <<  std::setprecision(10) << std::abs(point2->x() - point1->x())
+        <<"\n|dy| = " <<  std::setprecision(10) << std::abs(point2->y() - point1->y())
+        <<"\n|dz| = " <<  std::setprecision(10) << std::abs(point2->z() - point1->z());
+  }
   string(RESULT_ID())->setValue(anOutput.str());
 
   AttributeDoubleArrayPtr aValues =
@@ -156,10 +165,14 @@ void FeaturesPlugin_Measurement::computeDistance()
     return;
   }
 
-  double aDistance = GeomAlgoAPI_ShapeTools::minimalDistance(aShape1, aShape2);
+  std::array<double, 3> fromShape1To2;
+  double aDistance = GeomAlgoAPI_ShapeTools::minimalDistance(aShape1, aShape2, fromShape1To2);
 
   std::ostringstream anOutput;
-  anOutput << "Distance = " << std::setprecision(10) << aDistance;
+  anOutput << "Distance = " << std::setprecision(10) << aDistance
+           <<"\n|dx| = " <<  std::setprecision(10) << std::abs(fromShape1To2[0])
+      <<"\n|dy| = " <<  std::setprecision(10) << std::abs(fromShape1To2[1])
+      <<"\n|dz| = " <<  std::setprecision(10) << std::abs(fromShape1To2[2]);
   string(RESULT_ID())->setValue(anOutput.str());
 
   AttributeDoubleArrayPtr aValues =
index 89133a06bb74d0f3ff21fb5802178589ef8f5184..4fad7e2518625abbc15f4bcadd75f391cf87e742 100644 (file)
@@ -204,14 +204,36 @@ double GeomAlgoAPI_ShapeTools::radius(const std::shared_ptr<GeomAPI_Face>& theCy
 }
 
 //==================================================================================================
-double GeomAlgoAPI_ShapeTools::minimalDistance(const GeomShapePtr& theShape1,
-                                               const GeomShapePtr& theShape2)
+namespace {
+
+auto getExtemaDistShape = [](const GeomShapePtr& theShape1,
+    const GeomShapePtr& theShape2) -> BRepExtrema_DistShapeShape
 {
   const TopoDS_Shape& aShape1 = theShape1->impl<TopoDS_Shape>();
   const TopoDS_Shape& aShape2 = theShape2->impl<TopoDS_Shape>();
 
   BRepExtrema_DistShapeShape aDist(aShape1, aShape2);
   aDist.Perform();
+  return aDist;
+};
+}
+
+double GeomAlgoAPI_ShapeTools::minimalDistance(const GeomShapePtr& theShape1,
+                                               const GeomShapePtr& theShape2)
+{
+  BRepExtrema_DistShapeShape aDist = getExtemaDistShape(theShape1, theShape2);
+  return aDist.IsDone() ? aDist.Value() : Precision::Infinite();
+}
+
+double GeomAlgoAPI_ShapeTools::minimalDistance(const GeomShapePtr& theShape1,
+                                               const GeomShapePtr& theShape2, std::array<double, 3> & fromShape1To2)
+{
+  BRepExtrema_DistShapeShape aDist = getExtemaDistShape(theShape1, theShape2);
+  const auto & pt1 = aDist.PointOnShape1(1);
+  const auto & pt2 = aDist.PointOnShape2(1) ;
+  fromShape1To2[0] = pt2.X() - pt1.X();
+  fromShape1To2[1] = pt2.Y() - pt1.Y();
+  fromShape1To2[2] = pt2.Z() - pt1.Z();
   return aDist.IsDone() ? aDist.Value() : Precision::Infinite();
 }
 
index 4e1e6523a0d95ce80cc6223af87da34f8c672c2e..f9c2811ebc2be6fd740d54389777ec6cfa6def56 100644 (file)
@@ -24,7 +24,6 @@
 
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_Vertex.h>
-
 #include <map>
 #include <set>
 
@@ -65,6 +64,8 @@ public:
   /// \brief Calculate minimal distance between shapes
   GEOMALGOAPI_EXPORT static double minimalDistance(const GeomShapePtr& theShape1,
                                                    const GeomShapePtr& theShape2);
+  GEOMALGOAPI_EXPORT static double minimalDistance(const GeomShapePtr& theShape1,
+                                                   const GeomShapePtr& theShape2, std::array<double, 3> & fromShape1To2);
 
   /// \brief Combines faces with common edges to shells, or solids to compsolids.
   /// \param[in] theCompound compound of shapes.