30 #include "GeomAPI_ProjectPointOnSurf.hxx"
31 #include <ShapeAnalysis_Surface.hxx>
32 #include <BRep_Tool.hxx>
33 #include <BRepAdaptor_Surface.hxx>
34 #include <BRep_Tool.hxx>
35 #include <Poly_Triangulation.hxx>
36 #include <Geom_Plane.hxx>
38 #include <Geom_CylindricalSurface.hxx>
39 #include <gp_Cylinder.hxx>
40 #include <Geom_ConicalSurface.hxx>
41 #include <gp_Cone.hxx>
42 #include <Geom_SphericalSurface.hxx>
43 #include <IGESSolid_SphericalSurface.hxx>
44 #include <gp_Sphere.hxx>
45 #include "Geom_ToroidalSurface.hxx"
46 #include <gp_Torus.hxx>
47 #include <Geom_BSplineSurface.hxx>
48 #include <Geom_BezierSurface.hxx>
49 #include <GeomConvert.hxx>
50 #include <BRepBuilderAPI_NurbsConvert.hxx>
51 #include <BRepLib_FindSurface.hxx>
55 #include <Geom_RectangularTrimmedSurface.hxx>
56 #include <BRepClass_FaceClassifier.hxx>
57 #include <gp_Pnt2d.hxx>
58 #include <Geom_SurfaceOfRevolution.hxx>
60 #pragma package(smart_init)
76 surface=BRep_Tool::Surface(
face);
78 Handle(Standard_Type) type=surface->DynamicType();
79 if(type==STANDARD_TYPE(Geom_RectangularTrimmedSurface))
81 Handle(Geom_RectangularTrimmedSurface) RTSurface =
Handle(Geom_RectangularTrimmedSurface)::DownCast(surface);
82 surface = RTSurface->BasisSurface();
88 surface->Bounds(u1,u2,v1, v2);
95 if (surface->IsUPeriodic())
periode_u=surface->UPeriod();
98 if (surface->IsVPeriodic())
periode_v=surface->VPeriod();
101 if (type==STANDARD_TYPE(Geom_BSplineSurface))
112 surface=BRep_Tool::Surface(
face);
113 Handle(Standard_Type) type=surface->DynamicType();
114 if(type==STANDARD_TYPE(Geom_RectangularTrimmedSurface))
116 Handle(Geom_RectangularTrimmedSurface) RTSurface =
Handle(Geom_RectangularTrimmedSurface)::DownCast(surface);
117 surface = RTSurface->BasisSurface();
123 surface->Bounds(u1,u2,v1, v2);
130 if (surface->IsUPeriodic())
periode_u=surface->UPeriod();
133 if (surface->IsVPeriodic())
periode_v=surface->VPeriod();
136 if (type==STANDARD_TYPE(Geom_BSplineSurface))
147 surface=BRep_Tool::Surface(
face);
148 Handle(Standard_Type) type=surface->DynamicType();
149 if(type==STANDARD_TYPE(Geom_RectangularTrimmedSurface))
151 Handle(Geom_RectangularTrimmedSurface) RTSurface =
Handle(Geom_RectangularTrimmedSurface)::DownCast(surface);
152 surface = RTSurface->BasisSurface();
189 surface->D1(u,v,
P,D1U,D1V);
211 surface->D2(u,v,
P,D1U,D1V,D2U,D2V,D2UV);
249 GeomAPI_ProjectPointOnSurf PPS(
P,surface, precision);
250 double dist=PPS.LowerDistance();
256 PPS.LowerDistanceParameters(UU,VV);
265 GeomAPI_ProjectPointOnSurf projecteur;
268 ShapeAnalysis::GetFaceUVBounds(
face,u0,u1,v0,v1);
269 gp_Pnt point(xyz[0],xyz[1],xyz[2]);
270 projecteur.Init(point,surface,u0,u1,v0,v1);
271 if(projecteur.NbPoints()==0)
return false;
272 if(projecteur.LowerDistance()<precision)
return true;
275 std::cerr <<
"OCC_SURFACE::est_sur_surface(double* xyz, double precision) --> Non disponible" << std::endl;
325 Handle(Standard_Type) type=surface->DynamicType();
326 if (type==STANDARD_TYPE(Geom_Plane))
328 Handle(Geom_Plane) Pln=
Handle(Geom_Plane)::DownCast(surface);
329 gp_Pln plan=Pln->Pln();
332 gp_Pnt centre=plan.Location();
334 origine[0]=centre.X();
335 origine[1]=centre.Y();
336 origine[2]=centre.Z();
339 gp_Ax1 axe=plan.Axis();
340 gp_Dir direction=axe.Direction();
342 normal[0]=direction.X();
343 normal[1]=direction.Y();
344 normal[2]=direction.Z();
355 if (type==STANDARD_TYPE(Geom_CylindricalSurface))
357 Handle(Geom_CylindricalSurface) cylinder=
Handle(Geom_CylindricalSurface)::DownCast(surface);
358 gp_Cylinder cylin=cylinder->Cylinder();
361 gp_Pnt centre=cylin.Location();
362 origine[0]=centre.X();
363 origine[1]=centre.Y();
364 origine[2]=centre.Z();
365 double directionX[3];
368 rayon=cylin.Radius();
370 gp_Ax3 repere=cylin.Position();
371 gp_Dir dirX=repere.XDirection();
372 gp_Dir dirZ=repere.Direction();
373 directionX[0]=dirX.X();
374 directionX[1]=dirX.Y();
375 directionX[2]=dirX.Z();
376 direction[0]=dirZ.X();
377 direction[1]=dirZ.Y();
378 direction[2]=dirZ.Z();
396 if (type==STANDARD_TYPE(Geom_ConicalSurface))
398 Handle(Geom_ConicalSurface) cone=
Handle(Geom_ConicalSurface)::DownCast(surface);
399 gp_Cone con=cone->Cone();
402 gp_Pnt centre=con.Location();
403 origine[0]=centre.X();
404 origine[1]=centre.Y();
405 origine[2]=centre.Z();
407 double directionX[3];
409 rayon=con.RefRadius();
411 angle=con.SemiAngle();
413 gp_Ax3 repere=con.Position();
414 gp_Dir dirX=repere.XDirection();
415 gp_Dir dirZ=repere.Direction();
416 directionX[0]=dirX.X();
417 directionX[1]=dirX.Y();
418 directionX[2]=dirX.Z();
419 direction[0]=dirZ.X();
420 direction[1]=dirZ.Y();
421 direction[2]=dirZ.Z();
439 if (type==STANDARD_TYPE(Geom_SphericalSurface))
441 Handle(Geom_SphericalSurface) sphere=
Handle(Geom_SphericalSurface)::DownCast(surface);
442 gp_Sphere sph=sphere->Sphere();
445 gp_Pnt centre=sph.Location();
446 origine[0]=centre.X();
447 origine[1]=centre.Y();
448 origine[2]=centre.Z();
459 if (type==STANDARD_TYPE(Geom_ToroidalSurface))
461 Handle(Geom_ToroidalSurface) tore=
Handle(Geom_ToroidalSurface)::DownCast(surface);
462 gp_Torus tro=tore->Torus();
464 gp_Pnt centre=tro.Location();
465 origine[0]=centre.X();
466 origine[1]=centre.Y();
467 origine[2]=centre.Z();
469 double directionX[3];
471 Grayon=tro.MajorRadius();
473 Prayon=tro.MinorRadius();
474 gp_Ax3 repere=tro.Position();
475 gp_Dir dirX=repere.XDirection();
476 gp_Dir dirZ=repere.Direction();
477 directionX[0]=dirX.X();
478 directionX[1]=dirX.Y();
479 directionX[2]=dirX.Z();
480 direction[0]=dirZ.X();
481 direction[1]=dirZ.Y();
482 direction[2]=dirZ.Z();
498 if (type==STANDARD_TYPE(Geom_BSplineSurface))
500 Handle(Geom_BSplineSurface) bspline=
Handle(Geom_BSplineSurface)::DownCast(surface);
502 int nb_Uknot=bspline->NbUKnots();
503 for (
int i=1; i<=nb_Uknot; i++)
505 double Uvaleur=bspline->UKnot(i);
508 int nb_Vknot=bspline->NbVKnots();
509 for (
int j=1; j<=nb_Vknot; j++)
511 double Vvaleur=bspline->VKnot(j);
516 for (
int u=1; u<=bspline->NbUPoles(); u++)
517 for (
int v=1; v<=bspline->NbVPoles(); v++)
519 pctr=bspline->Pole(u, v);
525 poids=bspline->Weight(u, v);
529 double uDegree=bspline->UDegree();
531 double vDegree=bspline->VDegree();
541 BRepBuilderAPI_NurbsConvert NURBS(
face);
542 Handle(Geom_Surface) surface=BRepLib_FindSurface(NURBS).Surface();
543 Handle(Geom_BSplineSurface) bspline=GeomConvert::SurfaceToBSplineSurface(surface) ;
546 param.
ajouter( bspline->UDegree()+1);
547 param.
ajouter(bspline->VDegree()+1);
549 param.
ajouter(bspline->NbUPoles());
550 param.
ajouter(bspline->NbVPoles());
552 for (
unsigned int i=1;i<=bspline->NbUKnots();i++)
554 param.
ajouter(bspline->UKnot(i));
557 for (
unsigned int j=1;j<=bspline->NbVKnots();j++)
559 param.
ajouter(bspline->VKnot(j));
561 for (
int v=1;v<=bspline->NbVPoles();v++)
563 for (
int u=1;u<=bspline->NbUPoles();u++)
565 double w=bspline->Weight(u,v);
566 gp_Pnt point=bspline->Pole(u, v);
577 indx_premier_ptctr=5+bspline->NbUKnots()+bspline->NbVKnots();
587 BRepMesh_IncrementalMesh(
face,eps,angle_dev);
589 Handle (Poly_Triangulation) occtri=BRep_Tool::Triangulation(
face,L);
592 BRepMesh_IncrementalMesh(
face,eps);
593 occtri=BRep_Tool::Triangulation(
face,L);
595 int nbmaille=occtri->NbTriangles();
596 const Poly_Array1OfTriangle& triangles = occtri->Triangles();
597 const TColgp_Array1OfPnt2d& uvNodes = occtri->UVNodes();
598 int numechantillonpartri=
sqrt(numechantillon*1.0/nbmaille)+1;
599 for ( Standard_Integer i = 0; i < nbmaille; i++ )
602 Poly_Triangle triangle = triangles( i + 1 );
603 bool face_reversed = (
face.Orientation() == TopAbs_REVERSED);
605 triangle.Get( n1, n3, n2 );
607 triangle.Get( n1, n2, n3 );
608 gp_Pnt2d p1=uvNodes(n1);
611 gp_Pnt2d p2=uvNodes(n2);
614 gp_Pnt2d p3=uvNodes(n3);
617 for (
int ii=0;ii<numechantillonpartri;ii++)
618 for (
int jj=0;jj<numechantillonpartri;jj++)
620 double ksi=(ii*1.0+0.5)/(double)numechantillonpartri;
621 double eta=(jj*1.0+0.5)/(double)numechantillonpartri;
622 if (ksi+eta>0.999999999999) jj=numechantillonpartri;
625 double u=ksi*u1+eta*u2+(1.-ksi-eta)*u3;
626 double v=ksi*v1+eta*v2+(1.-ksi-eta)*v3;
629 tab.push_back(
P.X());
630 tab.push_back(
P.Y());
631 tab.push_back(
P.Z());
649 std::map<unsigned long,std::map<double,NOEUDARETE,std::less<double> >,std::less<unsigned long> > areteamaille;
651 for (
int i=0;i<nbboucle;i++)
655 for (
int j=0;j<nbarete;j++)
664 std::map<double,NOEUDARETE,std::less<double> > tmp;
665 std::pair<unsigned long,std::map<double,NOEUDARETE,std::less<double> > > maptmp(are->
get_id(),tmp);
666 areteamaille.insert(maptmp);
672 Handle (Poly_Triangulation) pt=BRep_Tool::Triangulation(
face,L);
673 int nbnoeud=pt->NbNodes();
674 int nbmaille=pt->NbTriangles();
675 const TColgp_Array1OfPnt& nodes = pt->Nodes();
676 const Poly_Array1OfTriangle& triangles = pt->Triangles();
677 const TColgp_Array1OfPnt2d& uvNodes = pt->UVNodes();
678 std::vector<MG_NOEUD*> tabnoeud;
679 for ( Standard_Integer i = 0; i < nbnoeud; i++ )
681 gp_Pnt p1=nodes(i+1);
685 double key=fabs(xx)+fabs(yy)+fabs(zz);
689 std::multimap<double,MG_NOEUD*,std::less<double> >::iterator it,itbas,ithaut;
690 itbas=tabnoeudfus.lower_bound(key*0.99);
691 ithaut=tabnoeudfus.upper_bound(key*1.1010101);
692 for ( it=itbas ; it != ithaut; it++ )
695 double xtmp=ntmp->
get_x();
696 double ytmp=ntmp->
get_y();
697 double ztmp=ntmp->
get_z();
712 som->get_point()->
evaluer(xyz);
728 double xyz[3]={xx,yy,zz};
729 are->inverser(t,xyz);
730 if (are->get_courbe()->est_periodique())
731 if (t< are->get_tmin()) t=t+are->get_courbe()->get_periode();
733 are->evaluer(t,xyztmp );
736 if ((t>are->get_tmin()) && (t<are->get_tmax()))
746 std::pair<double,MG_NOEUD*> tmp(key,nvnoeud);
747 tabnoeudfus.insert(tmp);
754 std::pair<double,NOEUDARETE> tmp(na.
t,na);
755 areteamaille[topo->
get_id()].insert(tmp);
760 tabnoeud.insert(tabnoeud.end(),nvnoeud);
762 for ( Standard_Integer i = 0; i < nbmaille; i++ )
765 Poly_Triangle triangle = triangles( i + 1 );
766 bool face_reversed = (
face.Orientation() == TopAbs_REVERSED);
768 triangle.Get( n1, n3, n2 );
770 triangle.Get( n1, n2, n3 );
774 if (noeud1==noeud2)
continue;
775 if (noeud1==noeud3)
continue;
776 if (noeud2==noeud3)
continue;
913 if (are->get_lien_maillage()->get_nb()==0)
915 unsigned long id=are->
get_id();
916 MG_NOEUD* nodep=(
MG_NOEUD*)are->get_cosommet1()->get_sommet()->get_lien_maillage()->get(0);
917 MG_NOEUD* noarr=(
MG_NOEUD*)are->get_cosommet2()->get_sommet()->get_lien_maillage()->get(0);
918 std::map<double,NOEUDARETE,std::less<double> >::iterator it=areteamaille[
id].begin();
920 while (it!=areteamaille[
id].end())
941 Handle(Standard_Type) type=surface->DynamicType();
943 if(type==STANDARD_TYPE(Geom_RectangularTrimmedSurface))
945 Handle(Geom_RectangularTrimmedSurface) RTSurface =
Handle(Geom_RectangularTrimmedSurface)::DownCast(surface);
946 Handle(Geom_Surface) basissurface = RTSurface->BasisSurface();
947 Handle(Standard_Type) type_basissurface=basissurface->DynamicType();
948 if(type_basissurface==STANDARD_TYPE(Geom_SphericalSurface))
950 type=STANDARD_TYPE(Geom_SphericalSurface);
953 if(type==STANDARD_TYPE(Geom_SphericalSurface))
955 BRepClass_FaceClassifier faceclassifier;
956 gp_Pnt2d pnt2d_pole_sud(0.0,-M_PI/2.);
957 faceclassifier.Perform(
face,pnt2d_pole_sud,eps);
958 if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
960 liste_pole->push_back(0.0);
961 liste_pole->push_back(-M_PI/2.);
963 gp_Pnt2d pnt2d_pole_nord(0.0,M_PI/2.);
964 faceclassifier.Perform(
face,pnt2d_pole_nord,eps);
965 if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
967 liste_pole->push_back(0.0);
968 liste_pole->push_back(M_PI/2.);
971 if(type==STANDARD_TYPE(Geom_SurfaceOfRevolution))
973 BRepClass_FaceClassifier faceclassifier;
974 gp_Pnt2d pnt2d_pole_sud(0.0,
v_min);
975 faceclassifier.Perform(
face,pnt2d_pole_sud,eps);
976 if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
978 liste_pole->push_back(0.0);
979 liste_pole->push_back(
v_min);
981 gp_Pnt2d pnt2d_pole_nord(0.0,
v_max);
982 faceclassifier.Perform(
face,pnt2d_pole_nord,eps);
983 if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
985 liste_pole->push_back(0.0);
986 liste_pole->push_back(
v_max);
994 Handle(Geom_BSplineSurface) bspline=
Handle(Geom_BSplineSurface)::DownCast(surface);
996 for (
int v=1; v<=bspline->NbVPoles(); v++)
998 gp_Pnt pctr1=bspline->Pole(1, v);
999 gp_Pnt pctr2=bspline->Pole(bspline->NbUPoles(), v);
1000 double poids1=bspline->Weight(1, v);
1001 double poids2=bspline->Weight(bspline->NbUPoles(), v);
1023 for (
int u=1; u<=bspline->NbUPoles(); u++)
1025 gp_Pnt pctr1=bspline->Pole(u,1);
1026 gp_Pnt pctr2=bspline->Pole(u,bspline->NbVPoles());
1027 double poids1=bspline->Weight(u,1);
1028 double poids2=bspline->Weight(u,bspline->NbVPoles());
1058 double u,v,distmin=1e300;
1059 surface->Bounds(u1,u2,v1, v2);
1060 for (
int i=0;i<NUMDECOUP+1;i++)
1061 for (
int j=0;j<NUMDECOUP+1;j++)
1063 double ut=u1+i*1.0/NUMDECOUP*(u2-u1);
1064 double vt=v1+j*1.0/NUMDECOUP*(v2-v1);
1066 surface->D0(ut,vt,
P);
1067 double xyz2[3]={
P.X(),
P.Y(),
P.Z()};
1079 while (sortie==
false)
1081 double uv2[3]={u,v,0.};
1082 double xyzuv[3],xyzuvdu[3],xyzuvdv[3],xyzuvduu[3],xyzuvduv[3],xyzuvdvv[3];
1083 deriver_seconde(uv2,xyzuvduu,xyzuvduv,xyzuvdvv,xyzuv,xyzuvdu,xyzuvdv);
1092 double Fdu=
P*vxyzuvduu+vxyzuvdu*vxyzuvdu;
1093 double Fdv=
P*vxyzuvduv+vxyzuvdv*vxyzuvdu;
1094 double Gdu=
P*vxyzuvduv+vxyzuvdu*vxyzuvdv;
1095 double Gdv=
P*vxyzuvdvv+vxyzuvdv*vxyzuvdv;
1098 double det=Fdu*Gdv-Gdu*Fdv;
1099 double deltau=(-F*Gdv+Gdu*G)/det;
1100 double deltav=(-Fdu*G+F*Fdv)/det;
1101 double new_u=u+deltau;
1102 double new_v=v+deltav;
1103 if (new_u<u1) new_u=u1;
1104 if (new_u>u2) new_u=u2;
1105 if (new_v<v1) new_v=v1;
1106 if (new_v>v2) new_v=v2;
1107 if (fabs(new_u-u)<precision)
1108 if (fabs(new_v-v)<precision)
1113 if (nbiteration>1000) sortie=
true;