#54769: isCylinder with parameters generates UNKNOWN_UserException

- Check that given direction values are valid Direction
 - Provide output parameters of surfaces for all cases
This commit is contained in:
vsv 2022-06-22 19:22:24 +03:00
parent 945a7450c6
commit 79fe2f5884
2 changed files with 136 additions and 110 deletions

View File

@ -60,6 +60,11 @@ GEOM_ICanonicalRecognition_i::~GEOM_ICanonicalRecognition_i()
MESSAGE("GEOM_ICanonicalRecognition_i::~GEOM_ICanonicalRecognition_i"); MESSAGE("GEOM_ICanonicalRecognition_i::~GEOM_ICanonicalRecognition_i");
} }
static bool isValidDirection(const GEOM::ListOfDouble& theDir)
{
return (theDir.length() == 3) && (gp_Vec(theDir[0], theDir[1], theDir[2]).Magnitude() > 0.);
}
//============================================================================= //=============================================================================
/* /*
* \brief Check if the shape is planar * \brief Check if the shape is planar
@ -70,7 +75,7 @@ CORBA::Boolean GEOM_ICanonicalRecognition_i::isPlane(GEOM::GEOM_Object_ptr theSh
{ {
Handle(::GEOM_Object) go = GetObjectImpl(theShape); Handle(::GEOM_Object) go = GetObjectImpl(theShape);
bool aIsValidNormal = theNormal.length() == 3; bool aIsValidNormal = isValidDirection(theNormal);
bool aIsValidOrigin = theOrigin.length() == 3; bool aIsValidOrigin = theOrigin.length() == 3;
gp_Pln aPln; gp_Pln aPln;
if (aIsValidNormal && aIsValidOrigin) { if (aIsValidNormal && aIsValidOrigin) {
@ -78,18 +83,16 @@ CORBA::Boolean GEOM_ICanonicalRecognition_i::isPlane(GEOM::GEOM_Object_ptr theSh
gp_Dir(theNormal[0], theNormal[1], theNormal[2])); gp_Dir(theNormal[0], theNormal[1], theNormal[2]));
} }
bool aResult = GetOperation()->isPlane(go, theTolerance, aPln); bool aResult = GetOperation()->isPlane(go, theTolerance, aPln);
if (aResult && aIsValidNormal && aIsValidOrigin) gp_Pnt aOrig = aPln.Location();
{ theOrigin[0] = aOrig.X();
gp_Pnt aOrig = aPln.Location(); theOrigin[1] = aOrig.Y();
theOrigin[0] = aOrig.X(); theOrigin[2] = aOrig.Z();
theOrigin[1] = aOrig.Y();
theOrigin[2] = aOrig.Z(); gp_Dir aNorm = aPln.Axis().Direction();
theNormal[0] = aNorm.X();
theNormal[1] = aNorm.Y();
theNormal[2] = aNorm.Z();
gp_Dir aNorm = aPln.Axis().Direction();
theNormal[0] = aNorm.X();
theNormal[1] = aNorm.Y();
theNormal[2] = aNorm.Z();
}
return aResult; return aResult;
} }
@ -112,14 +115,12 @@ CORBA::Boolean GEOM_ICanonicalRecognition_i::isSphere(GEOM::GEOM_Object_ptr theS
aSphere.SetRadius(theRadius); aSphere.SetRadius(theRadius);
} }
bool aResult = GetOperation()->isSphere(go, theTolerance, aSphere); bool aResult = GetOperation()->isSphere(go, theTolerance, aSphere);
if (aResult && aIsValidOrigin && aIsValidRadius) gp_Pnt aLoc = aSphere.Location();
{ theOrigin[0] = aLoc.X();
gp_Pnt aLoc = aSphere.Location(); theOrigin[1] = aLoc.Y();
theOrigin[0] = aLoc.X(); theOrigin[2] = aLoc.Z();
theOrigin[1] = aLoc.Y(); theRadius = aSphere.Radius();
theOrigin[2] = aLoc.Z();
theRadius = aSphere.Radius();
}
return aResult; return aResult;
} }
@ -133,31 +134,28 @@ CORBA::Boolean GEOM_ICanonicalRecognition_i::isCone(GEOM::GEOM_Object_ptr theSha
{ {
Handle(::GEOM_Object) go = GetObjectImpl(theShape); Handle(::GEOM_Object) go = GetObjectImpl(theShape);
bool aIsValidAxis = theAxis.length() == 3; bool aIsValidAxis = isValidDirection(theAxis);
bool aIsValidApex = theApex.length() == 3; bool aIsValidApex = theApex.length() == 3;
bool aIsValidAngle = theHalfAngle > 0; bool aIsValidAngle = theHalfAngle > 0;
gp_Cone aCone; gp_Cone aCone;
if (aIsValidAxis && aIsValidApex && aIsValidAngle) if (aIsValidAxis && aIsValidApex && aIsValidAngle)
{ {
gp_Pnt aLoc(theApex[0], theApex[1], theApex[2]); gp_Pnt aLoc(theApex[0], theApex[1], theApex[2]);
aCone.SetLocation(aLoc); gp_Ax3 aAx3(aLoc, gp_Dir(theAxis[0], theAxis[1], theAxis[2]));
aCone.SetAxis(gp_Ax1(aLoc, gp_Dir(theAxis[0], theAxis[1], theAxis[2]))); aCone.SetPosition(aAx3);
} }
bool aResult = GetOperation()->isCone(go, theTolerance, aCone); bool aResult = GetOperation()->isCone(go, theTolerance, aCone);
if (aResult && aIsValidAxis && aIsValidApex && aIsValidAngle) gp_Dir aDir = aCone.Axis().Direction();
{ theAxis[0] = aDir.X();
gp_Dir aDir = aCone.Axis().Direction(); theAxis[1] = aDir.Y();
theAxis[0] = aDir.X(); theAxis[2] = aDir.Z();
theAxis[1] = aDir.Y();
theAxis[2] = aDir.Z();
gp_Pnt aApex = aCone.Apex(); gp_Pnt aApex = aCone.Apex();
theApex[0] = aApex.X(); theApex[0] = aApex.X();
theApex[1] = aApex.Y(); theApex[1] = aApex.Y();
theApex[2] = aApex.Z(); theApex[2] = aApex.Z();
theHalfAngle = aCone.SemiAngle(); theHalfAngle = aCone.SemiAngle();
}
return aResult; return aResult;
} }
@ -171,32 +169,30 @@ CORBA::Boolean GEOM_ICanonicalRecognition_i::isCylinder(GEOM::GEOM_Object_ptr th
{ {
Handle(::GEOM_Object) go = GetObjectImpl(theShape); Handle(::GEOM_Object) go = GetObjectImpl(theShape);
bool aIsValidAxis = theAxis.length() == 3; bool aIsValidAxis = isValidDirection(theAxis);
bool aIsValidOrigin = theOrigin.length() == 3; bool aIsValidOrigin = theOrigin.length() == 3;
bool aIsValidRadius = theRadius > 0; bool aIsValidRadius = theRadius > 0;
gp_Cylinder aCylinder; gp_Cylinder aCylinder;
if (aIsValidAxis && aIsValidOrigin && aIsValidRadius) if (aIsValidAxis && aIsValidOrigin && aIsValidRadius)
{ {
gp_Pnt aLoc(theOrigin[0], theOrigin[0], theOrigin[0]); gp_Pnt aLoc(theOrigin[0], theOrigin[0], theOrigin[0]);
aCylinder.SetLocation(aLoc); gp_Ax3 aAx3(aLoc, gp_Dir(theAxis[0], theAxis[1], theAxis[2]));
aCylinder.SetAxis(gp_Ax1(aLoc, gp_Dir(theAxis[0], theAxis[1], theAxis[2]))); aCylinder.SetPosition(aAx3);
aCylinder.SetRadius(theRadius); aCylinder.SetRadius(theRadius);
} }
bool aResult = GetOperation()->isCylinder(go, theTolerance, aCylinder); bool aResult = GetOperation()->isCylinder(go, theTolerance, aCylinder);
if (aResult && aIsValidAxis && aIsValidOrigin && aIsValidRadius) gp_Dir aDir = aCylinder.Axis().Direction();
{ theAxis[0] = aDir.X();
gp_Dir aDir = aCylinder.Axis().Direction(); theAxis[1] = aDir.Y();
theAxis[0] = aDir.X(); theAxis[2] = aDir.Z();
theAxis[1] = aDir.Y();
theAxis[2] = aDir.Z();
gp_Pnt aLoc = aCylinder.Location(); gp_Pnt aLoc = aCylinder.Location();
theOrigin[0] = aLoc.X(); theOrigin[0] = aLoc.X();
theOrigin[1] = aLoc.Y(); theOrigin[1] = aLoc.Y();
theOrigin[2] = aLoc.Z(); theOrigin[2] = aLoc.Z();
theRadius = aCylinder.Radius();
theRadius = aCylinder.Radius();
}
return aResult; return aResult;
} }
@ -210,7 +206,7 @@ CORBA::Boolean GEOM_ICanonicalRecognition_i::isLine(GEOM::GEOM_Object_ptr theEdg
{ {
Handle(::GEOM_Object) go = GetObjectImpl(theEdge); Handle(::GEOM_Object) go = GetObjectImpl(theEdge);
bool aIsValidDir = theDir.length() == 3; bool aIsValidDir = isValidDirection(theDir);
bool aIsValidOrigin = theOrigin.length() == 3; bool aIsValidOrigin = theOrigin.length() == 3;
gp_Lin aLine; gp_Lin aLine;
if (aIsValidDir && aIsValidOrigin) if (aIsValidDir && aIsValidOrigin)
@ -219,18 +215,16 @@ CORBA::Boolean GEOM_ICanonicalRecognition_i::isLine(GEOM::GEOM_Object_ptr theEdg
aLine.SetDirection(gp_Dir(theDir[0], theDir[1], theDir[2])); aLine.SetDirection(gp_Dir(theDir[0], theDir[1], theDir[2]));
} }
bool aResult = GetOperation()->isLine(go, theTolerance, aLine); bool aResult = GetOperation()->isLine(go, theTolerance, aLine);
if (aResult && aIsValidDir && aIsValidOrigin) gp_Pnt aLoc = aLine.Location();
{ theOrigin[0] = aLoc.X();
gp_Pnt aLoc = aLine.Location(); theOrigin[1] = aLoc.Y();
theOrigin[0] = aLoc.X(); theOrigin[2] = aLoc.Z();
theOrigin[1] = aLoc.Y();
theOrigin[2] = aLoc.Z(); gp_Dir aDir = aLine.Direction();
theDir[0] = aDir.X();
theDir[1] = aDir.Y();
theDir[2] = aDir.Z();
gp_Dir aDir = aLine.Direction();
theDir[0] = aDir.X();
theDir[1] = aDir.Y();
theDir[2] = aDir.Z();
}
return aResult; return aResult;
} }
@ -243,30 +237,29 @@ CORBA::Boolean GEOM_ICanonicalRecognition_i::isCircle(GEOM::GEOM_Object_ptr theE
GEOM::ListOfDouble& theNormal, GEOM::ListOfDouble& theOrigin, CORBA::Double& theRadius) GEOM::ListOfDouble& theNormal, GEOM::ListOfDouble& theOrigin, CORBA::Double& theRadius)
{ {
Handle(::GEOM_Object) go = GetObjectImpl(theEdge); Handle(::GEOM_Object) go = GetObjectImpl(theEdge);
bool aIsValidNormal = theNormal.length() == 3; bool aIsValidNormal = isValidDirection(theNormal);
bool aIsValidOrigin = theOrigin.length() == 3; bool aIsValidOrigin = theOrigin.length() == 3;
bool aIsValidRadius = theRadius > 0; bool aIsValidRadius = theRadius > 0;
gp_Circ aCircle; gp_Circ aCircle;
if (aIsValidNormal && aIsValidOrigin && aIsValidRadius) if (aIsValidNormal && aIsValidOrigin && aIsValidRadius)
{ {
aCircle.SetAxis(gp_Ax1(gp_Pnt(theOrigin[0], theOrigin[1], theOrigin[2]), gp_Ax2 aAx2(gp_Pnt(theOrigin[0], theOrigin[1], theOrigin[2]),
gp_Dir(theNormal[0], theNormal[1], theNormal[2]))); gp_Dir(theNormal[0], theNormal[1], theNormal[2]));
aCircle.SetPosition(aAx2);
aCircle.SetRadius(theRadius); aCircle.SetRadius(theRadius);
} }
bool aResult = GetOperation()->isCircle(go, theTolerance, aCircle); bool aResult = GetOperation()->isCircle(go, theTolerance, aCircle);
if (aResult && aIsValidNormal && aIsValidOrigin && aIsValidRadius) gp_Pnt aLoc = aCircle.Location();
{ theOrigin[0] = aLoc.X();
gp_Pnt aLoc = aCircle.Location(); theOrigin[1] = aLoc.Y();
theOrigin[0] = aLoc.X(); theOrigin[2] = aLoc.Z();
theOrigin[1] = aLoc.Y();
theOrigin[2] = aLoc.Z(); gp_Dir aDir = aCircle.Axis().Direction();
theNormal[0] = aDir.X();
theNormal[1] = aDir.Y();
theNormal[2] = aDir.Z();
theRadius = aCircle.Radius();
gp_Dir aDir = aCircle.Axis().Direction();
theNormal[0] = aDir.X();
theNormal[1] = aDir.Y();
theNormal[2] = aDir.Z();
theRadius = aCircle.Radius();
}
return aResult; return aResult;
} }
@ -280,9 +273,9 @@ CORBA::Boolean GEOM_ICanonicalRecognition_i::isEllipse(GEOM::GEOM_Object_ptr the
CORBA::Double& theMajorRadius, CORBA::Double& theMinorRadius) CORBA::Double& theMajorRadius, CORBA::Double& theMinorRadius)
{ {
Handle(::GEOM_Object) go = GetObjectImpl(theEdge); Handle(::GEOM_Object) go = GetObjectImpl(theEdge);
bool aIsValidNormal = theNormal.length() == 3; bool aIsValidNormal = isValidDirection(theNormal);
bool aIsValidOrigin = theOrigin.length() == 3; bool aIsValidOrigin = theOrigin.length() == 3;
bool aIsValidDirX = theDirX.length() == 3; bool aIsValidDirX = isValidDirection(theDirX);
bool aIsValidRad1 = (theMajorRadius > 0) && (theMajorRadius > theMinorRadius); bool aIsValidRad1 = (theMajorRadius > 0) && (theMajorRadius > theMinorRadius);
bool aIsValidRad2 = (theMinorRadius > 0) && (theMajorRadius > theMinorRadius); bool aIsValidRad2 = (theMinorRadius > 0) && (theMajorRadius > theMinorRadius);
@ -295,25 +288,25 @@ CORBA::Boolean GEOM_ICanonicalRecognition_i::isEllipse(GEOM::GEOM_Object_ptr the
aElips = gp_Elips(aAx2, theMajorRadius, theMinorRadius); aElips = gp_Elips(aAx2, theMajorRadius, theMinorRadius);
} }
bool aResult = GetOperation()->isEllipse(go, theTolerance, aElips); bool aResult = GetOperation()->isEllipse(go, theTolerance, aElips);
if (aResult && aIsValidNormal && aIsValidOrigin && aIsValidDirX && aIsValidRad1 && aIsValidRad2) gp_Pnt aLoc = aElips.Position().Location();
{ if (theOrigin.length() != 3)
gp_Pnt aLoc = aElips.Position().Location(); theOrigin.allocbuf(3);
theOrigin[0] = aLoc.X(); theOrigin[0] = aLoc.X();
theOrigin[1] = aLoc.Y(); theOrigin[1] = aLoc.Y();
theOrigin[2] = aLoc.Z(); theOrigin[2] = aLoc.Z();
gp_Dir aNorm = aElips.Position().Direction(); gp_Dir aNorm = aElips.Position().Direction();
theNormal[0] = aNorm.X(); theNormal[0] = aNorm.X();
theNormal[1] = aNorm.Y(); theNormal[1] = aNorm.Y();
theNormal[2] = aNorm.Z(); theNormal[2] = aNorm.Z();
gp_Dir aDirX = aElips.Position().XDirection(); gp_Dir aDirX = aElips.Position().XDirection();
theDirX[0] = aDirX.X(); theDirX[0] = aDirX.X();
theDirX[1] = aDirX.Y(); theDirX[1] = aDirX.Y();
theDirX[2] = aDirX.Z(); theDirX[2] = aDirX.Z();
theMajorRadius = aElips.MajorRadius();
theMinorRadius = aElips.MinorRadius();
theMajorRadius = aElips.MajorRadius();
theMinorRadius = aElips.MinorRadius();
}
return aResult; return aResult;
} }

View File

@ -21,6 +21,11 @@
# Author : Vitaly SMETANNIKOV, Open CASCADE S.A.S. # Author : Vitaly SMETANNIKOV, Open CASCADE S.A.S.
# Module : GEOM_SWIG # Module : GEOM_SWIG
def setVectorSize(theVec):
"We have to set the vector size because we need to have output values in this vector"
if len(theVec) != 3:
theVec = [0,0,0]
return theVec
class CanonicalRecognition: class CanonicalRecognition:
"The class provides recognition of canonical shapes" "The class provides recognition of canonical shapes"
@ -29,29 +34,57 @@ class CanonicalRecognition:
self.CR = geompyD.GetICanonicalRecognition() self.CR = geompyD.GetICanonicalRecognition()
def isPlane(self, shape, tolerance, normal = [], origin = []): def isPlane(self, shape, tolerance, normal = [], origin = []):
"Check if shape is planar" """
return self.CR.isPlane(shape, tolerance, normal, origin) Check if shape is planar
Usage:
> CR.isPlane(shape, tolerance, normal, origin)
"""
return self.CR.isPlane(shape, tolerance, setVectorSize(normal), setVectorSize(origin))
def isSphere(self, shape, tolerance, origin = [], radius = 0.0): def isSphere(self, shape, tolerance, origin = [], radius = 0.0):
"Check if shape is spherical" """
return self.CR.isSphere(shape, tolerance, origin, radius) Check if shape is spherical
Usage:
> CR.isSphere(shape, tolerance, origin, radius)
"""
return self.CR.isSphere(shape, tolerance, setVectorSize(origin), radius)
def isCone(self, shape, tolerance, axis = [], apex = [], halfAngle = 0.0): def isCone(self, shape, tolerance, axis = [], apex = [], halfAngle = 0.0):
"Check if shape is conical" """
return self.CR.isCone(shape, tolerance, axis, apex, halfAngle) Check if shape is conical
Usage:
> CR.isCone(shape, tolerance, axis, apex, halfAngle)
"""
return self.CR.isCone(shape, tolerance, setVectorSize(axis), setVectorSize(apex), halfAngle)
def isCylinder(self, shape, tolerance, axis = [], origin = [], radius = 0.0): def isCylinder(self, shape, tolerance, axis = [], origin = [], radius = 0.0):
"Check if shape is cylinder" """
return self.CR.isCylinder(shape, tolerance, axis, origin, radius) Check if shape is cylinder
Usage:
> CR.isCylinder(shape, tolerance, axis, origin, radius)
"""
return self.CR.isCylinder(shape, tolerance, setVectorSize(axis), setVectorSize(origin), radius)
def isLine(self, edge, tolerance, direction = [], origin = []): def isLine(self, edge, tolerance, direction = [], origin = []):
"Check if edge/wire is line" """
return self.CR.isLine(edge, tolerance, direction, origin) Check if edge/wire is line
Usage:
> CR.isLine(edge, tolerance, direction, origin)
"""
return self.CR.isLine(edge, tolerance, setVectorSize(direction), setVectorSize(origin))
def isCircle(self, edge, tolerance, normal = [], origin = [], radius = 0.0): def isCircle(self, edge, tolerance, normal = [], origin = [], radius = 0.0):
"Check if edge/wire is circle" """
return self.CR.isCircle(edge, tolerance, normal, origin, radius) Check if edge/wire is circle
Usage:
> CR.isCircle(edge, tolerance, normal, origin, radius)
"""
return self.CR.isCircle(edge, tolerance, setVectorSize(normal), setVectorSize(origin), radius)
def isEllipse(self, edge, tolerance, normal = [], dirX = [], origin = [], majorRadius = 0.0, minorRadius = 0.0): def isEllipse(self, edge, tolerance, normal = [], dirX = [], origin = [], majorRadius = 0.0, minorRadius = 0.0):
"Check if edge/wire is ellipse" """
return self.CR.isEllipse(edge, tolerance, normal, dirX, origin, majorRadius, minorRadius) Check if edge/wire is ellipse
Usage:
> CR.isEllipse(edge, tolerance, normal, dirX, origin, majorRadius, minorRadius)
"""
return self.CR.isEllipse(edge, tolerance, setVectorSize(normal), setVectorSize(dirX), setVectorSize(origin), majorRadius, minorRadius)