diff --git a/src/BRepMesh/BRepMesh_FaceAttribute.cxx b/src/BRepMesh/BRepMesh_FaceAttribute.cxx index 4cba24b1f8..eba74c267c 100644 --- a/src/BRepMesh/BRepMesh_FaceAttribute.cxx +++ b/src/BRepMesh/BRepMesh_FaceAttribute.cxx @@ -47,6 +47,28 @@ BRepMesh_FaceAttribute::BRepMesh_FaceAttribute() 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 //purpose : @@ -55,7 +77,7 @@ BRepMesh_FaceAttribute::BRepMesh_FaceAttribute( const TopoDS_Face& theFace, const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices, const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints, - const Standard_Boolean theAdaptiveMin) + const Standard_Boolean theAdaptiveMin) : myDefFace (0.), myUMin (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 //purpose : diff --git a/src/BRepMesh/BRepMesh_FaceAttribute.hxx b/src/BRepMesh/BRepMesh_FaceAttribute.hxx index ffd811efbb..0460d5308b 100644 --- a/src/BRepMesh/BRepMesh_FaceAttribute.hxx +++ b/src/BRepMesh/BRepMesh_FaceAttribute.hxx @@ -29,6 +29,13 @@ class BRepMesh_FaceAttribute : public Standard_Transient { 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. //! @param theFace face the attribute is created for. //! Used for default initialization. Attribute keeps reference @@ -41,7 +48,7 @@ public: const TopoDS_Face& theFace, const BRepMesh::HDMapOfVertexInteger& theBoundaryVertices, const BRepMesh::HDMapOfIntegerPnt& theBoundaryPoints, - const Standard_Boolean theAdaptiveMin); + const Standard_Boolean theAdaptiveMin); //! Destructor. Standard_EXPORT virtual ~BRepMesh_FaceAttribute(); @@ -54,6 +61,16 @@ public: //! @name main geometrical properties. 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. inline const TopoDS_Face& Face() const diff --git a/src/BRepMesh/BRepMesh_FastDiscret.cxx b/src/BRepMesh/BRepMesh_FastDiscret.cxx index e78ba1e0bf..7ed1129ae3 100644 --- a/src/BRepMesh/BRepMesh_FastDiscret.cxx +++ b/src/BRepMesh/BRepMesh_FastDiscret.cxx @@ -179,20 +179,16 @@ void BRepMesh_FastDiscret::resetDataStructure() //======================================================================= Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace) { + myAttribute.Nullify(); + GetFaceAttribute(theFace, myAttribute, Standard_True); + try { OCC_CATCH_SIGNALS // Initialize face attributes - myAttribute.Nullify(); - GetFaceAttribute(theFace, myAttribute); - if (myAttribute.IsNull()) - { - myAttribute = new BRepMesh_FaceAttribute(theFace, - myBoundaryVertices, myBoundaryPoints,myParameters.AdaptiveMin); - - myAttributes.Bind(theFace, myAttribute); - } + if (!myAttribute->IsInitialized ()) + myAttribute->SetFace (theFace, myParameters.AdaptiveMin); BRepMesh::HIMapOfInteger& aVertexEdgeMap = myAttribute->ChangeVertexEdgeMap(); BRepMesh::HDMapOfShapePairOfPolygon& aInternalEdges = myAttribute->ChangeInternalEdges(); @@ -565,15 +561,15 @@ Standard_Integer BRepMesh_FastDiscret::Add(const TopoDS_Face& theFace) myAttribute->SetDeltaX(deltaX); myAttribute->SetDeltaY(deltaY); } + + myAttribute->ChangeMeshNodes() = + myAttribute->ChangeStructure()->Data()->Vertices(); } catch(Standard_Failure) { myAttribute->SetStatus(BRepMesh_Failure); } - myAttribute->ChangeMeshNodes() = - myAttribute->ChangeStructure()->Data()->Vertices(); - myAttribute->ChangeStructure().Nullify(); return myAttribute->GetStatus(); } @@ -923,13 +919,19 @@ void BRepMesh_FastDiscret::storePolygonSharedData( //======================================================================= Standard_Boolean BRepMesh_FastDiscret::GetFaceAttribute( const TopoDS_Face& theFace, - Handle(BRepMesh_FaceAttribute)& theAttribute ) const + Handle(BRepMesh_FaceAttribute)& theAttribute, + const Standard_Boolean isForceCreate) const { if (myAttributes.IsBound(theFace)) { theAttribute = myAttributes(theFace); return Standard_True; } + else if (isForceCreate) + { + theAttribute = new BRepMesh_FaceAttribute(myBoundaryVertices, myBoundaryPoints); + myAttributes.Bind(theFace, theAttribute); + } return Standard_False; } diff --git a/src/BRepMesh/BRepMesh_FastDiscret.hxx b/src/BRepMesh/BRepMesh_FastDiscret.hxx index 8ac5989ff4..be0236145a 100644 --- a/src/BRepMesh/BRepMesh_FastDiscret.hxx +++ b/src/BRepMesh/BRepMesh_FastDiscret.hxx @@ -154,9 +154,15 @@ public: return mySharedFaces; } - //! Gives face attribute. - Standard_EXPORT Standard_Boolean GetFaceAttribute - ( const TopoDS_Face& theFace, Handle(BRepMesh_FaceAttribute)& theAttribute ) const; + //! Returns attribute descriptor for the given face. + //! @param theFace face the attribute should be returned for. + //! @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. Standard_EXPORT void RemoveFaceAttribute( const TopoDS_Face& theFace ); @@ -346,7 +352,7 @@ private: TopoDS_Face myFace; BRepMesh::DMapOfShapePairOfPolygon myEdges; - BRepMesh::DMapOfFaceAttribute myAttributes; + mutable BRepMesh::DMapOfFaceAttribute myAttributes; TopTools_DataMapOfShapeReal myMapdefle; // Data shared for whole shape