Warning, /include/opencascade/IntCurveSurface_Polyhedron.gxx is written in an unsupported language. File is not indexed.
0001 // Created on: 1993-02-03
0002 // Created by: Laurent BUCHARD
0003 // Copyright (c) 1993-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016
0017 #include <gp.hxx>
0018 #include <gp_Pnt.hxx>
0019 #include <gp_Vec.hxx>
0020 #include <gp_Dir.hxx>
0021 #include <gp_Lin.hxx>
0022 #include <TColgp_Array2OfPnt.hxx>
0023 #include <TColStd_Array2OfReal.hxx>
0024
0025 #include <Bnd_Array1OfBox.hxx>
0026
0027 #include <Standard_ConstructionError.hxx>
0028
0029 #include <stdio.h>
0030
0031 #define CHECKBOUNDS 0
0032
0033
0034 //-----------------------------------------------------
0035 #define LONGUEUR_MINI_EDGE_TRIANGLE 1e-15
0036
0037
0038 //=======================================================================
0039 //function : IntCurveSurface_Polyhedron
0040 //purpose :
0041 //=======================================================================
0042 IntCurveSurface_Polyhedron::IntCurveSurface_Polyhedron (const ThePSurface& Surface,
0043 const Standard_Integer nbdU,
0044 const Standard_Integer nbdV,
0045 const Standard_Real u1,
0046 const Standard_Real v1,
0047 const Standard_Real u2,
0048 const Standard_Real v2)
0049 : nbdeltaU((nbdU<3)? 3 : nbdU),
0050 nbdeltaV((nbdV<3)? 3 : nbdV),
0051 TheDeflection(Epsilon(100.)),
0052 C_MyPnts(NULL),C_MyU(NULL),C_MyV(NULL),C_MyIsOnBounds(NULL)
0053 {
0054 Standard_Integer t = (nbdeltaU+1)*(nbdeltaV+1)+1;
0055 gp_Pnt *CMyPnts = new gp_Pnt[t]; C_MyPnts = (void *)CMyPnts;
0056 Standard_Real *CMyU = new Standard_Real[t]; C_MyU = (void *)CMyU;
0057 Standard_Real *CMyV = new Standard_Real[t]; C_MyV = (void *)CMyV;
0058
0059 // Modified by Sergey KHROMOV - Fri Dec 7 12:03:46 2001 Begin
0060 Standard_Boolean *CMyIsOnBounds = new Standard_Boolean[t];
0061
0062 C_MyIsOnBounds = (void *)CMyIsOnBounds;
0063 // Modified by Sergey KHROMOV - Fri Dec 7 12:03:47 2001 End
0064 Init(Surface,u1,v1,u2,v2);
0065 }
0066
0067 //=======================================================================
0068 //function : IntCurveSurface_Polyhedron
0069 //purpose :
0070 //=======================================================================
0071 IntCurveSurface_Polyhedron::IntCurveSurface_Polyhedron (const ThePSurface& Surface,
0072 const TColStd_Array1OfReal& Upars,
0073 const TColStd_Array1OfReal& Vpars)
0074 : nbdeltaU(Upars.Length()-1),
0075 nbdeltaV(Vpars.Length()-1),
0076 TheDeflection(Epsilon(100.)),
0077 C_MyPnts(NULL),C_MyU(NULL),C_MyV(NULL),C_MyIsOnBounds(NULL)
0078 {
0079 Standard_Integer t = (nbdeltaU+1)*(nbdeltaV+1)+1;
0080 gp_Pnt *CMyPnts = new gp_Pnt[t]; C_MyPnts = (void *)CMyPnts;
0081 Standard_Real *CMyU = new Standard_Real[t]; C_MyU = (void *)CMyU;
0082 Standard_Real *CMyV = new Standard_Real[t]; C_MyV = (void *)CMyV;
0083
0084 // Modified by Sergey KHROMOV - Fri Dec 7 12:03:46 2001 Begin
0085 Standard_Boolean *CMyIsOnBounds = new Standard_Boolean[t];
0086
0087 C_MyIsOnBounds = (void *)CMyIsOnBounds;
0088 // Modified by Sergey KHROMOV - Fri Dec 7 12:03:47 2001 End
0089 Init(Surface, Upars, Vpars);
0090 }
0091
0092
0093 void IntCurveSurface_Polyhedron::Destroy() {
0094 //-- printf("\n IntCurveSurface_Polyhedron::Destroy\n");
0095 gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts; if(C_MyPnts) delete [] CMyPnts;
0096 Standard_Real *CMyU = (Standard_Real *)C_MyU; if(C_MyU) delete [] CMyU;
0097 Standard_Real *CMyV = (Standard_Real *)C_MyV; if(C_MyV) delete [] CMyV;
0098
0099 // Modified by Sergey KHROMOV - Fri Dec 7 12:03:46 2001 Begin
0100 Standard_Boolean *CMyIsOnBounds = (Standard_Boolean *)C_MyIsOnBounds;
0101
0102 if(C_MyIsOnBounds) delete [] CMyIsOnBounds;
0103 // Modified by Sergey KHROMOV - Fri Dec 7 12:03:47 2001 End
0104
0105 C_MyPnts=C_MyU=C_MyV=C_MyIsOnBounds=NULL;
0106 }
0107
0108 //=======================================================================
0109 //function : Init
0110 //purpose :
0111 //=======================================================================
0112 void IntCurveSurface_Polyhedron::Init(const ThePSurface& Surface,
0113 const Standard_Real U0,
0114 const Standard_Real V0,
0115 const Standard_Real U1,
0116 const Standard_Real V1) {
0117 //#define DEBUGDUMP
0118 Standard_Integer i1,i2;
0119 Standard_Real U,V;
0120 Standard_Real U1mU0sNbdeltaU = (U1-U0)/(Standard_Real)nbdeltaU;
0121 Standard_Real V1mV0sNbdeltaV = (V1-V0)/(Standard_Real)nbdeltaV;
0122 gp_Pnt TP;
0123 Standard_Integer Index=1;
0124 //-- --------------------------------------------------
0125 //-- Index varie de 1 -> (nbdu+1)*(nbdv+1)
0126 //-- V est la colonne
0127 //-- U est la ligne
0128 //-- --------------------------------------------------
0129 gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts;
0130 Standard_Real *CMyU = (Standard_Real *)C_MyU;
0131 Standard_Real *CMyV = (Standard_Real *)C_MyV;
0132 Standard_Boolean *CMyIsOnBounds = (Standard_Boolean *)C_MyIsOnBounds;
0133
0134 for (i1 = 0, U = U0; i1 <= nbdeltaU; i1++, U+= U1mU0sNbdeltaU) {
0135 for (i2 = 0, V = V0; i2 <= nbdeltaV; i2++, V+= V1mV0sNbdeltaV ) {
0136 ThePSurfaceTool::D0(Surface,U,V,TP);
0137 //-- Point(TP,i1, i2,U,V);
0138 CMyPnts[Index] = TP;
0139 CMyU[Index] = U;
0140 CMyV[Index] = V;
0141 // Modified by Sergey KHROMOV - Fri Dec 7 12:07:51 2001
0142 CMyIsOnBounds[Index] = (i1 == 0 || i1 == nbdeltaU ||
0143 i2 == 0 || i2 == nbdeltaV);
0144 // Modified by Sergey KHROMOV - Fri Dec 7 12:07:52 2001
0145 TheBnd.Add(TP);
0146 Index++;
0147 }
0148 }
0149 //-- Calcul de la deflection Triangle <-> Point milieu
0150 Standard_Real tol=0.0; Standard_Integer nbtriangles = NbTriangles();
0151 for (i1=1; i1<=nbtriangles; i1++) {
0152 Standard_Real tol1 = DeflectionOnTriangle(Surface,i1);
0153 if(tol1>tol) tol=tol1;
0154 }
0155 //-- Calcul de la deflection Bord <-> Point milieu
0156
0157
0158 DeflectionOverEstimation(tol*1.2);
0159 FillBounding();
0160
0161 // Modified by Sergey KHROMOV - Fri Dec 7 11:23:33 2001 Begin
0162 Standard_Real aDeflection;
0163
0164 TheBorderDeflection = RealFirst();
0165
0166 // Compute the deflection on the lower bound (U-isoline) of the surface.
0167 aDeflection = ComputeBorderDeflection(Surface, U0, V0, V1, Standard_True);
0168
0169 if (aDeflection > TheBorderDeflection)
0170 TheBorderDeflection = aDeflection;
0171
0172 // Compute the deflection on the upper bound (U-isoline) of the surface.
0173 aDeflection = ComputeBorderDeflection(Surface, U1, V0, V1, Standard_True);
0174
0175 if (aDeflection > TheBorderDeflection)
0176 TheBorderDeflection = aDeflection;
0177
0178 // Compute the deflection on the lower bound (V-isoline) of the surface.
0179 aDeflection = ComputeBorderDeflection(Surface, V0, U0, U1, Standard_False);
0180
0181 if (aDeflection > TheBorderDeflection)
0182 TheBorderDeflection = aDeflection;
0183
0184 // Compute the deflection on the upper bound (V-isoline) of the surface.
0185 aDeflection = ComputeBorderDeflection(Surface, V1, U0, U1, Standard_False);
0186
0187 if (aDeflection > TheBorderDeflection)
0188 TheBorderDeflection = aDeflection;
0189
0190 // Modified by Sergey KHROMOV - Fri Dec 7 11:23:34 2001 End
0191
0192 #ifdef OCCT_DEBUG_DUMP
0193 Dump();
0194 #endif
0195 }
0196 //=======================================================================
0197 //function : Init
0198 //purpose :
0199 //=======================================================================
0200 void IntCurveSurface_Polyhedron::Init(const ThePSurface& Surface,
0201 const TColStd_Array1OfReal& Upars,
0202 const TColStd_Array1OfReal& Vpars) {
0203 //#define DEBUGDUMP
0204 Standard_Integer i1,i2;
0205 Standard_Real U,V;
0206 gp_Pnt TP;
0207 Standard_Integer Index=1;
0208 //-- --------------------------------------------------
0209 //-- Index varie de 1 -> (nbdu+1)*(nbdv+1)
0210 //-- V est la colonne
0211 //-- U est la ligne
0212 //-- --------------------------------------------------
0213 gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts;
0214 Standard_Real *CMyU = (Standard_Real *)C_MyU;
0215 Standard_Real *CMyV = (Standard_Real *)C_MyV;
0216 Standard_Boolean *CMyIsOnBounds = (Standard_Boolean *)C_MyIsOnBounds;
0217 Standard_Integer i0 = Upars.Lower(), j0 = Vpars.Lower();
0218
0219 for (i1 = 0; i1 <= nbdeltaU; i1++) {
0220 U = Upars(i1+i0);
0221 for (i2 = 0; i2 <= nbdeltaV; i2++) {
0222 V = Vpars(i2+j0);
0223 ThePSurfaceTool::D0(Surface,U,V,TP);
0224 //-- Point(TP,i1, i2,U,V);
0225 CMyPnts[Index] = TP;
0226 CMyU[Index] = U;
0227 CMyV[Index] = V;
0228 // Modified by Sergey KHROMOV - Fri Dec 7 12:07:51 2001
0229 CMyIsOnBounds[Index] = (i1 == 0 || i1 == nbdeltaU ||
0230 i2 == 0 || i2 == nbdeltaV);
0231 // Modified by Sergey KHROMOV - Fri Dec 7 12:07:52 2001
0232 TheBnd.Add(TP);
0233 Index++;
0234 }
0235 }
0236 //-- Calcul de la deflection Triangle <-> Point milieu
0237 Standard_Real tol=0.0; Standard_Integer nbtriangles = NbTriangles();
0238 for (i1=1; i1<=nbtriangles; i1++) {
0239 Standard_Real tol1 = DeflectionOnTriangle(Surface,i1);
0240 if(tol1>tol) tol=tol1;
0241 }
0242 //-- Calcul de la deflection Bord <-> Point milieu
0243
0244
0245 DeflectionOverEstimation(tol*1.2);
0246 FillBounding();
0247
0248 // Modified by Sergey KHROMOV - Fri Dec 7 11:23:33 2001 Begin
0249 Standard_Real aDeflection;
0250
0251 TheBorderDeflection = RealFirst();
0252 Standard_Real U0 = Upars(i0);
0253 Standard_Real V0 = Vpars(j0);
0254 Standard_Real U1 = Upars(Upars.Upper());
0255 Standard_Real V1 = Vpars(Vpars.Upper());
0256
0257 // Compute the deflection on the lower bound (U-isoline) of the surface.
0258 aDeflection = ComputeBorderDeflection(Surface, U0, V0, V1, Standard_True);
0259
0260 if (aDeflection > TheBorderDeflection)
0261 TheBorderDeflection = aDeflection;
0262
0263 // Compute the deflection on the upper bound (U-isoline) of the surface.
0264 aDeflection = ComputeBorderDeflection(Surface, U1, V0, V1, Standard_True);
0265
0266 if (aDeflection > TheBorderDeflection)
0267 TheBorderDeflection = aDeflection;
0268
0269 // Compute the deflection on the lower bound (V-isoline) of the surface.
0270 aDeflection = ComputeBorderDeflection(Surface, V0, U0, U1, Standard_False);
0271
0272 if (aDeflection > TheBorderDeflection)
0273 TheBorderDeflection = aDeflection;
0274
0275 // Compute the deflection on the upper bound (V-isoline) of the surface.
0276 aDeflection = ComputeBorderDeflection(Surface, V1, U0, U1, Standard_False);
0277
0278 if (aDeflection > TheBorderDeflection)
0279 TheBorderDeflection = aDeflection;
0280
0281 // Modified by Sergey KHROMOV - Fri Dec 7 11:23:34 2001 End
0282
0283 #ifdef OCCT_DEBUG_DUMP
0284 Dump();
0285 #endif
0286 }
0287 //=======================================================================
0288 //function : DeflectionOnTriangle
0289 //purpose :
0290 //=======================================================================
0291 Standard_Real IntCurveSurface_Polyhedron::DeflectionOnTriangle (const ThePSurface& Surface,
0292 const Standard_Integer Triang) const
0293 {
0294 Standard_Integer i1,i2,i3;
0295 Triangle(Triang,i1,i2,i3);
0296 //-- Calcul de l equation du plan
0297 Standard_Real u1,v1,u2,v2,u3,v3;
0298 gp_Pnt P1,P2,P3;
0299 P1 = Point(i1,u1,v1);
0300 P2 = Point(i2,u2,v2);
0301 P3 = Point(i3,u3,v3);
0302 if(P1.SquareDistance(P2)<=LONGUEUR_MINI_EDGE_TRIANGLE) return(0);
0303 if(P1.SquareDistance(P3)<=LONGUEUR_MINI_EDGE_TRIANGLE) return(0);
0304 if(P2.SquareDistance(P3)<=LONGUEUR_MINI_EDGE_TRIANGLE) return(0);
0305 gp_XYZ XYZ1=P2.XYZ()-P1.XYZ();
0306 gp_XYZ XYZ2=P3.XYZ()-P2.XYZ();
0307 gp_XYZ XYZ3=P1.XYZ()-P3.XYZ();
0308 gp_Vec NormalVector((XYZ1^XYZ2)+(XYZ2^XYZ3)+(XYZ3^XYZ1));
0309 Standard_Real aNormLen = NormalVector.Magnitude();
0310 if (aNormLen < gp::Resolution()) {
0311 return 0.;
0312 }
0313 //
0314 NormalVector.Divide(aNormLen);
0315 //-- Standard_Real PolarDistance = NormalVector * P1.XYZ();
0316 //-- Calcul du point u,v au centre du triangle
0317 Standard_Real u = (u1+u2+u3)/3.0;
0318 Standard_Real v = (v1+v2+v3)/3.0;
0319 gp_Pnt P = ThePSurfaceTool::Value(Surface,u,v);
0320 gp_Vec P1P(P1,P);
0321 return(Abs(P1P.Dot(NormalVector)));
0322 }
0323 //=======================================================================
0324 //function : Parameters
0325 //purpose :
0326 //=======================================================================
0327 void IntCurveSurface_Polyhedron::Parameters( const Standard_Integer Index
0328 ,Standard_Real &U
0329 ,Standard_Real &V) const
0330 {
0331 #if CHECKBOUNDS
0332 if(Index<0 || Index>((nbdeltaU+1)*(nbdeltaV+1))) {
0333 printf("\n Erreur IntCurveSurface_Polyhedron::Parameters\n");
0334 }
0335 #endif
0336 Standard_Real *CMyU = (Standard_Real *)C_MyU;
0337 U = CMyU[Index];
0338 Standard_Real *CMyV = (Standard_Real *)C_MyV;
0339 V = CMyV[Index];
0340 }
0341 //=======================================================================
0342 //function : DeflectionOverEstimation
0343 //purpose : Set
0344 //=======================================================================
0345 void IntCurveSurface_Polyhedron::DeflectionOverEstimation(const Standard_Real flec)
0346 {
0347 if(flec<0.0001) {
0348 TheDeflection=0.0001;
0349 TheBnd.Enlarge(0.0001);
0350 }
0351 else {
0352 TheDeflection=flec;
0353 TheBnd.Enlarge(flec);
0354 }
0355 }
0356 //=======================================================================
0357 //function : DeflectionOverEstimation
0358 //purpose : Get
0359 //=======================================================================
0360 Standard_Real IntCurveSurface_Polyhedron::DeflectionOverEstimation() const
0361 {
0362 return TheDeflection;
0363 }
0364 //=======================================================================
0365 //function : Bounding
0366 //purpose :
0367 //=======================================================================
0368 const Bnd_Box& IntCurveSurface_Polyhedron::Bounding() const
0369 {
0370 return TheBnd;
0371 }
0372 //=======================================================================
0373 //function : FillBounding
0374 //purpose :
0375 //=======================================================================
0376 void IntCurveSurface_Polyhedron::FillBounding()
0377 {
0378 TheComponentsBnd=new Bnd_HArray1OfBox(1, NbTriangles());
0379 Bnd_Box Boite;
0380 Standard_Integer np1, np2, np3;
0381 Standard_Integer nbtriangles = NbTriangles();
0382 for (Standard_Integer iTri=1; iTri<=nbtriangles; iTri++) {
0383 Triangle(iTri, np1, np2, np3);
0384 gp_Pnt p1(Point(np1));
0385 gp_Pnt p2(Point(np2));
0386 gp_Pnt p3(Point(np3));
0387 Boite.SetVoid();
0388 if(p1.SquareDistance(p2)>LONGUEUR_MINI_EDGE_TRIANGLE) {
0389 if(p1.SquareDistance(p3)>LONGUEUR_MINI_EDGE_TRIANGLE) {
0390 if(p2.SquareDistance(p3)>LONGUEUR_MINI_EDGE_TRIANGLE) {
0391 Boite.Add(p1);
0392 Boite.Add(p2);
0393 Boite.Add(p3);
0394 Boite.Enlarge(TheDeflection);
0395 }
0396 }
0397 }
0398 Boite.Enlarge(TheDeflection);
0399 TheComponentsBnd->SetValue(iTri,Boite);
0400 }
0401 }
0402 //=======================================================================
0403 //function : ComponentsBounding
0404 //purpose :
0405 //=======================================================================
0406 const Handle(Bnd_HArray1OfBox)&
0407 IntCurveSurface_Polyhedron::ComponentsBounding() const
0408 {
0409 return TheComponentsBnd;
0410 }
0411 //=======================================================================
0412 //function : NbTriangles
0413 //purpose :
0414 //=======================================================================
0415 Standard_Integer IntCurveSurface_Polyhedron::NbTriangles () const
0416 {
0417 return nbdeltaU*nbdeltaV*2;
0418 }
0419 //=======================================================================
0420 //function : NbPoints
0421 //purpose :
0422 //=======================================================================
0423 Standard_Integer IntCurveSurface_Polyhedron::NbPoints () const
0424 {
0425 return (nbdeltaU+1)*(nbdeltaV+1);
0426 }
0427 //=======================================================================
0428 //function : TriConnex
0429 //purpose :
0430 //=======================================================================
0431 Standard_Integer IntCurveSurface_Polyhedron::TriConnex
0432 (const Standard_Integer Triang,
0433 const Standard_Integer Pivot,
0434 const Standard_Integer Pedge,
0435 Standard_Integer& TriCon,
0436 Standard_Integer& OtherP) const
0437 {
0438 Standard_Integer Pivotm1 = Pivot-1;
0439 Standard_Integer nbdeltaVp1 = nbdeltaV+1;
0440 Standard_Integer nbdeltaVm2 = nbdeltaV + nbdeltaV;
0441
0442 // Pivot position in the MaTriangle :
0443 Standard_Integer ligP = Pivotm1/nbdeltaVp1;
0444 Standard_Integer colP = Pivotm1 - ligP * nbdeltaVp1;
0445
0446 // Point sur Edge position in the MaTriangle and edge typ :
0447 Standard_Integer ligE =0, colE =0, typE =0;
0448 if (Pedge!=0) {
0449 ligE= (Pedge-1)/nbdeltaVp1;
0450 colE= (Pedge-1) - (ligE * nbdeltaVp1);
0451 // Horizontal
0452 if (ligP==ligE) typE=1;
0453 // Vertical
0454 else if (colP==colE) typE=2;
0455 // Oblique
0456 else typE=3;
0457 }
0458 else {
0459 typE=0;
0460 }
0461
0462 // Triangle position General case :
0463
0464 Standard_Integer linT =0, colT =0;
0465 Standard_Integer linO =0, colO =0;
0466 Standard_Integer t =0, tt =0;
0467
0468 if (Triang!=0) {
0469 t = (Triang-1)/(nbdeltaVm2);
0470 tt= (Triang-1)-t*nbdeltaVm2;
0471 linT= 1+t;
0472 colT= 1+tt;
0473 if (typE==0) {
0474 if (ligP==linT) {
0475 ligE=ligP-1;
0476 colE=colP-1;
0477 typE=3;
0478 }
0479 else {
0480 if (colT==ligP+ligP) {
0481 ligE=ligP;
0482 colE=colP-1;
0483 typE=1;
0484 }
0485 else {
0486 ligE=ligP+1;
0487 colE=colP+1;
0488 typE=3;
0489 }
0490 }
0491 }
0492 switch (typE) {
0493 case 1: // Horizontal
0494 if (linT==ligP) {
0495 linT++;
0496 linO=ligP+1;
0497 colO=(colP>colE)? colP : colE; //--colO=Max(colP, colE);
0498 }
0499 else {
0500 linT--;
0501 linO=ligP-1;
0502 colO=(colP<colE)? colP : colE; //--colO=Min(colP, colE);
0503 }
0504 break;
0505 case 2: // Vertical
0506 if (colT==(colP+colP)) {
0507 colT++;
0508 linO=(ligP>ligE)? ligP : ligE; //--linO=Max(ligP, ligE);
0509 colO=colP+1;
0510 }
0511 else {
0512 colT--;
0513 linO=(ligP<ligE)? ligP : ligE; //--linO=Min(ligP, ligE);
0514 colO=colP-1;
0515 }
0516 break;
0517 case 3: // Oblique
0518 if ((colT&1)==0) {
0519 colT--;
0520 linO=(ligP>ligE)? ligP : ligE; //--linO=Max(ligP, ligE);
0521 colO=(colP<colE)? colP : colE; //--colO=Min(colP, colE);
0522 }
0523 else {
0524 colT++;
0525 linO=(ligP<ligE)? ligP : ligE; //--linO=Min(ligP, ligE);
0526 colO=(colP>colE)? colP : colE; //--colO=Max(colP, colE);
0527 }
0528 break;
0529 }
0530 }
0531 else {
0532 // Unknown Triangle position :
0533 if (Pedge==0) {
0534 // Unknown edge :
0535 linT=(1>ligP)? 1 : ligP; //--linT=Max(1, ligP);
0536 colT=(1>(colP+colP))? 1 : (colP+colP); //--colT=Max(1, colP+colP);
0537 if (ligP==0) linO=ligP+1;
0538 else linO=ligP-1;
0539 colO=colP;
0540 }
0541 else {
0542 // Known edge We take the left or down connectivity :
0543 switch (typE) {
0544 case 1: // Horizontal
0545 linT=ligP+1;
0546 colT=(colP>colE)? colP : colE; //--colT=Max(colP,colE);
0547 colT+=colT;
0548 linO=ligP+1;
0549 colO=(colP>colE)? colP : colE; //--colO=Max(colP,colE);
0550 break;
0551 case 2: // Vertical
0552 linT=(ligP>ligE)? ligP : ligE; //--linT=Max(ligP, ligE);
0553 colT=colP+colP;
0554 linO=(ligP<ligE)? ligP : ligE; //--linO=Min(ligP, ligE);
0555 colO=colP-1;
0556 break;
0557 case 3: // Oblique
0558 linT=(ligP>ligE)? ligP : ligE; //--linT=Max(ligP, ligE);
0559 colT=colP+colE;
0560 linO=(ligP>ligE)? ligP : ligE; //--linO=Max(ligP, ligE);
0561 colO=(colP<colE)? colP : colE; //--colO=Min(colP, colE);
0562 break;
0563 }
0564 }
0565 }
0566
0567 TriCon=(linT-1)*nbdeltaVm2 + colT;
0568
0569 if (linT<1) {
0570 linO=0;
0571 colO=colP+colP-colE;
0572 if (colO<0) {colO=0;linO=1;}
0573 else if (colO>nbdeltaV) {colO=nbdeltaV;linO=1;}
0574 TriCon=0;
0575 }
0576 else if (linT>nbdeltaU) {
0577 linO=nbdeltaU;
0578 colO=colP+colP-colE;
0579 if (colO<0) {colO=0;linO=nbdeltaU-1;}
0580 else if (colO>nbdeltaV) {colO=nbdeltaV;linO=nbdeltaU-1;}
0581 TriCon=0;
0582 }
0583
0584 if (colT<1) {
0585 colO=0;
0586 linO=ligP+ligP-ligE;
0587 if (linO<0) {linO=0;colO=1;}
0588 else if (linO>nbdeltaU) {linO=nbdeltaU;colO=1;}
0589 TriCon=0;
0590 }
0591 else if (colT>nbdeltaV) {
0592 colO=nbdeltaV;
0593 linO=ligP+ligP-ligE;
0594 if (linO<0) {linO=0;colO=nbdeltaV-1;}
0595 else if (linO>nbdeltaU) {linO=nbdeltaU;colO=nbdeltaV-1;}
0596 TriCon=0;
0597 }
0598
0599 OtherP=linO*nbdeltaVp1 + colO+1;
0600
0601 return TriCon;
0602 }
0603
0604
0605 //=======================================================================
0606 //function : PlaneEquation
0607 //purpose :
0608 //=======================================================================
0609 void IntCurveSurface_Polyhedron::PlaneEquation (const Standard_Integer Triang,
0610 gp_XYZ& NormalVector,
0611 Standard_Real& PolarDistance) const
0612 {
0613 Standard_Integer i1,i2,i3;
0614 Triangle(Triang,i1,i2,i3);
0615
0616 //-- gp_XYZ v1=Point(i2).XYZ()-Point(i1).XYZ();
0617 //-- gp_XYZ v2=Point(i3).XYZ()-Point(i2).XYZ();
0618 //-- gp_XYZ v3=Point(i1).XYZ()-Point(i3).XYZ();
0619
0620 gp_XYZ Pointi1(Point(i1).XYZ());
0621 gp_XYZ Pointi2(Point(i2).XYZ());
0622 gp_XYZ Pointi3(Point(i3).XYZ());
0623
0624
0625 gp_XYZ v1= Pointi2 - Pointi1;
0626 gp_XYZ v2= Pointi3 - Pointi2;
0627 gp_XYZ v3= Pointi1 - Pointi3;
0628
0629 if(v1.SquareModulus()<=LONGUEUR_MINI_EDGE_TRIANGLE) { NormalVector.SetCoord(1.0,0.0,0.0); return; }
0630 if(v2.SquareModulus()<=LONGUEUR_MINI_EDGE_TRIANGLE) { NormalVector.SetCoord(1.0,0.0,0.0); return; }
0631 if(v3.SquareModulus()<=LONGUEUR_MINI_EDGE_TRIANGLE) { NormalVector.SetCoord(1.0,0.0,0.0); return; }
0632
0633 NormalVector= (v1^v2)+(v2^v3)+(v3^v1);
0634 Standard_Real aNormLen = NormalVector.Modulus();
0635 if (aNormLen < gp::Resolution()) {
0636 PolarDistance = 0.;
0637 }
0638 else {
0639 NormalVector.Divide(aNormLen);
0640 PolarDistance = NormalVector * Point(i1).XYZ();
0641 }
0642 }
0643 //=======================================================================
0644 //function : Contain
0645 //purpose :
0646 //=======================================================================
0647 Standard_Boolean IntCurveSurface_Polyhedron::Contain (const Standard_Integer Triang,
0648 const gp_Pnt& ThePnt) const
0649 {
0650 Standard_Integer i1,i2,i3;
0651 Triangle(Triang,i1,i2,i3);
0652 gp_XYZ Pointi1(Point(i1).XYZ());
0653 gp_XYZ Pointi2(Point(i2).XYZ());
0654 gp_XYZ Pointi3(Point(i3).XYZ());
0655
0656 gp_XYZ v1=(Pointi2-Pointi1)^(ThePnt.XYZ()-Pointi1);
0657 gp_XYZ v2=(Pointi3-Pointi2)^(ThePnt.XYZ()-Pointi2);
0658 gp_XYZ v3=(Pointi1-Pointi3)^(ThePnt.XYZ()-Pointi3);
0659 if (v1*v2 >= 0. && v2*v3 >= 0. && v3*v1>=0.)
0660 return Standard_True;
0661 else
0662 return Standard_False;
0663 }
0664 //=======================================================================
0665 //function : Dump
0666 //purpose :
0667 //=======================================================================
0668 void IntCurveSurface_Polyhedron::Dump() const
0669 {
0670
0671 }
0672 //=======================================================================
0673 //function : Size
0674 //purpose :
0675 //=======================================================================
0676 void IntCurveSurface_Polyhedron::Size (Standard_Integer& nbdu,
0677 Standard_Integer& nbdv) const
0678 {
0679 nbdu=nbdeltaU;
0680 nbdv=nbdeltaV;
0681 }
0682 //=======================================================================
0683 //function : Triangle
0684 //purpose :
0685 //=======================================================================
0686 void IntCurveSurface_Polyhedron::Triangle (const Standard_Integer Index,
0687 Standard_Integer& P1,
0688 Standard_Integer& P2,
0689 Standard_Integer& P3) const
0690 {
0691 Standard_Integer line=1+((Index-1)/(nbdeltaV*2));
0692 Standard_Integer colon=1+((Index-1)%(nbdeltaV*2));
0693 Standard_Integer colpnt=(colon+1)/2;
0694
0695 // General formula = (line-1)*(nbdeltaV+1)+colpnt
0696
0697 // Position of P1 = MesXYZ(line,colpnt);
0698 P1= (line-1)*(nbdeltaV+1) + colpnt;
0699
0700 // Position of P2= MesXYZ(line+1,colpnt+((colon-1)%2));
0701 P2= line*(nbdeltaV+1) + colpnt+((colon-1)%2);
0702
0703 // Position of P3= MesXYZ(line+(colon%2),colpnt+1);
0704 P3= (line-1+(colon%2))*(nbdeltaV+1) + colpnt + 1;
0705 }
0706 //=======================================================================
0707 //function : Point
0708 //=======================================================================
0709 const gp_Pnt& IntCurveSurface_Polyhedron::Point(const Standard_Integer Index
0710 ,Standard_Real& U
0711 ,Standard_Real& V) const
0712 {
0713 #if CHECKBOUNDS
0714 if(Index<0 || Index>((nbdeltaU+1)*(nbdeltaV+1))) {
0715 printf("\n Erreur IntCurveSurface_Polyhedron::Parameters\n");
0716 }
0717 #endif
0718 gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts;
0719 Standard_Real *CMyU = (Standard_Real *)C_MyU;
0720 Standard_Real *CMyV = (Standard_Real *)C_MyV;
0721 U=CMyU[Index];
0722 V=CMyV[Index];
0723 return CMyPnts[Index];
0724 }
0725 //=======================================================================
0726 //function : Point
0727 //=======================================================================
0728 const gp_Pnt& IntCurveSurface_Polyhedron::Point(const Standard_Integer Index) const {
0729 #if CHECKBOUNDS
0730 if(Index<0 || Index>((nbdeltaU+1)*(nbdeltaV+1))) {
0731 printf("\n Erreur IntCurveSurface_Polyhedron::Parameters\n");
0732 }
0733 #endif
0734
0735 gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts;
0736 return CMyPnts[Index];
0737 }
0738 //=======================================================================
0739 //function : Point
0740 //=======================================================================
0741 //void IntCurveSurface_Polyhedron::Point (const gp_Pnt& p,
0742 // const Standard_Integer lig,
0743 // const Standard_Integer col,
0744 // const Standard_Real u,
0745 // const Standard_Real v)
0746 void IntCurveSurface_Polyhedron::Point (const gp_Pnt& ,
0747 const Standard_Integer ,
0748 const Standard_Integer ,
0749 const Standard_Real ,
0750 const Standard_Real )
0751 {
0752 printf("\n IntCurveSurface_Polyhedron::Point : Ne dois pas etre appelle\n");
0753 }
0754 //=======================================================================
0755 //function : Point
0756 //=======================================================================
0757 void IntCurveSurface_Polyhedron::Point (const Standard_Integer Index,gp_Pnt& P) const
0758 {
0759 #if CHECKBOUNDS
0760 if(Index<0 || Index>((nbdeltaU+1)*(nbdeltaV+1))) {
0761 printf("\n Erreur IntCurveSurface_Polyhedron::Parameters\n");
0762 }
0763 #endif
0764
0765 gp_Pnt *CMyPnts = (gp_Pnt *)C_MyPnts;
0766 P = CMyPnts[Index];
0767 }
0768
0769 // Modified by Sergey KHROMOV - Fri Dec 7 10:12:47 2001 Begin
0770
0771 //=======================================================================
0772 //function : IsOnBound
0773 //purpose : This method returns true if the edge based on points with
0774 // indices Index1 and Index2 represents a boundary edge.
0775 //=======================================================================
0776
0777 Standard_Boolean IntCurveSurface_Polyhedron::IsOnBound
0778 (const Standard_Integer Index1,
0779 const Standard_Integer Index2) const
0780 {
0781 #if CHECKBOUNDS
0782 if(Index1<0 || Index1>((nbdeltaU+1)*(nbdeltaV+1))) {
0783 printf("\n Erreur IntCurveSurface_Polyhedron::IsOnBound\n");
0784 }
0785 if(Index2<0 || Index2>((nbdeltaU+1)*(nbdeltaV+1))) {
0786 printf("\n Erreur IntCurveSurface_Polyhedron::IsOnBound\n");
0787 }
0788 #endif
0789 Standard_Boolean *CMyIsOnBounds = (Standard_Boolean *)C_MyIsOnBounds;
0790 Standard_Integer aDiff = Abs(Index1 - Index2);
0791 Standard_Integer i;
0792
0793 // Check if points are neighbour ones.
0794 if (aDiff != 1 && aDiff != nbdeltaV + 1)
0795 return Standard_False;
0796
0797 for (i = 0; i <= nbdeltaU; i++) {
0798 if ((Index1 == 1 + i*(nbdeltaV + 1)) && (Index2 == Index1 - 1))
0799 return Standard_False;
0800
0801 if ((Index1 == (1 + i)*(nbdeltaV + 1)) && (Index2 == Index1 + 1))
0802 return Standard_False;
0803 }
0804
0805 return (CMyIsOnBounds[Index1] && CMyIsOnBounds[Index2]);
0806 }
0807
0808 //=======================================================================
0809 //function : ComputeBorderDeflection
0810 //purpose : This method computes and returns a deflection of isoline
0811 // of given parameter on Surface.
0812 //=======================================================================
0813
0814 Standard_Real IntCurveSurface_Polyhedron::ComputeBorderDeflection
0815 (const ThePSurface &Surface,
0816 const Standard_Real Parameter,
0817 const Standard_Real PMin,
0818 const Standard_Real PMax,
0819 const Standard_Boolean isUIso) const
0820 {
0821 Standard_Integer aNbSamples;
0822 Standard_Integer i;
0823
0824 if (isUIso)
0825 aNbSamples = nbdeltaV;
0826 else
0827 aNbSamples = nbdeltaU;
0828
0829 Standard_Real aDelta = (PMax - PMin)/aNbSamples;
0830 Standard_Real aPar = PMin;
0831 Standard_Real aDeflection = RealFirst();
0832 gp_XYZ aP1;
0833 gp_XYZ aP2;
0834 gp_XYZ aPMid;
0835 gp_XYZ aPParMid;
0836
0837 for (i = 0; i <= aNbSamples; i++, aPar+= aDelta) {
0838 if (isUIso) {
0839 aP1 = ThePSurfaceTool::Value(Surface, Parameter, aPar).XYZ();
0840 aP2 = ThePSurfaceTool::Value(Surface, Parameter, aPar + aDelta).XYZ();
0841 aPParMid = ThePSurfaceTool::Value(Surface, Parameter, aPar + aDelta/2.).XYZ();
0842 } else {
0843 aP1 = ThePSurfaceTool::Value(Surface, aPar, Parameter).XYZ();
0844 aP2 = ThePSurfaceTool::Value(Surface, aPar + aDelta, Parameter).XYZ();
0845 aPParMid = ThePSurfaceTool::Value(Surface, aPar + aDelta/2., Parameter).XYZ();
0846 }
0847 aPMid = (aP2 + aP1)/2.;
0848
0849 Standard_Real aDist = (aPMid - aPParMid).Modulus();
0850
0851 if (aDist > aDeflection)
0852 aDeflection = aDist;
0853 }
0854
0855 return aDeflection;
0856 }
0857
0858 // Modified by Sergey KHROMOV - Fri Dec 7 11:21:52 2001 End