1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0026321: Crash in BRepMesh_FastDiscret::Add

BRepMesh_FaceAttribute: distinguish constructor and parameters initialization.
This commit is contained in:
oan 2016-02-16 19:08:13 +03:00 committed by bugmaster
parent eb5c2ff415
commit 0a2a7b466d
4 changed files with 80 additions and 19 deletions

View File

@ -47,6 +47,28 @@ BRepMesh_FaceAttribute::BRepMesh_FaceAttribute()
init(); init();
} }
//=======================================================================
//function : Constructor
//purpose :
//=======================================================================
BRepMesh_FaceAttribute::BRepMesh_FaceAttribute(
const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints)
: myDefFace (0.),
myUMin (0.),
myUMax (0.),
myVMin (0.),
myVMax (0.),
myDeltaX (1.),
myDeltaY (1.),
myMinStep (-1.),
myStatus (BRepMesh_NoError),
myAdaptiveMin (Standard_False),
myBoundaryVertices(theBoundaryVertices),
myBoundaryPoints (theBoundaryPoints)
{
}
//======================================================================= //=======================================================================
//function : Constructor //function : Constructor
//purpose : //purpose :
@ -55,7 +77,7 @@ BRepMesh_FaceAttribute::BRepMesh_FaceAttribute(
const TopoDS_Face& theFace, const TopoDS_Face& theFace,
const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices, const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints, const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints,
const Standard_Boolean theAdaptiveMin) const Standard_Boolean theAdaptiveMin)
: myDefFace (0.), : myDefFace (0.),
myUMin (0.), myUMin (0.),
myUMax (0.), myUMax (0.),
@ -81,6 +103,20 @@ BRepMesh_FaceAttribute::~BRepMesh_FaceAttribute()
{ {
} }
//=======================================================================
//function : SetFace
//purpose :
//=======================================================================
void BRepMesh_FaceAttribute::SetFace (
const TopoDS_Face& theFace,
const Standard_Boolean theAdaptiveMin)
{
myFace = theFace;
myAdaptiveMin = theAdaptiveMin;
init ();
}
//======================================================================= //=======================================================================
//function : init //function : init
//purpose : //purpose :

View File

@ -29,6 +29,13 @@ class BRepMesh_FaceAttribute : public Standard_Transient
{ {
public: public:
//! Constructor. Initializes empty attribute.
//! @param theBoundaryVertices shared map of shape vertices.
//! @param theBoundaryPoints shared discretization points of shape boundaries.
Standard_EXPORT BRepMesh_FaceAttribute(
const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints);
//! Constructor. //! Constructor.
//! @param theFace face the attribute is created for. //! @param theFace face the attribute is created for.
//! Used for default initialization. Attribute keeps reference //! Used for default initialization. Attribute keeps reference
@ -41,7 +48,7 @@ public:
const TopoDS_Face& theFace, const TopoDS_Face& theFace,
const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices, const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices,
const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints, const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints,
const Standard_Boolean theAdaptiveMin); const Standard_Boolean theAdaptiveMin);
//! Destructor. //! Destructor.
Standard_EXPORT virtual ~BRepMesh_FaceAttribute(); Standard_EXPORT virtual ~BRepMesh_FaceAttribute();
@ -54,6 +61,16 @@ public: //! @name main geometrical properties.
return mySurface; return mySurface;
} }
//! Returns True in case if this attribute has already been intialized.
inline Standard_Boolean IsInitialized () const
{
return !myFace.IsNull ();
}
//! Initializes this attribute by the given face.
Standard_EXPORT void SetFace (
const TopoDS_Face& theFace,
const Standard_Boolean theAdaptiveMin);
//! Returns forward oriented face to be used for calculations. //! Returns forward oriented face to be used for calculations.
inline const TopoDS_Face& Face() const inline const TopoDS_Face& Face() const

View File

@ -179,20 +179,16 @@ void BRepMesh_FastDiscret::resetDataStructure()
//======================================================================= //=======================================================================
Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace) Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace)
{ {
myAttribute.Nullify();
GetFaceAttribute(theFace, myAttribute, Standard_True);
try try
{ {
OCC_CATCH_SIGNALS OCC_CATCH_SIGNALS
// Initialize face attributes // Initialize face attributes
myAttribute.Nullify(); if (!myAttribute->IsInitialized ())
GetFaceAttribute(theFace, myAttribute); myAttribute->SetFace (theFace, myParameters.AdaptiveMin);
if (myAttribute.IsNull())
{
myAttribute = new BRepMesh_FaceAttribute(theFace,
myBoundaryVertices, myBoundaryPoints,myParameters.AdaptiveMin);
myAttributes.Bind(theFace, myAttribute);
}
BRepMesh::HIMapOfInteger& aVertexEdgeMap = myAttribute->ChangeVertexEdgeMap(); BRepMesh::HIMapOfInteger& aVertexEdgeMap = myAttribute->ChangeVertexEdgeMap();
BRepMesh::HDMapOfShapePairOfPolygon& aInternalEdges = myAttribute->ChangeInternalEdges(); BRepMesh::HDMapOfShapePairOfPolygon& aInternalEdges = myAttribute->ChangeInternalEdges();
@ -565,15 +561,15 @@ Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace)
myAttribute->SetDeltaX(deltaX); myAttribute->SetDeltaX(deltaX);
myAttribute->SetDeltaY(deltaY); myAttribute->SetDeltaY(deltaY);
} }
myAttribute->ChangeMeshNodes() =
myAttribute->ChangeStructure()->Data()->Vertices();
} }
catch(Standard_Failure) catch(Standard_Failure)
{ {
myAttribute->SetStatus(BRepMesh_Failure); myAttribute->SetStatus(BRepMesh_Failure);
} }
myAttribute->ChangeMeshNodes() =
myAttribute->ChangeStructure()->Data()->Vertices();
myAttribute->ChangeStructure().Nullify(); myAttribute->ChangeStructure().Nullify();
return myAttribute->GetStatus(); return myAttribute->GetStatus();
} }
@ -923,13 +919,19 @@ void BRepMesh_FastDiscret::storePolygonSharedData(
//======================================================================= //=======================================================================
Standard_Boolean BRepMesh_FastDiscret::GetFaceAttribute( Standard_Boolean BRepMesh_FastDiscret::GetFaceAttribute(
const TopoDS_Face& theFace, const TopoDS_Face& theFace,
Handle(BRepMesh_FaceAttribute)& theAttribute ) const Handle(BRepMesh_FaceAttribute)& theAttribute,
const Standard_Boolean isForceCreate) const
{ {
if (myAttributes.IsBound(theFace)) if (myAttributes.IsBound(theFace))
{ {
theAttribute = myAttributes(theFace); theAttribute = myAttributes(theFace);
return Standard_True; return Standard_True;
} }
else if (isForceCreate)
{
theAttribute = new BRepMesh_FaceAttribute(myBoundaryVertices, myBoundaryPoints);
myAttributes.Bind(theFace, theAttribute);
}
return Standard_False; return Standard_False;
} }

View File

@ -154,9 +154,15 @@ public:
return mySharedFaces; return mySharedFaces;
} }
//! Gives face attribute. //! Returns attribute descriptor for the given face.
Standard_EXPORT Standard_Boolean GetFaceAttribute //! @param theFace face the attribute should be returned for.
( const TopoDS_Face& theFace, Handle(BRepMesh_FaceAttribute)& theAttribute ) const; //! @param[out] theAttribute attribute found for the specified face.
//! @param isForceCreate if True creates new attribute in case if there
//! is no data for the given face.
Standard_EXPORT Standard_Boolean GetFaceAttribute (
const TopoDS_Face& theFace,
Handle(BRepMesh_FaceAttribute)& theAttribute,
const Standard_Boolean isForceCreate = Standard_False) const;
//! Remove face attribute as useless to free locate memory. //! Remove face attribute as useless to free locate memory.
Standard_EXPORT void RemoveFaceAttribute( const TopoDS_Face& theFace ); Standard_EXPORT void RemoveFaceAttribute( const TopoDS_Face& theFace );
@ -346,7 +352,7 @@ private:
TopoDS_Face myFace; TopoDS_Face myFace;
BRepMesh::DMapOfShapePairOfPolygon myEdges; BRepMesh::DMapOfShapePairOfPolygon myEdges;
BRepMesh::DMapOfFaceAttribute myAttributes; mutable BRepMesh::DMapOfFaceAttribute myAttributes;
TopTools_DataMapOfShapeReal myMapdefle; TopTools_DataMapOfShapeReal myMapdefle;
// Data shared for whole shape // Data shared for whole shape