From: nbv Date: Fri, 19 Oct 2018 13:38:02 +0000 (+0300) Subject: 0030008: BRepMesh does not respect angular deflection in internal area of bspline... X-Git-Tag: V7_4_0_beta~343 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=46478ffe32cfca537a35b744700e082f59ec4c4c 0030008: BRepMesh does not respect angular deflection in internal area of bspline surface 1. Check whether the mesh satisfies the required angular deflection has been amended. Namely normals (to the surface) in the ends of any not "frontier" link are made collinear (with the given angular tolerance). 2. New parameters AngleInterior and DeflectionInterior have been added in IMeshTools_Parameters structure. 3. In case of thin long faces with internal edges, add points of internal edges to control parameters using grabParamsOfInternalEdges() in order to avoid aberrations on its ends. Disable addition of parameters from boundary edges in case of BSpline surface. Deviation can be controlled through the deflection parameter. 4. Grab parameters from edges in case if there is just a single interval on BSpline surface along U and V direction. --- diff --git a/dox/dev_guides/upgrade/upgrade.md b/dox/dev_guides/upgrade/upgrade.md index 9df681aa6b..06fc1a0b36 100644 --- a/dox/dev_guides/upgrade/upgrade.md +++ b/dox/dev_guides/upgrade/upgrade.md @@ -1619,14 +1619,14 @@ Now methods *GeomConvert::ConcatG1*, *GeomConvert::ConcatC1*, *Geom2dConvert::Co @subsection upgrade_740_selection Changes in selection API and picked point calculation algorithm. -*SelectBasics_PickResult* structure has been extended, so that it now defines 3D point on detected entity in addition to Depth value along picking ray. +*SelectBasics_PickResult* structure has been extended, so that it now defines a 3D point on the detected entity in addition to Depth value along picking ray. *SelectMgr_SelectingVolumeManager::Overlap()* methods have been corrected to fill in *SelectBasics_PickResult* structure (depth and 3D point) instead of only depth value, so that custom *Select3D_SensitiveEntity* implementation should be updated accordingly (including *Select3D_SensitiveSet* subclasses). @subsection upgrade_740_ocafpersistence Document format version management improvement. -Previously Document format version after restoring by DocumentRetrievalDriver was propagated using static methods of corresponding units (like MDataStd or MNaming) to static variables of these units and after that became accessible to Drivers of these units. -Now Document format version is available to drivers via RelocationTable. The Relocation table now keeps HeaderData of the document and a format version can be extracted in next way: theRelocTable.GetHeaderData()->StorageVersion(). -Obsolete methods: *static void SetDocumentVersion (const Standard_Integer DocVersion)* and *static Standard_Integer DocumentVersion()* of *BinMDataStd*, *BinMNaming*, *XmlMDataStd* and *XmlMNaming* are removed. +Previously Document format version restored by *DocumentRetrievalDriver* was propagated using static methods of the corresponding units (like *MDataStd* or *MNaming*) to static variables of these units and after that became accessible to Drivers of these units. +Now Document format version is available to drivers via *RelocationTable*. The Relocation table now keeps *HeaderData* of the document and a format version can be extracted in the following way: *theRelocTable.GetHeaderData()->StorageVersion()*. +Obsolete methods: *static void SetDocumentVersion (const Standard_Integer DocVersion)* and *static Standard_Integer DocumentVersion()* have been removed from *BinMDataStd*, *BinMNaming*, *XmlMDataStd* and *XmlMNaming*. @subsection upgrade_740_changed_api_of_brepmesh BRepMesh - revision of the data model diff --git a/dox/user_guides/modeling_algos/images/modeling_algos_image057.png b/dox/user_guides/modeling_algos/images/modeling_algos_image057.png index d2aabb971c..450b8c6f12 100644 Binary files a/dox/user_guides/modeling_algos/images/modeling_algos_image057.png and b/dox/user_guides/modeling_algos/images/modeling_algos_image057.png differ diff --git a/dox/user_guides/modeling_algos/modeling_algos.md b/dox/user_guides/modeling_algos/modeling_algos.md index 30d5b4eeb6..d01a6ca487 100644 --- a/dox/user_guides/modeling_algos/modeling_algos.md +++ b/dox/user_guides/modeling_algos/modeling_algos.md @@ -3151,9 +3151,9 @@ At the second step, the faces are tessellated. Linear deflection limits the dist @figure{/user_guides/modeling_algos/images/modeling_algos_image056.png,"Deflection parameters of BRepMesh_IncrementalMesh algorithm",420} -Linear deflection limits the distance between triangles and the face interior. +There are additional options to control behavior of the meshing of face interior: *DeflectionInterior* and *AngleInterior*. *DeflectionInterior* limits the distance between triangles and the face interior. *AngleInterior* (used for tessellation of B-spline faces only) limits the angle between normals (N1, N2 and N3 in the picture) in the nodes of every link of the triangle. There is an exception for the links along the face boundary edges, "Angular Deflection" is used for them during edges discretization. -@figure{/user_guides/modeling_algos/images/modeling_algos_image057.png,"Linear deflection",420} +@figure{/user_guides/modeling_algos/images/modeling_algos_image057.png,"Linear and angular interior deflections",420} Note that if a given value of linear deflection is less than shape tolerance then the algorithm will skip this value and will take into account the shape tolerance. @@ -3171,24 +3171,24 @@ You can obtain information on the shape by first exploring it. To access triangu @subsubsection occt_modalg_11_3_1 Goals The main goals of the chosen architecture are: - * Remove tight connections between data structures, auxiliary tools and algorithms in order to create an extensible solution, easy for maintenance and improvements; + * Remove tight connections between data structures, auxiliary tools and algorithms to create an extensible solution, easy for maintenance and improvements; * Separate the code among several functional units responsible for specific operation for the sake of simplification of debugging and readability; - * Introduce new data structures enabling the possibility to manipulate a discrete model of a particular entity (edge, wire, face) in order to perform computations locally instead of processing an entire model; - * Implement a new triangulation algorithm replacing existing functionality that contains too complicated solutions that need to be moved to the upper level. In addition, provide the possibility to change algorithm depending on surface type (initially to speed up meshing of planes). + * Introduce new data structures enabling the possibility to manipulate a discrete model of a particular entity (edge, wire, face) in order to perform computations locally instead of processing the entire model; + * Implement a new triangulation algorithm replacing the existing functionality that contains overcomplicated solutions that need to be moved to the upper level. In addition, provide the possibility to change the algorithm depending on surface type (initially to speed up meshing of planes). @subsubsection occt_modalg_11_3_2 General workflow @figure{/user_guides/modeling_algos/images/modeling_algos_mesh_001.svg,"General workflow of BRepMesh component",500} -Generally, the workflow of the component can be divided on six parts: - * **Creation of model data structure**: source *TopoDS_Shape* passed to algorithm is analyzed and exploded on faces and edges. The reflection corresponding to each topological entity is created in the data model. Note that underlying algorithms use the data model as input and access it via a common interface which allows creating a custom data model with necessary dependencies between particular entities (see the paragraph "Data model interface"); - * **Discretize edges 3D & 2D curves**: 3D curve as well as an associated set of 2D curves of each model edge is discretized in order to create a coherent skeleton used as a base in face meshing process. If an edge of the source shape already contains polygonal data which suits the specified parameters, it is extracted from the shape and stored in the model as is. Each edge is processed separately, adjacency is not taken into account; +Generally, the workflow of the component can be divided into six parts: + * **Creation of model data structure**: source *TopoDS_Shape* passed to algorithm is analyzed and exploded into faces and edges. The reflection corresponding to each topological entity is created in the data model. Note that underlying algorithms use the data model as input and access it via a common interface which allows creating a custom data model with necessary dependencies between particular entities (see the paragraph "Data model interface"); + * **Discretize edges 3D & 2D curves**: 3D curve as well as an associated set of 2D curves of each model edge is discretized in order to create a coherent skeleton used as a base in face meshing process. If an edge of the source shape already contains polygonal data which suits the specified parameters, it is extracted from the shape and stored in the model as is. Each edge is processed separately, the adjacency is not taken into account; * **Heal discrete model**: the source *TopoDS_Shape* can contain problems, such as open wires or self-intersections, introduced during design, exchange or modification of model. In addition, some problems like self-intersections can be introduced by roughly discretized edges. This stage is responsible for analysis of a discrete model in order to detect and repair problems or to refuse further processing of a model part in case if a problem cannot be solved; * **Preprocess discrete model**: defines actions specific to the implemented approach to be performed before meshing of faces. By default, this operation iterates over model faces, checks the consistency of existing triangulations and cleans topological faces and adjacent edges from polygonal data in case of inconsistency or marks a face of the discrete model as not required for the computation; * **Discretize faces**: represents the core part performing mesh generation for a particular face based on 2D discrete data. This operation caches polygonal data associated with face edges in the data model for further processing and stores the generated mesh to *TopoDS_Face*; * **Postprocess discrete model**: defines actions specific for the implemented approach to be performed after meshing of faces. By default, this operation stores polygonal data obtained at the previous stage to *TopoDS_Edge* objects of the source model. @subsubsection occt_modalg_11_3_3 Common interfaces -The component structure contains two units: IMeshData (see Data model interface) and IMeshTools, defining common interfaces for the data model and algorithmic tools correspondingly. Class *IMeshTools_Context* represents a connector between these units. The context class caches the data model as well as the tools corresponding to each of six stages of the workflow mentioned above and provides methods to call the corresponding tool safely (designed similarly to *IntTools_Context* in order to keep consistency with OCCT core tools). All stages, except for the first one use data model as input and perform a specific action on the entire structure. Thus, API class *IMeshTools_ModelAlgo* is defined in order to unify the interface of tools manipulating the data model. Each tool supposed to process the data model should inherit this interface enabling the possibility to cache it in context. In contrast to others, the model builder interface is defined by another class *IMeshTools_ModelBuilder* due to a different meaning of the stage. The entry point starting the entire workflow is represented by *IMeshTools_MeshBuilder*. +The component structure contains two units: IMeshData (see Data model interface) and IMeshTools, defining common interfaces for the data model and algorithmic tools correspondingly. Class *IMeshTools_Context* represents a connector between these units. The context class caches the data model as well as the tools corresponding to each of six stages of the workflow mentioned above and provides methods to call the corresponding tool safely (designed similarly to *IntTools_Context* in order to keep consistency with OCCT core tools). All stages, except for the first one, use the data model as input and perform a specific action on the entire structure. Thus, API class *IMeshTools_ModelAlgo* is defined in order to unify the interface of tools manipulating the data model. Each tool supposed to process the data model should inherit this interface enabling the possibility to cache it in context. In contrast to others, the model builder interface is defined by another class *IMeshTools_ModelBuilder* due to a different meaning of the stage. The entry point starting the entire workflow is represented by *IMeshTools_MeshBuilder*. The default implementation of *IMeshTools_Context* is given in *BRepMesh_Context* class initializing the context by instances of default algorithmic tools. diff --git a/src/BRepMesh/BRepMesh_BoundaryParamsRangeSplitter.hxx b/src/BRepMesh/BRepMesh_BoundaryParamsRangeSplitter.hxx index ad0f2599fc..5006e1b65a 100644 --- a/src/BRepMesh/BRepMesh_BoundaryParamsRangeSplitter.hxx +++ b/src/BRepMesh/BRepMesh_BoundaryParamsRangeSplitter.hxx @@ -44,6 +44,11 @@ public: protected: + //! Initializes U and V parameters lists using CN continuity intervals. + virtual Standard_Boolean initParameters() const Standard_OVERRIDE + { + return Standard_True; + } }; #endif diff --git a/src/BRepMesh/BRepMesh_Deflection.cxx b/src/BRepMesh/BRepMesh_Deflection.cxx index d3e9757de4..bde26b833f 100644 --- a/src/BRepMesh/BRepMesh_Deflection.cxx +++ b/src/BRepMesh/BRepMesh_Deflection.cxx @@ -14,41 +14,46 @@ // commercial license or contractual agreement. #include + +#include +#include #include -#include #include #include -#include -#include -#include -#include -#include -#include +#include #include +#include //======================================================================= //function : RelativeEdgeDeflection //purpose : //======================================================================= -Standard_Real BRepMesh_Deflection::RelativeEdgeDeflection( - const TopoDS_Edge& theEdge, - const Standard_Real theDeflection, +Standard_Real BRepMesh_Deflection::ComputeAbsoluteDeflection( + const TopoDS_Shape& theShape, + const Standard_Real theRelativeDeflection, const Standard_Real theMaxShapeSize, Standard_Real& theAdjustmentCoefficient) { theAdjustmentCoefficient = 1.; - Standard_Real aEdgeDeflection = theDeflection; - if (theEdge.IsNull()) + if (theShape.IsNull()) { - return aEdgeDeflection; + return theRelativeDeflection; } Bnd_Box aBox; - BRepBndLib::Add (theEdge, aBox, Standard_False); - BRepMesh_ShapeTool::BoxMaxDimension (aBox, aEdgeDeflection); + BRepBndLib::Add (theShape, aBox, Standard_False); + + Standard_Real aShapeSize = theRelativeDeflection; + BRepMesh_ShapeTool::BoxMaxDimension (aBox, aShapeSize); // Adjust resulting value in relation to the total size - theAdjustmentCoefficient = theMaxShapeSize / (2 * aEdgeDeflection); + + Standard_Real aX1, aY1, aZ1, aX2, aY2, aZ2; + aBox.Get(aX1, aY1, aZ1, aX2, aY2, aZ2); + const Standard_Real aMaxShapeSize = (theMaxShapeSize > 0.0) ? theMaxShapeSize : + Max(aX2 - aX1, Max(aY2 - aY1, aZ2 - aZ1)); + + theAdjustmentCoefficient = aMaxShapeSize / (2 * aShapeSize); if (theAdjustmentCoefficient < 0.5) { theAdjustmentCoefficient = 0.5; @@ -58,7 +63,7 @@ Standard_Real BRepMesh_Deflection::RelativeEdgeDeflection( theAdjustmentCoefficient = 2.; } - return (theAdjustmentCoefficient * aEdgeDeflection * theDeflection); + return (theAdjustmentCoefficient * aShapeSize * theRelativeDeflection); } //======================================================================= @@ -75,8 +80,9 @@ void BRepMesh_Deflection::ComputeDeflection ( if (theParameters.Relative) { Standard_Real aScale; - aLinDeflection = RelativeEdgeDeflection (theDEdge->GetEdge (), - theParameters.Deflection, theMaxShapeSize, aScale); + aLinDeflection = ComputeAbsoluteDeflection(theDEdge->GetEdge(), + theParameters.Deflection, + theMaxShapeSize, aScale); // Is it OK? aAngDeflection = theParameters.Angle * aScale; @@ -144,7 +150,15 @@ void BRepMesh_Deflection::ComputeDeflection ( const IMeshData::IFaceHandle& theDFace, const IMeshTools_Parameters& theParameters) { - Standard_Real aFaceDeflection = 0.; + Standard_Real aDeflection = theParameters.DeflectionInterior; + if (theParameters.Relative) + { + Standard_Real aScale; + aDeflection = ComputeAbsoluteDeflection(theDFace->GetFace(), + aDeflection, -1.0, aScale); + } + + Standard_Real aFaceDeflection = 0.0; if (theDFace->WiresNb () > 0) { for (Standard_Integer aWireIt = 0; aWireIt < theDFace->WiresNb(); ++aWireIt) @@ -154,10 +168,8 @@ void BRepMesh_Deflection::ComputeDeflection ( aFaceDeflection /= theDFace->WiresNb (); } - else - { - aFaceDeflection = theParameters.Deflection; - } + + aFaceDeflection = Max(aDeflection, aFaceDeflection); theDFace->SetDeflection (Max(2.* BRepMesh_ShapeTool::MaxFaceTolerance( theDFace->GetFace()), aFaceDeflection)); diff --git a/src/BRepMesh/BRepMesh_Deflection.hxx b/src/BRepMesh/BRepMesh_Deflection.hxx index 7c3b5aed77..8a7e05df9e 100644 --- a/src/BRepMesh/BRepMesh_Deflection.hxx +++ b/src/BRepMesh/BRepMesh_Deflection.hxx @@ -31,16 +31,17 @@ class BRepMesh_Deflection : public Standard_Transient { public: - //! Returns relative deflection for edge with respect to shape size. - //! @param theEdge edge for which relative deflection should be computed. - //! @param theDeflection absolute deflection. - //! @param theMaxShapeSize maximum size of a shape. + //! Returns absolute deflection for theShape with respect to the + //! relative deflection and theMaxShapeSize. + //! @param theShape shape for that the deflection should be computed. + //! @param theRelativeDeflection relative deflection. + //! @param theMaxShapeSize maximum size of the whole shape. //! @param theAdjustmentCoefficient coefficient of adjustment between maximum //! size of shape and calculated relative deflection. - //! @return relative deflection for the edge. - Standard_EXPORT static Standard_Real RelativeEdgeDeflection ( - const TopoDS_Edge& theEdge, - const Standard_Real theDeflection, + //! @return absolute deflection for the shape. + Standard_EXPORT static Standard_Real ComputeAbsoluteDeflection ( + const TopoDS_Shape& theShape, + const Standard_Real theRelativeDeflection, const Standard_Real theMaxShapeSize, Standard_Real& theAdjustmentCoefficient); diff --git a/src/BRepMesh/BRepMesh_DelaunayDeflectionControlMeshAlgo.hxx b/src/BRepMesh/BRepMesh_DelaunayDeflectionControlMeshAlgo.hxx index 922d530bd4..78689d114d 100644 --- a/src/BRepMesh/BRepMesh_DelaunayDeflectionControlMeshAlgo.hxx +++ b/src/BRepMesh/BRepMesh_DelaunayDeflectionControlMeshAlgo.hxx @@ -18,6 +18,7 @@ #include #include +#include //! Extends node insertion Delaunay meshing algo in order to control //! deflection of generated trianges. Splits triangles failing the check. @@ -314,16 +315,56 @@ private: const gp_XY aMidPnt2d = (theNodesInfo[i].Point2d + theNodesInfo[j].Point2d) / 2.; - usePoint(aMidPnt2d, LineDeviation(theNodesInfo[i].Point, theNodesInfo[j].Point)); + if (!usePoint (aMidPnt2d, LineDeviation (theNodesInfo[i].Point, + theNodesInfo[j].Point))) + { + if (!checkLinkEndsForAngularDeviation(theNodesInfo[i], + theNodesInfo[j], + aMidPnt2d)) + { + myControlNodes->Append(aMidPnt2d); + } + } } } } + //! Checks the given point (located between the given nodes) + //! for specified angular deviation. + Standard_Boolean checkLinkEndsForAngularDeviation(const TriangleNodeInfo& theNodeInfo1, + const TriangleNodeInfo& theNodeInfo2, + const gp_XY& /*theMidPoint*/) + { + gp_Dir aNorm1, aNorm2; + const Handle(Geom_Surface)& aSurf = + this->getDFace()->GetSurface()->ChangeSurface().Surface().Surface(); + + if ((GeomLib::NormEstim(aSurf, theNodeInfo1.Point2d, Precision::Confusion(), aNorm1) == 0) && + (GeomLib::NormEstim(aSurf, theNodeInfo2.Point2d, Precision::Confusion(), aNorm2) == 0)) + { + Standard_Real anAngle = aNorm1.Angle(aNorm2); + if (anAngle > this->getParameters().AngleInterior) + return Standard_False; + } +#if 0 + else if (GeomLib::NormEstim(aSurf, theMidPoint, Precision::Confusion(), aNorm1) != 0) + { + // It is better to consider the singular point as a node of triangulation. + // However, it leads to hangs up meshing some faces (including faces with + // degenerated edges). E.g. tests "mesh standard_incmesh Q6". + // So, this code fragment is better to implement in the future. + return Standard_False; + } +#endif + + return Standard_True; + } + //! Computes deflection of the given point and caches it for //! insertion in case if it overflows deflection. //! @return True if point has been cached for insertion. template - inline void usePoint( + inline Standard_Boolean usePoint( const gp_XY& thePnt2d, const DeflectionFunctor& theDeflectionFunctor) { @@ -332,7 +373,10 @@ private: if (!checkDeflectionOfPointAndUpdateCache(thePnt2d, aPnt, theDeflectionFunctor.SquareDeviation(aPnt))) { myControlNodes->Append(thePnt2d); + return Standard_True; } + + return Standard_False; } //! Checks the given point for specified linear deflection. diff --git a/src/BRepMesh/BRepMesh_DelaunayNodeInsertionMeshAlgo.hxx b/src/BRepMesh/BRepMesh_DelaunayNodeInsertionMeshAlgo.hxx index 11091236c2..23863b74bd 100644 --- a/src/BRepMesh/BRepMesh_DelaunayNodeInsertionMeshAlgo.hxx +++ b/src/BRepMesh/BRepMesh_DelaunayNodeInsertionMeshAlgo.hxx @@ -46,7 +46,8 @@ protected: virtual std::pair getCellsCount (const Standard_Integer theVerticesNb) Standard_OVERRIDE { return BRepMesh_GeomTool::CellsCount (this->getDFace()->GetSurface(), theVerticesNb, - this->getParameters().Deflection, &this->getRangeSplitter()); + this->getDFace()->GetDeflection(), + &this->getRangeSplitter()); } //! Perfroms processing of generated mesh. Generates surface nodes and inserts them into structure. diff --git a/src/BRepMesh/BRepMesh_IncrementalMesh.hxx b/src/BRepMesh/BRepMesh_IncrementalMesh.hxx index b24e1aa5bd..3940eab4d0 100644 --- a/src/BRepMesh/BRepMesh_IncrementalMesh.hxx +++ b/src/BRepMesh/BRepMesh_IncrementalMesh.hxx @@ -51,7 +51,7 @@ public: //! @name mesher API Standard_EXPORT BRepMesh_IncrementalMesh(const TopoDS_Shape& theShape, const IMeshTools_Parameters& theParameters); - //! Performs meshing ot the shape. +//! Performs meshing ot the shape. Standard_EXPORT virtual void Perform() Standard_OVERRIDE; public: //! @name accessing to parameters. @@ -85,12 +85,23 @@ private: //! Initializes specific parameters inline void initParameters() { + if (myParameters.DeflectionInterior < Precision::Confusion()) + { + myParameters.DeflectionInterior = myParameters.Deflection; + } + if (myParameters.MinSize < Precision::Confusion()) { myParameters.MinSize = - Max(IMeshTools_Parameters::RelMinSize() * myParameters.Deflection, + Max(IMeshTools_Parameters::RelMinSize() * Min(myParameters.Deflection, + myParameters.DeflectionInterior), Precision::Confusion()); } + + if (myParameters.AngleInterior < Precision::Angular()) + { + myParameters.AngleInterior = 2.0 * myParameters.Angle; + } } public: //! @name plugin API diff --git a/src/BRepMesh/BRepMesh_ModelBuilder.cxx b/src/BRepMesh/BRepMesh_ModelBuilder.cxx index 63949d9d3f..dd9c3be4fa 100644 --- a/src/BRepMesh/BRepMesh_ModelBuilder.cxx +++ b/src/BRepMesh/BRepMesh_ModelBuilder.cxx @@ -70,7 +70,8 @@ Handle (IMeshData_Model) BRepMesh_ModelBuilder::Perform ( } else { - aModel->SetMaxSize(theParameters.Deflection); + aModel->SetMaxSize(Max(theParameters.Deflection, + theParameters.DeflectionInterior)); } Handle (IMeshTools_ShapeVisitor) aVisitor = diff --git a/src/BRepMesh/BRepMesh_NURBSRangeSplitter.cxx b/src/BRepMesh/BRepMesh_NURBSRangeSplitter.cxx index 6b09a39104..332be97de3 100644 --- a/src/BRepMesh/BRepMesh_NURBSRangeSplitter.cxx +++ b/src/BRepMesh/BRepMesh_NURBSRangeSplitter.cxx @@ -14,15 +14,14 @@ // commercial license or contractual agreement. #include + +#include +#include #include -#include -#include +#include #include -#include -#include -#include +#include #include -#include namespace { @@ -55,13 +54,6 @@ namespace { myParameters = theParameters; - if (myParameters.MinSize <= Precision::Confusion()) - { - myParameters.MinSize = - Max(IMeshTools_Parameters::RelMinSize() * myParameters.Deflection, - Precision::Confusion()); - } - Standard_Integer aStartIndex, aEndIndex; if (myIsoU) { @@ -106,8 +98,18 @@ namespace const Standard_Real aSqDist = BRepMesh_GeomTool::SquareDeflectionOfSegment( myPrevControlPnt, myCurrControlPnt, aMidPnt); - const Standard_Real aSqMaxDeflection = myDFace->GetDeflection() * myDFace->GetDeflection(); - if ((aSqDist > aSqMaxDeflection) && + Standard_Real anAngle = 0.0; + + if ((myPrevControlVec.SquareMagnitude() > Precision::SquareConfusion()) && + (myCurrControlVec.SquareMagnitude() > Precision::SquareConfusion())) + { + anAngle = myPrevControlVec.Angle(myCurrControlVec); + } + + const Standard_Real aSqMaxDeflection = myDFace->GetDeflection() * + myDFace->GetDeflection(); + + if (((aSqDist > aSqMaxDeflection) || (anAngle > myParameters.AngleInterior)) && aSqDist > myParameters.MinSize * myParameters.MinSize) { // insertion @@ -120,9 +122,8 @@ namespace // internals in order to prevent movement of triangle body // outside the surface in case of highly curved ones, e.g. // BSpline springs. - if (aSqDist < aSqMaxDeflection && - myControlParams->Length() > 3 && - theIndex < myControlParams->Length()) + if (((aSqDist < aSqMaxDeflection) || (anAngle < myParameters.AngleInterior)) && + myControlParams->Length() > 3 && theIndex < myControlParams->Length()) { // Remove too dense points const Standard_Real aTmpParam = myControlParams->Value(theIndex + 1); @@ -162,7 +163,7 @@ namespace // Lets check parameters for angular deflection. if (myPrevControlVec.SquareMagnitude() < gp::Resolution() || aTmpVec.SquareMagnitude() < gp::Resolution() || - myPrevControlVec.Angle(aTmpVec) < myParameters.Angle) + myPrevControlVec.Angle(aTmpVec) < myParameters.AngleInterior) { // For current Iso line we can remove this parameter. myControlParamsToRemove->Add(myCurrControlParam); @@ -257,6 +258,32 @@ namespace return isAdded; } + + //! Checks whether intervals should be split. + //! Returns true in case if it is impossible to compute normal + //! directly on intervals, false is returned elsewhere. + Standard_Boolean toSplitIntervals (const Handle (Geom_Surface)& theSurf, + const TColStd_Array1OfReal (&theIntervals)[2]) + { + Standard_Integer aIntervalU = theIntervals[0].Lower (); + for (; aIntervalU <= theIntervals[0].Upper (); ++aIntervalU) + { + const Standard_Real aParamU = theIntervals[0].Value(aIntervalU); + Standard_Integer aIntervalV = theIntervals[1].Lower (); + for (; aIntervalV <= theIntervals[1].Upper (); ++aIntervalV) + { + gp_Dir aNorm; + const Standard_Real aParamV = theIntervals[1].Value(aIntervalV); + if (GeomLib::NormEstim (theSurf, gp_Pnt2d (aParamU, aParamV), Precision::Confusion (), aNorm) != 0) + { + return Standard_True; + } + // TODO: do not split intervals if there is no normal in the middle of interval. + } + } + + return Standard_False; + } } //======================================================================= @@ -287,7 +314,10 @@ void BRepMesh_NURBSRangeSplitter::AdjustRange() Handle(IMeshData::ListOfPnt2d) BRepMesh_NURBSRangeSplitter::GenerateSurfaceNodes( const IMeshTools_Parameters& theParameters) const { - initParameters(); + if (!initParameters()) + { + return Handle(IMeshData::ListOfPnt2d)(); + } const std::pair& aRangeU = GetRangeU(); const std::pair& aRangeV = GetRangeV(); @@ -357,7 +387,7 @@ Handle(IMeshData::ListOfPnt2d) BRepMesh_NURBSRangeSplitter::GenerateSurfaceNodes // Function: initParameters // Purpose : //======================================================================= -void BRepMesh_NURBSRangeSplitter::initParameters() const +Standard_Boolean BRepMesh_NURBSRangeSplitter::initParameters() const { const Handle(BRepAdaptor_HSurface)& aSurface = GetSurface(); @@ -375,21 +405,79 @@ void BRepMesh_NURBSRangeSplitter::initParameters() const aSurface->UIntervals(aIntervals[0], aContinuity); aSurface->VIntervals(aIntervals[1], aContinuity); - Standard_Boolean isSplitIntervals = - (aIntervalsNb.first > 1 || aIntervalsNb.second > 1); + const Standard_Boolean isSplitIntervals = toSplitIntervals ( + aSurface->ChangeSurface().Surface().Surface(), aIntervals); - if (!isSplitIntervals && - (aSurface->GetType() == GeomAbs_BezierSurface || - aSurface->GetType() == GeomAbs_BSplineSurface)) + if (!initParamsFromIntervals(aIntervals[0], GetRangeU(), isSplitIntervals, + const_cast(GetParametersU()))) { - isSplitIntervals = (aSurface->NbUPoles() > 2 && aSurface->NbVPoles() > 2); + //if (!grabParamsOfEdges (Edge_Frontier, Param_U)) + { + return Standard_False; + } } - initParamsFromIntervals(aIntervals[0], GetRangeU(), isSplitIntervals, - const_cast(GetParametersU())); + if (!initParamsFromIntervals(aIntervals[1], GetRangeV(), isSplitIntervals, + const_cast(GetParametersV()))) + { + //if (!grabParamsOfEdges (Edge_Frontier, Param_V)) + { + return Standard_False; + } + } - initParamsFromIntervals(aIntervals[1], GetRangeV(), isSplitIntervals, - const_cast(GetParametersV())); + return grabParamsOfEdges(Edge_Internal, Param_U | Param_V); +} + +//======================================================================= +//function : grabParamsOfInternalEdges +//purpose : +//======================================================================= +Standard_Boolean BRepMesh_NURBSRangeSplitter::grabParamsOfEdges ( + const EdgeType theEdgeType, + const Standard_Integer theParamDimensionFlag) const +{ + if ((theParamDimensionFlag & (Param_U | Param_V)) == 0) + { + return Standard_False; + } + + const IMeshData::IFaceHandle& aDFace = GetDFace (); + for (Standard_Integer aWireIt = 0; aWireIt < aDFace->WiresNb (); ++aWireIt) + { + const IMeshData::IWireHandle& aDWire = aDFace->GetWire (aWireIt); + for (Standard_Integer aEdgeIt = 0; aEdgeIt < aDWire->EdgesNb (); ++aEdgeIt) + { + const IMeshData::IEdgePtr& aDEdge = aDWire->GetEdge (aEdgeIt); + for (Standard_Integer aPCurveIt = 0; aPCurveIt < aDEdge->PCurvesNb (); ++aPCurveIt) + { + const IMeshData::IPCurveHandle& aDPCurve = aDEdge->GetPCurve (aPCurveIt); + if (aDPCurve->GetFace () == aDFace) + { + if (theEdgeType == Edge_Internal && !aDPCurve->IsInternal ()) + { + continue; + } + + for (Standard_Integer aPointIt = 0; aPointIt < aDPCurve->ParametersNb (); ++aPointIt) + { + const gp_Pnt2d& aPnt2d = aDPCurve->GetPoint (aPointIt); + if (theParamDimensionFlag & Param_U) + { + const_cast(GetParametersU ()).Add (aPnt2d.X ()); + } + + if (theParamDimensionFlag & Param_V) + { + const_cast(GetParametersV ()).Add (aPnt2d.Y ()); + } + } + } + } + } + } + + return Standard_True; } //======================================================================= @@ -411,16 +499,13 @@ Handle(IMeshData::SequenceOfReal) BRepMesh_NURBSRangeSplitter::computeGrainAndFi aMinDiff /= theDelta; } - const Standard_Real aMinSize = - theParameters.MinSize > Precision::Confusion() ? theParameters.MinSize : - Max(IMeshTools_Parameters::RelMinSize() * theParameters.Deflection, - Precision::Confusion()); - - aMinDiff = Max(aMinSize, aMinDiff); + aMinDiff = Max(theParameters.MinSize, aMinDiff); const Standard_Real aDiffMaxLim = 0.1 * theRangeDiff; - const Standard_Real aDiffMinLim = Max(0.005 * theRangeDiff, 2. * theTol2d); - const Standard_Real aDiff = Max(aMinSize, Min(aDiffMaxLim, aDiffMinLim)); + const Standard_Real aDiffMinLim = Max(0.005 * theRangeDiff, + 2. * theTol2d); + const Standard_Real aDiff = Max(theParameters.MinSize, + Min(aDiffMaxLim, aDiffMinLim)); return filterParameters(theSourceParams, aMinDiff, aDiff, theAllocator); } diff --git a/src/BRepMesh/BRepMesh_NURBSRangeSplitter.hxx b/src/BRepMesh/BRepMesh_NURBSRangeSplitter.hxx index df0685d098..a74f2d23a2 100644 --- a/src/BRepMesh/BRepMesh_NURBSRangeSplitter.hxx +++ b/src/BRepMesh/BRepMesh_NURBSRangeSplitter.hxx @@ -46,7 +46,7 @@ public: protected: //! Initializes U and V parameters lists using CN continuity intervals. - Standard_EXPORT virtual void initParameters() const; + Standard_EXPORT virtual Standard_Boolean initParameters() const; private: @@ -66,6 +66,23 @@ private: const Standard_Real theFilterDist, const Handle(NCollection_IncAllocator)& theAllocator) const; + enum EdgeType + { + Edge_Internal, + Edge_Frontier + }; + + enum ParamDimension + { + Param_U = 0x1, + Param_V = 0x2 + }; + + //! Finds edges of discrete face and uses its points + //! as auxiliary control parameters for generation of nodes. + Standard_Boolean grabParamsOfEdges (const EdgeType theEdgeType, + const Standard_Integer theParamDimensionFlag) const; + private: GeomAbs_SurfaceType mySurfaceType; diff --git a/src/IMeshTools/IMeshTools_Parameters.hxx b/src/IMeshTools/IMeshTools_Parameters.hxx index 8598e03f99..fedfff395d 100644 --- a/src/IMeshTools/IMeshTools_Parameters.hxx +++ b/src/IMeshTools/IMeshTools_Parameters.hxx @@ -26,6 +26,8 @@ struct IMeshTools_Parameters { : Angle(0.5), Deflection(0.001), + AngleInterior(-1.0), + DeflectionInterior(-1.0), MinSize (-1.0), InParallel (Standard_False), Relative (Standard_False), @@ -42,12 +44,18 @@ struct IMeshTools_Parameters { return 0.1; } - //! Angular deflection + //! Angular deflection used to tessellate the boundary edges Standard_Real Angle; - //! Deflection + //!Linear deflection used to tessellate the boundary edges Standard_Real Deflection; + + //! Angular deflection used to tessellate the face interior + Standard_Real AngleInterior; + //! Linear deflection used to tessellate the face interior + Standard_Real DeflectionInterior; + //! Minimal allowed size of mesh element Standard_Real MinSize; diff --git a/src/MeshTest/MeshTest.cxx b/src/MeshTest/MeshTest.cxx index 02501b9783..fd6e23c518 100644 --- a/src/MeshTest/MeshTest.cxx +++ b/src/MeshTest/MeshTest.cxx @@ -118,8 +118,11 @@ static Standard_Integer incrementalmesh(Draw_Interpretor& di, Standard_Integer n Builds triangular mesh for the shape\n\ usage: incmesh Shape LinearDeflection [options]\n\ options:\n\ - -a val angular deflection in deg\n\ + -a val angular deflection for edges in deg\n\ (default ~28.64 deg = 0.5 rad)\n\n\ + -ai val angular deflection inside of faces in deg\n\ + (default ~57.29 deg = 1 rad)\n\n\ + -di val Linear deflection used to tessellate the face interior.\n\ -min minimum size parameter limiting size of triangle's\n\ edges to prevent sinking into amplification in case\n\ of distorted curves and surfaces\n\n\ @@ -142,6 +145,8 @@ options:\n\ } IMeshTools_Parameters aMeshParams; + aMeshParams.Deflection = aMeshParams.DeflectionInterior = + Max(Draw::Atof(argv[2]), Precision::Confusion()); if (nbarg > 3) { @@ -168,8 +173,16 @@ options:\n\ { aMeshParams.Angle = aVal * M_PI / 180.; } + else if (aOpt == "-ai") + { + aMeshParams.AngleInterior = aVal * M_PI / 180.; + } else if (aOpt == "-min") aMeshParams.MinSize = aVal; + else if (aOpt == "-di") + { + aMeshParams.DeflectionInterior = aVal; + } else --i; } diff --git a/tests/bugs/iges/buc60820_1 b/tests/bugs/iges/buc60820_1 index 04237f0ac7..ff82704d2c 100755 --- a/tests/bugs/iges/buc60820_1 +++ b/tests/bugs/iges/buc60820_1 @@ -12,5 +12,5 @@ tclean result incmesh result 0.1 triangles result -checktrinfo result -tri 646 -nod 568 +checktrinfo result -tri 638 -nod 564 checkview -display result -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/iges/buc60823 b/tests/bugs/iges/buc60823 index b1b0244ca5..4724b1cbc3 100755 --- a/tests/bugs/iges/buc60823 +++ b/tests/bugs/iges/buc60823 @@ -14,6 +14,6 @@ vdisplay result vsetdispmode result 1 vfit -checktrinfo result -tri 2788 -nod 2648 +checktrinfo result -tri 2708 -nod 2608 checkview -display result -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/iges/bug306 b/tests/bugs/iges/bug306 index dba9f81f4a..8b543c2862 100755 --- a/tests/bugs/iges/bug306 +++ b/tests/bugs/iges/bug306 @@ -20,7 +20,7 @@ vsetdispmode result 1 vdisplay result vfit -checktrinfo result -tri 6046 -nod 5924 +checktrinfo result -tri 5810 -nod 5806 checkmaxtol result -ref 0.92213088179312575 checknbshapes result -shell 1 diff --git a/tests/bugs/mesh/bug25519 b/tests/bugs/mesh/bug25519 index 7b8fd5e7e8..f0cbe48aaa 100755 --- a/tests/bugs/mesh/bug25519 +++ b/tests/bugs/mesh/bug25519 @@ -15,5 +15,5 @@ fit isos a 0 triangles a -checktrinfo a -tri 2971 -nod 1592 -defl 0.083467373173701759 -tol_rel_defl 0.05 -tol_rel_tri 0.05 -tol_rel_nod 0.05 +checktrinfo a -tri 2971 -nod 1592 -defl 0.091190343620839553 -tol_rel_defl 0.05 -tol_rel_tri 0.05 -tol_rel_nod 0.05 checkview -screenshot -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/mesh/bug30008_1 b/tests/bugs/mesh/bug30008_1 new file mode 100644 index 0000000000..1beebc5f40 --- /dev/null +++ b/tests/bugs/mesh/bug30008_1 @@ -0,0 +1,17 @@ +puts "=======" +puts "0030008: BRepMesh does not respect angular deflection in internal area of bspline surface" +puts "=======" +puts "" + +restore [locate_data_file bug30008_badshape.brep] result + +vinit +vsetdispmode 1 + +vdisplay result +vviewparams -scale 8.46292 -proj 0.653203 -0.644806 0.396926 -up -0.0109833 0.51609 0.856464 -at 347.559 1026.89 219.262 -eye 2080.75 -684.022 1272.45 + +tricheck result +checktrinfo result -tri 11826 -nod 7310 -defl 7.6167024939147652 + +checkview -screenshot -3d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/mesh/bug30008_2 b/tests/bugs/mesh/bug30008_2 new file mode 100644 index 0000000000..7daf3f0f66 --- /dev/null +++ b/tests/bugs/mesh/bug30008_2 @@ -0,0 +1,32 @@ +puts "=======" +puts "0030008: BRepMesh does not respect angular deflection in internal area of bspline surface" +puts "=======" +puts "" + +pcylinder cy 100 500 +bsplinecurve cc 5 4 -494.543457494654 6 500 4 507.372773368102 4 1501.91623086297 6 -500 -798.578274581199 755.284518447357 1 -500 -646.205376770376 627.428476092882 1 -500 -493.832478959552 499.572433738407 1 -500 -341.459581148729 371.716391383932 1 -500 -189.086683337906 243.860349029457 1 -500 -35.5842111132817 115.056481200973 1 -500 -33.7993197286247 114.2995541724 0.957903314642061 -500 -31.778022626919 114.565662984205 0.95790331464206 -500 -30.2498570721059 115.75876223351 1 -500 84.6852511720001 279.903107977019 1 -500 198.774589601206 442.839569245217 1 -500 312.863928030413 605.776030513415 1 -500 426.953266459619 768.712491781612 1 -500 541.042604888826 931.64895304981 1 +extsurf ss cc 1 0 0 + +mkface ff ss -494.543457494654 1501.91623086297 0 1000 +halfspace hs ff 0 0 500 + +bcut rc cy hs +explode rc f +copy rc_1 result +tscale result 0 0 0 0.01 +nurbsconvert result result + +incmesh result 0.15 -a 20 + +tricheck result +checktrinfo result -tri 193 -nod 147 -defl 0.042090809832482222 -tol_abs_defl 1.0e-7 + +vinit + +vdefaults -autoTriang 0 +vdisplay result +vfit +vsetdispmode 1 +vviewparams -scale 335.304 -eye 1.95918 0.124681 5.05411 -at 0.0736354 0.0378839 1.46922 -up -0.748808 0.542534 0.380715 -proj 0.4654 0.0214236 0.884841 + +checkview -screenshot -3d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/mesh/bug30167 b/tests/bugs/mesh/bug30167 index 547cdcfc95..4fd42ad6e5 100644 --- a/tests/bugs/mesh/bug30167 +++ b/tests/bugs/mesh/bug30167 @@ -12,6 +12,6 @@ vdisplay result vfit tricheck result -checktrinfo result -tri 4006 -nod 2092 -max_defl 0.46 +checktrinfo result -tri 3424 -nod 1801 -max_defl 0.52 checkview -screenshot -3d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/modalg_2/bug358 b/tests/bugs/modalg_2/bug358 index 8fa4df7aa2..620f147091 100755 --- a/tests/bugs/modalg_2/bug358 +++ b/tests/bugs/modalg_2/bug358 @@ -19,7 +19,7 @@ vdisplay result vfit vsetdispmode result 1 -checktrinfo result -tri 21446 -nod 11157 +checktrinfo result -tri 21654 -nod 11261 checkprops result -s 24861.2 checkshape result checkview -display result -2d -path ${imagedir}/${test_image}.png diff --git a/tests/bugs/moddata_2/fra62476_2 b/tests/bugs/moddata_2/fra62476_2 index 30e911d8b5..feebf5b4a4 100755 --- a/tests/bugs/moddata_2/fra62476_2 +++ b/tests/bugs/moddata_2/fra62476_2 @@ -13,5 +13,5 @@ tclean result incmesh result .1 triangles result -checktrinfo result -tri 355 -nod 210 +checktrinfo result -tri 335 -nod 200 checkview -display result -3d -path ${imagedir}/${test_image}.png diff --git a/tests/mesh/data/advanced/B8 b/tests/mesh/data/advanced/B8 index 5ffd436404..62f5350c5d 100755 --- a/tests/mesh/data/advanced/B8 +++ b/tests/mesh/data/advanced/B8 @@ -2,5 +2,5 @@ set TheFileName OCC357.brep if { [string compare $command "shading"] == 0 } { #set bug_area "OCC22687" set max_rel_tol_diff 0.25 - set rel_tol 1.0015290236679502 + set rel_tol 1.7957583466671934 } diff --git a/tests/mesh/data/standard/Q3 b/tests/mesh/data/standard/Q3 index 10ab26554b..e8a44d2e65 100755 --- a/tests/mesh/data/standard/Q3 +++ b/tests/mesh/data/standard/Q3 @@ -1,5 +1,5 @@ set TheFileName shading_147.brep if { [string compare $command "shading"] == 0 } { - set rel_tol 0.8093314937741523 + set rel_tol 0.8791879462861206 set max_rel_tol_diff 0.001 } diff --git a/tests/mesh/data/standard/U2 b/tests/mesh/data/standard/U2 index 2193082554..f5c48950be 100755 --- a/tests/mesh/data/standard/U2 +++ b/tests/mesh/data/standard/U2 @@ -3,7 +3,7 @@ set TheFileName shading_wrongshape_004.brep if { [string compare $command "shading"] == 0 } { set rel_tol 0.06073194250400039 } else { - set rel_tol 0.0021948131898279323 + set rel_tol 0.003702162749171707 } set max_rel_tol_diff 0.001 ###set bug_withouttri "OCC22687"