0024157: Parallelization of assembly part of BO
[occt.git] / src / GCPnts / GCPnts_QuasiUniformAbscissa.gxx
CommitLineData
b311480e 1// Created on: 1996-08-22
2// Created by: Stagiaire Mary FABIEN
3// Copyright (c) 1996-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23//=======================================================================
24//function : GCPnts_QuasiUniformAbscissa
25//purpose :
26//=======================================================================
27
28GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(TheCurve& C,
29 const Standard_Integer NbPoints)
30{
31 Initialize(C, NbPoints);
32}
33
34//=======================================================================
35//function : GCPnts_QuasiUniformAbscissa
36//purpose :
37//=======================================================================
38
39GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(TheCurve& C,
40 const Standard_Integer NbPoints,
41 const Standard_Real U1,
42 const Standard_Real U2)
43{
44 Initialize(C, NbPoints, U1, U2);
45}
46
47//=======================================================================
48//function : Initialize
49//purpose :
50//=======================================================================
51
52void GCPnts_QuasiUniformAbscissa::Initialize(TheCurve& C,
53 const Standard_Integer NbPoints)
54{
55 Initialize(C, NbPoints, C.FirstParameter(),
56 C.LastParameter());
57}
58
59
60//=======================================================================
61//function : Initialize
62//purpose :
63//=======================================================================
64
65void GCPnts_QuasiUniformAbscissa::Initialize(TheCurve& C,
66 const Standard_Integer NbPoints,
67 const Standard_Real U1,
68 const Standard_Real U2)
69{
70 Standard_Integer i;
71 if ((C.GetType() != GeomAbs_BezierCurve) && (C.GetType() != GeomAbs_BSplineCurve))
72 {
73 GCPnts_UniformAbscissa UA(C,NbPoints,U1,U2);
74 myDone = UA.IsDone();
75 myNbPoints = UA.NbPoints();
76 myParams = new TColStd_HArray1OfReal(1,myNbPoints);
77 for( i = 1 ; i <= myNbPoints ; i++ )
78 myParams->SetValue(i,UA.Parameter(i));
79#ifdef DEB
80
81// char name [100];
82// for( i = 1 ; i <= NbPoints ; i++ ) {
83// sprintf(name,"%s_%d","pnt2d",i+(compteur++));
84// DrawTrSurf::Set(name,C->Value(UA.Parameter(i)));
85// }
86#endif
87 }
88 else {
89 Standard_ConstructionError_Raise_if(NbPoints <= 1, "");
90
91// evaluate the approximative length of the 3dCurve
92 myNbPoints = NbPoints;
93 Standard_Real Length = 0.;
94 Standard_Real Dist, dU = (U2 - U1) / ( 2*NbPoints - 1);
95
96 TColgp_Array1OfPnt2d LP(1,2*NbPoints); // tableau Longueur <-> Param
97 ThePnt P1, P2;
98 P1 = C.Value(U1);
99
100// On additionne toutes les distances
101 for ( i = 0; i < 2*NbPoints ; i++) {
102 P2 = C.Value(U1 + i*dU);
103 Dist = P1.Distance(P2);
104 Length += Dist;
105 LP(i+1) = gp_Pnt2d( Length, U1 + (i*dU));
106 P1 = P2;
107 }
108
109// On cherche a mettre NbPoints dans la curve.
110// on met les points environ a Length/NbPoints.
111
112 Standard_Real DCorde = Length / ( NbPoints - 1);
113 Standard_Real Corde = DCorde;
114 Standard_Integer Index = 1;
115 Standard_Real U, Alpha;
116 myParams = new TColStd_HArray1OfReal(1,NbPoints);
117 myParams->SetValue(1,U1);
118 for ( i = 2; i < NbPoints; i++) {
119 while ( LP(Index).X() < Corde) Index ++;
120 Alpha = (Corde - LP(Index-1).X()) / (LP(Index).X() - LP(Index-1).X());
121 U = LP(Index-1).Y() + Alpha * ( LP(Index).Y() - LP(Index-1).Y());
122 myParams->SetValue(i,U);
123 Corde = i*DCorde;
124 }
125 myParams->SetValue(NbPoints,U2);
126 myDone = Standard_True;
127 }
128}
129