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

Integration of OCCT 6.5.0 from SVN

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

97
src/Geom2dAPI/Geom2dAPI.cdl Executable file
View File

@@ -0,0 +1,97 @@
-- File: Geom2dAPI.cdl
-- Created: Wed Mar 23 15:00:46 1994
-- Author: Bruno DUMORTIER
-- <dub@fuegox>
---Copyright: Matra Datavision 1994
package Geom2dAPI
---Purpose: The Geom2dAPI package provides an Application
-- Programming Interface for the Geometry.
--
-- The API is a set of classes aiming to provide :
--
-- * High level and simple calls for the most common
-- operations.
--
-- * Keeping an access on the low-level
-- implementation of high-level calls.
--
--
-- The API provides classes to call the algorithmes
-- of the Geometry
--
-- * The constructors of the classes provides the
-- different constructions methods.
--
-- * The class keeps as fields the different tools
-- used by the algorithmes
--
-- * The class provides a casting method to get
-- automatically the result with a function-like
-- call.
--
-- For example to evaluate the distance <D> between a
-- point <P> and a curve <C>, one can writes :
--
-- D = Geom2dAPI_ProjectPointOnCurve(P,C);
--
-- or
--
-- Geom2dAPI_ProjectPointOnCurve PonC(P,C);
-- D = PonC.LowerDistance();
--
uses
Geom2d,
gp,
TColgp,
Extrema,
Geom2dAdaptor,
Geom2dInt,
GeomAbs,
TColStd,
Quantity,
Approx,
StdFail
is
------------------------------------------------------------------
-- This classes provides algo to evaluate the distance between
-- points and curves, curves and curves.
------------------------------------------------------------------
class ProjectPointOnCurve;
class ExtremaCurveCurve;
------------------------------------------------------------------
-- This classes provides algo to evaluate a curve passing through
-- an array of points.
------------------------------------------------------------------
--- Approximation:
--
class PointsToBSpline;
--- Interpolation:
--
class Interpolate;
------------------------------------------------------------------
-- This classes provides algo to evaluate an intersection between
-- two 2d-Curves.
------------------------------------------------------------------
class InterCurveCurve;
end Geom2dAPI;

View File

@@ -0,0 +1,173 @@
-- File: Geom2dAPI_ExtremaCurveCurve.cdl
-- Created: Wed Mar 23 15:09:47 1994
-- Author: Bruno DUMORTIER
-- <dub@fuegox>
---Copyright: Matra Datavision 1994
class ExtremaCurveCurve from Geom2dAPI
---Purpose: Describes functions for computing all the extrema
-- between two 2D curves.
-- An ExtremaCurveCurve algorithm minimizes or
-- maximizes the distance between a point on the first
-- curve and a point on the second curve. Thus, it
-- computes the start point and end point of
-- perpendiculars common to the two curves (an
-- intersection point is not an extremum except where
-- the two curves are tangential at this point).
-- Solutions consist of pairs of points, and an extremum
-- is considered to be a segment joining the two points of a solution.
-- An ExtremaCurveCurve object provides a framework for:
-- - defining the construction of the extrema,
-- - implementing the construction algorithm, and
-- - consulting the results.
-- Warning
-- In some cases, the nearest points between two
-- curves do not correspond to one of the computed
-- extrema. Instead, they may be given by:
-- - a limit point of one curve and one of the following:
-- - its orthogonal projection on the other curve,
-- - a limit point of the other curve; or
-- - an intersection point between the two curves.
uses
Curve from Geom2d,
Curve from Geom2dAdaptor,
ExtCC2d from Extrema,
Pnt2d from gp,
Length from Quantity,
Parameter from Quantity
raises
OutOfRange from Standard,
NotDone from StdFail
is
Create(C1 , C2 : Curve from Geom2d;
U1min, U1max : Parameter from Quantity;
U2min, U2max : Parameter from Quantity)
---Purpose: Computes the extrema between
-- - the portion of the curve C1 limited by the two
-- points of parameter (U1min,U1max), and
-- - the portion of the curve C2 limited by the two
-- points of parameter (U2min,U2max).
-- Warning
-- Use the function NbExtrema to obtain the number
-- of solutions. If this algorithm fails, NbExtrema returns 0.
returns ExtremaCurveCurve from Geom2dAPI;
--------------------------------------------
-- on ne peut pas utiliser le constructeur vide
-- car n existe pas dans Geom2dExtrema_ExtCC
--------------------------------------------
-- Init(me : in out;
-- C1 , C2 : Curve from Geom2d;
-- U1min, U1max : Parameter from Quantity;
-- U2min, U2max : Parameter from Quantity)
-- is static;
NbExtrema(me)
---Purpose: Returns the number of extrema computed by this algorithm.
-- Note: if this algorithm fails, NbExtrema returns 0.
returns Integer from Standard
---C++: alias "Standard_EXPORT operator Standard_Integer() const;"
is static;
Points(me; Index : Integer from Standard;
P1, P2 : out Pnt2d from gp )
---Purpose: Returns the points P1 on the first curve and P2 on
-- the second curve, which are the ends of the
-- extremum of index Index computed by this algorithm.
-- Exceptions
-- Standard_OutOfRange if Index is not in the range [
-- 1,NbExtrema ], where NbExtrema is the
-- number of extrema computed by this algorithm.
raises
OutOfRange from Standard
is static;
Parameters(me; Index : Integer from Standard;
U1, U2 : out Parameter from Quantity)
---Purpose: Returns the parameters U1 of the point on the first
-- curve and U2 of the point on the second curve, which
-- are the ends of the extremum of index Index
-- computed by this algorithm.
-- Exceptions
-- Standard_OutOfRange if Index is not in the range [
-- 1,NbExtrema ], where NbExtrema is the
-- number of extrema computed by this algorithm.
raises
OutOfRange from Standard
is static;
Distance(me; Index : Integer from Standard)
returns Length from Quantity
---Purpose: Computes the distance between the end points of the
-- extremum of index Index computed by this algorithm.
-- Exceptions
-- Standard_OutOfRange if Index is not in the range [
-- 1,NbExtrema ], where NbExtrema is the
-- number of extrema computed by this algorithm.
raises
OutOfRange from Standard
is static;
NearestPoints(me; P1, P2 : out Pnt2d from gp)
---Purpose: Returns the points P1 on the first curve and P2 on
-- the second curve, which are the ends of the shortest
-- extremum computed by this algorithm.
-- Exceptions StdFail_NotDone if this algorithm fails.
raises
NotDone from StdFail
is static;
LowerDistanceParameters(me; U1, U2 : out Parameter from Quantity)
---Purpose: Returns the parameters U1 of the point on the first
-- curve and U2 of the point on the second curve, which
-- are the ends of the shortest extremum computed by this algorithm.
-- Exceptions
-- StdFail_NotDone if this algorithm fails.
raises
NotDone from StdFail
is static;
LowerDistance(me)
---Purpose: Computes the distance between the end points of the
-- shortest extremum computed by this algorithm.
-- Exceptions - StdFail_NotDone if this algorithm fails.
returns Length from Quantity
---C++: alias "Standard_EXPORT operator Standard_Real() const;"
raises
NotDone from StdFail
is static;
Extrema(me)
---Level: Advanced
---C++: return const&
---C++: inline
returns ExtCC2d from Extrema
is static;
fields
myIsDone: Boolean from Standard;
myIndex : Integer from Standard; -- index of the nearest solution
myExtCC : ExtCC2d from Extrema;
myC1 : Curve from Geom2dAdaptor;
myC2 : Curve from Geom2dAdaptor;
end ExtremaCurveCurve;

View File

@@ -0,0 +1,198 @@
// File: Geom2dAPI_ExtremaCurveCurve.cxx
// Created: Wed Mar 23 15:22:12 1994
// Author: Bruno DUMORTIER
// <dub@fuegox>
#include <Geom2dAPI_ExtremaCurveCurve.ixx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Extrema_POnCurv2d.hxx>
#include <Precision.hxx>
//=======================================================================
//function : Geom2dAPI_ExtremaCurveCurve
//purpose :
//=======================================================================
//Geom2dAPI_ExtremaCurveCurve::Geom2dAPI_ExtremaCurveCurve()
//{
//}
//=======================================================================
//function : Geom2dAPI_ExtremaCurveCurve
//purpose :
//=======================================================================
Geom2dAPI_ExtremaCurveCurve::Geom2dAPI_ExtremaCurveCurve
(const Handle(Geom2d_Curve)& C1,
const Handle(Geom2d_Curve)& C2,
const Standard_Real U1min,
const Standard_Real U1max,
const Standard_Real U2min,
const Standard_Real U2max)
{
myC1.Load(C1, U1min, U1max);
myC2.Load(C2, U2min, U2max);
Extrema_ExtCC2d theExtCC( myC1, myC2 );
myExtCC = theExtCC;
myIsDone = myExtCC.IsDone() && ( myExtCC.NbExt() > 0);
if ( myIsDone ) {
// evaluate the lower distance and its index;
Standard_Real Dist2, Dist2Min = myExtCC.SquareDistance(1);
myIndex = 1;
for ( Standard_Integer i = 2; i <= myExtCC.NbExt(); i++) {
Dist2 = myExtCC.SquareDistance(i);
if ( Dist2 < Dist2Min) {
Dist2Min = Dist2;
myIndex = i;
}
}
}
}
//=======================================================================
//function : NbExtrema
//purpose :
//=======================================================================
Standard_Integer Geom2dAPI_ExtremaCurveCurve::NbExtrema() const
{
if ( myIsDone)
return myExtCC.NbExt();
else
return 0;
}
//=======================================================================
//function : Points
//purpose :
//=======================================================================
void Geom2dAPI_ExtremaCurveCurve::Points
(const Standard_Integer Index,
gp_Pnt2d& P1,
gp_Pnt2d& P2) const
{
Standard_OutOfRange_Raise_if
(Index<1||Index>NbExtrema(), "Geom2dAPI_ExtremaCurveCurve::Points");
Extrema_POnCurv2d PC1, PC2;
myExtCC.Points(Index,PC1,PC2);
P1 = PC1.Value();
P2 = PC2.Value();
}
//=======================================================================
//function : Parameters
//purpose :
//=======================================================================
void Geom2dAPI_ExtremaCurveCurve::Parameters
(const Standard_Integer Index,
Standard_Real& U1,
Standard_Real& U2) const
{
Standard_OutOfRange_Raise_if
(Index<1||Index>NbExtrema(), "Geom2dAPI_ExtremaCurveCurve::Parameters");
Extrema_POnCurv2d PC1, PC2;
myExtCC.Points(Index,PC1,PC2);
U1 = PC1.Parameter();
U2 = PC2.Parameter();
}
//=======================================================================
//function : Distance
//purpose :
//=======================================================================
Standard_Real Geom2dAPI_ExtremaCurveCurve::Distance
(const Standard_Integer Index) const
{
Standard_OutOfRange_Raise_if
(Index<1||Index>NbExtrema(), "Geom2dAPI_ExtremaCurveCurve:Distance");
return sqrt (myExtCC.SquareDistance(Index));
}
//=======================================================================
//function : NearestPoints
//purpose :
//=======================================================================
void Geom2dAPI_ExtremaCurveCurve::NearestPoints
(gp_Pnt2d& P1, gp_Pnt2d& P2) const
{
StdFail_NotDone_Raise_if
( !myIsDone, "Geom2dAPI_ExtremaCurveCurve:NearestPoints");
Points(myIndex,P1,P2);
}
//=======================================================================
//function : LowerDistanceParameters
//purpose :
//=======================================================================
void Geom2dAPI_ExtremaCurveCurve::LowerDistanceParameters
(Standard_Real& U1,
Standard_Real& U2) const
{
StdFail_NotDone_Raise_if
( !myIsDone, "Geom2dAPI_ExtremaCurveCurve:LowerDistanceParameters");
Parameters(myIndex,U1,U2);
}
//=======================================================================
//function : LowerDistance
//purpose :
//=======================================================================
Standard_Real Geom2dAPI_ExtremaCurveCurve::LowerDistance() const
{
StdFail_NotDone_Raise_if
(!myIsDone, "Geom2dAPI_ExtremaCurveCurve:LowerDistance");
return sqrt (myExtCC.SquareDistance(myIndex));
}
//=======================================================================
//function : Standard_Real
//purpose :
//=======================================================================
Geom2dAPI_ExtremaCurveCurve::operator Standard_Real() const
{
return LowerDistance();
}
//=======================================================================
//function : Standard_Integer
//purpose :
//=======================================================================
Geom2dAPI_ExtremaCurveCurve::operator Standard_Integer() const
{
return myExtCC.NbExt();
}

View File

@@ -0,0 +1,16 @@
// File: Geom2dAPI_ExtremaCurveCurve.lxx
// Created: Wed Mar 23 15:27:51 1994
// Author: Bruno DUMORTIER
// <dub@fuegox>
//=======================================================================
//function : Extrema
//purpose :
//=======================================================================
inline const Extrema_ExtCC2d& Geom2dAPI_ExtremaCurveCurve::Extrema() const
{
return myExtCC;
}

View File

@@ -0,0 +1,174 @@
-- File: Geom2dAPI_InterCurveCurve.cdl
-- Created: Thu Mar 24 10:59:18 1994
-- Author: Bruno DUMORTIER
-- <dub@fuegox>
---Copyright: Matra Datavision 1994
class InterCurveCurve from Geom2dAPI
---Purpose: This class implements methods for computing
-- - the intersections between two 2D curves,
-- - the self-intersections of a 2D curve.
-- Using the InterCurveCurve algorithm allows to get the following results:
-- - intersection points in the case of cross intersections,
-- - intersection segments in the case of tangential intersections,
-- - nothing in the case of no intersections.
uses
Curve from Geom2d,
Pnt2d from gp,
GInter from Geom2dInt
raises
OutOfRange from Standard,
NullObject from Standard
is
Create
---Purpose: Create an empty intersector. Use the
-- function Init for further initialization of the intersection
-- algorithm by curves or curve.
---Level: Public
returns InterCurveCurve from Geom2dAPI;
Create(C1 : Curve from Geom2d;
C2 : Curve from Geom2d;
Tol : Real from Standard = 1.0e-6)
---Purpose: Creates an object and computes the
-- intersections between the curves C1 and C2.
returns InterCurveCurve from Geom2dAPI;
Create(C1 : Curve from Geom2d;
Tol : Real from Standard = 1.0e-6)
---Purpose:
-- Creates an object and computes self-intersections of the curve C1.
-- Tolerance value Tol, defaulted to 1.0e-6, defines the precision of
-- computing the intersection points.
-- In case of a tangential intersection, Tol also defines the
-- size of intersection segments (limited portions of the curves)
-- where the distance between all points from two curves (or a curve
-- in case of self-intersection) is less than Tol.
-- Warning
-- Use functions NbPoints and NbSegments to obtain the number of
-- solutions. If the algorithm finds no intersections NbPoints and
-- NbSegments return 0.
returns InterCurveCurve from Geom2dAPI;
Init( me : in out;
C1 : Curve from Geom2d;
C2 : Curve from Geom2d;
Tol : Real from Standard = 1.0e-6)
---Purpose: Initializes an algorithm with the
-- given arguments and computes the intersections between the curves C1. and C2.
is static;
Init( me : in out;
C1 : Curve from Geom2d;
Tol : Real from Standard = 1.0e-6)
---Purpose: Initializes an algorithm with the
-- given arguments and computes the self-intersections of the curve C1.
-- Tolerance value Tol, defaulted to 1.0e-6, defines the precision of
-- computing the intersection points. In case of a tangential
-- intersection, Tol also defines the size of intersection segments
-- (limited portions of the curves) where the distance between all
-- points from two curves (or a curve in case of self-intersection) is less than Tol.
-- Warning
-- Use functions NbPoints and NbSegments to obtain the number
-- of solutions. If the algorithm finds no intersections NbPoints
-- and NbSegments return 0.
is static;
NbPoints(me)
returns Integer from Standard
---Purpose: Returns the number of intersection-points in case of cross intersections.
-- NbPoints returns 0 if no intersections were found.
is static;
Point(me; Index : Integer from Standard)
returns Pnt2d from gp
---Purpose: Returns the intersection point of index Index.
-- Intersection points are computed in case of cross intersections with a
-- precision equal to the tolerance value assigned at the time of
-- construction or in the function Init (this value is defaulted to 1.0e-6).
-- Exceptions
-- Standard_OutOfRange if index is not in the range [ 1,NbPoints ], where
-- NbPoints is the number of computed intersection points
raises
OutOfRange from Standard
is static;
NbSegments(me)
returns Integer from Standard
---Purpose: Returns the number of tangential intersections.
-- NbSegments returns 0 if no intersections were found
is static;
Segment(me; Index : Integer from Standard;
Curve1, Curve2 : in out Curve from Geom2d)
---Purpose: Use this syntax only to get
-- solutions of tangential intersection between two curves.
-- Output values Curve1 and Curve2 are the intersection segments on the
-- first curve and on the second curve accordingly. Parameter Index
-- defines a number of computed solution.
-- An intersection segment is a portion of an initial curve limited
-- by two points. The distance from each point of this segment to the
-- other curve is less or equal to the tolerance value assigned at the
-- time of construction or in function Init (this value is defaulted to 1.0e-6).
-- Exceptions
-- Standard_OutOfRange if Index is not in the range [ 1,NbSegments ],
-- where NbSegments is the number of computed tangential intersections.
-- Standard_NullObject if the algorithm is initialized for the
-- computing of self-intersections on a curve.
raises
OutOfRange from Standard,
NullObject from Standard
is static;
Segment(me; Index : Integer from Standard;
Curve1 : in out Curve from Geom2d)
---Purpose: Use this syntax to get solutions of
-- tangential intersections only in case of a self-intersected curve.
-- Output value Curve1 is the intersection segment of the curve
-- defined by number Index. An intersection segment is a
-- portion of the initial curve limited by two points. The distance
-- between each point of this segment to another portion of the curve is
-- less or equal to the tolerance value assigned at the time of
-- construction or in the function Init (this value is defaulted to 1.0e-6).
-- Exceptions
-- Standard_OutOfRange if Index is not in the range [ 1,NbSegments ],
-- where NbSegments is the number of computed tangential intersections.
raises
OutOfRange from Standard
is static;
Intersector(me)
---Purpose: return the algorithmic object from Intersection.
---Level: Advanced
returns GInter from Geom2dInt
---C++: return const &
---C++: inline
is static;
fields
myIsDone : Boolean from Standard;
myCurve1 : Curve from Geom2d;
myCurve2 : Curve from Geom2d;
myIntersector : GInter from Geom2dInt;
end InterCurveCurve;

View File

@@ -0,0 +1,218 @@
// File: Geom2dAPI_InterCurveCurve.cxx
// Created: Thu Mar 24 11:41:35 1994
// Author: Bruno DUMORTIER
// <dub@fuegox>
#include <Geom2dAPI_InterCurveCurve.ixx>
#include <Geom2dAdaptor_Curve.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <IntRes2d_IntersectionPoint.hxx>
#include <IntRes2d_IntersectionSegment.hxx>
#include <Standard_NotImplemented.hxx>
//=======================================================================
//function : Geom2dAPI_InterCurveCurve
//purpose :
//=======================================================================
Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve()
{
myIsDone = Standard_False;
}
//=======================================================================
//function : Geom2dAPI_InterCurveCurve
//purpose :
//=======================================================================
Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve
(const Handle(Geom2d_Curve)& C1,
const Handle(Geom2d_Curve)& C2,
const Standard_Real Tol)
{
Init( C1, C2, Tol);
}
//=======================================================================
//function : Geom2dAPI_InterCurveCurve
//purpose :
//=======================================================================
Geom2dAPI_InterCurveCurve::Geom2dAPI_InterCurveCurve
(const Handle(Geom2d_Curve)& C1,
const Standard_Real Tol)
{
Init( C1, Tol);
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void Geom2dAPI_InterCurveCurve::Init
(const Handle(Geom2d_Curve)& C1,
const Handle(Geom2d_Curve)& C2,
const Standard_Real Tol)
{
myCurve1 = Handle(Geom2d_Curve)::DownCast(C1->Copy());
myCurve2 = Handle(Geom2d_Curve)::DownCast(C2->Copy());
Geom2dAdaptor_Curve AC1(C1);
Geom2dAdaptor_Curve AC2(C2);
myIntersector = Geom2dInt_GInter( AC1, AC2, Tol, Tol);
myIsDone = myIntersector.IsDone();
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void Geom2dAPI_InterCurveCurve::Init
(const Handle(Geom2d_Curve)& C1,
const Standard_Real Tol)
{
myCurve1 = Handle(Geom2d_Curve)::DownCast(C1->Copy());
myCurve2.Nullify();
Geom2dAdaptor_Curve AC1(C1);
myIntersector = Geom2dInt_GInter( AC1, Tol, Tol);
myIsDone = myIntersector.IsDone();
}
//=======================================================================
//function : NbPoints
//purpose :
//=======================================================================
Standard_Integer Geom2dAPI_InterCurveCurve::NbPoints() const
{
if ( myIsDone)
return myIntersector.NbPoints();
else
return 0;
}
//=======================================================================
//function : Point
//purpose :
//=======================================================================
gp_Pnt2d Geom2dAPI_InterCurveCurve::Point
(const Standard_Integer Index) const
{
Standard_OutOfRange_Raise_if(Index < 0 || Index > NbPoints(),
"Geom2dAPI_InterCurveCurve::Points");
return (myIntersector.Point(Index)).Value();
}
//=======================================================================
//function : NbSegments
//purpose :
//=======================================================================
Standard_Integer Geom2dAPI_InterCurveCurve::NbSegments() const
{
if ( myIsDone)
return myIntersector.NbSegments();
else
return 0;
}
//=======================================================================
//function : Segment
//purpose :
//=======================================================================
void Geom2dAPI_InterCurveCurve::Segment
(const Standard_Integer Index,
Handle(Geom2d_Curve)& Curve1,
Handle(Geom2d_Curve)& Curve2) const
{
Standard_OutOfRange_Raise_if(Index < 0 || Index > NbSegments(),
"Geom2dAPI_InterCurveCurve::Segment");
Standard_NullObject_Raise_if(myCurve2.IsNull(),
"Geom2dAPI_InterCurveCurve::Segment");
Standard_Real U1, U2, V1, V2;
IntRes2d_IntersectionSegment Seg = myIntersector.Segment(Index);
if ( Seg.IsOpposite()) {
if ( Seg.HasFirstPoint()) {
IntRes2d_IntersectionPoint IP1 = Seg.FirstPoint();
U1 = IP1.ParamOnFirst();
V2 = IP1.ParamOnSecond();
}
else {
U1 = Curve1->FirstParameter();
V2 = Curve2->LastParameter();
}
if ( Seg.HasLastPoint()) {
IntRes2d_IntersectionPoint IP2 = Seg.LastPoint();
U2 = IP2.ParamOnFirst();
V1 = IP2.ParamOnSecond();
}
else {
U2 = Curve1->FirstParameter();
V1 = Curve2->LastParameter();
}
}
else {
if ( Seg.HasFirstPoint()) {
IntRes2d_IntersectionPoint IP1 = Seg.FirstPoint();
U1 = IP1.ParamOnFirst();
V1 = IP1.ParamOnSecond();
}
else {
U1 = Curve1->FirstParameter();
V1 = Curve2->FirstParameter();
}
if ( Seg.HasLastPoint()) {
IntRes2d_IntersectionPoint IP2 = Seg.LastPoint();
U2 = IP2.ParamOnFirst();
V2 = IP2.ParamOnSecond();
}
else {
U2 = Curve1->FirstParameter();
V2 = Curve2->FirstParameter();
}
}
Curve1 = new Geom2d_TrimmedCurve(myCurve1, U1, U2);
Curve2 = new Geom2d_TrimmedCurve(myCurve2, V1, V2);
}
//=======================================================================
//function : Segment
//purpose :
//=======================================================================
void Geom2dAPI_InterCurveCurve::Segment
(const Standard_Integer Index,
Handle(Geom2d_Curve)& //Curve1
) const
{
Standard_NotImplemented::Raise(" ");
Standard_OutOfRange_Raise_if(Index < 0 || Index > NbSegments(),
"Geom2dAPI_InterCurveCurve::Segment");
}

View File

@@ -0,0 +1,15 @@
// File: Geom2dAPI_InterCurveCurve.lxx
// Created: Thu Mar 24 14:45:33 1994
// Author: Bruno DUMORTIER
// <dub@fuegox>
//=======================================================================
//function : Intersector
//purpose :
//=======================================================================
inline const Geom2dInt_GInter& Geom2dAPI_InterCurveCurve::Intersector() const
{
return myIntersector;
}

View File

@@ -0,0 +1,149 @@
-- File: GeomAPI_Interpolate.cdl
-- Created: Thu Aug 18 15:50:24 1994
-- Author: Laurent PAINNOT
-- <lpa@metrox>
---Copyright: Matra Datavision 1994
class Interpolate from Geom2dAPI
---Purpose: This class is used to interpolate a BsplineCurve
-- passing through an array of points, with a C2
-- Continuity if tangency is not requested at the point.
-- If tangency is requested at the point the continuity will
-- be C1. If Perodicity is requested the curve will be closed
-- and the junction will be the first point given. The curve will than be only C1
-- The curve is defined by a table of points through which it passes, and if required
-- by a parallel table of reals which gives the value of the parameter of each point through
-- which the resulting BSpline curve passes, and by vectors tangential to these points.
-- An Interpolate object provides a framework for: defining the constraints of the BSpline curve,
-- - implementing the interpolation algorithm, and consulting the results.
--
uses
Vec2d from gp,
Array1OfPnt2d from TColgp,
HArray1OfPnt2d from TColgp,
Array1OfVec2d from TColgp,
HArray1OfBoolean from TColStd,
HArray1OfReal from TColStd,
HArray1OfVec2d from TColgp,
BSplineCurve from Geom2d
raises
NotDone from StdFail,
ConstructionError from Standard
is
Create(Points : HArray1OfPnt2d from TColgp ;
PeriodicFlag : Boolean from Standard ;
Tolerance : Real)
---Purpose: Tolerance is to check if the points are not too close to one an other
-- It is also used to check if the tangent vector is not too small.
-- There should be at least 2 points
-- if PeriodicFlag is True then the curve will be periodic.
returns Interpolate from Geom2dAPI
raises ConstructionError from Standard ;
Create(Points : HArray1OfPnt2d from TColgp ;
Parameters : HArray1OfReal from TColStd;
PeriodicFlag : Boolean from Standard;
Tolerance : Real)
---Purpose: if PeriodicFlag is True then the curve will be periodic
-- Warning:
-- There should be as many parameters as there are points
-- except if PeriodicFlag is True : then there should be one more
-- parameter to close the curve
returns Interpolate from Geom2dAPI
raises ConstructionError from Standard ;
Load(me : in out;
InitialTangent : Vec2d from gp;
FinalTangent : Vec2d from gp)
---Purpose: Assigns this constrained BSpline curve to be
-- tangential to vectors InitialTangent and FinalTangent
-- at its first and last points respectively (i.e.
-- the first and last points of the table of
-- points through which the curve passes, as
-- defined at the time of initialization).
is static ;
Load(me : in out;
Tangents : Array1OfVec2d from TColgp ;
TangentFlags : HArray1OfBoolean from TColStd)
is static;
---Purpose: Assigns this constrained BSpline curve to be
-- tangential to vectors defined in the table Tangents,
-- which is parallel to the table of points
-- through which the curve passes, as
-- defined at the time of initialization. Vectors
-- in the table Tangents are defined only if
-- the flag given in the parallel table
-- TangentFlags is true: only these vectors
-- are set as tangency constraints.
ClearTangents(me : in out) ;
---Purpose: Clears all tangency constraints on this
-- constrained BSpline curve (as initialized by the function Load).
Perform(me : in out) ;
---Purpose: Computes the constrained BSpline curve. Use the function IsDone to verify that the
-- computation is successful, and then the function Curve to obtain the result.
Curve(me)
returns BSplineCurve from Geom2d
---C++: return const &
---C++: alias "Standard_EXPORT operator Handle(Geom2d_BSplineCurve)() const;"
---Purpose: Returns the computed BSpline curve. Raises StdFail_NotDone if the interpolation fails.
raises
NotDone from StdFail
is static;
IsDone(me)
returns Boolean from Standard
is static;
--- Purpose: Returns true if the constrained BSpline curve is successfully constructed.
-- Note: in this case, the result is given by the function Curve.
PerformNonPeriodic(me : in out)
---Purpose: Interpolates in a non periodic fashion
is private ;
PerformPeriodic(me : in out)
---Purpose: Interpolates in a C1 periodic fashion
is private ;
fields
myTolerance : Real from Standard ;
-- the 3D tolerance to check for degenerate points
myPoints : HArray1OfPnt2d from TColgp ;
-- the points to interpolates
myIsDone : Boolean from Standard ;
-- the algorithm did complete OK if Standard_True
myCurve : BSplineCurve from Geom2d ;
-- the interpolated curve
myTangents : HArray1OfVec2d from TColgp ;
-- the tangents only defined at slot i if
-- myTangenFlags->Value(i) is Standard_True
myTangentFlags : HArray1OfBoolean from TColStd ;
-- the flags defining the tangents
myParameters : HArray1OfReal from TColStd ;
-- the parameters used for the cubic interpolation
myPeriodic : Boolean from Standard ;
-- if Standard_True the curve will be periodic
myTangentRequest : Boolean from Standard ;
-- Tangents are given if True False otherwise
end Interpolate;

View File

@@ -0,0 +1,915 @@
// File: GeomAPI_Interpolate.cxx
// Created: Thu Aug 18 15:53:59 1994
// Author: Laurent PAINNOT
// <lpa@metrox>
// 8-Aug-95 : xab : interpolation uses BSplCLib::Interpolate
//
#include <Geom2dAPI_Interpolate.ixx>
#include <Standard_ConstructionError.hxx>
#include <PLib.hxx>
#include <BSplCLib.hxx>
#include <gp_Vec2d.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <TColStd_Array1OfBoolean.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <TColStd_HArray1OfBoolean.hxx>
//=======================================================================
//function : CheckPoints
//purpose :
//=======================================================================
static Standard_Boolean CheckPoints(const TColgp_Array1OfPnt2d& PointArray,
const Standard_Real Tolerance)
{
Standard_Integer ii ;
Standard_Real tolerance_squared = Tolerance * Tolerance,
distance_squared ;
Standard_Boolean result = Standard_True ;
for (ii = PointArray.Lower() ; result && ii < PointArray.Upper() ; ii++) {
distance_squared =
PointArray.Value(ii).SquareDistance(PointArray.Value(ii+1)) ;
result = (distance_squared >= tolerance_squared) ;
}
return result ;
}
//=======================================================================
//function : CheckTangents
//purpose :
//=======================================================================
static Standard_Boolean CheckTangents(
const TColgp_Array1OfVec2d& Tangents,
const TColStd_Array1OfBoolean& TangentFlags,
const Standard_Real Tolerance)
{
Standard_Integer ii,
index ;
Standard_Real tolerance_squared = Tolerance * Tolerance,
distance_squared ;
Standard_Boolean result = Standard_True ;
index = TangentFlags.Lower() ;
for (ii = Tangents.Lower(); result && ii <= Tangents.Upper() ; ii++) {
if(TangentFlags.Value(index)) {
distance_squared =
Tangents.Value(ii).SquareMagnitude() ;
result = (distance_squared >= tolerance_squared) ;
}
index += 1 ;
}
return result ;
}
//=======================================================================
//function : CheckParameters
//purpose :
//=======================================================================
static Standard_Boolean CheckParameters(const
TColStd_Array1OfReal& Parameters)
{
Standard_Integer ii ;
Standard_Real distance ;
Standard_Boolean result = Standard_True ;
for (ii = Parameters.Lower() ; result && ii < Parameters.Upper() ; ii++) {
distance =
Parameters.Value(ii+1) - Parameters.Value(ii) ;
result = (distance >= RealSmall()) ;
}
return result ;
}
//=======================================================================
//function : BuildParameters
//purpose :
//=======================================================================
static void BuildParameters(const Standard_Boolean PeriodicFlag,
const TColgp_Array1OfPnt2d& PointsArray,
Handle_TColStd_HArray1OfReal& ParametersPtr)
{
Standard_Integer ii,
index ;
Standard_Real distance ;
Standard_Integer
num_parameters = PointsArray.Length() ;
if (PeriodicFlag) {
num_parameters += 1 ;
}
ParametersPtr =
new TColStd_HArray1OfReal(1,
num_parameters) ;
ParametersPtr->SetValue(1,0.0e0) ;
index = 2 ;
for (ii = PointsArray.Lower() ; ii < PointsArray.Upper() ; ii++) {
distance =
PointsArray.Value(ii).Distance(PointsArray.Value(ii+1)) ;
ParametersPtr->SetValue(index,
ParametersPtr->Value(ii) + distance) ;
index += 1 ;
}
if (PeriodicFlag) {
distance =
PointsArray.Value(PointsArray.Upper()).
Distance(PointsArray.Value(PointsArray.Lower())) ;
ParametersPtr->SetValue(index,
ParametersPtr->Value(ii) + distance) ;
}
}
//=======================================================================
//function : BuildPeriodicTangents
//purpose :
//=======================================================================
static void BuildPeriodicTangent(
const TColgp_Array1OfPnt2d& PointsArray,
TColgp_Array1OfVec2d& TangentsArray,
TColStd_Array1OfBoolean& TangentFlags,
const TColStd_Array1OfReal& ParametersArray)
{
Standard_Integer
ii,
degree ;
Standard_Real *point_array,
*parameter_array,
eval_result[2][2] ;
gp_Vec2d a_vector ;
if (PointsArray.Length() < 3) {
Standard_ConstructionError::Raise();
}
if (!TangentFlags.Value(1)) {
degree = 3 ;
if (PointsArray.Length() == 3) {
degree = 2 ;
}
point_array = (Standard_Real *) &PointsArray.Value(PointsArray.Lower()) ;
parameter_array =
(Standard_Real *) &ParametersArray.Value(1) ;
TangentFlags.SetValue(1,Standard_True) ;
PLib::EvalLagrange(ParametersArray.Value(1),
1,
degree,
2,
point_array[0],
parameter_array[0],
eval_result[0][0]) ;
for (ii = 1 ; ii <= 2 ; ii++) {
a_vector.SetCoord(ii,eval_result[1][ii-1]) ;
}
TangentsArray.SetValue(1,a_vector) ;
}
}
//=======================================================================
//function : BuildTangents
//purpose :
//=======================================================================
static void BuildTangents(const TColgp_Array1OfPnt2d& PointsArray,
TColgp_Array1OfVec2d& TangentsArray,
TColStd_Array1OfBoolean& TangentFlags,
const TColStd_Array1OfReal& ParametersArray)
{
Standard_Integer ii,
degree ;
Standard_Real *point_array,
*parameter_array,
eval_result[2][2] ;
gp_Vec2d a_vector ;
degree = 3 ;
if ( PointsArray.Length() < 3) {
Standard_ConstructionError::Raise();
}
if (PointsArray.Length() == 3) {
degree = 2 ;
}
if (!TangentFlags.Value(1)) {
point_array = (Standard_Real *) &PointsArray.Value(PointsArray.Lower()) ;
parameter_array =
(Standard_Real *) &ParametersArray.Value(1) ;
TangentFlags.SetValue(1,Standard_True) ;
PLib::EvalLagrange(ParametersArray.Value(1),
1,
degree,
2,
point_array[0],
parameter_array[0],
eval_result[0][0]) ;
for (ii = 1 ; ii <= 2 ; ii++) {
a_vector.SetCoord(ii,eval_result[1][ii-1]) ;
}
TangentsArray.SetValue(1,a_vector) ;
}
if (! TangentFlags.Value(TangentFlags.Upper())) {
point_array =
(Standard_Real *) &PointsArray.Value(PointsArray.Upper() - degree) ;
TangentFlags.SetValue(TangentFlags.Upper(),Standard_True) ;
parameter_array =
(Standard_Real *)&ParametersArray.Value(ParametersArray.Upper() - degree) ;
PLib::EvalLagrange(ParametersArray.Value(ParametersArray.Upper()),
1,
degree,
2,
point_array[0],
parameter_array[0],
eval_result[0][0]) ;
for (ii = 1 ; ii <= 2 ; ii++) {
a_vector.SetCoord(ii,eval_result[1][ii-1]) ;
}
TangentsArray.SetValue(TangentsArray.Upper(),a_vector) ;
}
}
//=======================================================================
//function : BuildTangents
//purpose : scale the given tangent so that they have the length of
// the size of the derivative of the lagrange interpolation
//
//=======================================================================
static void ScaleTangents(const TColgp_Array1OfPnt2d& PointsArray,
TColgp_Array1OfVec2d& TangentsArray,
const TColStd_Array1OfBoolean& TangentFlags,
const TColStd_Array1OfReal& ParametersArray)
{
Standard_Integer ii,
jj,
degree=0,
index,
num_points ;
Standard_Real *point_array,
*parameter_array,
value[2],
ratio,
eval_result[2][2] ;
gp_Vec2d a_vector ;
num_points = PointsArray.Length() ;
if (num_points == 2) {
degree = 1 ;
}
else if (num_points >= 3) {
degree = 2 ;
}
index = PointsArray.Lower() ;
for (ii = TangentFlags.Lower() ; ii <= TangentFlags.Upper() ; ii++) {
if (TangentFlags.Value(ii)) {
point_array =
(Standard_Real *) &PointsArray.Value(index) ;
parameter_array =
(Standard_Real *) &ParametersArray.Value(index) ;
PLib::EvalLagrange(ParametersArray.Value(ii),
1,
degree,
2,
point_array[0],
parameter_array[0],
eval_result[0][0]) ;
value[0] =
value[1] = 0.0e0 ;
for (jj = 1 ; jj <= 2 ; jj++) {
value[0] += Abs(TangentsArray.Value(ii).Coord(jj)) ;
value[1] += Abs(eval_result[1][jj-1]) ;
}
ratio = value[1] / value[0] ;
for (jj = 1 ; jj <= 2 ; jj++) {
a_vector.SetCoord(jj, ratio *
TangentsArray.Value(ii).Coord(jj)) ;
}
TangentsArray.SetValue(ii, a_vector) ;
if (ii != TangentFlags.Lower()) {
index += 1 ;
}
if (index > PointsArray.Upper() - degree) {
index = PointsArray.Upper() - degree ;
}
}
}
}
//=======================================================================
//function : Geom2dAPI_Interpolate
//purpose :
//=======================================================================
Geom2dAPI_Interpolate::Geom2dAPI_Interpolate
(const Handle_TColgp_HArray1OfPnt2d& PointsPtr,
const Standard_Boolean PeriodicFlag,
const Standard_Real Tolerance) :
myTolerance(Tolerance),
myPoints(PointsPtr),
myIsDone(Standard_False),
myPeriodic(PeriodicFlag),
myTangentRequest(Standard_False)
{
Standard_Integer ii ;
Standard_Boolean result =
CheckPoints(PointsPtr->Array1(),
Tolerance) ;
myTangents =
new TColgp_HArray1OfVec2d(myPoints->Lower(),
myPoints->Upper()) ;
myTangentFlags =
new TColStd_HArray1OfBoolean(myPoints->Lower(),
myPoints->Upper()) ;
if (!result) {
Standard_ConstructionError::Raise();
}
BuildParameters(PeriodicFlag,
PointsPtr->Array1(),
myParameters) ;
for (ii = myPoints->Lower() ; ii <= myPoints->Upper() ; ii++) {
myTangentFlags->SetValue(ii,Standard_False) ;
}
}
//=======================================================================
//function : Geom2dAPI_Interpolate
//purpose :
//=======================================================================
Geom2dAPI_Interpolate::Geom2dAPI_Interpolate
(const Handle_TColgp_HArray1OfPnt2d& PointsPtr,
const Handle_TColStd_HArray1OfReal& ParametersPtr,
const Standard_Boolean PeriodicFlag,
const Standard_Real Tolerance) :
myTolerance(Tolerance),
myPoints(PointsPtr),
myIsDone(Standard_False),
myParameters(ParametersPtr),
myPeriodic(PeriodicFlag),
myTangentRequest(Standard_False)
{
Standard_Integer ii ;
Standard_Boolean result =
CheckPoints(PointsPtr->Array1(),
Tolerance) ;
if (PeriodicFlag) {
if ((PointsPtr->Length()) + 1 != ParametersPtr->Length()) {
Standard_ConstructionError::Raise();
}
}
myTangents =
new TColgp_HArray1OfVec2d(myPoints->Lower(),
myPoints->Upper()) ;
myTangentFlags =
new TColStd_HArray1OfBoolean(myPoints->Lower(),
myPoints->Upper()) ;
if (!result) {
Standard_ConstructionError::Raise();
}
result =
CheckParameters(ParametersPtr->Array1()) ;
if (!result) {
Standard_ConstructionError::Raise();
}
for (ii = myPoints->Lower() ; ii <= myPoints->Upper() ; ii++) {
myTangentFlags->SetValue(ii,Standard_False) ;
}
}
//=======================================================================
//function : Load
//purpose :
//=======================================================================
void Geom2dAPI_Interpolate::Load(
const TColgp_Array1OfVec2d& Tangents,
const Handle_TColStd_HArray1OfBoolean& TangentFlagsPtr)
{
Standard_Boolean result ;
Standard_Integer ii ;
myTangentRequest = Standard_True ;
myTangentFlags = TangentFlagsPtr ;
if (Tangents.Length() != myPoints->Length() ||
TangentFlagsPtr->Length() != myPoints->Length()) {
Standard_ConstructionError::Raise();
}
result =
CheckTangents(Tangents,
TangentFlagsPtr->Array1(),
myTolerance) ;
if (result) {
myTangents =
new TColgp_HArray1OfVec2d(Tangents.Lower(),Tangents.Upper()) ;
for (ii = Tangents.Lower() ; ii <= Tangents.Upper() ; ii++ ) {
myTangents->SetValue(ii,Tangents.Value(ii)) ;
}
ScaleTangents(myPoints->Array1(),
myTangents->ChangeArray1(),
TangentFlagsPtr->Array1(),
myParameters->Array1()) ;
}
else {
Standard_ConstructionError::Raise();
}
}
//=======================================================================
//function : Load
//purpose :
//=======================================================================
void Geom2dAPI_Interpolate::Load(const gp_Vec2d& InitialTangent,
const gp_Vec2d& FinalTangent)
{
Standard_Boolean result ;
myTangentRequest = Standard_True ;
myTangentFlags->SetValue(1,Standard_True) ;
myTangentFlags->SetValue(myPoints->Length(),Standard_True) ;
myTangents->SetValue(1,InitialTangent) ;
myTangents->SetValue(myPoints->Length(),FinalTangent);
result =
CheckTangents(myTangents->Array1(),
myTangentFlags->Array1(),
myTolerance) ;
if (!result) {
Standard_ConstructionError::Raise();
}
ScaleTangents(myPoints->Array1(),
myTangents->ChangeArray1(),
myTangentFlags->Array1(),
myParameters->Array1()) ;
}
//=======================================================================
//function : Perform
//purpose :
//=======================================================================
void Geom2dAPI_Interpolate::Perform()
{
if (myPeriodic) {
PerformPeriodic() ;
}
else {
PerformNonPeriodic() ;
}
}
//=======================================================================
//function : PerformPeriodic
//purpose :
//=======================================================================
void Geom2dAPI_Interpolate::PerformPeriodic()
{
Standard_Integer degree,
ii,
jj,
index,
index1,
// index2,
mult_index,
half_order,
inversion_problem,
num_points,
num_distinct_knots,
num_poles ;
Standard_Real period ;
gp_Pnt2d a_point ;
num_points = myPoints->Length() ;
period = myParameters->Value(myParameters->Upper()) -
myParameters->Value(myParameters->Lower()) ;
num_poles = num_points + 1 ;
if (num_points == 2 && !myTangentRequest) {
//
// build a periodic curve of degree 1
//
degree = 1 ;
TColStd_Array1OfInteger deg1_mults(1,num_poles) ;
for (ii = 1 ; ii <= num_poles ; ii++) {
deg1_mults.SetValue(ii,1) ;
}
myCurve =
new Geom2d_BSplineCurve(myPoints->Array1(),
myParameters->Array1(),
deg1_mults,
degree,
myPeriodic) ;
myIsDone = Standard_True ;
}
else {
num_distinct_knots = num_points + 1 ;
half_order = 2 ;
degree = 3 ;
num_poles += 2 ;
if (myTangentRequest)
for (ii = myTangentFlags->Lower() + 1 ;
ii <= myTangentFlags->Upper() ; ii++) {
if (myTangentFlags->Value(ii)) {
num_poles += 1 ;
}
}
TColStd_Array1OfReal parameters(1,num_poles) ;
TColStd_Array1OfReal flatknots(1,num_poles + degree + 1) ;
TColStd_Array1OfInteger mults(1,num_distinct_knots) ;
TColStd_Array1OfInteger contact_order_array(1, num_poles) ;
TColgp_Array1OfPnt2d poles(1,num_poles) ;
for (ii = 1 ; ii <= half_order ; ii++) {
flatknots.SetValue(ii,myParameters->Value(myParameters->Upper() -1) -
period) ;
flatknots.SetValue(ii + half_order,myParameters->
Value(myParameters->Lower())) ;
flatknots.SetValue(num_poles + ii,
myParameters->Value(myParameters->Upper())) ;
flatknots.SetValue(num_poles + half_order + ii,
myParameters->Value(half_order) + period) ;
}
for (ii = 1 ; ii <= num_poles ; ii++) {
contact_order_array.SetValue(ii,0) ;
}
for (ii = 2 ; ii < num_distinct_knots ; ii++) {
mults.SetValue(ii,1) ;
}
mults.SetValue(1,half_order) ;
mults.SetValue(num_distinct_knots ,half_order) ;
if (num_points >= 3) {
//
// only enter here if there are more than 3 points otherwise
// it means we have already the tangent
//
BuildPeriodicTangent(myPoints->Array1(),
myTangents->ChangeArray1(),
myTangentFlags->ChangeArray1(),
myParameters->Array1()) ;
}
contact_order_array.SetValue(2,1) ;
parameters.SetValue(1,myParameters->Value(1)) ;
parameters.SetValue(2,myParameters->Value(1)) ;
poles.SetValue(1,myPoints->Value(1)) ;
for (jj = 1 ; jj <= 2 ; jj++) {
a_point.SetCoord(jj,myTangents->Value(1).Coord(jj)) ;
}
poles.SetValue(2,a_point) ;
mult_index = 2 ;
index = 3 ;
index1 = degree + 2 ;
if (myTangentRequest) {
for (ii = myTangentFlags->Lower() + 1 ;
ii <= myTangentFlags->Upper() ; ii++) {
parameters.SetValue(index,myParameters->Value(ii)) ;
flatknots.SetValue(index1,myParameters->Value(ii)) ;
poles.SetValue(index,myPoints->Value(ii)) ;
index += 1 ;
index1 += 1 ;
if (myTangentFlags->Value(ii)) {
mults.SetValue(mult_index,mults.Value(mult_index) + 1) ;
contact_order_array(index) = 1 ;
parameters.SetValue(index,
myParameters->Value(ii)) ;
flatknots.SetValue(index1,myParameters->Value(ii)) ;
for (jj = 1 ; jj <= 2 ; jj++) {
a_point.SetCoord(jj,myTangents->Value(ii).Coord(jj)) ;
}
poles.SetValue(index,a_point) ;
index += 1 ;
index1 += 1 ;
}
mult_index += 1 ;
}
}
else {
index = degree + 1 ;
index1 = 2 ;
for(ii = myParameters->Lower() ; ii <= myParameters->Upper() ; ii++) {
parameters.SetValue(index1,
myParameters->Value(ii)) ;
flatknots.SetValue(index,
myParameters->Value(ii)) ;
index += 1 ;
index1 += 1 ;
}
index = 3 ;
for (ii = myPoints->Lower() + 1 ; ii <= myPoints->Upper() ; ii++) {
//
// copy all the given points since the last one will be initialized
// below by the first point in the array myPoints
//
poles.SetValue(index,
myPoints->Value(ii)) ;
index += 1 ;
}
}
contact_order_array.SetValue(num_poles - 1, 1) ;
parameters.SetValue(num_poles-1,
myParameters->Value(myParameters->Upper())) ;
//
// for the periodic curve ONLY the tangent of the first point
// will be used since the curve should close itself at the first
// point See BuildPeriodicTangent
//
for (jj = 1 ; jj <= 2 ; jj++) {
a_point.SetCoord(jj,myTangents->Value(1).Coord(jj)) ;
}
poles.SetValue(num_poles-1,a_point) ;
parameters.SetValue(num_poles,
myParameters->Value(myParameters->Upper())) ;
poles.SetValue(num_poles,
myPoints->Value(1)) ;
BSplCLib::Interpolate(degree,
flatknots,
parameters,
contact_order_array,
poles,
inversion_problem) ;
if (!inversion_problem) {
TColgp_Array1OfPnt2d newpoles(poles.Value(1),
1,
num_poles - 2) ;
myCurve =
new Geom2d_BSplineCurve(newpoles,
myParameters->Array1(),
mults,
degree,
myPeriodic) ;
myIsDone = Standard_True ;
}
}
}
//=======================================================================
//function : PerformNonPeriodic
//purpose :
//=======================================================================
void Geom2dAPI_Interpolate::PerformNonPeriodic()
{
Standard_Integer degree,
ii,
jj,
index,
index1,
index2,
index3,
mult_index,
inversion_problem,
num_points,
num_distinct_knots,
num_poles ;
gp_Pnt2d a_point ;
num_points =
num_distinct_knots =
num_poles = myPoints->Length() ;
if (num_poles == 2 && !myTangentRequest) {
degree = 1 ;
}
else if (num_poles == 3 && !myTangentRequest) {
degree = 2 ;
num_distinct_knots = 2 ;
}
else {
degree = 3 ;
num_poles += 2 ;
if (myTangentRequest)
for (ii = myTangentFlags->Lower() + 1 ;
ii < myTangentFlags->Upper() ; ii++) {
if (myTangentFlags->Value(ii)) {
num_poles += 1 ;
}
}
}
TColStd_Array1OfReal parameters(1,num_poles) ;
TColStd_Array1OfReal flatknots(1,num_poles + degree + 1) ;
TColStd_Array1OfInteger mults(1,num_distinct_knots) ;
TColStd_Array1OfReal knots(1,num_distinct_knots) ;
TColStd_Array1OfInteger contact_order_array(1, num_poles) ;
TColgp_Array1OfPnt2d poles(1,num_poles) ;
for (ii = 1 ; ii <= degree + 1 ; ii++) {
flatknots.SetValue(ii,myParameters->Value(1)) ;
flatknots.SetValue(ii + num_poles,
myParameters->Value(num_points)) ;
}
for (ii = 1 ; ii <= num_poles ; ii++) {
contact_order_array.SetValue(ii,0) ;
}
for (ii = 2 ; ii < num_distinct_knots ; ii++) {
mults.SetValue(ii,1) ;
}
mults.SetValue(1,degree + 1) ;
mults.SetValue(num_distinct_knots ,degree + 1) ;
switch (degree) {
case 1:
for (ii = 1 ; ii <= num_poles ; ii++) {
poles.SetValue(ii ,myPoints->Value(ii)) ;
}
myCurve =
new Geom2d_BSplineCurve(poles,
myParameters->Array1(),
mults,
degree) ;
myIsDone = Standard_True ;
break ;
case 2:
knots.SetValue(1,myParameters->Value(1)) ;
knots.SetValue(2,myParameters->Value(3)) ;
for (ii = 1 ; ii <= num_poles ; ii++) {
poles.SetValue(ii,myPoints->Value(ii)) ;
}
BSplCLib::Interpolate(degree,
flatknots,
myParameters->Array1(),
contact_order_array,
poles,
inversion_problem) ;
if (!inversion_problem) {
myCurve =
new Geom2d_BSplineCurve(poles,
knots,
mults,
degree) ;
myIsDone = Standard_True ;
}
break ;
case 3:
//
// check if the boundary conditions are set
//
if (num_points >= 3) {
//
// cannot build the tangents with degree 3 with only 2 points
// if those where not given in advance
//
BuildTangents(myPoints->Array1(),
myTangents->ChangeArray1(),
myTangentFlags->ChangeArray1(),
myParameters->Array1()) ;
}
contact_order_array.SetValue(2,1) ;
parameters.SetValue(1,myParameters->Value(1)) ;
parameters.SetValue(2,myParameters->Value(1)) ;
poles.SetValue(1,myPoints->Value(1)) ;
for (jj = 1 ; jj <= 2 ; jj++) {
a_point.SetCoord(jj,myTangents->Value(1).Coord(jj)) ;
}
poles.SetValue(2,a_point) ;
mult_index = 2 ;
index = 3 ;
index1 = 2 ;
index2 = myPoints->Lower() + 1 ;
index3 = degree + 2 ;
if (myTangentRequest) {
for (ii = myParameters->Lower() + 1 ;
ii < myParameters->Upper() ; ii++) {
parameters.SetValue(index,myParameters->Value(ii)) ;
poles.SetValue(index,myPoints->Value(index2)) ;
flatknots.SetValue(index3,myParameters->Value(ii)) ;
index += 1 ;
index3 += 1 ;
if (myTangentFlags->Value(index1)) {
//
// set the multiplicities, the order of the contact, the
// the flatknots,
//
mults.SetValue(mult_index,mults.Value(mult_index) + 1) ;
contact_order_array(index) = 1 ;
flatknots.SetValue(index3, myParameters->Value(ii)) ;
parameters.SetValue(index,
myParameters->Value(ii)) ;
for (jj = 1 ; jj <= 2 ; jj++) {
a_point.SetCoord(jj,myTangents->Value(ii).Coord(jj)) ;
}
poles.SetValue(index,a_point) ;
index += 1 ;
index3 += 1 ;
}
mult_index += 1 ;
index1 += 1 ;
index2 += 1 ;
}
}
else {
index1 = 2 ;
for(ii = myParameters->Lower() ; ii <= myParameters->Upper() ; ii++) {
parameters.SetValue(index1,
myParameters->Value(ii)) ;
index1 += 1 ;
}
index = 3 ;
for (ii = myPoints->Lower() + 1 ; ii <= myPoints->Upper() - 1 ; ii++) {
poles.SetValue(index,
myPoints->Value(ii)) ;
index += 1 ;
}
index = degree + 1 ;
for(ii = myParameters->Lower() ; ii <= myParameters->Upper() ; ii++) {
flatknots.SetValue(index,
myParameters->Value(ii)) ;
index += 1 ;
}
}
for (jj = 1 ; jj <= 2 ; jj++) {
a_point.SetCoord(jj,
myTangents->Value(num_points).Coord(jj)) ;
}
poles.SetValue(num_poles-1 ,a_point) ;
contact_order_array.SetValue(num_poles - 1,1) ;
parameters.SetValue(num_poles,
myParameters->Value(myParameters->Upper())) ;
parameters.SetValue(num_poles -1,
myParameters->Value(myParameters->Upper())) ;
poles.SetValue(num_poles,
myPoints->Value(num_points)) ;
BSplCLib::Interpolate(degree,
flatknots,
parameters,
contact_order_array,
poles,
inversion_problem) ;
if (!inversion_problem) {
myCurve =
new Geom2d_BSplineCurve(poles,
myParameters->Array1(),
mults,
degree) ;
myIsDone = Standard_True ;
}
break ;
}
}
//=======================================================================
//function : Handle_Geom2d_BSplineCurve&
//purpose :
//=======================================================================
const Handle(Geom2d_BSplineCurve)& Geom2dAPI_Interpolate::Curve() const
{
if ( !myIsDone)
StdFail_NotDone::Raise(" ");
return myCurve;
}
//=======================================================================
//function : Geom2d_BSplineCurve
//purpose :
//=======================================================================
Geom2dAPI_Interpolate::operator Handle(Geom2d_BSplineCurve)() const
{
return myCurve;
}
//=======================================================================
//function : IsDone
//purpose :
//=======================================================================
Standard_Boolean Geom2dAPI_Interpolate::IsDone() const
{
return myIsDone;
}

View File

@@ -0,0 +1,254 @@
-- File: Geom2dAPI_PointsToBSpline.cdl
-- Created: Wed Mar 23 15:13:17 1994
-- Author: Bruno DUMORTIER
-- <dub@fuegox>
---Copyright: Matra Datavision 1994
class PointsToBSpline from Geom2dAPI
---Purpose: This class is used to approximate a BsplineCurve
-- passing through an array of points, with a given
-- Continuity.
-- Describes functions for building a 2D BSpline
-- curve which approximates a set of points.
-- A PointsToBSpline object provides a framework for:
-- - defining the data of the BSpline curve to be built,
-- - implementing the approximation algorithm, and
-- - consulting the results
uses
Array1OfReal from TColStd,
Array1OfPnt2d from TColgp,
Shape from GeomAbs,
BSplineCurve from Geom2d,
ParametrizationType from Approx
raises
NotDone from StdFail,
OutOfRange from Standard
is
Create
---Purpose: Constructs an empty approximation algorithm.
-- Use an Init function to define and build the BSpline curve.
returns PointsToBSpline from Geom2dAPI;
Create(Points : Array1OfPnt2d from TColgp;
DegMin : Integer from Standard = 3;
DegMax : Integer from Standard = 8;
Continuity : Shape from GeomAbs = GeomAbs_C2;
Tol2D : Real from Standard = 1.0e-6)
---Purpose: Approximate a BSpline Curve passing through an
-- array of Point. The resulting BSpline will have
-- the following properties:
-- 1- his degree will be in the range [Degmin,Degmax]
-- 2- his continuity will be at least <Continuity>
-- 3- the distance from the point <Points> to the
-- BSpline will be lower to Tol2D
---Level: Public
returns PointsToBSpline from Geom2dAPI;
Create(YValues : Array1OfReal from TColStd;
X0 : Real from Standard;
DX : Real from Standard;
DegMin : Integer from Standard = 3;
DegMax : Integer from Standard = 8;
Continuity : Shape from GeomAbs = GeomAbs_C2;
Tol2D : Real from Standard = 1.0e-6)
---Purpose: Approximate a BSpline Curve passing through an
-- array of Point. Of coordinates :
--
-- X = X0 + DX * (i-YValues.Lower())
-- Y = YValues(i)
--
-- With i in the range YValues.Lower(), YValues.Upper()
--
-- The BSpline will be parametrized from t = X0 to
-- X0 + DX * (YValues.Upper() - YValues.Lower())
--
-- And will satisfy X(t) = t
--
-- The resulting BSpline will have
-- the following properties:
-- 1- his degree will be in the range [Degmin,Degmax]
-- 2- his continuity will be at least <Continuity>
-- 3- the distance from the point <Points> to the
-- BSpline will be lower to Tol2D
---Level: Public
returns PointsToBSpline from Geom2dAPI;
Create(Points : Array1OfPnt2d from TColgp;
ParType : ParametrizationType from Approx;
DegMin : Integer from Standard = 3;
DegMax : Integer from Standard = 8;
Continuity : Shape from GeomAbs = GeomAbs_C2;
Tol2D : Real from Standard = 1.0e-3)
---Purpose: Approximate a BSpline Curve passing through an
-- array of Point. The resulting BSpline will have
-- the following properties:
-- 1- his degree will be in the range [Degmin,Degmax]
-- 2- his continuity will be at least <Continuity>
-- 3- the distance from the point <Points> to the
-- BSpline will be lower to Tol2D
---Level: Public
returns PointsToBSpline from Geom2dAPI;
Create(Points : Array1OfPnt2d from TColgp;
Parameters : Array1OfReal from TColStd;
DegMin : Integer from Standard = 3;
DegMax : Integer from Standard = 8;
Continuity : Shape from GeomAbs = GeomAbs_C2;
Tol2D : Real from Standard = 1.0e-3)
---Purpose: Approximate a BSpline Curve passing through an
-- array of Point, which parameters are given by the
-- array <Parameters>.
-- The resulting BSpline will have the following
-- properties:
-- 1- his degree will be in the range [Degmin,Degmax]
-- 2- his continuity will be at least <Continuity>
-- 3- the distance from the point <Points> to the
-- BSpline will be lower to Tol2D
---Level: Public
returns PointsToBSpline from Geom2dAPI
raises OutOfRange from Standard;
Create(Points : Array1OfPnt2d from TColgp;
Weight1 : Real from Standard;
Weight2 : Real from Standard;
Weight3 : Real from Standard;
DegMax : Integer from Standard = 8;
Continuity : Shape from GeomAbs = GeomAbs_C2;
Tol3D : Real from Standard = 1.0e-3)
---Purpose: Approximate a BSpline Curve passing through an
-- array of Point using variational smoothing algorithm,
-- which tries to minimize additional criterium:
-- Weight1*CurveLength + Weight2*Curvature + Weight3*Torsion
---Level: Public
returns PointsToBSpline from Geom2dAPI;
Init(me : in out;
Points : Array1OfPnt2d from TColgp;
DegMin : Integer from Standard = 3;
DegMax : Integer from Standard = 8;
Continuity : Shape from GeomAbs = GeomAbs_C2;
Tol2D : Real from Standard = 1.0e-6)
---Purpose: Approximate a BSpline Curve passing through an
-- array of Point. The resulting BSpline will have
-- the following properties:
-- 1- his degree will be in the range [Degmin,Degmax]
-- 2- his continuity will be at least <Continuity>
-- 3- the distance from the point <Points> to the
-- BSpline will be lower to Tol2D
---Level: Public
is static;
Init(me : in out;
YValues : Array1OfReal from TColStd;
X0 : Real from Standard;
DX : Real from Standard;
DegMin : Integer from Standard = 3;
DegMax : Integer from Standard = 8;
Continuity : Shape from GeomAbs = GeomAbs_C2;
Tol2D : Real from Standard = 1.0e-6)
---Purpose: Approximate a BSpline Curve passing through an
-- array of Point. Of coordinates :
--
-- X = X0 + DX * (i-YValues.Lower())
-- Y = YValues(i)
--
-- With i in the range YValues.Lower(), YValues.Upper()
--
-- The BSpline will be parametrized from t = X0 to
-- X0 + DX * (YValues.Upper() - YValues.Lower())
--
-- And will satisfy X(t) = t
--
-- The resulting BSpline will have
-- the following properties:
-- 1- his degree will be in the range [Degmin,Degmax]
-- 2- his continuity will be at least <Continuity>
-- 3- the distance from the point <Points> to the
-- BSpline will be lower to Tol2D
---Level: Public
is static;
Init(me : in out;
Points : Array1OfPnt2d from TColgp;
ParType : ParametrizationType from Approx;
DegMin : Integer from Standard = 3;
DegMax : Integer from Standard = 8;
Continuity : Shape from GeomAbs = GeomAbs_C2;
Tol2D : Real from Standard = 1.0e-3)
---Purpose: Approximate a BSpline Curve passing through an
-- array of Point. The resulting BSpline will have
-- the following properties:
-- 1- his degree will be in the range [Degmin,Degmax]
-- 2- his continuity will be at least <Continuity>
-- 3- the distance from the point <Points> to the
-- BSpline will be lower to Tol2D
---Level: Public
is static;
Init(me : in out;
Points : Array1OfPnt2d from TColgp;
Parameters : Array1OfReal from TColStd;
DegMin : Integer from Standard = 3;
DegMax : Integer from Standard = 8;
Continuity : Shape from GeomAbs = GeomAbs_C2;
Tol2D : Real from Standard = 1.0e-3)
---Purpose: Approximate a BSpline Curve passing through an
-- array of Point, which parameters are given by the
-- array <Parameters>.
-- The resulting BSpline will have the following
-- properties:
-- 1- his degree will be in the range [Degmin,Degmax]
-- 2- his continuity will be at least <Continuity>
-- 3- the distance from the point <Points> to the
-- BSpline will be lower to Tol2D
---Level: Public
is static;
Init(me : in out;
Points : Array1OfPnt2d from TColgp;
Weight1 : Real from Standard;
Weight2 : Real from Standard;
Weight3 : Real from Standard;
DegMax : Integer from Standard = 8;
Continuity : Shape from GeomAbs = GeomAbs_C2;
Tol2D : Real from Standard = 1.0e-3)
---Purpose: Approximate a BSpline Curve passing through an
-- array of Point using variational smoothing algorithm,
-- which tries to minimize additional criterium:
-- Weight1*CurveLength + Weight2*Curvature + Weight3*Torsion
---Level: Public
is static;
Curve(me)
---Purpose: Returns the approximate BSpline Curve
---Level: Public
returns BSplineCurve from Geom2d
---C++: return const &
---C++: alias "Standard_EXPORT operator Handle(Geom2d_BSplineCurve)() const;"
raises
NotDone from StdFail
is static;
IsDone(me)
returns Boolean from Standard;
fields
myIsDone : Boolean from Standard;
myCurve : BSplineCurve from Geom2d;
end PointsToBSpline;

View File

@@ -0,0 +1,485 @@
// File: Geom2dAPI_PointsToBSpline.cxx
// Created: Wed Mar 23 15:28:27 1994
// Author: Bruno DUMORTIER
// <dub@fuegox>
#include <Geom2dAPI_PointsToBSpline.ixx>
#include <AppDef_BSplineCompute.hxx>
#include <AppDef_MultiLine.hxx>
#include <AppParCurves_MultiBSpCurve.hxx>
#include <BSplCLib.hxx>
#include <TColStd_Array1OfInteger.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <math_Vector.hxx>
#include <AppDef_MultiPointConstraint.hxx>
#include <AppParCurves_HArray1OfConstraintCouple.hxx>
#include <AppDef_TheVariational.hxx>
//=======================================================================
//function : Geom2dAPI_PointsToBSpline
//purpose :
//=======================================================================
Geom2dAPI_PointsToBSpline::Geom2dAPI_PointsToBSpline()
{
myIsDone = Standard_False;
}
//=======================================================================
//function : Geom2dAPI_PointsToBSpline
//purpose :
//=======================================================================
Geom2dAPI_PointsToBSpline::Geom2dAPI_PointsToBSpline
(const TColgp_Array1OfPnt2d& Points,
const Standard_Integer DegMin,
const Standard_Integer DegMax,
const GeomAbs_Shape Continuity,
const Standard_Real Tol2D)
{
Init(Points,DegMin,DegMax,Continuity,Tol2D);
}
//=======================================================================
//function : Geom2dAPI_PointsToBSpline
//purpose :
//=======================================================================
Geom2dAPI_PointsToBSpline::Geom2dAPI_PointsToBSpline
(const TColStd_Array1OfReal& YValues,
const Standard_Real X0,
const Standard_Real DX,
const Standard_Integer DegMin,
const Standard_Integer DegMax,
const GeomAbs_Shape Continuity,
const Standard_Real Tol2D)
{
Init(YValues,X0,DX,DegMin,DegMax,Continuity,Tol2D);
}
//=======================================================================
//function : Geom2dAPI_PointsToBSpline
//purpose :
//=======================================================================
Geom2dAPI_PointsToBSpline::Geom2dAPI_PointsToBSpline
(const TColgp_Array1OfPnt2d& Points,
const Approx_ParametrizationType ParType,
const Standard_Integer DegMin,
const Standard_Integer DegMax,
const GeomAbs_Shape Continuity,
const Standard_Real Tol2D)
{
myIsDone = Standard_False;
Init(Points,ParType,DegMin,DegMax,Continuity,Tol2D);
}
//=======================================================================
//function : Geom2dAPI_PointsToBSpline
//purpose :
//=======================================================================
Geom2dAPI_PointsToBSpline::Geom2dAPI_PointsToBSpline
(const TColgp_Array1OfPnt2d& Points,
const TColStd_Array1OfReal& Params,
const Standard_Integer DegMin,
const Standard_Integer DegMax,
const GeomAbs_Shape Continuity,
const Standard_Real Tol2D)
{
myIsDone = Standard_False;
Init(Points,Params,DegMin,DegMax,Continuity,Tol2D);
}
//=======================================================================
//function : Geom2dAPI_PointsToBSpline
//purpose :
//=======================================================================
Geom2dAPI_PointsToBSpline::Geom2dAPI_PointsToBSpline
(const TColgp_Array1OfPnt2d& Points,
const Standard_Real W1,
const Standard_Real W2,
const Standard_Real W3,
const Standard_Integer DegMax,
const GeomAbs_Shape Continuity,
const Standard_Real Tol2D)
{
myIsDone = Standard_False;
Init(Points,W1,W2,W3,DegMax,Continuity,Tol2D);
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void Geom2dAPI_PointsToBSpline::Init
(const TColgp_Array1OfPnt2d& Points,
const Approx_ParametrizationType ParType,
const Standard_Integer DegMin,
const Standard_Integer DegMax,
const GeomAbs_Shape Continuity,
const Standard_Real Tol2D)
{
Standard_Real Tol3D = 0.; // dummy argument for BSplineCompute.
Standard_Integer nbit = 2;
Standard_Boolean UseSquares = Standard_False;
if(Tol2D <= 1.e-3) UseSquares = Standard_True;
AppDef_BSplineCompute TheComputer
(DegMin,DegMax,Tol3D,Tol2D,nbit,Standard_True,ParType,UseSquares);
switch( Continuity) {
case GeomAbs_C0:
TheComputer.SetContinuity(0); break;
case GeomAbs_G1:
case GeomAbs_C1:
TheComputer.SetContinuity(1); break;
case GeomAbs_G2:
case GeomAbs_C2:
TheComputer.SetContinuity(2); break;
default:
TheComputer.SetContinuity(3);
}
TheComputer.Perform(Points);
AppParCurves_MultiBSpCurve TheCurve = TheComputer.Value();
TColgp_Array1OfPnt2d Poles(1,TheCurve.NbPoles());
TheCurve.Curve(1, Poles);
myCurve = new Geom2d_BSplineCurve(Poles,
TheCurve.Knots(),
TheCurve.Multiplicities(),
TheCurve.Degree());
myIsDone = Standard_True;
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void Geom2dAPI_PointsToBSpline::Init
(const TColStd_Array1OfReal& YValues,
const Standard_Real X0,
const Standard_Real DX,
const Standard_Integer DegMin,
const Standard_Integer DegMax,
const GeomAbs_Shape Continuity,
const Standard_Real Tol2D)
{
// first approximate the Y values (with dummy 0 as X values)
Standard_Real Tol3D = 0.; // dummy argument for BSplineCompute.
TColgp_Array1OfPnt2d Points(YValues.Lower(),YValues.Upper());
math_Vector Param(YValues.Lower(),YValues.Upper());
Standard_Real length = DX * (YValues.Upper() - YValues.Lower());
Standard_Integer i;
for (i = YValues.Lower(); i <= YValues.Upper(); i++) {
Param(i) = (X0+(i-1)*DX)/(X0+length);
Points(i).SetCoord(0.0, YValues(i));
}
AppDef_BSplineCompute TheComputer
(Param, DegMin,DegMax,Tol3D,Tol2D,0, Standard_True, Standard_True);
switch( Continuity) {
case GeomAbs_C0:
TheComputer.SetContinuity(0); break;
case GeomAbs_G1:
case GeomAbs_C1:
TheComputer.SetContinuity(1); break;
case GeomAbs_G2:
case GeomAbs_C2:
TheComputer.SetContinuity(2); break;
default:
TheComputer.SetContinuity(3);
}
TheComputer.Perform(Points);
const AppParCurves_MultiBSpCurve& TheCurve = TheComputer.Value();
Standard_Integer Degree = TheCurve.Degree();
TColgp_Array1OfPnt2d Poles(1,TheCurve.NbPoles());
Standard_Integer nk = TheCurve.Knots().Length();
TColStd_Array1OfReal Knots(1,nk);
TColStd_Array1OfInteger Mults(1,nk);
TheCurve.Curve(1, Poles);
// compute X values for the poles
TColStd_Array1OfReal XPoles(1,Poles.Upper());
// start with a line
TColStd_Array1OfReal TempPoles(1,2);
TColStd_Array1OfReal TempKnots(1,2);
TColStd_Array1OfInteger TempMults(1,2);
TempMults.Init(2);
TempPoles(1) = X0;
TempPoles(2) = X0 + length;
TempKnots(1) = 0.;
TempKnots(2) = 1.;
// increase the Degree
TColStd_Array1OfReal NewTempPoles(1,Degree+1);
TColStd_Array1OfReal NewTempKnots(1,2);
TColStd_Array1OfInteger NewTempMults(1,2);
BSplCLib::IncreaseDegree(1,Degree,Standard_False,1,
TempPoles,TempKnots,TempMults,
NewTempPoles,NewTempKnots,NewTempMults);
// insert the Knots
BSplCLib::InsertKnots(Degree,Standard_False,1,
NewTempPoles,NewTempKnots,NewTempMults,
TheCurve.Knots(),TheCurve.Multiplicities(),
XPoles,Knots,Mults,
Epsilon(1));
// scale the knots
for (i = 1; i <= nk; i++) {
Knots(i) = X0 + length * Knots(i);
}
// set the Poles
for (i = 1; i <= Poles.Upper(); i++) {
Poles(i).SetX(XPoles(i));
}
myCurve = new Geom2d_BSplineCurve(Poles, Knots, Mults, Degree);
myIsDone = Standard_True;
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void Geom2dAPI_PointsToBSpline::Init
(const TColgp_Array1OfPnt2d& Points,
const Standard_Integer DegMin,
const Standard_Integer DegMax,
const GeomAbs_Shape Continuity,
const Standard_Real Tol2D)
{
myIsDone = Standard_False;
Init(Points,Approx_ChordLength,DegMin,DegMax,Continuity,Tol2D);
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void Geom2dAPI_PointsToBSpline::Init
(const TColgp_Array1OfPnt2d& Points,
const TColStd_Array1OfReal& Params,
const Standard_Integer DegMin,
const Standard_Integer DegMax,
const GeomAbs_Shape Continuity,
const Standard_Real Tol2D)
{
if (Params.Length() != Points.Length()) Standard_OutOfRange::Raise("");
Standard_Real Tol3D = 0.; // dummy argument for BSplineCompute.
Standard_Integer Nbp = Params.Length();
math_Vector theParams(1,Nbp);
theParams(1) = 0.;
theParams(Nbp) = 1.;
Standard_Real Uf = Params(Params.Lower());
Standard_Real Ul = Params(Params.Upper()) - Uf;
for (Standard_Integer i=2; i<Nbp; i++) {
theParams(i) = (Params(i)-Uf)/Ul;
}
AppDef_BSplineCompute TheComputer
(DegMin,DegMax,Tol3D,Tol2D,0,
Standard_True,Approx_IsoParametric,Standard_True);
TheComputer.SetParameters(theParams);
switch( Continuity) {
case GeomAbs_C0:
TheComputer.SetContinuity(0); break;
case GeomAbs_G1:
case GeomAbs_C1:
TheComputer.SetContinuity(1); break;
case GeomAbs_G2:
case GeomAbs_C2:
TheComputer.SetContinuity(2); break;
default:
TheComputer.SetContinuity(3);
}
TheComputer.Perform(Points);
AppParCurves_MultiBSpCurve TheCurve = TheComputer.Value();
TColgp_Array1OfPnt2d Poles(1,TheCurve.NbPoles());
TheCurve.Curve(1, Poles);
myCurve = new Geom2d_BSplineCurve(Poles,
TheCurve.Knots(),
TheCurve.Multiplicities(),
TheCurve.Degree());
myIsDone = Standard_True;
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void Geom2dAPI_PointsToBSpline::Init
(const TColgp_Array1OfPnt2d& Points,
const Standard_Real W1,
const Standard_Real W2,
const Standard_Real W3,
const Standard_Integer DegMax,
const GeomAbs_Shape Continuity,
const Standard_Real Tol2D)
{
Standard_Integer NbPoint = Points.Length(), i;
Standard_Integer nbit = 2;
if(Tol2D <= 1.e-3) nbit = 0;
//Variational algo
AppDef_MultiLine multL(NbPoint);
for(i = 1; i <= NbPoint; ++i) {
AppDef_MultiPointConstraint mpc(0, 1);
mpc.SetPoint2d(1, Points.Value(Points.Lower() + i - 1));
multL.SetValue(i, mpc);
}
Handle(AppParCurves_HArray1OfConstraintCouple) TABofCC =
new AppParCurves_HArray1OfConstraintCouple(1, NbPoint);
AppParCurves_Constraint Constraint=AppParCurves_NoConstraint;
for(i = 1; i <= NbPoint; ++i) {
AppParCurves_ConstraintCouple ACC(i,Constraint);
TABofCC->SetValue(i,ACC);
}
AppDef_TheVariational Variation(multL, 1, NbPoint, TABofCC);
//===================================
Standard_Integer theMaxSegments = 1000;
Standard_Boolean theWithMinMax = Standard_False;
//===================================
Variation.SetMaxDegree(DegMax);
Variation.SetContinuity(Continuity);
Variation.SetMaxSegment(theMaxSegments);
Variation.SetTolerance(Tol2D);
Variation.SetWithMinMax(theWithMinMax);
Variation.SetNbIterations(nbit);
Variation.SetCriteriumWeight(W1, W2, W3);
if(!Variation.IsCreated()) {
return;
}
if(Variation.IsOverConstrained()) {
return;
}
try {
Variation.Approximate();
}
catch (Standard_Failure) {
return;
}
if(!Variation.IsDone()) {
return;
}
AppParCurves_MultiBSpCurve TheCurve = Variation.Value();
TColgp_Array1OfPnt2d Poles(1,TheCurve.NbPoles());
TheCurve.Curve(1, Poles);
myCurve = new Geom2d_BSplineCurve(Poles,
TheCurve.Knots(),
TheCurve.Multiplicities(),
TheCurve.Degree());
myIsDone = Standard_True;
}
//=======================================================================
//function : Handle_Geom2d_BSplineCurve&
//purpose :
//=======================================================================
const Handle(Geom2d_BSplineCurve)& Geom2dAPI_PointsToBSpline::Curve() const
{
if ( !myIsDone)
StdFail_NotDone::Raise(" ");
return myCurve;
}
//=======================================================================
//function : Geom2d_BSplineCurve
//purpose :
//=======================================================================
Geom2dAPI_PointsToBSpline::operator Handle(Geom2d_BSplineCurve)() const
{
return myCurve;
}
//=======================================================================
//function : Geom2d_BSplineCurve
//purpose :
//=======================================================================
Standard_Boolean Geom2dAPI_PointsToBSpline::IsDone() const
{
return myIsDone;
}

View File

@@ -0,0 +1,182 @@
-- File: Geom2dAPI_ProjectPointOnCurve.cdl
-- Created: Wed Mar 23 15:03:16 1994
-- Author: Bruno DUMORTIER
-- <dub@fuegox>
---Copyright: Matra Datavision 1994
class ProjectPointOnCurve from Geom2dAPI
---Purpose:
-- This class implements methods for computing all the orthogonal
-- projections of a 2D point onto a 2D curve.
uses
Curve from Geom2d,
Curve from Geom2dAdaptor,
ExtPC2d from Extrema,
Pnt2d from gp,
Length from Quantity,
Parameter from Quantity
raises
OutOfRange from Standard,
NotDone from StdFail
is
Create
---Purpose: Constructs an empty projector algorithm. Use an Init
-- function to define the point and the curve on which it is going to work.
returns ProjectPointOnCurve from Geom2dAPI;
Create(P : Pnt2d from gp;
Curve : Curve from Geom2d)
---Purpose: Create the projection of a point <P> on a curve
-- <Curve>
---Level: Public
returns ProjectPointOnCurve from Geom2dAPI;
Create(P : Pnt2d from gp;
Curve : Curve from Geom2d;
Umin, Usup : Parameter from Quantity)
---Purpose: Create the projection of a point <P> on a curve
-- <Curve> limited by the two points of parameter Umin and Usup.
-- Warning
-- Use the function NbPoints to obtain the number of solutions. If
-- projection fails, NbPoints returns 0.
returns ProjectPointOnCurve from Geom2dAPI;
Init(me : in out;
P : Pnt2d from gp;
Curve : Curve from Geom2d)
---Purpose: Initializes this algorithm with the given arguments, and
-- computes the orthogonal projections of a point <P> on a curve <Curve>
is static;
Init(me : in out;
P : Pnt2d from gp;
Curve : Curve from Geom2d;
Umin, Usup : Parameter from Quantity)
---Purpose: Initializes this algorithm with the given arguments, and
-- computes the orthogonal projections of the point P onto the portion
-- of the curve Curve limited by the two points of parameter Umin and Usup.
is static;
NbPoints(me)
---Purpose: return the number of of computed
-- orthogonal projectionn points.
returns Integer from Standard
---C++: alias "Standard_EXPORT operator Standard_Integer() const;"
is static;
Point(me; Index : Integer from Standard)
returns Pnt2d from gp
---Purpose: Returns the orthogonal projection
-- on the curve. Index is a number of a computed point.
-- Exceptions
-- Standard_OutOfRange if Index is not in the range [ 1,NbPoints ], where
-- NbPoints is the number of solution points.
raises
OutOfRange from Standard
is static;
Parameter(me; Index : Integer from Standard)
returns Parameter from Quantity
---Purpose: Returns the parameter on the curve
-- of a point which is the orthogonal projection. Index is a number of a
-- computed projected point.
-- Exceptions
-- Standard_OutOfRange if Index is not in the range [ 1,NbPoints ], where
-- NbPoints is the number of solution points.
raises
OutOfRange from Standard
is static;
Parameter(me; Index : Integer from Standard;
U : out Parameter from Quantity)
---Purpose: Returns the parameter on the curve
-- of a point which is the orthogonal projection. Index is a number of a
-- computed projected point.
-- Exceptions
-- Standard_OutOfRange if Index is not in the range [ 1,NbPoints ], where
-- NbPoints is the number of solution points
raises
OutOfRange from Standard
is static;
Distance(me; Index : Integer from Standard)
returns Length from Quantity
---Purpose: Computes the distance between the
-- point and its computed orthogonal projection on the curve. Index is a
-- number of computed projected point.
-- Exceptions
-- Standard_OutOfRange if Index is not in the range [ 1,NbPoints ], where
-- NbPoints is the number of solution points.
raises
OutOfRange from Standard
is static;
NearestPoint(me)
returns Pnt2d from gp
---Purpose: Returns the nearest orthogonal projection of the point on the curve.
-- Exceptions
-- StdFail_NotDone if this algorithm fails.
---C++: alias "Standard_EXPORT operator gp_Pnt2d() const;"
raises
NotDone from StdFail
is static;
LowerDistanceParameter(me)
returns Parameter from Quantity
---Purpose: Returns the parameter on the curve
-- of the nearest orthogonal projection of the point.
-- Exceptions
-- StdFail_NotDone if this algorithm fails.
raises
NotDone from StdFail
is static;
LowerDistance(me)
---Purpose: Computes the distance between the
-- point and its nearest orthogonal projection on the curve.
-- Exceptions
-- StdFail_NotDone if this algorithm fails.
returns Length from Quantity
---C++: alias "Standard_EXPORT operator Standard_Real() const;"
raises
NotDone from StdFail
is static;
Extrema(me)
---Purpose: return the algorithmic object from Extrema
---Level: Advanced
---C++: return const&
---C++: inline
returns ExtPC2d from Extrema
is static;
fields
myIsDone: Boolean from Standard;
myIndex : Integer from Standard; -- index of the nearest solution
myExtPC : ExtPC2d from Extrema;
myC : Curve from Geom2dAdaptor;
end ProjectPointOnCurve;

View File

@@ -0,0 +1,243 @@
// File: Geom2dAPI_ProjectPointOnCurve.cxx
// Created: Wed Mar 23 15:16:37 1994
// Author: Bruno DUMORTIER
// <dub@fuegox>
#include <Geom2dAPI_ProjectPointOnCurve.ixx>
#include <Geom2dAdaptor_Curve.hxx>
//=======================================================================
//function : Geom2dAPI_ProjectPointOnCurve
//purpose :
//=======================================================================
Geom2dAPI_ProjectPointOnCurve::Geom2dAPI_ProjectPointOnCurve()
{
myIsDone = Standard_False;
}
//=======================================================================
//function : Geom2dAPI_ProjectPointOnCurve
//purpose :
//=======================================================================
Geom2dAPI_ProjectPointOnCurve::Geom2dAPI_ProjectPointOnCurve
(const gp_Pnt2d& P,
const Handle(Geom2d_Curve)& Curve)
{
Init(P,Curve);
}
//=======================================================================
//function : Geom2dAPI_ProjectPointOnCurve
//purpose :
//=======================================================================
Geom2dAPI_ProjectPointOnCurve::Geom2dAPI_ProjectPointOnCurve
(const gp_Pnt2d& P,
const Handle(Geom2d_Curve)& Curve,
const Standard_Real Umin,
const Standard_Real Usup)
{
Init(P,Curve,Umin,Usup);
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void Geom2dAPI_ProjectPointOnCurve::Init
(const gp_Pnt2d& P,
const Handle(Geom2d_Curve)& Curve)
{
Init(P,Curve,Curve->FirstParameter(),Curve->LastParameter());
}
//=======================================================================
//function : Init
//purpose :
//=======================================================================
void Geom2dAPI_ProjectPointOnCurve::Init
(const gp_Pnt2d& P,
const Handle(Geom2d_Curve)& Curve,
const Standard_Real Umin,
const Standard_Real Usup )
{
myC.Load(Curve,Umin,Usup);
Extrema_ExtPC2d theExtPC2d(P, myC);
myExtPC = theExtPC2d;
myIsDone = myExtPC.IsDone() && ( myExtPC.NbExt() > 0);
// evaluate the lower distance and its index;
if ( myIsDone) {
Standard_Real Dist2, Dist2Min = myExtPC.SquareDistance(1);
myIndex = 1;
for ( Standard_Integer i = 2; i <= myExtPC.NbExt(); i++) {
Dist2 = myExtPC.SquareDistance(i);
if ( Dist2 < Dist2Min) {
Dist2Min = Dist2;
myIndex = i;
}
}
}
}
//=======================================================================
//function : NbPoints
//purpose :
//=======================================================================
Standard_Integer Geom2dAPI_ProjectPointOnCurve::NbPoints() const
{
if ( myIsDone)
return myExtPC.NbExt();
else
return 0;
}
//=======================================================================
//function : Point
//purpose :
//=======================================================================
gp_Pnt2d Geom2dAPI_ProjectPointOnCurve::Point
(const Standard_Integer Index) const
{
Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
"Geom2dAPI_ProjectPointOnCurve::Point");
return (myExtPC.Point(Index)).Value();
}
//=======================================================================
//function : Parameter
//purpose :
//=======================================================================
Standard_Real Geom2dAPI_ProjectPointOnCurve::Parameter
(const Standard_Integer Index) const
{
Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
"Geom2dAPI_ProjectPointOnCurve::Parameter");
return (myExtPC.Point(Index)).Parameter();
}
//=======================================================================
//function : Parameter
//purpose :
//=======================================================================
void Geom2dAPI_ProjectPointOnCurve::Parameter
(const Standard_Integer Index,
Standard_Real& U ) const
{
Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
"Geom2dAPI_ProjectPointOnCurve::Parameter");
U = (myExtPC.Point(Index)).Parameter();
}
//=======================================================================
//function : Distance
//purpose :
//=======================================================================
Standard_Real Geom2dAPI_ProjectPointOnCurve::Distance
(const Standard_Integer Index) const
{
Standard_OutOfRange_Raise_if( Index < 1 || Index > NbPoints(),
"Geom2dAPI_ProjectPointOnCurve::Distance");
return sqrt(myExtPC.SquareDistance(Index));
}
//=======================================================================
//function : NearestPoint
//purpose :
//=======================================================================
gp_Pnt2d Geom2dAPI_ProjectPointOnCurve::NearestPoint() const
{
StdFail_NotDone_Raise_if
(!myIsDone, "Geom2dAPI_ProjectPointOnCurve:NearestPoint");
return (myExtPC.Point(myIndex)).Value();
}
//=======================================================================
//function : Standard_Integer
//purpose :
//=======================================================================
Geom2dAPI_ProjectPointOnCurve::operator Standard_Integer() const
{
return NbPoints();
}
//=======================================================================
//function : gp_Pnt2d
//purpose :
//=======================================================================
Geom2dAPI_ProjectPointOnCurve::operator gp_Pnt2d() const
{
return NearestPoint();
}
//=======================================================================
//function : LowerDistanceParameter
//purpose :
//=======================================================================
Standard_Real Geom2dAPI_ProjectPointOnCurve::LowerDistanceParameter() const
{
StdFail_NotDone_Raise_if
(!myIsDone, "Geom2dAPI_ProjectPointOnCurve:LowerDistanceParameter");
return (myExtPC.Point(myIndex)).Parameter();
}
//=======================================================================
//function : LowerDistance
//purpose :
//=======================================================================
Standard_Real Geom2dAPI_ProjectPointOnCurve::LowerDistance() const
{
StdFail_NotDone_Raise_if
(!myIsDone,"Geom2dAPI_ProjectPointOnCurve:LowerDistance");
return sqrt (myExtPC.SquareDistance(myIndex));
}
//=======================================================================
//function : operator
//purpose :
//=======================================================================
Geom2dAPI_ProjectPointOnCurve::operator Standard_Real() const
{
return LowerDistance();
}

View File

@@ -0,0 +1,15 @@
// File: Geom2dAPI_ProjectPointOnCurve.lxx
// Created: Wed Mar 23 15:21:27 1994
// Author: Bruno DUMORTIER
// <dub@fuegox>
//=======================================================================
//function : Extrema
//purpose :
//=======================================================================
inline const Extrema_ExtPC2d& Geom2dAPI_ProjectPointOnCurve::Extrema() const
{
return myExtPC;
}