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

Integration of OCCT 6.5.0 from SVN

This commit is contained in:
bugmaster
2011-03-16 07:30:28 +00:00
committed by bugmaster
parent 4903637061
commit 7fd59977df
16375 changed files with 3882564 additions and 0 deletions

231
src/BRepGProp/BRepGProp.cdl Executable file
View File

@@ -0,0 +1,231 @@
-- File: BRepGProp.cdl
-- Created: Fri Dec 4 16:56:29 1992
-- Author: Isabelle GRIGNON
-- <isg@sdsun2>
---Copyright: Matra Datavision 1992
package BRepGProp
---Purpose: Provides global functions to compute a shape's global
-- properties for lines, surfaces or volumes, and bring
-- them together with the global properties already
-- computed for a geometric system.
-- The global properties computed for a system are :
-- - its mass,
-- - its center of mass,
-- - its matrix of inertia,
-- - its moment about an axis,
-- - its radius of gyration about an axis,
-- - and its principal properties of inertia such as
-- principal axis, principal moments, principal radius of gyration.
uses GProp,
BRepAdaptor,
BRepTools,
BRep,
TopExp,
TopoDS,
Geom2dAdaptor,
gp,
GeomAbs,
TColStd
is
class EdgeTool;
class Face;
class Domain;
class Cinert instantiates CGProps from GProp( Curve from BRepAdaptor,
EdgeTool from BRepGProp);
class Sinert instantiates SGProps from GProp( Edge from TopoDS,
Face from BRepGProp ,
Domain from BRepGProp);
class Vinert instantiates VGProps from GProp( Edge from TopoDS,
Face from BRepGProp,
Domain from BRepGProp);
class VinertGK instantiates VGPropsGK from GProp( Edge from TopoDS,
Face from BRepGProp,
Domain from BRepGProp);
--
-- Package methods to compute global properties.
--
LinearProperties(S : Shape from TopoDS; LProps : in out GProps from GProp);
---Purpose: Computes the linear global properties of the shape S,
-- i.e. the global properties induced by each edge of the
-- shape S, and brings them together with the global
-- properties still retained by the framework LProps. If
-- the current system of LProps was empty, its global
-- properties become equal to the linear global
-- properties of S.
-- For this computation no linear density is attached to
-- the edges. So, for example, the added mass
-- corresponds to the sum of the lengths of the edges of
-- S. The density of the composed systems, i.e. that of
-- each component of the current system of LProps, and
-- that of S which is considered to be equal to 1, must be coherent.
-- Note that this coherence cannot be checked. You are
-- advised to use a separate framework for each
-- density, and then to bring these frameworks together
-- into a global one.
-- The point relative to which the inertia of the system is
-- computed is the reference point of the framework LProps.
-- Note: if your programming ensures that the framework
-- LProps retains only linear global properties (brought
-- together for example, by the function
-- LinearProperties) for objects the density of which is
-- equal to 1 (or is not defined), the function Mass will
-- return the total length of edges of the system analysed by LProps.
-- Warning
-- No check is performed to verify that the shape S
-- retains truly linear properties. If S is simply a vertex, it
-- is not considered to present any additional global properties.
SurfaceProperties(S : Shape from TopoDS; SProps : in out GProps from GProp);
---Purpose: Computes the surface global properties of the
-- shape S, i.e. the global properties induced by each
-- face of the shape S, and brings them together with
-- the global properties still retained by the framework
-- SProps. If the current system of SProps was empty,
-- its global properties become equal to the surface
-- global properties of S.
-- For this computation, no surface density is attached
-- to the faces. Consequently, the added mass
-- corresponds to the sum of the areas of the faces of
-- S. The density of the component systems, i.e. that
-- of each component of the current system of
-- SProps, and that of S which is considered to be
-- equal to 1, must be coherent.
-- Note that this coherence cannot be checked. You
-- are advised to use a framework for each different
-- value of density, and then to bring these
-- frameworks together into a global one.
-- The point relative to which the inertia of the system
-- is computed is the reference point of the framework SProps.
-- Note : if your programming ensures that the
-- framework SProps retains only surface global
-- properties, brought together, for example, by the
-- function SurfaceProperties, for objects the density
-- of which is equal to 1 (or is not defined), the
-- function Mass will return the total area of faces of
-- the system analysed by SProps.
-- Warning
-- No check is performed to verify that the shape S
-- retains truly surface properties. If S is simply a
-- vertex, an edge or a wire, it is not considered to
-- present any additional global properties.
SurfaceProperties(S : Shape from TopoDS; SProps : in out GProps from GProp;
Eps: Real) returns Real;
---Purpose: Updates <SProps> with the shape <S>, that contains its pricipal properties.
-- The surface properties of all the faces in <S> are computed.
-- Adaptive 2D Gauss integration is used.
-- Parameter Eps sets maximal relative error of computed mass (area) for each face.
-- Error is calculated as Abs((M(i+1)-M(i))/M(i+1)), M(i+1) and M(i) are values
-- for two successive steps of adaptive integration.
-- Method returns estimation of relative error reached for whole shape.
-- WARNING: if Eps > 0.001 algorithm performs non-adaptive integration.
------------------------
-- VolumeProperties --
------------------------
---Purpose:
-- Computes the global volume properties of the solid
-- S, and brings them together with the global
-- properties still retained by the framework VProps. If
-- the current system of VProps was empty, its global
-- properties become equal to the global properties of S for volume.
-- For this computation, no volume density is attached
-- to the solid. Consequently, the added mass
-- corresponds to the volume of S. The density of the
-- component systems, i.e. that of each component of
-- the current system of VProps, and that of S which
-- is considered to be equal to 1, must be coherent to each other.
-- Note that this coherence cannot be checked. You
-- are advised to use a separate framework for each
-- density, and then to bring these frameworks
-- together into a global one.
-- The point relative to which the inertia of the system
-- is computed is the reference point of the framework VProps.
-- Note: if your programming ensures that the
-- framework VProps retains only global properties of
-- volume (brought together for example, by the
-- function VolumeProperties) for objects the density
-- of which is equal to 1 (or is not defined), the
-- function Mass will return the total volume of the
-- solids of the system analysed by VProps.
-- Warning
-- The shape S must represent an object whose
-- global volume properties can be computed. It may
-- be a finite solid, or a series of finite solids all
-- oriented in a coherent way. Nonetheless, S must be
-- exempt of any free boundary. Note that these
-- conditions of coherence are not checked by this
-- algorithm, and results will be false if they are not respected.
VolumeProperties(S : Shape from TopoDS; VProps : in out GProps from GProp;
OnlyClosed: Boolean = Standard_False);
VolumeProperties(S : Shape from TopoDS; VProps : in out GProps from GProp;
Eps: Real; OnlyClosed: Boolean = Standard_False) returns Real;
---Purpose: Updates <VProps> with the shape <S>, that contains its pricipal properties.
-- The volume properties of all the FORWARD and REVERSED faces in <S> are computed.
-- If OnlyClosed is True then computed faces must belong to closed Shells.
-- Adaptive 2D Gauss integration is used.
-- Parameter Eps sets maximal relative error of computed mass (volume) for each face.
-- Error is calculated as Abs((M(i+1)-M(i))/M(i+1)), M(i+1) and M(i) are values
-- for two successive steps of adaptive integration.
-- Method returns estimation of relative error reached for whole shape.
-- WARNING: if Eps > 0.001 algorithm performs non-adaptive integration.
-- ----------------------------------------------------------------------------------------
VolumePropertiesGK(S : Shape from TopoDS;
VProps : in out GProps from GProp;
Eps : Real from Standard = 0.001;
OnlyClosed: Boolean from Standard = Standard_False;
IsUseSpan : Boolean from Standard = Standard_False;
CGFlag : Boolean from Standard = Standard_False;
IFlag : Boolean from Standard = Standard_False)
returns Real;
---Purpose: Updates <VProps> with the shape <S>, that contains its pricipal properties.
-- The volume properties of all the FORWARD and REVERSED faces in <S> are computed.
-- If OnlyClosed is True then computed faces must belong to closed Shells.
-- Adaptive 2D Gauss integration is used.
-- Parameter IsUseSpan says if it is necessary to define spans on a face.
-- This option has an effect only for BSpline faces.
-- Parameter Eps sets maximal relative error of computed property for each face.
-- Error is delivered by the adaptive Gauss-Kronrod method of integral computation
-- that is used for properties computation.
-- Method returns estimation of relative error reached for whole shape.
-- Returns negative value if the computation is failed.
VolumePropertiesGK(S : Shape from TopoDS;
VProps : in out GProps from GProp;
thePln: Pln from gp;
Eps : Real from Standard = 0.001;
OnlyClosed: Boolean from Standard = Standard_False;
IsUseSpan : Boolean from Standard = Standard_False;
CGFlag : Boolean from Standard = Standard_False;
IFlag : Boolean from Standard = Standard_False)
returns Real;
end BRepGProp;

411
src/BRepGProp/BRepGProp.cxx Executable file
View File

@@ -0,0 +1,411 @@
#include <BRepGProp.hxx>
#include <BRepGProp_Cinert.hxx>
#include <BRepGProp_Sinert.hxx>
#include <BRepGProp_Vinert.hxx>
#include <BRepGProp_VinertGK.hxx>
#include <BRepGProp_Face.hxx>
#include <BRepGProp_Domain.hxx>
#include <TopoDS.hxx>
#include <BRepAdaptor_Curve.hxx>
#include <TopTools.hxx>
#include <BRep_Tool.hxx>
#include <TopTools_ListOfShape.hxx>
#include <BRepCheck_Shell.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
#ifdef DEB
static Standard_Integer AffichEps = 0;
#endif
static gp_Pnt roughBaryCenter(const TopoDS_Shape& S){
Standard_Integer i; TopExp_Explorer ex;
gp_XYZ xyz(0,0,0);
for (ex.Init(S,TopAbs_VERTEX), i = 0; ex.More(); ex.Next(), i++)
xyz += BRep_Tool::Pnt(TopoDS::Vertex(ex.Current())).XYZ();
if ( i > 0 ) xyz /= i;
return gp_Pnt(xyz);
}
void BRepGProp::LinearProperties(const TopoDS_Shape& S, GProp_GProps& SProps){
// find the origin
gp_Pnt P(0,0,0);
P.Transform(S.Location());
SProps = GProp_GProps(P);
BRepAdaptor_Curve BAC;
// Standard_Integer n,i;
TopExp_Explorer ex;
for (ex.Init(S,TopAbs_EDGE); ex.More(); ex.Next()) {
BAC.Initialize(TopoDS::Edge(ex.Current()));
BRepGProp_Cinert CG(BAC,P);
SProps.Add(CG);
}
}
static Standard_Real surfaceProperties(const TopoDS_Shape& S, GProp_GProps& Props, const Standard_Real Eps){
Standard_Integer i, iErrorMax = 0;
Standard_Real ErrorMax = 0.0, Error;
TopExp_Explorer ex;
gp_Pnt P(roughBaryCenter(S));
BRepGProp_Sinert G; G.SetLocation(P);
BRepGProp_Face BF;
BRepGProp_Domain BD;
for (ex.Init(S,TopAbs_FACE), i = 1; ex.More(); ex.Next(), i++) {
const TopoDS_Face& F = TopoDS::Face(ex.Current());
BF.Load(F);
if(!BF.NaturalRestriction()) BD.Init(F);
if(Eps < 1.0) {
G.Perform(BF, BD, Eps);
Error = G.GetEpsilon();
if(ErrorMax < Error){ ErrorMax = Error; iErrorMax = i;}
} else {
if(BF.NaturalRestriction()) G.Perform(BF);
else G.Perform(BF, BD);
}
Props.Add(G);
#ifdef DEB
if(AffichEps) cout<<"\n"<<i<<":\tEpsArea = "<< G.GetEpsilon();
#endif
}
#ifdef DEB
if(AffichEps) cout<<"\n-----------------\n"<<iErrorMax<<":\tMaxError = "<<ErrorMax<<"\n";
#endif
return ErrorMax;
}
void BRepGProp::SurfaceProperties(const TopoDS_Shape& S, GProp_GProps& Props){
// find the origin
gp_Pnt P(0,0,0);
P.Transform(S.Location());
Props = GProp_GProps(P);
surfaceProperties(S,Props,1.0);
}
Standard_Real BRepGProp::SurfaceProperties(const TopoDS_Shape& S, GProp_GProps& Props, const Standard_Real Eps){
// find the origin
gp_Pnt P(0,0,0); P.Transform(S.Location());
Props = GProp_GProps(P);
Standard_Real ErrorMax = surfaceProperties(S,Props,Eps);
return ErrorMax;
}
//=======================================================================
//function : volumeProperties
//purpose :
//=======================================================================
static Standard_Real volumeProperties(const TopoDS_Shape& S, GProp_GProps& Props, const Standard_Real Eps){
Standard_Integer i, iErrorMax = 0;
Standard_Real ErrorMax = 0.0, Error = 0.0;
TopExp_Explorer ex;
gp_Pnt P(roughBaryCenter(S));
BRepGProp_Vinert G; G.SetLocation(P);
BRepGProp_Face BF;
BRepGProp_Domain BD;
for (ex.Init(S,TopAbs_FACE), i = 1; ex.More(); ex.Next(), i++) {
const TopoDS_Face& F = TopoDS::Face(ex.Current());
if ((F.Orientation() == TopAbs_FORWARD) || (F.Orientation() == TopAbs_REVERSED)){
BF.Load(F);
if(!BF.NaturalRestriction()) BD.Init(F);
if(Eps < 1.0) {
G.Perform(BF, BD, Eps);
Error = G.GetEpsilon();
if(ErrorMax < Error){ ErrorMax = Error; iErrorMax = i;}
}
else {
if(BF.NaturalRestriction()) G.Perform(BF);
else G.Perform(BF, BD);
}
Props.Add(G);
#ifdef DEB
if(AffichEps) cout<<"\n"<<i<<":\tEpsVolume = "<< G.GetEpsilon();
#endif
}
}
#ifdef DEB
if(AffichEps) cout<<"\n-----------------\n"<<iErrorMax<<":\tMaxError = "<<ErrorMax<<"\n";
#endif
return ErrorMax;
}
void BRepGProp::VolumeProperties(const TopoDS_Shape& S, GProp_GProps& Props, const Standard_Boolean OnlyClosed){
// find the origin
gp_Pnt P(0,0,0); P.Transform(S.Location());
Props = GProp_GProps(P);
Standard_Real Error = 0.0;
if(OnlyClosed){
TopExp_Explorer ex(S,TopAbs_SHELL);
for (; ex.More(); ex.Next()) {
const TopoDS_Shape& Sh = ex.Current();
if(BRep_Tool::IsClosed(Sh)) Error = volumeProperties(Sh,Props,1.0);
}
} else Error = volumeProperties(S,Props,1.0);
}
//=======================================================================
//function : VolumeProperties
//purpose :
//=======================================================================
Standard_Real BRepGProp::VolumeProperties(const TopoDS_Shape& S, GProp_GProps& Props,
const Standard_Real Eps, const Standard_Boolean OnlyClosed)
{
// find the origin
gp_Pnt P(0,0,0); P.Transform(S.Location());
Props = GProp_GProps(P);
Standard_Integer i, iErrorMax = 0;
Standard_Real ErrorMax = 0.0, Error = 0.0;
if(OnlyClosed){
TopExp_Explorer ex(S,TopAbs_SHELL);
for (i = 1; ex.More(); ex.Next(), i++) {
const TopoDS_Shape& Sh = ex.Current();
if(BRep_Tool::IsClosed(Sh)) {
Error = volumeProperties(Sh,Props,Eps);
if(ErrorMax < Error){ ErrorMax = Error; iErrorMax = i;}
}
}
} else ErrorMax = volumeProperties(S,Props,Eps);
#ifdef DEB
if(AffichEps) cout<<"\n\n==================="<<iErrorMax<<":\tMaxEpsVolume = "<<ErrorMax<<"\n";
#endif
return ErrorMax;
}
//===========================================================================================//
// Volume properties by Gauss-Kronrod integration
//===========================================================================================//
//=======================================================================
//function : VolumePropertiesGK
//purpose :
//=======================================================================
static Standard_Real volumePropertiesGK(const TopoDS_Shape &theShape,
GProp_GProps &theProps,
const Standard_Real theTol,
const Standard_Boolean IsUseSpan,
const Standard_Boolean CGFlag,
const Standard_Boolean IFlag)
{
TopExp_Explorer anExp;
anExp.Init(theShape, TopAbs_FACE);
Standard_Real aTol = theTol;
// Compute properties.
gp_Pnt aLoc(roughBaryCenter(theShape));
BRepGProp_VinertGK aVProps;
BRepGProp_Face aPropFace(IsUseSpan);
BRepGProp_Domain aPropDomain;
Standard_Real aLocalError;
Standard_Real anError = 0.;
aVProps.SetLocation(aLoc);
for (; anExp.More(); anExp.Next()) {
TopoDS_Face aFace = TopoDS::Face(anExp.Current());
if (aFace.Orientation() == TopAbs_FORWARD ||
aFace.Orientation() == TopAbs_REVERSED) {
aPropFace.Load(aFace);
if(aPropFace.NaturalRestriction())
aLocalError = aVProps.Perform(aPropFace, aTol, CGFlag, IFlag);
else {
aPropDomain.Init(aFace);
aLocalError = aVProps.Perform(aPropFace, aPropDomain, aTol, CGFlag, IFlag);
}
if (aLocalError < 0.)
return aLocalError;
anError += aLocalError;
theProps.Add(aVProps);
}
}
return anError;
}
//=======================================================================
//function : VolumePropertiesGK
//purpose :
//=======================================================================
Standard_Real BRepGProp::VolumePropertiesGK(const TopoDS_Shape &S,
GProp_GProps &Props,
const Standard_Real Eps,
const Standard_Boolean OnlyClosed,
const Standard_Boolean IsUseSpan,
const Standard_Boolean CGFlag,
const Standard_Boolean IFlag)
{
gp_Pnt P(0,0,0);
Standard_Real anError = 0.;
P.Transform(S.Location());
Props = GProp_GProps(P);
if(OnlyClosed) {
// To select closed shells.
TopExp_Explorer anExp;
TopTools_ListOfShape aClosedShells;
anExp.Init(S, TopAbs_SHELL);
for (; anExp.More(); anExp.Next()) {
const TopoDS_Shape &aShell = anExp.Current();
BRepCheck_Shell aChecker(TopoDS::Shell(aShell));
BRepCheck_Status aStatus = aChecker.Closed(Standard_False);
if(aStatus == BRepCheck_NoError)
aClosedShells.Append(aShell);
}
if (aClosedShells.IsEmpty())
return -1.;
// Compute the properties for each closed shell.
Standard_Real aTol = Eps;
Standard_Real aLocalError;
TopTools_ListIteratorOfListOfShape anIter(aClosedShells);
for (; anIter.More(); anIter.Next()) {
const TopoDS_Shape &aShell = anIter.Value();
aLocalError = volumePropertiesGK(aShell, Props, aTol, IsUseSpan, CGFlag, IFlag);
if (aLocalError < 0)
return aLocalError;
anError += aLocalError;
}
} else
anError = volumePropertiesGK(S, Props, Eps, IsUseSpan, CGFlag, IFlag);
Standard_Real vol = Props.Mass();
if(vol > Epsilon(1.)) anError /= vol;
return anError;
}
//=======================================================================
//function : VolumeProperties
//purpose :
//=======================================================================
static Standard_Real volumePropertiesGK(const TopoDS_Shape &theShape,
GProp_GProps &theProps,
const gp_Pln &thePln,
const Standard_Real theTol,
const Standard_Boolean IsUseSpan,
const Standard_Boolean CGFlag,
const Standard_Boolean IFlag)
{
TopExp_Explorer anExp;
anExp.Init(theShape, TopAbs_FACE);
Standard_Real aTol = theTol;
// Compute properties.
gp_Pnt aLoc(roughBaryCenter(theShape));
BRepGProp_VinertGK aVProps;
BRepGProp_Face aPropFace(IsUseSpan);
BRepGProp_Domain aPropDomain;
Standard_Real aLocalError;
Standard_Real anError = 0.;
aVProps.SetLocation(aLoc);
for (; anExp.More(); anExp.Next()) {
TopoDS_Face aFace = TopoDS::Face(anExp.Current());
if (aFace.Orientation() == TopAbs_FORWARD ||
aFace.Orientation() == TopAbs_REVERSED) {
aPropFace.Load(aFace);
if(aPropFace.NaturalRestriction())
aLocalError = aVProps.Perform(aPropFace, thePln, aTol, CGFlag, IFlag);
else {
aPropDomain.Init(aFace);
aLocalError = aVProps.Perform(aPropFace, aPropDomain, thePln, aTol, CGFlag, IFlag);
}
if (aLocalError < 0.)
return aLocalError;
anError += aLocalError;
theProps.Add(aVProps);
}
}
return anError;
}
//=======================================================================
//function : VolumeProperties
//purpose :
//=======================================================================
Standard_Real BRepGProp::VolumePropertiesGK(const TopoDS_Shape &S,
GProp_GProps &Props,
const gp_Pln &thePln,
const Standard_Real Eps,
const Standard_Boolean OnlyClosed,
const Standard_Boolean IsUseSpan,
const Standard_Boolean CGFlag,
const Standard_Boolean IFlag)
{
gp_Pnt P(0,0,0);
Standard_Real anError = 0.;
P.Transform(S.Location());
Props = GProp_GProps(P);
if(OnlyClosed) {
// To select closed shells.
TopExp_Explorer anExp;
TopTools_ListOfShape aClosedShells;
anExp.Init(S, TopAbs_SHELL);
for (; anExp.More(); anExp.Next()) {
const TopoDS_Shape &aShell = anExp.Current();
BRepCheck_Shell aChecker(TopoDS::Shell(aShell));
BRepCheck_Status aStatus = aChecker.Closed(Standard_False);
if(aStatus == BRepCheck_NoError)
aClosedShells.Append(aShell);
}
if (aClosedShells.IsEmpty())
return -1.;
// Compute the properties for each closed shell.
Standard_Real aTol = Eps;
Standard_Real aLocalError;
TopTools_ListIteratorOfListOfShape anIter(aClosedShells);
for (; anIter.More(); anIter.Next()) {
const TopoDS_Shape &aShell = anIter.Value();
aLocalError = volumePropertiesGK(aShell, Props, thePln, aTol, IsUseSpan, CGFlag, IFlag);
if (aLocalError < 0)
return aLocalError;
anError += aLocalError;
}
} else
anError = volumePropertiesGK(S, Props, thePln, Eps, IsUseSpan, CGFlag, IFlag);
Standard_Real vol = Props.Mass();
if(vol > Epsilon(1.)) anError /= vol;
return anError;
}

View File

@@ -0,0 +1,61 @@
-- File: BRepGProp_Domain.cdl
-- Created: Fri Nov 27 16:44:12 1992
-- Author: Isabelle GRIGNON
-- <isg@sdsun2>
---Copyright: Matra Datavision 1992
class Domain from BRepGProp
---Purpose: Arc iterator. Returns only Forward and Reversed edges from
-- the face in an undigested order.
uses Face from TopoDS,
Edge from TopoDS,
Explorer from TopExp
is
Create returns Domain;
--- Purpose : Empty constructor.
---C++: inline
Create (F : Face from TopoDS) returns Domain;
--- Purpose : Constructor. Initializes the domain with the face.
---C++: inline
Init(me : in out;F : Face from TopoDS);
--- Purpose : Initializes the domain with the face.
---C++: inline
More(me : in out) returns Boolean from Standard
--- Purpose :
-- Returns True if there is another arc of curve in the list.
---C++: inline
is static;
Init(me : in out)
--- Purpose : Initializes the exploration with the face already set.
---C++: inline
is static;
Value(me : in out) returns Edge from TopoDS
---Purpose: Returns the current edge.
---C++: return const &
---C++: inline
is static;
Next(me : in out)
--- Purpose :
-- Sets the index of the arc iterator to the next arc of
-- curve.
is static;
fields
myExplorer : Explorer from TopExp;
end Domain;

View File

@@ -0,0 +1,24 @@
// File: BRepGProp_Domain.cxx
// Created: Tue Dec 13 08:58:57 2005
// Author: Sergey KHROMOV
// <skv@dimox>
#include <BRepGProp_Domain.ixx>
//=======================================================================
//function : Next
//purpose : Sets the index of the arc iterator to the next arc of curve.
//=======================================================================
void BRepGProp_Domain::Next () {
// skip INTERNAL and EXTERNAL edges
myExplorer.Next();
while (myExplorer.More()) {
TopAbs_Orientation Or = myExplorer.Current().Orientation();
if ((Or == TopAbs_FORWARD) || (Or == TopAbs_REVERSED)) return;
myExplorer.Next();
}
}

View File

@@ -0,0 +1,67 @@
// File: BRepGProp_Domain.lxx
// Created: Tue Dec 13 08:57:55 2005
// Author: Sergey KHROMOV
// <skv@dimox>
#include <TopoDS.hxx>
#include <TopoDS_Face.hxx>
//=======================================================================
//function : BRepGProp_Domain
//purpose : Empty constructor.
//=======================================================================
inline BRepGProp_Domain::BRepGProp_Domain ()
{
}
//=======================================================================
//function : BRepGProp_Domain
//purpose : Constructor. Initializes the domain with the face.
//=======================================================================
inline BRepGProp_Domain::BRepGProp_Domain (const TopoDS_Face& F) :
myExplorer(F.Oriented(TopAbs_FORWARD),TopAbs_EDGE)
{
}
//=======================================================================
//function : Init
//purpose : Initializes the domain with the face.
//=======================================================================
inline void BRepGProp_Domain::Init(const TopoDS_Face& F)
{
myExplorer.Init(F.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
}
//=======================================================================
//function : More
//purpose : Returns True if there is another arc of curve in the list.
//=======================================================================
inline Standard_Boolean BRepGProp_Domain::More ()
{
return myExplorer.More();
}
//=======================================================================
//function : Init
//purpose : Initializes the exploration with the face already set.
//=======================================================================
inline void BRepGProp_Domain::Init ()
{
myExplorer.ReInit();
}
//=======================================================================
//function : Value
//purpose : Returns the current edge.
//=======================================================================
inline const TopoDS_Edge& BRepGProp_Domain::Value ()
{
return TopoDS::Edge(myExplorer.Current());
}

View File

@@ -0,0 +1,72 @@
-- File: BRepGProp_EdgeTool.cdl
-- Created: Tue Dec 7 10:39:08 1993
-- Author: Modelistation
-- <model@zerox>
---Copyright: Matra Datavision 1993
class EdgeTool from BRepGProp
--- Purpose : Provides the required methods to instantiate
-- CGProps from GProp with a Curve from BRepAdaptor.
uses Pnt from gp,
Vec from gp,
Curve from BRepAdaptor,
Shape from GeomAbs,
Array1OfReal from TColStd
raises
OutOfRange from Standard
is
FirstParameter (myclass; C : Curve from BRepAdaptor) returns Real;
--- Purpose :
-- Returns the parametric value of the start point of
-- the curve. The curve is oriented from the start point
-- to the end point.
LastParameter (myclass; C : Curve from BRepAdaptor) returns Real;
--- Purpose :
-- Returns the parametric value of the end point of
-- the curve. The curve is oriented from the start point
-- to the end point.
IntegrationOrder (myclass; C : Curve from BRepAdaptor) returns Integer;
--- Purpose :
-- Returns the number of Gauss points required to do
-- the integration with a good accuracy using the
-- Gauss method. For a polynomial curve of degree n
-- the maxima of accuracy is obtained with an order
-- of integration equal to 2*n-1.
Value (myclass; C : Curve from BRepAdaptor; U : Real) returns Pnt;
--- Purpose : Returns the point of parameter U on the loaded curve.
D1 (myclass; C : Curve from BRepAdaptor; U: Real; P: out Pnt; V1: out Vec);
--- Purpose :
-- Returns the point of parameter U and the first derivative
-- at this point.
NbIntervals(myclass; C : Curve from BRepAdaptor; S : Shape from GeomAbs)
---Purpose: Returns the number of intervals for continuity
-- <S>. May be one if Continuity(me) >= <S>
returns Integer;
Intervals(myclass; C : Curve from BRepAdaptor;
T : in out Array1OfReal from TColStd;
S : Shape from GeomAbs)
---Purpose: Stores in <T> the parameters bounding the intervals
-- of continuity <S>.
--
-- The array must provide enough room to accomodate
-- for the parameters. i.e. T.Length() > NbIntervals()
raises
OutOfRange from Standard;
end EdgeTool;

View File

@@ -0,0 +1,79 @@
#include <BRepGProp_EdgeTool.ixx>
#include <GeomAdaptor_Curve.hxx>
#include <Geom_Curve.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BSplineCurve.hxx>
Standard_Real BRepGProp_EdgeTool::FirstParameter(const BRepAdaptor_Curve& C)
{
return C.FirstParameter();
}
Standard_Real BRepGProp_EdgeTool::LastParameter(const BRepAdaptor_Curve& C)
{
return C.LastParameter();
}
Standard_Integer BRepGProp_EdgeTool::IntegrationOrder(const BRepAdaptor_Curve& BAC)
{
switch (BAC.GetType()) {
case GeomAbs_Line :
return 2;
case GeomAbs_Parabola :
return 5;
case GeomAbs_BezierCurve :
{
const GeomAdaptor_Curve& GAC = BAC.Curve();
const Handle(Geom_Curve)& GC = GAC.Curve();
const Handle(Geom_BezierCurve)& GBZC = (*((Handle(Geom_BezierCurve)*)&GC));
Standard_Integer n = 2*(GBZC->NbPoles()) - 1;
return n;
}
break;
case GeomAbs_BSplineCurve :
{
const GeomAdaptor_Curve& GAC = BAC.Curve();
const Handle(Geom_Curve)& GC = GAC.Curve();
const Handle(Geom_BSplineCurve)& GBSC = (*((Handle(Geom_BSplineCurve)*)&GC));
Standard_Integer n = 2*(GBSC->NbPoles()) - 1;
return n;
}
break;
default :
return 10;
}
//POP WE should return something : -> Default
return 10;
}
gp_Pnt BRepGProp_EdgeTool::Value(const BRepAdaptor_Curve& C, const Standard_Real U)
{
return C.Value(U);
}
void BRepGProp_EdgeTool::D1(const BRepAdaptor_Curve& C,
const Standard_Real U, gp_Pnt& P, gp_Vec& V1)
{
C.D1(U,P,V1);
}
// modified by NIZHNY-MKK Thu Jun 9 12:15:15 2005.BEGIN
Standard_Integer BRepGProp_EdgeTool::NbIntervals(const BRepAdaptor_Curve& C,const GeomAbs_Shape S)
{
BRepAdaptor_Curve* pC = (BRepAdaptor_Curve*) &C; // at the moment actually NbIntervals() does not modify the
// object "C". So it is safe to do such a cast.
return pC->NbIntervals(S);
}
void BRepGProp_EdgeTool::Intervals(const BRepAdaptor_Curve& C,TColStd_Array1OfReal& T,const GeomAbs_Shape S)
{
BRepAdaptor_Curve* pC = (BRepAdaptor_Curve*) &C; // at the moment actually Intervals() does not modify the
// object "C". So it is safe to do such a cast.
pC->Intervals(T, S);
}
// modified by NIZHNY-MKK Thu Jun 9 12:15:18 2005.END

166
src/BRepGProp/BRepGProp_Face.cdl Executable file
View File

@@ -0,0 +1,166 @@
-- File: BRepGProp_Face.cdl
-- Created: Wed Apr 14 18:04:46 1993
-- Author: Isabelle GRIGNON
-- <isg@sdsun2>
---Copyright: Matra Datavision 1993
class Face from BRepGProp
uses Pnt2d from gp,
Vec2d from gp,
Pnt from gp,
Vec from gp,
Edge from TopoDS,
Face from TopoDS,
Surface from BRepAdaptor,
Curve from Geom2dAdaptor,
Array1OfReal from TColStd,
HArray1OfReal from TColStd,
IsoType from GeomAbs
is
Create (IsUseSpan: Boolean from Standard = Standard_False)
---Purpose: Constructor. Initializes the object with a flag IsUseSpan
-- that says if it is necessary to define spans on a face.
-- This option has an effect only for BSpline faces. Spans
-- are returned by the methods GetUKnots and GetTKnots.
---C++: inline
returns Face from BRepGProp;
Create(F : Face from TopoDS;
IsUseSpan: Boolean from Standard = Standard_False)
---Purpose: Constructor. Initializes the object with the face and the
-- flag IsUseSpan that says if it is necessary to define
-- spans on a face. This option has an effect only for
-- BSpline faces. Spans are returned by the methods GetUKnots
-- and GetTKnots.
---C++: inline
returns Face from BRepGProp;
Load(me : in out; F : Face from TopoDS)
is static;
VIntegrationOrder (me) returns Integer
is static;
NaturalRestriction(me) returns Boolean
---Purpose: Returns Standard_True if the face is not trimmed.
---C++: inline
is static;
Value2d (me; U :Real) returns Pnt2d from gp
---Purpose: Returns the value of the boundary curve of the face.
---C++: inline
is static;
SIntOrder (me; Eps :Real) returns Integer
is static;
SVIntSubs (me) returns Integer
is static;
SUIntSubs (me) returns Integer
is static;
UKnots(me; Knots : out Array1OfReal from TColStd)
is static;
VKnots(me; Knots : out Array1OfReal from TColStd)
is static;
LIntOrder (me; Eps :Real) returns Integer
is static;
LIntSubs (me) returns Integer
is static;
LKnots(me; Knots : out Array1OfReal from TColStd)
is static;
--
-- Methods required by GProp
--
UIntegrationOrder (me) returns Integer
---Purpose: Returns the number of points required to do the
-- integration in the U parametric direction with
-- a good accuracy.
is static;
Bounds(me; U1,U2,V1,V2 : out Real)
---Purpose: Returns the parametric bounds of the Face.
is static;
Normal (me; U, V : Real; P : out Pnt; VNor: out Vec)
---Purpose: Computes the point of parameter U, V on the Face <S> and
-- the normal to the face at this point.
is static;
Load(me : in out; E : Edge from TopoDS)
---Purpose: Loading the boundary arc.
is static;
FirstParameter (me) returns Real
---Purpose: Returns the parametric value of the start point of
-- the current arc of curve.
---C++: inline
is static;
LastParameter (me) returns Real
---Purpose: Returns the parametric value of the end point of
-- the current arc of curve.
---C++: inline
is static;
IntegrationOrder (me) returns Integer
---Purpose: Returns the number of points required to do the
-- integration along the parameter of curve.
is static;
D12d (me; U : Real ;P : out Pnt2d from gp ;
V1 : out Vec2d from gp)
---Purpose: Returns the point of parameter U and the first derivative
-- at this point of a boundary curve.
---C++: inline
is static;
-- Modified by skv - Fri Dec 9 16:44:00 2005 Begin
Load(me : in out; IsFirstParam: Boolean from Standard;
theIsoType : IsoType from GeomAbs);
---Purpose: Loading the boundary arc. This arc is either a top, bottom,
-- left or right bound of a UV rectangle in which the
-- parameters of surface are defined.
-- If IsFirstParam is equal to Standard_True, the face is
-- initialized by either left of bottom bound. Otherwise it is
-- initialized by the top or right one.
-- If theIsoType is equal to GeomAbs_IsoU, the face is
-- initialized with either left or right bound. Otherwise -
-- with either top or bottom one.
GetUKnots(me; theUMin : Real from Standard;
theUMax : Real from Standard;
theUKnots: in out HArray1OfReal from TColStd);
---Purpose: Returns an array of U knots of the face. The first and last
-- elements of the array will be theUMin and theUMax. The
-- middle elements will be the U Knots of the face greater
-- then theUMin and lower then theUMax in increasing order.
-- If the face is not a BSpline, the array initialized with
-- theUMin and theUMax only.
GetTKnots(me; theTMin : Real from Standard;
theTMax : Real from Standard;
theTKnots: in out HArray1OfReal from TColStd);
---Purpose: Returns an array of combination of T knots of the arc and
-- V knots of the face. The first and last elements of the
-- array will be theTMin and theTMax. The middle elements will
-- be the Knots of the arc and the values of parameters of
-- arc on which the value points have V coordinates close to V
-- knots of face. All the parameter will be greater then
-- theTMin and lower then theTMax in increasing order.
-- If the face is not a BSpline, the array initialized with
-- theTMin and theTMax only.
-- Modified by skv - Fri Dec 9 16:44:00 2005 End
fields
mySurface : Surface from BRepAdaptor;
myCurve : Curve from Geom2dAdaptor;
mySReverse : Boolean from Standard;
myIsUseSpan: Boolean from Standard;
end Face;

808
src/BRepGProp/BRepGProp_Face.cxx Executable file
View File

@@ -0,0 +1,808 @@
#include <BRepGProp_Face.ixx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>
#include <GeomAdaptor_Surface.hxx>
#include <Geom_Surface.hxx>
#include <Geom_BezierSurface.hxx>
#include <Geom_BSplineSurface.hxx>
#include <Geom2d_BezierCurve.hxx>
#include <Geom2d_BSplineCurve.hxx>
#include <math.hxx>
#include <Bnd_Box2d.hxx>
#include <BndLib_Add2dCurve.hxx>
#include <GeomAdaptor_Curve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Precision.hxx>
#include <TColStd_SequenceOfReal.hxx>
#include <Geom_SurfaceOfLinearExtrusion.hxx>
#include <Geom2d_Line.hxx>
//=======================================================================
//function : UIntegrationOrder
//purpose :
//=======================================================================
Standard_Integer BRepGProp_Face::UIntegrationOrder() const {
Standard_Integer Nu;
switch (mySurface.GetType()) {
case GeomAbs_Plane :
Nu =4;
break;
case GeomAbs_BezierSurface :
{
Nu = (*((Handle(Geom_BezierSurface)*)&((mySurface.Surface()).Surface())))->UDegree()+1;
Nu = Max(4,Nu);
}
break;
case GeomAbs_BSplineSurface :
{
Standard_Integer a = (*((Handle(Geom_BSplineSurface)*)&((mySurface.Surface()).Surface())))->UDegree()+1;
Standard_Integer b = (*((Handle(Geom_BSplineSurface)*)&((mySurface.Surface()).Surface())))->NbUKnots()-1;
Nu = Max(4,a*b);
}
break;
default :
Nu = 9;
break;
}
return Max(8,2*Nu);
}
//=======================================================================
//function : VIntegrationOrder
//purpose :
//=======================================================================
Standard_Integer BRepGProp_Face::VIntegrationOrder() const
{
Standard_Integer Nv;
switch (mySurface.GetType()) {
case GeomAbs_Plane :
Nv = 4;
break;
case GeomAbs_BezierSurface :
{
Nv = (*((Handle(Geom_BezierSurface)*)&((mySurface.Surface()).Surface())))->VDegree()+1;
Nv = Max(4,Nv);
}
break;
case GeomAbs_BSplineSurface :
{
Standard_Integer a = (*((Handle(Geom_BSplineSurface)*)&((mySurface.Surface()).Surface())))->VDegree()+1;
Standard_Integer b = (*((Handle(Geom_BSplineSurface)*)&((mySurface.Surface()).Surface())))->NbVKnots()-1;
Nv = Max(4,a*b);
}
break;
default :
Nv = 9;
break;
}
return Max(8,2*Nv);
}
//=======================================================================
//function : IntegrationOrder
//purpose :
//=======================================================================
Standard_Integer BRepGProp_Face::IntegrationOrder() const
{
Standard_Integer N;
switch (myCurve.GetType()) {
case GeomAbs_Line :
N = 2;
break;
case GeomAbs_Circle :
case GeomAbs_Ellipse :
case GeomAbs_Hyperbola :
N = 9;
break;
case GeomAbs_Parabola :
N = 9;
break;
case GeomAbs_BezierCurve :
{
N = (*((Handle(Geom2d_BezierCurve)*)&(myCurve.Curve())))->Degree() + 1;
}
break;
case GeomAbs_BSplineCurve :
{
Standard_Integer a = (*((Handle(Geom2d_BSplineCurve)*)&(myCurve.Curve())))->Degree() + 1;
Standard_Integer b = (*((Handle(Geom2d_BSplineCurve)*)&(myCurve.Curve())))->NbKnots() - 1;
N = a * b;
}
break;
default :
N = 9;
break;
}
return Max(4,2*N);
}
//=======================================================================
//function : Bounds
//purpose :
//=======================================================================
void BRepGProp_Face::Bounds(Standard_Real& U1,
Standard_Real& U2,
Standard_Real& V1,
Standard_Real& V2)const
{
U1 = mySurface.FirstUParameter();
U2 = mySurface.LastUParameter();
V1 = mySurface.FirstVParameter();
V2 = mySurface.LastVParameter();
}
//=======================================================================
//function : Load
//purpose :
//=======================================================================
void BRepGProp_Face::Load(const TopoDS_Edge& E)
{
Standard_Real a,b;
Handle(Geom2d_Curve) C =
BRep_Tool::CurveOnSurface(E, mySurface.Face(), a,b);
if (E.Orientation() == TopAbs_REVERSED) {
Standard_Real x = a;
a = C->ReversedParameter(b);
b = C->ReversedParameter(x);
C = C->Reversed();
}
myCurve.Load(C,a,b);
}
//=======================================================================
//function : Load
//purpose :
//=======================================================================
void BRepGProp_Face::Load(const TopoDS_Face& F)
{
TopoDS_Shape aLocalShape = F.Oriented(TopAbs_FORWARD);
mySurface.Initialize(TopoDS::Face(aLocalShape));
// mySurface.Initialize(TopoDS::Face(F.Oriented(TopAbs_FORWARD)));
mySReverse = (F.Orientation() == TopAbs_REVERSED);
}
//=======================================================================
//function : Normal
//purpose :
//=======================================================================
void BRepGProp_Face::Normal (const Standard_Real U,
const Standard_Real V,
gp_Pnt &P,
gp_Vec &VNor) const
{
gp_Vec D1U,D1V;
mySurface.D1(U,V,P,D1U,D1V);
VNor = D1U.Crossed(D1V);
if (mySReverse) VNor.Reverse();
}
// APO 17.04.2002 (OCC104)
// This is functions that calculate coeff. to optimize "integration order".
//They had been produced experementally for some hard example.
static Standard_Real AS = -0.15, AL = -0.50, B = 1.0, C = 0.75, D = 0.25;
static inline Standard_Real SCoeff(const Standard_Real Eps){
return Eps < 0.1? AS*(B+Log10(Eps)) + C: C;
}
static inline Standard_Real LCoeff(const Standard_Real Eps){
return Eps < 0.1? AL*(B+Log10(Eps)) + D: D;
}
//=======================================================================
//function : SIntOrder
//purpose :
//=======================================================================
Standard_Integer BRepGProp_Face::SIntOrder(const Standard_Real Eps) const
{
Standard_Integer Nv, Nu;
switch (mySurface.GetType()) {
case GeomAbs_Plane:
Nu = 1; Nv = 1; break;
case GeomAbs_Cylinder:
Nu = 2; Nv = 1; break;
case GeomAbs_Cone:
Nu = 2; Nv = 1; break;
case GeomAbs_Sphere:
Nu = 2; Nv = 2; break;
case GeomAbs_Torus:
Nu = 2; Nv = 2; break;
case GeomAbs_BezierSurface:
Nv = (*((Handle(Geom_BezierSurface)*)&((mySurface.Surface()).Surface())))->VDegree();
Nu = (*((Handle(Geom_BezierSurface)*)&((mySurface.Surface()).Surface())))->UDegree();
break;
case GeomAbs_BSplineSurface:
Nv = (*((Handle(Geom_BSplineSurface)*)&((mySurface.Surface()).Surface())))->VDegree();
Nu = (*((Handle(Geom_BSplineSurface)*)&((mySurface.Surface()).Surface())))->UDegree();
break;
default:
Nu = 2; Nv = 2; break;
}
return Min(RealToInt(Ceiling(SCoeff(Eps)*Max((Nu+1),(Nv+1)))), math::GaussPointsMax());
}
//=======================================================================
//function : SUIntSubs
//purpose :
//=======================================================================
Standard_Integer BRepGProp_Face::SUIntSubs() const
{
Standard_Integer N;
switch (mySurface.GetType()) {
case GeomAbs_Plane:
N = 2; break;
case GeomAbs_Cylinder:
N = 4; break;
case GeomAbs_Cone:
N = 4; break;
case GeomAbs_Sphere:
N = 4; break;
case GeomAbs_Torus:
N = 4; break;
case GeomAbs_BezierSurface:
N = 2; break;
case GeomAbs_BSplineSurface:
N = (*((Handle(Geom_BSplineSurface)*)&((mySurface.Surface()).Surface())))->NbUKnots(); break;
default:
N = 2; break;
}
return N - 1;
}
//=======================================================================
//function : SVIntSubs
//purpose :
//=======================================================================
Standard_Integer BRepGProp_Face::SVIntSubs() const
{
Standard_Integer N;
switch (mySurface.GetType()) {
case GeomAbs_Plane:
N = 2; break;
case GeomAbs_Cylinder:
N = 2; break;
case GeomAbs_Cone:
N = 2; break;
case GeomAbs_Sphere:
N = 3; break;
case GeomAbs_Torus:
N = 4; break;
case GeomAbs_BezierSurface:
N = 2; break;
case GeomAbs_BSplineSurface:
N = (*((Handle(Geom_BSplineSurface)*)&((mySurface.Surface()).Surface())))->NbVKnots();
break;
default:
N = 2; break;
}
return N - 1;
}
//=======================================================================
//function : UKnots
//purpose :
//=======================================================================
void BRepGProp_Face::UKnots(TColStd_Array1OfReal& Knots) const
{
switch (mySurface.GetType()) {
case GeomAbs_Plane:
Knots(1) = mySurface.FirstUParameter(); Knots(2) = mySurface.LastUParameter();
break;
case GeomAbs_Cylinder:
case GeomAbs_Cone:
case GeomAbs_Sphere:
case GeomAbs_Torus:
Knots(1) = 0.0; Knots(2) = PI*2.0/3.0; Knots(3) = PI*4.0/3.0; Knots(4) = PI*6.0/3.0;
break;
case GeomAbs_BSplineSurface:
(*((Handle(Geom_BSplineSurface)*)&((mySurface.Surface()).Surface())))->UKnots(Knots);
break;
default:
Knots(1) = mySurface.FirstUParameter(); Knots(2) = mySurface.LastUParameter();
break;
}
}
//=======================================================================
//function : VKnots
//purpose :
//=======================================================================
void BRepGProp_Face::VKnots(TColStd_Array1OfReal& Knots) const
{
switch (mySurface.GetType()) {
case GeomAbs_Plane:
case GeomAbs_Cylinder:
case GeomAbs_Cone:
Knots(1) = mySurface.FirstUParameter(); Knots(2) = mySurface.LastUParameter();
break;
case GeomAbs_Sphere:
Knots(1) = -PI/2.0; Knots(2) = 0.0; Knots(3) = +PI/2.0;
break;
case GeomAbs_Torus:
Knots(1) = 0.0; Knots(2) = PI*2.0/3.0; Knots(3) = PI*4.0/3.0; Knots(4) = PI*6.0/3.0;
break;
case GeomAbs_BSplineSurface:
(*((Handle(Geom_BSplineSurface)*)&((mySurface.Surface()).Surface())))->VKnots(Knots);
break;
default:
Knots(1) = mySurface.FirstUParameter(); Knots(2) = mySurface.LastUParameter();
break;
}
}
//=======================================================================
//function : LIntOrder
//purpose :
//=======================================================================
Standard_Integer BRepGProp_Face::LIntOrder(const Standard_Real Eps) const
{
Bnd_Box2d aBox;
BndLib_Add2dCurve aB;
aB.Add(myCurve, 1.e-7, aBox);
Standard_Real aXmin, aXmax, aYmin, aYmax;
aBox.Get(aXmin, aYmin, aXmax, aYmax);
Standard_Real aVmin = mySurface.FirstVParameter();
Standard_Real aVmax = mySurface.LastVParameter();
Standard_Real anR = Min((aYmax-aYmin)/(aVmax-aVmin), 1.);
// Standard_Integer anRInt = Max(RealToInt(Ceiling(SVIntSubs()*anR)), 2);
Standard_Integer anRInt = RealToInt(Ceiling(SVIntSubs()*anR));
Standard_Integer aLSubs = LIntSubs();
// Standard_Real NL, NS = Max(SIntOrder(1.0)*anRInt/LIntSubs(), 1);
Standard_Real NL, NS = Max(SIntOrder(1.)*anRInt/aLSubs, 1);
switch (myCurve.GetType()) {
case GeomAbs_Line:
NL = 1; break;
case GeomAbs_Circle:
NL = 2 * 3; break; //correction for the spans of converted curve
case GeomAbs_Ellipse:
NL = 2 * 3; break; //
case GeomAbs_Parabola:
NL = 2 * 3; break;
case GeomAbs_Hyperbola:
NL = 3 * 3; break;
case GeomAbs_BezierCurve:
NL = (*((Handle(Geom2d_BezierCurve)*)&(myCurve.Curve())))->Degree();
break;
case GeomAbs_BSplineCurve:
NL = (*((Handle(Geom2d_BSplineCurve)*)&(myCurve.Curve())))->Degree();
break;
default:
NL = 3 * 3; break;
}
NL = Max(NL, NS);
Standard_Integer nn =
RealToInt (aLSubs <= 4 ? Ceiling(LCoeff(Eps)*(NL+1)) : NL+1);
//return Min(RealToInt(Ceiling(LCoeff(Eps)*(NL+1)*NS)), math::GaussPointsMax());
return Min(nn, math::GaussPointsMax());
}
//=======================================================================
//function : LIntSubs
//purpose :
//=======================================================================
Standard_Integer BRepGProp_Face::LIntSubs() const
{
Standard_Integer N;
switch (myCurve.GetType()) {
case GeomAbs_Line:
N = 2; break;
case GeomAbs_Circle:
case GeomAbs_Ellipse:
N = 4; break;
case GeomAbs_Parabola:
case GeomAbs_Hyperbola:
N = 2; break;
case GeomAbs_BSplineCurve:
N = (*((Handle(Geom2d_BSplineCurve)*)&(myCurve.Curve())))->NbKnots();
break;
default:
N = 2; break;
}
return N - 1;
}
//=======================================================================
//function : LKnots
//purpose :
//=======================================================================
void BRepGProp_Face::LKnots(TColStd_Array1OfReal& Knots) const
{
switch (myCurve.GetType()) {
case GeomAbs_Line:
Knots(1) = myCurve.FirstParameter(); Knots(2) = myCurve.LastParameter();
break;
case GeomAbs_Circle:
case GeomAbs_Ellipse:
Knots(1) = 0.0; Knots(2) = PI*2.0/3.0; Knots(3) = PI*4.0/3.0; Knots(2) = PI*6.0/3.0;
break;
case GeomAbs_Parabola:
case GeomAbs_Hyperbola:
Knots(1) = myCurve.FirstParameter(); Knots(2) = myCurve.LastParameter();
break;
case GeomAbs_BSplineCurve:
(*((Handle(Geom2d_BSplineCurve)*)&(myCurve.Curve())))->Knots(Knots);
break;
default:
Knots(1) = myCurve.FirstParameter(); Knots(2) = myCurve.LastParameter();
break;
}
}
//=======================================================================
//function : Load
//purpose :
//=======================================================================
void BRepGProp_Face::Load(const Standard_Boolean IsFirstParam,
const GeomAbs_IsoType theIsoType)
{
Standard_Real aLen;
Standard_Real aU1;
Standard_Real aU2;
Standard_Real aV1;
Standard_Real aV2;
gp_Pnt2d aLoc;
gp_Dir2d aDir;
Bounds(aU1, aU2, aV1, aV2);
if (theIsoType == GeomAbs_IsoU) {
aLen = aV2 - aV1;
if (IsFirstParam) {
aLoc.SetCoord(aU1, aV2);
aDir.SetCoord(0., -1.);
} else {
aLoc.SetCoord(aU2, aV1);
aDir.SetCoord(0., 1.);
}
} else if (theIsoType == GeomAbs_IsoV) {
aLen = aU2 - aU1;
if (IsFirstParam) {
aLoc.SetCoord(aU1, aV1);
aDir.SetCoord(1., 0.);
} else {
aLoc.SetCoord(aU2, aV2);
aDir.SetCoord(-1., 0.);
}
} else
return;
Handle(Geom2d_Curve) aLin = new Geom2d_Line(aLoc, aDir);
myCurve.Load(aLin, 0., aLen);
}
//=======================================================================
//function : GetRealKnots
//purpose :
//=======================================================================
static void GetRealKnots(const Standard_Real theMin,
const Standard_Real theMax,
const Handle(TColStd_HArray1OfReal) &theKnots,
Handle(TColStd_HArray1OfReal) &theRealKnots)
{
Standard_Integer i = theKnots->Lower() - 1;
Standard_Integer iU = theKnots->Upper();
Standard_Integer aStartI = 0;
Standard_Integer aEndI = 0;
Standard_Real aTol = Precision::Confusion();
while (++i < iU) {
if (aStartI == 0 && theKnots->Value(i) > theMin + aTol)
aStartI = i;
if (aEndI == 0 && theKnots->Value(i + 1) > theMax - aTol)
aEndI = i;
if (aStartI != 0 && aEndI != 0)
break;
}
if (aStartI == 0)
aStartI = iU;
Standard_Integer aNbNode = Max(0, aEndI - aStartI + 1) + 2;
Standard_Integer j;
theRealKnots = new TColStd_HArray1OfReal(1, aNbNode);
theRealKnots->SetValue(1, theMin);
theRealKnots->SetValue(aNbNode, theMax);
for (i = 2, j = aStartI; j <= aEndI; i++, j++)
theRealKnots->SetValue(i, theKnots->Value(j));
}
//=======================================================================
//function : GetCurveKnots
//purpose :
//=======================================================================
static void GetCurveKnots(const Standard_Real theMin,
const Standard_Real theMax,
const Geom2dAdaptor_Curve &theCurve,
Handle(TColStd_HArray1OfReal) &theKnots)
{
Standard_Boolean isSBSpline = theCurve.GetType() == GeomAbs_BSplineCurve;
if (isSBSpline) {
Handle(Geom2d_BSplineCurve) aCrv;
Standard_Integer aNbKnots;
Handle(TColStd_HArray1OfReal) aCrvKnots;
aCrv = Handle(Geom2d_BSplineCurve)::DownCast(theCurve.Curve());
aNbKnots = aCrv->NbKnots();
aCrvKnots = new TColStd_HArray1OfReal(1, aNbKnots);
aCrv->Knots(aCrvKnots->ChangeArray1());
GetRealKnots(theMin, theMax, aCrvKnots, theKnots);
} else {
theKnots = new TColStd_HArray1OfReal(1, 2);
theKnots->SetValue(1, theMin);
theKnots->SetValue(2, theMax);
}
}
//=======================================================================
//function : GetIntervalNbr
//purpose :
//=======================================================================
static Standard_Integer GetIntervalNbr
(const Standard_Real theParam,
const Handle(TColStd_HArray1OfReal) &theSurfKnots,
const Standard_Integer theIndStart,
const Standard_Integer theIndEnd)
{
Standard_Integer i;
Standard_Real aTol = Precision::Confusion();
for (i = theIndStart + 1; i < theIndEnd; i++) {
if (theSurfKnots->Value(i) > theParam + aTol)
return i - 1;
}
return Min(theIndStart, theIndEnd - 1);
}
//=======================================================================
//function : GetRealCurveKnots
//purpose :
//=======================================================================
static void GetRealCurveKnots
(const Handle(TColStd_HArray1OfReal) &theCurveKnots,
const Handle(TColStd_HArray1OfReal) &theSurfKnots,
const Geom2dAdaptor_Curve &theCurve,
Handle(TColStd_HArray1OfReal) &theTKnots)
{
Standard_Integer i = theCurveKnots->Lower();
Standard_Integer iU = theCurveKnots->Upper();
Standard_Integer aNbIntPnt = 23;
TColStd_SequenceOfReal aSeqKnot;
Standard_Real aTol = Precision::Confusion();
Standard_Real aTParam;
while (i < iU) {
Standard_Real aT1 = theCurveKnots->Value(i++);
Standard_Real aT2 = theCurveKnots->Value(i);
Standard_Real aStep = (aT2 - aT1)/(aNbIntPnt + 1.);
Standard_Integer j;
gp_Pnt2d aValue;
gp_Vec2d aDir;
Standard_Integer aSurfLInd = theSurfKnots->Lower();
Standard_Integer aSurfUInd = theSurfKnots->Upper();
Standard_Integer anIntrvlInd;
Standard_Real aTParamOld;
Standard_Real aVParam;
Standard_Real aVParamOld;
Standard_Real aDiffOld;
Standard_Real aDiff;
// Append the first curve knot of each interval in the sequence of knots.
aSeqKnot.Append(aT1);
aTParamOld = aT1;
theCurve.D0(aTParamOld, aValue);
aVParamOld = aValue.Y();
anIntrvlInd = GetIntervalNbr(aVParamOld, theSurfKnots,
aSurfLInd, aSurfUInd);
aDiffOld = Min(Abs(aVParamOld - theSurfKnots->Value(anIntrvlInd)),
Abs(aVParamOld - theSurfKnots->Value(anIntrvlInd + 1)));
for (j = 1; j <= aNbIntPnt; j++) {
aTParam = aT1 + j*aStep;
theCurve.D1(aTParam, aValue, aDir);
aVParam = aValue.Y();
aDiff = Min(Abs(aVParam - theSurfKnots->Value(anIntrvlInd)),
Abs(aVParam - theSurfKnots->Value(anIntrvlInd + 1)));
// Skip points if the curve goes along V isoline.
if (Abs(aDir.Y()) > aTol) {
Standard_Boolean isLower =
(aVParam - aTol < theSurfKnots->Value(anIntrvlInd));
Standard_Boolean isUpper =
(aVParam + aTol > theSurfKnots->Value(anIntrvlInd + 1));
if (isLower || isUpper) {
if (isLower) {
aSurfLInd = theSurfKnots->Lower();
aSurfUInd = anIntrvlInd - 1;
} else if (isUpper) {
aSurfLInd = anIntrvlInd + 1;
aSurfUInd = theSurfKnots->Upper();
}
// The V interval is changed. Find new interval.
anIntrvlInd = GetIntervalNbr(aVParam, theSurfKnots,
aSurfLInd, aSurfUInd);
// Add the value that is closer to surface knots.
// Check if the previous value is already added.
if (aDiff < aDiffOld)
aSeqKnot.Append(aTParam);
else if (Abs(aSeqKnot.Last() - aTParamOld) > aTol)
aSeqKnot.Append(aTParamOld);
}
}
// Prepare data for the next iteration.
aTParamOld = aTParam;
aVParamOld = aVParam;
aDiffOld = aDiff;
}
}
// Add the last curve knot to the sequence.
aSeqKnot.Append(theCurveKnots->Value(iU));
// Fill the array of knots.
Standard_Integer aKnotsLen = aSeqKnot.Length();
theTKnots = new TColStd_HArray1OfReal(1, aKnotsLen);
for (i = 1; i <= aKnotsLen; i++) {
aTParam = aSeqKnot.Value(i);
theTKnots->SetValue(i, aTParam);
}
}
//=======================================================================
//function : GetUKnots
//purpose :
//=======================================================================
void BRepGProp_Face::GetUKnots
(const Standard_Real theUMin,
const Standard_Real theUMax,
Handle(TColStd_HArray1OfReal) &theUKnots) const
{
Standard_Boolean isSBSpline = mySurface.GetType() == GeomAbs_BSplineSurface;
Standard_Boolean isCBSpline = Standard_False;
if (!isSBSpline) {
// Check the basis curve of the surface of linear extrusion.
if (mySurface.GetType() == GeomAbs_SurfaceOfExtrusion) {
GeomAdaptor_Curve aCurve;
Handle(Geom_Surface) aSurf = mySurface.Surface().Surface();
aCurve.Load((*((Handle(Geom_SurfaceOfLinearExtrusion)*)&aSurf))->BasisCurve());
isCBSpline = aCurve.GetType() == GeomAbs_BSplineCurve;
}
}
if (myIsUseSpan && (isSBSpline || isCBSpline)) {
// Using span decomposition for BSpline.
Handle(TColStd_HArray1OfReal) aKnots;
Standard_Integer aNbKnots;
if (isSBSpline) {
// Get U knots of BSpline surface.
Handle(Geom_Surface) aSurf = mySurface.Surface().Surface();
Handle(Geom_BSplineSurface) aBSplSurf;
aBSplSurf = Handle(Geom_BSplineSurface)::DownCast(aSurf);
aNbKnots = aBSplSurf->NbUKnots();
aKnots = new TColStd_HArray1OfReal(1, aNbKnots);
aBSplSurf->UKnots(aKnots->ChangeArray1());
} else {
// Get U knots of BSpline curve - basis curve of
// the surface of linear extrusion.
GeomAdaptor_Curve aCurve;
Handle(Geom_Surface) aSurf = mySurface.Surface().Surface();
Handle(Geom_BSplineCurve) aBSplCurve;
aCurve.Load((*((Handle(Geom_SurfaceOfLinearExtrusion)*)&aSurf))->BasisCurve());
aBSplCurve = aCurve.BSpline();
aNbKnots = aBSplCurve->NbKnots();
aKnots = new TColStd_HArray1OfReal(1, aNbKnots);
aBSplCurve->Knots(aKnots->ChangeArray1());
}
// Compute number of knots inside theUMin and theUMax.
GetRealKnots(theUMin, theUMax, aKnots, theUKnots);
} else {
// No span decomposition.
theUKnots = new TColStd_HArray1OfReal(1, 2);
theUKnots->SetValue(1, theUMin);
theUKnots->SetValue(2, theUMax);
}
}
//=======================================================================
//function : GetTKnots
//purpose :
//=======================================================================
void BRepGProp_Face::GetTKnots
(const Standard_Real theTMin,
const Standard_Real theTMax,
Handle(TColStd_HArray1OfReal) &theTKnots) const
{
Standard_Boolean isBSpline = mySurface.GetType() == GeomAbs_BSplineSurface;
if (myIsUseSpan && isBSpline) {
// Using span decomposition for BSpline.
Handle(TColStd_HArray1OfReal) aSurfKnots;
Standard_Integer aNbKnots;
// Get V knots of BSpline surface.
Handle(Geom_Surface) aSurf = mySurface.Surface().Surface();
Handle(Geom_BSplineSurface) aBSplSurf;
aBSplSurf = Handle(Geom_BSplineSurface)::DownCast(aSurf);
aNbKnots = aBSplSurf->NbVKnots();
aSurfKnots = new TColStd_HArray1OfReal(1, aNbKnots);
aBSplSurf->VKnots(aSurfKnots->ChangeArray1());
// Handle(TColStd_HArray1OfReal) aCurveKnots;
// GetCurveKnots(theTMin, theTMax, myCurve, aCurveKnots);
// GetRealCurveKnots(aCurveKnots, aSurfKnots, myCurve, theTKnots);
GetCurveKnots(theTMin, theTMax, myCurve, theTKnots);
} else {
theTKnots = new TColStd_HArray1OfReal(1, 2);
theTKnots->SetValue(1, theTMin);
theTKnots->SetValue(2, theTMax);
}
}

View File

@@ -0,0 +1,85 @@
// File: BRepGProp_Face.lxx
// Created: Tue Dec 20 15:30:17 2005
// Author: Sergey KHROMOV
// <skv@dimox>
#include <BRep_Tool.hxx>
//=======================================================================
//function : BRepGProp_Face
//purpose : Constructor. Initializes the object with IsUseSpan.
//=======================================================================
inline BRepGProp_Face::BRepGProp_Face(const Standard_Boolean IsUseSpan)
: myIsUseSpan(IsUseSpan)
{
}
//=======================================================================
//function : BRepGProp_Face
//purpose : Constructor.Initializes the object with the face and
// IsUseSpan flan.
//=======================================================================
inline BRepGProp_Face::BRepGProp_Face(const TopoDS_Face &F,
const Standard_Boolean IsUseSpan)
: myIsUseSpan(IsUseSpan)
{
Load(F);
}
//=======================================================================
//function : NaturalRestriction
//purpose : Returns Standard_True if the face is not trimmed.
//=======================================================================
inline Standard_Boolean BRepGProp_Face::NaturalRestriction() const
{
return BRep_Tool::NaturalRestriction(mySurface.Face());
}
//=======================================================================
//function : Value2d
//purpose : Returns the value of the boundary curve of the face.
//=======================================================================
inline gp_Pnt2d BRepGProp_Face::Value2d(const Standard_Real U) const
{
return myCurve.Value(U);
}
//=======================================================================
//function : D12d
//purpose : Returns the point of parameter U and the first derivative
// at this point of a boundary curve.
//=======================================================================
inline void BRepGProp_Face::D12d(const Standard_Real U,
gp_Pnt2d &P,
gp_Vec2d &V1) const
{
myCurve.D1(U,P,V1);
}
//=======================================================================
//function : FirstParameter
//purpose : Returns the parametric value of the start point of
// the current arc of curve.
//=======================================================================
inline Standard_Real BRepGProp_Face::FirstParameter() const
{
return myCurve.FirstParameter();
}
//=======================================================================
//function : LastParameter
//purpose : Returns the parametric value of the end point of
// the current arc of curve.
//=======================================================================
inline Standard_Real BRepGProp_Face::LastParameter() const
{
return myCurve.LastParameter();
}