0021189: [CEA 451] areCoordsInside implementation in GE

This commit is contained in:
vsr 2011-02-18 07:55:09 +00:00
parent ef26af8d03
commit a3cc005370
6 changed files with 87 additions and 0 deletions

View 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.

View 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

View 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,

View 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

View 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,

View 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.