From 9f730900596e9412f431c23b2bd985063814a750 Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 17 Jun 2022 17:19:17 +0300 Subject: [PATCH] bos #29468: Advanced geometry features: distance Edge-Edge & Face-Face --- doc/salome/examples/shape_proximity.py | 40 ++ doc/salome/examples/tests.set | 1 + .../gui/GEOM/images/Shape_proximity_0.png | Bin 0 -> 9214 bytes .../gui/GEOM/images/Shape_proximity_1.png | Bin 0 -> 10746 bytes doc/salome/gui/GEOM/input/shape_proximity.doc | 52 ++ .../gui/GEOM/input/tui_measurement_tools.doc | 1 + .../gui/GEOM/input/tui_shape_proximity.doc | 6 + .../GEOM/input/using_measurement_tools.doc | 1 + idl/GEOM_Gen.idl | 32 ++ src/GEOMImpl/CMakeLists.txt | 3 + src/GEOMImpl/GEOMImpl_Gen.cxx | 2 + src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx | 190 ++++++++ src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx | 10 + src/GEOMImpl/GEOMImpl_IProximity.hxx | 122 +++++ .../GEOMImpl_ShapeProximityDriver.cxx | 457 ++++++++++++++++++ .../GEOMImpl_ShapeProximityDriver.hxx | 45 ++ src/GEOMImpl/GEOMImpl_Types.hxx | 5 + src/GEOM_I/GEOM_IMeasureOperations_i.cc | 94 ++++ src/GEOM_I/GEOM_IMeasureOperations_i.hh | 9 + src/GEOM_SWIG/CMakeLists.txt | 1 + src/GEOM_SWIG/geomBuilder.py | 16 + src/GEOM_SWIG/proximity.py | 91 ++++ test/test_proximity_edge_edge.py | 130 +++++ test/test_proximity_face_face.py | 87 ++++ test/tests.set | 2 + 25 files changed, 1397 insertions(+) create mode 100644 doc/salome/examples/shape_proximity.py create mode 100644 doc/salome/gui/GEOM/images/Shape_proximity_0.png create mode 100644 doc/salome/gui/GEOM/images/Shape_proximity_1.png create mode 100644 doc/salome/gui/GEOM/input/shape_proximity.doc create mode 100644 doc/salome/gui/GEOM/input/tui_shape_proximity.doc create mode 100644 src/GEOMImpl/GEOMImpl_IProximity.hxx create mode 100644 src/GEOMImpl/GEOMImpl_ShapeProximityDriver.cxx create mode 100644 src/GEOMImpl/GEOMImpl_ShapeProximityDriver.hxx create mode 100644 src/GEOM_SWIG/proximity.py create mode 100644 test/test_proximity_edge_edge.py create mode 100644 test/test_proximity_face_face.py diff --git a/doc/salome/examples/shape_proximity.py b/doc/salome/examples/shape_proximity.py new file mode 100644 index 000000000..4e634fdc1 --- /dev/null +++ b/doc/salome/examples/shape_proximity.py @@ -0,0 +1,40 @@ +# Shape Proximity + +import math +import salome +salome.salome_init_without_session() +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New() + +# create conical and planar faces +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) +Cone_1 = geompy.MakeConeR1R2H(100, 0, 300) +Cone_1_face_3 = geompy.GetSubShape(Cone_1, [3]) +Cone_1_wire_4 = geompy.GetSubShape(Cone_1, [4]) +Face_1 = geompy.MakeFaceFromSurface(Cone_1_face_3, Cone_1_wire_4) +Face_1_edge_5 = geompy.GetSubShape(Face_1, [5]) +Face_2 = geompy.MakeFaceObjHW(Face_1_edge_5, 200, 200) +geompy.Rotate(Face_2, OY, 90*math.pi/180.0) +Face_2_vertex_7 = geompy.GetSubShape(Face_2, [7]) +Translation_1 = geompy.MakeTranslationTwoPoints(Face_2, Face_2_vertex_7, O) + +shape1 = Face_1 +shape2 = Translation_1 + +# perform proximity calculation with the default parameters +p1 = geompy.ShapeProximity() +proximity1 = p1.proximity(shape1, shape2) +print("Proximity with default parameters: ", proximity1) + +# perform proximity calculation with custom parameters +p2 = geompy.ShapeProximity() +p2.setShapes(shape1, shape2) +p2.setSampling(shape1, 100) # number of sample points for the first shape +p2.setSampling(shape2, 40) # number of sample points for the second shape +proximity2_coarse = p2.coarseProximity() +proximity2_fine = p2.preciseProximity() +print("Proximity with custom parameters: coarse = ", proximity2_coarse, "; precise = ", proximity2_fine) diff --git a/doc/salome/examples/tests.set b/doc/salome/examples/tests.set index 327d64070..c2c8eb81e 100644 --- a/doc/salome/examples/tests.set +++ b/doc/salome/examples/tests.set @@ -135,4 +135,5 @@ SET(GOOD_TESTS working_with_groups_ex06.py GEOM_Field.py check_self_intersections_fast.py # OCC > 6.9.0 + shape_proximity.py ) diff --git a/doc/salome/gui/GEOM/images/Shape_proximity_0.png b/doc/salome/gui/GEOM/images/Shape_proximity_0.png new file mode 100644 index 0000000000000000000000000000000000000000..196b764c7181d8d6c05f40e0f2b16b1aa305a8c8 GIT binary patch literal 9214 zcmZ`<2{@G9+kb{Kw#Je|8m1)L(DGJHm@E;gX(19O-a=kf3`Lkkw4g=dm0g+2HloSC zr|hB`SzkLdmi+DOeCK&4^?uj)|E{jCdd_psegE#?y_|FIXYLbE>aP>rBnUy!y5k1A zXCR1&4gP-T=K~`cBbO-f51);ZzAnUp|HKs}KLaBI*9^>EA!q{$f;K9k6jfejfE4+l4Uoc?iR;-AWw z(GY}#j_V#hce8c0<5q+v*}HOLJV5^5=dCz#e*gZbl%S)2LRV8Oc4kqXoW#P6M_H&)wd5-n2lKfAQZ` zQX_V^V}RhNf13Xb$iI*g3{QF$IzmK~NF#`tLMj@LvyD9Yu>N(XvA>e0ZRPg z$#Fc5%Izrdt`r-mO>@vKAwPux&gj!487QkEX~2M~za<(ysvf5!vfQ-4UVXo(P2v5A7w#aExJFm{(Z0 zkmwlD4Y-*uPXyQ-9$u3i#WBQS>~Siz6^hxZovpKx+gs&CMtsNzGf5sYERMg)}F#|#$|CJ>K zfc{(+q1>(qdkzLl@#D+0*H5`?kH$^dOO7BSVViJVuse>ze6GRUV0F1G5D_QVvuE#< z1#L>Ubr&AX;yuT3p$p8^3%Zx9|Hf6L+PapzOaT2;0|C&81{9GHeLtUyRTC^Tp82G> zNU+asYn_eW)_UlHJH>GA;=}DeBkwuGxj4qrp9Ub}#WC)UA+Q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BcEfwDAA?b`?o+Qs%WpurV6!XJiA-Ny8jeYkw3jL&x_A Q{4<>6dM9<$v`K#d1L5)wHUIzs literal 0 HcmV?d00001 diff --git a/doc/salome/gui/GEOM/images/Shape_proximity_1.png b/doc/salome/gui/GEOM/images/Shape_proximity_1.png new file mode 100644 index 0000000000000000000000000000000000000000..1217989e093ad0ca60008d05149d57670d8e163c GIT binary patch literal 10746 zcmZ{Kc|6oz^#2Emlw}xEwn@=wlPFslj6GYl5P2+xELq1ECaK0YCOnjV*GeK~Z()XH zPqvVKNrbVE<##`$p6B^~U*F#!Uf0~uz305o`<#2uxu2OZBLgjVw*71n1hMOAW6whn zV+QyuW8Dd6b`{;F4{q9Ko)Em3C^9np;@zT-PU>Rd&+RZO=T=%mjm=ba{ zz3ioa)5YbQs~7kPLFyjYti7(;p?n;@98g+1`bKsquCYK63ev%$q?DPApb1`sb z?$QUoICWF(dnWl0$F&%_U-G=(`@|*VO1ZF;eZfFkLs|bb+=~v}k7;Yk&c@f(C0DK} zmNyCW6z|P?t#%xX8sz5sAVEMKAqYMoZ6IQ9?K&{BG8UjL92|JSN_lm@{!+E!)!Am_ zV$Yj_fe?h*&)drkK?EZR!lJiFkE|-1alp%e zcm3J@XFMf2XukOWlk!K}?-9=mAOJ1!h|kx*43{i0KrY`pE<~e*Rw@F*ACh(yjx?t*v*#(?F?BpTy-q^GRBKS%9$GFx-WLn0%fN|gCTTWTeVklo{(Thq@v%Fbr=;WmMP1RM}8!3_IYp=sJGhY=93# z0%GtV*w0J-^9YCmQ^l0WC}yq2jR7YpZ3ZkFPoK|L0!o22uv!$E?smsC zlF@HpMv?{^^L2&l7((SxWdr#B)dh5-vQ&>~-u@QWVkwG59lk?-dd7z8PGjN9kT`AU zrsF(tVfZjh3lYVeg=f{b4lOyP%TR+xskIAdgdo!crH*JbAbO$>fB~K@64eFjHEY4Y z()+VBkzCm}NUn^1upIbzZJD>0~*F5HD#yXH~Oi7G3z*pT>)6dsD~;aRV!E0mUJGr%e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bu};rz7Ek%L)HuANQ}7B*JKW{8H(Uq*roD;~N_-tO+v{8D8yaJm_p zHNHPIVp5)l?j_?v?e zWWN}>A=yEmdRjU6z4;CKxKCvGg$9ubUbtZmv!X1(4Qr62g-x1sm=Nf{8pq<_1mV^z zJ`pWzHXDP_oE2UhE$MoRv%2-mFh~G_xYo{so1*b86MSc*YS)btm4sJ(S%CZjxmUAc)B?tdjN)lzMtk2Q3*{Ts(tP4hnFr7+(v=ZLAIr5sI3B z@(zo$6W&zi9U`BTd($}HoTzw6c(aqqxaekp;4_uI(gP>uTr2!+&dyD!A3j^4l_{qj zFh1%&z?ne#xO_88sXRO@KOZf+q>1&$p8b*oxs=u@TYu_!piQOTgVJ?cD?a((w@^)8 zsb_DD-dazMt*)A_RVo~+55EjL8&gR?xg5UmYPY&Nbds`S?zuD}9?9SryK9+R#AA)> zhM^a5$0+;Uq3rrNDDc{o+_bJ;(l#Ee&mRJ7_v};d=VSmOeRqF)0c}1P5XWv`C~38x zB)9TuGwv3r-ZXeEkzUW)|5_F&a!Up$^qi1DTNe*ni+>@}i<>u_&H+8gfZ2G@AXtaS zQivV3xp~jBK(`^hrm8WmOuhW2Q^aLus4Cxu_PIaMcDm+hVy5Rv*Atu^)W-ulsE}{- z9nDpWdoQemE5i|Ro5~^^M!ecr1nToNzmjzsFocxK`g%9&4QLm<6GW*YyYHXY7|(X> zG`C?vsUvQDVUWM}iQ4Hiv1-3GBVa3j6_L}vpZN2vV_4r76I7=i$|!&BmzbE;N=!`G z;yL|iR+6CGk7>QePVqKK0~aSwhz^nd*L4;Fyups6e#HA+Y#h+*I#W$I`cVDr`f G3i*Gk1Nv0} literal 0 HcmV?d00001 diff --git a/doc/salome/gui/GEOM/input/shape_proximity.doc b/doc/salome/gui/GEOM/input/shape_proximity.doc new file mode 100644 index 000000000..fc82ece1e --- /dev/null +++ b/doc/salome/gui/GEOM/input/shape_proximity.doc @@ -0,0 +1,52 @@ +/*! + +\page shape_proximity_page Shape Proximity + +The Shape Proximity operation calculates maximal of all possible distances between two shapes. +Considering this case : + +\image html Shape_proximity_0.png + +The proximity of blue shape to the red one is computed like this : +For each point of blue the distance to the red is computed using perpendicular projection. The proximity value returned is equal to maximal value of all of this distances. +To do that the implemented algorithm + +1 - sampling shapes by points then calculating the distance from each sample point from one shape to another + +2 - find the position which gives the maximal distance + +3 - improve the proximity value basing on the exact shapes using the points found on step 2 as a start position + +It may happen that for some point of blue shape no distance to red shape exist using perpendicular projection. +This is typically the case here : + +\image html Shape_proximity_1.png + +In the case of no perpendicular projection of a point on blue shape exists, instead of perpendicular projection the minimal distance to border point of red shape is considered. +The distance from EndBlue Point is taken using EndRed Point (black line represents the distance for EndBlue). + +This is just a TUI functionality. The provided class +
+geompy.ShapeProximity()
+
+has an interface to compute proximity value with default parameters +
+p = geompy.ShapeProximity()
+value = p.proximity(shape1, shape2)
+
+ +Moreover, it also provides the functionality to customize the calculation. +For example, compute coarse proximity value basing on the number of sampling points for each shape, +or compute the precise value as a refining operation after the coarse value calculation. +
+p = geompy.ShapeProximity()
+p.setShapes(shape1, shape2) # customize calculator with input shapes
+p.setSampling(shape1, 100)  # assign number of sample points for the first shape
+p.setSampling(shape2, 25)   # assign number of sample points for the second shape
+coarse_proximity = p.coarseProximity() # rough proximity value basing on the shape sampling and tessellation
+fine_proximity = p.preciseProximity()  # more precise proximity value using exact shapes
+
+ +See also a \ref tui_shape_proximity_page "TUI example". + +*/ diff --git a/doc/salome/gui/GEOM/input/tui_measurement_tools.doc b/doc/salome/gui/GEOM/input/tui_measurement_tools.doc index 3966c9c0f..a4e7f5c9d 100644 --- a/doc/salome/gui/GEOM/input/tui_measurement_tools.doc +++ b/doc/salome/gui/GEOM/input/tui_measurement_tools.doc @@ -22,6 +22,7 @@
  • \subpage tui_check_self_intersections_fast_page
  • \subpage tui_fast_intersection_page
  • \subpage tui_check_conformity_page
  • +
  • \subpage tui_shape_proximity_page
  • */ diff --git a/doc/salome/gui/GEOM/input/tui_shape_proximity.doc b/doc/salome/gui/GEOM/input/tui_shape_proximity.doc new file mode 100644 index 000000000..34efab45d --- /dev/null +++ b/doc/salome/gui/GEOM/input/tui_shape_proximity.doc @@ -0,0 +1,6 @@ +/*! + +\page tui_shape_proximity_page Compute Proximity between Shapes +\tui_script{shape_proximity.py} + +*/ diff --git a/doc/salome/gui/GEOM/input/using_measurement_tools.doc b/doc/salome/gui/GEOM/input/using_measurement_tools.doc index 11803eec2..c30850fd3 100644 --- a/doc/salome/gui/GEOM/input/using_measurement_tools.doc +++ b/doc/salome/gui/GEOM/input/using_measurement_tools.doc @@ -21,6 +21,7 @@
  • \subpage whatis_page "WhatIs"
  • \subpage inspect_object_operation_page "Inspect Object"
  • \subpage shape_statistics_operation_page "Shape Statistics"
  • +
  • \subpage shape_proximity_page "Shapes Proximity"
  • \n To check their integrity: diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 89a1e7779..d33bc140d 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -4833,6 +4833,38 @@ module GEOM * \param theShape Shape for update. */ double UpdateTolerance(in GEOM_Object theShape); + + /*! + * \brief Get the calculator for the proximity value between the given shapes. + * \param theShape1,theShape2 Shapes to find proximity. + * \return The calculator object. + */ + GEOM_Object ShapeProximityCalculator(in GEOM_Object theShape1, in GEOM_Object theShape2); + + /*! + * \brief Set number sample points to compute the coarse proximity. + * \param theCalculator Proximity calculator. + * \param theShape Shape to be samples. + * \param theNbSamples Number of samples points. + */ + void SetShapeSampling(in GEOM_Object theCalculator, + in GEOM_Object theShape, + in long theNbSamples); + + /*! + * \brief Compute coarse value of the proximity basing on the polygonal representation of shapes. + * \param theCalculator Proximity calculator. + * \return Proximity value. + */ + double GetCoarseProximity(in GEOM_Object theCalculator); + + /*! + * \brief Compute precise value of the proximity basing on the exact shapes. + * \param theCalculator Proximity calculator. + * \return Proximity value. + */ + double GetPreciseProximity(in GEOM_Object theCalculator); + }; // # GEOM_IGroupOperations: diff --git a/src/GEOMImpl/CMakeLists.txt b/src/GEOMImpl/CMakeLists.txt index 6dbbae81e..f79a186a5 100644 --- a/src/GEOMImpl/CMakeLists.txt +++ b/src/GEOMImpl/CMakeLists.txt @@ -95,6 +95,7 @@ SET(GEOMImpl_HEADERS GEOMImpl_ILine.hxx GEOMImpl_IPatchFace.hxx GEOMImpl_IPlane.hxx + GEOMImpl_IProximity.hxx GEOMImpl_IMarker.hxx GEOMImpl_ITranslate.hxx GEOMImpl_IMirror.hxx @@ -182,6 +183,7 @@ SET(GEOMImpl_HEADERS GEOMImpl_FillingDriver.hxx GEOMImpl_GlueDriver.hxx GEOMImpl_PatchFaceDriver.hxx + GEOMImpl_ShapeProximityDriver.hxx GEOMImpl_Types.hxx GEOM_GEOMImpl.hxx GEOMImpl_ICanonicalRecognition.hxx @@ -261,6 +263,7 @@ SET(GEOMImpl_SOURCES GEOMImpl_FillingDriver.cxx GEOMImpl_GlueDriver.cxx GEOMImpl_PatchFaceDriver.cxx + GEOMImpl_ShapeProximityDriver.cxx GEOMImpl_FieldDriver.cxx GEOMImpl_ICanonicalRecognition.cxx ) diff --git a/src/GEOMImpl/GEOMImpl_Gen.cxx b/src/GEOMImpl/GEOMImpl_Gen.cxx index 7df117c33..e1d7d3a28 100644 --- a/src/GEOMImpl/GEOMImpl_Gen.cxx +++ b/src/GEOMImpl/GEOMImpl_Gen.cxx @@ -84,6 +84,7 @@ #include #include #include +#include //============================================================================= /*! @@ -165,6 +166,7 @@ GEOMImpl_Gen::GEOMImpl_Gen() TFunction_DriverTable::Get()->AddDriver(GEOMImpl_MeasureDriver::GetID(), new GEOMImpl_MeasureDriver()); TFunction_DriverTable::Get()->AddDriver(GEOMImpl_PatchFaceDriver::GetID(), new GEOMImpl_PatchFaceDriver()); TFunction_DriverTable::Get()->AddDriver(GEOMImpl_ConformityDriver::GetID(), new GEOMImpl_ConformityDriver()); + TFunction_DriverTable::Get()->AddDriver(GEOMImpl_ShapeProximityDriver::GetID(), new GEOMImpl_ShapeProximityDriver()); // Field TFunction_DriverTable::Get()->AddDriver(GEOMImpl_FieldDriver::GetID(), new GEOMImpl_FieldDriver()); diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx index 1c8c7add3..7bfc35b5f 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx @@ -25,7 +25,9 @@ #include #include +#include #include +#include #include @@ -3278,3 +3280,191 @@ void GEOMImpl_IMeasureOperations::FillErrors } } } + +//======================================================================= +//function : ShapeProximityCalculator +//purpose : returns an object to compute the proximity value +//======================================================================= +Handle(GEOM_Object) GEOMImpl_IMeasureOperations::ShapeProximityCalculator + (Handle(GEOM_Object) theShape1, + Handle(GEOM_Object) theShape2) +{ + SetErrorCode(KO); + + if (theShape1.IsNull() || theShape2.IsNull()) + return NULL; + + Handle(GEOM_Function) aShapeFunc1 = theShape1->GetLastFunction(); + Handle(GEOM_Function) aShapeFunc2 = theShape2->GetLastFunction(); + if (aShapeFunc1.IsNull() || aShapeFunc2.IsNull()) + return NULL; + + Handle(GEOM_Object) aProximityCalc = GetEngine()->AddObject(GEOM_SHAPE_PROXIMITY); + if (aProximityCalc.IsNull()) + return NULL; + + Handle(GEOM_Function) aProximityFuncCoarse = + aProximityCalc->AddFunction(GEOMImpl_ShapeProximityDriver::GetID(), PROXIMITY_COARSE); + //Check if the function is set correctly + if (aProximityFuncCoarse.IsNull() || + aProximityFuncCoarse->GetDriverGUID() != GEOMImpl_ShapeProximityDriver::GetID()) + return NULL; + + GEOMImpl_IProximity aProximity (aProximityFuncCoarse); + aProximity.SetShapes(aShapeFunc1, aShapeFunc2); + + //Make a Python command + GEOM::TPythonDump pd (aProximityFuncCoarse); + pd << "p = geompy.ShapeProximity()\n"; + pd << "p.setShapes(" << theShape1 << ", " << theShape2 << ")"; + + SetErrorCode(OK); + return aProximityCalc; +} + +//======================================================================= +//function : SetShapeSampling +//purpose : set number sample points to compute the coarse proximity +//======================================================================= +void GEOMImpl_IMeasureOperations::SetShapeSampling(Handle(GEOM_Object) theCalculator, + Handle(GEOM_Object) theShape, + const Standard_Integer theNbSamples) +{ + SetErrorCode(KO); + if (theShape.IsNull() || + theCalculator.IsNull() || + theCalculator->GetNbFunctions() <= 0 || + theNbSamples <= 0) + return ; + + Handle(GEOM_Function) aProximityFuncCoarse = theCalculator->GetFunction(1); + if (aProximityFuncCoarse.IsNull() || + aProximityFuncCoarse->GetDriverGUID() != GEOMImpl_ShapeProximityDriver::GetID()) + return ; + + Handle(GEOM_Function) aShapeFunc = theShape->GetLastFunction(); + if (aShapeFunc.IsNull()) + return ; + + GEOMImpl_IProximity aProximity(aProximityFuncCoarse); + Handle(GEOM_Function) aShape1, aShape2; + aProximity.GetShapes(aShape1, aShape2); + if (aShape1->GetValue() == aShapeFunc->GetValue()) + aProximity.SetNbSamples(PROXIMITY_ARG_SAMPLES1, theNbSamples); + else if (aShape2->GetValue() == aShapeFunc->GetValue()) + aProximity.SetNbSamples(PROXIMITY_ARG_SAMPLES2, theNbSamples); + + //Make a Python command + GEOM::TPythonDump(aProximityFuncCoarse, /*append=*/true) << + "p.setSampling(" << theShape << ", " << theNbSamples << ")"; + + SetErrorCode(OK); +} + +//======================================================================= +//function : GetCoarseProximity +//purpose : compute coarse proximity +//======================================================================= +Standard_Real GEOMImpl_IMeasureOperations::GetCoarseProximity(Handle(GEOM_Object) theCalculator, + bool doPythonDump) +{ + SetErrorCode(KO); + if (theCalculator.IsNull()) + return -1; + + Handle(GEOM_Function) aProximityFuncCoarse = theCalculator->GetFunction(1); + if (aProximityFuncCoarse.IsNull() || + aProximityFuncCoarse->GetDriverGUID() != GEOMImpl_ShapeProximityDriver::GetID() || + aProximityFuncCoarse->GetType() != PROXIMITY_COARSE) + return -1; + + // Perform + // We have to recompute the function each time, + // because the number of samples can be changed + try { + OCC_CATCH_SIGNALS; + if (!GetSolver()->ComputeFunction(aProximityFuncCoarse)) { + SetErrorCode("shape proximity driver failed"); + return -1; + } + } + catch (Standard_Failure& aFail) { + SetErrorCode(aFail.GetMessageString()); + return -1; + } + + //Make a Python command + if (doPythonDump) + GEOM::TPythonDump(aProximityFuncCoarse, /*append=*/true) << "value = p.coarseProximity()"; + + SetErrorCode(OK); + GEOMImpl_IProximity aProximity (aProximityFuncCoarse); + return aProximity.GetValue(); +} + +//======================================================================= +//function : GetPreciseProximity +//purpose : compute precise proximity +//======================================================================= +Standard_Real GEOMImpl_IMeasureOperations::GetPreciseProximity(Handle(GEOM_Object) theCalculator) +{ + SetErrorCode(KO); + if (theCalculator.IsNull()) + return -1; + + Handle(GEOM_Function) aProximityFuncCoarse = theCalculator->GetFunction(1); + Handle(GEOM_Function) aProximityFuncFine = theCalculator->GetFunction(2); + if (aProximityFuncFine.IsNull()) + aProximityFuncFine = theCalculator->AddFunction + (GEOMImpl_ShapeProximityDriver::GetID(), PROXIMITY_PRECISE); + + //Check if the functions are set correctly + if (aProximityFuncCoarse.IsNull() || + aProximityFuncCoarse->GetDriverGUID() != GEOMImpl_ShapeProximityDriver::GetID() || + aProximityFuncFine.IsNull() || + aProximityFuncFine->GetDriverGUID() != GEOMImpl_ShapeProximityDriver::GetID()) + return -1; + + // perform coarse computation beforehand + GetCoarseProximity(theCalculator, /*doPythonDump=*/false); + + // transfer parameters from the coarse to precise calculator + GEOMImpl_IProximity aCoarseProximity (aProximityFuncCoarse); + Handle(GEOM_Function) aShape1, aShape2; + aCoarseProximity.GetShapes(aShape1, aShape2); + if (aShape1.IsNull() || aShape2.IsNull()) + return -1; + gp_Pnt aProxPnt1, aProxPnt2; + Standard_Integer intStatus1, intStatus2; + aCoarseProximity.GetProximityPoints(aProxPnt1, aProxPnt2); + aCoarseProximity.GetStatusOfPoints(intStatus1, intStatus2); + Standard_Real aResultValue = aCoarseProximity.GetValue(); + + GEOMImpl_IProximity aFineProximity (aProximityFuncFine); + aFineProximity.SetShapes(aShape1, aShape2); + aFineProximity.SetProximityPoints(aProxPnt1, aProxPnt2); + aFineProximity.SetStatusOfPoints(intStatus1, intStatus2); + aFineProximity.SetValue(aResultValue); // in some cases this value cannot be precised + + // Perform + try { + OCC_CATCH_SIGNALS; + if (!GetSolver()->ComputeFunction(aProximityFuncFine)) { + SetErrorCode("shape proximity driver failed"); + return -1; + } + } + catch (Standard_Failure& aFail) { + SetErrorCode(aFail.GetMessageString()); + return -1; + } + + aResultValue = aFineProximity.GetValue(); + aFineProximity.GetProximityPoints(aProxPnt1, aProxPnt2); + + //Make a Python command + GEOM::TPythonDump(aProximityFuncCoarse, /*append=*/true) << "value = p.preciseProximity()"; + + SetErrorCode(OK); + return aResultValue; +} diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx index d896b5da1..3e96a3295 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx @@ -244,6 +244,16 @@ class GEOMImpl_IMeasureOperations : public GEOM_IOperations { Handle(GEOM_Object) thePoint, Handle(GEOM_Object) theDirection); + // Methods to compute proximity between two shapes + Standard_EXPORT Handle(GEOM_Object) ShapeProximityCalculator(Handle(GEOM_Object) theShape1, + Handle(GEOM_Object) theShape2); + Standard_EXPORT Standard_Real GetCoarseProximity(Handle(GEOM_Object) theCalculator, + bool doPythonDump = true); + Standard_EXPORT Standard_Real GetPreciseProximity(Handle(GEOM_Object) theCalculator); + Standard_EXPORT void SetShapeSampling(Handle(GEOM_Object) theCalculator, + Handle(GEOM_Object) theShape, + const Standard_Integer theNbSamples); + private: void FillErrorsSub diff --git a/src/GEOMImpl/GEOMImpl_IProximity.hxx b/src/GEOMImpl/GEOMImpl_IProximity.hxx new file mode 100644 index 000000000..c32a5fdb7 --- /dev/null +++ b/src/GEOMImpl/GEOMImpl_IProximity.hxx @@ -0,0 +1,122 @@ +// Copyright (C) 2022-2022 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 + +#define PROXIMITY_ARG_SHAPE1 1 +#define PROXIMITY_ARG_SHAPE2 2 +#define PROXIMITY_ARG_SAMPLES1 3 +#define PROXIMITY_ARG_SAMPLES2 4 +#define PROXIMITY_ARG_POINT1 5 +#define PROXIMITY_ARG_POINT2 6 +#define PROXIMITY_ARG_VALUE 7 +#define PROXIMITY_ARG_STATUS1 8 +#define PROXIMITY_ARG_STATUS2 9 + +class GEOMImpl_IProximity +{ +public: + + GEOMImpl_IProximity(Handle(GEOM_Function) theFunction) : _func(theFunction) {} + + void SetShapes(Handle(GEOM_Function) theShape1, Handle(GEOM_Function) theShape2) + { + _func->SetReference(PROXIMITY_ARG_SHAPE1, theShape1); + _func->SetReference(PROXIMITY_ARG_SHAPE2, theShape2); + } + + void GetShapes(Handle(GEOM_Function)& theShape1, Handle(GEOM_Function)& theShape2) const + { + theShape1 = _func->GetReference(PROXIMITY_ARG_SHAPE1); + theShape2 = _func->GetReference(PROXIMITY_ARG_SHAPE2); + } + + void SetNbSamples(const Standard_Integer thePosition, const Standard_Integer theNbSamples) const + { + _func->SetInteger(thePosition, theNbSamples); + } + + Standard_Integer GetNbSamples(const Standard_Integer thePosition) const + { + return _func->GetInteger(thePosition); + } + + void SetProximityPoints(const gp_Pnt& thePoint1, const gp_Pnt& thePoint2) + { + setPoint(PROXIMITY_ARG_POINT1, thePoint1); + setPoint(PROXIMITY_ARG_POINT2, thePoint2); + } + + void SetStatusOfPoints(const Standard_Integer theStatus1, const Standard_Integer theStatus2) + { + setStatus(PROXIMITY_ARG_STATUS1, theStatus1); + setStatus(PROXIMITY_ARG_STATUS2, theStatus2); + } + + void GetProximityPoints(gp_Pnt& thePoint1, gp_Pnt& thePoint2) + { + thePoint1 = getPoint(PROXIMITY_ARG_POINT1); + thePoint2 = getPoint(PROXIMITY_ARG_POINT2); + } + + void GetStatusOfPoints(Standard_Integer& theStatus1, Standard_Integer& theStatus2) + { + theStatus1 = getStatus(PROXIMITY_ARG_STATUS1); + theStatus2 = getStatus(PROXIMITY_ARG_STATUS2); + } + + void SetValue(const Standard_Real theValue) + { + _func->SetReal(PROXIMITY_ARG_VALUE, theValue); + } + + Standard_Real GetValue() const + { + return _func->GetReal(PROXIMITY_ARG_VALUE); + } + +private: + void setPoint(const Standard_Integer thePosition, const gp_Pnt& thePoint) + { + Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3); + aCoords->SetValue(1, thePoint.X()); + aCoords->SetValue(2, thePoint.Y()); + aCoords->SetValue(3, thePoint.Z()); + _func->SetRealArray(thePosition, aCoords); + } + + void setStatus(const Standard_Integer thePosition, const Standard_Integer theStatus) + { + _func->SetInteger(thePosition, theStatus); + } + + gp_Pnt getPoint(const Standard_Integer thePosition) + { + Handle(TColStd_HArray1OfReal) aCoords = _func->GetRealArray(thePosition); + return gp_Pnt(aCoords->Value(1), aCoords->Value(2), aCoords->Value(3)); + } + + Standard_Integer getStatus(const Standard_Integer thePosition) + { + return _func->GetInteger(thePosition); + } + +private: + Handle(GEOM_Function) _func; +}; diff --git a/src/GEOMImpl/GEOMImpl_ShapeProximityDriver.cxx b/src/GEOMImpl/GEOMImpl_ShapeProximityDriver.cxx new file mode 100644 index 000000000..e1397efc4 --- /dev/null +++ b/src/GEOMImpl/GEOMImpl_ShapeProximityDriver.cxx @@ -0,0 +1,457 @@ +// Copyright (C) 2022-2022 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + static void tessellateShape(const TopoDS_Shape& theShape) + { + Standard_Boolean isTessellate = Standard_False; + TopLoc_Location aLoc; + for (TopExp_Explorer anExp(theShape, TopAbs_FACE); anExp.More() && !isTessellate; anExp.Next()) + { + Handle(Poly_Triangulation) aTria = BRep_Tool::Triangulation(TopoDS::Face(anExp.Value()), aLoc); + isTessellate = aTria.IsNull(); + } + for (TopExp_Explorer anExp(theShape, TopAbs_EDGE); anExp.More() && !isTessellate; anExp.Next()) + { + Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(TopoDS::Edge(anExp.Value()), aLoc); + isTessellate = aPoly.IsNull(); + } + + if (isTessellate) + { + BRepMesh_IncrementalMesh aMesher(theShape, 0.1); + Standard_ProgramError_Raise_if(!aMesher.IsDone(), "Meshing failed"); + } + } + + static Standard_Real paramOnCurve(const BRepAdaptor_Curve& theCurve, const gp_Pnt& thePoint, const Standard_Real theTol) + { + Extrema_ExtPC aParamSearch(thePoint, theCurve, theCurve.FirstParameter(), theCurve.LastParameter()); + if (aParamSearch.IsDone()) + { + Standard_Integer anIndMin = 0, aNbExt = aParamSearch.NbExt(); + Standard_Real aSqDistMin = RealLast(); + for (Standard_Integer i = 1; i <= aNbExt; ++i) + { + if (aParamSearch.SquareDistance(i) < aSqDistMin) + { + anIndMin = i; + aSqDistMin = aParamSearch.SquareDistance(i); + } + } + if (anIndMin != 0 && aSqDistMin <= theTol * theTol) + { + return aParamSearch.Point(anIndMin).Parameter(); + } + } + return 0.5 * (theCurve.FirstParameter() + theCurve.LastParameter()); + } + + static void paramsOnSurf(const BRepAdaptor_Surface& theSurf, const gp_Pnt& thePoint, const Standard_Real theTol, + Standard_Real& theU, Standard_Real& theV) + { + Extrema_ExtPS aParamSearch(thePoint, theSurf, Precision::PConfusion(), Precision::PConfusion()); + if (aParamSearch.IsDone()) + { + Standard_Integer anIndMin = 0, aNbExt = aParamSearch.NbExt(); + Standard_Real aSqDistMin = RealLast(); + for (Standard_Integer i = 1; i <= aNbExt; ++i) + { + if (aParamSearch.SquareDistance(i) < aSqDistMin) + { + anIndMin = i; + aSqDistMin = aParamSearch.SquareDistance(i); + } + } + if (anIndMin != 0 && aSqDistMin <= theTol * theTol) + { + return aParamSearch.Point(anIndMin).Parameter(theU, theV); + } + } + theU = 0.5 * (theSurf.FirstUParameter() + theSurf.LastUParameter()); + theV = 0.5 * (theSurf.FirstVParameter() + theSurf.LastVParameter()); + } + + static Standard_Real extremaEE(const TopoDS_Edge& theEdge1, const TopoDS_Edge& theEdge2, + gp_Pnt& thePoint1, gp_Pnt& thePoint2) + { + BRepAdaptor_Curve aCurve1(theEdge1); + BRepAdaptor_Curve aCurve2(theEdge2); + + TopLoc_Location aLoc; + Standard_Real aTol1 = BRep_Tool::Tolerance(theEdge1); + Handle(Poly_Polygon3D) aPoly1 = BRep_Tool::Polygon3D (theEdge1, aLoc); + if (!aPoly1.IsNull()) + aTol1 = Max (aTol1, aPoly1->Deflection()); + Standard_Real aTol2 = BRep_Tool::Tolerance(theEdge2); + Handle(Poly_Polygon3D) aPoly2 = BRep_Tool::Polygon3D (theEdge2, aLoc); + if (!aPoly2.IsNull()) + aTol2 = Max (aTol2, aPoly2->Deflection()); + + Standard_Real aU1 = paramOnCurve(aCurve1, thePoint1, 2*aTol1); + Standard_Real aU2 = paramOnCurve(aCurve2, thePoint2, 2*aTol2); + + Standard_Real aValue = -1.0; + Extrema_LocateExtCC anExtr(aCurve1, aCurve2, aU1, aU2); + if (anExtr.IsDone()) + { + aValue = Sqrt(anExtr.SquareDistance()); + + Extrema_POnCurv aP1, aP2; + anExtr.Point(aP1, aP2); + thePoint1 = aP1.Value(); + thePoint2 = aP2.Value(); + } + return aValue; + } + + static Standard_Real extremaPE(const gp_Pnt& thePoint, + const TopoDS_Edge& theEdge, + gp_Pnt& thePointOnEdge) + { + BRepAdaptor_Curve aCurve (theEdge); + + TopLoc_Location aLoc; + Standard_Real aTol = BRep_Tool::Tolerance(theEdge); + Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D (theEdge, aLoc); + if (!aPoly.IsNull()) + aTol = Max (aTol, aPoly->Deflection()); + + Standard_Real aParam = paramOnCurve (aCurve, thePointOnEdge, 2*aTol); + + Standard_Real aValue = -1.0; + Extrema_LocateExtPC anExtr (thePoint, aCurve, aParam, Precision::PConfusion()); + if (anExtr.IsDone()) + { + aValue = Sqrt(anExtr.SquareDistance()); + + Extrema_POnCurv aPointOnCurve = anExtr.Point(); + thePointOnEdge = aPointOnCurve.Value(); + } + return aValue; + } + + static Standard_Real extremaPF(const gp_Pnt& thePoint, + const TopoDS_Face& theFace, + gp_Pnt& thePointOnFace) + { + BRepAdaptor_Surface aSurf (theFace); + + TopLoc_Location aLoc; + Standard_Real aTol = BRep_Tool::Tolerance(theFace); + Handle(Poly_Triangulation) aTria = BRep_Tool::Triangulation (theFace, aLoc); + if (!aTria.IsNull()) + aTol = Max (aTol, aTria->Deflection()); + + Standard_Real aU, aV; + paramsOnSurf(aSurf, thePointOnFace, 2*aTol, aU, aV); + + Standard_Real aValue = -1.0; + Extrema_GenLocateExtPS anExtr (aSurf); + anExtr.Perform (thePoint, aU, aV); + if (anExtr.IsDone()) + { + aValue = Sqrt(anExtr.SquareDistance()); + + Extrema_POnSurf aPointOnSurf = anExtr.Point(); + thePointOnFace = aPointOnSurf.Value(); + } + return aValue; + } + + static Standard_Real extremaEF(const TopoDS_Edge& theEdge, const TopoDS_Face& theFace, + gp_Pnt& thePonE, gp_Pnt& thePonF) + { + BRepAdaptor_Curve aCurve(theEdge); + BRepAdaptor_Surface aSurf(theFace); + + TopLoc_Location aLoc; + Standard_Real aTolEdge = BRep_Tool::Tolerance(theEdge); + Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D (theEdge, aLoc); + if (!aPoly.IsNull()) + aTolEdge = Max (aTolEdge, aPoly->Deflection()); + Standard_Real aTolFace = BRep_Tool::Tolerance(theFace); + Handle(Poly_Triangulation) aTria = BRep_Tool::Triangulation (theFace, aLoc); + if (!aTria.IsNull()) + aTolFace = Max (aTolFace, aTria->Deflection()); + + Standard_Real aP = paramOnCurve(aCurve, thePonE, 2*aTolEdge); + Standard_Real aU, aV; + paramsOnSurf(aSurf, thePonF, 2*aTolFace, aU, aV); + + Standard_Real aValue = -1.0; + Extrema_GenLocateExtCS anExtr(aCurve, aSurf, aP, aU, aV, Precision::PConfusion(), Precision::PConfusion()); + if (anExtr.IsDone()) + { + aValue = Sqrt(anExtr.SquareDistance()); + thePonE = anExtr.PointOnCurve().Value(); + thePonF = anExtr.PointOnSurface().Value(); + } + return aValue; + } + + static Standard_Real extremaFF(const TopoDS_Face& theFace1, const TopoDS_Face& theFace2, + gp_Pnt& thePoint1, gp_Pnt& thePoint2) + { + BRepAdaptor_Surface aSurf1(theFace1); + BRepAdaptor_Surface aSurf2(theFace2); + + TopLoc_Location aLoc; + Standard_Real aTol1 = BRep_Tool::Tolerance(theFace1); + Handle(Poly_Triangulation) aTria1 = BRep_Tool::Triangulation (theFace1, aLoc); + if (!aTria1.IsNull()) + aTol1 = Max (aTol1, aTria1->Deflection()); + Standard_Real aTol2 = BRep_Tool::Tolerance(theFace2); + Handle(Poly_Triangulation) aTria2 = BRep_Tool::Triangulation (theFace2, aLoc); + if (!aTria2.IsNull()) + aTol2 = Max (aTol2, aTria2->Deflection()); + + Standard_Real aU1, aV1; + paramsOnSurf(aSurf1, thePoint1, 2*aTol1, aU1, aV1); + Standard_Real aU2, aV2; + paramsOnSurf(aSurf2, thePoint2, 2*aTol2, aU2, aV2); + + Standard_Real aValue = -1.0; + Extrema_GenLocateExtSS anExtr(aSurf1, aSurf2, aU1, aV1, aU2, aV2, Precision::PConfusion(), Precision::PConfusion()); + if (anExtr.IsDone()) + { + aValue = Sqrt(anExtr.SquareDistance()); + thePoint1 = anExtr.PointOnS1().Value(); + thePoint2 = anExtr.PointOnS2().Value(); + } + return aValue; + } +} + +//======================================================================= +//function : GetID +//purpose : +//======================================================================= +const Standard_GUID& GEOMImpl_ShapeProximityDriver::GetID() +{ + static Standard_GUID aShapeProximityDriver("1C3449A6-E4EB-407D-B623-89261C4BA785"); + return aShapeProximityDriver; +} + +//======================================================================= +//function : Execute +//purpose : +//======================================================================= +Standard_Integer GEOMImpl_ShapeProximityDriver::Execute(Handle(TFunction_Logbook)& log) const +{ + if (Label().IsNull()) + return 0; + + Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label()); + GEOMImpl_IProximity aProximity (aFunction); + + Handle(GEOM_Function) aShapeFunc1, aShapeFunc2; + aProximity.GetShapes(aShapeFunc1, aShapeFunc2); + if (aShapeFunc1.IsNull() || aShapeFunc2.IsNull()) + return 0; + + TopoDS_Shape aShape1 = aShapeFunc1->GetValue(); + TopoDS_Shape aShape2 = aShapeFunc2->GetValue(); + + Standard_Real aValue = -1.0; + + if (aFunction->GetType() == PROXIMITY_COARSE) + { + // tessellate shapes if there is no mesh exists + tessellateShape(aShape1); + tessellateShape(aShape2); + + // compute proximity basing on the tessellation + BRepExtrema_ShapeProximity aCalcProx; + aCalcProx.LoadShape1(aShape1); + aCalcProx.LoadShape2(aShape2); + aCalcProx.SetNbSamples1(aProximity.GetNbSamples(PROXIMITY_ARG_SAMPLES1)); + aCalcProx.SetNbSamples2(aProximity.GetNbSamples(PROXIMITY_ARG_SAMPLES2)); + aCalcProx.Perform(); + + if (aCalcProx.IsDone()) + { + aValue = aCalcProx.Proximity(); + aProximity.SetProximityPoints(aCalcProx.ProximityPoint1(), + aCalcProx.ProximityPoint2()); + aProximity.SetStatusOfPoints((Standard_Integer)aCalcProx.ProxPntStatus1(), + (Standard_Integer)aCalcProx.ProxPntStatus2()); + } + else + Standard_ConstructionError::Raise("Failed to compute coarse proximity"); + } + else if (aFunction->GetType() == PROXIMITY_PRECISE) + { + // coarse proximity value + // in some cases this value cannot be precised + // it can be precised only if at least one point is in the middle of the shape + aValue = aProximity.GetValue(); + + TopAbs_ShapeEnum aType1 = aShape1.ShapeType(); + TopAbs_ShapeEnum aType2 = aShape2.ShapeType(); + + gp_Pnt aPnt1, aPnt2; + BRepExtrema_ProximityDistTool::ProxPnt_Status aStatus1, aStatus2; + Standard_Integer intStatus1, intStatus2; + aProximity.GetProximityPoints(aPnt1, aPnt2); + aProximity.GetStatusOfPoints(intStatus1, intStatus2); + aStatus1 = (BRepExtrema_ProximityDistTool::ProxPnt_Status)intStatus1; + aStatus2 = (BRepExtrema_ProximityDistTool::ProxPnt_Status)intStatus2; + + if (aType1 == TopAbs_EDGE) + { + if (aType2 == TopAbs_EDGE) + { + if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaEE(TopoDS::Edge(aShape1), TopoDS::Edge(aShape2), aPnt1, aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaPE(aPnt1, TopoDS::Edge(aShape2), aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER) + { + aValue = extremaPE(aPnt2, TopoDS::Edge(aShape1), aPnt1); + } + } + else if (aType2 == TopAbs_FACE) + { + if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaEF(TopoDS::Edge(aShape1), TopoDS::Face(aShape2), aPnt1, aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaPF(aPnt1, TopoDS::Face(aShape2), aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER) + { + aValue = extremaPE(aPnt2, TopoDS::Edge(aShape1), aPnt1); + } + } + } + else if (aType1 == TopAbs_FACE) + { + if (aType2 == TopAbs_EDGE) + { + if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaEF(TopoDS::Edge(aShape2), TopoDS::Face(aShape1), aPnt2, aPnt1); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaPE(aPnt1, TopoDS::Edge(aShape2), aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER) + { + aValue = extremaPF(aPnt2, TopoDS::Face(aShape1), aPnt1); + } + } + else if (aType2 == TopAbs_FACE) + { + if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaFF(TopoDS::Face(aShape1), TopoDS::Face(aShape2), aPnt1, aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE) + { + aValue = extremaPF(aPnt1, TopoDS::Face(aShape2), aPnt2); + } + else if (aStatus1 == BRepExtrema_ProximityDistTool::ProxPnt_Status_MIDDLE && + aStatus2 == BRepExtrema_ProximityDistTool::ProxPnt_Status_BORDER) + { + aValue = extremaPF(aPnt2, TopoDS::Face(aShape1), aPnt1); + } + } + } + + if (aValue >= 0) + aProximity.SetProximityPoints(aPnt1, aPnt2); + else + Standard_ConstructionError::Raise("Failed to compute precise proximity"); + } + else + { + Standard_ConstructionError::Raise("incorrect algorithm"); + } + + aProximity.SetValue(aValue); + log->SetTouched(Label()); + return 1; +} + +//======================================================================= +//function : GetCreationInformation +//purpose : Returns a name of creation operation and names and values of creation parameters +//======================================================================= +bool GEOMImpl_ShapeProximityDriver::GetCreationInformation( + std::string& theOperationName, + std::vector& theParams) +{ + if (Label().IsNull()) + return false; + + Handle(GEOM_Function) aFunc = GEOM_Function::GetFunction(Label()); + GEOMImpl_IProximity aProxFunc(aFunc); + Handle(GEOM_Function) aShape1, aShape2; + aProxFunc.GetShapes(aShape1, aShape2); + + if (aFunc->GetType() == PROXIMITY_COARSE) + theOperationName = "PROXIMITY_COARSE"; + else if (aFunc->GetType() == PROXIMITY_PRECISE) + theOperationName = "PROXIMITY_PRECISE"; + + AddParam(theParams, "Shape1", aShape1); + AddParam(theParams, "Shape2", aShape2); + + return false; +} + +IMPLEMENT_STANDARD_RTTIEXT(GEOMImpl_ShapeProximityDriver, GEOM_BaseDriver) diff --git a/src/GEOMImpl/GEOMImpl_ShapeProximityDriver.hxx b/src/GEOMImpl/GEOMImpl_ShapeProximityDriver.hxx new file mode 100644 index 000000000..3a1312e2f --- /dev/null +++ b/src/GEOMImpl/GEOMImpl_ShapeProximityDriver.hxx @@ -0,0 +1,45 @@ +// Copyright (C) 2022-2022 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 +// +#ifndef _GEOMImpl_ShapeProximityDriver_HeaderFile +#define _GEOMImpl_ShapeProximityDriver_HeaderFile + +#include + +DEFINE_STANDARD_HANDLE(GEOMImpl_ShapeProximityDriver, GEOM_BaseDriver) + +class GEOMImpl_ShapeProximityDriver : public GEOM_BaseDriver { + +public: + + Standard_EXPORT GEOMImpl_ShapeProximityDriver() {} + Standard_EXPORT virtual Standard_Integer Execute(Handle(TFunction_Logbook)& log) const; + Standard_EXPORT virtual void Validate(Handle(TFunction_Logbook)&) const {} + Standard_EXPORT Standard_Boolean MustExecute(const Handle(TFunction_Logbook)&) const { return Standard_True; } + + Standard_EXPORT static const Standard_GUID& GetID(); + Standard_EXPORT ~GEOMImpl_ShapeProximityDriver() {} + + Standard_EXPORT virtual + bool GetCreationInformation(std::string& theOperationName, + std::vector& params); + + DEFINE_STANDARD_RTTIEXT(GEOMImpl_ShapeProximityDriver, GEOM_BaseDriver) +}; + +#endif diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index fec26368a..8984fe939 100644 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -125,6 +125,7 @@ #define GEOM_PATCH_FACE 60 +#define GEOM_SHAPE_PROXIMITY 61 #define GEOM_CHECKCONFORMITY 62 //GEOM_Function types @@ -365,6 +366,10 @@ #define VERTEX_BY_INDEX 5 #define CURVATURE_VEC_MEASURE 6 +// Proximity algorithms +#define PROXIMITY_COARSE 1 +#define PROXIMITY_PRECISE 2 + #define GROUP_FUNCTION 1 // Curve constructor type diff --git a/src/GEOM_I/GEOM_IMeasureOperations_i.cc b/src/GEOM_I/GEOM_IMeasureOperations_i.cc index c2bffa8e9..e829aceab 100644 --- a/src/GEOM_I/GEOM_IMeasureOperations_i.cc +++ b/src/GEOM_I/GEOM_IMeasureOperations_i.cc @@ -1443,3 +1443,97 @@ void GEOM_IMeasureOperations_i::ConvertToList(const GEOM::GEOM_IMeasureOperation theListOfResults.push_back(aCheck); } } + +//============================================================================= +/*! + * ShapeProximityCalculator + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::ShapeProximityCalculator(GEOM::GEOM_Object_ptr theShape1, + GEOM::GEOM_Object_ptr theShape2) +{ + GEOM::GEOM_Object_var anEmptyCalc; + + //Set a not done flag + GetOperations()->SetNotDone(); + + //Get the reference shape + Handle(::GEOM_Object) aShape1 = GetObjectImpl(theShape1); + Handle(::GEOM_Object) aShape2 = GetObjectImpl(theShape2); + if (aShape1.IsNull() || aShape2.IsNull()) + return anEmptyCalc._retn(); + + Handle(::GEOM_Object) aCalculator = GetOperations()->ShapeProximityCalculator(aShape1, aShape2); + if (!GetOperations()->IsDone() || aCalculator.IsNull()) + return anEmptyCalc._retn(); + + return GetObject(aCalculator); +} + +//============================================================================= +/*! + * SetShapeSampling + */ + //============================================================================= +void GEOM_IMeasureOperations_i::SetShapeSampling(GEOM::GEOM_Object_ptr theCalculator, + GEOM::GEOM_Object_ptr theShape, + CORBA::Long theNbSamples) +{ + //Set a not done flag + GetOperations()->SetNotDone(); + + //Get the proximity calculator + Handle(::GEOM_Object) aCalc = GetObjectImpl(theCalculator); + if (aCalc.IsNull()) + return ; + //Get the reference shape + Handle(::GEOM_Object) aShape = GetObjectImpl(theShape); + if (aShape.IsNull()) + return ; + + GetOperations()->SetShapeSampling(aCalc, aShape, theNbSamples); +} + +//============================================================================= +/*! + * GetCoarseProximity + */ + //============================================================================= +CORBA::Double GEOM_IMeasureOperations_i::GetCoarseProximity(GEOM::GEOM_Object_ptr theCalculator) +{ + //Set a not done flag + GetOperations()->SetNotDone(); + + //Get the reference shape + Handle(::GEOM_Object) aCalc = GetObjectImpl(theCalculator); + if (aCalc.IsNull()) + return -1.0; + + Standard_Real aProximity = GetOperations()->GetCoarseProximity(aCalc); + if (!GetOperations()->IsDone()) + return -1.0; + + return aProximity; +} + +//============================================================================= +/*! + * GetPreciseProximity + */ + //============================================================================= +CORBA::Double GEOM_IMeasureOperations_i::GetPreciseProximity(GEOM::GEOM_Object_ptr theCalculator) +{ + //Set a not done flag + GetOperations()->SetNotDone(); + + //Get the reference shape + Handle(::GEOM_Object) aCalc = GetObjectImpl(theCalculator); + if (aCalc.IsNull()) + return -1.0; + + Standard_Real aProximity = GetOperations()->GetPreciseProximity(aCalc); + if (!GetOperations()->IsDone()) + return -1.0; + + return aProximity; +} diff --git a/src/GEOM_I/GEOM_IMeasureOperations_i.hh b/src/GEOM_I/GEOM_IMeasureOperations_i.hh index 630218c04..ded2f9c41 100644 --- a/src/GEOM_I/GEOM_IMeasureOperations_i.hh +++ b/src/GEOM_I/GEOM_IMeasureOperations_i.hh @@ -191,6 +191,15 @@ class GEOM_I_EXPORT GEOM_IMeasureOperations_i : CORBA::Double UpdateTolerance(GEOM::GEOM_Object_ptr theShape); + // Methods to compute proximity between two shapes + GEOM::GEOM_Object_ptr ShapeProximityCalculator (GEOM::GEOM_Object_ptr theShape1, + GEOM::GEOM_Object_ptr theShape2); + void SetShapeSampling(GEOM::GEOM_Object_ptr theCalculator, + GEOM::GEOM_Object_ptr theShape, + CORBA::Long theNbSamples); + CORBA::Double GetCoarseProximity(GEOM::GEOM_Object_ptr theCalculator); + CORBA::Double GetPreciseProximity(GEOM::GEOM_Object_ptr theCalculator); + ::GEOMImpl_IMeasureOperations* GetOperations() { return (::GEOMImpl_IMeasureOperations*)GetImpl(); } diff --git a/src/GEOM_SWIG/CMakeLists.txt b/src/GEOM_SWIG/CMakeLists.txt index e9b78cadc..5735fa949 100644 --- a/src/GEOM_SWIG/CMakeLists.txt +++ b/src/GEOM_SWIG/CMakeLists.txt @@ -73,6 +73,7 @@ SET(_python_SCRIPTS gsketcher.py canonicalrecognition.py conformity.py + proximity.py ) # Advanced scripts diff --git a/src/GEOM_SWIG/geomBuilder.py b/src/GEOM_SWIG/geomBuilder.py index cf5a9dba0..d28107781 100644 --- a/src/GEOM_SWIG/geomBuilder.py +++ b/src/GEOM_SWIG/geomBuilder.py @@ -262,6 +262,7 @@ import functools from salome.geom.gsketcher import Sketcher3D, Sketcher2D, Polyline2D from salome.geom.canonicalrecognition import CanonicalRecognition from salome.geom.conformity import CheckConformity +from salome.geom.proximity import ShapeProximity # In case the omniORBpy EnumItem class does not fully support Python 3 # (for instance in version 4.2.1-2), the comparison ordering methods must be @@ -14056,6 +14057,21 @@ class geomBuilder(GEOM._objref_GEOM_Gen): conf = CheckConformity (shape, self) return conf + ## Obtain a shape proximity calculator + # @return An instance of @ref proximity.ShapeProximity "ShapeProximity" interface + # + # @ref tui_proximity_page "Example" + def ShapeProximity (self): + """ + Obtain a shape proximity calculator. + + Example of usage: + prox = geompy.ShapeProximity() + value = prox.proximity(shape1, shape2) + """ + prox = ShapeProximity (self) + return prox + # end of l2_testing ## @} diff --git a/src/GEOM_SWIG/proximity.py b/src/GEOM_SWIG/proximity.py new file mode 100644 index 000000000..ac24fbe12 --- /dev/null +++ b/src/GEOM_SWIG/proximity.py @@ -0,0 +1,91 @@ +# -*- coding: iso-8859-1 -*- +# Copyright (C) 2022-2022 CEA/DEN, EDF R&D, OPEN CASCADE +# +# 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 + +## @defgroup proximity ShapeProximity - tool to check the proximity distance between two shapes +# @{ +# @details +# The tool provides the user a possibility to compute the proximity distance between two shapes: +# * a minimal diameter of a tube containing both edges (for edge-edge proximity); +# * a minimal thickness of a shell containing both faces (for face-face proximity). +# +# In other words, this tool calculate maximal of all possible distances between pair of objects. +# It is supported to compute distance between two edges or between two faces. +# Other combinations of shapes are prohibited. +# @} + +""" + \namespace geompy + \brief ShapeProximity interface +""" + +## A class to compute proximity value between two shapes. +# Use geompy.ShapeProximity() method to obtain an instance of this class. +# +# @ref tui_proximity_page "Example" +# @ingroup proximity +class ShapeProximity(): + """ + ShapeProximity interface. + + Example of usage: + prox = geompy.ShapeProximity() + value = prox.proximity(shape1, shape2) + """ + + def __init__(self, geompyD): + self.myCommand = "ShapeProximity" + self.myOp = geompyD.GetIMeasureOperations() + pass + + ## Computes proximity between two shapes of the same type + def proximity(self, shape1, shape2): + self.setShapes(shape1, shape2) + #self.coarseProximity() + return self.preciseProximity() + pass + + ## Customize object with the input shapes + def setShapes(self, shape1, shape2): + self.myProximityValue = None + from salome.geom.geomBuilder import RaiseIfFailed + self.myCalc = self.myOp.ShapeProximityCalculator(shape1, shape2) + RaiseIfFailed(self.myCommand, self.myOp) + pass + + ## Define the minimal number of sample points for the given shape, + # which should be used for raw computation of proximity value + def setSampling(self, shape, nbSamples): + self.myOp.SetShapeSampling(self.myCalc, shape, nbSamples) + pass + + ## Find rough proximity value based on polygon/tessellation representation + def coarseProximity(self): + from salome.geom.geomBuilder import RaiseIfFailed + self.myProximityValue = self.myOp.GetCoarseProximity(self.myCalc) + RaiseIfFailed(self.myCommand, self.myOp) + return self.myProximityValue + pass + + ## Find precise proximity value based on exact shapes + def preciseProximity(self): + from salome.geom.geomBuilder import RaiseIfFailed + self.myProximityValue = self.myOp.GetPreciseProximity(self.myCalc) + RaiseIfFailed(self.myCommand, self.myOp) + return self.myProximityValue + pass diff --git a/test/test_proximity_edge_edge.py b/test/test_proximity_edge_edge.py new file mode 100644 index 000000000..9c8e7329c --- /dev/null +++ b/test/test_proximity_edge_edge.py @@ -0,0 +1,130 @@ +# Shape Proximity between edges + +import math +import salome +salome.salome_init_without_session() +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New() + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) + +# Case 1: two bezier curves (original Cas2_29468.py) +from math import sqrt + +# 283x384 +szY = 384 +listOfPtsRed_gimp = [(10,84), (54,96),(145,146),(167,167),(185,212),(187,234),(176,302)] +listOfPtsBlue_gimp = [(120,72),(170,87),(227,118),(238,126),(243,157),(203,216),(134,281),(94,324)] +# +listOfPtsRed = [(x,szY-y) for x,y in listOfPtsRed_gimp] +listOfPtsBlue = [(x,szY-y) for x,y in listOfPtsBlue_gimp] +# +verticesRed = [geompy.MakeVertex(x,y,0) for x,y in listOfPtsRed] +verticesBlue = [geompy.MakeVertex(x,y,0) for x,y in listOfPtsBlue] +for i,(x,y) in enumerate(listOfPtsRed): + geompy.addToStudy(geompy.MakeVertex(x,y,0),"red_pt{}".format(i)) +for i,(x,y) in enumerate(listOfPtsBlue): + geompy.addToStudy(geompy.MakeVertex(x,y,0),"blue_pt{}".format(i)) +redEdge = geompy.MakeBezier(verticesRed) +blueEdge = geompy.MakeBezier(verticesBlue) +# +geompy.addToStudy(redEdge,"red") +geompy.addToStudy(blueEdge,"blue") + +XY_red = (152,214) +XY_blue = (215,260) +exp_red = geompy.MakeVertex(*XY_red,0) +exp_blue = geompy.MakeVertex(*XY_blue,0) +geompy.addToStudy(exp_red,"exp_red") +geompy.addToStudy(exp_blue,"exp_blue") + +p = geompy.ShapeProximity() +p.setShapes(redEdge, blueEdge) +p.setSampling(redEdge, 1000) +p.setSampling(blueEdge, 1000) +p_coarse = p.coarseProximity() +p_precise = p.preciseProximity() +print( "coarse = {} ; fine = {}".format(p_coarse,p_precise) ) +print( "Manually obtained value = {}".format( sqrt( (XY_red[0]-XY_blue[0])**2 + (XY_red[1]-XY_blue[1])**2 ) ) ) + +assert(math.fabs(p_coarse - 223.00892775) < 1.e-7) + +prev = geompy.ShapeProximity() +prev.setShapes(blueEdge, redEdge) +prev.setSampling(redEdge, 1000) +prev.setSampling(blueEdge, 1000) +p_coarse = prev.coarseProximity() +p_precise = prev.preciseProximity() +print( "coarse = {} ; fine = {}".format(p_coarse,p_precise) ) + +assert(math.fabs(p_coarse - 84.89994110) < 1.e-7) + +# Case 2: two bezier curves (different coarse and fine proximities) +V1 = geompy.MakeVertex(10, 10, 0) +V2 = geompy.MakeVertex(20, -10, 0) +V3 = geompy.MakeVertex(30, 0, 0) +V4 = geompy.MakeVertex(0, -3, 0) +V5 = geompy.MakeVertex(13, -10, 0) +V6 = geompy.MakeVertex(25, 10, 0) +V7 = geompy.MakeVertex(30, 5, 0) +BC1 = geompy.MakeBezier([ O, V1, V2, V3], False, "BC1") +BC2 = geompy.MakeBezier([V4, V5, V6, V7], False, "BC2") + +pcalc = geompy.ShapeProximity() +pcalc.setShapes(BC1, BC2) +p_coarse = pcalc.coarseProximity() +p_fine = pcalc.preciseProximity() + +assert(math.fabs(p_coarse - 7.3126564) < 1.e-7) +assert(math.fabs(p_fine - 7.380468495) < 1.e-7) + +# Case 3: arc and segment +Vertex_1 = geompy.MakeVertex(0, 0, -1) +Vertex_2 = geompy.MakeVertex(1, 0, 0) +Vertex_3 = geompy.MakeVertex(0, 0, 1) +Arc_1 = geompy.MakeArc(Vertex_1, Vertex_2, Vertex_3) +Arc_1_vertex_2 = geompy.GetSubShape(Arc_1, [2]) +Edge_1 = geompy.MakeEdgeOnCurveByLength(Arc_1, 3, Arc_1_vertex_2) +Edge_2 = geompy.MakeEdge(Vertex_1, Vertex_3) + +shape1 = Edge_1 +shape2 = Edge_2 + +# perform proximity calculation with the default parameters +p1 = geompy.ShapeProximity() +proximity1 = p1.proximity(shape1, shape2) + +# perform proximity calculation with custom parameters +p2 = geompy.ShapeProximity() +p2.setShapes(shape1, shape2) +p2.setSampling(shape1, 100) # number of sample points for the first shape +p2.setSampling(shape2, 40) # number of sample points for the second shape +proximity2_coarse = p2.coarseProximity() +proximity2_fine = p2.preciseProximity() + +assert(math.fabs(proximity1 - proximity2_fine) < 1.e-7) +assert(math.fabs(proximity2_coarse - 0.99998769) < 1.e-7) +assert(math.fabs(proximity2_fine - 1) < 1.e-7) + +# move second edge and check proximity +Translation_1 = geompy.MakeTranslation(Edge_2, 0.3, 0, 0) +shape2 = Translation_1 + +# perform proximity calculation with the default parameters +p1 = geompy.ShapeProximity() +proximity1 = p1.proximity(shape1, shape2) + +# perform proximity calculation with custom parameters +p2 = geompy.ShapeProximity() +p2.setShapes(shape1, shape2) +p2.setSampling(shape1, 100) # number of sample points for the first shape +p2.setSampling(shape2, 40) # number of sample points for the second shape +proximity2_coarse = p2.coarseProximity() +proximity2_fine = p2.preciseProximity() + +assert(math.fabs(proximity1 - 0.7) < 1.e-7) +assert(math.fabs(proximity2_fine - 0.7) < 1.e-7) diff --git a/test/test_proximity_face_face.py b/test/test_proximity_face_face.py new file mode 100644 index 000000000..a143709ba --- /dev/null +++ b/test/test_proximity_face_face.py @@ -0,0 +1,87 @@ +# Shape Proximity between faces + +import math +import salome +salome.salome_init_without_session() +import GEOM +from salome.geom import geomBuilder +geompy = geomBuilder.New() + +O = geompy.MakeVertex(0, 0, 0) +OX = geompy.MakeVectorDXDYDZ(1, 0, 0) +OY = geompy.MakeVectorDXDYDZ(0, 1, 0) +OZ = geompy.MakeVectorDXDYDZ(0, 0, 1) + +# Case 1: cylinder and sphere (different coarse and fine proximities) +OCyl = geompy.MakeVertex(0, -5, 15) +Cyl = geompy.MakeCylinder(OCyl, OY, 3, 10, "Cyl") +AX1 = geompy.MakeTranslation(OX, 0, 0, 15, "AX1") +geompy.Rotate(Cyl, AX1, -20.0*math.pi/180.0) +Cyl_face = geompy.SubShapeAllSortedCentres(Cyl, geompy.ShapeType["FACE"], "Face")[1] +Sph = geompy.MakeSphereR(10, "Sph") +Box_1 = geompy.MakeBoxDXDYDZ(40, 40, 27.071067) +Translation_1 = geompy.MakeTranslation(Box_1, -20, -20, -20) +Cut_1 = geompy.MakeCutList(Sph, [Translation_1], True, "Cut_1") +Sph_face = geompy.SubShapeAllSortedCentres(Cut_1, geompy.ShapeType["FACE"], "Face")[1] + +pcalc = geompy.ShapeProximity() +#pcalc.setShapes(Cyl_face, Sph_face) +pcalc.setShapes(Sph_face, Cyl_face) +p_coarse = pcalc.coarseProximity() +p_fine = pcalc.preciseProximity() + +assert(math.fabs(p_coarse - 9.8649933) < 1.e-7) +assert(math.fabs(p_fine - 7.6984631) < 1.e-7) + +geompy.MakeVertex(0, 2.63303, 17.2342, "p1") +geompy.MakeVertex(0, 0, 10, "p2") + +print("With sampling 0: coarse = {} ; fine = {}".format(p_coarse, p_fine)) + +pcalc.setSampling(Cyl_face, 100) # number of sample points for the first shape +pcalc.setSampling(Sph_face, 100) # number of sample points for the second shape +p_coarse = pcalc.coarseProximity() +p_fine = pcalc.preciseProximity() + +print("With sampling 100: coarse = {} ; fine = {}".format(p_coarse, p_fine)) + +pcalc.setSampling(Cyl_face, 1000) # number of sample points for the first shape +pcalc.setSampling(Sph_face, 1000) # number of sample points for the second shape +p_coarse = pcalc.coarseProximity() +p_fine = pcalc.preciseProximity() + +print("With sampling 1000: coarse = {} ; fine = {}".format(p_coarse, p_fine)) + +# Case 2: conical and planar faces +Cone_1 = geompy.MakeConeR1R2H(100, 0, 300) +Cone_1_face_3 = geompy.GetSubShape(Cone_1, [3]) +Cone_1_wire_4 = geompy.GetSubShape(Cone_1, [4]) +Face_1 = geompy.MakeFaceFromSurface(Cone_1_face_3, Cone_1_wire_4, "Face_1") +Face_1_edge_5 = geompy.GetSubShape(Face_1, [5]) +Face_2 = geompy.MakeFaceObjHW(Face_1_edge_5, 200, 200) +geompy.Rotate(Face_2, OY, 90*math.pi/180.0) +Face_2_vertex_7 = geompy.GetSubShape(Face_2, [7]) +Translation_1 = geompy.MakeTranslationTwoPoints(Face_2, Face_2_vertex_7, O, "Translation_1") + +shape1 = Face_1 +shape2 = Translation_1 + +# perform proximity calculation with the default parameters +p1 = geompy.ShapeProximity() +proximity1 = p1.proximity(shape1, shape2) + +# perform proximity calculation with custom parameters +p2 = geompy.ShapeProximity() +p2.setShapes(shape1, shape2) +p2.setSampling(shape1, 100) # number of sample points for the first shape +p2.setSampling(shape2, 40) # number of sample points for the second shape +proximity2_coarse = p2.coarseProximity() +proximity2_fine = p2.preciseProximity() + +assert(math.fabs(proximity1 - proximity2_fine) < 1.e-7) +assert(math.fabs(proximity2_coarse - 127.1141386) < 1.e-7) +#assert(math.fabs(proximity2_fine - 94.8683298) < 1.e-7) +assert(math.fabs(proximity2_fine - 127.1141386) < 1.e-7) + +geompy.MakeVertex(0, 0, 300, "p3") +geompy.MakeVertex(-63.2456, 0, 189.737, "p4") diff --git a/test/tests.set b/test/tests.set index 1688ac2c7..7a002556f 100644 --- a/test/tests.set +++ b/test/tests.set @@ -27,5 +27,7 @@ IF(${OpenCASCADE_VERSION}.${OpenCASCADE_SP_VERSION} VERSION_GREATER "7.5.3.3") test_point_cloud_on_face.py test_CR.py test_conformity.py + test_proximity_edge_edge.py + test_proximity_face_face.py ) ENDIF() -- 2.39.2