mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-14 13:30:48 +03:00
Integration of OCCT 6.5.0 from SVN
This commit is contained in:
180
src/Convert/Convert.cdl
Executable file
180
src/Convert/Convert.cdl
Executable file
@@ -0,0 +1,180 @@
|
||||
-- File: Convert.cdl
|
||||
-- Created: Thu Oct 10 11:23:08 1991
|
||||
-- Author: Jean Claude VAUTHIER
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
|
||||
|
||||
package Convert
|
||||
|
||||
--- Purpose:
|
||||
--The Convert package provides algorithms to convert the following into a BSpline curve or surface:
|
||||
-- - a bounded curve based on an elementary 2D curve (line, circle or conic) from the gp package,
|
||||
-- - a bounded surface based on an elementary surface (cylinder, cone, sphere or torus) from the gp package,
|
||||
-- - a series of adjacent 2D or 3D Bezier curves defined by their poles.
|
||||
-- These algorithms compute the data needed to define the resulting BSpline curve or surface.
|
||||
-- This elementary data (degrees, periodic characteristics, poles and weights, knots and
|
||||
-- multiplicities) may then be used directly in an algorithm, or can be used to construct the curve
|
||||
-- or the surface by calling the appropriate constructor provided by the classes
|
||||
-- Geom2d_BSplineCurve, Geom_BSplineCurve or Geom_BSplineSurface.
|
||||
|
||||
uses TColStd,
|
||||
TColgp,
|
||||
StdFail,
|
||||
gp,
|
||||
GeomAbs,
|
||||
TCollection
|
||||
|
||||
is
|
||||
|
||||
enumeration ParameterisationType is
|
||||
TgtThetaOver2,
|
||||
TgtThetaOver2_1,
|
||||
TgtThetaOver2_2,
|
||||
TgtThetaOver2_3,
|
||||
TgtThetaOver2_4,
|
||||
---Purpose:
|
||||
-- Identifies a type of parameterization of a circle or ellipse represented as a BSpline curve.
|
||||
-- For a circle with a center C and a radius R (for example a Geom2d_Circle or a Geom_Circle),
|
||||
-- the natural parameterization is angular. It uses the angle Theta made by the vector CM with
|
||||
-- the 'X Axis' of the circle's local coordinate system as parameter for the current point M. The
|
||||
-- coordinates of the point M are as follows:
|
||||
-- X = R *cos ( Theta )
|
||||
-- y = R * sin ( Theta )
|
||||
-- Similarly, for an ellipse with a center C, a major radius R and a minor radius r, the circle Circ
|
||||
-- with center C and radius R (and located in the same plane as the ellipse) lends its natural
|
||||
-- angular parameterization to the ellipse. This is achieved by an affine transformation in the plane
|
||||
-- of the ellipse, in the ratio r / R, about the 'X Axis' of its local coordinate system. The
|
||||
-- coordinates of the current point M are as follows:
|
||||
-- X = R * cos ( Theta )
|
||||
-- y = r * sin ( Theta )
|
||||
-- The process of converting a circle or an ellipse into a rational or non-rational BSpline curve
|
||||
-- transforms the Theta angular parameter into a parameter t. This ensures the rational or
|
||||
-- polynomial parameterization of the resulting BSpline curve. Several types of parametric
|
||||
-- transformations are available.
|
||||
-- TgtThetaOver2
|
||||
-- The most usual method is Convert_TgtThetaOver2 where the parameter t on the BSpline
|
||||
-- curve is obtained by means of transformation of the following type:
|
||||
-- t = tan ( Theta / 2 )
|
||||
-- The result of this definition is:
|
||||
-- cos ( Theta ) = ( 1. - t**2 ) / ( 1. + t**2 )
|
||||
-- sin ( Theta ) = 2. * t / ( 1. + t**2 )
|
||||
-- which ensures the rational parameterization of the circle or the ellipse. However, this is not the
|
||||
-- most suitable parameterization method where the arc of the circle or ellipse has a large opening
|
||||
-- angle. In such cases, the curve will be represented by a BSpline with intermediate knots. Each
|
||||
-- span, i.e. each portion of curve between two different knot values, will use parameterization of
|
||||
-- this type.
|
||||
-- The number of spans is calculated using the following rule:
|
||||
-- ( 1.2 * Delta / Pi ) + 1
|
||||
-- where Delta is equal to the opening angle (in radians) of the arc of the circle (Delta is
|
||||
-- equal to 2.* Pi in the case of a complete circle).
|
||||
-- The resulting BSpline curve is "exact", i.e. computing any point of parameter t on the BSpline
|
||||
-- curve gives an exact point on the circle or the ellipse.
|
||||
-- TgtThetaOver2_N
|
||||
-- Where N is equal to 1, 2, 3 or 4, this ensures the same type of parameterization as
|
||||
-- Convert_TgtThetaOver2 but sets the number of spans in the resulting BSpline curve to N
|
||||
-- rather than allowing the algorithm to make this calculation.
|
||||
-- However, the opening angle Delta (parametric angle, given in radians) of the arc of the circle
|
||||
-- (or of the ellipse) must comply with the following:
|
||||
-- - Delta <= 0.9999 * Pi for the Convert_TgtThetaOver2_1 method, or
|
||||
-- - Delta <= 1.9999 * Pi for the Convert_TgtThetaOver2_2 method.
|
||||
-- QuasiAngular
|
||||
-- The Convert_QuasiAngular method of parameterization uses a different type of rational
|
||||
-- parameterization. This method ensures that the parameter t along the resulting BSpline curve is
|
||||
-- very close to the natural parameterization angle Theta of the circle or ellipse (i.e. which uses
|
||||
-- the functions sin ( Theta ) and cos ( Theta ).
|
||||
-- The resulting BSpline curve is "exact", i.e. computing any point of parameter t on the BSpline
|
||||
-- curve gives an exact point on the circle or the ellipse.
|
||||
-- RationalC1
|
||||
-- The Convert_RationalC1 method of parameterization uses a further type of rational
|
||||
-- parameterization. This method ensures that the equation relating to the resulting BSpline curve
|
||||
-- has a "C1" continuous denominator, which is not the case with the above methods. RationalC1
|
||||
-- enhances the degree of continuity at the junction point of the different spans of the curve.
|
||||
-- The resulting BSpline curve is "exact", i.e. computing any point of parameter t on the BSpline
|
||||
-- curve gives an exact point on the circle or the ellipse.
|
||||
-- Polynomial
|
||||
-- The Convert_Polynomial method is used to produce polynomial (i.e. non-rational)
|
||||
-- parameterization of the resulting BSpline curve with 8 poles (i.e. a polynomial degree equal to 7).
|
||||
-- However, the result is an approximation of the circle or ellipse (i.e. computing the point of
|
||||
-- parameter t on the BSpline curve does not give an exact point on the circle or the ellipse).
|
||||
QuasiAngular,
|
||||
RationalC1,
|
||||
Polynomial;
|
||||
|
||||
|
||||
|
||||
imported CosAndSinEvalFunction ;
|
||||
-- typedef void *CosAndSinEvalFunction(Standard_Real,
|
||||
-- const Standard_Integer,
|
||||
-- const TColgp_Array1OfPnt2d&
|
||||
-- const TColStd_Array1OfReal&
|
||||
-- const TColStd_Array1OfInteger&
|
||||
-- Standard_Real Result[2]
|
||||
--
|
||||
|
||||
|
||||
deferred class ConicToBSplineCurve;
|
||||
--- Purpose :
|
||||
-- Super class of the following classes :
|
||||
|
||||
class CircleToBSplineCurve;
|
||||
--- Purpose : Converts a circle into a B-spline curve.
|
||||
|
||||
class EllipseToBSplineCurve;
|
||||
--- Purpose : Converts an ellipse into a B-spline curve.
|
||||
|
||||
class HyperbolaToBSplineCurve;
|
||||
--- Purpose : Converts an hyperbola into a B-spline curve.
|
||||
|
||||
class ParabolaToBSplineCurve;
|
||||
--- Purpose : Converts a parabola into a B-spline curve.
|
||||
|
||||
|
||||
|
||||
|
||||
deferred class ElementarySurfaceToBSplineSurface;
|
||||
-- Super class of the following classes :
|
||||
|
||||
class CylinderToBSplineSurface;
|
||||
--- Purpose : Converts a bounded cylinder into a B-spline surface.
|
||||
|
||||
class ConeToBSplineSurface;
|
||||
--- Purpose : Converts a bounded cone into a B-spline surface.
|
||||
|
||||
class TorusToBSplineSurface;
|
||||
--- Purpose : Converts a torus into a B-spline surface.
|
||||
|
||||
class SphereToBSplineSurface;
|
||||
--- Purpose : Converts a sphere into a B-spline surface.
|
||||
|
||||
|
||||
|
||||
class SequenceOfArray1OfPoles
|
||||
instantiates Sequence from TCollection( HArray1OfPnt from TColgp);
|
||||
|
||||
class CompBezierCurvesToBSplineCurve;
|
||||
---Purpose: Converts a list of connecting BezierCurves
|
||||
-- into a B-spline curve.
|
||||
|
||||
alias SequenceOfArray1OfPoles2d is SequenceOfArray1OfPnt2d from TColgp;
|
||||
|
||||
|
||||
class CompBezierCurves2dToBSplineCurve2d;
|
||||
---Purpose: Converts a list of connecting BezierCurves
|
||||
-- into a B-spline curve.
|
||||
|
||||
class CompPolynomialToPoles;
|
||||
---Purpose: Convert a serie of Polynomial N-Dimensional
|
||||
-- Curves that are have continuity CM to an
|
||||
-- N-Dimensional Bspline Curve that has continuity
|
||||
-- CM
|
||||
|
||||
class GridPolynomialToPoles;
|
||||
---Purpose: Convert a grid of Polynomial Surfaces
|
||||
-- that are have continuity CM to an
|
||||
-- Bspline Surface that has continuity
|
||||
-- CM
|
||||
|
||||
|
||||
end Convert;
|
58
src/Convert/Convert_CircleToBSplineCurve.cdl
Executable file
58
src/Convert/Convert_CircleToBSplineCurve.cdl
Executable file
@@ -0,0 +1,58 @@
|
||||
-- File: CircleToBSplineCurve.cdl
|
||||
-- Created: Thu Oct 10 14:22:44 1991
|
||||
-- Author: Jean Claude VAUTHIER
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class CircleToBSplineCurve from Convert inherits ConicToBSplineCurve
|
||||
|
||||
--- Purpose :
|
||||
-- This algorithm converts a circle into a rational B-spline curve.
|
||||
-- The circle is a Circ2d from package gp and its parametrization is :
|
||||
-- P (U) = Loc + R * (Cos(U) * Xdir + Sin(U) * YDir) where Loc is the
|
||||
-- center of the circle Xdir and Ydir are the normalized directions
|
||||
-- of the local cartesian coordinate system of the circle.
|
||||
-- The parametrization range for the circle is U [0, 2Pi].
|
||||
--
|
||||
--- Warnings :
|
||||
-- The parametrization range for the B-spline curve is not [0, 2Pi].
|
||||
--
|
||||
--- KeyWords :
|
||||
-- Convert, Circle, BSplineCurve, 2D .
|
||||
|
||||
|
||||
uses Circ2d from gp,
|
||||
ParameterisationType from Convert
|
||||
|
||||
raises DomainError from Standard
|
||||
|
||||
is
|
||||
|
||||
Create (C : Circ2d;
|
||||
Parameterisation : ParameterisationType from Convert
|
||||
= Convert_TgtThetaOver2)
|
||||
returns CircleToBSplineCurve;
|
||||
--- Purpose :
|
||||
-- The equivalent B-spline curve has the same orientation
|
||||
-- as the circle C.
|
||||
|
||||
|
||||
Create (C : Circ2d; U1, U2 : Real ;
|
||||
Parameterisation : ParameterisationType from Convert
|
||||
= Convert_TgtThetaOver2)
|
||||
returns CircleToBSplineCurve
|
||||
--- Purpose :
|
||||
-- The circle C is limited between the parametric values U1, U2
|
||||
-- in radians. U1 and U2 [0.0, 2*Pi] .
|
||||
-- The equivalent B-spline curve is oriented from U1 to U2 and has
|
||||
-- the same orientation as the circle C.
|
||||
raises DomainError;
|
||||
--- Purpose :
|
||||
-- Raised if U1 = U2 or U1 = U2 + 2.0 * Pi
|
||||
|
||||
|
||||
end CircleToBSplineCurve;
|
||||
|
177
src/Convert/Convert_CircleToBSplineCurve.cxx
Executable file
177
src/Convert/Convert_CircleToBSplineCurve.cxx
Executable file
@@ -0,0 +1,177 @@
|
||||
//File Convert_CircleToBSplineCurve.cxx
|
||||
//JCV 16/10/91
|
||||
|
||||
#include <Convert_CircleToBSplineCurve.ixx>
|
||||
#include <TColgp_HArray1OfPnt2d.hxx>
|
||||
#include <TColStd_HArray1OfReal.hxx>
|
||||
#include <TColStd_HArray1OfInteger.hxx>
|
||||
#include <TColStd_Array1OfReal.hxx>
|
||||
#include <TColgp_Array1OfPnt2d.hxx>
|
||||
|
||||
#include <Precision.hxx>
|
||||
#include <gp.hxx>
|
||||
#include <gp_Ax2d.hxx>
|
||||
#include <gp_Dir2d.hxx>
|
||||
#include <gp_Trsf2d.hxx>
|
||||
|
||||
//Attention :
|
||||
//Pour eviter de trainer des tableaux persistent dans les champs
|
||||
//on dimensionne les tableaux au maxi (TheNbKnots et TheNbPoles)
|
||||
//qui correspondent au cercle complet. Pour un arc de cercle on a
|
||||
//evidemment besoin de moins de poles et de noeuds, c'est pourquoi les
|
||||
//champs nbKnots et nbPoles sont presents et sont mis a jour dans le
|
||||
//constructeur d'un arc de cercle B-spline pour tenir compte du nombre
|
||||
//effectif de poles et de noeuds.
|
||||
|
||||
|
||||
// parametrization :
|
||||
// Reference : Rational B-spline for Curve and Surface Representation
|
||||
// Wayne Tiller CADG September 1983
|
||||
//
|
||||
// x(t) = (1 - t^2) / (1 + t^2)
|
||||
// y(t) = 2 t / (1 + t^2)
|
||||
//
|
||||
// then t = Sqrt(2) u / ((Sqrt(2) - 2) u + 2)
|
||||
//
|
||||
// => u = 2 t / (Sqrt(2) + (2 - Sqrt(2)) t)
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_CircleToBSplineCurve
|
||||
//purpose : this constructs a periodic circle
|
||||
//=======================================================================
|
||||
|
||||
Convert_CircleToBSplineCurve::Convert_CircleToBSplineCurve
|
||||
(const gp_Circ2d& C, const Convert_ParameterisationType Parameterisation)
|
||||
:Convert_ConicToBSplineCurve(0,0,0){
|
||||
|
||||
Standard_Integer ii ;
|
||||
|
||||
Standard_Real R,
|
||||
value ;
|
||||
Handle(TColStd_HArray1OfReal) CosNumeratorPtr,
|
||||
SinNumeratorPtr ;
|
||||
|
||||
|
||||
R = C.Radius() ;
|
||||
if (Parameterisation != Convert_TgtThetaOver2 &&
|
||||
Parameterisation != Convert_RationalC1) {
|
||||
// Dans ce cas BuildCosAndSin ne sait pas gerer la periodicite
|
||||
// => on trim sur 0,2*PI
|
||||
isperiodic = Standard_False;
|
||||
Convert_ConicToBSplineCurve::
|
||||
BuildCosAndSin(Parameterisation,
|
||||
0, 2*PI,
|
||||
CosNumeratorPtr,
|
||||
SinNumeratorPtr,
|
||||
weights,
|
||||
degree,
|
||||
knots,
|
||||
mults);
|
||||
}
|
||||
else {
|
||||
isperiodic = Standard_True;
|
||||
Convert_ConicToBSplineCurve::
|
||||
BuildCosAndSin(Parameterisation,
|
||||
CosNumeratorPtr,
|
||||
SinNumeratorPtr,
|
||||
weights,
|
||||
degree,
|
||||
knots,
|
||||
mults);
|
||||
}
|
||||
|
||||
|
||||
nbPoles = CosNumeratorPtr->Length();
|
||||
nbKnots = knots->Length();
|
||||
|
||||
poles =
|
||||
new TColgp_HArray1OfPnt2d(1,nbPoles);
|
||||
|
||||
|
||||
gp_Dir2d Ox = C.XAxis().Direction();
|
||||
gp_Dir2d Oy = C.YAxis().Direction();
|
||||
gp_Trsf2d Trsf;
|
||||
Trsf.SetTransformation( C.XAxis(), gp::OX2d());
|
||||
if ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.0e0) {
|
||||
value = R ;
|
||||
}
|
||||
else {
|
||||
value = -R ;
|
||||
}
|
||||
|
||||
// On replace la bspline dans le repere du cercle.
|
||||
// et on calcule les poids de la bspline.
|
||||
|
||||
for (ii = 1; ii <= nbPoles ; ii++) {
|
||||
poles->ChangeArray1()(ii).SetCoord(1, R * CosNumeratorPtr->Value(ii)) ;
|
||||
poles->ChangeArray1()(ii).SetCoord(2, value * SinNumeratorPtr->Value(ii)) ;
|
||||
poles->ChangeArray1()(ii).Transform( Trsf);
|
||||
}
|
||||
|
||||
}
|
||||
//=======================================================================
|
||||
//function : Convert_CircleToBSplineCurve
|
||||
//purpose : this constructs a non periodic circle
|
||||
//=======================================================================
|
||||
|
||||
Convert_CircleToBSplineCurve::Convert_CircleToBSplineCurve
|
||||
(const gp_Circ2d& C,
|
||||
const Standard_Real UFirst,
|
||||
const Standard_Real ULast,
|
||||
const Convert_ParameterisationType Parameterisation)
|
||||
:Convert_ConicToBSplineCurve(0,0,0)
|
||||
{
|
||||
Standard_Real delta = ULast - UFirst ;
|
||||
Standard_Real Eps = Precision::PConfusion();
|
||||
|
||||
if ( (delta > (2*PI + Eps)) || (delta <= 0.0e0) ) {
|
||||
Standard_DomainError::Raise( "Convert_CircleToBSplineCurve");
|
||||
}
|
||||
|
||||
Standard_Integer ii;
|
||||
Standard_Real R, value ;
|
||||
Handle(TColStd_HArray1OfReal) CosNumeratorPtr,SinNumeratorPtr ;
|
||||
|
||||
|
||||
R = C.Radius() ;
|
||||
isperiodic = Standard_False;
|
||||
Convert_ConicToBSplineCurve::BuildCosAndSin(Parameterisation,
|
||||
UFirst,
|
||||
ULast,
|
||||
CosNumeratorPtr,
|
||||
SinNumeratorPtr,
|
||||
weights,
|
||||
degree,
|
||||
knots,
|
||||
mults) ;
|
||||
|
||||
|
||||
|
||||
nbPoles = CosNumeratorPtr->Length();
|
||||
nbKnots = knots->Length();
|
||||
|
||||
poles =
|
||||
new TColgp_HArray1OfPnt2d(1,nbPoles) ;
|
||||
|
||||
gp_Dir2d Ox = C.XAxis().Direction();
|
||||
gp_Dir2d Oy = C.YAxis().Direction();
|
||||
gp_Trsf2d Trsf;
|
||||
Trsf.SetTransformation( C.XAxis(), gp::OX2d());
|
||||
if ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.0e0) {
|
||||
value = R ;
|
||||
}
|
||||
else {
|
||||
value = -R ;
|
||||
}
|
||||
|
||||
// On replace la bspline dans le repere du cercle.
|
||||
// et on calcule les poids de la bspline.
|
||||
|
||||
for (ii = 1; ii <= nbPoles ; ii++) {
|
||||
poles->ChangeArray1()(ii).SetCoord(1, R * CosNumeratorPtr->Value(ii)) ;
|
||||
poles->ChangeArray1()(ii).SetCoord(2, value * SinNumeratorPtr->Value(ii)) ;
|
||||
poles->ChangeArray1()(ii).Transform( Trsf);
|
||||
}
|
||||
|
||||
}
|
||||
|
183
src/Convert/Convert_CompBezierCurves2dToBSplineCurve2d.cdl
Executable file
183
src/Convert/Convert_CompBezierCurves2dToBSplineCurve2d.cdl
Executable file
@@ -0,0 +1,183 @@
|
||||
-- File: Convert_CompBezierCurves2dToBSplineCurve2d.cdl
|
||||
-- Created: Tue Nov 9 10:52:26 1993
|
||||
-- Author: Modelistation
|
||||
-- <model@topsn3>
|
||||
---Copyright: Matra Datavision 1993
|
||||
|
||||
class CompBezierCurves2dToBSplineCurve2d from Convert
|
||||
|
||||
---Purpose: Converts a list of connecting Bezier Curves 2d to a
|
||||
-- BSplineCurve 2d.
|
||||
-- if possible, the continuity of the BSpline will be
|
||||
-- increased to more than C0.
|
||||
|
||||
|
||||
uses
|
||||
SequenceOfReal from TColStd,
|
||||
SequenceOfInteger from TColStd,
|
||||
Array1OfReal from TColStd,
|
||||
Array1OfInteger from TColStd,
|
||||
Array1OfPnt2d from TColgp,
|
||||
SequenceOfPnt2d from TColgp,
|
||||
SequenceOfArray1OfPoles2d from Convert
|
||||
|
||||
|
||||
raises
|
||||
ConstructionError from Standard
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
--- Don't forget to use the method Perform before accessing the Result.
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
is
|
||||
Create( AngularTolerance : Real = 1.0e-4 )
|
||||
returns CompBezierCurves2dToBSplineCurve2d from Convert;
|
||||
---Purpose: Constructs a framework for converting a sequence of
|
||||
-- adjacent non-rational Bezier curves into a BSpline curve.
|
||||
-- Knots will be created on the computed BSpline curve at
|
||||
-- each junction point of two consecutive Bezier curves. The
|
||||
-- degree of continuity of the BSpline curve will be increased at
|
||||
-- the junction point of two consecutive Bezier curves if their
|
||||
-- tangent vectors at this point are parallel. AngularTolerance
|
||||
-- (given in radians, and defaulted to 1.0 e-4) will be used
|
||||
-- to check the parallelism of the two tangent vectors.
|
||||
-- Use the following functions:
|
||||
-- - AddCurve to define in sequence the adjacent Bezier
|
||||
-- curves to be converted,
|
||||
-- - Perform to compute the data needed to build the BSpline curve,
|
||||
-- - and the available consultation functions to access the
|
||||
-- computed data. This data may be used to construct the BSpline curve.
|
||||
|
||||
AddCurve( me : in out;
|
||||
Poles : Array1OfPnt2d from TColgp)
|
||||
is static;
|
||||
--- Purpose: Adds the Bezier curve defined by the table of poles Poles, to
|
||||
-- the sequence (still contained in this framework) of adjacent
|
||||
-- Bezier curves to be converted into a BSpline curve.
|
||||
-- Only polynomial (i.e. non-rational) Bezier curves are
|
||||
-- converted using this framework.
|
||||
-- If this is not the first call to the function (i.e. if this framework
|
||||
-- still contains data in its sequence of Bezier curves), the
|
||||
-- degree of continuity of the BSpline curve will be increased at
|
||||
-- the time of computation at the first point of the added Bezier
|
||||
-- curve (i.e. the first point of the Poles table). This will be the
|
||||
-- case if the tangent vector of the curve at this point is
|
||||
-- parallel to the tangent vector at the end point of the
|
||||
-- preceding Bezier curve in the sequence of Bezier curves still
|
||||
-- contained in this framework. An angular tolerance given at
|
||||
-- the time of construction of this framework, will be used to
|
||||
-- check the parallelism of the two tangent vectors. This
|
||||
-- checking procedure, and all the relative computations will be
|
||||
-- performed by the function Perform.
|
||||
-- When the sequence of adjacent Bezier curves is complete,
|
||||
-- use the following functions:
|
||||
-- - Perform to compute the data needed to build the BSpline curve,
|
||||
-- - and the available consultation functions to access the
|
||||
-- computed data. This data may be used to construct the BSpline curve.
|
||||
-- Warning
|
||||
-- The sequence of Bezier curves treated by this framework is
|
||||
-- automatically initialized with the first Bezier curve when the
|
||||
-- function is first called. During subsequent use of this function,
|
||||
-- ensure that the first point of the added Bezier curve (i.e. the
|
||||
-- first point of the Poles table) is coincident with the last point
|
||||
-- of the sequence (i.e. the last point of the preceding Bezier
|
||||
-- curve in the sequence) of Bezier curves still contained in
|
||||
-- this framework. An error may occur at the time of
|
||||
-- computation if this condition is not satisfied. Particular care
|
||||
-- must be taken with respect to the above, as this condition is
|
||||
-- not checked either when defining the sequence of Bezier
|
||||
-- curves or at the time of computation.
|
||||
|
||||
|
||||
Perform(me: in out)
|
||||
---Purpose: Computes all the data needed to build a BSpline curve
|
||||
-- equivalent to the sequence of adjacent Bezier curves still
|
||||
-- contained in this framework.
|
||||
-- A knot is inserted on the computed BSpline curve at the
|
||||
-- junction point of two consecutive Bezier curves. The
|
||||
-- degree of continuity of the BSpline curve will be increased
|
||||
-- at the junction point of two consecutive Bezier curves if
|
||||
-- their tangent vectors at this point are parallel. An angular
|
||||
-- tolerance given at the time of construction of this
|
||||
-- framework is used to check the parallelism of the two
|
||||
-- tangent vectors.
|
||||
-- Use the available consultation functions to access the
|
||||
-- computed data. This data may then be used to construct
|
||||
-- the BSpline curve.
|
||||
-- Warning
|
||||
-- Ensure that the curves in the sequence of Bezier curves
|
||||
-- contained in this framework are adjacent. An error may
|
||||
-- occur at the time of computation if this condition is not
|
||||
-- satisfied. Particular care must be taken with respect to the
|
||||
-- above as this condition is not checked, either when
|
||||
-- defining the Bezier curve sequence or at the time of computation.
|
||||
is static;
|
||||
|
||||
|
||||
Degree(me) returns Integer from Standard
|
||||
is static;
|
||||
---Purpose: Returns the degree of the BSpline curve whose data is
|
||||
-- computed in this framework.
|
||||
-- Warning
|
||||
-- Take particular care not to use this function before the
|
||||
-- computation is performed (Perform function), as this
|
||||
-- condition is not checked and an error may therefore occur.
|
||||
|
||||
NbPoles(me) returns Integer from Standard
|
||||
is static;
|
||||
---Purpose: Returns the number of poles of the BSpline curve whose
|
||||
-- data is computed in this framework.
|
||||
-- Warning
|
||||
-- Take particular care not to use this function before the
|
||||
-- computation is performed (Perform function), as this
|
||||
-- condition is not checked and an error may therefore occur.
|
||||
|
||||
Poles(me; Poles : in out Array1OfPnt2d from TColgp)
|
||||
is static;
|
||||
--- Purpose: Loads the Poles table with the poles of the BSpline curve
|
||||
-- whose data is computed in this framework.
|
||||
-- Warning
|
||||
-- - Do not use this function before the computation is
|
||||
-- performed (Perform function).
|
||||
-- - The length of the Poles array must be equal to the
|
||||
-- number of poles of the BSpline curve whose data is
|
||||
-- computed in this framework.
|
||||
-- Particular care must be taken with respect to the above, as
|
||||
-- these conditions are not checked, and an error may occur.
|
||||
|
||||
NbKnots(me) returns Integer from Standard
|
||||
is static;
|
||||
--- Purpose: Returns the number of knots of the BSpline curve whose
|
||||
-- data is computed in this framework.
|
||||
-- Warning
|
||||
-- Take particular care not to use this function before the
|
||||
-- computation is performed (Perform function), as this
|
||||
-- condition is not checked and an error may therefore occur.
|
||||
|
||||
KnotsAndMults(me;
|
||||
Knots : in out Array1OfReal from TColStd;
|
||||
Mults : in out Array1OfInteger from TColStd)
|
||||
is static;
|
||||
--- Purpose: Loads the Knots table with the knots
|
||||
-- and the Mults table with the corresponding multiplicities
|
||||
-- of the BSpline curve whose data is computed in this framework.
|
||||
-- Warning
|
||||
-- - Do not use this function before the computation is
|
||||
-- performed (Perform function).
|
||||
-- - The length of the Knots and Mults arrays must be equal
|
||||
-- to the number of knots in the BSpline curve whose data is
|
||||
-- computed in this framework.
|
||||
-- Particular care must be taken with respect to the above as
|
||||
-- these conditions are not checked, and an error may occur.
|
||||
|
||||
|
||||
fields
|
||||
mySequence : SequenceOfArray1OfPoles2d from Convert;
|
||||
CurvePoles : SequenceOfPnt2d from TColgp;
|
||||
CurveKnots : SequenceOfReal from TColStd;
|
||||
KnotsMultiplicities : SequenceOfInteger from TColStd;
|
||||
myDegree : Integer from Standard;
|
||||
myAngular : Real from Standard;
|
||||
myDone : Boolean from Standard;
|
||||
|
||||
end CompBezierCurves2dToBSplineCurve2d;
|
243
src/Convert/Convert_CompBezierCurves2dToBSplineCurve2d.cxx
Executable file
243
src/Convert/Convert_CompBezierCurves2dToBSplineCurve2d.cxx
Executable file
@@ -0,0 +1,243 @@
|
||||
// File: Convert_CompBezierCurves2dToBSplineCurve2d.cxx
|
||||
// Created: Wed Oct 20 14:55:08 1993
|
||||
// Author: Bruno DUMORTIER
|
||||
// <dub@topsn3>
|
||||
// modified 25/06/1996 PMN : Ajout d'une tolerance Angulaire dans le
|
||||
// constructeur pour le test de continuite G1 (1 Radians c'etait trop
|
||||
// cf BUG PRO4481)
|
||||
|
||||
#include <Convert_CompBezierCurves2dToBSplineCurve2d.ixx>
|
||||
|
||||
#include <Precision.hxx>
|
||||
#include <BSplCLib.hxx>
|
||||
#include <PLib.hxx>
|
||||
#include <gp_Pnt2d.hxx>
|
||||
#include <gp_Vec2d.hxx>
|
||||
#include <gp.hxx>
|
||||
#include <TColgp_HArray1OfPnt2d.hxx>
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_CompBezierCurves2dToBSplineCurve2d
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_CompBezierCurves2dToBSplineCurve2d::
|
||||
Convert_CompBezierCurves2dToBSplineCurve2d(
|
||||
const Standard_Real AngularTolerance) :
|
||||
myAngular(AngularTolerance),
|
||||
myDone(Standard_False)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : AddCurve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_CompBezierCurves2dToBSplineCurve2d::AddCurve
|
||||
(const TColgp_Array1OfPnt2d& Poles)
|
||||
{
|
||||
if ( !mySequence.IsEmpty()) {
|
||||
gp_Pnt2d P1,P2;
|
||||
P1 = mySequence.Last()->Value(mySequence.Last()->Upper());
|
||||
P2 = Poles(Poles.Lower());
|
||||
|
||||
// User defined tolerance NYI
|
||||
// Standard_ConstructionError_Raise_if
|
||||
// ( !P1.IsEqual(P2,Precision::Confusion()),
|
||||
// "Convert_CompBezierCurves2dToBSplineCurve2d::Addcurve");
|
||||
|
||||
}
|
||||
myDone = Standard_False;
|
||||
Handle(TColgp_HArray1OfPnt2d) HPoles =
|
||||
new TColgp_HArray1OfPnt2d(Poles.Lower(),Poles.Upper());
|
||||
HPoles->ChangeArray1() = Poles;
|
||||
mySequence.Append(HPoles);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Degree
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_CompBezierCurves2dToBSplineCurve2d::Degree()
|
||||
const {
|
||||
return myDegree;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbPoles
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_CompBezierCurves2dToBSplineCurve2d::NbPoles()
|
||||
const {
|
||||
return CurvePoles.Length();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Poles
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_CompBezierCurves2dToBSplineCurve2d::Poles
|
||||
(TColgp_Array1OfPnt2d& Poles) const
|
||||
{
|
||||
Standard_Integer i, Lower = Poles.Lower(), Upper = Poles.Upper();
|
||||
Standard_Integer k = 1;
|
||||
for (i = Lower; i <= Upper; i++) {
|
||||
Poles(i) = CurvePoles(k++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbKnots
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_CompBezierCurves2dToBSplineCurve2d::NbKnots()
|
||||
const {
|
||||
return CurveKnots.Length();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : KnotsAndMults
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_CompBezierCurves2dToBSplineCurve2d::KnotsAndMults
|
||||
(TColStd_Array1OfReal& Knots,
|
||||
TColStd_Array1OfInteger& Mults ) const
|
||||
{
|
||||
Standard_Integer i, LowerK = Knots.Lower(), UpperK = Knots.Upper();
|
||||
Standard_Integer LowerM = Mults.Lower(), UpperM = Mults.Upper();
|
||||
Standard_Integer k = 1;
|
||||
for (i = LowerK; i <= UpperK; i++) {
|
||||
Knots(i) = CurveKnots(k++);
|
||||
}
|
||||
k = 1;
|
||||
for (i = LowerM; i <= UpperM; i++) {
|
||||
Mults(i) = KnotsMultiplicities(k++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_CompBezierCurves2dToBSplineCurve2d::Perform()
|
||||
{
|
||||
myDone = Standard_True;
|
||||
CurvePoles.Clear();
|
||||
CurveKnots.Clear();
|
||||
KnotsMultiplicities.Clear();
|
||||
Standard_Integer LowerI = 1;
|
||||
Standard_Integer UpperI = mySequence.Length();
|
||||
Standard_Integer NbrCurv = UpperI-LowerI+1;
|
||||
// Standard_Integer NbKnotsSpl = NbrCurv + 1 ;
|
||||
TColStd_Array1OfReal CurveKnVals (1,NbrCurv);
|
||||
|
||||
Standard_Integer i;
|
||||
myDegree = 0;
|
||||
for ( i = 1; i <= mySequence.Length(); i++) {
|
||||
myDegree = Max( myDegree, (mySequence(i))->Length() -1);
|
||||
}
|
||||
|
||||
Standard_Real D1, D2, Lambda, Det=0;
|
||||
gp_Pnt2d P1, P2, P3;
|
||||
Standard_Integer Deg, Inc, MaxDegree = myDegree;
|
||||
TColgp_Array1OfPnt2d Points(1, myDegree+1);
|
||||
|
||||
for (i = LowerI ; i <= UpperI ; i++) {
|
||||
// 1- Elever la courbe de Bezier au degre maximum.
|
||||
Deg = mySequence(i)->Length()-1;
|
||||
Inc = myDegree - Deg;
|
||||
if ( Inc > 0) {
|
||||
BSplCLib::IncreaseDegree(myDegree,
|
||||
mySequence(i)->Array1(), PLib::NoWeights(),
|
||||
Points, PLib::NoWeights());
|
||||
}
|
||||
else {
|
||||
Points = mySequence(i)->Array1();
|
||||
}
|
||||
|
||||
// 2- Traiter le noeud de jonction entre 2 courbes de Bezier.
|
||||
if (i == LowerI) {
|
||||
// Traitement du noeud initial de la BSpline.
|
||||
for (Standard_Integer j = 1 ; j <= MaxDegree ; j++) {
|
||||
CurvePoles.Append(Points(j));
|
||||
}
|
||||
CurveKnVals(1) = 1.; // Pour amorcer la serie.
|
||||
KnotsMultiplicities.Append(MaxDegree+1);
|
||||
Det = 1.;
|
||||
}
|
||||
|
||||
|
||||
if (i != LowerI) {
|
||||
P2 = Points(1);
|
||||
P3 = Points(2);
|
||||
gp_Vec2d V1(P1, P2), V2(P2, P3);
|
||||
D1 = P1.SquareDistance(P2);
|
||||
D2 = P3.SquareDistance(P2);
|
||||
Lambda = Sqrt(D2/D1);
|
||||
|
||||
|
||||
// Traitement de la tangence entre la Bezier et sa precedente.
|
||||
// Ceci permet d''assurer au moins une continuite C1 si
|
||||
// les tangentes sont coherentes.
|
||||
|
||||
|
||||
// Test de l'angle a myAngular
|
||||
|
||||
if (V1.Magnitude() > gp::Resolution() &&
|
||||
V2.Magnitude() > gp::Resolution() &&
|
||||
V1.IsParallel(V2, myAngular )) {
|
||||
KnotsMultiplicities.Append(MaxDegree-1);
|
||||
CurveKnVals(i) = CurveKnVals(i-1) * Lambda;
|
||||
Det += CurveKnVals(i);
|
||||
|
||||
}
|
||||
else {
|
||||
CurveKnVals(i) = 1.0e0 ;
|
||||
Det += CurveKnVals(i) ;
|
||||
CurvePoles.Append(Points(1));
|
||||
KnotsMultiplicities.Append(MaxDegree);
|
||||
}
|
||||
|
||||
// Stocker les poles.
|
||||
for (Standard_Integer j = 2 ; j <= MaxDegree ; j++) {
|
||||
CurvePoles.Append(Points(j));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (i == UpperI) {
|
||||
// Traitement du noeud terminal de la BSpline.
|
||||
CurvePoles.Append(Points(MaxDegree+1));
|
||||
KnotsMultiplicities.Append(MaxDegree+1);
|
||||
}
|
||||
P1 = Points(MaxDegree);
|
||||
}
|
||||
|
||||
// Corriger les valeurs nodales pour les faire varier dans [0.,1.].
|
||||
CurveKnots.Append(0.0);
|
||||
for (i = 2 ; i <= NbrCurv ; i++) {
|
||||
CurveKnots.Append(CurveKnots(i-1) + (CurveKnVals(i-1)/Det));
|
||||
}
|
||||
CurveKnots.Append(1.0);
|
||||
}
|
||||
|
||||
|
185
src/Convert/Convert_CompBezierCurvesToBSplineCurve.cdl
Executable file
185
src/Convert/Convert_CompBezierCurvesToBSplineCurve.cdl
Executable file
@@ -0,0 +1,185 @@
|
||||
-- File: Convert_CompBezierCurvesToBSplineCurve.cdl
|
||||
-- Created: Wed Oct 20 11:54:50 1993
|
||||
-- Author: Bruno DUMORTIER
|
||||
-- <dub@topsn3>
|
||||
---Copyright: Matra Datavision 1993
|
||||
|
||||
|
||||
class CompBezierCurvesToBSplineCurve from Convert
|
||||
|
||||
---Purpose: An algorithm to convert a sequence of adjacent
|
||||
-- non-rational Bezier curves into a BSpline curve.
|
||||
-- A CompBezierCurvesToBSplineCurve object provides a framework for:
|
||||
-- - defining the sequence of adjacent non-rational Bezier
|
||||
-- curves to be converted into a BSpline curve,
|
||||
-- - implementing the computation algorithm, and
|
||||
-- - consulting the results.
|
||||
-- Warning
|
||||
-- Do not attempt to convert rational Bezier curves using this type of algorithm.
|
||||
|
||||
uses
|
||||
Array1OfReal from TColStd,
|
||||
SequenceOfReal from TColStd,
|
||||
SequenceOfInteger from TColStd,
|
||||
Array1OfInteger from TColStd,
|
||||
Array1OfPnt from TColgp,
|
||||
SequenceOfPnt from TColgp,
|
||||
SequenceOfArray1OfPoles from Convert
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
--- Don't forget to use the method Perform before accessing the Result.
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
raises
|
||||
ConstructionError from Standard
|
||||
|
||||
is
|
||||
Create ( AngularTolerance : Real = 1.0e-4 )
|
||||
returns CompBezierCurvesToBSplineCurve from Convert;
|
||||
---Purpose: Constructs a framework for converting a sequence of
|
||||
-- adjacent non-rational Bezier curves into a BSpline curve.
|
||||
-- Knots will be created on the computed BSpline curve at
|
||||
-- each junction point of two consecutive Bezier curves. The
|
||||
-- degree of continuity of the BSpline curve will be increased at
|
||||
-- the junction point of two consecutive Bezier curves if their
|
||||
-- tangent vectors at this point are parallel. AngularTolerance
|
||||
-- (given in radians, and defaulted to 1.0 e-4) will be used
|
||||
-- to check the parallelism of the two tangent vectors.
|
||||
-- Use the following functions:
|
||||
-- - AddCurve to define in sequence the adjacent Bezier
|
||||
-- curves to be converted,
|
||||
-- - Perform to compute the data needed to build the BSpline curve,
|
||||
-- - and the available consultation functions to access the
|
||||
-- computed data. This data may be used to construct the BSpline curve.
|
||||
|
||||
AddCurve( me : in out;
|
||||
Poles : Array1OfPnt from TColgp)
|
||||
is static;
|
||||
--- Purpose: Adds the Bezier curve defined by the table of poles Poles, to
|
||||
-- the sequence (still contained in this framework) of adjacent
|
||||
-- Bezier curves to be converted into a BSpline curve.
|
||||
-- Only polynomial (i.e. non-rational) Bezier curves are
|
||||
-- converted using this framework.
|
||||
-- If this is not the first call to the function (i.e. if this framework
|
||||
-- still contains data in its Bezier curve sequence), the degree
|
||||
-- of continuity of the BSpline curve will be increased at the
|
||||
-- time of computation at the first point of the added Bezier
|
||||
-- curve (i.e. the first point of the Poles table). This will be the
|
||||
-- case if the tangent vector of the curve at this point is
|
||||
-- parallel to the tangent vector at the end point of the
|
||||
-- preceding Bezier curve in the Bezier curve sequence still
|
||||
-- contained in this framework. An angular tolerance given at
|
||||
-- the time of construction of this framework will be used to
|
||||
-- check the parallelism of the two tangent vectors. This
|
||||
-- checking procedure and all related computations will be
|
||||
-- performed by the Perform function.
|
||||
-- When the adjacent Bezier curve sequence is complete, use
|
||||
-- the following functions:
|
||||
-- - Perform to compute the data needed to build the BSpline curve,
|
||||
-- - and the available consultation functions to access the
|
||||
-- computed data. This data may be used to construct the BSpline curve.
|
||||
-- Warning
|
||||
-- The Bezier curve sequence treated by this framework is
|
||||
-- automatically initialized with the first Bezier curve when the
|
||||
-- function is first called. During subsequent use of this function,
|
||||
-- ensure that the first point of the added Bezier curve (i.e. the
|
||||
-- first point of the Poles table) is coincident with the last point
|
||||
-- of the Bezier curve sequence (i.e. the last point of the
|
||||
-- preceding Bezier curve in the sequence) still contained in
|
||||
-- this framework. An error may occur at the time of
|
||||
-- computation if this condition is not satisfied. Particular care
|
||||
-- must be taken with respect to the above, as this condition is
|
||||
-- not checked either when defining the Bezier curve
|
||||
-- sequence or at the time of computation.
|
||||
|
||||
Perform(me: in out)
|
||||
---Purpose: Computes all the data needed to build a BSpline curve
|
||||
-- equivalent to the adjacent Bezier curve sequence still
|
||||
-- contained in this framework.
|
||||
-- A knot is inserted on the computed BSpline curve at the
|
||||
-- junction point of two consecutive Bezier curves. The
|
||||
-- degree of continuity of the BSpline curve will be increased
|
||||
-- at the junction point of two consecutive Bezier curves if
|
||||
-- their tangent vectors at this point are parallel. An angular
|
||||
-- tolerance given at the time of construction of this
|
||||
-- framework is used to check the parallelism of the two
|
||||
-- tangent vectors.
|
||||
-- Use the available consultation functions to access the
|
||||
-- computed data. This data may then be used to construct
|
||||
-- the BSpline curve.
|
||||
-- Warning
|
||||
-- Make sure that the curves in the Bezier curve sequence
|
||||
-- contained in this framework are adjacent. An error may
|
||||
-- occur at the time of computation if this condition is not
|
||||
-- satisfied. Particular care must be taken with respect to the
|
||||
-- above as this condition is not checked, either when
|
||||
-- defining the Bezier curve sequence or at the time of computation.
|
||||
is static;
|
||||
|
||||
|
||||
Degree(me) returns Integer from Standard
|
||||
is static;
|
||||
---Purpose: Returns the degree of the BSpline curve whose data is
|
||||
-- computed in this framework.
|
||||
-- Warning
|
||||
-- Take particular care not to use this function before the
|
||||
-- computation is performed (Perform function), as this
|
||||
-- condition is not checked and an error may therefore occur.
|
||||
|
||||
NbPoles(me) returns Integer from Standard
|
||||
is static;
|
||||
---Purpose: Returns the number of poles of the BSpline curve whose
|
||||
-- data is computed in this framework.
|
||||
-- Warning
|
||||
-- Take particular care not to use this function before the
|
||||
-- computation is performed (Perform function), as this
|
||||
-- condition is not checked and an error may therefore occur.
|
||||
|
||||
Poles(me; Poles : in out Array1OfPnt from TColgp)
|
||||
is static;
|
||||
--- Purpose: Loads the Poles table with the poles of the BSpline curve
|
||||
-- whose data is computed in this framework.
|
||||
-- Warning
|
||||
-- - Do not use this function before the computation is
|
||||
-- performed (Perform function).
|
||||
-- - The length of the Poles array must be equal to the
|
||||
-- number of poles of the BSpline curve whose data is
|
||||
-- computed in this framework.
|
||||
-- Particular care must be taken with respect to the above, as
|
||||
-- these conditions are not checked, and an error may occur.
|
||||
|
||||
NbKnots(me) returns Integer from Standard
|
||||
is static;
|
||||
---Purpose: Returns the number of knots of the BSpline curve whose
|
||||
-- data is computed in this framework.
|
||||
-- Warning
|
||||
-- Take particular care not to use this function before the
|
||||
-- computation is performed (Perform function), as this
|
||||
-- condition is not checked and an error may therefore occur.
|
||||
KnotsAndMults(me;
|
||||
Knots : in out Array1OfReal from TColStd;
|
||||
Mults : in out Array1OfInteger from TColStd)
|
||||
is static;
|
||||
---Purpose:
|
||||
-- - loads the Knots table with the knots,
|
||||
-- - and loads the Mults table with the corresponding multiplicities
|
||||
-- of the BSpline curve whose data is computed in this framework.
|
||||
-- Warning
|
||||
-- - Do not use this function before the computation is
|
||||
-- performed (Perform function).
|
||||
-- - The length of the Knots and Mults arrays must be equal
|
||||
-- to the number of knots in the BSpline curve whose data is
|
||||
-- computed in this framework.
|
||||
-- Particular care must be taken with respect to the above as
|
||||
-- these conditions are not checked, and an error may occur.
|
||||
|
||||
fields
|
||||
mySequence : SequenceOfArray1OfPoles from Convert;
|
||||
CurvePoles : SequenceOfPnt from TColgp;
|
||||
CurveKnots : SequenceOfReal from TColStd;
|
||||
KnotsMultiplicities : SequenceOfInteger from TColStd;
|
||||
myDegree : Integer from Standard;
|
||||
myAngular : Real from Standard;
|
||||
myDone : Boolean from Standard;
|
||||
|
||||
end CompBezierCurvesToBSplineCurve;
|
245
src/Convert/Convert_CompBezierCurvesToBSplineCurve.cxx
Executable file
245
src/Convert/Convert_CompBezierCurvesToBSplineCurve.cxx
Executable file
@@ -0,0 +1,245 @@
|
||||
// File: Convert_CompBezierCurvesToBSplineCurve.cxx
|
||||
// Created: Wed Oct 20 14:55:08 1993
|
||||
// Author: Bruno DUMORTIER
|
||||
// <dub@topsn3>
|
||||
// modified 25/06/1996 PMN : Ajout d'une tolerance Angulaire dans le
|
||||
// constructeur pour le test de continuite G1 (1 Radians c'etait trop
|
||||
// cf BUG PRO4481)
|
||||
|
||||
#include <Convert_CompBezierCurvesToBSplineCurve.ixx>
|
||||
|
||||
#include <Precision.hxx>
|
||||
#include <BSplCLib.hxx>
|
||||
#include <PLib.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp.hxx>
|
||||
#include <gp_Vec.hxx>
|
||||
#include <TColgp_HArray1OfPnt.hxx>
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_CompBezierCurvesToBSplineCurve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
|
||||
Convert_CompBezierCurvesToBSplineCurve::
|
||||
Convert_CompBezierCurvesToBSplineCurve(
|
||||
const Standard_Real AngularTolerance) :
|
||||
myAngular(AngularTolerance),
|
||||
myDone(Standard_False)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : AddCurve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_CompBezierCurvesToBSplineCurve::AddCurve
|
||||
(const TColgp_Array1OfPnt& Poles)
|
||||
{
|
||||
if ( !mySequence.IsEmpty()) {
|
||||
gp_Pnt P1,P2;
|
||||
P1 = mySequence.Last()->Value(mySequence.Last()->Upper());
|
||||
P2 = Poles(Poles.Lower());
|
||||
|
||||
// NYI
|
||||
if ( !P1.IsEqual(P2,Precision::Confusion()))
|
||||
cout << "Convert_CompBezierCurvesToBSplineCurve::Addcurve" << endl;;
|
||||
}
|
||||
myDone = Standard_False;
|
||||
Handle(TColgp_HArray1OfPnt) HPoles =
|
||||
new TColgp_HArray1OfPnt(Poles.Lower(),Poles.Upper());
|
||||
HPoles->ChangeArray1() = Poles;
|
||||
mySequence.Append(HPoles);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Degree
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_CompBezierCurvesToBSplineCurve::Degree() const
|
||||
{
|
||||
return myDegree;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbPoles
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_CompBezierCurvesToBSplineCurve::NbPoles() const
|
||||
{
|
||||
return CurvePoles.Length();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Poles
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_CompBezierCurvesToBSplineCurve::Poles
|
||||
(TColgp_Array1OfPnt& Poles) const
|
||||
{
|
||||
Standard_Integer i, Lower = Poles.Lower(), Upper = Poles.Upper();
|
||||
Standard_Integer k = 1;
|
||||
for (i = Lower; i <= Upper; i++) {
|
||||
Poles(i) = CurvePoles(k++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbKnots
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_CompBezierCurvesToBSplineCurve::NbKnots() const
|
||||
{
|
||||
return CurveKnots.Length();
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : KnotsAndMults
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_CompBezierCurvesToBSplineCurve::KnotsAndMults
|
||||
(TColStd_Array1OfReal& Knots,
|
||||
TColStd_Array1OfInteger& Mults ) const
|
||||
{
|
||||
Standard_Integer i, LowerK = Knots.Lower(), UpperK = Knots.Upper();
|
||||
Standard_Integer LowerM = Mults.Lower(), UpperM = Mults.Upper();
|
||||
Standard_Integer k = 1;
|
||||
for (i = LowerK; i <= UpperK; i++) {
|
||||
Knots(i) = CurveKnots(k++);
|
||||
}
|
||||
k = 1;
|
||||
for (i = LowerM; i <= UpperM; i++) {
|
||||
Mults(i) = KnotsMultiplicities(k++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Perform
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_CompBezierCurvesToBSplineCurve::Perform()
|
||||
{
|
||||
myDone = Standard_True;
|
||||
CurvePoles.Clear();
|
||||
CurveKnots.Clear();
|
||||
KnotsMultiplicities.Clear();
|
||||
Standard_Integer LowerI = 1;
|
||||
Standard_Integer UpperI = mySequence.Length();
|
||||
Standard_Integer NbrCurv = UpperI-LowerI+1;
|
||||
// Standard_Integer NbKnotsSpl = NbrCurv + 1 ;
|
||||
TColStd_Array1OfReal CurveKnVals (1,NbrCurv);
|
||||
|
||||
Standard_Integer i;
|
||||
myDegree = 0;
|
||||
for ( i = 1; i <= mySequence.Length(); i++) {
|
||||
myDegree = Max( myDegree, (mySequence(i))->Length() -1);
|
||||
}
|
||||
|
||||
Standard_Real D1, D2, Lambda, Det=0;
|
||||
gp_Pnt P1, P2, P3;
|
||||
Standard_Integer Deg, Inc, MaxDegree = myDegree;
|
||||
TColgp_Array1OfPnt Points(1, myDegree+1);
|
||||
|
||||
for (i = LowerI ; i <= UpperI ; i++) {
|
||||
// 1- Elever la courbe de Bezier au degre maximum.
|
||||
Deg = mySequence(i)->Length()-1;
|
||||
Inc = myDegree - Deg;
|
||||
if ( Inc > 0) {
|
||||
BSplCLib::IncreaseDegree(myDegree,
|
||||
mySequence(i)->Array1(), PLib::NoWeights(),
|
||||
Points, PLib::NoWeights());
|
||||
}
|
||||
else {
|
||||
Points = mySequence(i)->Array1();
|
||||
}
|
||||
|
||||
// 2- Traiter le noeud de jonction entre 2 courbes de Bezier.
|
||||
if (i == LowerI) {
|
||||
// Traitement du noeud initial de la BSpline.
|
||||
for (Standard_Integer j = 1 ; j <= MaxDegree ; j++) {
|
||||
CurvePoles.Append(Points(j));
|
||||
}
|
||||
CurveKnVals(1) = 1.; // Pour amorcer la serie.
|
||||
KnotsMultiplicities.Append(MaxDegree+1);
|
||||
Det = 1.;
|
||||
}
|
||||
|
||||
|
||||
if (i != LowerI) {
|
||||
P2 = Points(1);
|
||||
P3 = Points(2);
|
||||
gp_Vec V1(P1, P2), V2(P2, P3);
|
||||
D1 = P1.SquareDistance(P2);
|
||||
D2 = P3.SquareDistance(P2);
|
||||
Lambda = Sqrt(D2/D1);
|
||||
// cout << "D1, D2, Lambda : " << D1 << " " << D2 << " " << Lambda << endl;
|
||||
|
||||
// Traitement de la tangence entre la Bezier et sa precedente.
|
||||
// Ceci permet d''assurer au moins une continuite C1 si
|
||||
// les tangentes sont coherentes.
|
||||
|
||||
if (V1.Magnitude() > gp::Resolution() &&
|
||||
V2.Magnitude() > gp::Resolution() &&
|
||||
V1.IsParallel(V2, myAngular )) {
|
||||
if(CurveKnVals(i-1) * Lambda > 10. * Epsilon(Det)) {
|
||||
KnotsMultiplicities.Append(MaxDegree-1);
|
||||
CurveKnVals(i) = CurveKnVals(i-1) * Lambda;
|
||||
Det += CurveKnVals(i);
|
||||
}
|
||||
else {
|
||||
CurvePoles.Append(Points(1));
|
||||
KnotsMultiplicities.Append(MaxDegree);
|
||||
CurveKnVals(i) = 1.0 ;
|
||||
Det += CurveKnVals(i) ;
|
||||
}
|
||||
}
|
||||
else {
|
||||
CurvePoles.Append(Points(1));
|
||||
KnotsMultiplicities.Append(MaxDegree);
|
||||
CurveKnVals(i) = 1.0 ;
|
||||
Det += CurveKnVals(i) ;
|
||||
}
|
||||
|
||||
// Stocker les poles.
|
||||
for (Standard_Integer j = 2 ; j <= MaxDegree ; j++) {
|
||||
CurvePoles.Append(Points(j));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (i == UpperI) {
|
||||
// Traitement du noeud terminal de la BSpline.
|
||||
CurvePoles.Append(Points(MaxDegree+1));
|
||||
KnotsMultiplicities.Append(MaxDegree+1);
|
||||
}
|
||||
P1 = Points(MaxDegree);
|
||||
}
|
||||
|
||||
// Corriger les valeurs nodales pour les faire varier dans [0.,1.].
|
||||
CurveKnots.Append(0.0);
|
||||
// cout << "Convert : Det = " << Det << endl;
|
||||
for (i = 2 ; i <= NbrCurv ; i++) {
|
||||
CurveKnots.Append(CurveKnots(i-1) + (CurveKnVals(i-1)/Det));
|
||||
}
|
||||
CurveKnots.Append(1.0);
|
||||
}
|
||||
|
||||
|
147
src/Convert/Convert_CompPolynomialToPoles.cdl
Executable file
147
src/Convert/Convert_CompPolynomialToPoles.cdl
Executable file
@@ -0,0 +1,147 @@
|
||||
-- File: Convert_CompPolynomialToPoles.cdl
|
||||
-- Created: Tue May 30 13:38:39 1995
|
||||
-- Author: Xavier BENVENISTE
|
||||
-- <xab@nonox>
|
||||
---Copyright: Matra Datavision 1995
|
||||
|
||||
class CompPolynomialToPoles from Convert
|
||||
|
||||
---Purpose: To convert an function (curve) polynomial by span in a BSpline.
|
||||
--
|
||||
-- This class uses the following arguments :
|
||||
-- NumCurves : the number of Polynomial Curves
|
||||
-- Continuity: the requested continuity for the n-dimensional Spline
|
||||
-- Dimension : the dimension of the Spline
|
||||
-- MaxDegree : maximum allowed degree for each composite
|
||||
-- polynomial segment.
|
||||
-- NumCoeffPerCurve : the number of coefficient per segments = degree - 1
|
||||
-- Coefficients : the coefficients organized in the following way
|
||||
-- [1..<myNumPolynomials>][1..myMaxDegree +1][1..myDimension]
|
||||
-- that is : index [n,d,i] is at slot
|
||||
-- (n-1) * (myMaxDegree + 1) * myDimension + (d-1) * myDimension + i
|
||||
-- PolynomialIntervals : nth polynomial represents a polynomial between
|
||||
-- myPolynomialIntervals->Value(n,0) and
|
||||
-- myPolynomialIntervals->Value(n,1)
|
||||
-- TrueIntervals : the nth polynomial has to be mapped linearly to be
|
||||
-- defined on the following interval :
|
||||
-- myTrueIntervals->Value(n) and myTrueIntervals->Value(n+1)
|
||||
-- so that it represent adequatly the function with the
|
||||
-- required continuity
|
||||
|
||||
uses Array1OfReal from TColStd,
|
||||
HArray1OfReal from TColStd,
|
||||
HArray2OfReal from TColStd,
|
||||
HArray1OfInteger from TColStd,
|
||||
Array1OfReal from TColStd,
|
||||
Array2OfReal from TColStd,
|
||||
Array1OfInteger from TColStd,
|
||||
Shape from GeomAbs
|
||||
raises
|
||||
|
||||
OutOfRange from Standard,
|
||||
ConstructionError from Standard
|
||||
|
||||
is
|
||||
|
||||
Create(NumCurves : Integer ;
|
||||
Continuity : Integer ;
|
||||
Dimension : Integer ;
|
||||
MaxDegree : Integer ;
|
||||
NumCoeffPerCurve : HArray1OfInteger from TColStd ;
|
||||
Coefficients : HArray1OfReal from TColStd ;
|
||||
PolynomialIntervals : HArray2OfReal from TColStd ;
|
||||
TrueIntervals : HArray1OfReal from TColStd)
|
||||
raises ConstructionError ;
|
||||
---Purpose: Warning!
|
||||
-- Continuity can be at MOST the maximum degree of
|
||||
-- the polynomial functions
|
||||
-- TrueIntervals :
|
||||
-- this is the true parameterisation for the composite curve
|
||||
-- that is : the curve has myContinuity if the nth curve
|
||||
-- is parameterized between myTrueIntervals(n) and myTrueIntervals(n+1)
|
||||
--
|
||||
-- Coefficients have to be the implicit "c form":
|
||||
-- Coefficients[Numcurves][MaxDegree+1][Dimension]
|
||||
--
|
||||
-- Warning!
|
||||
-- The NumberOfCoefficient of an polynome is his degree + 1
|
||||
-- Example: To convert the linear function f(x) = 2*x + 1 on the
|
||||
-- domaine [2,5] to BSpline with the bound [-1,1]. Arguments are :
|
||||
-- NumCurves = 1;
|
||||
-- Continuity = 1;
|
||||
-- Dimension = 1;
|
||||
-- MaxDegree = 1;
|
||||
-- NumCoeffPerCurve [1] = {2};
|
||||
-- Coefficients[2] = {1, 2};
|
||||
-- PolynomialIntervals[1,2] = {{2,5}}
|
||||
-- TrueIntervals[2] = {-1, 1}
|
||||
|
||||
|
||||
Create(NumCurves : Integer ;
|
||||
Dimension : Integer ;
|
||||
MaxDegree : Integer ;
|
||||
Continuity : Array1OfInteger from TColStd ;
|
||||
NumCoeffPerCurve : Array1OfInteger from TColStd ;
|
||||
Coefficients : Array1OfReal from TColStd ;
|
||||
PolynomialIntervals : Array2OfReal from TColStd ;
|
||||
TrueIntervals : Array1OfReal from TColStd)
|
||||
---Purpose: To Convert sevral span with different order of Continuity.
|
||||
-- Warning: The Length of Continuity have to be NumCurves-1
|
||||
raises ConstructionError;
|
||||
|
||||
Create(Dimension : Integer ;
|
||||
MaxDegree : Integer ;
|
||||
Degree : Integer ;
|
||||
Coefficients : Array1OfReal from TColStd ;
|
||||
PolynomialIntervals: Array1OfReal from TColStd ;
|
||||
TrueIntervals : Array1OfReal from TColStd)
|
||||
---Purpose: To Convert only one span.
|
||||
raises ConstructionError;
|
||||
|
||||
|
||||
Perform(me : in out;
|
||||
NumCurves : Integer;
|
||||
MaxDegree : Integer;
|
||||
Dimension : Integer ;
|
||||
NumCoeffPerCurve : Array1OfInteger from TColStd ;
|
||||
Coefficients : Array1OfReal from TColStd;
|
||||
PolynomialIntervals : Array2OfReal from TColStd ;
|
||||
TrueIntervals : Array1OfReal from TColStd) is private;
|
||||
|
||||
NbPoles(me) returns Integer ;
|
||||
--
|
||||
---Purpose: number of poles of the n-dimensional BSpline
|
||||
--
|
||||
Poles(me; Poles : in out HArray2OfReal from TColStd) ;
|
||||
---Purpose: returns the poles of the n-dimensional BSpline
|
||||
-- in the following format :
|
||||
-- [1..NumPoles][1..Dimension]
|
||||
--
|
||||
Degree(me)
|
||||
returns Integer ;
|
||||
|
||||
NbKnots(me)
|
||||
returns Integer ;
|
||||
|
||||
---Purpose: Degree of the n-dimensional Bspline
|
||||
Knots(me; K : in out HArray1OfReal from TColStd) ;
|
||||
|
||||
---Purpose: Knots of the n-dimensional Bspline
|
||||
|
||||
Multiplicities(me; M : in out HArray1OfInteger from TColStd) ;
|
||||
---Purpose: Multiplicities of the knots in the BSpline
|
||||
IsDone(me) returns Boolean ;
|
||||
|
||||
|
||||
fields
|
||||
myFlatKnots : HArray1OfReal from TColStd ;
|
||||
myKnots : HArray1OfReal from TColStd ;
|
||||
myMults : HArray1OfInteger from TColStd ;
|
||||
myPoles : HArray2OfReal from TColStd ;
|
||||
-- the poles of the n-dimensional Bspline organized in the following
|
||||
-- fashion
|
||||
-- [1..NumPoles][1..myDimension]
|
||||
myDegree : Integer ;
|
||||
myDone : Boolean ;
|
||||
|
||||
end CompPolynomialToPoles ;
|
367
src/Convert/Convert_CompPolynomialToPoles.cxx
Executable file
367
src/Convert/Convert_CompPolynomialToPoles.cxx
Executable file
@@ -0,0 +1,367 @@
|
||||
// File: Convert_CompPolynomialToPoles.cxx
|
||||
// Created: Tue May 30 14:34:29 1995
|
||||
// Author: Xavier BENVENISTE
|
||||
// <xab@nonox>
|
||||
|
||||
// 19-06-96 : JPI : NbPoles doit utiliser ColLength() au lieu de RowLength()
|
||||
// 16-09-96 : PMN : On ne doit pas se soucier de la continuite lorsqu'il n'y
|
||||
// qu'un seul segment(PRO5474).
|
||||
// 11-12-96 : PMN : Respect de l'indicage des tableaux passer en arguments
|
||||
// TrueIntervals et PolynomialIntervals (BUC40077)
|
||||
// 15-04-97 : PMN : Constructeurs avec un seul segement ou differentes
|
||||
// continuitees.
|
||||
|
||||
#define No_Standard_OutOfRange
|
||||
|
||||
#include <Convert_CompPolynomialToPoles.ixx>
|
||||
#include <TColStd_Array1OfReal.hxx>
|
||||
#include <TColStd_Array1OfInteger.hxx>
|
||||
#include <TColStd_HArray1OfReal.hxx>
|
||||
#include <TColStd_HArray1OfInteger.hxx>
|
||||
#include <PLib.hxx>
|
||||
#include <BSplCLib.hxx>
|
||||
#include <Standard_ConstructionError.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Constructor
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_CompPolynomialToPoles::Convert_CompPolynomialToPoles(
|
||||
const Standard_Integer NumCurves,
|
||||
const Standard_Integer Continuity,
|
||||
const Standard_Integer Dimension,
|
||||
const Standard_Integer MaxDegree,
|
||||
const Handle_TColStd_HArray1OfInteger& NumCoeffPerCurve,
|
||||
const Handle_TColStd_HArray1OfReal& Coefficients,
|
||||
const Handle_TColStd_HArray2OfReal& PolynomialIntervals,
|
||||
const Handle_TColStd_HArray1OfReal& TrueIntervals)
|
||||
: myDone(Standard_False)
|
||||
{
|
||||
Standard_Integer ii, delta;
|
||||
if (NumCurves <= 0 ||
|
||||
NumCoeffPerCurve.IsNull() ||
|
||||
Coefficients.IsNull() ||
|
||||
PolynomialIntervals.IsNull() ||
|
||||
TrueIntervals.IsNull() ||
|
||||
Continuity < 0 ||
|
||||
MaxDegree <= 0 ||
|
||||
Dimension <= 0 ||
|
||||
PolynomialIntervals->RowLength() != 2) {
|
||||
Standard_ConstructionError::
|
||||
Raise("Convert_CompPolynomialToPoles:bad arguments");
|
||||
}
|
||||
myDegree = 0 ;
|
||||
|
||||
delta = NumCurves - 1 ;
|
||||
for (ii = NumCoeffPerCurve->Lower();
|
||||
ii <= NumCoeffPerCurve->Lower() + delta ;
|
||||
ii++) {
|
||||
myDegree = Max(NumCoeffPerCurve->Value(ii)-1,myDegree) ;
|
||||
}
|
||||
if ((Continuity > myDegree)&& (NumCurves>1)) {
|
||||
Standard_ConstructionError::
|
||||
Raise("Convert_CompPolynomialToPoles:Continuity is too great");
|
||||
}
|
||||
//
|
||||
// prepare output
|
||||
//
|
||||
Standard_Integer Tindex, multiplicities ;
|
||||
|
||||
myKnots =
|
||||
new TColStd_HArray1OfReal(1, NumCurves + 1) ;
|
||||
for (ii = 1, Tindex = TrueIntervals->Lower() ;
|
||||
ii <= NumCurves + 1 ; ii++,Tindex++ ) {
|
||||
myKnots->ChangeArray1().SetValue(ii,TrueIntervals->Value(Tindex)) ;
|
||||
}
|
||||
|
||||
multiplicities = myDegree - Continuity ;
|
||||
myMults =
|
||||
new TColStd_HArray1OfInteger(1, NumCurves + 1) ;
|
||||
for (ii = 2 ; ii < NumCurves + 1 ; ii++) {
|
||||
myMults -> SetValue(ii,multiplicities);
|
||||
}
|
||||
myMults -> SetValue(1, myDegree + 1) ;
|
||||
myMults -> SetValue(NumCurves + 1, myDegree + 1) ;
|
||||
|
||||
Perform(NumCurves, MaxDegree, Dimension,
|
||||
NumCoeffPerCurve->Array1(), Coefficients->Array1(),
|
||||
PolynomialIntervals->Array2(), TrueIntervals->Array1());
|
||||
}
|
||||
|
||||
Convert_CompPolynomialToPoles::
|
||||
Convert_CompPolynomialToPoles(const Standard_Integer NumCurves,
|
||||
const Standard_Integer Dimension,
|
||||
const Standard_Integer MaxDegree,
|
||||
const TColStd_Array1OfInteger& Continuity,
|
||||
const TColStd_Array1OfInteger& NumCoeffPerCurve,
|
||||
const TColStd_Array1OfReal& Coefficients,
|
||||
const TColStd_Array2OfReal& PolynomialIntervals,
|
||||
const TColStd_Array1OfReal& TrueIntervals)
|
||||
: myDone(Standard_False)
|
||||
{
|
||||
Standard_Integer ii, delta;
|
||||
if (NumCurves <= 0 ||
|
||||
MaxDegree <= 0 ||
|
||||
Dimension <= 0 ||
|
||||
PolynomialIntervals.RowLength() != 2) {
|
||||
Standard_ConstructionError::
|
||||
Raise("Convert_CompPolynomialToPoles:bad arguments");
|
||||
}
|
||||
myDegree = 0 ;
|
||||
|
||||
delta = NumCurves - 1 ;
|
||||
for (ii = NumCoeffPerCurve.Lower();
|
||||
ii <= NumCoeffPerCurve.Lower() + delta ;
|
||||
ii++) {
|
||||
myDegree = Max(NumCoeffPerCurve.Value(ii)-1,myDegree) ;
|
||||
}
|
||||
//
|
||||
// prepare output
|
||||
//
|
||||
Standard_Integer Tindex ;
|
||||
|
||||
myKnots =
|
||||
new TColStd_HArray1OfReal(1, NumCurves + 1) ;
|
||||
for (ii = 1, Tindex = TrueIntervals.Lower() ;
|
||||
ii <= NumCurves + 1 ; ii++,Tindex++ ) {
|
||||
myKnots->ChangeArray1().SetValue(ii,TrueIntervals.Value(Tindex)) ;
|
||||
}
|
||||
|
||||
myMults =
|
||||
new TColStd_HArray1OfInteger(1, NumCurves + 1) ;
|
||||
for (ii = 2 ; ii < NumCurves + 1 ; ii++) {
|
||||
if ((Continuity(ii) > myDegree)&& (NumCurves>1)) {
|
||||
Standard_ConstructionError::
|
||||
Raise("Convert_CompPolynomialToPoles:Continuity is too great");
|
||||
}
|
||||
|
||||
myMults -> SetValue(ii, myDegree-Continuity(ii) );
|
||||
}
|
||||
myMults -> SetValue(1, myDegree + 1) ;
|
||||
myMults -> SetValue(NumCurves + 1, myDegree + 1) ;
|
||||
|
||||
// Calculs
|
||||
Perform(NumCurves, MaxDegree, Dimension,
|
||||
NumCoeffPerCurve, Coefficients,
|
||||
PolynomialIntervals, TrueIntervals);
|
||||
}
|
||||
|
||||
Convert_CompPolynomialToPoles::
|
||||
Convert_CompPolynomialToPoles(const Standard_Integer Dimension,
|
||||
const Standard_Integer MaxDegree,
|
||||
const Standard_Integer Degree,
|
||||
const TColStd_Array1OfReal& Coefficients,
|
||||
const TColStd_Array1OfReal& PolynomialIntervals,
|
||||
const TColStd_Array1OfReal& TrueIntervals) :
|
||||
myDegree(Degree) ,
|
||||
myDone(Standard_False)
|
||||
|
||||
{
|
||||
if (MaxDegree <= 0 ||
|
||||
Dimension <= 0 ||
|
||||
PolynomialIntervals.Length() != 2)
|
||||
{
|
||||
Standard_ConstructionError::
|
||||
Raise("Convert_CompPolynomialToPoles:bad arguments");
|
||||
}
|
||||
|
||||
TColStd_Array2OfReal ThePolynomialIntervals(1,1,1,2);
|
||||
ThePolynomialIntervals.SetValue(1,1,PolynomialIntervals(PolynomialIntervals.Lower()));
|
||||
ThePolynomialIntervals.SetValue(1,2,PolynomialIntervals(PolynomialIntervals.Upper()));
|
||||
|
||||
TColStd_Array1OfInteger NumCoeffPerCurve(1,1);
|
||||
NumCoeffPerCurve(1) = Degree+1;
|
||||
|
||||
myKnots =
|
||||
new TColStd_HArray1OfReal(1, 2) ;
|
||||
myKnots->ChangeArray1().SetValue(1, TrueIntervals.Value(TrueIntervals.Lower()));
|
||||
myKnots->ChangeArray1().SetValue(2, TrueIntervals.Value(TrueIntervals.Lower()+1));
|
||||
|
||||
myMults =
|
||||
new TColStd_HArray1OfInteger(1, 2) ;
|
||||
myMults->Init( myDegree + 1);
|
||||
|
||||
|
||||
// Calculs
|
||||
Perform(1, MaxDegree, Dimension,
|
||||
NumCoeffPerCurve, Coefficients,
|
||||
ThePolynomialIntervals, TrueIntervals);
|
||||
}
|
||||
|
||||
void Convert_CompPolynomialToPoles::
|
||||
Perform(const Standard_Integer NumCurves,
|
||||
const Standard_Integer MaxDegree,
|
||||
const Standard_Integer Dimension,
|
||||
const TColStd_Array1OfInteger& NumCoeffPerCurve,
|
||||
const TColStd_Array1OfReal& Coefficients,
|
||||
const TColStd_Array2OfReal& PolynomialIntervals,
|
||||
const TColStd_Array1OfReal& TrueIntervals)
|
||||
{
|
||||
Standard_Integer ii,
|
||||
num_flat_knots,
|
||||
index, Tindex, Pindex,
|
||||
coeff_index,
|
||||
inversion_problem,
|
||||
poles_index,
|
||||
num_poles ;
|
||||
Standard_Real normalized_value,
|
||||
*coefficient_array,
|
||||
*poles_array ;
|
||||
|
||||
num_flat_knots = 2 * myDegree + 2 ;
|
||||
for (ii=2; ii<myMults->Length(); ii++) {
|
||||
num_flat_knots += myMults->Value(ii);
|
||||
}
|
||||
num_poles = num_flat_knots - myDegree - 1 ;
|
||||
|
||||
myFlatKnots = new TColStd_HArray1OfReal(1,num_flat_knots) ;
|
||||
BSplCLib::KnotSequence (myKnots->Array1(),
|
||||
myMults->Array1(),
|
||||
myDegree,
|
||||
Standard_False,
|
||||
myFlatKnots->ChangeArray1());
|
||||
|
||||
TColStd_Array1OfReal parameters(1,num_poles) ;
|
||||
BSplCLib::BuildSchoenbergPoints(myDegree,
|
||||
myFlatKnots->Array1(),
|
||||
parameters) ;
|
||||
myPoles = new TColStd_HArray2OfReal(1, num_poles,
|
||||
1, Dimension) ;
|
||||
index = 2;
|
||||
Tindex = TrueIntervals.Lower()+1;
|
||||
Pindex = PolynomialIntervals.LowerRow();
|
||||
poles_array =
|
||||
(Standard_Real *) &(myPoles->ChangeArray2()).Value(1,1) ;
|
||||
|
||||
TColStd_Array1OfInteger contact_array(1,num_poles) ;
|
||||
|
||||
poles_index = 0 ;
|
||||
for (ii = 1 ; ii <= num_poles ; ii++, poles_index += Dimension) {
|
||||
contact_array.SetValue(ii,0) ;
|
||||
while (parameters.Value(ii) >= TrueIntervals(Tindex) &&
|
||||
index <= NumCurves) {
|
||||
index++; Tindex++; Pindex++;
|
||||
}
|
||||
//
|
||||
// normalized value so that it fits the original intervals for
|
||||
// the polynomial definition of the curves
|
||||
//
|
||||
normalized_value = parameters.Value(ii) - TrueIntervals(Tindex-1) ;
|
||||
normalized_value /= TrueIntervals(Tindex)
|
||||
- TrueIntervals(Tindex-1) ;
|
||||
normalized_value = (1.0e0 -normalized_value) *
|
||||
PolynomialIntervals(Pindex, PolynomialIntervals.LowerCol())
|
||||
+ normalized_value *
|
||||
PolynomialIntervals(Pindex, PolynomialIntervals.UpperCol()) ;
|
||||
coeff_index = ((index-2) * Dimension * (Max(MaxDegree, myDegree) + 1))
|
||||
+ Coefficients.Lower();
|
||||
|
||||
coefficient_array =
|
||||
(Standard_Real *) &(Coefficients(coeff_index)) ;
|
||||
Standard_Integer Deg = NumCoeffPerCurve(NumCoeffPerCurve.Lower()+index-2) - 1;
|
||||
|
||||
PLib::NoDerivativeEvalPolynomial
|
||||
(normalized_value,
|
||||
Deg,
|
||||
Dimension,
|
||||
Deg * Dimension,
|
||||
coefficient_array[0],
|
||||
poles_array[poles_index]) ;
|
||||
}
|
||||
//
|
||||
// interpolation at schoenberg points should yield the desired
|
||||
// result
|
||||
//
|
||||
BSplCLib::Interpolate(myDegree,
|
||||
myFlatKnots->Array1(),
|
||||
parameters,
|
||||
contact_array,
|
||||
Dimension,
|
||||
poles_array[0],
|
||||
inversion_problem) ;
|
||||
if (inversion_problem != 0) {
|
||||
Standard_ConstructionError::
|
||||
Raise("Convert_CompPolynomialToPoles:inversion_problem");
|
||||
}
|
||||
myDone = Standard_True ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbPoles
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_CompPolynomialToPoles::NbPoles() const
|
||||
{
|
||||
if (myDone) {
|
||||
return myPoles->ColLength() ;
|
||||
}
|
||||
else
|
||||
return 0 ;
|
||||
}
|
||||
//=======================================================================
|
||||
//function : Poles
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_CompPolynomialToPoles::Poles(
|
||||
Handle_TColStd_HArray2OfReal& P) const
|
||||
{ if (myDone) {
|
||||
P = myPoles ; }
|
||||
}
|
||||
//=======================================================================
|
||||
//function : NbKnots
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_CompPolynomialToPoles::NbKnots() const
|
||||
{
|
||||
if (myDone) {
|
||||
return myKnots->Length() ;
|
||||
}
|
||||
else
|
||||
return 0 ;
|
||||
}
|
||||
//=======================================================================
|
||||
//function : Knots
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_CompPolynomialToPoles::Knots(
|
||||
Handle_TColStd_HArray1OfReal& K) const
|
||||
{ if (myDone) {
|
||||
K = myKnots ; }
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Knots
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_CompPolynomialToPoles::Multiplicities(
|
||||
Handle_TColStd_HArray1OfInteger& M) const
|
||||
{ if (myDone) {
|
||||
M = myMults ; }
|
||||
}
|
||||
//=======================================================================
|
||||
//function : IsDone
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Convert_CompPolynomialToPoles::IsDone() const
|
||||
{ return myDone ; }
|
||||
//=======================================================================
|
||||
//function : IsDone
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_CompPolynomialToPoles::Degree() const
|
||||
{
|
||||
if (myDone) {
|
||||
return myDegree ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
53
src/Convert/Convert_ConeToBSplineSurface.cdl
Executable file
53
src/Convert/Convert_ConeToBSplineSurface.cdl
Executable file
@@ -0,0 +1,53 @@
|
||||
-- File: ConeToBSplineSurface.cdl
|
||||
-- Created: Thu Oct 10 15:39:30 1991
|
||||
-- Author: Jean Claude VAUTHIER
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
class ConeToBSplineSurface from Convert
|
||||
|
||||
--- Purpose :
|
||||
-- This algorithm converts a bounded Cone into a rational
|
||||
-- B-spline surface.
|
||||
-- The cone a Cone from package gp. Its parametrization is :
|
||||
-- P (U, V) = Loc + V * Zdir +
|
||||
-- (R + V*Tan(Ang)) * (Cos(U)*Xdir + Sin(U)*Ydir)
|
||||
-- where Loc is the location point of the cone, Xdir, Ydir and Zdir
|
||||
-- are the normalized directions of the local cartesian coordinate
|
||||
-- system of the cone (Zdir is the direction of the Cone's axis) ,
|
||||
-- Ang is the cone semi-angle. The U parametrization range is
|
||||
-- [0, 2PI].
|
||||
--- KeyWords :
|
||||
-- Convert, Cone, BSplineSurface.
|
||||
|
||||
inherits ElementarySurfaceToBSplineSurface
|
||||
|
||||
uses Cone from gp
|
||||
|
||||
raises DomainError from Standard
|
||||
|
||||
is
|
||||
|
||||
Create (C : Cone; U1, U2, V1, V2 : Real) returns ConeToBSplineSurface
|
||||
--- Purpose :
|
||||
-- The equivalent B-spline surface as the same orientation as the
|
||||
-- Cone in the U and V parametric directions.
|
||||
raises DomainError;
|
||||
--- Purpose :
|
||||
-- Raised if U1 = U2 or U1 = U2 + 2.0 * Pi
|
||||
-- Raised if V1 = V2.
|
||||
|
||||
|
||||
Create (C : Cone; V1, V2 : Real) returns ConeToBSplineSurface
|
||||
--- Purpose :
|
||||
-- The equivalent B-spline surface as the same orientation as the
|
||||
-- Cone in the U and V parametric directions.
|
||||
raises DomainError;
|
||||
--- Purpose :
|
||||
-- Raised if V1 = V2.
|
||||
|
||||
|
||||
|
||||
end ConeToBSplineSurface;
|
||||
|
||||
|
||||
|
188
src/Convert/Convert_ConeToBSplineSurface.cxx
Executable file
188
src/Convert/Convert_ConeToBSplineSurface.cxx
Executable file
@@ -0,0 +1,188 @@
|
||||
//File Convert_ConeToBSplineSurface.cxx
|
||||
//JCV 16/10/91
|
||||
|
||||
#include <Convert_ConeToBSplineSurface.ixx>
|
||||
|
||||
#include <gp.hxx>
|
||||
#include <gp_Trsf.hxx>
|
||||
|
||||
static const Standard_Integer TheUDegree = 2;
|
||||
static const Standard_Integer TheVDegree = 1;
|
||||
static const Standard_Integer TheNbUKnots = 5;
|
||||
static const Standard_Integer TheNbVKnots = 2;
|
||||
static const Standard_Integer TheNbUPoles = 9;
|
||||
static const Standard_Integer TheNbVPoles = 2;
|
||||
|
||||
|
||||
static void ComputePoles( const Standard_Real R,
|
||||
const Standard_Real A,
|
||||
const Standard_Real U1,
|
||||
const Standard_Real U2,
|
||||
const Standard_Real V1,
|
||||
const Standard_Real V2,
|
||||
TColgp_Array2OfPnt& Poles)
|
||||
{
|
||||
Standard_Real deltaU = U2 - U1;
|
||||
|
||||
Standard_Integer i;
|
||||
|
||||
// Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds)
|
||||
Standard_Integer
|
||||
nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
|
||||
Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
|
||||
|
||||
Standard_Real x[TheNbVPoles];
|
||||
Standard_Real z[TheNbVPoles];
|
||||
|
||||
x[0] = R + V1 * Sin(A);
|
||||
z[0] = V1 * Cos(A);
|
||||
x[1] = R + V2 * Sin(A);
|
||||
z[1] = V2 * Cos(A);
|
||||
|
||||
Standard_Real UStart = U1;
|
||||
Poles(1,1) = gp_Pnt(x[0]*Cos(UStart),x[0]*Sin(UStart),z[0]);
|
||||
Poles(1,2) = gp_Pnt(x[1]*Cos(UStart),x[1]*Sin(UStart),z[1]);
|
||||
|
||||
for ( i = 1; i <= nbUSpans; i++) {
|
||||
Poles( 2*i, 1) = gp_Pnt( x[0] * Cos(UStart+AlfaU) / Cos(AlfaU),
|
||||
x[0] * Sin(UStart+AlfaU) / Cos(AlfaU),
|
||||
z[0] );
|
||||
Poles( 2*i, 2) = gp_Pnt( x[1] * Cos(UStart+AlfaU) / Cos(AlfaU),
|
||||
x[1] * Sin(UStart+AlfaU) / Cos(AlfaU),
|
||||
z[1] );
|
||||
Poles(2*i+1,1) = gp_Pnt( x[0] * Cos(UStart+2*AlfaU),
|
||||
x[0] * Sin(UStart+2*AlfaU),
|
||||
z[0] );
|
||||
Poles(2*i+1,2) = gp_Pnt( x[1] * Cos(UStart+2*AlfaU),
|
||||
x[1] * Sin(UStart+2*AlfaU),
|
||||
z[1] );
|
||||
UStart += 2*AlfaU;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_ConeToBSplineSurface
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_ConeToBSplineSurface::Convert_ConeToBSplineSurface
|
||||
(const gp_Cone& C ,
|
||||
const Standard_Real U1,
|
||||
const Standard_Real U2,
|
||||
const Standard_Real V1,
|
||||
const Standard_Real V2 )
|
||||
: Convert_ElementarySurfaceToBSplineSurface (TheNbUPoles, TheNbVPoles,
|
||||
TheNbUKnots, TheNbVKnots,
|
||||
TheUDegree , TheVDegree )
|
||||
{
|
||||
Standard_Real deltaU = U2 - U1;
|
||||
Standard_DomainError_Raise_if( (Abs(V2-V1) <= Abs(Epsilon(V1))) ||
|
||||
(deltaU > 2*PI) ||
|
||||
(deltaU < 0. ),
|
||||
"Convert_ConeToBSplineSurface");
|
||||
|
||||
isuperiodic = Standard_False;
|
||||
isvperiodic = Standard_False;
|
||||
|
||||
Standard_Integer i,j;
|
||||
// construction du cone dans le repere de reference xOy.
|
||||
|
||||
// Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds)
|
||||
Standard_Integer
|
||||
nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
|
||||
Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
|
||||
|
||||
nbUPoles = 2 * nbUSpans + 1;
|
||||
nbUKnots = nbUSpans + 1;
|
||||
|
||||
nbVPoles = 2;
|
||||
nbVKnots = 2;
|
||||
|
||||
Standard_Real R = C.RefRadius();
|
||||
Standard_Real A = C.SemiAngle();
|
||||
|
||||
ComputePoles( R, A, U1, U2, V1, V2, poles);
|
||||
|
||||
for ( i = 1; i<= nbUKnots; i++) {
|
||||
uknots(i) = U1 + (i-1) * 2 * AlfaU;
|
||||
umults(i) = 2;
|
||||
}
|
||||
umults(1)++; umults(nbUKnots)++;
|
||||
vknots(1) = V1; vmults(1) = 2;
|
||||
vknots(2) = V2; vmults(2) = 2;
|
||||
|
||||
// On replace la bspline dans le repere de la sphere.
|
||||
// et on calcule les poids de la bspline.
|
||||
Standard_Real W1;
|
||||
gp_Trsf Trsf;
|
||||
Trsf.SetTransformation( C.Position(), gp::XOY());
|
||||
|
||||
for ( i = 1; i <= nbUPoles; i++) {
|
||||
if ( i % 2 == 0) W1 = Cos(AlfaU);
|
||||
else W1 = 1.;
|
||||
|
||||
for ( j = 1; j <= nbVPoles; j++) {
|
||||
weights( i, j) = W1;
|
||||
poles( i, j).Transform( Trsf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_ConeToBSplineSurface
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_ConeToBSplineSurface::Convert_ConeToBSplineSurface
|
||||
(const gp_Cone& C ,
|
||||
const Standard_Real V1,
|
||||
const Standard_Real V2 )
|
||||
: Convert_ElementarySurfaceToBSplineSurface (TheNbUPoles, TheNbVPoles,
|
||||
TheNbUKnots, TheNbVKnots,
|
||||
TheUDegree, TheVDegree)
|
||||
{
|
||||
Standard_DomainError_Raise_if( Abs(V2-V1) <= Abs(Epsilon(V1)),
|
||||
"Convert_ConeToBSplineSurface");
|
||||
|
||||
Standard_Integer i,j;
|
||||
|
||||
isuperiodic = Standard_True;
|
||||
isvperiodic = Standard_False;
|
||||
|
||||
// construction du cone dans le repere de reference xOy.
|
||||
|
||||
Standard_Real R = C.RefRadius();
|
||||
Standard_Real A = C.SemiAngle();
|
||||
|
||||
ComputePoles( R, A, 0., 2.*PI, V1, V2, poles);
|
||||
|
||||
nbUPoles = 6;
|
||||
nbUKnots = 4;
|
||||
nbVPoles = 2;
|
||||
nbVKnots = 2;
|
||||
|
||||
for ( i = 1; i <= nbUKnots; i++) {
|
||||
uknots(i) = ( i-1) * 2. * PI /3.;
|
||||
umults(i) = 2;
|
||||
}
|
||||
vknots(1) = V1; vmults(1) = 2;
|
||||
vknots(2) = V2; vmults(2) = 2;
|
||||
|
||||
// On replace la bspline dans le repere du cone.
|
||||
// et on calcule les poids de la bspline.
|
||||
Standard_Real W;
|
||||
gp_Trsf Trsf;
|
||||
Trsf.SetTransformation( C.Position(), gp::XOY());
|
||||
|
||||
for ( i = 1; i <= nbUPoles; i++) {
|
||||
if ( i % 2 == 0) W = 0.5; // = Cos(pi /3)
|
||||
else W = 1.;
|
||||
|
||||
for ( j = 1; j <= nbVPoles; j++) {
|
||||
weights( i, j) = W;
|
||||
poles( i, j).Transform( Trsf);
|
||||
}
|
||||
}
|
||||
}
|
165
src/Convert/Convert_ConicToBSplineCurve.cdl
Executable file
165
src/Convert/Convert_ConicToBSplineCurve.cdl
Executable file
@@ -0,0 +1,165 @@
|
||||
-- File: ConicToBSplineCurve.cdl
|
||||
-- Created: Thu Oct 10 11:26:44 1991
|
||||
-- Author: Jean Claude VAUTHIER
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
deferred class ConicToBSplineCurve from Convert
|
||||
|
||||
---Purpose: Root class for algorithms which convert a conic curve into
|
||||
-- a BSpline curve (CircleToBSplineCurve, EllipseToBSplineCurve,
|
||||
-- HyperbolaToBSplineCurve, ParabolaToBSplineCurve).
|
||||
-- These algorithms all work on 2D curves from the gp
|
||||
-- package and compute all the data needed to construct a
|
||||
-- BSpline curve equivalent to the conic curve. This data consists of:
|
||||
-- - the degree of the curve,
|
||||
-- - the periodic characteristics of the curve,
|
||||
-- - a poles table with associated weights,
|
||||
-- - a knots table with associated multiplicities.
|
||||
-- The abstract class ConicToBSplineCurve provides a
|
||||
-- framework for storing and consulting this computed data.
|
||||
-- The data may then be used to construct a
|
||||
-- Geom2d_BSplineCurve curvSuper class of the following classes :
|
||||
-- This abstract class implements the methods to get the geometric
|
||||
-- representation of the B-spline curve equivalent to the conic.
|
||||
-- The B-spline is computed at the creation time in the sub classes.
|
||||
-- The B-spline curve is defined with its degree, its control points
|
||||
-- (Poles), its weights, its knots and their multiplicity.
|
||||
-- All the geometric entities used in this package are defined in 2D
|
||||
-- space.
|
||||
-- KeyWords :
|
||||
-- Convert, Conic, BSplineCurve, 2D.
|
||||
|
||||
uses Array1OfInteger from TColStd,
|
||||
Array1OfReal from TColStd,
|
||||
HArray1OfInteger from TColStd,
|
||||
HArray1OfReal from TColStd,
|
||||
HArray1OfPnt2d from TColgp,
|
||||
ParameterisationType from Convert,
|
||||
Pnt2d from gp
|
||||
|
||||
|
||||
raises OutOfRange from Standard,
|
||||
ConstructionError from Standard
|
||||
|
||||
|
||||
is
|
||||
|
||||
Degree (me) returns Integer is static;
|
||||
---Purpose: Returns the degree of the BSpline curve whose data is
|
||||
-- computed in this framework.
|
||||
|
||||
NbPoles (me) returns Integer is static;
|
||||
---Purpose: Returns the number of poles of the BSpline curve whose
|
||||
-- data is computed in this framework.
|
||||
|
||||
NbKnots (me) returns Integer is static;
|
||||
---Purpose: Returns the number of knots of the BSpline curve whose
|
||||
-- data is computed in this framework.
|
||||
|
||||
IsPeriodic(me) returns Boolean is static;
|
||||
--- Purpose: Returns true if the BSpline curve whose data is computed in
|
||||
-- this framework is periodic.
|
||||
|
||||
Pole (me; Index : Integer) returns Pnt2d
|
||||
--- Purpose : Returns the pole of index Index to the poles table of the
|
||||
-- BSpline curve whose data is computed in this framework.
|
||||
-- Exceptions
|
||||
-- Standard_OutOfRange if Index is outside the bounds of
|
||||
-- the poles table of the BSpline curve whose data is computed in this framework.
|
||||
raises OutOfRange
|
||||
is static;
|
||||
|
||||
|
||||
Weight (me; Index : Integer) returns Real
|
||||
--- Purpose : Returns the weight of the pole of index Index to the poles
|
||||
-- table of the BSpline curve whose data is computed in this framework.
|
||||
-- Exceptions
|
||||
-- Standard_OutOfRange if Index is outside the bounds of
|
||||
-- the poles table of the BSpline curve whose data is computed in this framework.
|
||||
raises OutOfRange
|
||||
is static;
|
||||
|
||||
|
||||
Knot (me; Index : Integer) returns Real
|
||||
--- Purpose : Returns the knot of index Index to the knots table of the
|
||||
-- BSpline curve whose data is computed in this framework.
|
||||
-- Exceptions
|
||||
-- Standard_OutOfRange if Index is outside the bounds of
|
||||
-- the knots table of the BSpline curve whose data is computed in this framework.
|
||||
raises OutOfRange
|
||||
is static;
|
||||
|
||||
|
||||
Multiplicity (me; Index : Integer) returns Integer
|
||||
--- Purpose : Returns the multiplicity of the knot of index Index to the
|
||||
-- knots table of the BSpline curve whose data is computed in this framework.
|
||||
-- Exceptions
|
||||
-- Standard_OutOfRange if Index is outside the bounds of
|
||||
-- the knots table of the BSpline curve whose data is computed in this framework.
|
||||
raises OutOfRange
|
||||
is static;
|
||||
|
||||
|
||||
Initialize (NumberOfPoles, NumberOfKnots, Degree : Integer);
|
||||
|
||||
BuildCosAndSin(me ;
|
||||
Parametrisation : ParameterisationType from Convert ;
|
||||
--
|
||||
-- allowed parameterisation are TgtThetaOver2 and RationalC1
|
||||
-- will raise otherwise
|
||||
CosNumerator : in out HArray1OfReal from TColStd ;
|
||||
-- Array has the following dimensions :
|
||||
-- <1, NbPoles> without multiplying by the weights
|
||||
|
||||
SinNumerator : in out HArray1OfReal from TColStd ;
|
||||
-- Array has the following dimensions :
|
||||
-- <1, NbPoles> without multiplying by the weights
|
||||
Denominator : in out HArray1OfReal from TColStd ;
|
||||
-- Array has the following dimension
|
||||
-- <1, NbPoles>
|
||||
Degree : in out Integer from Standard ;
|
||||
Knots : in out HArray1OfReal from TColStd ;
|
||||
Mults : in out HArray1OfInteger from TColStd)
|
||||
raises ConstructionError
|
||||
-- see above
|
||||
is static ;
|
||||
-- builds a full periodic circle
|
||||
--
|
||||
BuildCosAndSin(me;
|
||||
Parametrisation : ParameterisationType from Convert ;
|
||||
UFirst : Real from Standard ;
|
||||
ULast : Real from Standard ;
|
||||
CosNumerator : in out HArray1OfReal from TColStd ;
|
||||
-- Array has the following dimensions :
|
||||
-- <1, NbPoles> without multiplying by the weights
|
||||
|
||||
SinNumerator : in out HArray1OfReal from TColStd ;
|
||||
-- Array has the following dimensions :
|
||||
-- <1, NbPoles> without multiplying by the weights
|
||||
Denominator : in out HArray1OfReal from TColStd ;
|
||||
-- Array has the following dimension
|
||||
-- <1, NbPoles>
|
||||
Degree : in out Integer from Standard ;
|
||||
Knots : in out HArray1OfReal from TColStd ;
|
||||
Mults : in out HArray1OfInteger from TColStd)
|
||||
raises ConstructionError
|
||||
is static ;
|
||||
|
||||
fields
|
||||
|
||||
poles : HArray1OfPnt2d is protected;
|
||||
weights : HArray1OfReal is protected;
|
||||
knots : HArray1OfReal is protected;
|
||||
mults : HArray1OfInteger is protected;
|
||||
degree : Integer is protected;
|
||||
nbPoles : Integer is protected;
|
||||
nbKnots : Integer is protected;
|
||||
isperiodic : Boolean is protected;
|
||||
|
||||
end ConicToBSplineCurve;
|
||||
|
||||
|
772
src/Convert/Convert_ConicToBSplineCurve.cxx
Executable file
772
src/Convert/Convert_ConicToBSplineCurve.cxx
Executable file
@@ -0,0 +1,772 @@
|
||||
//File Convert_ConicToBSplineCurve.cxx
|
||||
//JCV 16/10/91
|
||||
|
||||
#define No_Standard_OutOfRange
|
||||
|
||||
#include <Convert_ConicToBSplineCurve.ixx>
|
||||
#include <Convert_CosAndSinEvalFunction.hxx>
|
||||
#include <Convert_PolynomialCosAndSin.hxx>
|
||||
#include <TColStd_Array1OfReal.hxx>
|
||||
#include <TColStd_Array1OfInteger.hxx>
|
||||
#include <TColgp_Array1OfPnt2d.hxx>
|
||||
#include <TColgp_Array1OfPnt.hxx>
|
||||
#include <TColStd_HArray1OfReal.hxx>
|
||||
#include <TColStd_Array1OfReal.hxx>
|
||||
#include <TColStd_HArray1OfInteger.hxx>
|
||||
#include <TColgp_HArray1OfPnt2d.hxx>
|
||||
|
||||
#include <PLib.hxx>
|
||||
#include <BSplCLib.hxx>
|
||||
#include <Precision.hxx>
|
||||
#include <gp.hxx>
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
#include <Standard_ConstructionError.hxx>
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_ConicToBSplineCurve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_ConicToBSplineCurve::Convert_ConicToBSplineCurve
|
||||
(const Standard_Integer NbPoles,
|
||||
const Standard_Integer NbKnots,
|
||||
const Standard_Integer Degree )
|
||||
: degree (Degree) , nbPoles (NbPoles) , nbKnots (NbKnots)
|
||||
|
||||
{
|
||||
if (NbPoles >= 2) {
|
||||
poles = new TColgp_HArray1OfPnt2d (1, NbPoles) ;
|
||||
|
||||
weights = new TColStd_HArray1OfReal (1, NbPoles) ;
|
||||
}
|
||||
if (NbKnots >= 2) {
|
||||
knots = new TColStd_HArray1OfReal (1, NbKnots) ;
|
||||
mults = new TColStd_HArray1OfInteger(1,NbKnots) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Degree
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_ConicToBSplineCurve::Degree () const
|
||||
{
|
||||
return degree;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NbPoles
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_ConicToBSplineCurve::NbPoles () const
|
||||
{
|
||||
return nbPoles;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : NbKnots
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_ConicToBSplineCurve::NbKnots () const
|
||||
{
|
||||
return nbKnots;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsPeriodic
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Convert_ConicToBSplineCurve::IsPeriodic() const
|
||||
{
|
||||
return isperiodic;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Pole
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
gp_Pnt2d Convert_ConicToBSplineCurve::Pole
|
||||
(const Standard_Integer Index) const
|
||||
{
|
||||
if (Index < 1 || Index > nbPoles)
|
||||
Standard_OutOfRange::Raise(" ");
|
||||
return poles->Value (Index);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Weight
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Real Convert_ConicToBSplineCurve::Weight
|
||||
(const Standard_Integer Index) const
|
||||
{
|
||||
if (Index < 1 || Index > nbPoles)
|
||||
Standard_OutOfRange::Raise(" ");
|
||||
return weights->Value (Index);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Knot
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Real Convert_ConicToBSplineCurve::Knot
|
||||
(const Standard_Integer Index) const
|
||||
{
|
||||
if (Index < 1 || Index > nbKnots)
|
||||
Standard_OutOfRange::Raise(" ");
|
||||
return knots->Value (Index);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Multiplicity
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_ConicToBSplineCurve::Multiplicity
|
||||
(const Standard_Integer Index) const
|
||||
{
|
||||
if (Index < 1 || Index > nbKnots)
|
||||
Standard_OutOfRange::Raise(" ");
|
||||
return mults->Value (Index);
|
||||
}
|
||||
//=======================================================================
|
||||
//function : CosAndSinRationalC1
|
||||
//purpose : evaluates U(t) and V(t) such that
|
||||
// 2 2
|
||||
// U - V
|
||||
// cos (theta(t)) = ----------
|
||||
// 2 2
|
||||
// U + V
|
||||
//
|
||||
|
||||
// 2 * U*V
|
||||
// sin (theta(t)) = ----------
|
||||
// 2 2
|
||||
// U + V
|
||||
// 2 2
|
||||
// such that the derivative at the domain bounds of U + V is 0.0e0
|
||||
// with is helpfull when having to make a C1 BSpline by merging two
|
||||
// BSpline toghether
|
||||
//=======================================================================
|
||||
|
||||
void CosAndSinRationalC1(Standard_Real Parameter,
|
||||
const Standard_Integer EvalDegree,
|
||||
const TColgp_Array1OfPnt2d& EvalPoles,
|
||||
const TColStd_Array1OfReal& EvalKnots,
|
||||
const TColStd_Array1OfInteger& EvalMults,
|
||||
Standard_Real Result[2])
|
||||
{
|
||||
gp_Pnt2d a_point ;
|
||||
BSplCLib::D0(Parameter,
|
||||
0,
|
||||
EvalDegree,
|
||||
Standard_False,
|
||||
EvalPoles,
|
||||
BSplCLib::NoWeights(),
|
||||
EvalKnots,
|
||||
EvalMults,
|
||||
a_point) ;
|
||||
Result[0] = a_point.Coord(1) ;
|
||||
Result[1] = a_point.Coord(2) ;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : CosAndSinQuasiAngular
|
||||
//purpose : evaluates U(t) and V(t) such that
|
||||
// 2 2
|
||||
// U - V
|
||||
// cos (theta(t)) = ----------
|
||||
// 2 2
|
||||
// U + V
|
||||
//
|
||||
|
||||
// 2 * U*V
|
||||
// sin (theta(t)) = ----------
|
||||
// 2 2
|
||||
// U + V
|
||||
//=======================================================================
|
||||
|
||||
void CosAndSinQuasiAngular(Standard_Real Parameter,
|
||||
const Standard_Integer EvalDegree,
|
||||
const TColgp_Array1OfPnt2d& EvalPoles,
|
||||
// const TColStd_Array1OfReal& EvalKnots,
|
||||
const TColStd_Array1OfReal& ,
|
||||
// const TColStd_Array1OfInteger& EvalMults,
|
||||
const TColStd_Array1OfInteger& ,
|
||||
Standard_Real Result[2])
|
||||
{
|
||||
Standard_Real
|
||||
param,
|
||||
*coeff ;
|
||||
|
||||
coeff = (Standard_Real *) &EvalPoles(EvalPoles.Lower()) ;
|
||||
//
|
||||
// rational_function_coeff represent a rational approximation
|
||||
// of U ---> cotan( PI * U /2) between [0 1]
|
||||
// rational_function_coeff[i][0] is the denominator
|
||||
// rational_function_coeff[i][1] is the numerator
|
||||
//
|
||||
param = Parameter * 0.5e0 ;
|
||||
PLib::NoDerivativeEvalPolynomial (param,
|
||||
EvalDegree,
|
||||
2,
|
||||
EvalDegree << 1,
|
||||
coeff[0],
|
||||
Result[0]) ;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : function that build the Bspline Representation of
|
||||
// an algorithmic description of the function cos and sin
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
void AlgorithmicCosAndSin(Standard_Integer Degree,
|
||||
const TColStd_Array1OfReal& FlatKnots,
|
||||
const Standard_Integer EvalDegree,
|
||||
const TColgp_Array1OfPnt2d& EvalPoles,
|
||||
const TColStd_Array1OfReal& EvalKnots,
|
||||
const TColStd_Array1OfInteger& EvalMults,
|
||||
Convert_CosAndSinEvalFunction Evaluator,
|
||||
TColStd_Array1OfReal& CosNumerator,
|
||||
TColStd_Array1OfReal& SinNumerator,
|
||||
TColStd_Array1OfReal& Denominator)
|
||||
{
|
||||
Standard_Integer order,
|
||||
num_poles,
|
||||
pivot_index_problem,
|
||||
ii;
|
||||
|
||||
Standard_Real result[2],
|
||||
inverse ;
|
||||
|
||||
order = Degree + 1 ;
|
||||
num_poles = FlatKnots.Length() - order ;
|
||||
|
||||
if (num_poles != CosNumerator.Length() ||
|
||||
num_poles != SinNumerator.Length() ||
|
||||
num_poles != Denominator.Length() ) {
|
||||
Standard_ConstructionError::Raise();
|
||||
}
|
||||
TColStd_Array1OfReal parameters(1,num_poles) ;
|
||||
TColgp_Array1OfPnt poles_array(1,num_poles) ;
|
||||
TColStd_Array1OfInteger contact_order_array(1,num_poles) ;
|
||||
BSplCLib::BuildSchoenbergPoints(Degree,
|
||||
FlatKnots,
|
||||
parameters) ;
|
||||
for (ii = parameters.Lower() ; ii <= parameters.Upper() ; ii++) {
|
||||
Evaluator(parameters(ii),
|
||||
EvalDegree,
|
||||
EvalPoles,
|
||||
EvalKnots,
|
||||
EvalMults,
|
||||
result) ;
|
||||
contact_order_array(ii) = 0 ;
|
||||
|
||||
poles_array(ii).SetCoord(1,
|
||||
(result[1]*result[1] - result[0]*result[0]));
|
||||
poles_array(ii).SetCoord(2,
|
||||
2.0e0 * result[1]* result[0]) ;
|
||||
poles_array(ii).SetCoord(3,
|
||||
result[1]*result[1] + result[0] * result[0]) ;
|
||||
}
|
||||
BSplCLib::Interpolate(Degree,
|
||||
FlatKnots,
|
||||
parameters,
|
||||
contact_order_array,
|
||||
poles_array,
|
||||
pivot_index_problem) ;
|
||||
for (ii = 1 ; ii <= num_poles ; ii++) {
|
||||
inverse = 1.0e0 / poles_array(ii).Coord(3) ;
|
||||
CosNumerator(ii) = poles_array(ii).Coord(1) * inverse ;
|
||||
SinNumerator(ii) = poles_array(ii).Coord(2) * inverse ;
|
||||
Denominator(ii) = poles_array(ii).Coord(3) ;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : BuildCosAndSin
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_ConicToBSplineCurve::BuildCosAndSin(
|
||||
const Convert_ParameterisationType Parameterisation,
|
||||
const Standard_Real UFirst,
|
||||
const Standard_Real ULast,
|
||||
Handle(TColStd_HArray1OfReal)& CosNumeratorPtr,
|
||||
Handle(TColStd_HArray1OfReal)& SinNumeratorPtr,
|
||||
Handle(TColStd_HArray1OfReal)& DenominatorPtr,
|
||||
Standard_Integer& Degree,
|
||||
Handle(TColStd_HArray1OfReal)& KnotsPtr,
|
||||
Handle(TColStd_HArray1OfInteger)& MultsPtr) const
|
||||
{
|
||||
Standard_Real delta = ULast - UFirst,
|
||||
direct,
|
||||
inverse,
|
||||
value1,
|
||||
value2,
|
||||
cos_beta,
|
||||
sin_beta,
|
||||
alpha=0,
|
||||
alpha_2,
|
||||
alpha_4,
|
||||
tan_alpha_2,
|
||||
beta,
|
||||
p_param,
|
||||
q_param,
|
||||
param ;
|
||||
|
||||
Standard_Integer num_poles,
|
||||
ii,
|
||||
jj,
|
||||
num_knots=0,
|
||||
num_spans=0,
|
||||
num_flat_knots,
|
||||
num_temp_knots,
|
||||
temp_degree=0,
|
||||
tgt_theta_flag,
|
||||
num_temp_poles,
|
||||
order ;
|
||||
|
||||
Convert_CosAndSinEvalFunction *EvaluatorPtr=NULL ;
|
||||
|
||||
tgt_theta_flag = 0 ;
|
||||
|
||||
|
||||
switch (Parameterisation) {
|
||||
case Convert_TgtThetaOver2:
|
||||
num_spans =
|
||||
(Standard_Integer)IntegerPart( 1.2 * delta / PI) + 1;
|
||||
|
||||
tgt_theta_flag = 1 ;
|
||||
break ;
|
||||
case Convert_TgtThetaOver2_1:
|
||||
num_spans = 1 ;
|
||||
if (delta > 0.9999 * PI) {
|
||||
Standard_ConstructionError::Raise() ;
|
||||
}
|
||||
tgt_theta_flag = 1 ;
|
||||
break ;
|
||||
case Convert_TgtThetaOver2_2:
|
||||
num_spans = 2 ;
|
||||
if (delta > 1.9999 * PI) {
|
||||
Standard_ConstructionError::Raise() ;
|
||||
}
|
||||
tgt_theta_flag = 1 ;
|
||||
break ;
|
||||
|
||||
case Convert_TgtThetaOver2_3:
|
||||
num_spans = 3 ;
|
||||
tgt_theta_flag = 1 ;
|
||||
break ;
|
||||
case Convert_TgtThetaOver2_4:
|
||||
num_spans = 4 ;
|
||||
tgt_theta_flag = 1 ;
|
||||
break ;
|
||||
case Convert_QuasiAngular:
|
||||
num_poles = 7 ;
|
||||
Degree = 6 ;
|
||||
num_spans = 1 ;
|
||||
num_knots = 2 ;
|
||||
order = Degree + 1 ;
|
||||
break ;
|
||||
case Convert_RationalC1:
|
||||
Degree = 4 ;
|
||||
order = Degree + 1 ;
|
||||
num_poles = 8 ;
|
||||
num_knots = 3 ;
|
||||
num_spans = 2 ;
|
||||
break ;
|
||||
case Convert_Polynomial:
|
||||
Degree = 7 ;
|
||||
num_poles = 8 ;
|
||||
num_knots = 2 ;
|
||||
num_spans = 1 ;
|
||||
break ;
|
||||
default:
|
||||
break ;
|
||||
}
|
||||
if (tgt_theta_flag) {
|
||||
alpha = delta / ( 2.0e0 * num_spans) ;
|
||||
Degree = 2 ;
|
||||
num_poles = 2 * num_spans + 1;
|
||||
}
|
||||
|
||||
CosNumeratorPtr =
|
||||
new TColStd_HArray1OfReal(1,num_poles) ;
|
||||
SinNumeratorPtr =
|
||||
new TColStd_HArray1OfReal(1,num_poles) ;
|
||||
DenominatorPtr =
|
||||
new TColStd_HArray1OfReal(1,num_poles) ;
|
||||
KnotsPtr =
|
||||
new TColStd_HArray1OfReal(1,num_spans+1) ;
|
||||
MultsPtr =
|
||||
new TColStd_HArray1OfInteger(1,num_spans+1) ;
|
||||
if (tgt_theta_flag) {
|
||||
|
||||
param = UFirst ;
|
||||
CosNumeratorPtr->SetValue(1,Cos(UFirst)) ;
|
||||
SinNumeratorPtr->SetValue(1,Sin(UFirst)) ;
|
||||
DenominatorPtr ->SetValue(1,1.0e0) ;
|
||||
KnotsPtr->SetValue(1,param) ;
|
||||
MultsPtr->SetValue(1,Degree + 1) ;
|
||||
direct = Cos(alpha) ;
|
||||
inverse = 1.0e0 / direct ;
|
||||
for (ii = 1 ; ii <= num_spans ; ii++ ) {
|
||||
CosNumeratorPtr->SetValue(2 * ii, inverse * Cos(param + alpha)) ;
|
||||
SinNumeratorPtr->SetValue(2 * ii, inverse * Sin(param + alpha)) ;
|
||||
DenominatorPtr->SetValue(2 * ii, direct) ;
|
||||
CosNumeratorPtr->SetValue(2 * ii + 1, Cos(param + 2 * alpha)) ;
|
||||
SinNumeratorPtr->SetValue(2 * ii + 1, Sin(param + 2 * alpha)) ;
|
||||
DenominatorPtr->SetValue(2 * ii + 1, 1.0e0) ;
|
||||
KnotsPtr->SetValue(ii + 1, param + 2 * alpha) ;
|
||||
MultsPtr->SetValue(ii + 1, 2) ;
|
||||
param += 2 * alpha ;
|
||||
}
|
||||
MultsPtr->SetValue(num_spans + 1, Degree + 1) ;
|
||||
}
|
||||
else if (Parameterisation != Convert_Polynomial) {
|
||||
alpha = ULast - UFirst ;
|
||||
alpha *= 0.5e0 ;
|
||||
beta = ULast + UFirst ;
|
||||
beta *= 0.5e0 ;
|
||||
cos_beta = Cos(beta) ;
|
||||
sin_beta = Sin(beta) ;
|
||||
num_flat_knots = num_poles + order ;
|
||||
|
||||
num_temp_poles = 4 ;
|
||||
num_temp_knots = 3 ;
|
||||
TColStd_Array1OfReal flat_knots(1, num_flat_knots) ;
|
||||
|
||||
|
||||
TColgp_Array1OfPnt2d temp_poles(1,num_temp_poles) ;
|
||||
TColStd_Array1OfReal temp_knots(1,num_temp_knots) ;
|
||||
TColStd_Array1OfInteger temp_mults(1,num_temp_knots) ;
|
||||
|
||||
for (ii = 1 ; ii <= order ; ii++) {
|
||||
flat_knots(ii) = -alpha ;
|
||||
flat_knots(ii + num_poles) = alpha ;
|
||||
}
|
||||
KnotsPtr->SetValue(1,UFirst) ;
|
||||
KnotsPtr->SetValue(num_knots, ULast) ;
|
||||
MultsPtr->SetValue(1,order) ;
|
||||
MultsPtr->SetValue(num_knots,order) ;
|
||||
|
||||
switch (Parameterisation) {
|
||||
case Convert_QuasiAngular:
|
||||
//
|
||||
// we code here in temp_poles(xx).Coord(1) the following function V(t)
|
||||
// and in temp_poles(xx).Coord(2) the function U(t)
|
||||
// 3
|
||||
// V(t) = t + c t
|
||||
// 2
|
||||
// U(t) = 1 + b t
|
||||
// 1
|
||||
// c = --- + b = q_param
|
||||
// 3
|
||||
// 3
|
||||
// gamma
|
||||
// gamma + ------ - tang gamma
|
||||
// 3
|
||||
// b =------------------------------ = p_param
|
||||
// 2
|
||||
// gamma (tang gamma - gamma)
|
||||
//
|
||||
// with gamma = alpha / 2
|
||||
//
|
||||
//
|
||||
|
||||
alpha_2 = alpha * 0.5e0 ;
|
||||
p_param = - 1.0e0 / (alpha_2 * alpha_2) ;
|
||||
|
||||
if (alpha_2 < PI * 0.5e0) {
|
||||
tan_alpha_2 = Tan(alpha_2) ;
|
||||
value1 = 3.0e0 * (tan_alpha_2 - alpha_2) ;
|
||||
value1 = alpha_2 / value1 ;
|
||||
p_param += value1 ;
|
||||
}
|
||||
q_param = (1.0e0 / 3.0e0) + p_param ;
|
||||
|
||||
|
||||
temp_degree = 3 ;
|
||||
temp_poles(1).SetCoord(1,0.0e0);
|
||||
temp_poles(2).SetCoord(1,1.0e0);
|
||||
temp_poles(3).SetCoord(1,0.0e0) ;
|
||||
temp_poles(4).SetCoord(1,q_param) ;
|
||||
|
||||
temp_poles(1).SetCoord(2, 1.0e0) ;
|
||||
temp_poles(2).SetCoord(2, 0.0e0) ;
|
||||
temp_poles(3).SetCoord(2, p_param) ;
|
||||
temp_poles(4).SetCoord(2, 0.0e0);
|
||||
EvaluatorPtr = &CosAndSinQuasiAngular ;
|
||||
break ;
|
||||
case Convert_RationalC1:
|
||||
for (ii = order + 1 ; ii <= num_poles ; ii++) {
|
||||
flat_knots(ii) = 0.0e0 ;
|
||||
}
|
||||
KnotsPtr->SetValue(2,UFirst + alpha) ;
|
||||
MultsPtr->SetValue(2,Degree -1) ;
|
||||
temp_degree = 2 ;
|
||||
alpha_2 = alpha * 0.5e0 ;
|
||||
alpha_4 = alpha * 0.25e0 ;
|
||||
tan_alpha_2 = Tan(alpha_2) ;
|
||||
jj = 1 ;
|
||||
for (ii = 1 ; ii <= 2 ; ii++) {
|
||||
temp_poles(1+ ii).SetCoord(2,1.0e0 + alpha_4 * tan_alpha_2) ;
|
||||
temp_poles(jj).SetCoord(2,1.e0) ;
|
||||
jj += 3 ;
|
||||
}
|
||||
temp_poles(1).SetCoord(1,-tan_alpha_2) ;
|
||||
temp_poles(2).SetCoord(1,alpha_4 - tan_alpha_2) ;
|
||||
temp_poles(3).SetCoord(1,-alpha_4 + tan_alpha_2) ;
|
||||
temp_poles(4).SetCoord(1,tan_alpha_2) ;
|
||||
temp_knots(1) = -alpha ;
|
||||
temp_knots(2) = 0.0e0 ;
|
||||
temp_knots(3) = alpha ;
|
||||
temp_mults(1) = temp_degree + 1;
|
||||
temp_mults(2) = 1 ;
|
||||
temp_mults(3) = temp_degree + 1;
|
||||
|
||||
EvaluatorPtr = &CosAndSinRationalC1 ;
|
||||
break ;
|
||||
default:
|
||||
break ;
|
||||
}
|
||||
AlgorithmicCosAndSin(Degree,
|
||||
flat_knots,
|
||||
temp_degree,
|
||||
temp_poles,
|
||||
temp_knots,
|
||||
temp_mults,
|
||||
*EvaluatorPtr,
|
||||
CosNumeratorPtr->ChangeArray1(),
|
||||
SinNumeratorPtr->ChangeArray1(),
|
||||
DenominatorPtr->ChangeArray1()) ;
|
||||
|
||||
for (ii = 1 ; ii <= num_poles ; ii++) {
|
||||
value1 = cos_beta * CosNumeratorPtr->Value(ii) -
|
||||
sin_beta * SinNumeratorPtr->Value(ii) ;
|
||||
value2 = sin_beta * CosNumeratorPtr->Value(ii) +
|
||||
cos_beta * SinNumeratorPtr->Value(ii) ;
|
||||
CosNumeratorPtr->SetValue(ii,value1) ;
|
||||
SinNumeratorPtr->SetValue(ii,value2) ;
|
||||
}
|
||||
}
|
||||
else { // Convert_Polynomial
|
||||
|
||||
KnotsPtr->SetValue(1, 0.) ;
|
||||
KnotsPtr->SetValue(num_knots, 1.);
|
||||
MultsPtr->SetValue(1, num_poles);
|
||||
MultsPtr->SetValue(num_knots, num_poles);
|
||||
|
||||
BuildPolynomialCosAndSin(UFirst,ULast,num_poles,
|
||||
CosNumeratorPtr,SinNumeratorPtr,DenominatorPtr);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//=======================================================================
|
||||
//function : BuildCosAndSin
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Convert_ConicToBSplineCurve::BuildCosAndSin(
|
||||
const Convert_ParameterisationType Parameterisation,
|
||||
Handle(TColStd_HArray1OfReal)& CosNumeratorPtr,
|
||||
Handle(TColStd_HArray1OfReal)& SinNumeratorPtr,
|
||||
Handle(TColStd_HArray1OfReal)& DenominatorPtr,
|
||||
Standard_Integer& Degree,
|
||||
Handle(TColStd_HArray1OfReal)& KnotsPtr,
|
||||
Handle(TColStd_HArray1OfInteger)& MultsPtr) const
|
||||
{
|
||||
Standard_Real half_pi,
|
||||
param,
|
||||
first_param,
|
||||
last_param,
|
||||
// direct,
|
||||
inverse,
|
||||
value1,
|
||||
value2,
|
||||
value3 ;
|
||||
|
||||
Standard_Integer
|
||||
ii,
|
||||
jj,
|
||||
index,
|
||||
num_poles,
|
||||
num_periodic_poles,
|
||||
temp_degree,
|
||||
pivot_index_problem,
|
||||
num_flat_knots,
|
||||
num_knots,
|
||||
order ;
|
||||
|
||||
if (Parameterisation != Convert_TgtThetaOver2 &&
|
||||
Parameterisation != Convert_RationalC1) {
|
||||
Standard_ConstructionError::Raise() ;
|
||||
}
|
||||
Handle(TColStd_HArray1OfReal) temp_cos_ptr,
|
||||
temp_sin_ptr,
|
||||
temp_denominator_ptr,
|
||||
temp_knots_ptr;
|
||||
Handle(TColStd_HArray1OfInteger) temp_mults_ptr;
|
||||
if (Parameterisation == Convert_TgtThetaOver2) {
|
||||
BuildCosAndSin(Convert_TgtThetaOver2_3,
|
||||
0.0e0,
|
||||
2 * PI,
|
||||
temp_cos_ptr,
|
||||
temp_sin_ptr,
|
||||
temp_denominator_ptr,
|
||||
Degree,
|
||||
KnotsPtr,
|
||||
MultsPtr) ;
|
||||
CosNumeratorPtr =
|
||||
new TColStd_HArray1OfReal(1,temp_cos_ptr->Length() -1) ;
|
||||
SinNumeratorPtr =
|
||||
new TColStd_HArray1OfReal(1,temp_cos_ptr->Length() -1) ;
|
||||
DenominatorPtr =
|
||||
new TColStd_HArray1OfReal(1,temp_cos_ptr->Length() -1) ;
|
||||
for (ii = temp_cos_ptr->Lower() ; ii <= temp_cos_ptr->Upper()-1 ; ii++) {
|
||||
CosNumeratorPtr->SetValue(ii,temp_cos_ptr->Value(ii)) ;
|
||||
SinNumeratorPtr->SetValue(ii,temp_sin_ptr->Value(ii)) ;
|
||||
DenominatorPtr->SetValue(ii,temp_denominator_ptr->Value(ii)) ;
|
||||
}
|
||||
for (ii = MultsPtr->Lower() ; ii <= MultsPtr->Upper() ; ii++) {
|
||||
MultsPtr->SetValue(ii, Degree) ;
|
||||
}
|
||||
}
|
||||
else if (Parameterisation == Convert_RationalC1)
|
||||
{
|
||||
first_param = 0.0e0 ;
|
||||
last_param = PI ;
|
||||
BuildCosAndSin(Convert_RationalC1,
|
||||
first_param,
|
||||
last_param,
|
||||
temp_cos_ptr,
|
||||
temp_sin_ptr,
|
||||
temp_denominator_ptr,
|
||||
temp_degree,
|
||||
temp_knots_ptr,
|
||||
temp_mults_ptr) ;
|
||||
|
||||
|
||||
Degree = 4 ;
|
||||
order = Degree + 1 ;
|
||||
num_knots = 5 ;
|
||||
num_flat_knots = (Degree -1) * num_knots + 2 * 2 ;
|
||||
num_poles = num_flat_knots - order ;
|
||||
num_periodic_poles = num_poles - 2 ;
|
||||
TColStd_Array1OfReal flat_knots(1,num_flat_knots) ;
|
||||
CosNumeratorPtr =
|
||||
new TColStd_HArray1OfReal(1,num_periodic_poles) ;
|
||||
SinNumeratorPtr =
|
||||
new TColStd_HArray1OfReal(1,num_periodic_poles) ;
|
||||
DenominatorPtr =
|
||||
new TColStd_HArray1OfReal(1,num_periodic_poles) ;
|
||||
|
||||
half_pi = PI * 0.5e0 ;
|
||||
index = 1 ;
|
||||
for (jj = 1 ; jj <= 2 ; jj++) {
|
||||
flat_knots(index) = - half_pi ;
|
||||
index += 1 ;
|
||||
}
|
||||
for (ii = 1 ; ii <= num_knots ; ii++) {
|
||||
for (jj = 1 ; jj <= Degree -1 ; jj++) {
|
||||
flat_knots(index) = (ii-1) * half_pi ;
|
||||
|
||||
index += 1 ;
|
||||
|
||||
}
|
||||
}
|
||||
for (jj = 1 ; jj <= 2 ; jj++) {
|
||||
flat_knots(index) = 2 * PI + half_pi ;
|
||||
index += 1 ;
|
||||
}
|
||||
KnotsPtr =
|
||||
new TColStd_HArray1OfReal(1,num_knots) ;
|
||||
MultsPtr =
|
||||
new TColStd_HArray1OfInteger(1,num_knots) ;
|
||||
for ( ii = 1 ; ii <= num_knots ; ii++) {
|
||||
KnotsPtr->SetValue(ii, (ii-1) * half_pi) ;
|
||||
MultsPtr->SetValue(ii, Degree-1) ;
|
||||
}
|
||||
order = degree + 1 ;
|
||||
|
||||
TColStd_Array1OfReal parameters(1,num_poles) ;
|
||||
TColgp_Array1OfPnt poles_array(1,num_poles) ;
|
||||
TColStd_Array1OfInteger contact_order_array(1,num_poles) ;
|
||||
BSplCLib::BuildSchoenbergPoints(Degree,
|
||||
flat_knots,
|
||||
parameters) ;
|
||||
inverse = 1.0e0 ;
|
||||
for (ii = parameters.Lower() ; ii <= parameters.Upper() ; ii++) {
|
||||
param = parameters(ii) ;
|
||||
if (param > PI) {
|
||||
inverse = -1.0e0 ;
|
||||
param -= PI ;
|
||||
}
|
||||
BSplCLib::D0(param,
|
||||
0,
|
||||
temp_degree,
|
||||
Standard_False,
|
||||
temp_cos_ptr->Array1(),
|
||||
temp_denominator_ptr->Array1(),
|
||||
temp_knots_ptr->Array1(),
|
||||
temp_mults_ptr->Array1(),
|
||||
value1) ;
|
||||
|
||||
BSplCLib::D0(param,
|
||||
0,
|
||||
temp_degree,
|
||||
Standard_False,
|
||||
temp_sin_ptr->Array1(),
|
||||
temp_denominator_ptr->Array1(),
|
||||
temp_knots_ptr->Array1(),
|
||||
temp_mults_ptr->Array1(),
|
||||
value2) ;
|
||||
BSplCLib::D0(param,
|
||||
0,
|
||||
temp_degree,
|
||||
Standard_False,
|
||||
temp_denominator_ptr->Array1(),
|
||||
BSplCLib::NoWeights(),
|
||||
temp_knots_ptr->Array1(),
|
||||
temp_mults_ptr->Array1(),
|
||||
value3) ;
|
||||
contact_order_array(ii) = 0 ;
|
||||
|
||||
poles_array(ii).SetCoord(1,
|
||||
value1 * value3 * inverse) ;
|
||||
poles_array(ii).SetCoord(2,
|
||||
value2 * value3 * inverse) ;
|
||||
poles_array(ii).SetCoord(3,
|
||||
value3) ;
|
||||
}
|
||||
BSplCLib::Interpolate(Degree,
|
||||
flat_knots,
|
||||
parameters,
|
||||
contact_order_array,
|
||||
poles_array,
|
||||
pivot_index_problem) ;
|
||||
for (ii = 1 ; ii <= num_periodic_poles ; ii++) {
|
||||
inverse = 1.0e0 / poles_array(ii).Coord(3) ;
|
||||
CosNumeratorPtr->ChangeArray1()(ii) = poles_array(ii).Coord(1) * inverse ;
|
||||
SinNumeratorPtr->ChangeArray1()(ii) = poles_array(ii).Coord(2) * inverse ;
|
||||
DenominatorPtr->ChangeArray1()(ii) = poles_array(ii).Coord(3) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
19
src/Convert/Convert_CosAndSinEvalFunction.hxx
Executable file
19
src/Convert/Convert_CosAndSinEvalFunction.hxx
Executable file
@@ -0,0 +1,19 @@
|
||||
// File: Convert_CosAnSinEvalFunction.hxx
|
||||
// Created: Wed Aug 23 14:31:24 1995
|
||||
// Author: Xavier BENVENISTE
|
||||
// <xab@nonox>
|
||||
#include <TColgp_Array1OfPnt2d.hxx>
|
||||
#include <TColStd_Array1OfReal.hxx>
|
||||
#include <TColStd_Array1OfInteger.hxx>
|
||||
|
||||
#ifndef _Convert_CosAnSinEvalFunction_HeaderFile
|
||||
#define _Convert_CosAnSinEvalFunction_HeaderFile
|
||||
|
||||
typedef void Convert_CosAndSinEvalFunction(Standard_Real,
|
||||
const Standard_Integer,
|
||||
const TColgp_Array1OfPnt2d&,
|
||||
const TColStd_Array1OfReal&,
|
||||
const TColStd_Array1OfInteger&,
|
||||
Standard_Real Result[2]) ;
|
||||
|
||||
#endif
|
55
src/Convert/Convert_CylinderToBSplineSurface.cdl
Executable file
55
src/Convert/Convert_CylinderToBSplineSurface.cdl
Executable file
@@ -0,0 +1,55 @@
|
||||
-- File: CylinderToBSplineSurface.cdl
|
||||
-- Created: Thu Oct 10 15:14:38 1991
|
||||
-- Author: Jean Claude VAUTHIER
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
|
||||
|
||||
class CylinderToBSplineSurface from Convert
|
||||
|
||||
--- Purpose :
|
||||
-- This algorithm converts a bounded cylinder into a rational
|
||||
-- B-spline surface. The cylinder is a Cylinder from package gp.
|
||||
-- The parametrization of the cylinder is :
|
||||
-- P (U, V) = Loc + V * Zdir + Radius * (Xdir*Cos(U) + Ydir*Sin(U))
|
||||
-- where Loc is the location point of the cylinder, Xdir, Ydir and
|
||||
-- Zdir are the normalized directions of the local cartesian
|
||||
-- coordinate system of the cylinder (Zdir is the direction of the
|
||||
-- cylinder's axis). The U parametrization range is U [0, 2PI].
|
||||
--- KeyWords :
|
||||
-- Convert, Cylinder, BSplineSurface.
|
||||
|
||||
inherits ElementarySurfaceToBSplineSurface
|
||||
|
||||
|
||||
uses Cylinder from gp
|
||||
|
||||
raises DomainError from Standard
|
||||
|
||||
is
|
||||
|
||||
Create (Cyl : Cylinder; U1, U2, V1, V2 : Real)
|
||||
returns CylinderToBSplineSurface
|
||||
--- Purpose :
|
||||
-- The equivalent B-splineSurface as the same orientation as the
|
||||
-- cylinder in the U and V parametric directions.
|
||||
raises DomainError;
|
||||
--- Purpose :
|
||||
-- Raised if U1 = U2 or U1 = U2 + 2.0 * Pi
|
||||
-- Raised if V1 = V2.
|
||||
|
||||
|
||||
Create (Cyl : Cylinder; V1, V2 : Real)
|
||||
returns CylinderToBSplineSurface
|
||||
--- Purpose :
|
||||
-- The equivalent B-splineSurface as the same orientation as the
|
||||
-- cylinder in the U and V parametric directions.
|
||||
raises DomainError;
|
||||
--- Purpose :
|
||||
-- Raised if V1 = V2.
|
||||
|
||||
|
||||
end CylinderToBSplineSurface;
|
||||
|
||||
|
179
src/Convert/Convert_CylinderToBSplineSurface.cxx
Executable file
179
src/Convert/Convert_CylinderToBSplineSurface.cxx
Executable file
@@ -0,0 +1,179 @@
|
||||
//File Convert_CylinderToBSplineSurface.cxx
|
||||
//JCV 16/10/91
|
||||
|
||||
|
||||
#include <Convert_CylinderToBSplineSurface.ixx>
|
||||
|
||||
#include <gp.hxx>
|
||||
#include <gp_Trsf.hxx>
|
||||
|
||||
static const Standard_Integer TheUDegree = 2;
|
||||
static const Standard_Integer TheVDegree = 1;
|
||||
static const Standard_Integer TheNbUKnots = 5;
|
||||
static const Standard_Integer TheNbVKnots = 2;
|
||||
static const Standard_Integer TheNbUPoles = 9;
|
||||
static const Standard_Integer TheNbVPoles = 2;
|
||||
|
||||
|
||||
static void ComputePoles( const Standard_Real R,
|
||||
const Standard_Real U1,
|
||||
const Standard_Real U2,
|
||||
const Standard_Real V1,
|
||||
const Standard_Real V2,
|
||||
TColgp_Array2OfPnt& Poles)
|
||||
{
|
||||
Standard_Real deltaU = U2 - U1;
|
||||
|
||||
Standard_Integer i;
|
||||
|
||||
// Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds)
|
||||
Standard_Integer
|
||||
nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
|
||||
Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
|
||||
|
||||
Standard_Real UStart = U1;
|
||||
Poles(1,1) = gp_Pnt(R*Cos(UStart),R*Sin(UStart),V1);
|
||||
Poles(1,2) = gp_Pnt(R*Cos(UStart),R*Sin(UStart),V2);
|
||||
|
||||
for ( i = 1; i <= nbUSpans; i++) {
|
||||
Poles( 2*i, 1) = gp_Pnt( R * Cos(UStart+AlfaU) / Cos(AlfaU),
|
||||
R * Sin(UStart+AlfaU) / Cos(AlfaU),
|
||||
V1 );
|
||||
Poles( 2*i, 2) = gp_Pnt( R * Cos(UStart+AlfaU) / Cos(AlfaU),
|
||||
R * Sin(UStart+AlfaU) / Cos(AlfaU),
|
||||
V2 );
|
||||
Poles(2*i+1,1) = gp_Pnt( R * Cos(UStart+2*AlfaU),
|
||||
R * Sin(UStart+2*AlfaU),
|
||||
V1 );
|
||||
Poles(2*i+1,2) = gp_Pnt( R * Cos(UStart+2*AlfaU),
|
||||
R * Sin(UStart+2*AlfaU),
|
||||
V2 );
|
||||
UStart += 2*AlfaU;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_CylinderToBSplineSurface
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_CylinderToBSplineSurface::Convert_CylinderToBSplineSurface
|
||||
(const gp_Cylinder& Cyl,
|
||||
const Standard_Real U1 ,
|
||||
const Standard_Real U2 ,
|
||||
const Standard_Real V1 ,
|
||||
const Standard_Real V2 )
|
||||
: Convert_ElementarySurfaceToBSplineSurface (TheNbUPoles, TheNbVPoles,
|
||||
TheNbUKnots, TheNbVKnots,
|
||||
TheUDegree , TheVDegree )
|
||||
{
|
||||
Standard_Real deltaU = U2 - U1;
|
||||
Standard_DomainError_Raise_if( (Abs(V2-V1) <= Abs(Epsilon(V1))) ||
|
||||
(deltaU > 2*PI) ||
|
||||
(deltaU < 0. ),
|
||||
"Convert_CylinderToBSplineSurface");
|
||||
|
||||
isuperiodic = Standard_False;
|
||||
isvperiodic = Standard_False;
|
||||
|
||||
Standard_Integer i,j;
|
||||
// construction du cylindre dans le repere de reference xOy.
|
||||
|
||||
// Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds)
|
||||
Standard_Integer
|
||||
nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
|
||||
Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
|
||||
|
||||
nbUPoles = 2 * nbUSpans + 1;
|
||||
nbUKnots = nbUSpans + 1;
|
||||
|
||||
nbVPoles = 2;
|
||||
nbVKnots = 2;
|
||||
|
||||
Standard_Real R = Cyl.Radius();
|
||||
|
||||
ComputePoles( R, U1, U2, V1, V2, poles);
|
||||
|
||||
for ( i = 1; i<= nbUKnots; i++) {
|
||||
uknots(i) = U1 + (i-1) * 2 * AlfaU;
|
||||
umults(i) = 2;
|
||||
}
|
||||
umults(1)++; umults(nbUKnots)++;
|
||||
vknots(1) = V1; vmults(1) = 2;
|
||||
vknots(2) = V2; vmults(2) = 2;
|
||||
|
||||
// On replace la bspline dans le repere de la sphere.
|
||||
// et on calcule les poids de la bspline.
|
||||
Standard_Real W1;
|
||||
gp_Trsf Trsf;
|
||||
Trsf.SetTransformation( Cyl.Position(), gp::XOY());
|
||||
|
||||
for ( i = 1; i <= nbUPoles; i++) {
|
||||
if ( i % 2 == 0) W1 = Cos(AlfaU);
|
||||
else W1 = 1.;
|
||||
|
||||
for ( j = 1; j <= nbVPoles; j++) {
|
||||
weights( i, j) = W1;
|
||||
poles( i, j).Transform( Trsf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_CylinderToBSplineSurface
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_CylinderToBSplineSurface::Convert_CylinderToBSplineSurface
|
||||
(const gp_Cylinder& Cyl,
|
||||
const Standard_Real V1 ,
|
||||
const Standard_Real V2 )
|
||||
: Convert_ElementarySurfaceToBSplineSurface (TheNbUPoles, TheNbVPoles,
|
||||
TheNbUKnots, TheNbVKnots,
|
||||
TheUDegree , TheVDegree)
|
||||
{
|
||||
Standard_DomainError_Raise_if( Abs(V2-V1) <= Abs(Epsilon(V1)),
|
||||
"Convert_CylinderToBSplineSurface");
|
||||
|
||||
Standard_Integer i,j;
|
||||
|
||||
isuperiodic = Standard_True;
|
||||
isvperiodic = Standard_False;
|
||||
|
||||
// construction du cylindre dans le repere de reference xOy.
|
||||
|
||||
Standard_Real R = Cyl.Radius();
|
||||
|
||||
ComputePoles( R, 0., 2.*PI, V1, V2, poles);
|
||||
|
||||
nbUPoles = 6;
|
||||
nbUKnots = 4;
|
||||
nbVPoles = 2;
|
||||
nbVKnots = 2;
|
||||
|
||||
for ( i = 1; i <= nbUKnots; i++) {
|
||||
uknots(i) = ( i-1) * 2. * PI /3.;
|
||||
umults(i) = 2;
|
||||
}
|
||||
vknots(1) = V1; vmults(1) = 2;
|
||||
vknots(2) = V2; vmults(2) = 2;
|
||||
|
||||
// On replace la bspline dans le repere du cone.
|
||||
// et on calcule les poids de la bspline.
|
||||
Standard_Real W;
|
||||
gp_Trsf Trsf;
|
||||
Trsf.SetTransformation( Cyl.Position(), gp::XOY());
|
||||
|
||||
for ( i = 1; i <= nbUPoles; i++) {
|
||||
if ( i % 2 == 0) W = 0.5; // = Cos(pi /3)
|
||||
else W = 1.;
|
||||
|
||||
for ( j = 1; j <= nbVPoles; j++) {
|
||||
weights( i, j) = W;
|
||||
poles( i, j).Transform( Trsf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
163
src/Convert/Convert_ElementarySurfaceToBSplineSurface.cdl
Executable file
163
src/Convert/Convert_ElementarySurfaceToBSplineSurface.cdl
Executable file
@@ -0,0 +1,163 @@
|
||||
-- File: ElementarySurfaceToBSplineSurface.cdl
|
||||
-- Created: Thu Oct 10 12:04:22 1991
|
||||
-- Author: Jean Claude VAUTHIER
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
deferred class ElementarySurfaceToBSplineSurface from Convert
|
||||
|
||||
--- Purpose :Root class for algorithms which convert an elementary
|
||||
-- surface (cylinder, cone, sphere or torus) into a BSpline
|
||||
-- surface (CylinderToBSplineSurface, ConeToBSplineSurface,
|
||||
-- SphereToBSplineSurface, TorusToBSplineSurface).
|
||||
-- These algorithms all work on elementary surfaces from
|
||||
-- the gp package and compute all the data needed to
|
||||
-- construct a BSpline surface equivalent to the cylinder,
|
||||
-- cone, sphere or torus. This data consists of the following:
|
||||
-- - degrees in the u and v parametric directions,
|
||||
-- - periodic characteristics in the u and v parametric directions,
|
||||
-- - a poles table with associated weights,
|
||||
-- - a knots table (for the u and v parametric directions)
|
||||
-- with associated multiplicities.
|
||||
-- The abstract class
|
||||
-- ElementarySurfaceToBSplineSurface provides a
|
||||
-- framework for storing and consulting this computed data.
|
||||
-- This data may then be used to construct a
|
||||
-- Geom_BSplineSurface surface, for example.
|
||||
-- All those classes define algorithmes to convert an
|
||||
-- ElementarySurface into a B-spline surface.
|
||||
-- This abstract class implements the methods to get
|
||||
-- the geometric representation of the B-spline surface.
|
||||
-- The B-spline representation is computed at the creation
|
||||
-- time in the sub classes.
|
||||
-- The B-spline surface is defined with its degree in the
|
||||
-- parametric U and V directions, its control points (Poles),
|
||||
-- its weights, its knots and their multiplicity.
|
||||
-- KeyWords :
|
||||
-- Convert, ElementarySurface, BSplineSurface.
|
||||
|
||||
|
||||
uses Array1OfInteger from TColStd,
|
||||
Array1OfReal from TColStd,
|
||||
Array2OfReal from TColStd,
|
||||
Array2OfPnt from TColgp,
|
||||
Pnt from gp
|
||||
|
||||
|
||||
raises OutOfRange from Standard
|
||||
|
||||
is
|
||||
|
||||
UDegree (me) returns Integer is static;
|
||||
|
||||
|
||||
VDegree (me) returns Integer is static;
|
||||
|
||||
---Purpose: Returns the degree for the u or v parametric direction of
|
||||
-- the BSpline surface whose data is computed in this framework.
|
||||
|
||||
NbUPoles (me) returns Integer is static;
|
||||
|
||||
|
||||
NbVPoles (me) returns Integer is static;
|
||||
---Purpose: Returns the number of poles for the u or v parametric
|
||||
-- direction of the BSpline surface whose data is computed in this framework.
|
||||
|
||||
NbUKnots (me) returns Integer is static;
|
||||
|
||||
|
||||
NbVKnots (me) returns Integer is static;
|
||||
---Purpose: Returns the number of knots for the u or v parametric
|
||||
-- direction of the BSpline surface whose data is computed in this framework .
|
||||
|
||||
IsUPeriodic(me) returns Boolean is static;
|
||||
|
||||
|
||||
IsVPeriodic(me) returns Boolean is static;
|
||||
---Purpose: Returns true if the BSpline surface whose data is computed
|
||||
-- in this framework is periodic in the u or v parametric direction.
|
||||
|
||||
Pole (me; UIndex, VIndex : Integer) returns Pnt
|
||||
--- Purpose : Returns the pole of index (UIndex,VIndex) to the poles
|
||||
-- table of the BSpline surface whose data is computed in this framework.
|
||||
-- Exceptions
|
||||
-- Standard_OutOfRange if, for the BSpline surface whose
|
||||
-- data is computed in this framework:
|
||||
-- - UIndex is outside the bounds of the poles table in the u
|
||||
-- parametric direction, or
|
||||
-- - VIndex is outside the bounds of the poles table in the v
|
||||
-- parametric direction.
|
||||
raises OutOfRange
|
||||
is static;
|
||||
|
||||
|
||||
Weight (me; UIndex, VIndex : Integer) returns Real
|
||||
--- Purpose : Returns the weight of the pole of index (UIndex,VIndex) to
|
||||
-- the poles table of the BSpline surface whose data is computed in this framework.
|
||||
-- Exceptions
|
||||
-- Standard_OutOfRange if, for the BSpline surface whose
|
||||
-- data is computed in this framework:
|
||||
-- - UIndex is outside the bounds of the poles table in the u
|
||||
-- parametric direction, or
|
||||
-- - VIndex is outside the bounds of the poles table in the v
|
||||
-- parametric direction.
|
||||
raises OutOfRange
|
||||
is static;
|
||||
|
||||
|
||||
UKnot (me; UIndex : Integer) returns Real
|
||||
--- Purpose : Returns the U-knot of range UIndex.
|
||||
raises OutOfRange
|
||||
--- Purpose : Raised if UIndex < 1 or UIndex > NbUKnots.
|
||||
is static;
|
||||
|
||||
|
||||
VKnot (me; UIndex : Integer) returns Real
|
||||
--- Purpose : Returns the V-knot of range VIndex.
|
||||
raises OutOfRange
|
||||
--- Purpose : Raised if VIndex < 1 or VIndex > NbVKnots.
|
||||
is static;
|
||||
|
||||
|
||||
UMultiplicity (me; UIndex : Integer) returns Integer
|
||||
--- Purpose : Returns the multiplicity of the U-knot of range UIndex.
|
||||
raises OutOfRange
|
||||
--- Purpose : Raised if UIndex < 1 or UIndex > NbUKnots.
|
||||
is static;
|
||||
|
||||
|
||||
VMultiplicity (me; VIndex : Integer) returns Integer
|
||||
--- Purpose : Returns the multiplicity of the V-knot of range VIndex.
|
||||
raises OutOfRange
|
||||
--- Purpose : Raised if VIndex < 1 or VIndex > NbVKnots.
|
||||
is static;
|
||||
|
||||
|
||||
Initialize (NumberOfUPoles, NumberOfVPoles, NumberOfUKnots,
|
||||
NumberOfVKnots, UDegree, VDegree : Integer);
|
||||
|
||||
|
||||
fields
|
||||
|
||||
poles : Array2OfPnt is protected;
|
||||
weights : Array2OfReal is protected;
|
||||
uknots : Array1OfReal is protected;
|
||||
umults : Array1OfInteger is protected;
|
||||
vknots : Array1OfReal is protected;
|
||||
vmults : Array1OfInteger is protected;
|
||||
udegree : Integer is protected;
|
||||
vdegree : Integer is protected;
|
||||
nbUPoles : Integer is protected;
|
||||
nbVPoles : Integer is protected;
|
||||
nbUKnots : Integer is protected;
|
||||
nbVKnots : Integer is protected;
|
||||
isuperiodic : Boolean is protected;
|
||||
isvperiodic : Boolean is protected;
|
||||
|
||||
|
||||
end ElementarySurfaceToBSplineSurface;
|
||||
|
||||
|
205
src/Convert/Convert_ElementarySurfaceToBSplineSurface.cxx
Executable file
205
src/Convert/Convert_ElementarySurfaceToBSplineSurface.cxx
Executable file
@@ -0,0 +1,205 @@
|
||||
//File Convert_ElementarySurfaceToBSplineSurface.cxx
|
||||
//JCV 16/10/91
|
||||
|
||||
|
||||
|
||||
#include <Convert_ElementarySurfaceToBSplineSurface.ixx>
|
||||
|
||||
#include <Standard_OutOfRange.hxx>
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_ElementarySurfaceToBSplineSurface
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_ElementarySurfaceToBSplineSurface::
|
||||
Convert_ElementarySurfaceToBSplineSurface
|
||||
(const Standard_Integer NbUPoles,
|
||||
const Standard_Integer NbVPoles,
|
||||
const Standard_Integer NbUKnots,
|
||||
const Standard_Integer NbVKnots,
|
||||
const Standard_Integer UDegree,
|
||||
const Standard_Integer VDegree) :
|
||||
poles (1, NbUPoles, 1, NbVPoles), weights (1, NbUPoles, 1, NbVPoles),
|
||||
uknots (1, NbUKnots), umults (1, NbUKnots),
|
||||
vknots (1, NbVKnots), vmults (1, NbVKnots),
|
||||
udegree (UDegree), vdegree (VDegree),
|
||||
nbUPoles (NbUPoles), nbVPoles (NbVPoles),
|
||||
nbUKnots (NbUKnots), nbVKnots (NbVKnots)
|
||||
|
||||
{ }
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : UDegree
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_ElementarySurfaceToBSplineSurface::UDegree () const
|
||||
{
|
||||
return udegree;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : VDegree
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_ElementarySurfaceToBSplineSurface::VDegree () const
|
||||
{
|
||||
return vdegree;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbUPoles
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_ElementarySurfaceToBSplineSurface::NbUPoles () const
|
||||
{
|
||||
return nbUPoles;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbVPoles
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_ElementarySurfaceToBSplineSurface::NbVPoles () const
|
||||
{
|
||||
return nbVPoles;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbUKnots
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_ElementarySurfaceToBSplineSurface::NbUKnots () const
|
||||
{
|
||||
return nbUKnots;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : NbVKnots
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_ElementarySurfaceToBSplineSurface::NbVKnots () const
|
||||
{
|
||||
return nbVKnots;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : IsUPeriodic
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Convert_ElementarySurfaceToBSplineSurface::IsUPeriodic()
|
||||
const
|
||||
{
|
||||
return isuperiodic;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsVPeriodic
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Convert_ElementarySurfaceToBSplineSurface::IsVPeriodic()
|
||||
const
|
||||
{
|
||||
return isvperiodic;
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Pole
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
gp_Pnt Convert_ElementarySurfaceToBSplineSurface::Pole
|
||||
(const Standard_Integer UIndex,
|
||||
const Standard_Integer VIndex ) const
|
||||
{
|
||||
Standard_OutOfRange_Raise_if (
|
||||
UIndex < 1 || UIndex > nbUPoles ||
|
||||
VIndex < 1 || VIndex > nbVPoles, " ");
|
||||
return poles (UIndex, VIndex);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Weight
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Real Convert_ElementarySurfaceToBSplineSurface::Weight
|
||||
(const Standard_Integer UIndex,
|
||||
const Standard_Integer VIndex ) const
|
||||
{
|
||||
Standard_OutOfRange_Raise_if (
|
||||
UIndex < 1 || UIndex > nbUPoles ||
|
||||
VIndex < 1 || VIndex > nbVPoles," ");
|
||||
return weights (UIndex, VIndex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : UKnot
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Real Convert_ElementarySurfaceToBSplineSurface::UKnot
|
||||
(const Standard_Integer UIndex) const
|
||||
{
|
||||
Standard_OutOfRange_Raise_if (UIndex < 1 || UIndex > nbUKnots, " ");
|
||||
return uknots (UIndex);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : VKnot
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Real Convert_ElementarySurfaceToBSplineSurface::VKnot
|
||||
(const Standard_Integer VIndex) const
|
||||
{
|
||||
Standard_OutOfRange_Raise_if (VIndex < 1 || VIndex > nbVKnots, " ");
|
||||
return vknots (VIndex);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : UMultiplicity
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_ElementarySurfaceToBSplineSurface::UMultiplicity
|
||||
(const Standard_Integer UIndex) const
|
||||
{
|
||||
Standard_OutOfRange_Raise_if (UIndex < 1 || UIndex > nbUKnots, " ");
|
||||
return umults (UIndex);
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : VMultiplicity
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Integer Convert_ElementarySurfaceToBSplineSurface::VMultiplicity
|
||||
(const Standard_Integer VIndex) const
|
||||
{
|
||||
Standard_OutOfRange_Raise_if (VIndex < 1 || VIndex > nbVKnots, " ");
|
||||
return vmults (VIndex);
|
||||
}
|
52
src/Convert/Convert_EllipseToBSplineCurve.cdl
Executable file
52
src/Convert/Convert_EllipseToBSplineCurve.cdl
Executable file
@@ -0,0 +1,52 @@
|
||||
-- File: EllipseToBSplineCurve.cdl
|
||||
-- Created: Thu Oct 10 14:38:50 1991
|
||||
-- Author: Jean Claude VAUTHIER
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class EllipseToBSplineCurve from Convert inherits ConicToBSplineCurve
|
||||
|
||||
--- Purpose :
|
||||
-- This algorithm converts a ellipse into a rational B-spline curve.
|
||||
-- The ellipse is represented an Elips2d from package gp with
|
||||
-- the parametrization :
|
||||
-- P (U) =
|
||||
-- Loc + (MajorRadius * Cos(U) * Xdir + MinorRadius * Sin(U) * Ydir)
|
||||
-- where Loc is the center of the ellipse, Xdir and Ydir are the
|
||||
-- normalized directions of the local cartesian coordinate system of
|
||||
-- the ellipse. The parametrization range is U [0, 2PI].
|
||||
--- KeyWords :
|
||||
-- Convert, Ellipse, BSplineCurve, 2D .
|
||||
|
||||
uses Elips2d from gp,
|
||||
ParameterisationType from Convert
|
||||
|
||||
raises DomainError from Standard
|
||||
|
||||
is
|
||||
|
||||
Create (E : Elips2d;
|
||||
Parameterisation : ParameterisationType from Convert
|
||||
= Convert_TgtThetaOver2 ) returns EllipseToBSplineCurve;
|
||||
--- Purpose : The equivalent B-spline curve has the same orientation
|
||||
-- as the ellipse E.
|
||||
|
||||
|
||||
Create (E : Elips2d; U1, U2 : Real;
|
||||
Parameterisation : ParameterisationType from Convert
|
||||
= Convert_TgtThetaOver2 ) returns EllipseToBSplineCurve
|
||||
--- Purpose :
|
||||
-- The ellipse E is limited between the parametric values U1, U2.
|
||||
-- The equivalent B-spline curve is oriented from U1 to U2 and has
|
||||
-- the same orientation as E.
|
||||
raises DomainError;
|
||||
--- Purpose :
|
||||
-- Raised if U1 = U2 or U1 = U2 + 2.0 * Pi
|
||||
|
||||
|
||||
|
||||
end EllipseToBSplineCurve;
|
||||
|
180
src/Convert/Convert_EllipseToBSplineCurve.cxx
Executable file
180
src/Convert/Convert_EllipseToBSplineCurve.cxx
Executable file
@@ -0,0 +1,180 @@
|
||||
//File Convert_EllipseToBSplineCurve.cxx
|
||||
//JCV 16/10/91
|
||||
|
||||
|
||||
#include <Convert_EllipseToBSplineCurve.ixx>
|
||||
|
||||
#include <TColgp_HArray1OfPnt2d.hxx>
|
||||
#include <TColStd_HArray1OfReal.hxx>
|
||||
#include <TColStd_HArray1OfInteger.hxx>
|
||||
#include <TColStd_Array1OfReal.hxx>
|
||||
#include <TColgp_Array1OfPnt2d.hxx>
|
||||
|
||||
#include <gp.hxx>
|
||||
#include <gp_Ax2d.hxx>
|
||||
#include <gp_Dir2d.hxx>
|
||||
#include <gp_Trsf2d.hxx>
|
||||
|
||||
#include <Precision.hxx>
|
||||
|
||||
//Attention :
|
||||
//Pour eviter de trainer des tableaux persistent dans les champs
|
||||
//on dimensionne les tableaux au maxi (TheNbKnots et TheNbPoles)
|
||||
//qui correspondent au cercle complet. Pour un arc de cercle on a
|
||||
//evidemment besoin de moins de poles et de noeuds, c'est pourquoi les
|
||||
//champs nbKnots et nbPoles sont presents et sont mis a jour dans le
|
||||
//constructeur d'un arc de cercle B-spline pour tenir compte du nombre
|
||||
//effectif de poles et de noeuds.
|
||||
|
||||
|
||||
// parametrization :
|
||||
// Reference : Rational B-spline for Curve and Surface Representation
|
||||
// Wayne Tiller CADG September 1983
|
||||
//
|
||||
// x(t) = (1 - t^2) / (1 + t^2)
|
||||
// y(t) = 2 t / (1 + t^2)
|
||||
//
|
||||
// then t = Sqrt(2) u / ((Sqrt(2) - 2) u + 2)
|
||||
//
|
||||
// => u = 2 t / (Sqrt(2) + (2 - Sqrt(2)) t)
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_EllipseToBSplineCurve
|
||||
//purpose : this constructs a periodic Ellipse
|
||||
//=======================================================================
|
||||
|
||||
Convert_EllipseToBSplineCurve::Convert_EllipseToBSplineCurve
|
||||
(const gp_Elips2d& E, const Convert_ParameterisationType Parameterisation)
|
||||
:Convert_ConicToBSplineCurve(0,0,0){
|
||||
|
||||
Standard_Integer ii ;
|
||||
|
||||
Standard_Real R,
|
||||
r,
|
||||
value ;
|
||||
Handle(TColStd_HArray1OfReal) CosNumeratorPtr,
|
||||
SinNumeratorPtr ;
|
||||
|
||||
|
||||
R = E.MajorRadius();
|
||||
r = E.MinorRadius();
|
||||
|
||||
|
||||
if (Parameterisation != Convert_TgtThetaOver2 &&
|
||||
Parameterisation != Convert_RationalC1) {
|
||||
// Dans ce cas BuildCosAndSin ne sait pas gerer la periodicite
|
||||
// => on trim sur 0,2*PI
|
||||
isperiodic = Standard_False;
|
||||
Convert_ConicToBSplineCurve::
|
||||
BuildCosAndSin(Parameterisation,
|
||||
0, 2*PI,
|
||||
CosNumeratorPtr,
|
||||
SinNumeratorPtr,
|
||||
weights,
|
||||
degree,
|
||||
knots,
|
||||
mults) ;
|
||||
}
|
||||
else {
|
||||
isperiodic = Standard_True;
|
||||
Convert_ConicToBSplineCurve::
|
||||
BuildCosAndSin(Parameterisation,
|
||||
CosNumeratorPtr,
|
||||
SinNumeratorPtr,
|
||||
weights,
|
||||
degree,
|
||||
knots,
|
||||
mults);
|
||||
}
|
||||
|
||||
nbPoles = CosNumeratorPtr->Length();
|
||||
nbKnots = knots->Length();
|
||||
|
||||
poles =
|
||||
new TColgp_HArray1OfPnt2d(1,nbPoles) ;
|
||||
|
||||
|
||||
gp_Dir2d Ox = E.XAxis().Direction();
|
||||
gp_Dir2d Oy = E.YAxis().Direction();
|
||||
gp_Trsf2d Trsf;
|
||||
Trsf.SetTransformation( E.XAxis(), gp::OX2d());
|
||||
if ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.0e0) {
|
||||
value = r ;
|
||||
}
|
||||
else {
|
||||
value = -r ;
|
||||
}
|
||||
|
||||
// On replace la bspline dans le repere du cercle.
|
||||
// et on calcule les poids de la bspline.
|
||||
|
||||
for (ii = 1; ii <= nbPoles ; ii++) {
|
||||
poles->ChangeArray1()(ii).SetCoord(1, R * CosNumeratorPtr->Value(ii)) ;
|
||||
poles->ChangeArray1()(ii).SetCoord(2, value * SinNumeratorPtr->Value(ii)) ;
|
||||
poles->ChangeArray1()(ii).Transform( Trsf);
|
||||
}
|
||||
|
||||
}
|
||||
//=======================================================================
|
||||
//function : Convert_EllipseToBSplineCurve
|
||||
//purpose : this constructs a non periodic Ellipse
|
||||
//=======================================================================
|
||||
|
||||
Convert_EllipseToBSplineCurve::Convert_EllipseToBSplineCurve
|
||||
(const gp_Elips2d& E,
|
||||
const Standard_Real UFirst,
|
||||
const Standard_Real ULast,
|
||||
const Convert_ParameterisationType Parameterisation)
|
||||
:Convert_ConicToBSplineCurve(0,0,0)
|
||||
{
|
||||
#ifndef No_Exception
|
||||
Standard_Real Tol = Precision::PConfusion();
|
||||
Standard_Real delta = ULast - UFirst;
|
||||
#endif
|
||||
Standard_DomainError_Raise_if( (delta > (2*PI+Tol)) || (delta <= 0.0e0),
|
||||
"Convert_EllipseToBSplineCurve");
|
||||
Standard_Integer ii;
|
||||
Standard_Real R, r, value;
|
||||
Handle(TColStd_HArray1OfReal) CosNumeratorPtr, SinNumeratorPtr;
|
||||
|
||||
R = E.MajorRadius();
|
||||
r = E.MinorRadius();
|
||||
|
||||
isperiodic = Standard_False;
|
||||
Convert_ConicToBSplineCurve::BuildCosAndSin(Parameterisation,
|
||||
UFirst,
|
||||
ULast,
|
||||
CosNumeratorPtr,
|
||||
SinNumeratorPtr,
|
||||
weights,
|
||||
degree,
|
||||
knots,
|
||||
mults) ;
|
||||
|
||||
nbPoles = CosNumeratorPtr->Length();
|
||||
nbKnots = knots->Length();
|
||||
|
||||
poles = new TColgp_HArray1OfPnt2d(1,nbPoles) ;
|
||||
|
||||
gp_Dir2d Ox = E.XAxis().Direction();
|
||||
gp_Dir2d Oy = E.YAxis().Direction();
|
||||
gp_Trsf2d Trsf;
|
||||
Trsf.SetTransformation( E.XAxis(), gp::OX2d());
|
||||
if ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.0e0) {
|
||||
value = r ;
|
||||
}
|
||||
else {
|
||||
value = -r ;
|
||||
}
|
||||
|
||||
// On replace la bspline dans le repere du cercle.
|
||||
// et on calcule les poids de la bspline.
|
||||
|
||||
for (ii = 1; ii <= nbPoles ; ii++) {
|
||||
poles->ChangeArray1()(ii).SetCoord(1, R * CosNumeratorPtr->Value(ii)) ;
|
||||
poles->ChangeArray1()(ii).SetCoord(2, value * SinNumeratorPtr->Value(ii)) ;
|
||||
poles->ChangeArray1()(ii).Transform( Trsf);
|
||||
}
|
||||
|
||||
}
|
||||
|
157
src/Convert/Convert_GridPolynomialToPoles.cdl
Executable file
157
src/Convert/Convert_GridPolynomialToPoles.cdl
Executable file
@@ -0,0 +1,157 @@
|
||||
-- File: Convert_GridPolynomilaToPoles.cdl
|
||||
-- Created: Mon Jul 8 13:28:08 1996
|
||||
-- Author: Philippe MANGIN
|
||||
-- <pmn@sgi29>
|
||||
---Copyright: Matra Datavision 1996
|
||||
|
||||
|
||||
class GridPolynomialToPoles from Convert
|
||||
|
||||
---Purpose:
|
||||
|
||||
uses Array1OfReal from TColStd,
|
||||
HArray1OfReal from TColStd,
|
||||
HArray2OfReal from TColStd,
|
||||
HArray1OfInteger from TColStd,
|
||||
HArray2OfInteger from TColStd,
|
||||
HArray2OfPnt from TColgp,
|
||||
Shape from GeomAbs
|
||||
raises
|
||||
|
||||
DomainError from Standard,
|
||||
NotDone from StdFail
|
||||
|
||||
is
|
||||
|
||||
Create(MaxUDegree : Integer ;
|
||||
MaxVDegree : Integer ;
|
||||
NumCoeff : HArray1OfInteger from TColStd ;
|
||||
Coefficients : HArray1OfReal from TColStd ;
|
||||
PolynomialUIntervals : HArray1OfReal from TColStd ;
|
||||
PolynomialVIntervals : HArray1OfReal from TColStd )
|
||||
returns GridPolynomialToPoles
|
||||
---Purpose: To only one polynomial Surface.
|
||||
-- The Length of <PolynomialUIntervals> and <PolynomialVIntervals>
|
||||
-- have to be 2.
|
||||
-- This values defined the parametric domain of the Polynomial Equation.
|
||||
--
|
||||
-- Coefficients :
|
||||
-- The <Coefficients> have to be formated than an "C array"
|
||||
-- [MaxUDegree+1] [MaxVDegree+1] [3]
|
||||
--
|
||||
---Level: Public
|
||||
raises DomainError; -- if <NumCoeff> is not a [1, 2] array
|
||||
-- if the <Coefficients> is not a [1,(MaxUDegree+1)*(MaxVDegree+1)*3]
|
||||
-- array
|
||||
|
||||
|
||||
Create(NbUSurfaces : Integer;
|
||||
NBVSurfaces : Integer;
|
||||
UContinuity : Integer ;
|
||||
VContinuity : Integer ;
|
||||
MaxUDegree : Integer ;
|
||||
MaxVDegree : Integer ;
|
||||
NumCoeffPerSurface : HArray2OfInteger from TColStd ;
|
||||
Coefficients : HArray1OfReal from TColStd ;
|
||||
PolynomialUIntervals : HArray1OfReal from TColStd ;
|
||||
PolynomialVIntervals : HArray1OfReal from TColStd ;
|
||||
TrueUIntervals : HArray1OfReal from TColStd;
|
||||
TrueVIntervals : HArray1OfReal from TColStd)
|
||||
returns GridPolynomialToPoles
|
||||
---Purpose: To one grid of polynomial Surface.
|
||||
-- Warning!
|
||||
-- Continuity in each parametric direction can be at MOST the
|
||||
-- maximum degree of the polynomial functions.
|
||||
--
|
||||
-- <TrueUIntervals>, <TrueVIntervals> :
|
||||
-- this is the true parameterisation for the composite surface
|
||||
--
|
||||
-- Coefficients :
|
||||
-- The Coefficients have to be formated than an "C array"
|
||||
-- [NbVSurfaces] [NBUSurfaces] [MaxUDegree+1] [MaxVDegree+1] [3]
|
||||
-- raises DomainError if <NumCoeffPerSurface> is not a
|
||||
-- [1, NbVSurfaces*NbUSurfaces, 1,2] array.
|
||||
-- if <Coefficients> is not a
|
||||
--[1, NbVSurfaces*NBUSurfaces*(MaxUDegree+1)*(MaxVDegree+1)*3] array
|
||||
raises DomainError ;
|
||||
|
||||
|
||||
Perform(me : in out;
|
||||
UContinuity : Integer ;
|
||||
VContinuity : Integer ;
|
||||
MaxUDegree : Integer ;
|
||||
MaxVDegree : Integer ;
|
||||
NumCoeffPerSurface : HArray2OfInteger from TColStd ;
|
||||
Coefficients : HArray1OfReal from TColStd ;
|
||||
PolynomialUIntervals : HArray1OfReal from TColStd ;
|
||||
PolynomialVIntervals : HArray1OfReal from TColStd ;
|
||||
TrueUIntervals : HArray1OfReal from TColStd ;
|
||||
TrueVIntervals : HArray1OfReal from TColStd );
|
||||
|
||||
BuildArray(me;
|
||||
Degree : Integer;
|
||||
Knots : HArray1OfReal;
|
||||
Continuty : Integer;
|
||||
FlatKnots : in out HArray1OfReal;
|
||||
Mults : in out HArray1OfInteger;
|
||||
Parameters : in out HArray1OfReal)
|
||||
is private;
|
||||
|
||||
|
||||
NbUPoles(me) returns Integer ;
|
||||
NbVPoles(me) returns Integer ;
|
||||
|
||||
Poles(me)
|
||||
---Purpose: returns the poles of the BSpline Surface
|
||||
---C++: return const &
|
||||
returns HArray2OfPnt ;
|
||||
|
||||
UDegree(me)
|
||||
returns Integer ;
|
||||
|
||||
VDegree(me)
|
||||
returns Integer ;
|
||||
|
||||
NbUKnots(me)
|
||||
returns Integer ;
|
||||
|
||||
NbVKnots(me)
|
||||
returns Integer ;
|
||||
|
||||
UKnots(me)
|
||||
---Purpose: Knots in the U direction
|
||||
---C++: return const &
|
||||
returns HArray1OfReal;
|
||||
|
||||
VKnots(me)
|
||||
---Purpose: Knots in the V direction
|
||||
---C++: return const &
|
||||
returns HArray1OfReal;
|
||||
|
||||
UMultiplicities(me)
|
||||
---Purpose: Multiplicities of the knots in the U direction
|
||||
---C++: return const &
|
||||
returns HArray1OfInteger;
|
||||
|
||||
VMultiplicities(me)
|
||||
---Purpose: Multiplicities of the knots in the V direction
|
||||
---C++: return const &
|
||||
returns HArray1OfInteger;
|
||||
|
||||
IsDone(me) returns Boolean ;
|
||||
|
||||
|
||||
fields
|
||||
|
||||
myUFlatKnots : HArray1OfReal from TColStd ;
|
||||
myVFlatKnots : HArray1OfReal from TColStd ;
|
||||
myUKnots : HArray1OfReal from TColStd ;
|
||||
myVKnots : HArray1OfReal from TColStd ;
|
||||
myUMults : HArray1OfInteger from TColStd ;
|
||||
myVMults : HArray1OfInteger from TColStd ;
|
||||
myPoles : HArray2OfPnt from TColgp ;
|
||||
myUDegree : Integer ;
|
||||
myVDegree : Integer ;
|
||||
myDone : Boolean ;
|
||||
|
||||
end GridPolynomialToPoles;
|
359
src/Convert/Convert_GridPolynomialToPoles.cxx
Executable file
359
src/Convert/Convert_GridPolynomialToPoles.cxx
Executable file
@@ -0,0 +1,359 @@
|
||||
// File: Convert_GridPolynomialToPoles.cxx
|
||||
// Created: Mon Jul 8 14:40:31 1996
|
||||
// Author: Philippe MANGIN
|
||||
// <pmn@sgi29>
|
||||
// Modified: Fri Oct 3 14:58:05 1997
|
||||
// by: Joelle CHAUVET
|
||||
// Condition d'extraction corrigee
|
||||
// + positionnement par EvalPoly2Var
|
||||
|
||||
|
||||
#include <Convert_GridPolynomialToPoles.ixx>
|
||||
|
||||
#include <StdFail_NotDone.hxx>
|
||||
#include <Standard_DomainError.hxx>
|
||||
#include <PLib.hxx>
|
||||
#include <BSplSLib.hxx>
|
||||
#include <BSplCLib.hxx>
|
||||
|
||||
|
||||
Convert_GridPolynomialToPoles::
|
||||
Convert_GridPolynomialToPoles(
|
||||
const Standard_Integer MaxUDegree,
|
||||
const Standard_Integer MaxVDegree,
|
||||
const Handle(TColStd_HArray1OfInteger)& NumCoeffPerSurface,
|
||||
const Handle(TColStd_HArray1OfReal)& Coefficients,
|
||||
const Handle(TColStd_HArray1OfReal)& PolynomialUIntervals,
|
||||
const Handle(TColStd_HArray1OfReal)& PolynomialVIntervals) :
|
||||
myDone(Standard_False)
|
||||
{
|
||||
// Les Controles
|
||||
if ((NumCoeffPerSurface->Lower()!=1 ) ||
|
||||
(NumCoeffPerSurface->Upper()!= 2) )
|
||||
{
|
||||
Standard_DomainError::Raise("Convert : Wrong Coefficients");
|
||||
}
|
||||
if ((Coefficients->Lower()!=1 ) ||
|
||||
(Coefficients->Upper()!= 3*(MaxUDegree+1)*(MaxVDegree+1)))
|
||||
{
|
||||
Standard_DomainError::Raise("Convert : Wrong Coefficients");
|
||||
}
|
||||
|
||||
// Les Degres
|
||||
myUDegree = NumCoeffPerSurface->Value(1)-1;
|
||||
myVDegree = NumCoeffPerSurface->Value(2)-1;
|
||||
|
||||
if (myUDegree > MaxUDegree)
|
||||
Standard_DomainError::Raise
|
||||
("Convert : Incoherence beetween NumCoeffPerSurface and MaxUDegree");
|
||||
if (myVDegree > MaxVDegree)
|
||||
Standard_DomainError::Raise
|
||||
("Convert : Incoherence beetween NumCoeffPerSurface and MaxVDegree");
|
||||
|
||||
Handle(TColStd_HArray2OfInteger) NumCoeff =
|
||||
new (TColStd_HArray2OfInteger)(1, 1, 1, 2);
|
||||
NumCoeff->SetValue(1, 1, NumCoeffPerSurface->Value(1));
|
||||
NumCoeff->SetValue(1, 2, NumCoeffPerSurface->Value(2));
|
||||
|
||||
Perform (0, 0,
|
||||
MaxUDegree, MaxVDegree,
|
||||
NumCoeff,
|
||||
Coefficients,
|
||||
PolynomialUIntervals,
|
||||
PolynomialVIntervals,
|
||||
PolynomialUIntervals,
|
||||
PolynomialVIntervals);
|
||||
}
|
||||
|
||||
Convert_GridPolynomialToPoles::
|
||||
Convert_GridPolynomialToPoles(
|
||||
const Standard_Integer NbUSurfaces,
|
||||
const Standard_Integer NbVSurfaces,
|
||||
const Standard_Integer UContinuity,
|
||||
const Standard_Integer VContinuity,
|
||||
const Standard_Integer MaxUDegree,
|
||||
const Standard_Integer MaxVDegree,
|
||||
const Handle(TColStd_HArray2OfInteger)& NumCoeffPerSurface,
|
||||
const Handle(TColStd_HArray1OfReal)& Coefficients,
|
||||
const Handle(TColStd_HArray1OfReal)& PolynomialUIntervals,
|
||||
const Handle(TColStd_HArray1OfReal)& PolynomialVIntervals,
|
||||
const Handle(TColStd_HArray1OfReal)& TrueUIntervals,
|
||||
const Handle(TColStd_HArray1OfReal)& TrueVIntervals) :
|
||||
myDone(Standard_False)
|
||||
{
|
||||
Standard_Integer ii;
|
||||
Standard_Integer RealUDegree = Max(MaxUDegree, 2*UContinuity + 1);
|
||||
Standard_Integer RealVDegree = Max(MaxVDegree, 2*VContinuity + 1);
|
||||
myUDegree = 0;
|
||||
myVDegree = 0;
|
||||
|
||||
// Les controles
|
||||
if((NumCoeffPerSurface->LowerRow()!=1) ||
|
||||
(NumCoeffPerSurface->UpperRow()!=NbUSurfaces*NbVSurfaces) ||
|
||||
(NumCoeffPerSurface->LowerCol()!=1) ||
|
||||
(NumCoeffPerSurface->UpperCol()!=2) )
|
||||
{
|
||||
Standard_DomainError::Raise("Convert : Wrong NumCoeffPerSurface");
|
||||
}
|
||||
|
||||
if ((Coefficients->Lower()!=1 ) ||
|
||||
(Coefficients->Upper()!= 3*NbUSurfaces*NbVSurfaces*
|
||||
(RealUDegree + 1) * (RealVDegree + 1)) )
|
||||
{
|
||||
Standard_DomainError::Raise("Convert : Wrong Coefficients");
|
||||
}
|
||||
|
||||
// Calcul des degree
|
||||
for (ii=1; ii<=NbUSurfaces*NbVSurfaces; ii++) {
|
||||
if (NumCoeffPerSurface->Value(ii,1) > myUDegree+1)
|
||||
myUDegree = NumCoeffPerSurface->Value(ii,1)-1;
|
||||
if (NumCoeffPerSurface->Value(ii,2) > myVDegree+1)
|
||||
myVDegree = NumCoeffPerSurface->Value(ii,2)-1;
|
||||
}
|
||||
|
||||
if (myUDegree > RealUDegree)
|
||||
Standard_DomainError::Raise
|
||||
("Convert : Incoherence beetween NumCoeffPerSurface and MaxUDegree");
|
||||
if (myVDegree > RealVDegree)
|
||||
Standard_DomainError::Raise
|
||||
("Convert : Incoherence beetween NumCoeffPerSurface and MaxVDegree");
|
||||
|
||||
Perform (UContinuity, VContinuity,
|
||||
RealUDegree, RealVDegree,
|
||||
NumCoeffPerSurface,
|
||||
Coefficients,
|
||||
PolynomialUIntervals,
|
||||
PolynomialVIntervals,
|
||||
TrueUIntervals,
|
||||
TrueVIntervals);
|
||||
}
|
||||
|
||||
void Convert_GridPolynomialToPoles::Perform(const Standard_Integer UContinuity,
|
||||
const Standard_Integer VContinuity,
|
||||
const Standard_Integer MaxUDegree,
|
||||
const Standard_Integer MaxVDegree,
|
||||
const Handle(TColStd_HArray2OfInteger)& NumCoeffPerSurface,
|
||||
const Handle(TColStd_HArray1OfReal)& Coefficients,
|
||||
const Handle(TColStd_HArray1OfReal)& PolynomialUIntervals,
|
||||
const Handle(TColStd_HArray1OfReal)& PolynomialVIntervals,
|
||||
const Handle(TColStd_HArray1OfReal)& TrueUIntervals,
|
||||
const Handle(TColStd_HArray1OfReal)& TrueVIntervals)
|
||||
{
|
||||
// (1) Construction des Tables monodimensionnelles ----------------------------
|
||||
Handle(TColStd_HArray1OfReal) UParameters, VParameters;
|
||||
myUKnots = new (TColStd_HArray1OfReal) (1, TrueUIntervals->Length());
|
||||
myUKnots->ChangeArray1() = TrueUIntervals->Array1();
|
||||
myVKnots = new (TColStd_HArray1OfReal) (1, TrueVIntervals->Length());
|
||||
myVKnots->ChangeArray1() = TrueVIntervals->Array1();
|
||||
|
||||
BuildArray( myUDegree,
|
||||
myUKnots,
|
||||
UContinuity,
|
||||
myUFlatKnots,
|
||||
myUMults,
|
||||
UParameters);
|
||||
|
||||
BuildArray( myVDegree,
|
||||
myVKnots,
|
||||
VContinuity,
|
||||
myVFlatKnots,
|
||||
myVMults,
|
||||
VParameters);
|
||||
|
||||
// (2) Digitalisation -------------------------------------------------------
|
||||
|
||||
Standard_Integer ii, jj, Uindex=0, Vindex=0;
|
||||
Standard_Integer Patch_Indice=0;
|
||||
Standard_Real NValue, UValue, VValue;
|
||||
Standard_Integer dimension = 3*( myVDegree+1);
|
||||
Standard_Integer SizPatch = 3 * (MaxUDegree+1) * (MaxVDegree+1);
|
||||
myPoles = new (TColgp_HArray2OfPnt) (1, UParameters->Length(),
|
||||
1, VParameters->Length());
|
||||
|
||||
TColStd_Array1OfReal Patch(1, (myUDegree+1)*dimension);
|
||||
TColStd_Array1OfReal Point(1, 3);
|
||||
Standard_Real * Coeffs = (Standard_Real *) &Patch.ChangeValue(1);
|
||||
Standard_Real * Digit = (Standard_Real *) &Point.ChangeValue(1);
|
||||
|
||||
for (ii=1, Uindex=1; ii<=UParameters->Length(); ii++) {
|
||||
|
||||
while (UParameters->Value(ii) > TrueUIntervals->Value(Uindex+1)
|
||||
&& Uindex < myUKnots->Length()-1) { Uindex++; }
|
||||
|
||||
NValue = (UParameters->Value(ii) - TrueUIntervals->Value(Uindex) )
|
||||
/ (TrueUIntervals->Value(Uindex+1) - TrueUIntervals->Value(Uindex));
|
||||
UValue = (1-NValue) * PolynomialUIntervals->Value(1)
|
||||
+ NValue * PolynomialUIntervals->Value(2) ;
|
||||
|
||||
for (jj=1, Vindex=1; jj<=VParameters->Length(); jj++) {
|
||||
|
||||
while (VParameters->Value(jj) > TrueVIntervals->Value(Vindex+1)
|
||||
&& Vindex < myVKnots->Length()-1) { Vindex++; }
|
||||
|
||||
NValue = (VParameters->Value(jj) - TrueVIntervals->Value(Vindex) )
|
||||
/ (TrueVIntervals->Value(Vindex+1) - TrueVIntervals->Value(Vindex));
|
||||
VValue = (1-NValue) * PolynomialVIntervals->Value(1)
|
||||
+ NValue * PolynomialVIntervals->Value(2) ;
|
||||
|
||||
// (2.1) Extraction du bon Patch
|
||||
if (Patch_Indice != Uindex + (myUKnots->Length()-1)*(Vindex-1)) {
|
||||
Standard_Integer k1, k2, pos, ll=1;
|
||||
Patch_Indice = Uindex + (myUKnots->Length()-1)*(Vindex-1);
|
||||
for (k1 = 1; k1 <= NumCoeffPerSurface->Value(Patch_Indice, 1); k1++) {
|
||||
pos = SizPatch*(Patch_Indice-1)+3*(MaxVDegree+1)*(k1-1)+1;
|
||||
for (k2 = 1;
|
||||
k2 <= NumCoeffPerSurface->Value(Patch_Indice, 2);
|
||||
k2++, pos+=3 ) {
|
||||
Patch(ll) = Coefficients->Value(pos);
|
||||
Patch(ll+1) = Coefficients->Value(pos+1);
|
||||
Patch(ll+2) = Coefficients->Value(pos+2);
|
||||
ll += 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// (2.2) Positionnement en UValue,VValue
|
||||
PLib::EvalPoly2Var(UValue,VValue,0,0,
|
||||
NumCoeffPerSurface->Value(Patch_Indice,1)-1,
|
||||
NumCoeffPerSurface->Value(Patch_Indice,2)-1,
|
||||
3,
|
||||
Coeffs[0],
|
||||
Digit[0]);
|
||||
|
||||
myPoles->SetValue(ii, jj, gp_Pnt (Digit[0], Digit[1], Digit[2]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// (3)Interpolation --------------------------------------------------------------
|
||||
|
||||
Standard_Integer InversionProblem;
|
||||
BSplSLib::Interpolate(myUDegree, myVDegree,
|
||||
myUFlatKnots->Array1(),
|
||||
myVFlatKnots->Array1(),
|
||||
UParameters->Array1(),
|
||||
VParameters->Array1(),
|
||||
myPoles->ChangeArray2(),
|
||||
InversionProblem);
|
||||
myDone = (InversionProblem == 0);
|
||||
}
|
||||
|
||||
|
||||
void Convert_GridPolynomialToPoles::BuildArray(const Standard_Integer Degree,
|
||||
const Handle(TColStd_HArray1OfReal)& Knots,
|
||||
const Standard_Integer Continuity,
|
||||
Handle(TColStd_HArray1OfReal)& FlatKnots,
|
||||
Handle(TColStd_HArray1OfInteger)& Mults,
|
||||
Handle(TColStd_HArray1OfReal)& Parameters) const
|
||||
{
|
||||
Standard_Integer NumCurves = Knots->Length()-1;
|
||||
|
||||
// Calcul des Multiplicites
|
||||
Standard_Integer ii;
|
||||
Standard_Integer multiplicities = Degree - Continuity;
|
||||
Mults = new (TColStd_HArray1OfInteger)(1, Knots->Length());
|
||||
|
||||
for (ii = 2 ; ii < Knots->Length() ; ii++) {
|
||||
Mults ->SetValue(ii,multiplicities) ;
|
||||
}
|
||||
Mults ->SetValue(1, Degree + 1) ;
|
||||
Mults ->SetValue(NumCurves + 1, Degree + 1) ;
|
||||
|
||||
// Calcul des Noeuds Plats
|
||||
Standard_Integer num_flat_knots = multiplicities * (NumCurves - 1)
|
||||
+ 2 * Degree + 2;
|
||||
FlatKnots =
|
||||
new TColStd_HArray1OfReal(1,num_flat_knots) ;
|
||||
|
||||
BSplCLib::KnotSequence (Knots->Array1(),
|
||||
Mults->Array1(),
|
||||
Degree,
|
||||
Standard_False,
|
||||
FlatKnots->ChangeArray1());
|
||||
|
||||
// Calcul du nombre de Poles
|
||||
Standard_Integer num_poles = num_flat_knots - Degree - 1;
|
||||
|
||||
// Cacul des parametres d'interpolation
|
||||
Parameters = new (TColStd_HArray1OfReal) (1,num_poles);
|
||||
BSplCLib::BuildSchoenbergPoints(Degree,
|
||||
FlatKnots->Array1(),
|
||||
Parameters->ChangeArray1());
|
||||
}
|
||||
|
||||
Standard_Integer Convert_GridPolynomialToPoles::NbUPoles() const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!myDone, "GridPolynomialToPoles");
|
||||
return myPoles->ColLength();
|
||||
}
|
||||
|
||||
Standard_Integer Convert_GridPolynomialToPoles::NbVPoles() const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!myDone, "GridPolynomialToPoles");
|
||||
return myPoles->RowLength();
|
||||
}
|
||||
|
||||
|
||||
const Handle(TColgp_HArray2OfPnt)&
|
||||
Convert_GridPolynomialToPoles::Poles() const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!myDone, "GridPolynomialToPoles");
|
||||
return myPoles;
|
||||
}
|
||||
|
||||
Standard_Integer Convert_GridPolynomialToPoles::UDegree() const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!myDone, "GridPolynomialToPoles");
|
||||
return myUDegree;
|
||||
}
|
||||
|
||||
Standard_Integer Convert_GridPolynomialToPoles::VDegree() const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!myDone, "GridPolynomialToPoles");
|
||||
return myVDegree;
|
||||
}
|
||||
|
||||
Standard_Integer Convert_GridPolynomialToPoles::NbUKnots() const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!myDone, "GridPolynomialToPoles");
|
||||
return myUKnots->Length();
|
||||
}
|
||||
|
||||
Standard_Integer Convert_GridPolynomialToPoles::NbVKnots() const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!myDone, "GridPolynomialToPoles");
|
||||
return myVKnots->Length();
|
||||
}
|
||||
|
||||
const Handle(TColStd_HArray1OfReal)&
|
||||
Convert_GridPolynomialToPoles::UKnots() const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!myDone, "GridPolynomialToPoles");
|
||||
return myUKnots;
|
||||
}
|
||||
|
||||
const Handle(TColStd_HArray1OfReal)&
|
||||
Convert_GridPolynomialToPoles::VKnots() const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!myDone, "GridPolynomialToPoles");
|
||||
return myVKnots;
|
||||
}
|
||||
|
||||
const Handle(TColStd_HArray1OfInteger)&
|
||||
Convert_GridPolynomialToPoles::UMultiplicities() const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!myDone, "GridPolynomialToPoles");
|
||||
return myUMults;
|
||||
}
|
||||
|
||||
const Handle(TColStd_HArray1OfInteger)&
|
||||
Convert_GridPolynomialToPoles::VMultiplicities() const
|
||||
{
|
||||
StdFail_NotDone_Raise_if(!myDone, "GridPolynomialToPoles");
|
||||
return myVMults;
|
||||
}
|
||||
|
||||
Standard_Boolean Convert_GridPolynomialToPoles::IsDone() const
|
||||
{
|
||||
return myDone;
|
||||
}
|
34
src/Convert/Convert_HyperbolaToBSplineCurve.cdl
Executable file
34
src/Convert/Convert_HyperbolaToBSplineCurve.cdl
Executable file
@@ -0,0 +1,34 @@
|
||||
-- File: HyperbolaToBSplineCurve.cdl
|
||||
-- Created: Thu Oct 10 14:48:30 1991
|
||||
-- Author: Jean Claude VAUTHIER
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
|
||||
class HyperbolaToBSplineCurve from Convert inherits ConicToBSplineCurve
|
||||
|
||||
--- Purpose :
|
||||
-- This algorithm converts a hyperbola into a rational B-spline curve.
|
||||
-- The hyperbola is an Hypr2d from package gp with the
|
||||
-- parametrization :
|
||||
-- P (U) =
|
||||
-- Loc + (MajorRadius * Cosh(U) * Xdir + MinorRadius * Sinh(U) * Ydir)
|
||||
-- where Loc is the location point of the hyperbola, Xdir and Ydir are
|
||||
-- the normalized directions of the local cartesian coordinate system
|
||||
-- of the hyperbola.
|
||||
--- KeyWords :
|
||||
-- Convert, Hyperbola, BSplineCurve, 2D .
|
||||
|
||||
uses Hypr2d from gp
|
||||
|
||||
is
|
||||
|
||||
|
||||
Create (H : Hypr2d; U1, U2 : Real) returns HyperbolaToBSplineCurve;
|
||||
--- Purpose :
|
||||
-- The hyperbola H is limited between the parametric values U1, U2
|
||||
-- and the equivalent B-spline curve has the same orientation as the
|
||||
-- hyperbola.
|
||||
|
||||
|
||||
end HyperbolaToBSplineCurve;
|
76
src/Convert/Convert_HyperbolaToBSplineCurve.cxx
Executable file
76
src/Convert/Convert_HyperbolaToBSplineCurve.cxx
Executable file
@@ -0,0 +1,76 @@
|
||||
//File Convert_HyperbolaToBSplineCurve.cxx
|
||||
//JCV 16/10/91
|
||||
|
||||
|
||||
#include <Convert_HyperbolaToBSplineCurve.ixx>
|
||||
#include <TColgp_HArray1OfPnt2d.hxx>
|
||||
#include <TColStd_HArray1OfReal.hxx>
|
||||
#include <TColStd_HArray1OfInteger.hxx>
|
||||
#include <TColStd_Array1OfReal.hxx>
|
||||
#include <TColgp_Array1OfPnt2d.hxx>
|
||||
|
||||
#include <gp.hxx>
|
||||
#include <gp_Ax2d.hxx>
|
||||
#include <gp_Dir2d.hxx>
|
||||
#include <gp_Trsf2d.hxx>
|
||||
|
||||
static Standard_Integer TheDegree = 2;
|
||||
static Standard_Integer MaxNbKnots = 2;
|
||||
static Standard_Integer MaxNbPoles = 3;
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_HyperbolaToBSplineCurve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_HyperbolaToBSplineCurve::Convert_HyperbolaToBSplineCurve
|
||||
(const gp_Hypr2d& H ,
|
||||
const Standard_Real U1,
|
||||
const Standard_Real U2 )
|
||||
|
||||
: Convert_ConicToBSplineCurve (MaxNbPoles, MaxNbKnots, TheDegree)
|
||||
{
|
||||
Standard_DomainError_Raise_if( Abs(U2 - U1) < Epsilon(0.),
|
||||
"Convert_ParabolaToBSplineCurve");
|
||||
|
||||
Standard_Real UF = Min (U1, U2);
|
||||
Standard_Real UL = Max( U1, U2);
|
||||
|
||||
nbPoles = 3;
|
||||
nbKnots = 2;
|
||||
isperiodic = Standard_False;
|
||||
knots->ChangeArray1()(1) = UF; mults->ChangeArray1()(1) = 3;
|
||||
knots->ChangeArray1()(2) = UL; mults->ChangeArray1()(2) = 3;
|
||||
|
||||
// construction de l hyperbole dans le repere de reference xOy.
|
||||
|
||||
Standard_Real R = H.MajorRadius();
|
||||
Standard_Real r = H.MinorRadius();
|
||||
gp_Dir2d Ox = H.Axis().XDirection();
|
||||
gp_Dir2d Oy = H.Axis().YDirection();
|
||||
Standard_Real S = ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.) ? 1 : -1;
|
||||
|
||||
// poles exprimes dans le repere de reference
|
||||
// le 2eme pole est a l intersection des 2 tangentes a la courbe
|
||||
// aux pointx P(UF), P(UL)
|
||||
// le poids de ce pole est egal a : Cosh((UL-UF)/2)
|
||||
|
||||
weights->ChangeArray1()(1) = 1.;
|
||||
weights->ChangeArray1()(2) = Cosh((UL-UF)/2);
|
||||
weights->ChangeArray1()(3) = 1.;
|
||||
|
||||
Standard_Real delta = Sinh(UL-UF);
|
||||
Standard_Real x = R * ( Sinh(UL) - Sinh(UF)) / delta;
|
||||
Standard_Real y = S * r * ( Cosh(UL) - Cosh(UF)) / delta;
|
||||
poles->ChangeArray1()(1) = gp_Pnt2d( R * Cosh(UF), S * r * Sinh(UF));
|
||||
poles->ChangeArray1()(2) = gp_Pnt2d( x, y);
|
||||
poles->ChangeArray1()(3) = gp_Pnt2d( R * Cosh(UL), S * r * Sinh(UL));
|
||||
|
||||
// on replace la bspline dans le repere de l hyperbole
|
||||
gp_Trsf2d Trsf;
|
||||
Trsf.SetTransformation( H.Axis().XAxis(), gp::OX2d());
|
||||
poles->ChangeArray1()(1).Transform( Trsf);
|
||||
poles->ChangeArray1()(2).Transform( Trsf);
|
||||
poles->ChangeArray1()(3).Transform( Trsf);
|
||||
}
|
33
src/Convert/Convert_ParabolaToBSplineCurve.cdl
Executable file
33
src/Convert/Convert_ParabolaToBSplineCurve.cdl
Executable file
@@ -0,0 +1,33 @@
|
||||
-- File: ParabolaToBSplineCurve.cdl
|
||||
-- Created: Thu Oct 10 14:52:24 1991
|
||||
-- Author: Jean Claude VAUTHIER
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
|
||||
class ParabolaToBSplineCurve from Convert inherits ConicToBSplineCurve
|
||||
|
||||
--- Purpose :
|
||||
-- This algorithm converts a parabola into a non rational B-spline
|
||||
-- curve.
|
||||
-- The parabola is a Parab2d from package gp with the parametrization
|
||||
-- P (U) = Loc + F * (U*U * Xdir + 2 * U * Ydir) where Loc is the
|
||||
-- apex of the parabola, Xdir is the normalized direction of the
|
||||
-- symmetry axis of the parabola, Ydir is the normalized direction of
|
||||
-- the directrix and F is the focal length.
|
||||
--- KeyWords :
|
||||
-- Convert, Parabola, BSplineCurve, 2D .
|
||||
|
||||
uses Parab2d from gp
|
||||
|
||||
is
|
||||
|
||||
|
||||
Create (Prb : Parab2d; U1, U2 : Real) returns ParabolaToBSplineCurve;
|
||||
--- Purpose :
|
||||
-- The parabola Prb is limited between the parametric values U1, U2
|
||||
-- and the equivalent B-spline curve as the same orientation as the
|
||||
-- parabola Prb.
|
||||
|
||||
|
||||
end ParabolaToBSplineCurve;
|
71
src/Convert/Convert_ParabolaToBSplineCurve.cxx
Executable file
71
src/Convert/Convert_ParabolaToBSplineCurve.cxx
Executable file
@@ -0,0 +1,71 @@
|
||||
//File Convert_ParabolaToBSplineCurve.cxx
|
||||
//JCV 16/10/91
|
||||
|
||||
|
||||
#include <Convert_ParabolaToBSplineCurve.ixx>
|
||||
|
||||
#include <gp.hxx>
|
||||
#include <gp_Ax2d.hxx>
|
||||
#include <gp_Dir2d.hxx>
|
||||
#include <gp_Trsf2d.hxx>
|
||||
#include <TColgp_HArray1OfPnt2d.hxx>
|
||||
#include <TColStd_HArray1OfReal.hxx>
|
||||
#include <TColStd_HArray1OfInteger.hxx>
|
||||
#include <TColStd_Array1OfReal.hxx>
|
||||
#include <TColgp_Array1OfPnt2d.hxx>
|
||||
|
||||
static Standard_Integer TheDegree = 2;
|
||||
static Standard_Integer MaxNbKnots = 2;
|
||||
static Standard_Integer MaxNbPoles = 3;
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_ParabolaToBSplineCurve
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_ParabolaToBSplineCurve::Convert_ParabolaToBSplineCurve
|
||||
(const gp_Parab2d& Prb,
|
||||
const Standard_Real U1 ,
|
||||
const Standard_Real U2 )
|
||||
: Convert_ConicToBSplineCurve (MaxNbPoles, MaxNbKnots, TheDegree)
|
||||
{
|
||||
Standard_DomainError_Raise_if( Abs(U2 - U1) < Epsilon(0.),
|
||||
"Convert_ParabolaToBSplineCurve");
|
||||
|
||||
Standard_Real UF = Min (U1, U2);
|
||||
Standard_Real UL = Max( U1, U2);
|
||||
|
||||
Standard_Real p = Prb.Parameter();
|
||||
|
||||
nbPoles = 3;
|
||||
nbKnots = 2;
|
||||
isperiodic = Standard_False;
|
||||
knots->ChangeArray1()(1) = UF; mults->ChangeArray1()(1) = 3;
|
||||
knots->ChangeArray1()(2) = UL; mults->ChangeArray1()(2) = 3;
|
||||
|
||||
weights->ChangeArray1()(1) = 1.;
|
||||
weights->ChangeArray1()(2) = 1.;
|
||||
weights->ChangeArray1()(3) = 1.;
|
||||
|
||||
gp_Dir2d Ox = Prb.Axis().XDirection();
|
||||
gp_Dir2d Oy = Prb.Axis().YDirection();
|
||||
Standard_Real S = ( Ox.X() * Oy.Y() - Ox.Y() * Oy.X() > 0.) ? 1 : -1;
|
||||
|
||||
|
||||
// poles exprimes dans le repere de reference
|
||||
poles->ChangeArray1()(1) =
|
||||
gp_Pnt2d( ( UF * UF) / ( 2. * p), S * UF );
|
||||
poles->ChangeArray1()(2) =
|
||||
gp_Pnt2d( ( UF * UL) / ( 2. * p), S * ( UF + UL) / 2. );
|
||||
poles->ChangeArray1()(3) =
|
||||
gp_Pnt2d( ( UL * UL) / ( 2. * p), S * UL );
|
||||
|
||||
// on replace la bspline dans le repere de la parabole.
|
||||
gp_Trsf2d Trsf;
|
||||
Trsf.SetTransformation( Prb.Axis().XAxis(), gp::OX2d());
|
||||
poles->ChangeArray1()(1).Transform( Trsf);
|
||||
poles->ChangeArray1()(2).Transform( Trsf);
|
||||
poles->ChangeArray1()(3).Transform( Trsf);
|
||||
}
|
||||
|
||||
|
289
src/Convert/Convert_PolynomialCosAndSin.cxx
Executable file
289
src/Convert/Convert_PolynomialCosAndSin.cxx
Executable file
@@ -0,0 +1,289 @@
|
||||
// File: Convert_PolynomialCosAndSin.cxx
|
||||
// Created: Tue Oct 10 15:56:28 1995
|
||||
// Author: Jacques GOUSSARD
|
||||
// <jag@bravox>
|
||||
//PMN 4/12/1997 On se ramene toujours sur [0, Delta] pour eviter les cas tordus
|
||||
|
||||
|
||||
#include <Convert_PolynomialCosAndSin.hxx>
|
||||
|
||||
#include <TColgp_Array1OfPnt2d.hxx>
|
||||
#include <gp_Trsf2d.hxx>
|
||||
#include <gp_Pnt2d.hxx>
|
||||
#include <gp_Vec2d.hxx>
|
||||
#include <gp_XY.hxx>
|
||||
|
||||
#include <gp.hxx>
|
||||
#include <Precision.hxx>
|
||||
#include <PLib.hxx>
|
||||
#include <BSplCLib.hxx>
|
||||
|
||||
#include <Standard_ConstructionError.hxx>
|
||||
|
||||
static Standard_Real Locate(const Standard_Real Angfin,
|
||||
const TColgp_Array1OfPnt2d& TPoles,
|
||||
const Standard_Real Umin,
|
||||
const Standard_Real Umax)
|
||||
{
|
||||
Standard_Real umin = Umin;
|
||||
Standard_Real umax = Umax;
|
||||
Standard_Real Ptol = Precision::Angular();
|
||||
Standard_Real Utol = Precision::PConfusion();
|
||||
while (Abs(umax-umin)>= Utol) {
|
||||
Standard_Real ptest = (umax+umin)/2.;
|
||||
gp_Pnt2d valP;
|
||||
BSplCLib::D0(ptest,TPoles,BSplCLib::NoWeights(),valP);
|
||||
Standard_Real theta = ATan2(valP.Y(),valP.X());
|
||||
if (theta < 0.) {
|
||||
theta +=2.*PI;
|
||||
}
|
||||
if (Abs(theta - Angfin) < Ptol) {
|
||||
return ptest;
|
||||
}
|
||||
if (theta < Angfin) {
|
||||
umin = ptest;
|
||||
}
|
||||
else if (theta > Angfin) {
|
||||
umax = ptest;
|
||||
}
|
||||
}
|
||||
return (umin+umax)/2.;
|
||||
}
|
||||
|
||||
|
||||
void BuildPolynomialCosAndSin
|
||||
(const Standard_Real UFirst,
|
||||
const Standard_Real ULast,
|
||||
const Standard_Integer num_poles,
|
||||
Handle(TColStd_HArray1OfReal)& CosNumeratorPtr,
|
||||
Handle(TColStd_HArray1OfReal)& SinNumeratorPtr,
|
||||
Handle(TColStd_HArray1OfReal)& DenominatorPtr)
|
||||
{
|
||||
|
||||
Standard_Real Delta,
|
||||
locUFirst,
|
||||
// locULast,
|
||||
// temp_value,
|
||||
t_min,
|
||||
t_max,
|
||||
trim_min,
|
||||
trim_max,
|
||||
middle,
|
||||
Angle,
|
||||
PI2 = 2*PI ;
|
||||
Standard_Integer ii, degree = num_poles -1 ;
|
||||
locUFirst = UFirst ;
|
||||
|
||||
// On Rammene le UFirst dans [-2PI; 2PI]
|
||||
// afin de faire des rotation sans risque
|
||||
while (locUFirst > PI2) {
|
||||
locUFirst -= PI2;
|
||||
}
|
||||
while (locUFirst < - PI2) {
|
||||
locUFirst += PI2;
|
||||
}
|
||||
|
||||
// on se ramene a l'arc [0, Delta]
|
||||
Delta = ULast - UFirst;
|
||||
middle = 0.5e0 * Delta ;
|
||||
//
|
||||
// on fait coincider la bisectrice du secteur angulaire que l on desire avec
|
||||
// l axe -Ox de definition du cercle en Bezier de degree 7 de sorte que le
|
||||
// parametre 1/2 de la Bezier soit exactement un point de la bissectrice du
|
||||
// secteur angulaire que l on veut.
|
||||
//
|
||||
Angle = middle - PI ;
|
||||
//
|
||||
// Cercle de rayon 1. Voir Euclid
|
||||
//
|
||||
|
||||
TColgp_Array1OfPnt2d TPoles(1,8),
|
||||
NewTPoles(1,8) ;
|
||||
TPoles(1).SetCoord(1.,0.);
|
||||
TPoles(2).SetCoord(1.,1.013854);
|
||||
TPoles(3).SetCoord(-0.199043,1.871905);
|
||||
TPoles(4).SetCoord(-1.937729,1.057323);
|
||||
TPoles(5).SetCoord(-1.937729,-1.057323);
|
||||
TPoles(6).SetCoord(-0.199043,-1.871905);
|
||||
TPoles(7).SetCoord(1.,-1.013854);
|
||||
TPoles(8).SetCoord(1.,0.);
|
||||
gp_Trsf2d T;
|
||||
T.SetRotation(gp::Origin2d(),Angle);
|
||||
for (ii=1; ii<=num_poles; ii++) {
|
||||
TPoles(ii).Transform(T);
|
||||
}
|
||||
|
||||
|
||||
t_min = 1.0e0 - (Delta * 1.3e0 / PI) ;
|
||||
t_min *= 0.5e0 ;
|
||||
t_min = Max(t_min,0.0e0) ;
|
||||
t_max = 1.0e0 + (Delta * 1.3e0 / PI) ;
|
||||
t_max *= 0.5e0 ;
|
||||
t_max = Min(t_max,1.0e0) ;
|
||||
trim_max = Locate(Delta,
|
||||
TPoles,
|
||||
t_min,
|
||||
t_max);
|
||||
//
|
||||
// puisque la Bezier est symetrique par rapport a la bissectrice du
|
||||
// secteur angulaire ...
|
||||
|
||||
trim_min = 1.0e0 - trim_max ;
|
||||
//
|
||||
Standard_Real knot_array[2] ;
|
||||
Standard_Integer mults_array[2] ;
|
||||
knot_array[0] = 0.0e0 ;
|
||||
knot_array[1] = 1.0e0 ;
|
||||
mults_array[0] = degree + 1 ;
|
||||
mults_array[1] = degree + 1 ;
|
||||
|
||||
TColStd_Array1OfReal the_knots(knot_array[0],1,2),
|
||||
the_new_knots(knot_array[0],1,2);
|
||||
TColStd_Array1OfInteger the_mults(mults_array[0],1,2),
|
||||
the_new_mults(mults_array[0],1,2) ;
|
||||
|
||||
BSplCLib::Trimming(degree,
|
||||
Standard_False,
|
||||
the_knots,
|
||||
the_mults,
|
||||
TPoles,
|
||||
BSplCLib::NoWeights(),
|
||||
trim_min,
|
||||
trim_max,
|
||||
the_new_knots,
|
||||
the_new_mults,
|
||||
NewTPoles,
|
||||
BSplCLib::NoWeights());
|
||||
|
||||
// recalage sans doute superflu
|
||||
Standard_Real SinD = Sin(Delta), CosD = Cos(Delta);
|
||||
gp_Pnt2d Pdeb(1., 0.);
|
||||
gp_Pnt2d Pfin(CosD, SinD);
|
||||
|
||||
Standard_Real dtg = NewTPoles(1).Distance(NewTPoles(2));
|
||||
NewTPoles(1) = Pdeb;
|
||||
gp_XY theXY(0.,dtg);
|
||||
Pdeb.ChangeCoord() += theXY;
|
||||
NewTPoles(2) = Pdeb;
|
||||
|
||||
// Recalages a la Euclid
|
||||
dtg = NewTPoles(num_poles).Distance(NewTPoles(num_poles-1));
|
||||
NewTPoles(num_poles) = Pfin;
|
||||
theXY.SetCoord(dtg*SinD,-dtg*CosD);
|
||||
Pfin.ChangeCoord() += theXY;
|
||||
NewTPoles(num_poles-1) = Pfin;
|
||||
|
||||
// Rotation pour se ramener a l'arc [LocUFirst, LocUFirst+Delta]
|
||||
T.SetRotation(gp::Origin2d(), locUFirst);
|
||||
for (ii=1; ii<=num_poles; ii++) {
|
||||
NewTPoles(ii).Transform(T);
|
||||
}
|
||||
|
||||
for (ii=1; ii<=num_poles; ii++) {
|
||||
CosNumeratorPtr->SetValue(ii,NewTPoles(ii).X());
|
||||
SinNumeratorPtr->SetValue(ii,NewTPoles(ii).Y());
|
||||
DenominatorPtr->SetValue(ii,1.);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void BuildHermitePolynomialCosAndSin
|
||||
(const Standard_Real UFirst,
|
||||
const Standard_Real ULast,
|
||||
const Standard_Integer num_poles,
|
||||
Handle(TColStd_HArray1OfReal)& CosNumeratorPtr,
|
||||
Handle(TColStd_HArray1OfReal)& SinNumeratorPtr,
|
||||
Handle(TColStd_HArray1OfReal)& DenominatorPtr)
|
||||
{
|
||||
|
||||
if (num_poles%2 != 0) {
|
||||
Standard_ConstructionError::Raise();
|
||||
}
|
||||
Standard_Integer ii;
|
||||
Standard_Integer ordre_deriv = num_poles/2;
|
||||
Standard_Real ang = ULast - UFirst;
|
||||
Standard_Real Cd = Cos(UFirst);
|
||||
Standard_Real Sd = Sin(UFirst);
|
||||
Standard_Real Cf = Cos(ULast);
|
||||
Standard_Real Sf = Sin(ULast);
|
||||
|
||||
Standard_Integer Degree = num_poles-1;
|
||||
TColStd_Array1OfReal FlatKnots(1,2*num_poles);
|
||||
TColStd_Array1OfReal Parameters(1,num_poles);
|
||||
TColStd_Array1OfInteger ContactOrderArray(1,num_poles);
|
||||
TColgp_Array1OfPnt2d Poles(1,num_poles);
|
||||
TColgp_Array1OfPnt2d TPoles(1,num_poles);
|
||||
|
||||
|
||||
for (ii=1; ii<=num_poles; ii++) {
|
||||
FlatKnots(ii) = 0.;
|
||||
FlatKnots(ii+num_poles) = 1.;
|
||||
}
|
||||
|
||||
Standard_Real coef = 1.;
|
||||
Standard_Real xd,yd,xf,yf;
|
||||
|
||||
for (ii=1; ii<=ordre_deriv; ii++) {
|
||||
Parameters(ii) = 0.;
|
||||
Parameters(ii+ordre_deriv) = 1.;
|
||||
|
||||
ContactOrderArray(ii) = ContactOrderArray(num_poles-ii+1) = ii-1;
|
||||
|
||||
switch ((ii-1)%4) {
|
||||
case 0:
|
||||
{
|
||||
xd = Cd*coef;
|
||||
yd = Sd*coef;
|
||||
xf = Cf*coef;
|
||||
yf = Sf*coef;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
{
|
||||
xd = -Sd*coef;
|
||||
yd = Cd*coef;
|
||||
xf = -Sf*coef;
|
||||
yf = Cf*coef;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
xd = -Cd*coef;
|
||||
yd = -Sd*coef;
|
||||
xf = -Cf*coef;
|
||||
yf = -Sf*coef;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
xd = Sd*coef;
|
||||
yd = -Cd*coef;
|
||||
xf = Sf*coef;
|
||||
yf = -Cf*coef;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
Poles(ii).SetX(xd);
|
||||
Poles(ii).SetY(yd);
|
||||
Poles(num_poles-ii+1).SetX(xf);
|
||||
Poles(num_poles-ii+1).SetY(yf);
|
||||
|
||||
coef *= ang;
|
||||
}
|
||||
|
||||
Standard_Integer InversionPb;
|
||||
BSplCLib::Interpolate(Degree,FlatKnots,Parameters,
|
||||
ContactOrderArray,Poles,InversionPb);
|
||||
|
||||
if (InversionPb !=0) {
|
||||
Standard_ConstructionError::Raise();
|
||||
}
|
||||
for (ii=1; ii<=num_poles; ii++) {
|
||||
CosNumeratorPtr->SetValue(ii,Poles(ii).X());
|
||||
SinNumeratorPtr->SetValue(ii,Poles(ii).Y());
|
||||
DenominatorPtr->SetValue(ii,1.);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
23
src/Convert/Convert_PolynomialCosAndSin.hxx
Executable file
23
src/Convert/Convert_PolynomialCosAndSin.hxx
Executable file
@@ -0,0 +1,23 @@
|
||||
// File: Convert_PolynomialCosAndSin.hxx
|
||||
// Created: Tue Oct 10 15:28:11 1995
|
||||
// Author: Jacques GOUSSARD
|
||||
// <jag@bravox>
|
||||
|
||||
|
||||
#include <TColStd_HArray1OfReal.hxx>
|
||||
#include <TColStd_HArray1OfInteger.hxx>
|
||||
|
||||
#ifndef _Convert_PolynomialCosAnSin_HeaderFile
|
||||
#define _Convert_PolynomialCosAnSin_HeaderFile
|
||||
|
||||
void BuildPolynomialCosAndSin
|
||||
(const Standard_Real,
|
||||
const Standard_Real,
|
||||
const Standard_Integer,
|
||||
Handle(TColStd_HArray1OfReal)&,
|
||||
Handle(TColStd_HArray1OfReal)&,
|
||||
Handle(TColStd_HArray1OfReal)&);
|
||||
|
||||
#endif
|
||||
|
||||
|
68
src/Convert/Convert_SphereToBSplineSurface.cdl
Executable file
68
src/Convert/Convert_SphereToBSplineSurface.cdl
Executable file
@@ -0,0 +1,68 @@
|
||||
-- File: SphereToBSplineSurface.cdl
|
||||
-- Created: Thu Oct 10 15:43:43 1991
|
||||
-- Author: Jean Claude VAUTHIER
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class SphereToBSplineSurface from Convert
|
||||
|
||||
--- Purpose :
|
||||
-- This algorithm converts a bounded Sphere into a rational
|
||||
-- B-spline surface. The sphere is a Sphere from package gp.
|
||||
-- The parametrization of the sphere is
|
||||
-- P (U, V) = Loc + Radius * Sin(V) * Zdir +
|
||||
-- Radius * Cos(V) * (Cos(U)*Xdir + Sin(U)*Ydir)
|
||||
-- where Loc is the center of the sphere Xdir, Ydir and Zdir are the
|
||||
-- normalized directions of the local cartesian coordinate system of
|
||||
-- the sphere. The parametrization range is U [0, 2PI] and
|
||||
-- V [-PI/2, PI/2].
|
||||
--- KeyWords :
|
||||
-- Convert, Sphere, BSplineSurface.
|
||||
|
||||
inherits ElementarySurfaceToBSplineSurface
|
||||
|
||||
uses Sphere from gp
|
||||
|
||||
raises DomainError from Standard
|
||||
|
||||
is
|
||||
|
||||
Create (Sph : Sphere; U1, U2, V1, V2 : Real) returns SphereToBSplineSurface
|
||||
--- Purpose :
|
||||
-- The equivalent B-spline surface as the same orientation as the
|
||||
-- sphere in the U and V parametric directions.
|
||||
raises DomainError;
|
||||
--- Purpose :
|
||||
-- Raised if U1 = U2 or U1 = U2 + 2.0 * Pi
|
||||
-- Raised if V1 = V2.
|
||||
|
||||
|
||||
Create (Sph : Sphere;
|
||||
Param1, Param2 : Real;
|
||||
UTrim : Boolean = Standard_True)
|
||||
returns SphereToBSplineSurface
|
||||
--- Purpose :
|
||||
-- The equivalent B-spline surface as the same orientation
|
||||
-- as the sphere in the U and V parametric directions.
|
||||
raises DomainError;
|
||||
--- Purpose :
|
||||
-- Raised if UTrim = True and Param1 = Param2 or
|
||||
-- Param1 = Param2 + 2.0 * Pi
|
||||
-- Raised if UTrim = False and Param1 = Param2
|
||||
|
||||
|
||||
Create (Sph : Sphere) returns SphereToBSplineSurface;
|
||||
--- Purpose :
|
||||
-- The equivalent B-spline surface as the same orientation
|
||||
-- as the sphere in the U and V parametric directions.
|
||||
|
||||
|
||||
|
||||
end SphereToBSplineSurface;
|
||||
|
||||
|
||||
|
||||
|
310
src/Convert/Convert_SphereToBSplineSurface.cxx
Executable file
310
src/Convert/Convert_SphereToBSplineSurface.cxx
Executable file
@@ -0,0 +1,310 @@
|
||||
//File Convert_SphereToBSplineSurface.cxx
|
||||
//JCV 16/10/91
|
||||
|
||||
#include <Convert_SphereToBSplineSurface.ixx>
|
||||
|
||||
#include <gp.hxx>
|
||||
#include <gp_Trsf.hxx>
|
||||
|
||||
static const Standard_Integer TheUDegree = 2;
|
||||
static const Standard_Integer TheVDegree = 2;
|
||||
static const Standard_Integer MaxNbUKnots = 4;
|
||||
static const Standard_Integer MaxNbVKnots = 3;
|
||||
static const Standard_Integer MaxNbUPoles = 7;
|
||||
static const Standard_Integer MaxNbVPoles = 5;
|
||||
|
||||
|
||||
static void ComputePoles ( const Standard_Real R,
|
||||
const Standard_Real U1,
|
||||
const Standard_Real U2,
|
||||
const Standard_Real V1,
|
||||
const Standard_Real V2,
|
||||
TColgp_Array2OfPnt& Poles)
|
||||
{
|
||||
Standard_Real deltaU = U2 - U1;
|
||||
Standard_Real deltaV = V2 - V1;
|
||||
|
||||
Standard_Integer i, j;
|
||||
|
||||
// Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds)
|
||||
Standard_Integer
|
||||
nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
|
||||
Standard_Integer
|
||||
nbVSpans = (Standard_Integer)IntegerPart( 1.2 * deltaV / PI) + 1;
|
||||
Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
|
||||
Standard_Real AlfaV = deltaV / ( nbVSpans * 2);
|
||||
|
||||
Standard_Integer nbVP = 2 * nbVSpans + 1;
|
||||
|
||||
Standard_Real x[MaxNbVPoles];
|
||||
Standard_Real z[MaxNbVPoles];
|
||||
|
||||
x[0] = R * Cos( V1);
|
||||
z[0] = R * Sin( V1);
|
||||
|
||||
Standard_Real VStart = V1;
|
||||
for ( i = 1; i <= nbVSpans; i++) {
|
||||
x[2*i-1] = R * Cos( VStart + AlfaV) / Cos( AlfaV);
|
||||
z[2*i-1] = R * Sin( VStart + AlfaV) / Cos( AlfaV);
|
||||
x[2*i] = R * Cos( VStart + 2 * AlfaV);
|
||||
z[2*i] = R * Sin( VStart + 2 * AlfaV);
|
||||
VStart += 2*AlfaV;
|
||||
}
|
||||
|
||||
Standard_Real UStart = U1;
|
||||
for ( j = 0; j <= nbVP-1; j++) {
|
||||
Poles( 1, j+1) = gp_Pnt(x[j]*Cos(UStart),x[j]*Sin(UStart),z[j]);
|
||||
}
|
||||
|
||||
for ( i = 1; i <= nbUSpans; i++) {
|
||||
for ( j = 0; j<= nbVP-1; j++) {
|
||||
Poles( 2*i, j+1) = gp_Pnt( x[j] * Cos(UStart+AlfaU) / Cos(AlfaU),
|
||||
x[j] * Sin(UStart+AlfaU) / Cos(AlfaU),
|
||||
z[j] );
|
||||
Poles(2*i+1,j+1) = gp_Pnt( x[j] * Cos(UStart+2*AlfaU),
|
||||
x[j] * Sin(UStart+2*AlfaU),
|
||||
z[j] );
|
||||
}
|
||||
UStart += 2*AlfaU;
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_SphereToBSplineSurface
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_SphereToBSplineSurface::Convert_SphereToBSplineSurface
|
||||
(const gp_Sphere& Sph,
|
||||
const Standard_Real U1 ,
|
||||
const Standard_Real U2 ,
|
||||
const Standard_Real V1 ,
|
||||
const Standard_Real V2 )
|
||||
: Convert_ElementarySurfaceToBSplineSurface (MaxNbUPoles, MaxNbVPoles,
|
||||
MaxNbUKnots, MaxNbVKnots,
|
||||
TheUDegree , TheVDegree)
|
||||
{
|
||||
Standard_Real deltaU = U2 - U1;
|
||||
Standard_Real deltaV = V2 - V1;
|
||||
Standard_DomainError_Raise_if( (deltaU>2*PI) || (deltaU<0.) ||
|
||||
(V1 < -PI/2.0) || (V2 > PI/2),
|
||||
"Convert_SphereToBSplineSurface");
|
||||
|
||||
isuperiodic = Standard_False;
|
||||
isvperiodic = Standard_False;
|
||||
|
||||
Standard_Integer i,j;
|
||||
// construction de la sphere dans le repere de reference xOy.
|
||||
|
||||
// Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds)
|
||||
Standard_Integer
|
||||
nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
|
||||
Standard_Integer
|
||||
nbVSpans = (Standard_Integer)IntegerPart( 1.2 * deltaV / PI) + 1;
|
||||
Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
|
||||
Standard_Real AlfaV = deltaV / ( nbVSpans * 2);
|
||||
|
||||
nbUPoles = 2 * nbUSpans + 1;
|
||||
nbVPoles = 2 * nbVSpans + 1;
|
||||
nbUKnots = nbUSpans + 1;
|
||||
nbVKnots = nbVSpans + 1;
|
||||
|
||||
Standard_Real R = Sph.Radius();
|
||||
|
||||
ComputePoles( R, U1, U2, V1, V2, poles);
|
||||
|
||||
for ( i = 1; i<= nbUKnots; i++) {
|
||||
uknots(i) = U1 + (i-1) * 2 * AlfaU;
|
||||
umults(i) = 2;
|
||||
}
|
||||
umults(1)++; umults(nbUKnots)++;
|
||||
for ( i = 1; i<= nbVKnots; i++) {
|
||||
vknots(i) = V1 + (i-1) * 2 * AlfaV;
|
||||
vmults(i) = 2;
|
||||
}
|
||||
vmults(1)++; vmults(nbVKnots)++;
|
||||
|
||||
|
||||
// On replace la bspline dans le repere de la sphere.
|
||||
// et on calcule les poids de la bspline.
|
||||
Standard_Real W1, W2;
|
||||
gp_Trsf Trsf;
|
||||
Trsf.SetTransformation( Sph.Position(), gp::XOY());
|
||||
|
||||
for ( i = 1; i <= nbUPoles; i++) {
|
||||
if ( i % 2 == 0) W1 = Cos(AlfaU);
|
||||
else W1 = 1.;
|
||||
|
||||
for ( j = 1; j <= nbVPoles; j++) {
|
||||
if ( j % 2 == 0) W2 = Cos(AlfaV);
|
||||
else W2 = 1.;
|
||||
|
||||
weights( i, j) = W1 * W2;
|
||||
poles( i, j).Transform( Trsf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_SphereToBSplineSurface
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_SphereToBSplineSurface::Convert_SphereToBSplineSurface
|
||||
(const gp_Sphere& Sph ,
|
||||
const Standard_Real Param1,
|
||||
const Standard_Real Param2,
|
||||
const Standard_Boolean UTrim )
|
||||
: Convert_ElementarySurfaceToBSplineSurface (MaxNbUPoles, MaxNbVPoles,
|
||||
MaxNbUKnots, MaxNbVKnots,
|
||||
TheUDegree , TheVDegree)
|
||||
{
|
||||
#ifndef No_Exception
|
||||
Standard_Real delta = Param2 - Param1;
|
||||
#endif
|
||||
Standard_DomainError_Raise_if( (delta>2*PI) || (delta<0.),
|
||||
"Convert_SphereToBSplineSurface");
|
||||
|
||||
Standard_Integer i, j;
|
||||
Standard_Real deltaU, deltaV;
|
||||
|
||||
isuperiodic = !UTrim;
|
||||
isvperiodic = Standard_False;
|
||||
|
||||
Standard_Real R = Sph.Radius();
|
||||
|
||||
Standard_Real W1, W2, CosU, CosV;
|
||||
|
||||
if ( isuperiodic) {
|
||||
ComputePoles(R, 0., 2.*PI, Param1, Param2, poles);
|
||||
|
||||
nbUPoles = 6;
|
||||
nbUKnots = 4;
|
||||
|
||||
deltaV = Param2 - Param1;
|
||||
Standard_Integer
|
||||
nbVSpans = (Standard_Integer)IntegerPart( 1.2 * deltaV / PI) + 1;
|
||||
Standard_Real AlfaV = deltaV / ( nbVSpans * 2);
|
||||
nbVPoles = 2 * nbVSpans + 1;
|
||||
nbVKnots = nbVSpans + 1;
|
||||
|
||||
for ( i = 1; i <= nbUKnots; i++) {
|
||||
uknots(i) = ( i-1) * 2. * PI /3.;
|
||||
umults(i) = 2;
|
||||
}
|
||||
for ( i = 1; i <= nbVKnots; i++) {
|
||||
vknots(i) = Param1 + (i-1) * 2 * AlfaV;
|
||||
vmults(i) = 2;
|
||||
}
|
||||
vmults(1)++; vmults(nbVKnots)++;
|
||||
|
||||
CosU = 0.5; // = Cos(pi /3)
|
||||
CosV = Cos(AlfaV);
|
||||
}
|
||||
else {
|
||||
ComputePoles(R, Param1, Param2, -PI/2., PI/2., poles);
|
||||
|
||||
nbVPoles = 5;
|
||||
nbVKnots = 3;
|
||||
|
||||
deltaU = Param2 - Param1;
|
||||
Standard_Integer
|
||||
nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
|
||||
Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
|
||||
nbUPoles = 2 * nbUSpans + 1;
|
||||
nbUKnots = nbUSpans + 1;
|
||||
|
||||
vknots(1) = -PI/2.; vmults(1) = 3;
|
||||
vknots(2) = 0.; vmults(2) = 2;
|
||||
vknots(3) = PI/2.; vmults(3) = 3;
|
||||
for ( i = 1; i <= nbUKnots; i++) {
|
||||
uknots(i) = Param1 + (i-1) * 2 * AlfaU;
|
||||
umults(i) = 2;
|
||||
}
|
||||
umults(1)++; umults(nbUKnots)++;
|
||||
|
||||
CosV = 0.5; // = Cos(pi /3)
|
||||
CosU = Cos(AlfaU);
|
||||
}
|
||||
|
||||
// On replace la bspline dans le repere de la sphere.
|
||||
// et on calcule les poids de la bspline.
|
||||
gp_Trsf Trsf;
|
||||
Trsf.SetTransformation( Sph.Position(), gp::XOY());
|
||||
|
||||
for ( i = 1; i <= nbUPoles; i++) {
|
||||
if ( i % 2 == 0) W1 = CosU;
|
||||
else W1 = 1.;
|
||||
|
||||
for ( j = 1; j <= nbVPoles; j++) {
|
||||
if ( j % 2 == 0) W2 = CosV;
|
||||
else W2 = 1.;
|
||||
|
||||
weights( i, j) = W1 * W2;
|
||||
poles( i, j).Transform( Trsf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_SphereToBSplineSurface
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_SphereToBSplineSurface::Convert_SphereToBSplineSurface
|
||||
(const gp_Sphere& Sph)
|
||||
: Convert_ElementarySurfaceToBSplineSurface (MaxNbUPoles, MaxNbVPoles,
|
||||
MaxNbUKnots, MaxNbVKnots,
|
||||
TheUDegree , TheVDegree)
|
||||
{
|
||||
isuperiodic = Standard_True;
|
||||
isvperiodic = Standard_False;
|
||||
|
||||
Standard_Real W1, W2;
|
||||
Standard_Integer i, j;
|
||||
|
||||
nbUPoles = 6;
|
||||
nbVPoles = 5;
|
||||
nbUKnots = 4;
|
||||
nbVKnots = 3;
|
||||
|
||||
// Construction de la sphere dans le repere reference xOy.
|
||||
|
||||
Standard_Real R = Sph.Radius();
|
||||
|
||||
ComputePoles( R, 0., 2.*PI, -PI/2., PI/2., poles);
|
||||
|
||||
uknots( 1) = 0.;
|
||||
uknots( 2) = 2. * PI / 3.;
|
||||
uknots( 3) = 4. * PI / 3.;
|
||||
uknots( 4) = 2. * PI;
|
||||
vknots( 1) = -PI/2.;
|
||||
vknots( 2) = 0.;
|
||||
vknots( 3) = PI/2.;
|
||||
for ( i = 1; i <= 4; i++) {
|
||||
umults( i) = 2;
|
||||
}
|
||||
vmults(1) = vmults(3) = 3;
|
||||
vmults(2) = 2;
|
||||
|
||||
// On replace la bspline dans le repere de la sphere.
|
||||
// et on calcule les poids de la bspline.
|
||||
gp_Trsf Trsf;
|
||||
Trsf.SetTransformation( Sph.Position(), gp::XOY());
|
||||
|
||||
for ( i = 1; i <= nbUPoles; i++) {
|
||||
if ( i % 2 == 0) W1 = 0.5;
|
||||
else W1 = 1.;
|
||||
|
||||
for ( j = 1; j <= nbVPoles; j++) {
|
||||
if ( j % 2 == 0) W2 = Sqrt(2.) /2.;
|
||||
else W2 = 1.;
|
||||
|
||||
weights( i, j) = W1 * W2;
|
||||
poles( i, j).Transform( Trsf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
64
src/Convert/Convert_TorusToBSplineSurface.cdl
Executable file
64
src/Convert/Convert_TorusToBSplineSurface.cdl
Executable file
@@ -0,0 +1,64 @@
|
||||
-- File: TorusToBSplineSurface.cdl
|
||||
-- Created: Thu Oct 10 15:57:19 1991
|
||||
-- Author: Jean Claude VAUTHIER
|
||||
---Copyright: Matra Datavision 1991, 1992
|
||||
|
||||
|
||||
|
||||
|
||||
class TorusToBSplineSurface from Convert
|
||||
|
||||
--- Purpose :
|
||||
-- This algorithm converts a bounded Torus into a rational
|
||||
-- B-spline surface. The torus is a Torus from package gp.
|
||||
-- The parametrization of the torus is :
|
||||
-- P (U, V) =
|
||||
-- Loc + MinorRadius * Sin(V) * Zdir +
|
||||
-- (MajorRadius+MinorRadius*Cos(V)) * (Cos(U)*Xdir + Sin(U)*Ydir)
|
||||
-- where Loc is the center of the torus, Xdir, Ydir and Zdir are the
|
||||
-- normalized directions of the local cartesian coordinate system of
|
||||
-- the Torus. The parametrization range is U [0, 2PI], V [0, 2PI].
|
||||
--- KeyWords :
|
||||
-- Convert, Torus, BSplineSurface.
|
||||
|
||||
inherits ElementarySurfaceToBSplineSurface
|
||||
|
||||
uses Torus from gp
|
||||
|
||||
raises DomainError from Standard
|
||||
|
||||
is
|
||||
|
||||
Create (T : Torus; U1, U2, V1, V2 : Real) returns TorusToBSplineSurface
|
||||
--- Purpose :
|
||||
-- The equivalent B-spline surface as the same orientation as the
|
||||
-- torus in the U and V parametric directions.
|
||||
raises DomainError;
|
||||
--- Purpose :
|
||||
-- Raised if U1 = U2 or U1 = U2 + 2.0 * Pi
|
||||
-- Raised if V1 = V2 or V1 = V2 + 2.0 * Pi
|
||||
|
||||
|
||||
Create (T : Torus;
|
||||
Param1, Param2 : Real;
|
||||
UTrim : Boolean = Standard_True)
|
||||
returns TorusToBSplineSurface
|
||||
--- Purpose :
|
||||
-- The equivalent B-spline surface as the same orientation as the
|
||||
-- torus in the U and V parametric directions.
|
||||
raises DomainError;
|
||||
--- Purpose :
|
||||
-- Raised if Param1 = Param2 or Param1 = Param2 + 2.0 * Pi
|
||||
|
||||
|
||||
Create (T : Torus) returns TorusToBSplineSurface;
|
||||
--- Purpose :
|
||||
-- The equivalent B-spline surface as the same orientation as the
|
||||
-- torus in the U and V parametric directions.
|
||||
|
||||
|
||||
end TorusToBSplineSurface;
|
||||
|
||||
|
||||
|
||||
|
311
src/Convert/Convert_TorusToBSplineSurface.cxx
Executable file
311
src/Convert/Convert_TorusToBSplineSurface.cxx
Executable file
@@ -0,0 +1,311 @@
|
||||
//File Convert_TorusToBSplineSurface.cxx
|
||||
//JCV 16/10/91
|
||||
|
||||
#include <Convert_TorusToBSplineSurface.ixx>
|
||||
|
||||
#include <gp.hxx>
|
||||
#include <gp_Trsf.hxx>
|
||||
|
||||
static const Standard_Integer TheUDegree = 2;
|
||||
static const Standard_Integer TheVDegree = 2;
|
||||
static const Standard_Integer MaxNbUKnots = 4;
|
||||
static const Standard_Integer MaxNbVKnots = 4;
|
||||
static const Standard_Integer MaxNbUPoles = 7;
|
||||
static const Standard_Integer MaxNbVPoles = 7;
|
||||
|
||||
|
||||
static void ComputePoles ( const Standard_Real R,
|
||||
const Standard_Real r,
|
||||
const Standard_Real U1,
|
||||
const Standard_Real U2,
|
||||
const Standard_Real V1,
|
||||
const Standard_Real V2,
|
||||
TColgp_Array2OfPnt& Poles)
|
||||
{
|
||||
Standard_Real deltaU = U2 - U1;
|
||||
Standard_Real deltaV = V2 - V1;
|
||||
|
||||
Standard_Integer i, j;
|
||||
|
||||
// Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds)
|
||||
Standard_Integer
|
||||
nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
|
||||
Standard_Integer
|
||||
nbVSpans = (Standard_Integer)IntegerPart( 1.2 * deltaV / PI) + 1;
|
||||
Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
|
||||
Standard_Real AlfaV = deltaV / ( nbVSpans * 2);
|
||||
|
||||
Standard_Integer nbVP = 2 * nbVSpans + 1;
|
||||
|
||||
Standard_Real x[MaxNbVPoles];
|
||||
Standard_Real z[MaxNbVPoles];
|
||||
|
||||
x[0] = R + r * Cos( V1);
|
||||
z[0] = r * Sin( V1);
|
||||
|
||||
Standard_Real VStart = V1;
|
||||
for ( i = 1; i <= nbVSpans; i++) {
|
||||
x[2*i-1] = R + r * Cos( VStart + AlfaV) / Cos( AlfaV);
|
||||
z[2*i-1] = r * Sin( VStart + AlfaV) / Cos( AlfaV);
|
||||
x[2*i] = R + r * Cos( VStart + 2 * AlfaV);
|
||||
z[2*i] = r * Sin( VStart + 2 * AlfaV);
|
||||
VStart += 2*AlfaV;
|
||||
}
|
||||
|
||||
Standard_Real UStart = U1;
|
||||
for ( j = 0; j <= nbVP-1; j++) {
|
||||
Poles( 1, j+1) = gp_Pnt(x[j]*Cos(UStart),x[j]*Sin(UStart),z[j]);
|
||||
}
|
||||
|
||||
for ( i = 1; i <= nbUSpans; i++) {
|
||||
for ( j = 0; j<= nbVP-1; j++) {
|
||||
Poles( 2*i, j+1) = gp_Pnt( x[j] * Cos(UStart+AlfaU) / Cos(AlfaU),
|
||||
x[j] * Sin(UStart+AlfaU) / Cos(AlfaU),
|
||||
z[j] );
|
||||
Poles(2*i+1,j+1) = gp_Pnt( x[j] * Cos(UStart+2*AlfaU),
|
||||
x[j] * Sin(UStart+2*AlfaU),
|
||||
z[j] );
|
||||
}
|
||||
UStart += 2*AlfaU;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_TorusToBSplineSurface
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_TorusToBSplineSurface::Convert_TorusToBSplineSurface
|
||||
(const gp_Torus& T,
|
||||
const Standard_Real U1,
|
||||
const Standard_Real U2,
|
||||
const Standard_Real V1,
|
||||
const Standard_Real V2)
|
||||
: Convert_ElementarySurfaceToBSplineSurface (MaxNbUPoles, MaxNbVPoles,
|
||||
MaxNbUKnots, MaxNbVKnots,
|
||||
TheUDegree , TheVDegree)
|
||||
{
|
||||
Standard_Real deltaU = U2 - U1;
|
||||
Standard_Real deltaV = V2 - V1;
|
||||
Standard_DomainError_Raise_if( (deltaU>2*PI) || (deltaU<0.) ||
|
||||
(deltaV>2*PI) || (deltaV<0.),
|
||||
"Convert_TorusToBSplineSurface");
|
||||
|
||||
isuperiodic = Standard_False;
|
||||
isvperiodic = Standard_False;
|
||||
|
||||
Standard_Integer i,j;
|
||||
// construction du tore dans le repere de reference xOy.
|
||||
|
||||
// Nombre de spans : ouverture maximale = 150 degres ( = PI / 1.2 rds)
|
||||
Standard_Integer
|
||||
nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
|
||||
Standard_Integer
|
||||
nbVSpans = (Standard_Integer)IntegerPart( 1.2 * deltaV / PI) + 1;
|
||||
Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
|
||||
Standard_Real AlfaV = deltaV / ( nbVSpans * 2);
|
||||
|
||||
nbUPoles = 2 * nbUSpans + 1;
|
||||
nbVPoles = 2 * nbVSpans + 1;
|
||||
nbUKnots = nbUSpans + 1;
|
||||
nbVKnots = nbVSpans + 1;
|
||||
|
||||
Standard_Real R = T.MajorRadius();
|
||||
Standard_Real r = T.MinorRadius();
|
||||
|
||||
ComputePoles( R, r, U1, U2, V1, V2, poles);
|
||||
|
||||
for ( i = 1; i<= nbUKnots; i++) {
|
||||
uknots(i) = U1 + (i-1) * 2 * AlfaU;
|
||||
umults(i) = 2;
|
||||
}
|
||||
umults(1)++; umults(nbUKnots)++;
|
||||
for ( i = 1; i<= nbVKnots; i++) {
|
||||
vknots(i) = V1 + (i-1) * 2 * AlfaV;
|
||||
vmults(i) = 2;
|
||||
}
|
||||
vmults(1)++; vmults(nbVKnots)++;
|
||||
|
||||
|
||||
// On replace la bspline dans le repere du tore.
|
||||
// et on calcule les poids de la bspline.
|
||||
Standard_Real W1, W2;
|
||||
gp_Trsf Trsf;
|
||||
Trsf.SetTransformation( T.Position(), gp::XOY());
|
||||
|
||||
for ( i = 1; i <= nbUPoles; i++) {
|
||||
if ( i % 2 == 0) W1 = Cos(AlfaU);
|
||||
else W1 = 1.;
|
||||
|
||||
for ( j = 1; j <= nbVPoles; j++) {
|
||||
if ( j % 2 == 0) W2 = Cos(AlfaV);
|
||||
else W2 = 1.;
|
||||
|
||||
weights( i, j) = W1 * W2;
|
||||
poles( i, j).Transform( Trsf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_TorusToBSplineSurface
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_TorusToBSplineSurface::Convert_TorusToBSplineSurface
|
||||
(const gp_Torus& T,
|
||||
const Standard_Real Param1,
|
||||
const Standard_Real Param2,
|
||||
const Standard_Boolean UTrim )
|
||||
: Convert_ElementarySurfaceToBSplineSurface (MaxNbUPoles, MaxNbVPoles,
|
||||
MaxNbUKnots, MaxNbVKnots,
|
||||
TheUDegree , TheVDegree)
|
||||
{
|
||||
#ifndef No_Exception
|
||||
Standard_Real delta = Param2 - Param1;
|
||||
#endif
|
||||
Standard_DomainError_Raise_if( (delta>2*PI) || (delta<0.),
|
||||
"Convert_TorusToBSplineSurface");
|
||||
|
||||
Standard_Integer i, j;
|
||||
Standard_Real deltaU, deltaV;
|
||||
|
||||
isuperiodic = !UTrim;
|
||||
isvperiodic = UTrim;
|
||||
|
||||
Standard_Real R = T.MajorRadius();
|
||||
Standard_Real r = T.MinorRadius();
|
||||
|
||||
Standard_Real W1, W2, CosU, CosV;
|
||||
|
||||
if ( isuperiodic) {
|
||||
ComputePoles(R, r, 0, 2.*PI, Param1, Param2, poles);
|
||||
|
||||
nbUPoles = 6;
|
||||
nbUKnots = 4;
|
||||
|
||||
deltaV = Param2 - Param1;
|
||||
Standard_Integer
|
||||
nbVSpans = (Standard_Integer)IntegerPart( 1.2 * deltaV / PI) + 1;
|
||||
Standard_Real AlfaV = deltaV / ( nbVSpans * 2);
|
||||
nbVPoles = 2 * nbVSpans + 1;
|
||||
nbVKnots = nbVSpans + 1;
|
||||
|
||||
for ( i = 1; i <= nbUKnots; i++) {
|
||||
uknots(i) = ( i-1) * 2. * PI /3.;
|
||||
umults(i) = 2;
|
||||
}
|
||||
for ( i = 1; i <= nbVKnots; i++) {
|
||||
vknots(i) = Param1 + (i-1) * 2 * AlfaV;
|
||||
vmults(i) = 2;
|
||||
}
|
||||
vmults(1)++; vmults(nbVKnots)++;
|
||||
|
||||
CosU = 0.5; // = Cos(pi /3)
|
||||
CosV = Cos(AlfaV);
|
||||
}
|
||||
else {
|
||||
ComputePoles(R, r, Param1, Param2, 0., 2.*PI, poles);
|
||||
|
||||
nbVPoles = 6;
|
||||
nbVKnots = 4;
|
||||
|
||||
deltaU = Param2 - Param1;
|
||||
Standard_Integer
|
||||
nbUSpans = (Standard_Integer)IntegerPart( 1.2 * deltaU / PI) + 1;
|
||||
Standard_Real AlfaU = deltaU / ( nbUSpans * 2);
|
||||
nbUPoles = 2 * nbUSpans + 1;
|
||||
nbUKnots = nbUSpans + 1;
|
||||
|
||||
for ( i = 1; i <= nbVKnots; i++) {
|
||||
vknots(i) = ( i-1) * 2. * PI /3.;
|
||||
vmults(i) = 2;
|
||||
}
|
||||
for ( i = 1; i <= nbUKnots; i++) {
|
||||
uknots(i) = Param1 + (i-1) * 2 * AlfaU;
|
||||
umults(i) = 2;
|
||||
}
|
||||
umults(1)++; umults(nbUKnots)++;
|
||||
|
||||
CosV = 0.5; // = Cos(pi /3)
|
||||
CosU = Cos(AlfaU);
|
||||
}
|
||||
|
||||
// On replace la bspline dans le repere du tore.
|
||||
// et on calcule les poids de la bspline.
|
||||
gp_Trsf Trsf;
|
||||
Trsf.SetTransformation( T.Position(), gp::XOY());
|
||||
|
||||
for ( i = 1; i <= nbUPoles; i++) {
|
||||
if ( i % 2 == 0) W1 = CosU;
|
||||
else W1 = 1.;
|
||||
|
||||
for ( j = 1; j <= nbVPoles; j++) {
|
||||
if ( j % 2 == 0) W2 = CosV;
|
||||
else W2 = 1.;
|
||||
|
||||
weights( i, j) = W1 * W2;
|
||||
poles( i, j).Transform( Trsf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//=======================================================================
|
||||
//function : Convert_TorusToBSplineSurface
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Convert_TorusToBSplineSurface::Convert_TorusToBSplineSurface
|
||||
(const gp_Torus& T )
|
||||
: Convert_ElementarySurfaceToBSplineSurface (MaxNbUPoles, MaxNbVPoles,
|
||||
MaxNbUKnots, MaxNbVKnots,
|
||||
TheUDegree , TheVDegree )
|
||||
{
|
||||
isuperiodic = Standard_True;
|
||||
isvperiodic = Standard_True;
|
||||
|
||||
Standard_Real W1, W2;
|
||||
Standard_Integer i, j;
|
||||
|
||||
nbUPoles = 6;
|
||||
nbVPoles = 6;
|
||||
nbUKnots = 4;
|
||||
nbVKnots = 4;
|
||||
|
||||
// Construction du Tore dans le repere reference xOy.
|
||||
|
||||
Standard_Real R = T.MajorRadius();
|
||||
Standard_Real r = T.MinorRadius();
|
||||
|
||||
ComputePoles( R, r, 0., 2.*PI, 0., 2.*PI, poles);
|
||||
|
||||
uknots( 1) = vknots( 1) = 0.;
|
||||
uknots( 2) = vknots( 2) = 2. * PI / 3.;
|
||||
uknots( 3) = vknots( 3) = 4. * PI / 3.;
|
||||
uknots( 4) = vknots( 4) = 2. * PI;
|
||||
for ( i = 1; i <= 4; i++) {
|
||||
umults( i) = vmults( i) = 2;
|
||||
}
|
||||
|
||||
// On replace la bspline dans le repere du tore.
|
||||
// et on calcule les poids de la bspline.
|
||||
gp_Trsf Trsf;
|
||||
Trsf.SetTransformation( T.Position(), gp::XOY());
|
||||
|
||||
for ( i = 1; i <= nbUPoles; i++) {
|
||||
if ( i % 2 == 0) W1 = 0.5;
|
||||
else W1 = 1.;
|
||||
|
||||
for ( j = 1; j <= nbVPoles; j++) {
|
||||
if ( j % 2 == 0) W2 = 0.5;
|
||||
else W2 = 1.;
|
||||
|
||||
weights( i, j) = W1 * W2;
|
||||
poles( i, j).Transform( Trsf);
|
||||
}
|
||||
}
|
||||
}
|
3
src/Convert/FILES
Executable file
3
src/Convert/FILES
Executable file
@@ -0,0 +1,3 @@
|
||||
Convert_CosAndSinEvalFunction.hxx
|
||||
Convert_PolynomialCosAndSin.hxx
|
||||
Convert_PolynomialCosAndSin.cxx
|
Reference in New Issue
Block a user