]> SALOME platform Git repositories - modules/geom.git/commitdiff
Salome HOME
0021189: [CEA 451] areCoordsInside implementation in GE
authorvsr <vsr@opencascade.com>
Fri, 18 Feb 2011 07:55:09 +0000 (07:55 +0000)
committervsr <vsr@opencascade.com>
Fri, 18 Feb 2011 07:55:09 +0000 (07:55 +0000)
idl/GEOM_Gen.idl
src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx
src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx
src/GEOM_I/GEOM_IMeasureOperations_i.cc
src/GEOM_I/GEOM_IMeasureOperations_i.hh
src/GEOM_SWIG/geompyDC.py

index 142b0585c7ad64119095dd2aa982bcdcb6f4516d..bde038897eab5d9685fc6b62d13b2acddf7c65cd 100644 (file)
@@ -138,6 +138,7 @@ module GEOM
 
   typedef sequence<string>      string_array;
   typedef sequence<short>       short_array;
+  typedef sequence<boolean>     ListOfBool;
   typedef sequence<long>        ListOfLong;
   typedef sequence<double>      ListOfDouble;
 
@@ -3141,6 +3142,16 @@ module GEOM
      */
     string WhatIs (in GEOM_Object theShape);
 
+    /*!
+     *  Check if points defined by coords = [x1, y1, z1, x2, y2, z2, ...] are inside or on
+     *  the shape theShape.
+     *  \param theShape Shape to check.
+     *  \param coords list of coordinates.
+     *  \param tolerance tolerance.
+     *  \return list of boolean.
+     */
+    ListOfBool AreCoordsInside(in GEOM_Object theShape, in ListOfDouble coords, in double tolerance);
+
     /*!
      *  Get minimal distance between the given shapes.
      *  \param theShape1,theShape2 Shapes to find minimal distance between.
index d0ac43e7cd89e8b5f78151ae3c2bde92a23e3ae5..57deaa5d7f5c75ca3debf41f30fa7b8dc5d9e373 100644 (file)
@@ -1680,6 +1680,37 @@ static bool CheckSingularCase(const TopoDS_Shape& aSh1,
 */
 
 
+//=============================================================================
+/*!
+ *  AreCoordsInside
+ */
+//=============================================================================
+std::vector<bool> GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape,
+                                                              const std::vector<double>& coords,
+                                                              double tolerance)
+{
+  std::vector<bool> res;
+  if (!theShape.IsNull()) {
+    Handle(GEOM_Function) aRefShape = theShape->GetLastFunction();
+    if (!aRefShape.IsNull()) {
+      TopoDS_Shape aShape = aRefShape->GetValue();
+      if (!aShape.IsNull()) {
+       BRepClass3d_SolidClassifier SC(aShape);
+       unsigned int nb_points = coords.size()/3;
+       for (int i = 0; i < nb_points; i++) {
+         double x = coords[3*i];
+         double y = coords[3*i+1];
+         double z = coords[3*i+2];
+         gp_Pnt aPnt(x, y, z);
+         SC.Perform(aPnt, tolerance);
+         res.push_back( ( SC.State() == TopAbs_IN ) || ( SC.State() == TopAbs_ON ) );
+       }
+      }
+    }
+  }
+  return res;
+}
+
 //=============================================================================
 /*!
  *  GetMinDistance
index f48d4d8fe70891a07769817ecfbee9c6f1549663..5696d48ccacf23ac8431cccefb1735ff48b2f8e4 100644 (file)
@@ -34,6 +34,7 @@
 #include <TColStd_HSequenceOfReal.hxx>
 #include <gp_Ax3.hxx>
 #include <Geom_Surface.hxx>
+#include <Precision.hxx>
 
 class GEOM_Engine;
 class Handle(GEOM_Object);
@@ -128,6 +129,10 @@ class GEOMImpl_IMeasureOperations : public GEOM_IOperations {
 
   Standard_EXPORT TCollection_AsciiString WhatIs (Handle(GEOM_Object) theShape);
 
+  Standard_EXPORT std::vector<bool> AreCoordsInside (Handle(GEOM_Object) theShape,
+                                                    const std::vector<double>& coords,
+                                                    double tolerance = Precision::Confusion());
+
   Standard_EXPORT Standard_Real GetMinDistance (Handle(GEOM_Object) theShape1,
                                                 Handle(GEOM_Object) theShape2,
                                                 Standard_Real& X1, Standard_Real& Y1, Standard_Real& Z1,
index e76c9da8839743cdb3787407c065e0cf9603348d..dc6f9c0c6b2aa7ed0aeda236ddfbbfa0ccf95ece 100644 (file)
@@ -386,6 +386,34 @@ char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
   return CORBA::string_dup(aDescription.ToCString());
 }
 
+//=============================================================================
+/*!
+ *  AreCoordsInside
+ */
+//=============================================================================
+GEOM::ListOfBool* GEOM_IMeasureOperations_i::AreCoordsInside (GEOM::GEOM_Object_ptr theShape,
+                                                             const GEOM::ListOfDouble& theCoords,
+                                                             CORBA::Double tolerance)
+{
+  //Set a not done flag
+  GetOperations()->SetNotDone();
+  
+  unsigned int nb_points = theCoords.length()/3;
+
+  GEOM::ListOfBool_var aResults = new GEOM::ListOfBool;
+  aResults->length(nb_points);
+  
+  Handle(GEOM_Object) aShape = GetObjectImpl(theShape);
+  
+  std::vector<double> tmp(3*nb_points);
+  for (int i = 0; i < 3*nb_points; i++)
+    tmp[i] = theCoords[i];
+  std::vector<bool> res = GetOperations()->AreCoordsInside(aShape, tmp, tolerance);
+  for (int i = 0; i < nb_points; i++)
+    aResults[i] = i < res.size() ? res[i] : false;
+  return aResults._retn();
+}
+
 //=============================================================================
 /*!
  *  GetMinDistance
index 591971d0f38070180384edf7d1e9119ddf69dd62..af88d448f4b08234f3af560d88fc390551118c1d 100644 (file)
@@ -88,6 +88,10 @@ class GEOM_I_EXPORT GEOM_IMeasureOperations_i :
 
   char* WhatIs (GEOM::GEOM_Object_ptr theShape);
 
+  GEOM::ListOfBool* AreCoordsInside (GEOM::GEOM_Object_ptr theShape,
+                                    const GEOM::ListOfDouble& theCoords,
+                                    CORBA::Double theTolerance);
+
   CORBA::Double GetMinDistance (GEOM::GEOM_Object_ptr theShape1,
                                GEOM::GEOM_Object_ptr theShape2,
                                 CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
index 3a97c58ed6a6056ffd37e321789bb8563f9f3fc7..0d54181253c3cbaab2ebb2cebf92a970b3e80af5 100644 (file)
@@ -3324,6 +3324,14 @@ class geompyDC(GEOM._objref_GEOM_Gen):
             RaiseIfFailed("GetInertia", self.MeasuOp)
             return aTuple
 
+        ## Get if coords are included in the shape (ST_IN or ST_ON)
+        #  @param theShape Shape 
+        #  @param coords list of points coordinates [x1, y1, z1, x2, y2, z2, ...]
+        #  @param tolerance to be used (default is 1.0e-7)
+        #  @return list_of_boolean = [res1, res2, ...]
+        def AreCoordsInside(self, theShape, coords, tolerance=1.e-7):
+            return self.MeasuOp.AreCoordsInside(theShape, coords, tolerance)
+
         ## Get minimal distance between the given shapes.
         #  @param theShape1,theShape2 Shapes to find minimal distance between.
         #  @return Value of the minimal distance between the given shapes.