From b67c6ffd068db9de9deff24e16e31fc7633e6135 Mon Sep 17 00:00:00 2001 From: rraphael Date: Wed, 25 Nov 2020 18:26:09 +0100 Subject: [PATCH] add distance coordinates to measurement for distances and linear edges --- .../FeaturesPlugin_Measurement.cpp | 17 ++++++++++-- src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp | 26 +++++++++++++++++-- src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h | 3 ++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp b/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp index dfde5d610..a7ade701c 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Measurement.cpp @@ -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 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 = diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp index 89133a06b..4fad7e251 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp @@ -204,14 +204,36 @@ double GeomAlgoAPI_ShapeTools::radius(const std::shared_ptr& 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(); const TopoDS_Shape& aShape2 = theShape2->impl(); 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 & 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(); } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h index 4e1e6523a..f9c2811eb 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h @@ -24,7 +24,6 @@ #include #include - #include #include @@ -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 & fromShape1To2); /// \brief Combines faces with common edges to shells, or solids to compsolids. /// \param[in] theCompound compound of shapes. -- 2.39.2