summaryrefslogtreecommitdiff
path: root/inc/GCPnts_QuasiUniformAbscissa.gxx
blob: 70d5161f09712daa11c8f7df5cc6c3d6a768bde0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// File:	GCPnts_QuasiUniformAbscissa.gxx
// Created:	Thu Aug 22 15:58:50 1996
// Author:	Stagiaire Mary FABIEN
//		<fbi@zozox.paris1.matra-dtv.fr>


//=======================================================================
//function : GCPnts_QuasiUniformAbscissa
//purpose  : 
//=======================================================================

GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(TheCurve& C, 
					       const Standard_Integer NbPoints)
{
  Initialize(C, NbPoints);
}

//=======================================================================
//function : GCPnts_QuasiUniformAbscissa
//purpose  : 
//=======================================================================

GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(TheCurve& C, 
					       const Standard_Integer NbPoints,
					       const Standard_Real U1, 
					       const Standard_Real U2)
{
  Initialize(C, NbPoints, U1, U2);
}

//=======================================================================
//function : Initialize
//purpose  : 
//=======================================================================

void GCPnts_QuasiUniformAbscissa::Initialize(TheCurve& C, 
					const Standard_Integer NbPoints)
{
  Initialize(C, NbPoints, C.FirstParameter(),
	     C.LastParameter());
} 


//=======================================================================
//function : Initialize
//purpose  : 
//=======================================================================

void GCPnts_QuasiUniformAbscissa::Initialize(TheCurve& C, 
					     const Standard_Integer NbPoints,
					     const Standard_Real U1, 
					     const Standard_Real U2)
{
  Standard_Integer i;
  if ((C.GetType() != GeomAbs_BezierCurve) && (C.GetType() != GeomAbs_BSplineCurve))
    {
      GCPnts_UniformAbscissa UA(C,NbPoints,U1,U2);
      myDone = UA.IsDone();
      myNbPoints = UA.NbPoints();
      myParams = new TColStd_HArray1OfReal(1,myNbPoints);
      for( i = 1 ; i <= myNbPoints ; i++ ) 
	myParams->SetValue(i,UA.Parameter(i));
#ifdef DEB

//      char name [100];
//      for( i = 1 ; i <= NbPoints ; i++ ) {
//	sprintf(name,"%s_%d","pnt2d",i+(compteur++));
//	DrawTrSurf::Set(name,C->Value(UA.Parameter(i)));
//      }
#endif
    }
  else {
    Standard_ConstructionError_Raise_if(NbPoints <= 1, "");
    
// evaluate the approximative length of the 3dCurve
    myNbPoints = NbPoints;
    Standard_Real Length = 0.;
    Standard_Real Dist, dU = (U2 - U1) / ( 2*NbPoints - 1);
    
    TColgp_Array1OfPnt2d LP(1,2*NbPoints); // tableau Longueur <-> Param
    ThePnt P1, P2;
    P1 = C.Value(U1);
    
// On additionne toutes les distances
    for ( i = 0; i < 2*NbPoints ; i++) {
      P2      = C.Value(U1 + i*dU);
      Dist    = P1.Distance(P2);
      Length += Dist;
      LP(i+1) = gp_Pnt2d( Length, U1 + (i*dU));
      P1      = P2;
    }

// On cherche a mettre NbPoints dans la curve.
// on met les points environ a Length/NbPoints.

    Standard_Real DCorde = Length / ( NbPoints - 1); 
    Standard_Real Corde  = DCorde;
    Standard_Integer Index = 1;
    Standard_Real U, Alpha;
    myParams = new TColStd_HArray1OfReal(1,NbPoints); 
    myParams->SetValue(1,U1); 
    for ( i = 2; i < NbPoints; i++) {
      while ( LP(Index).X() < Corde) Index ++;
      Alpha = (Corde - LP(Index-1).X()) / (LP(Index).X() - LP(Index-1).X());
      U = LP(Index-1).Y() + Alpha * ( LP(Index).Y() - LP(Index-1).Y());
      myParams->SetValue(i,U);
      Corde = i*DCorde;
    }
    myParams->SetValue(NbPoints,U2);
    myDone = Standard_True;
  }
}