summaryrefslogtreecommitdiff
path: root/inc/Approx_ComputeCSurface.gxx
blob: b8f2dbdd0a7695184572866e9caab7bcf7dc4921 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#include <Precision.hxx>
#include <TColStd_Array2OfReal.hxx>


Approx_ComputeCSurface::Approx_ComputeCSurface(
			  const Surface&                Surf,
			  const Standard_Integer        degreemin,
			  const Standard_Integer        degreemax,
			  const Standard_Real           Tolerance3d,
			  const AppParCurves_Constraint FirstCons,
			  const AppParCurves_Constraint LastUCons,
			  const AppParCurves_Constraint LastVCons,
			  const AppParCurves_Constraint LastCons,
			  const Standard_Boolean        cutting)
{
  mydegremin = degreemin;
  mydegremax = degreemax;
  mytol3d = Tolerance3d;
  myfirstUCons  = FirstCons;
  mylastUCons   = LastUCons;
  mylastVCons   = LastVCons;
  mylastCons    = LastCons;
  mycut = cutting;
  
  Perform(Surf);
}



Approx_ComputeCSurface::Approx_ComputeCSurface(
			  const Standard_Integer        degreemin,
			  const Standard_Integer        degreemax,
			  const Standard_Real           Tolerance3d,
			  const AppParCurves_Constraint FirstCons,
			  const AppParCurves_Constraint LastUCons,
			  const AppParCurves_Constraint LastVCons,
			  const AppParCurves_Constraint LastCons,
			  const Standard_Boolean        cutting)
{
  mydegremin = degreemin;
  mydegremax = degreemax;
  mytol3d = Tolerance3d;
  myfirstUCons  = FirstCons;
  mylastUCons   = LastUCons;
  mylastVCons   = LastVCons;
  mylastCons    = LastCons;
  mycut = cutting;
}



void Approx_ComputeCSurface::Perform(const Surface& Surf) 
{
  Standard_Real UFirst, ULast, VFirst, VLast;
  UFirst = SurfaceTool::FirstUParameter(Surf);
  ULast  = SurfaceTool::LastUParameter(Surf);
  VFirst = SurfaceTool::FirstVParameter(Surf);
  VLast  = SurfaceTool::LastVParameter(Surf);
  Standard_Boolean Finish = Standard_False, 
          begin = Standard_True, Ok = Standard_False;
  Standard_Real thetol3d;
  Standard_Real myfirstU = UFirst, mylastU = ULast;
  Standard_Real myfirstV = VFirst, mylastV = VLast;
  Standard_Integer i;

  TColStd_Array2OfReal Error(1, 50, 1, 50);   // pour l instant

  if (!mycut) {
    alldone = Compute(Surf, UFirst, ULast, VFirst, VLast, thetol3d);
    if (!alldone) {
      tolreached = Standard_False;
      mySurfaces.Append(TheSurface);
      Tolers3d.Append(thetol3d);
      myfirstUparam.Append(UFirst);
      mylastUparam.Append(ULast);
      myfirstVparam.Append(VFirst);
      mylastVparam.Append(VLast);
    }
  }

  else {  // gestion du decoupage:
    TColStd_SequenceOfReal TheU, TheV;
    TheU.Append(UFirst);
    TheU.Append(ULast);
    TheV.Append(VFirst);
    TheV.Append(VLast);

    while (!Finish) {
      
      Ok = Compute(Surf, myfirstU, mylastU, myfirstV, mylastV, thetol3d);
      if (Ok) {
	if (Abs(ULast-mylastU) <= Precision::PConfusion() &&
	    Abs(VLast-mylastV) <= Precision::PConfusion()) {
	  Finish = Standard_True;
	  alldone = Standard_True;
	  return;
	}
	myfirstU = mylastU;
	mylastU = ULast;
      }
      else {
	// choix du decoupage en u ou en v:
	// si debut, en u:
	if (begin) {
	  begin = Standard_False;
	  mylastU = (myfirstU + mylastU)/2.;
	  TheU.InsertAfter(1, mylastU);
	  Error.SetValue(1, 1, currenttol3d);
	}
	else {
	  Standard_Real tolu, tolv;
	  for (i = 1; i <= TheU.Length(); i++) {
	    
	  }

	}


      }
      
      
    }      

  }

}



Standard_Boolean Approx_ComputeCSurface::Compute(const Surface&      Surf,
						 const Standard_Real Ufirst,
						 const Standard_Real Ulast,
						 const Standard_Real Vfirst,
						 const Standard_Real Vlast,
						 Standard_Real&      TheTol3d) 

{
  Standard_Integer NbPoints = 12;     // 12 * 12 sur la surface.
  Standard_Integer degu, degv;
  Standard_Real Fv;

  for (degu = mydegremin; degu <= mydegremax; degu++) {
    for (degv = mydegremin; degv <= mydegremax; degv++) {
      Approx_MySLeastSquare LSQ(Surf, Ufirst, Ulast, Vfirst, Vlast,
				myfirstUCons, mylastUCons, 
				mylastVCons, mylastCons,
				degu, degv, NbPoints);
      LSQ.Error(Fv, TheTol3d);
      if (TheTol3d <= mytol3d) {
	TheSurface = LSQ.Value();
	mySurfaces.Append(TheSurface);
	tolreached = Standard_True;
	Tolers3d.Append(TheTol3d);
	currenttol3d = TheTol3d;
	myfirstUparam.Append(Ufirst);
	mylastUparam.Append(Ulast);
	myfirstVparam.Append(Vfirst);
	mylastVparam.Append(Vlast);
	return Standard_True;
      }
      
      if (degu == mydegremax && degv == mydegremax) {
	TheSurface = LSQ.Value();
	tolreached = Standard_False;
	currenttol3d = TheTol3d;
      }
    }
  }
  return Standard_False;
}



Standard_Real Approx_ComputeCSurface::Error(const Standard_Integer Index)const
{
  return Tolers3d.Value(Index);
}
				   


Handle(Geom_BezierSurface) Approx_ComputeCSurface::Value(const Standard_Integer Index)const
{
  return Handle(Geom_BezierSurface)::DownCast(mySurfaces.Value(Index));
}


Standard_Integer Approx_ComputeCSurface::NbSurfaces() const
{
  return mySurfaces.Length();
}


void Approx_ComputeCSurface::Parameters(const Standard_Integer Index,
					Standard_Real& firstU,
					Standard_Real& lastU,
					Standard_Real& firstV,
					Standard_Real& lastV)const
{
  firstU = myfirstUparam.Value(Index);
  lastU = mylastUparam.Value(Index);
  firstV = myfirstVparam.Value(Index);
  lastV = mylastVparam.Value(Index);
}


Standard_Boolean Approx_ComputeCSurface::IsToleranceReached() const
{
  return tolreached;
}

Standard_Boolean Approx_ComputeCSurface::IsAllApproximated() const
{
  return alldone;
}


void Approx_ComputeCSurface::SetDegrees(const Standard_Integer degreemin,
					const Standard_Integer degreemax)
{
  mydegremin = degreemin;
  mydegremax = degreemax;
}



void Approx_ComputeCSurface::SetTolerance(const Standard_Real Tolerance3d)
{
  mytol3d = Tolerance3d;
}