From a3cc00537074b4477ecf5585ee51a5860ead8b9f Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 18 Feb 2011 07:55:09 +0000 Subject: [PATCH] 0021189: [CEA 451] areCoordsInside implementation in GE --- idl/GEOM_Gen.idl | 11 +++++++ src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx | 31 ++++++++++++++++++++ src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx | 5 ++++ src/GEOM_I/GEOM_IMeasureOperations_i.cc | 28 ++++++++++++++++++ src/GEOM_I/GEOM_IMeasureOperations_i.hh | 4 +++ src/GEOM_SWIG/geompyDC.py | 8 +++++ 6 files changed, 87 insertions(+) diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 142b0585c..bde038897 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -138,6 +138,7 @@ module GEOM typedef sequence string_array; typedef sequence short_array; + typedef sequence ListOfBool; typedef sequence ListOfLong; typedef sequence 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. diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx index d0ac43e7c..57deaa5d7 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx @@ -1680,6 +1680,37 @@ static bool CheckSingularCase(const TopoDS_Shape& aSh1, */ +//============================================================================= +/*! + * AreCoordsInside + */ +//============================================================================= +std::vector GEOMImpl_IMeasureOperations::AreCoordsInside(Handle(GEOM_Object) theShape, + const std::vector& coords, + double tolerance) +{ + std::vector 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 diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx index f48d4d8fe..5696d48cc 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx @@ -34,6 +34,7 @@ #include #include #include +#include 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 AreCoordsInside (Handle(GEOM_Object) theShape, + const std::vector& 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, diff --git a/src/GEOM_I/GEOM_IMeasureOperations_i.cc b/src/GEOM_I/GEOM_IMeasureOperations_i.cc index e76c9da88..dc6f9c0c6 100644 --- a/src/GEOM_I/GEOM_IMeasureOperations_i.cc +++ b/src/GEOM_I/GEOM_IMeasureOperations_i.cc @@ -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 tmp(3*nb_points); + for (int i = 0; i < 3*nb_points; i++) + tmp[i] = theCoords[i]; + std::vector 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 diff --git a/src/GEOM_I/GEOM_IMeasureOperations_i.hh b/src/GEOM_I/GEOM_IMeasureOperations_i.hh index 591971d0f..af88d448f 100644 --- a/src/GEOM_I/GEOM_IMeasureOperations_i.hh +++ b/src/GEOM_I/GEOM_IMeasureOperations_i.hh @@ -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, diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index 3a97c58ed..0d5418125 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -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. -- 2.39.2