1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-24 13:50:49 +03:00

Compare commits

..

1 Commits

Author SHA1 Message Date
ssafarov
623e17d27f 0027170: Reading STEP files produces invalid shapes
Added a new GetEdgeCurve() method that returns a 3D curve or a curve on a surface by subtracting the location of the face.
2022-02-09 11:35:21 +03:00
5 changed files with 211 additions and 102 deletions

View File

@@ -148,14 +148,15 @@ void BRepCheck_Edge::Minimum()
BRepCheck::Add(lst,BRepCheck_InvalidRange); BRepCheck::Add(lst,BRepCheck_InvalidRange);
} }
else { else {
if (myCref->IsCurve3D()) { IsCurve3D = myCref->IsCurve3D();
if (IsCurve3D) {
// eap 6 Jun 2002 occ332 // eap 6 Jun 2002 occ332
// better transform C3d instead of transforming Surf upto C3d initial location, // better transform C3d instead of transforming Surf upto C3d initial location,
// on transformed BSpline surface 'same parameter' may seem wrong // on transformed BSpline surface 'same parameter' may seem wrong
TopLoc_Location L = myShape.Location() * myCref->Location(); TopLoc_Location L = myShape.Location() * myCref->Location();
Handle(Geom_Curve) C3d = Handle(Geom_Curve)::DownCast Handle(Geom_Curve) C3d = Handle(Geom_Curve)::DownCast
(myCref->Curve3D()->Transformed (myCref->Curve3D()->Transformed
(/*myCref->Location()*/L.Transformation())); (/*myCref->Location()*/L.Transformation()));
Standard_Boolean IsPeriodic = C3d->IsPeriodic(); Standard_Boolean IsPeriodic = C3d->IsPeriodic();
Standard_Real aPeriod = RealLast(); Standard_Real aPeriod = RealLast();
if(IsPeriodic) if(IsPeriodic)
@@ -186,9 +187,8 @@ void BRepCheck_Edge::Minimum()
} }
else else
{ {
GeomAdaptor_Curve GAC3d(C3d, C3d->TransformedParameter(First, L.Transformation()), TopoDS_Shape aShape;
C3d->TransformedParameter(Last, L.Transformation())); myHCurve = GetEdgeCurve(aShape);
myHCurve = new GeomAdaptor_Curve(GAC3d);
} }
} }
else { // curve on surface else { // curve on surface
@@ -226,11 +226,8 @@ void BRepCheck_Edge::Minimum()
} }
else else
{ {
Handle(GeomAdaptor_Surface) GAHSref = new GeomAdaptor_Surface(Sref); TopoDS_Shape aShape;
Handle(Geom2dAdaptor_Curve) GHPCref = myHCurve = GetEdgeCurve(aShape);
new Geom2dAdaptor_Curve(PCref,First,Last);
Adaptor3d_CurveOnSurface ACSref(GHPCref,GAHSref);
myHCurve = new Adaptor3d_CurveOnSurface(ACSref);
} }
} }
} }
@@ -301,6 +298,7 @@ void BRepCheck_Edge::InContext(const TopoDS_Shape& S)
return; return;
} }
// Modified by skv - Tue Apr 27 11:48:14 2004 End // Modified by skv - Tue Apr 27 11:48:14 2004 End
myHCurve = GetEdgeCurve(S);
Standard_Real First = myHCurve->FirstParameter(); Standard_Real First = myHCurve->FirstParameter();
Standard_Real Last = myHCurve->LastParameter(); Standard_Real Last = myHCurve->LastParameter();
@@ -372,7 +370,7 @@ void BRepCheck_Edge::InContext(const TopoDS_Shape& S)
Handle(Geom_Surface) Sb = cr->Surface(); Handle(Geom_Surface) Sb = cr->Surface();
Sb = Handle(Geom_Surface)::DownCast Sb = Handle(Geom_Surface)::DownCast
// (Su->Transformed(L.Transformation())); // (Su->Transformed(L.Transformation()));
(Su->Transformed(/*L*/(Floc * TFloc).Transformation())); (Su->Transformed(/*L*/TFloc.Transformation()));
Handle(Geom2d_Curve) PC = cr->PCurve(); Handle(Geom2d_Curve) PC = cr->PCurve();
Handle(GeomAdaptor_Surface) GAHS = new GeomAdaptor_Surface(Sb); Handle(GeomAdaptor_Surface) GAHS = new GeomAdaptor_Surface(Sb);
Handle(Geom2dAdaptor_Curve) GHPC = new Geom2dAdaptor_Curve(PC,f,l); Handle(Geom2dAdaptor_Curve) GHPC = new Geom2dAdaptor_Curve(PC,f,l);
@@ -440,7 +438,7 @@ void BRepCheck_Edge::InContext(const TopoDS_Shape& S)
// plan en position // plan en position
if (myGctrl) { if (myGctrl) {
P = Handle(Geom_Plane):: P = Handle(Geom_Plane)::
DownCast(P->Transformed(/*L*/(Floc * TFloc).Transformation()));// eap occ332 DownCast(P->Transformed(/*L*/TFloc.Transformation()));// eap occ332
//on projette Cref sur ce plan //on projette Cref sur ce plan
Handle(GeomAdaptor_Surface) GAHS = new GeomAdaptor_Surface(P); Handle(GeomAdaptor_Surface) GAHS = new GeomAdaptor_Surface(P);
@@ -548,6 +546,64 @@ Standard_Boolean BRepCheck_Edge::GeometricControls() const
return myGctrl; return myGctrl;
} }
//=======================================================================
//function : GetEdgeCurve
//purpose :
//=======================================================================
Handle(Adaptor3d_Curve) BRepCheck_Edge::GetEdgeCurve(const TopoDS_Shape& theShape)
{
Handle(Adaptor3d_Curve) aLocalCurve;
Handle(BRep_GCurve) GCref(Handle(BRep_GCurve)::DownCast(myCref));
Standard_Real First, Last;
GCref->Range(First, Last);
if (IsCurve3D)
{
TopLoc_Location L = myShape.Location() * myCref->Location();
Handle(Geom_Curve) C3d;
if (!theShape.IsNull())
{
C3d = Handle(Geom_Curve)::DownCast
(myCref->Curve3D()->Transformed
(/*myCref->Location()*/L.Predivided(theShape.Location()).Transformation()));
}
else
{
C3d = Handle(Geom_Curve)::DownCast
(myCref->Curve3D()->Transformed
(/*myCref->Location()*/L.Transformation()));
}
GeomAdaptor_Curve GAC3d(C3d, C3d->TransformedParameter(First, L.Transformation()),
C3d->TransformedParameter(Last, L.Transformation()));
aLocalCurve = new GeomAdaptor_Curve(GAC3d);
}
else
{
Handle(Geom_Surface) Sref = myCref->Surface();
if (!theShape.IsNull())
{
Sref = Handle(Geom_Surface)::DownCast
(Sref->Transformed(myCref->Location().Predivided(theShape.Location()).Transformation()));
}
else
{
Sref = Handle(Geom_Surface)::DownCast
(Sref->Transformed(myCref->Location().Transformation()));
}
const Handle(Geom2d_Curve)& PCref = myCref->PCurve();
Handle(GeomAdaptor_Surface) GAHSref = new GeomAdaptor_Surface(Sref);
Handle(Geom2dAdaptor_Curve) GHPCref =
new Geom2dAdaptor_Curve(PCref, First, Last);
Adaptor3d_CurveOnSurface ACSref(GHPCref, GAHSref);
aLocalCurve = new Adaptor3d_CurveOnSurface(ACSref);
}
return aLocalCurve;
}
//======================================================================= //=======================================================================
//function : SetStatus //function : SetStatus
//purpose : //purpose :

View File

@@ -45,6 +45,11 @@ public:
Standard_EXPORT Standard_Boolean GeometricControls() const; Standard_EXPORT Standard_Boolean GeometricControls() const;
//! Creates a 3d curve or surface on a curve by subtracting the location of the face
//! @param[in] theShape input shape to get the location from it
//! @return a 3d curve or curve on a surface
Standard_EXPORT Handle(Adaptor3d_Curve) GetEdgeCurve(const TopoDS_Shape& theShape);
Standard_EXPORT void GeometricControls (const Standard_Boolean B); Standard_EXPORT void GeometricControls (const Standard_Boolean B);
Standard_EXPORT Standard_Real Tolerance(); Standard_EXPORT Standard_Real Tolerance();
@@ -81,6 +86,7 @@ private:
Handle(Adaptor3d_Curve) myHCurve; Handle(Adaptor3d_Curve) myHCurve;
Standard_Boolean myGctrl; Standard_Boolean myGctrl;
Standard_Boolean myIsExactMethod; Standard_Boolean myIsExactMethod;
Standard_Boolean IsCurve3D;
}; };
#endif // _BRepCheck_Edge_HeaderFile #endif // _BRepCheck_Edge_HeaderFile

View File

@@ -13,4 +13,3 @@ TKGeomAlgo
TKV3d TKV3d
TKLCAF TKLCAF
TKXCAF TKXCAF
TKRWMesh

View File

@@ -14,21 +14,15 @@
// commercial license or contractual agreement. // commercial license or contractual agreement.
#include <VrmlData_ShapeConvert.hxx> #include <VrmlData_ShapeConvert.hxx>
#include <VrmlData_Scene.hxx>
#include <VrmlData_Appearance.hxx>
#include <VrmlData_Coordinate.hxx>
#include <VrmlData_Group.hxx> #include <VrmlData_Group.hxx>
#include <VrmlData_Coordinate.hxx>
#include <VrmlData_IndexedFaceSet.hxx> #include <VrmlData_IndexedFaceSet.hxx>
#include <VrmlData_IndexedLineSet.hxx> #include <VrmlData_IndexedLineSet.hxx>
#include <VrmlData_Scene.hxx>
#include <VrmlData_ShapeNode.hxx> #include <VrmlData_ShapeNode.hxx>
#include <BRep_Builder.hxx> #include <BRep_Builder.hxx>
#include <BRep_Tool.hxx> #include <BRep_Tool.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <Geom_Surface.hxx> #include <Geom_Surface.hxx>
#include <GeomLib.hxx>
#include <GCPnts_TangentialDeflection.hxx>
#include <NCollection_DataMap.hxx> #include <NCollection_DataMap.hxx>
#include <Poly_Triangulation.hxx> #include <Poly_Triangulation.hxx>
#include <Poly_Connect.hxx> #include <Poly_Connect.hxx>
@@ -39,6 +33,7 @@
#include <TColgp_Array1OfPnt2d.hxx> #include <TColgp_Array1OfPnt2d.hxx>
#include <TDataStd_Name.hxx> #include <TDataStd_Name.hxx>
#include <TDF_Label.hxx> #include <TDF_Label.hxx>
//#include <TDF_LabelSequence.hxx>
#include <TDocStd_Document.hxx> #include <TDocStd_Document.hxx>
#include <TopExp_Explorer.hxx> #include <TopExp_Explorer.hxx>
#include <TopoDS.hxx> #include <TopoDS.hxx>
@@ -46,11 +41,14 @@
#include <TopoDS_Face.hxx> #include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx> #include <TopoDS_Shape.hxx>
#include <TopoDS_Wire.hxx> #include <TopoDS_Wire.hxx>
#include <GCPnts_TangentialDeflection.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <TColStd_Array1OfReal.hxx> #include <TColStd_Array1OfReal.hxx>
#include <TColStd_HArray1OfReal.hxx> #include <TColStd_HArray1OfReal.hxx>
#include <TShort_Array1OfShortReal.hxx> #include <TShort_Array1OfShortReal.hxx>
#include <GeomLib.hxx>
#include <TShort_HArray1OfShortReal.hxx> #include <TShort_HArray1OfShortReal.hxx>
#include <RWMesh_FaceIterator.hxx> #include <VrmlData_Appearance.hxx>
#include <XCAFDoc_ColorTool.hxx> #include <XCAFDoc_ColorTool.hxx>
#include <XCAFDoc_DocumentTool.hxx> #include <XCAFDoc_DocumentTool.hxx>
#include <XCAFDoc_ShapeTool.hxx> #include <XCAFDoc_ShapeTool.hxx>
@@ -577,6 +575,7 @@ Handle(VrmlData_Appearance) VrmlData_ShapeConvert::defaultMaterialEdge () const
return anAppearance; return anAppearance;
} }
//======================================================================= //=======================================================================
//function : addShape //function : addShape
//purpose : Adds the shape from the document //purpose : Adds the shape from the document
@@ -585,18 +584,33 @@ void VrmlData_ShapeConvert::addShape (const Handle(VrmlData_Group)& theParent,
const TDF_Label& theLabel, const TDF_Label& theLabel,
const Handle(TDocStd_Document)& theDoc) const Handle(TDocStd_Document)& theDoc)
{ {
const TopoDS_Shape aShape = XCAFDoc_ShapeTool::GetShape(theLabel); Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(theDoc->Main());
Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool(theDoc->Main()); Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool(theDoc->Main());
Handle(VrmlData_Group) aGroup; Handle(XCAFDoc_VisMaterialTool) aMatTool = XCAFDoc_DocumentTool::VisMaterialTool(theDoc->Main());
Standard_Integer aNbFaces = 0;
for (RWMesh_FaceIterator aFaceIter (theLabel, TopLoc_Location(), true); aFaceIter.More(); aFaceIter.Next()) NCollection_DataMap<TopoDS_Shape, TDF_Label> aChildShapeToLabels;
TDF_LabelSequence aChildLabels;
aShapeTool->GetSubShapes(theLabel, aChildLabels);
for (TDF_LabelSequence::Iterator aChildIter(aChildLabels); aChildIter.More(); aChildIter.Next())
{ {
++aNbFaces; const TDF_Label& aChildLabel = aChildIter.Value();
TopoDS_Shape aChildShape;
if (aShapeTool->GetShape(aChildLabel, aChildShape))
{
aChildShapeToLabels.Bind(aChildShape, aChildLabel);
}
} }
const TopoDS_Shape aShape = aShapeTool->GetShape(theLabel);
Handle(VrmlData_Group) aGroup = 0L;
TopExp_Explorer anExp(aShape, TopAbs_FACE);
Standard_Integer nbFaces = 0;
for (; anExp.More(); anExp.Next()) {
nbFaces++;
}
Handle(TDataStd_Name) aNameAttribute; Handle(TDataStd_Name) aNameAttribute;
theLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttribute); theLabel.FindAttribute(TDataStd_Name::GetID(), aNameAttribute);
if (aNbFaces > 1) if (nbFaces > 1)
{ {
if (!aNameAttribute.IsNull()) if (!aNameAttribute.IsNull())
{ {
@@ -616,88 +630,112 @@ void VrmlData_ShapeConvert::addShape (const Handle(VrmlData_Group)& theParent,
} }
} }
for (RWMesh_FaceIterator aFaceIter (theLabel, TopLoc_Location(), true); aFaceIter.More(); aFaceIter.Next()) anExp.Init(aShape, TopAbs_FACE);
{ for (; anExp.More(); anExp.Next()) {
TopLoc_Location aLoc; TopLoc_Location aLoc;
const TopoDS_Face& aFace = aFaceIter.Face(); Handle(VrmlData_Geometry) aTShapeNode =
Handle(VrmlData_Geometry) aTShapeNode = makeTShapeNode (aFace, TopAbs_FACE, aLoc); makeTShapeNode(anExp.Current(), TopAbs_FACE, aLoc);
if (aTShapeNode.IsNull()) if (!aTShapeNode.IsNull())
{ {
continue; Handle(VrmlData_ShapeNode) aShapeNode = 0L;
} if (aGroup.IsNull() && !aNameAttribute.IsNull())
{
TCollection_AsciiString aName = aNameAttribute->Get();
aName.ChangeAll(' ', '_');
aName.ChangeAll('#', '_');
aShapeNode = new VrmlData_ShapeNode(myScene, aName.ToCString());
}
else
{
aShapeNode = new VrmlData_ShapeNode(myScene, 0L);
}
Handle(VrmlData_ShapeNode) aShapeNode = 0L; // set color
if (aGroup.IsNull() && !aNameAttribute.IsNull()) XCAFPrs_Style aStyle;
{ Quantity_ColorRGBA aColor;
TCollection_AsciiString aName = aNameAttribute->Get(); TDF_Label aLabel, anAttribLab;
aName.ChangeAll(' ', '_'); if (aChildShapeToLabels.Find (anExp.Current(), aLabel))
aName.ChangeAll('#', '_'); {
aShapeNode = new VrmlData_ShapeNode(myScene, aName.ToCString()); Handle(XCAFDoc_VisMaterial) aVisMat = aMatTool->GetShapeMaterial (aLabel);
} if (!aVisMat.IsNull()
else && !aVisMat->IsEmpty())
{ {
aShapeNode = new VrmlData_ShapeNode(myScene, 0L); anAttribLab = aVisMat->Label();
} aStyle.SetMaterial (aVisMat);
}
else if (aColorTool->GetColor (aLabel, XCAFDoc_ColorSurf, anAttribLab)
|| aColorTool->GetColor (aLabel, XCAFDoc_ColorGen, anAttribLab))
{
aColorTool->GetColor (anAttribLab, aColor);
aStyle.SetColorSurf (aColor);
}
}
if (!aStyle.IsSetColorSurf()
&& aStyle.Material().IsNull())
{
Handle(XCAFDoc_VisMaterial) aVisMat = aMatTool->GetShapeMaterial (theLabel);
if (!aVisMat.IsNull()
&& !aVisMat->IsEmpty())
{
anAttribLab = aVisMat->Label();
aStyle.SetMaterial (aVisMat);
}
if (aColorTool->GetColor (theLabel, XCAFDoc_ColorSurf, anAttribLab)
|| aColorTool->GetColor (theLabel, XCAFDoc_ColorGen, anAttribLab))
{
aColorTool->GetColor (anAttribLab, aColor);
aStyle.SetColorSurf (aColor);
}
}
if (!aStyle.IsSetColorSurf()
&& aStyle.Material().IsNull())
{
aShapeNode->SetAppearance(defaultMaterialFace());
}
else
{
aShapeNode->SetAppearance (makeMaterialFromStyle (aStyle, anAttribLab));
}
// set color myScene.AddNode(aShapeNode, theParent.IsNull() && aGroup.IsNull());
const XCAFPrs_Style& aStyle = aFaceIter.FaceStyle(); aShapeNode->SetGeometry(aTShapeNode);
TDF_Label anAttribLab; if (aLoc.IsIdentity())
if (!aStyle.Material().IsNull()
&& !aStyle.Material()->IsEmpty())
{
anAttribLab = aStyle.Material()->Label();
}
else if (aStyle.IsSetColorSurf())
{
aColorTool->FindColor (aStyle.GetColorSurfRGBA(), anAttribLab);
}
if (!aStyle.IsSetColorSurf()
&& aStyle.Material().IsNull())
{
aShapeNode->SetAppearance (defaultMaterialFace());
}
else
{
aShapeNode->SetAppearance (makeMaterialFromStyle (aStyle, anAttribLab));
}
myScene.AddNode(aShapeNode, theParent.IsNull() && aGroup.IsNull());
aShapeNode->SetGeometry(aTShapeNode);
if (aLoc.IsIdentity())
{
// Store the shape node directly into the main Group.
if (!aGroup.IsNull())
{ {
aGroup->AddNode(aShapeNode); // Store the shape node directly into the main Group.
if (!aGroup.IsNull())
{
aGroup->AddNode(aShapeNode);
}
else if (!theParent.IsNull())
{
theParent->AddNode(aShapeNode);
}
} }
else if (!theParent.IsNull()) else
{ {
theParent->AddNode(aShapeNode); // Create a Transform grouping node
Handle(VrmlData_Group) aTrans = new VrmlData_Group(myScene, 0L,
Standard_True);
gp_Trsf aTrsf(aLoc);
if (fabs(myScale - 1.) > Precision::Confusion())
{
const gp_XYZ aTransl = aTrsf.TranslationPart() * myScale;
aTrsf.SetTranslationPart(aTransl);
}
aTrans->SetTransform(aTrsf);
myScene.AddNode(aTrans, theParent.IsNull() && aGroup.IsNull());
if (!aGroup.IsNull())
{
aGroup->AddNode(aTrans);
}
else if (!theParent.IsNull())
{
theParent->AddNode(aTrans);
}
// Store the shape node under the transform.
aTrans->AddNode(aShapeNode);
} }
} }
else
{
// Create a Transform grouping node
Handle(VrmlData_Group) aTrans = new VrmlData_Group (myScene, 0L, Standard_True);
gp_Trsf aTrsf(aLoc);
if (fabs(myScale - 1.) > Precision::Confusion())
{
const gp_XYZ aTransl = aTrsf.TranslationPart() * myScale;
aTrsf.SetTranslationPart(aTransl);
}
aTrans->SetTransform(aTrsf);
myScene.AddNode(aTrans, theParent.IsNull() && aGroup.IsNull());
if (!aGroup.IsNull())
{
aGroup->AddNode(aTrans);
}
else if (!theParent.IsNull())
{
theParent->AddNode(aTrans);
}
// Store the shape node under the transform.
aTrans->AddNode(aShapeNode);
}
} }
} }

10
tests/bugs/heal/bug27170 Normal file
View File

@@ -0,0 +1,10 @@
puts "============"
puts "0027170: Reading STEP files produces invalid shapes"
puts "============"
restore [locate_data_file bug27170_f.brep] f
fixshape result f
ttranslate result 9.68119149294e-13 217.938944319 299.700009766
checkshape result