1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-05-01 10:26:12 +03:00
occt/src/BRepMesh/BRepMesh_GeomTool.cxx
msv 8109385697 0027362: Meshing performance
1) BRepMesh_FastDiscretFace.cxx:
- exclude planes from procedure of inserting internal points.
- localize declaration of the container aNewVertices in each method where it is needed.
- correct the logic of the method insertInternalVerticesOther, so that to separate the processes of removing extra points and addition of new points in different cycles, thus making the code more clear and in addition stable.
- insert useful output of intermediate mesh to a file in control() method for debug purposes (with definition DEBUG_MESH).

2) Add global functions MeshTest_DrawTriangles and MeshTest_DrawLinks to draw mesh data in debug session.

3) BRepMesh_FastDiscret:
- in the method Add calculations of deflections have been simplified for non-relative mode.
- replace the attribute MinDist with Deflection in EdgeAttributes structure. Correct its computation so that later to store this value as deflection of the polygon.

4) Make protection against exception in the method BRepMesh_Delaun::addTriangle() when an added triangle creates a third connection of a mesh edge.

5) BRepMesh_EdgeTessellator.cxx, BRepMesh_EdgeTessellationExtractor.cxx: use Geom2dAdaptor_Curve in order to use b-spline cache while computing value on a curve.

6) In BndLib_Box2dCurve::PerformBSpline, avoid creating new b-spline in case of requested parameter range differ from natural bounds insignificantly.

7) In GeomAdaptor classes, postpone building of cache till the time of its actual usage. So, creation of an adapter to compute intervals of continuity does not lead to creation of internal cache.

8) In the methods BRepAdaptor_Curve::Bezier and BSpline do not call Transformed() if transformation is identity.

9) In the classes Geom_BSplineCurve, Geom_BSplineSurface, Geom_BezierCurve, Geom_BezierSurface, Geom2d_BSplineCurve, Geom2d_BezierCurve change the method Pole() to return the point by const reference.

10) In CPnts_AbscissaPoint.cxx, compute derivative by D1 instead of DN to make use of b-spline cache.

11) Change test cases to actual state:
  - Number of triangles/nodes can grow due to more accurate work with deflection of edges. Now the edge is tessellated using its own tolerance instead of maximal tolerance of all shapes in the face.
  - Accept new numbers of mesh errors (free links, free nodes) for really bad shapes.
  - Correct the test "bugs/mesh/bug25612" to produce stable result.
  - Disable redundant checks in test cases bug25378* (lower limit for computation time).

- Speed up iso-lines computation for offset of bspline surfaces. For that use adaptor instead of original surface in evaluator of approximation.
- Add output of polylines for debug of insertInternalVerticesOther().

Reference data in test case bugs\moddata_2\bug453_3 have been changed to be close to expected theoretical values. This makes the test give stable result on different platforms.
2016-07-07 14:24:39 +03:00

333 lines
10 KiB
C++

// Created on: 1993-09-29
// Created by: Isabelle GRIGNON
// Copyright (c) 1993-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BRepMesh_GeomTool.hxx>
#include <TopAbs_Orientation.hxx>
#include <CSLib.hxx>
#include <Precision.hxx>
#include <Adaptor3d_IsoCurve.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <BRepAdaptor_HSurface.hxx>
#include <Geom2d_Curve.hxx>
#include <BRep_Tool.hxx>
//=======================================================================
//function : Constructor
//purpose :
//=======================================================================
BRepMesh_GeomTool::BRepMesh_GeomTool(
const BRepAdaptor_Curve& theCurve,
const Standard_Real theFirstParam,
const Standard_Real theLastParam,
const Standard_Real theLinDeflection,
const Standard_Real theAngDeflection,
const Standard_Integer theMinPointsNb,
const Standard_Real theMinSize)
: myEdge(&theCurve.Edge()),
myIsoType(GeomAbs_NoneIso)
{
myDiscretTool.Initialize(theCurve, theFirstParam, theLastParam,
theAngDeflection, theLinDeflection, theMinPointsNb,
Precision::PConfusion(), theMinSize);
}
//=======================================================================
//function : Constructor
//purpose :
//=======================================================================
BRepMesh_GeomTool::BRepMesh_GeomTool(
const Handle(BRepAdaptor_HSurface)& theSurface,
const GeomAbs_IsoType theIsoType,
const Standard_Real theParamIso,
const Standard_Real theFirstParam,
const Standard_Real theLastParam,
const Standard_Real theLinDeflection,
const Standard_Real theAngDeflection,
const Standard_Integer theMinPointsNb,
const Standard_Real theMinSize)
: myEdge(NULL),
myIsoType(theIsoType)
{
Adaptor3d_IsoCurve aIso(theSurface, theIsoType, theParamIso,
theFirstParam, theLastParam);
myDiscretTool.Initialize(aIso, theFirstParam, theLastParam,
theAngDeflection, theLinDeflection, theMinPointsNb,
Precision::PConfusion(), theMinSize);
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
Standard_Boolean BRepMesh_GeomTool::Value(
const Standard_Integer theIndex,
Standard_Real& theParam,
gp_Pnt& thePoint) const
{
if (theIndex < 1 || theIndex > NbPoints())
return Standard_False;
if (myEdge == NULL)
return Standard_False;
thePoint = myDiscretTool.Value(theIndex);
theParam = myDiscretTool.Parameter(theIndex);
return Standard_True;
}
//=======================================================================
//function : Value
//purpose :
//=======================================================================
Standard_Boolean BRepMesh_GeomTool::Value(const Standard_Integer theIndex,
const Standard_Real theIsoParam,
Standard_Real& theParam,
gp_Pnt& thePoint,
gp_Pnt2d& theUV) const
{
if (theIndex < 1 || theIndex > NbPoints())
return Standard_False;
thePoint = myDiscretTool.Value(theIndex);
theParam = myDiscretTool.Parameter(theIndex);
if (myIsoType == GeomAbs_IsoU)
theUV.SetCoord(theIsoParam, theParam);
else
theUV.SetCoord(theParam, theIsoParam);
return Standard_True;
}
//=======================================================================
//function : Normal
//purpose :
//=======================================================================
Standard_Boolean BRepMesh_GeomTool::Normal(
const Handle(BRepAdaptor_HSurface)& theSurface,
const Standard_Real theParamU,
const Standard_Real theParamV,
gp_Pnt& thePoint,
gp_Dir& theNormal)
{
Standard_Boolean isOK = Standard_True;
gp_Vec aD1U, aD1V;
theSurface->D1(theParamU, theParamV, thePoint, aD1U, aD1V);
CSLib_DerivativeStatus aStatus;
CSLib::Normal(aD1U, aD1V, Precision::Angular(), aStatus, theNormal);
if (aStatus != CSLib_Done)
{
gp_Vec aD2U,aD2V,aD2UV;
theSurface->D2(theParamU, theParamV, thePoint, aD1U, aD1V, aD2U, aD2V, aD2UV);
CSLib_NormalStatus aNormalStatus;
CSLib::Normal(aD1U, aD1V, aD2U, aD2V, aD2UV, Precision::Angular(),
isOK, aNormalStatus, theNormal);
}
if (!isOK)
return Standard_False;
const TopoDS_Face& aFace = ((BRepAdaptor_Surface*)&(theSurface->Surface()))->Face();
TopAbs_Orientation aOri = aFace.Orientation();
if (aOri == TopAbs_REVERSED)
theNormal.Reverse();
return Standard_True;
}
//=============================================================================
//function : IntLinLin
//purpose :
//=============================================================================
BRepMesh_GeomTool::IntFlag BRepMesh_GeomTool::IntLinLin(
const gp_XY& theStartPnt1,
const gp_XY& theEndPnt1,
const gp_XY& theStartPnt2,
const gp_XY& theEndPnt2,
gp_XY& theIntPnt,
Standard_Real (&theParamOnSegment)[2])
{
gp_XY aVec1 = theEndPnt1 - theStartPnt1;
gp_XY aVec2 = theEndPnt2 - theStartPnt2;
gp_XY aVecO1O2 = theStartPnt2 - theStartPnt1;
Standard_Real aCrossD1D2 = aVec1 ^ aVec2;
Standard_Real aCrossD1D3 = aVecO1O2 ^ aVec2;
const Standard_Real aPrec = gp::Resolution();
// Are edgegs codirectional
if ( Abs( aCrossD1D2 ) < aPrec )
{
// Just a parallel case?
if( Abs( aCrossD1D3 ) < aPrec )
return BRepMesh_GeomTool::Same;
else
return BRepMesh_GeomTool::NoIntersection;
}
theParamOnSegment[0] = aCrossD1D3 / aCrossD1D2;
theIntPnt = theStartPnt1 + theParamOnSegment[0] * aVec1;
Standard_Real aCrossD2D3 = aVecO1O2 ^ aVec1;
theParamOnSegment[1] = aCrossD2D3 / aCrossD1D2;
return BRepMesh_GeomTool::Cross;
}
//=============================================================================
//function : IntSegSeg
//purpose :
//=============================================================================
BRepMesh_GeomTool::IntFlag BRepMesh_GeomTool::IntSegSeg(
const gp_XY& theStartPnt1,
const gp_XY& theEndPnt1,
const gp_XY& theStartPnt2,
const gp_XY& theEndPnt2,
const Standard_Boolean isConsiderEndPointTouch,
const Standard_Boolean isConsiderPointOnSegment,
gp_Pnt2d& theIntPnt)
{
Standard_Integer aPointHash[] = {
classifyPoint(theStartPnt1, theEndPnt1, theStartPnt2),
classifyPoint(theStartPnt1, theEndPnt1, theEndPnt2 ),
classifyPoint(theStartPnt2, theEndPnt2, theStartPnt1),
classifyPoint(theStartPnt2, theEndPnt2, theEndPnt1 )
};
// Consider case when edges have shared vertex
if ( aPointHash[0] < 0 || aPointHash[1] < 0 )
{
if ( isConsiderEndPointTouch )
return BRepMesh_GeomTool::EndPointTouch;
return BRepMesh_GeomTool::NoIntersection;
}
Standard_Integer aPosHash =
aPointHash[0] + aPointHash[1] + aPointHash[2] + aPointHash[3];
/*=========================================*/
/* 1) hash code == 1:
0+
/
0 1/ 0
+======+==========+
2) hash code == 2:
0 1 1 0
a) +----+========+---+
0 1 1 0
b) +-------+===+=====+
*/
/*=========================================*/
if ( aPosHash == 1 )
{
if (isConsiderPointOnSegment)
{
if (aPointHash[0] == 1)
theIntPnt = theStartPnt1;
else if (aPointHash[1] == 1)
theIntPnt = theEndPnt1;
else if (aPointHash[2] == 1)
theIntPnt = theStartPnt2;
else
theIntPnt = theEndPnt2;
return BRepMesh_GeomTool::PointOnSegment;
}
return BRepMesh_GeomTool::NoIntersection;
}
else if ( aPosHash == 2 )
return BRepMesh_GeomTool::Glued;
Standard_Real aParam[2];
IntFlag aIntFlag = IntLinLin(theStartPnt1, theEndPnt1,
theStartPnt2, theEndPnt2, theIntPnt.ChangeCoord(), aParam);
if (aIntFlag == BRepMesh_GeomTool::NoIntersection)
return BRepMesh_GeomTool::NoIntersection;
if (aIntFlag == BRepMesh_GeomTool::Same)
{
if ( aPosHash < -2 )
return BRepMesh_GeomTool::Same;
else if ( aPosHash == -1 )
return BRepMesh_GeomTool::Glued;
return BRepMesh_GeomTool::NoIntersection;
}
// Cross
// Intersection is out of segments ranges
const Standard_Real aPrec = Precision::PConfusion();
const Standard_Real aEndPrec = 1 - aPrec;
for (Standard_Integer i = 0; i < 2; ++i)
{
if( aParam[i] < aPrec || aParam[i] > aEndPrec )
return BRepMesh_GeomTool::NoIntersection;
}
return BRepMesh_GeomTool::Cross;
}
//=============================================================================
//function : classifyPoint
//purpose :
//=============================================================================
Standard_Integer BRepMesh_GeomTool::classifyPoint(
const gp_XY& thePoint1,
const gp_XY& thePoint2,
const gp_XY& thePointToCheck)
{
gp_XY aP1 = thePoint2 - thePoint1;
gp_XY aP2 = thePointToCheck - thePoint1;
const Standard_Real aPrec = Precision::PConfusion();
const Standard_Real aSqPrec = aPrec * aPrec;
Standard_Real aDist = Abs(aP1 ^ aP2);
if (aDist > aPrec)
{
aDist = (aDist * aDist) / aP1.SquareModulus();
if (aDist > aSqPrec)
return 0; //out
}
gp_XY aMult = aP1.Multiplied(aP2);
if ( aMult.X() < 0.0 || aMult.Y() < 0.0 )
return 0; //out
if (aP1.SquareModulus() < aP2.SquareModulus())
return 0; //out
if (thePointToCheck.IsEqual(thePoint1, aPrec) ||
thePointToCheck.IsEqual(thePoint2, aPrec))
{
return -1; //coinsides with an end point
}
return 1;
}