0021538: EDF GEOM: GetShapesOnShapeAsCompound fails on cylinders for some cases

This commit is contained in:
vsr 2012-11-16 05:56:15 +00:00
parent b10aa2d603
commit dfc4b8a3e1

View File

@ -78,12 +78,25 @@
#include <GEOMAlgo_PassKey.hxx> #include <GEOMAlgo_PassKey.hxx>
#include <GEOMAlgo_DataMapOfPassKeyInteger.hxx> #include <GEOMAlgo_DataMapOfPassKeyInteger.hxx>
#include <GEOMAlgo_DataMapIteratorOfDataMapOfPassKeyInteger.hxx> #include <GEOMAlgo_DataMapIteratorOfDataMapOfPassKeyInteger.hxx>
//
#include <gp_Dir2d.hxx>
#include <gp_Pnt2d.hxx>
#include <Geom2d_Line.hxx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Geom2dHatch_Hatcher.hxx>
#include <TColStd_ListOfInteger.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <HatchGen_Domain.hxx>
#include <Geom2dHatch_Hatcher.hxx>
#include <IntTools_Context.hxx>
#include <BRepTools.hxx>
#include <IntTools_Tools.hxx>
//======================================================================= //=======================================================================
//function : GEOMAlgo_FinderShapeOn1 //function : GEOMAlgo_FinderShapeOn1
//purpose : //purpose :
//======================================================================= //=======================================================================
GEOMAlgo_FinderShapeOn2::GEOMAlgo_FinderShapeOn2() GEOMAlgo_FinderShapeOn2::GEOMAlgo_FinderShapeOn2()
: :
GEOMAlgo_ShapeAlgo() GEOMAlgo_ShapeAlgo()
{ {
@ -97,14 +110,14 @@
//function : ~ //function : ~
//purpose : //purpose :
//======================================================================= //=======================================================================
GEOMAlgo_FinderShapeOn2::~GEOMAlgo_FinderShapeOn2() GEOMAlgo_FinderShapeOn2::~GEOMAlgo_FinderShapeOn2()
{ {
} }
//======================================================================= //=======================================================================
//function : SetClsf //function : SetClsf
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::SetClsf(const Handle(GEOMAlgo_Clsf)& aClsf) void GEOMAlgo_FinderShapeOn2::SetClsf(const Handle(GEOMAlgo_Clsf)& aClsf)
{ {
myClsf=aClsf; myClsf=aClsf;
} }
@ -112,7 +125,7 @@
//function : Clsf //function : Clsf
//purpose : //purpose :
//======================================================================= //=======================================================================
const Handle(GEOMAlgo_Clsf)& GEOMAlgo_FinderShapeOn2::Clsf() const const Handle(GEOMAlgo_Clsf)& GEOMAlgo_FinderShapeOn2::Clsf() const
{ {
return myClsf; return myClsf;
} }
@ -120,7 +133,7 @@
//function : SetShapeType //function : SetShapeType
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::SetShapeType(const TopAbs_ShapeEnum aType) void GEOMAlgo_FinderShapeOn2::SetShapeType(const TopAbs_ShapeEnum aType)
{ {
myShapeType=aType; myShapeType=aType;
} }
@ -128,7 +141,7 @@
//function : ShapeType //function : ShapeType
//purpose : //purpose :
//======================================================================= //=======================================================================
TopAbs_ShapeEnum GEOMAlgo_FinderShapeOn2::ShapeType()const TopAbs_ShapeEnum GEOMAlgo_FinderShapeOn2::ShapeType()const
{ {
return myShapeType; return myShapeType;
} }
@ -136,7 +149,7 @@
//function : SetState //function : SetState
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::SetState(const GEOMAlgo_State aState) void GEOMAlgo_FinderShapeOn2::SetState(const GEOMAlgo_State aState)
{ {
myState=aState; myState=aState;
} }
@ -144,7 +157,7 @@
//function : State //function : State
//purpose : //purpose :
//======================================================================= //=======================================================================
GEOMAlgo_State GEOMAlgo_FinderShapeOn2::State() const GEOMAlgo_State GEOMAlgo_FinderShapeOn2::State() const
{ {
return myState; return myState;
} }
@ -152,7 +165,7 @@
//function : SetNbPntsMin //function : SetNbPntsMin
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::SetNbPntsMin(const Standard_Integer aNb) void GEOMAlgo_FinderShapeOn2::SetNbPntsMin(const Standard_Integer aNb)
{ {
myNbPntsMin=aNb; myNbPntsMin=aNb;
} }
@ -160,7 +173,7 @@
//function : NbPntsMin //function : NbPntsMin
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer GEOMAlgo_FinderShapeOn2::NbPntsMin()const Standard_Integer GEOMAlgo_FinderShapeOn2::NbPntsMin()const
{ {
return myNbPntsMin; return myNbPntsMin;
} }
@ -168,7 +181,7 @@
//function : SetNbPntsMax //function : SetNbPntsMax
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::SetNbPntsMax(const Standard_Integer aNb) void GEOMAlgo_FinderShapeOn2::SetNbPntsMax(const Standard_Integer aNb)
{ {
myNbPntsMax=aNb; myNbPntsMax=aNb;
} }
@ -176,7 +189,7 @@
//function : NbPntsMax //function : NbPntsMax
//purpose : //purpose :
//======================================================================= //=======================================================================
Standard_Integer GEOMAlgo_FinderShapeOn2::NbPntsMax()const Standard_Integer GEOMAlgo_FinderShapeOn2::NbPntsMax()const
{ {
return myNbPntsMax; return myNbPntsMax;
} }
@ -192,7 +205,7 @@
// function: Shapes // function: Shapes
// purpose: // purpose:
//======================================================================= //=======================================================================
const TopTools_ListOfShape& GEOMAlgo_FinderShapeOn2::Shapes() const const TopTools_ListOfShape& GEOMAlgo_FinderShapeOn2::Shapes() const
{ {
Standard_Integer i, aNb; Standard_Integer i, aNb;
TopTools_ListOfShape* pL; TopTools_ListOfShape* pL;
@ -213,7 +226,7 @@
//function : Perform //function : Perform
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::Perform() void GEOMAlgo_FinderShapeOn2::Perform()
{ {
myErrorStatus=0; myErrorStatus=0;
myWarningStatus=0; myWarningStatus=0;
@ -265,7 +278,7 @@
//function : CheckData //function : CheckData
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::CheckData() void GEOMAlgo_FinderShapeOn2::CheckData()
{ {
Standard_Integer iErr; Standard_Integer iErr;
// //
@ -306,7 +319,7 @@
//function : ProcessVertices //function : ProcessVertices
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::ProcessVertices() void GEOMAlgo_FinderShapeOn2::ProcessVertices()
{ {
myErrorStatus=0; myErrorStatus=0;
// //
@ -347,7 +360,7 @@
//function : ProcessEdges //function : ProcessEdges
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::ProcessEdges() void GEOMAlgo_FinderShapeOn2::ProcessEdges()
{ {
myErrorStatus=0; myErrorStatus=0;
// //
@ -450,7 +463,7 @@
//function : ProcessFaces //function : ProcessFaces
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::ProcessFaces() void GEOMAlgo_FinderShapeOn2::ProcessFaces()
{ {
myErrorStatus=0; myErrorStatus=0;
// //
@ -545,7 +558,7 @@
//function : ProcessSolids //function : ProcessSolids
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::ProcessSolids() void GEOMAlgo_FinderShapeOn2::ProcessSolids()
{ {
myErrorStatus=0; myErrorStatus=0;
// //
@ -592,11 +605,9 @@
//function : InnerPoints //function : InnerPoints
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Face& aF, void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Face& aF,
GEOMAlgo_ListOfPnt& aLP) GEOMAlgo_ListOfPnt& aLP)
{ {
myErrorStatus=0;
//
Standard_Integer j, j1, j2, k, n[4], aNbLinks, aNx, aNb, iCnt;//, aNbMax, *pIds; Standard_Integer j, j1, j2, k, n[4], aNbLinks, aNx, aNb, iCnt;//, aNbMax, *pIds;
TopLoc_Location aLoc; TopLoc_Location aLoc;
Handle(Poly_Triangulation) aTRF; Handle(Poly_Triangulation) aTRF;
@ -605,6 +616,8 @@
GEOMAlgo_DataMapIteratorOfDataMapOfPassKeyInteger aIt; GEOMAlgo_DataMapIteratorOfDataMapOfPassKeyInteger aIt;
gp_Pnt aP, aP1, aP2; gp_Pnt aP, aP1, aP2;
// //
myErrorStatus=0;
//
aLP.Clear(); aLP.Clear();
// //
aTRF=BRep_Tool::Triangulation(aF, aLoc); aTRF=BRep_Tool::Triangulation(aF, aLoc);
@ -648,20 +661,11 @@
iCnt=aIt.Value(); iCnt=aIt.Value();
if (iCnt==1) { if (iCnt==1) {
const GEOMAlgo_PassKey& aPK=aIt.Key(); const GEOMAlgo_PassKey& aPK=aIt.Key();
//qf
/*
aNbMax=aPK.NbMax();
pIds=(Standard_Integer*)aPK.Key();
for (k=1; k<3; ++k) {
aNx=*(pIds+aNbMax-k);
aMBN.Add(aNx);
}
*/
aNx=(Standard_Integer)aPK.Id(1); aNx=(Standard_Integer)aPK.Id(1);
aMBN.Add(aNx); aMBN.Add(aNx);
aNx=(Standard_Integer)aPK.Id(2); aNx=(Standard_Integer)aPK.Id(2);
aMBN.Add(aNx); aMBN.Add(aNx);
//qt
} }
} }
// //
@ -677,74 +681,76 @@
// //
aNb=aLP.Extent(); aNb=aLP.Extent();
// //
if (!aNb && myNbPntsMin) { //modified by NIZNHY-PKV Mon Sep 24 08:42:32 2012f
// try to fill it yourself if (!aNb && myNbPntsMin) { // A
Standard_Boolean bIsDone; Standard_Boolean bIsDone, bHasFirstPoint, bHasSecondPoint;
Standard_Integer aN1, aN2; Standard_Integer i, aNb, aIx, iErr, aNbDomains;
Standard_Real aUMin, aUMax, aVMin, aVMax, dU, aUx, aVx, aV1, aV2;
gp_Pnt aPx;
gp_Dir2d aD2D (0., 1.);
gp_Pnt2d aP2D;
Handle(Geom2d_Line) aL2D;
Handle(Geom_Surface) aS; Handle(Geom_Surface) aS;
GeomAdaptor_Surface aGAS; TopoDS_Face aFF;
GeomAbs_SurfaceType aType;
// //
aS=BRep_Tool::Surface(aF); aFF=aF;
aGAS.Load(aS); aFF.Orientation (TopAbs_FORWARD);
aType=aGAS.GetType(); //
if (aType==GeomAbs_Plane || aType==GeomAbs_Cylinder) { Geom2dHatch_Hatcher& aHatcher=myContext->Hatcher(aFF);
// inner links //
aNbLinks=aMPKI.Extent(); aS=BRep_Tool::Surface(aFF);
aIt.Initialize(aMPKI); BRepTools::UVBounds(aFF, aUMin, aUMax, aVMin, aVMax);
for (; aIt.More(); aIt.Next()) { //
iCnt=aIt.Value(); aNb=myNbPntsMin+1;
if (iCnt>1) { dU=(aUMax-aUMin)/aNb;
// take the first having occured inner link for (i=1; i<aNb; ++i) {
// and discretize it aUx=aUMin+i*dU;
const GEOMAlgo_PassKey& aPK=aIt.Key(); aP2D.SetCoord(aUx, 0.);
//qf aL2D=new Geom2d_Line (aP2D, aD2D);
/* Geom2dAdaptor_Curve aHCur(aL2D);
aNbMax=aPK.NbMax(); //
pIds=(Standard_Integer*)aPK.Key(); aHatcher.ClrHatchings();
aN1=*(pIds+aNbMax-1); aIx=aHatcher.AddHatching(aHCur);
aN2=*(pIds+aNbMax-2); //
*/ aHatcher.Trim(aIx);
// bIsDone=aHatcher.TrimDone(aIx);
aN1=(Standard_Integer)aPK.Id(1); if (!bIsDone) {
aN2=(Standard_Integer)aPK.Id(2); myErrorStatus=42;
//qt return;
aP1=aNodes(aN1).Transformed(aTrsf); }
aP2=aNodes(aN2).Transformed(aTrsf); //
// aHatcher.ComputeDomains(aIx);
if (aType==GeomAbs_Cylinder) { bIsDone=aHatcher.IsDone(aIx);
Standard_Real aTolSM; if (!bIsDone) {
gp_Cylinder aCyl; continue;
// }
aTolSM=1.523e-6;//~1.-cos(0.1 deg) //
aCyl=aGAS.Cylinder(); aNbDomains=aHatcher.NbDomains(aIx);
if (!GEOMAlgo_SurfaceTools::IsCoaxial(aP1, aP2, aCyl, aTolSM)) { for (j=1; j<=aNbDomains; ++j) {
continue; const HatchGen_Domain& aDomain=aHatcher.Domain (aIx, j) ;
} // 1
} bHasFirstPoint=aDomain.HasFirstPoint();
// bHasSecondPoint=aDomain.HasSecondPoint();
BRepLib_MakeEdge aBME(aP1, aP2); if (!bHasFirstPoint || !bHasSecondPoint) {
bIsDone=aBME.IsDone(); continue;
if (!bIsDone) { }
myErrorStatus=30; //can not obtain the line fron the link // 2
return; aV1=aDomain.FirstPoint().Parameter();
} aV2=aDomain.SecondPoint().Parameter();
// aVx=IntTools_Tools::IntermediatePoint(aV1, aV2);
const TopoDS_Shape& aSx=aBME.Shape(); // 3
const TopoDS_Edge& aE=TopoDS::Edge(aSx); aS->D0(aUx, aVx, aPx);
// aLP.Append(aPx);
InnerPoints(aE, myNbPntsMin, aLP); break;
break; }
}// if (iCnt>1) }// for (i=1; i<aNb; ++i) {
}// for (; aIt.More(); aIt.Next())
}// if (aType==GeomAbs_Plane || aType==GeomAbs_Cylinder)
}// if (!aNb && myNbPntsMin) { }// if (!aNb && myNbPntsMin) {
} }
//======================================================================= //=======================================================================
//function : InnerPoints //function : InnerPoints
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Edge& aE, void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Edge& aE,
GEOMAlgo_ListOfPnt& aLP) GEOMAlgo_ListOfPnt& aLP)
{ {
myErrorStatus=0; myErrorStatus=0;
@ -800,7 +806,7 @@
//function : InnerPoints //function : InnerPoints
//purpose : //purpose :
//======================================================================= //=======================================================================
void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Edge& aE, void GEOMAlgo_FinderShapeOn2::InnerPoints(const TopoDS_Edge& aE,
const Standard_Integer aNbPntsMin, const Standard_Integer aNbPntsMin,
GEOMAlgo_ListOfPnt& aLP) GEOMAlgo_ListOfPnt& aLP)
{ {
@ -843,3 +849,63 @@
// 30- can not obtain the line from the link // 30- can not obtain the line from the link
// 40- point can not be classified // 40- point can not be classified
// 41- invalid data for classifier // 41- invalid data for classifier
// 42- can not compute hatching
/*
// A
if (!aNb && myNbPntsMin) {
// try to fill it yourself
Standard_Boolean bIsDone;
Standard_Integer aN1, aN2;
Handle(Geom_Surface) aS;
GeomAdaptor_Surface aGAS;
GeomAbs_SurfaceType aType;
//
aS=BRep_Tool::Surface(aF);
aGAS.Load(aS);
aType=aGAS.GetType();
if (aType==GeomAbs_Plane || aType==GeomAbs_Cylinder) {
// inner links
aNbLinks=aMPKI.Extent();
aIt.Initialize(aMPKI);
for (; aIt.More(); aIt.Next()) {
iCnt=aIt.Value();
if (iCnt>1) {
// take the first having occured inner link
// and discretize it
const GEOMAlgo_PassKey& aPK=aIt.Key();
//
aN1=(Standard_Integer)aPK.Id(1);
aN2=(Standard_Integer)aPK.Id(2);
//
aP1=aNodes(aN1).Transformed(aTrsf);
aP2=aNodes(aN2).Transformed(aTrsf);
//
if (aType==GeomAbs_Cylinder) {
Standard_Real aTolSM;
gp_Cylinder aCyl;
//
aTolSM=1.523e-6;//~1.-cos(0.1 deg)
aCyl=aGAS.Cylinder();
if (!GEOMAlgo_SurfaceTools::IsCoaxial(aP1, aP2, aCyl, aTolSM)) {
continue;
}
}
//
BRepLib_MakeEdge aBME(aP1, aP2);
bIsDone=aBME.IsDone();
if (!bIsDone) {
myErrorStatus=30; //can not obtain the line fron the link
return;
}
//
const TopoDS_Shape& aSx=aBME.Shape();
const TopoDS_Edge& aE=TopoDS::Edge(aSx);
//
InnerPoints(aE, myNbPntsMin, aLP);
break;
}// if (iCnt>1)
}// for (; aIt.More(); aIt.Next())
}// if (aType==GeomAbs_Plane || aType==GeomAbs_Cylinder)
}// if (!aNb && myNbPntsMin) {
*/