b311480e |
1 | // Created on: 1993-02-03 |
2 | // Created by: Laurent BUCHARD |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <gp_Pnt.hxx> |
18 | #include <gp_Vec.hxx> |
19 | #include <gp_Dir.hxx> |
20 | #include <gp_Lin.hxx> |
21 | #include <TColgp_Array2OfPnt.hxx> |
22 | #include <TColStd_Array2OfReal.hxx> |
23 | |
24 | #include <Bnd_Array1OfBox.hxx> |
25 | |
26 | #include <Standard_ConstructionError.hxx> |
27 | |
28 | //#if defined (WNT) || !defined (DEB) |
29 | #include <stdio.h> |
30 | //#endif |
31 | |
32 | #define CHECKBOUNDS 0 |
33 | |
34 | |
35 | //----------------------------------------------------- |
36 | #define LONGUEUR_MINI_EDGE_TRIANGLE 1e-15 |
37 | |
38 | |
39 | //======================================================================= |
40 | //function : IntCurveSurface_Polyhedron |
41 | //purpose : |
42 | //======================================================================= |
43 | IntCurveSurface_Polyhedron::IntCurveSurface_Polyhedron (const ThePSurface& Surface, |
44 | const Standard_Integer nbdU, |
45 | const Standard_Integer nbdV, |
46 | const Standard_Real u1, |
47 | const Standard_Real v1, |
48 | const Standard_Real u2, |
49 | const Standard_Real v2) |
50 | : nbdeltaU((nbdU<3)? 3 : nbdU), |
51 | nbdeltaV((nbdV<3)? 3 : nbdV), |
52 | TheDeflection(Epsilon(100.)), |
53 | C_MyPnts(NULL),C_MyU(NULL),C_MyV(NULL),C_MyIsOnBounds(NULL) |
54 | { |
55 | Standard_Integer t = (nbdeltaU+1)*(nbdeltaV+1)+1; |
56 | gp_Pnt *CMyPnts = new gp_Pnt[t]; C_MyPnts = (void *)CMyPnts; |
57 | Standard_Real *CMyU = new Standard_Real[t]; C_MyU = (void *)CMyU; |
58 | Standard_Real *CMyV = new Standard_Real[t]; C_MyV = (void *)CMyV; |
59 | |
60 | // Modified by Sergey KHROMOV - Fri Dec 7 12:03:46 2001 Begin |
61 | Standard_Boolean *CMyIsOnBounds = new Standard_Boolean[t]; |
62 | |
63 | C_MyIsOnBounds = (void *)CMyIsOnBounds; |
64 | // Modified by Sergey KHROMOV - Fri Dec 7 12:03:47 2001 End |
65 | Init(Surface,u1,v1,u2,v2); |
66 | } |
67 | |
68 | //======================================================================= |
69 | //function : IntCurveSurface_Polyhedron |
70 | //purpose : |
71 | //======================================================================= |
72 | IntCurveSurface_Polyhedron::IntCurveSurface_Polyhedron (const ThePSurface& Surface, |
73 | const TColStd_Array1OfReal& Upars, |
74 | const TColStd_Array1OfReal& Vpars) |
75 | : nbdeltaU(Upars.Length()-1), |
76 | nbdeltaV(Vpars.Length()-1), |
77 | TheDeflection(Epsilon(100.)), |
78 | C_MyPnts(NULL),C_MyU(NULL),C_MyV(NULL),C_MyIsOnBounds(NULL) |
79 | { |
80 | Standard_Integer t = (nbdeltaU+1)*(nbdeltaV+1)+1; |
81 | gp_Pnt *CMyPnts = new gp_Pnt[t]; C_MyPnts = (void *)CMyPnts; |
82 | Standard_Real *CMyU = new Standard_Real[t]; C_MyU = (void *)CMyU; |
83 | Standard_Real *CMyV = new Standard_Real[t]; C_MyV = (void *)CMyV; |
84 | |
85 | // Modified by Sergey KHROMOV - Fri Dec 7 12:03:46 2001 Begin |
86 | Standard_Boolean *CMyIsOnBounds = new Standard_Boolean[t]; |
87 | |
88 | C_MyIsOnBounds = (void *)CMyIsOnBounds; |
89 | // Modified by Sergey KHROMOV - Fri Dec 7 12:03:47 2001 End |
90 | Init(Surface, Upars, Vpars); |
91 | } |
92 | |
93 | |
94 | void IntCurveSurface_Polyhedron::Destroy() { |
95 | //-- printf("\n IntCurveSurface_Polyhedron::Destroy\n"); |
96 | gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts; if(C_MyPnts) delete [] CMyPnts; |
97 | Standard_Real *CMyU = (Standard_Real *)C_MyU; if(C_MyU) delete [] CMyU; |
98 | Standard_Real *CMyV = (Standard_Real *)C_MyV; if(C_MyV) delete [] CMyV; |
99 | |
100 | // Modified by Sergey KHROMOV - Fri Dec 7 12:03:46 2001 Begin |
101 | Standard_Boolean *CMyIsOnBounds = (Standard_Boolean *)C_MyIsOnBounds; |
102 | |
103 | if(C_MyIsOnBounds) delete [] CMyIsOnBounds; |
104 | // Modified by Sergey KHROMOV - Fri Dec 7 12:03:47 2001 End |
105 | |
106 | C_MyPnts=C_MyU=C_MyV=C_MyIsOnBounds=NULL; |
107 | } |
108 | |
109 | //======================================================================= |
110 | //function : Init |
111 | //purpose : |
112 | //======================================================================= |
113 | void IntCurveSurface_Polyhedron::Init(const ThePSurface& Surface, |
114 | const Standard_Real U0, |
115 | const Standard_Real V0, |
116 | const Standard_Real U1, |
117 | const Standard_Real V1) { |
617cf082 |
118 | //#define DEBUGDUMP |
7fd59977 |
119 | Standard_Integer i1,i2; |
120 | Standard_Real U,V; |
121 | Standard_Real U1mU0sNbdeltaU = (U1-U0)/(Standard_Real)nbdeltaU; |
122 | Standard_Real V1mV0sNbdeltaV = (V1-V0)/(Standard_Real)nbdeltaV; |
123 | gp_Pnt TP; |
124 | Standard_Integer Index=1; |
125 | //-- -------------------------------------------------- |
126 | //-- Index varie de 1 -> (nbdu+1)*(nbdv+1) |
127 | //-- V est la colonne |
128 | //-- U est la ligne |
129 | //-- -------------------------------------------------- |
130 | gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts; |
131 | Standard_Real *CMyU = (Standard_Real *)C_MyU; |
132 | Standard_Real *CMyV = (Standard_Real *)C_MyV; |
133 | Standard_Boolean *CMyIsOnBounds = (Standard_Boolean *)C_MyIsOnBounds; |
134 | |
135 | for (i1 = 0, U = U0; i1 <= nbdeltaU; i1++, U+= U1mU0sNbdeltaU) { |
136 | for (i2 = 0, V = V0; i2 <= nbdeltaV; i2++, V+= V1mV0sNbdeltaV ) { |
137 | ThePSurfaceTool::D0(Surface,U,V,TP); |
138 | //-- Point(TP,i1, i2,U,V); |
139 | CMyPnts[Index] = TP; |
140 | CMyU[Index] = U; |
141 | CMyV[Index] = V; |
142 | // Modified by Sergey KHROMOV - Fri Dec 7 12:07:51 2001 |
143 | CMyIsOnBounds[Index] = (i1 == 0 || i1 == nbdeltaU || |
144 | i2 == 0 || i2 == nbdeltaV); |
145 | // Modified by Sergey KHROMOV - Fri Dec 7 12:07:52 2001 |
146 | TheBnd.Add(TP); |
147 | Index++; |
148 | } |
149 | } |
150 | //-- Calcul de la deflection Triangle <-> Point milieu |
151 | Standard_Real tol=0.0; Standard_Integer nbtriangles = NbTriangles(); |
152 | for (i1=1; i1<=nbtriangles; i1++) { |
153 | Standard_Real tol1 = DeflectionOnTriangle(Surface,i1); |
154 | if(tol1>tol) tol=tol1; |
155 | } |
156 | //-- Calcul de la deflection Bord <-> Point milieu |
157 | |
158 | |
159 | DeflectionOverEstimation(tol*1.2); |
160 | FillBounding(); |
161 | |
162 | // Modified by Sergey KHROMOV - Fri Dec 7 11:23:33 2001 Begin |
163 | Standard_Real aDeflection; |
164 | |
165 | TheBorderDeflection = RealFirst(); |
166 | |
167 | // Compute the deflection on the lower bound (U-isoline) of the surface. |
168 | aDeflection = ComputeBorderDeflection(Surface, U0, V0, V1, Standard_True); |
169 | |
170 | if (aDeflection > TheBorderDeflection) |
171 | TheBorderDeflection = aDeflection; |
172 | |
173 | // Compute the deflection on the upper bound (U-isoline) of the surface. |
174 | aDeflection = ComputeBorderDeflection(Surface, U1, V0, V1, Standard_True); |
175 | |
176 | if (aDeflection > TheBorderDeflection) |
177 | TheBorderDeflection = aDeflection; |
178 | |
179 | // Compute the deflection on the lower bound (V-isoline) of the surface. |
180 | aDeflection = ComputeBorderDeflection(Surface, V0, U0, U1, Standard_False); |
181 | |
182 | if (aDeflection > TheBorderDeflection) |
183 | TheBorderDeflection = aDeflection; |
184 | |
185 | // Compute the deflection on the upper bound (V-isoline) of the surface. |
186 | aDeflection = ComputeBorderDeflection(Surface, V1, U0, U1, Standard_False); |
187 | |
188 | if (aDeflection > TheBorderDeflection) |
189 | TheBorderDeflection = aDeflection; |
190 | |
191 | // Modified by Sergey KHROMOV - Fri Dec 7 11:23:34 2001 End |
192 | |
617cf082 |
193 | #ifdef DEBUGDUMP |
7fd59977 |
194 | Dump(); |
617cf082 |
195 | #endif |
7fd59977 |
196 | } |
197 | //======================================================================= |
198 | //function : Init |
199 | //purpose : |
200 | //======================================================================= |
201 | void IntCurveSurface_Polyhedron::Init(const ThePSurface& Surface, |
202 | const TColStd_Array1OfReal& Upars, |
203 | const TColStd_Array1OfReal& Vpars) { |
617cf082 |
204 | //#define DEBUGDUMP |
7fd59977 |
205 | Standard_Integer i1,i2; |
206 | Standard_Real U,V; |
207 | gp_Pnt TP; |
208 | Standard_Integer Index=1; |
209 | //-- -------------------------------------------------- |
210 | //-- Index varie de 1 -> (nbdu+1)*(nbdv+1) |
211 | //-- V est la colonne |
212 | //-- U est la ligne |
213 | //-- -------------------------------------------------- |
214 | gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts; |
215 | Standard_Real *CMyU = (Standard_Real *)C_MyU; |
216 | Standard_Real *CMyV = (Standard_Real *)C_MyV; |
217 | Standard_Boolean *CMyIsOnBounds = (Standard_Boolean *)C_MyIsOnBounds; |
218 | Standard_Integer i0 = Upars.Lower(), j0 = Vpars.Lower(); |
219 | |
220 | for (i1 = 0; i1 <= nbdeltaU; i1++) { |
221 | U = Upars(i1+i0); |
222 | for (i2 = 0; i2 <= nbdeltaV; i2++) { |
223 | V = Vpars(i2+j0); |
224 | ThePSurfaceTool::D0(Surface,U,V,TP); |
225 | //-- Point(TP,i1, i2,U,V); |
226 | CMyPnts[Index] = TP; |
227 | CMyU[Index] = U; |
228 | CMyV[Index] = V; |
229 | // Modified by Sergey KHROMOV - Fri Dec 7 12:07:51 2001 |
230 | CMyIsOnBounds[Index] = (i1 == 0 || i1 == nbdeltaU || |
231 | i2 == 0 || i2 == nbdeltaV); |
232 | // Modified by Sergey KHROMOV - Fri Dec 7 12:07:52 2001 |
233 | TheBnd.Add(TP); |
234 | Index++; |
235 | } |
236 | } |
237 | //-- Calcul de la deflection Triangle <-> Point milieu |
238 | Standard_Real tol=0.0; Standard_Integer nbtriangles = NbTriangles(); |
239 | for (i1=1; i1<=nbtriangles; i1++) { |
240 | Standard_Real tol1 = DeflectionOnTriangle(Surface,i1); |
241 | if(tol1>tol) tol=tol1; |
242 | } |
243 | //-- Calcul de la deflection Bord <-> Point milieu |
244 | |
245 | |
246 | DeflectionOverEstimation(tol*1.2); |
247 | FillBounding(); |
248 | |
249 | // Modified by Sergey KHROMOV - Fri Dec 7 11:23:33 2001 Begin |
250 | Standard_Real aDeflection; |
251 | |
252 | TheBorderDeflection = RealFirst(); |
253 | Standard_Real U0 = Upars(i0); |
254 | Standard_Real V0 = Vpars(j0); |
255 | Standard_Real U1 = Upars(Upars.Upper()); |
256 | Standard_Real V1 = Vpars(Vpars.Upper()); |
257 | |
258 | // Compute the deflection on the lower bound (U-isoline) of the surface. |
259 | aDeflection = ComputeBorderDeflection(Surface, U0, V0, V1, Standard_True); |
260 | |
261 | if (aDeflection > TheBorderDeflection) |
262 | TheBorderDeflection = aDeflection; |
263 | |
264 | // Compute the deflection on the upper bound (U-isoline) of the surface. |
265 | aDeflection = ComputeBorderDeflection(Surface, U1, V0, V1, Standard_True); |
266 | |
267 | if (aDeflection > TheBorderDeflection) |
268 | TheBorderDeflection = aDeflection; |
269 | |
270 | // Compute the deflection on the lower bound (V-isoline) of the surface. |
271 | aDeflection = ComputeBorderDeflection(Surface, V0, U0, U1, Standard_False); |
272 | |
273 | if (aDeflection > TheBorderDeflection) |
274 | TheBorderDeflection = aDeflection; |
275 | |
276 | // Compute the deflection on the upper bound (V-isoline) of the surface. |
277 | aDeflection = ComputeBorderDeflection(Surface, V1, U0, U1, Standard_False); |
278 | |
279 | if (aDeflection > TheBorderDeflection) |
280 | TheBorderDeflection = aDeflection; |
281 | |
282 | // Modified by Sergey KHROMOV - Fri Dec 7 11:23:34 2001 End |
283 | |
617cf082 |
284 | #ifdef DEBUGDUMP |
7fd59977 |
285 | Dump(); |
617cf082 |
286 | #endif |
7fd59977 |
287 | } |
288 | //======================================================================= |
289 | //function : DeflectionOnTriangle |
290 | //purpose : |
291 | //======================================================================= |
292 | Standard_Real IntCurveSurface_Polyhedron::DeflectionOnTriangle (const ThePSurface& Surface, |
293 | const Standard_Integer Triang) const |
294 | { |
295 | Standard_Integer i1,i2,i3; |
296 | Triangle(Triang,i1,i2,i3); |
297 | //-- Calcul de l equation du plan |
298 | Standard_Real u1,v1,u2,v2,u3,v3; |
299 | gp_Pnt P1,P2,P3; |
300 | P1 = Point(i1,u1,v1); |
301 | P2 = Point(i2,u2,v2); |
302 | P3 = Point(i3,u3,v3); |
303 | if(P1.SquareDistance(P2)<=LONGUEUR_MINI_EDGE_TRIANGLE) return(0); |
304 | if(P1.SquareDistance(P3)<=LONGUEUR_MINI_EDGE_TRIANGLE) return(0); |
305 | if(P2.SquareDistance(P3)<=LONGUEUR_MINI_EDGE_TRIANGLE) return(0); |
306 | gp_XYZ XYZ1=P2.XYZ()-P1.XYZ(); |
307 | gp_XYZ XYZ2=P3.XYZ()-P2.XYZ(); |
308 | gp_XYZ XYZ3=P1.XYZ()-P3.XYZ(); |
309 | gp_Vec NormalVector((XYZ1^XYZ2)+(XYZ2^XYZ3)+(XYZ3^XYZ1)); |
310 | NormalVector.Normalize(); |
311 | //-- Standard_Real PolarDistance = NormalVector * P1.XYZ(); |
312 | //-- Calcul du point u,v au centre du triangle |
313 | Standard_Real u = (u1+u2+u3)/3.0; |
314 | Standard_Real v = (v1+v2+v3)/3.0; |
315 | gp_Pnt P = ThePSurfaceTool::Value(Surface,u,v); |
316 | gp_Vec P1P(P1,P); |
317 | return(Abs(P1P.Dot(NormalVector))); |
318 | } |
319 | //======================================================================= |
320 | //function : Parameters |
321 | //purpose : |
322 | //======================================================================= |
323 | void IntCurveSurface_Polyhedron::Parameters( const Standard_Integer Index |
324 | ,Standard_Real &U |
325 | ,Standard_Real &V) const |
326 | { |
327 | #if CHECKBOUNDS |
328 | if(Index<0 || Index>((nbdeltaU+1)*(nbdeltaV+1))) { |
329 | printf("\n Erreur IntCurveSurface_Polyhedron::Parameters\n"); |
330 | } |
331 | #endif |
332 | Standard_Real *CMyU = (Standard_Real *)C_MyU; |
333 | U = CMyU[Index]; |
334 | Standard_Real *CMyV = (Standard_Real *)C_MyV; |
335 | V = CMyV[Index]; |
336 | } |
337 | //======================================================================= |
338 | //function : DeflectionOverEstimation |
339 | //purpose : Set |
340 | //======================================================================= |
341 | void IntCurveSurface_Polyhedron::DeflectionOverEstimation(const Standard_Real flec) |
342 | { |
343 | if(flec<0.0001) { |
344 | TheDeflection=0.0001; |
345 | TheBnd.Enlarge(0.0001); |
346 | } |
347 | else { |
348 | TheDeflection=flec; |
349 | TheBnd.Enlarge(flec); |
350 | } |
351 | } |
352 | //======================================================================= |
353 | //function : DeflectionOverEstimation |
354 | //purpose : Get |
355 | //======================================================================= |
356 | Standard_Real IntCurveSurface_Polyhedron::DeflectionOverEstimation() const |
357 | { |
358 | return TheDeflection; |
359 | } |
360 | //======================================================================= |
361 | //function : Bounding |
362 | //purpose : |
363 | //======================================================================= |
364 | const Bnd_Box& IntCurveSurface_Polyhedron::Bounding() const |
365 | { |
366 | return TheBnd; |
367 | } |
368 | //======================================================================= |
369 | //function : FillBounding |
370 | //purpose : |
371 | //======================================================================= |
372 | void IntCurveSurface_Polyhedron::FillBounding() |
373 | { |
374 | TheComponentsBnd=new Bnd_HArray1OfBox(1, NbTriangles()); |
375 | Bnd_Box Boite; |
376 | Standard_Integer np1, np2, np3; |
377 | Standard_Integer nbtriangles = NbTriangles(); |
378 | for (Standard_Integer iTri=1; iTri<=nbtriangles; iTri++) { |
379 | Triangle(iTri, np1, np2, np3); |
380 | gp_Pnt p1(Point(np1)); |
381 | gp_Pnt p2(Point(np2)); |
382 | gp_Pnt p3(Point(np3)); |
383 | Boite.SetVoid(); |
384 | if(p1.SquareDistance(p2)>LONGUEUR_MINI_EDGE_TRIANGLE) { |
385 | if(p1.SquareDistance(p3)>LONGUEUR_MINI_EDGE_TRIANGLE) { |
386 | if(p2.SquareDistance(p3)>LONGUEUR_MINI_EDGE_TRIANGLE) { |
387 | Boite.Add(p1); |
388 | Boite.Add(p2); |
389 | Boite.Add(p3); |
390 | Boite.Enlarge(TheDeflection); |
391 | } |
392 | } |
393 | } |
394 | Boite.Enlarge(TheDeflection); |
395 | TheComponentsBnd->SetValue(iTri,Boite); |
396 | } |
397 | } |
398 | //======================================================================= |
399 | //function : ComponentsBounding |
400 | //purpose : |
401 | //======================================================================= |
402 | const Handle(Bnd_HArray1OfBox)& |
403 | IntCurveSurface_Polyhedron::ComponentsBounding() const |
404 | { |
405 | return TheComponentsBnd; |
406 | } |
407 | //======================================================================= |
408 | //function : NbTriangles |
409 | //purpose : |
410 | //======================================================================= |
411 | Standard_Integer IntCurveSurface_Polyhedron::NbTriangles () const |
412 | { |
413 | return nbdeltaU*nbdeltaV*2; |
414 | } |
415 | //======================================================================= |
416 | //function : NbPoints |
417 | //purpose : |
418 | //======================================================================= |
419 | Standard_Integer IntCurveSurface_Polyhedron::NbPoints () const |
420 | { |
421 | return (nbdeltaU+1)*(nbdeltaV+1); |
422 | } |
423 | //======================================================================= |
424 | //function : TriConnex |
425 | //purpose : |
426 | //======================================================================= |
427 | Standard_Integer IntCurveSurface_Polyhedron::TriConnex |
428 | (const Standard_Integer Triang, |
429 | const Standard_Integer Pivot, |
430 | const Standard_Integer Pedge, |
431 | Standard_Integer& TriCon, |
432 | Standard_Integer& OtherP) const |
433 | { |
7fd59977 |
434 | Standard_Integer Pivotm1 = Pivot-1; |
435 | Standard_Integer nbdeltaVp1 = nbdeltaV+1; |
436 | Standard_Integer nbdeltaVm2 = nbdeltaV + nbdeltaV; |
437 | |
438 | // Pivot position in the MaTriangle : |
439 | Standard_Integer ligP = Pivotm1/nbdeltaVp1; |
440 | Standard_Integer colP = Pivotm1 - ligP * nbdeltaVp1; |
441 | |
442 | // Point sur Edge position in the MaTriangle and edge typ : |
7fd59977 |
443 | Standard_Integer ligE =0, colE =0, typE =0; |
7fd59977 |
444 | if (Pedge!=0) { |
445 | ligE= (Pedge-1)/nbdeltaVp1; |
446 | colE= (Pedge-1) - (ligE * nbdeltaVp1); |
447 | // Horizontal |
448 | if (ligP==ligE) typE=1; |
449 | // Vertical |
450 | else if (colP==colE) typE=2; |
451 | // Oblique |
452 | else typE=3; |
453 | } |
454 | else { |
455 | typE=0; |
456 | } |
457 | |
458 | // Triangle position General case : |
1d47d8d0 |
459 | |
7fd59977 |
460 | Standard_Integer linT =0, colT =0; |
461 | Standard_Integer linO =0, colO =0; |
462 | Standard_Integer t =0, tt =0; |
1d47d8d0 |
463 | |
7fd59977 |
464 | if (Triang!=0) { |
465 | t = (Triang-1)/(nbdeltaVm2); |
466 | tt= (Triang-1)-t*nbdeltaVm2; |
467 | linT= 1+t; |
468 | colT= 1+tt; |
469 | if (typE==0) { |
470 | if (ligP==linT) { |
471 | ligE=ligP-1; |
472 | colE=colP-1; |
473 | typE=3; |
474 | } |
475 | else { |
476 | if (colT==ligP+ligP) { |
477 | ligE=ligP; |
478 | colE=colP-1; |
479 | typE=1; |
480 | } |
481 | else { |
482 | ligE=ligP+1; |
483 | colE=colP+1; |
484 | typE=3; |
485 | } |
486 | } |
487 | } |
488 | switch (typE) { |
489 | case 1: // Horizontal |
490 | if (linT==ligP) { |
491 | linT++; |
492 | linO=ligP+1; |
493 | colO=(colP>colE)? colP : colE; //--colO=Max(colP, colE); |
494 | } |
495 | else { |
496 | linT--; |
497 | linO=ligP-1; |
498 | colO=(colP<colE)? colP : colE; //--colO=Min(colP, colE); |
499 | } |
500 | break; |
501 | case 2: // Vertical |
502 | if (colT==(colP+colP)) { |
503 | colT++; |
504 | linO=(ligP>ligE)? ligP : ligE; //--linO=Max(ligP, ligE); |
505 | colO=colP+1;; |
506 | } |
507 | else { |
508 | colT--; |
509 | linO=(ligP<ligE)? ligP : ligE; //--linO=Min(ligP, ligE); |
510 | colO=colP-1;; |
511 | } |
512 | break; |
513 | case 3: // Oblique |
514 | if ((colT&1)==0) { |
515 | colT--; |
516 | linO=(ligP>ligE)? ligP : ligE; //--linO=Max(ligP, ligE); |
517 | colO=(colP<colE)? colP : colE; //--colO=Min(colP, colE); |
518 | } |
519 | else { |
520 | colT++; |
521 | linO=(ligP<ligE)? ligP : ligE; //--linO=Min(ligP, ligE); |
522 | colO=(colP>colE)? colP : colE; //--colO=Max(colP, colE); |
523 | } |
524 | break; |
525 | } |
526 | } |
527 | else { |
528 | // Unknown Triangle position : |
529 | if (Pedge==0) { |
530 | // Unknown edge : |
531 | linT=(1>ligP)? 1 : ligP; //--linT=Max(1, ligP); |
532 | colT=(1>(colP+colP))? 1 : (colP+colP); //--colT=Max(1, colP+colP); |
533 | if (ligP==0) linO=ligP+1; |
534 | else linO=ligP-1; |
535 | colO=colP; |
536 | } |
537 | else { |
538 | // Known edge We take the left or down connectivity : |
539 | switch (typE) { |
540 | case 1: // Horizontal |
541 | linT=ligP+1; |
542 | colT=(colP>colE)? colP : colE; //--colT=Max(colP,colE); |
543 | colT+=colT; |
544 | linO=ligP+1; |
545 | colO=(colP>colE)? colP : colE; //--colO=Max(colP,colE); |
546 | break; |
547 | case 2: // Vertical |
548 | linT=(ligP>ligE)? ligP : ligE; //--linT=Max(ligP, ligE); |
549 | colT=colP+colP; |
550 | linO=(ligP<ligE)? ligP : ligE; //--linO=Min(ligP, ligE); |
551 | colO=colP-1; |
552 | break; |
553 | case 3: // Oblique |
554 | linT=(ligP>ligE)? ligP : ligE; //--linT=Max(ligP, ligE); |
555 | colT=colP+colE; |
556 | linO=(ligP>ligE)? ligP : ligE; //--linO=Max(ligP, ligE); |
557 | colO=(colP<colE)? colP : colE; //--colO=Min(colP, colE); |
558 | break; |
559 | } |
560 | } |
561 | } |
562 | |
563 | TriCon=(linT-1)*nbdeltaVm2 + colT; |
564 | |
565 | if (linT<1) { |
566 | linO=0; |
567 | colO=colP+colP-colE; |
568 | if (colO<0) {colO=0;linO=1;} |
569 | else if (colO>nbdeltaV) {colO=nbdeltaV;linO=1;} |
570 | TriCon=0; |
571 | } |
572 | else if (linT>nbdeltaU) { |
573 | linO=nbdeltaU; |
574 | colO=colP+colP-colE; |
575 | if (colO<0) {colO=0;linO=nbdeltaU-1;} |
576 | else if (colO>nbdeltaV) {colO=nbdeltaV;linO=nbdeltaU-1;} |
577 | TriCon=0; |
578 | } |
579 | |
580 | if (colT<1) { |
581 | colO=0; |
582 | linO=ligP+ligP-ligE; |
583 | if (linO<0) {linO=0;colO=1;} |
584 | else if (linO>nbdeltaU) {linO=nbdeltaU;colO=1;} |
585 | TriCon=0; |
586 | } |
587 | else if (colT>nbdeltaV) { |
588 | colO=nbdeltaV; |
589 | linO=ligP+ligP-ligE; |
590 | if (linO<0) {linO=0;colO=nbdeltaV-1;} |
591 | else if (linO>nbdeltaU) {linO=nbdeltaU;colO=nbdeltaV-1;} |
592 | TriCon=0; |
593 | } |
594 | |
595 | OtherP=linO*nbdeltaVp1 + colO+1; |
596 | |
597 | return TriCon; |
598 | } |
599 | |
600 | |
601 | //======================================================================= |
602 | //function : PlaneEquation |
603 | //purpose : |
604 | //======================================================================= |
605 | void IntCurveSurface_Polyhedron::PlaneEquation (const Standard_Integer Triang, |
606 | gp_XYZ& NormalVector, |
607 | Standard_Real& PolarDistance) const |
608 | { |
609 | Standard_Integer i1,i2,i3; |
610 | Triangle(Triang,i1,i2,i3); |
611 | |
612 | //-- gp_XYZ v1=Point(i2).XYZ()-Point(i1).XYZ(); |
613 | //-- gp_XYZ v2=Point(i3).XYZ()-Point(i2).XYZ(); |
614 | //-- gp_XYZ v3=Point(i1).XYZ()-Point(i3).XYZ(); |
615 | |
616 | gp_XYZ Pointi1(Point(i1).XYZ()); |
617 | gp_XYZ Pointi2(Point(i2).XYZ()); |
618 | gp_XYZ Pointi3(Point(i3).XYZ()); |
619 | |
620 | |
621 | gp_XYZ v1= Pointi2 - Pointi1; |
622 | gp_XYZ v2= Pointi3 - Pointi2; |
623 | gp_XYZ v3= Pointi1 - Pointi3; |
624 | |
625 | if(v1.SquareModulus()<=LONGUEUR_MINI_EDGE_TRIANGLE) { NormalVector.SetCoord(1.0,0.0,0.0); return; } |
626 | if(v2.SquareModulus()<=LONGUEUR_MINI_EDGE_TRIANGLE) { NormalVector.SetCoord(1.0,0.0,0.0); return; } |
627 | if(v3.SquareModulus()<=LONGUEUR_MINI_EDGE_TRIANGLE) { NormalVector.SetCoord(1.0,0.0,0.0); return; } |
628 | |
629 | NormalVector= (v1^v2)+(v2^v3)+(v3^v1); |
630 | NormalVector.Normalize(); |
631 | PolarDistance = NormalVector * Point(i1).XYZ(); |
632 | } |
633 | //======================================================================= |
634 | //function : Contain |
635 | //purpose : |
636 | //======================================================================= |
637 | Standard_Boolean IntCurveSurface_Polyhedron::Contain (const Standard_Integer Triang, |
638 | const gp_Pnt& ThePnt) const |
639 | { |
640 | Standard_Integer i1,i2,i3; |
641 | Triangle(Triang,i1,i2,i3); |
642 | gp_XYZ Pointi1(Point(i1).XYZ()); |
643 | gp_XYZ Pointi2(Point(i2).XYZ()); |
644 | gp_XYZ Pointi3(Point(i3).XYZ()); |
645 | |
646 | gp_XYZ v1=(Pointi2-Pointi1)^(ThePnt.XYZ()-Pointi1); |
647 | gp_XYZ v2=(Pointi3-Pointi2)^(ThePnt.XYZ()-Pointi2); |
648 | gp_XYZ v3=(Pointi1-Pointi3)^(ThePnt.XYZ()-Pointi3); |
649 | if (v1*v2 >= 0. && v2*v3 >= 0. && v3*v1>=0.) |
650 | return Standard_True; |
651 | else |
652 | return Standard_False; |
653 | } |
654 | //======================================================================= |
655 | //function : Dump |
656 | //purpose : |
657 | //======================================================================= |
658 | void IntCurveSurface_Polyhedron::Dump() const |
659 | { |
660 | |
661 | } |
662 | //======================================================================= |
663 | //function : Size |
664 | //purpose : |
665 | //======================================================================= |
666 | void IntCurveSurface_Polyhedron::Size (Standard_Integer& nbdu, |
667 | Standard_Integer& nbdv) const |
668 | { |
669 | nbdu=nbdeltaU; |
670 | nbdv=nbdeltaV; |
671 | } |
672 | //======================================================================= |
673 | //function : Triangle |
674 | //purpose : |
675 | //======================================================================= |
676 | void IntCurveSurface_Polyhedron::Triangle (const Standard_Integer Index, |
677 | Standard_Integer& P1, |
678 | Standard_Integer& P2, |
679 | Standard_Integer& P3) const |
680 | { |
681 | Standard_Integer line=1+((Index-1)/(nbdeltaV*2)); |
682 | Standard_Integer colon=1+((Index-1)%(nbdeltaV*2)); |
683 | Standard_Integer colpnt=(colon+1)/2; |
684 | |
685 | // General formula = (line-1)*(nbdeltaV+1)+colpnt |
686 | |
687 | // Position of P1 = MesXYZ(line,colpnt); |
688 | P1= (line-1)*(nbdeltaV+1) + colpnt; |
689 | |
690 | // Position of P2= MesXYZ(line+1,colpnt+((colon-1)%2)); |
691 | P2= line*(nbdeltaV+1) + colpnt+((colon-1)%2); |
692 | |
693 | // Position of P3= MesXYZ(line+(colon%2),colpnt+1); |
694 | P3= (line-1+(colon%2))*(nbdeltaV+1) + colpnt + 1; |
695 | } |
696 | //======================================================================= |
697 | //function : Point |
698 | //======================================================================= |
699 | const gp_Pnt& IntCurveSurface_Polyhedron::Point(const Standard_Integer Index |
700 | ,Standard_Real& U |
701 | ,Standard_Real& V) const |
702 | { |
703 | #if CHECKBOUNDS |
704 | if(Index<0 || Index>((nbdeltaU+1)*(nbdeltaV+1))) { |
705 | printf("\n Erreur IntCurveSurface_Polyhedron::Parameters\n"); |
706 | } |
707 | #endif |
708 | gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts; |
709 | Standard_Real *CMyU = (Standard_Real *)C_MyU; |
710 | Standard_Real *CMyV = (Standard_Real *)C_MyV; |
711 | U=CMyU[Index]; |
712 | V=CMyV[Index]; |
713 | return CMyPnts[Index]; |
714 | } |
715 | //======================================================================= |
716 | //function : Point |
717 | //======================================================================= |
718 | const gp_Pnt& IntCurveSurface_Polyhedron::Point(const Standard_Integer Index) const { |
719 | #if CHECKBOUNDS |
720 | if(Index<0 || Index>((nbdeltaU+1)*(nbdeltaV+1))) { |
721 | printf("\n Erreur IntCurveSurface_Polyhedron::Parameters\n"); |
722 | } |
723 | #endif |
724 | |
725 | gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts; |
726 | return CMyPnts[Index]; |
727 | } |
728 | //======================================================================= |
729 | //function : Point |
730 | //======================================================================= |
731 | //void IntCurveSurface_Polyhedron::Point (const gp_Pnt& p, |
732 | // const Standard_Integer lig, |
733 | // const Standard_Integer col, |
734 | // const Standard_Real u, |
735 | // const Standard_Real v) |
736 | void IntCurveSurface_Polyhedron::Point (const gp_Pnt& , |
737 | const Standard_Integer , |
738 | const Standard_Integer , |
739 | const Standard_Real , |
740 | const Standard_Real ) |
741 | { |
742 | printf("\n IntCurveSurface_Polyhedron::Point : Ne dois pas etre appelle\n"); |
743 | } |
744 | //======================================================================= |
745 | //function : Point |
746 | //======================================================================= |
747 | void IntCurveSurface_Polyhedron::Point (const Standard_Integer Index,gp_Pnt& P) const |
748 | { |
749 | #if CHECKBOUNDS |
750 | if(Index<0 || Index>((nbdeltaU+1)*(nbdeltaV+1))) { |
751 | printf("\n Erreur IntCurveSurface_Polyhedron::Parameters\n"); |
752 | } |
753 | #endif |
754 | |
755 | gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts; |
756 | P = CMyPnts[Index]; |
757 | } |
758 | |
759 | // Modified by Sergey KHROMOV - Fri Dec 7 10:12:47 2001 Begin |
760 | |
761 | //======================================================================= |
762 | //function : IsOnBound |
763 | //purpose : This method returns true if the edge based on points with |
764 | // indices Index1 and Index2 represents a boundary edge. |
765 | //======================================================================= |
766 | |
767 | Standard_Boolean IntCurveSurface_Polyhedron::IsOnBound |
768 | (const Standard_Integer Index1, |
769 | const Standard_Integer Index2) const |
770 | { |
771 | #if CHECKBOUNDS |
772 | if(Index1<0 || Index1>((nbdeltaU+1)*(nbdeltaV+1))) { |
773 | printf("\n Erreur IntCurveSurface_Polyhedron::IsOnBound\n"); |
774 | } |
775 | if(Index2<0 || Index2>((nbdeltaU+1)*(nbdeltaV+1))) { |
776 | printf("\n Erreur IntCurveSurface_Polyhedron::IsOnBound\n"); |
777 | } |
778 | #endif |
779 | Standard_Boolean *CMyIsOnBounds = (Standard_Boolean *)C_MyIsOnBounds; |
780 | Standard_Integer aDiff = Abs(Index1 - Index2); |
781 | Standard_Integer i; |
782 | |
783 | // Check if points are neighbour ones. |
784 | if (aDiff != 1 && aDiff != nbdeltaV + 1) |
785 | return Standard_False; |
786 | |
787 | for (i = 0; i <= nbdeltaU; i++) { |
788 | if ((Index1 == 1 + i*(nbdeltaV + 1)) && (Index2 == Index1 - 1)) |
789 | return Standard_False; |
790 | |
791 | if ((Index1 == (1 + i)*(nbdeltaV + 1)) && (Index2 == Index1 + 1)) |
792 | return Standard_False; |
793 | } |
794 | |
795 | return (CMyIsOnBounds[Index1] && CMyIsOnBounds[Index2]); |
796 | } |
797 | |
798 | //======================================================================= |
799 | //function : ComputeBorderDeflection |
800 | //purpose : This method computes and returns a deflection of isoline |
801 | // of given parameter on Surface. |
802 | //======================================================================= |
803 | |
804 | Standard_Real IntCurveSurface_Polyhedron::ComputeBorderDeflection |
805 | (const ThePSurface &Surface, |
806 | const Standard_Real Parameter, |
807 | const Standard_Real PMin, |
808 | const Standard_Real PMax, |
809 | const Standard_Boolean isUIso) const |
810 | { |
811 | Standard_Integer aNbSamples; |
812 | Standard_Integer i; |
813 | |
814 | if (isUIso) |
815 | aNbSamples = nbdeltaV; |
816 | else |
817 | aNbSamples = nbdeltaU; |
818 | |
819 | Standard_Real aDelta = (PMax - PMin)/aNbSamples; |
820 | Standard_Real aPar = PMin; |
821 | Standard_Real aDeflection = RealFirst(); |
822 | gp_XYZ aP1; |
823 | gp_XYZ aP2; |
824 | gp_XYZ aPMid; |
825 | gp_XYZ aPParMid; |
826 | |
827 | for (i = 0; i <= aNbSamples; i++, aPar+= aDelta) { |
828 | if (isUIso) { |
829 | aP1 = ThePSurfaceTool::Value(Surface, Parameter, aPar).XYZ(); |
830 | aP2 = ThePSurfaceTool::Value(Surface, Parameter, aPar + aDelta).XYZ(); |
831 | aPParMid = ThePSurfaceTool::Value(Surface, Parameter, aPar + aDelta/2.).XYZ(); |
832 | } else { |
833 | aP1 = ThePSurfaceTool::Value(Surface, aPar, Parameter).XYZ(); |
834 | aP2 = ThePSurfaceTool::Value(Surface, aPar + aDelta, Parameter).XYZ(); |
835 | aPParMid = ThePSurfaceTool::Value(Surface, aPar + aDelta/2., Parameter).XYZ(); |
836 | } |
837 | aPMid = (aP2 + aP1)/2.; |
838 | |
839 | Standard_Real aDist = (aPMid - aPParMid).Modulus(); |
840 | |
841 | if (aDist > aDeflection) |
842 | aDeflection = aDist; |
843 | } |
844 | |
845 | return aDeflection; |
846 | } |
847 | |
848 | // Modified by Sergey KHROMOV - Fri Dec 7 11:21:52 2001 End |