Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/opencascade/IntCurveSurface_Polygon.gxx is written in an unsupported language. File is not indexed.

0001 // Created on: 1992-10-12
0002 // Created by: Laurent BUCHARD
0003 // Copyright (c) 1992-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 <Standard_ConstructionError.hxx>
0018 #include <Bnd_Box.hxx>
0019 #include <TColgp_Array1OfPnt.hxx>
0020 #include <gp_Lin.hxx>
0021 #include <gp_Vec.hxx>
0022 #include <gp_Dir.hxx>
0023 
0024 
0025 //======================================================================
0026 //== On echantillonne sur le Domain de la Curve  NbPts Points 
0027 //== a parametres constants.
0028 //== 
0029 //== On estime la fleche maximum en prenant la distance maxi entre la 
0030 //== droite Curve.Value(X(i))-->Curve.Value(X(i+1)) 
0031 //== et le point Curve.Value(X(i+1/2))
0032 //======================================================================
0033 IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve&        C,
0034                                                  const Standard_Integer tNbPts):
0035        ThePnts(1,(tNbPts<5)? 5 : tNbPts) 
0036 { 
0037   Standard_Integer NbPts = (tNbPts<5)? 5 : tNbPts;
0038   NbPntIn = NbPts;
0039   Binf = TheCurveTool::FirstParameter(C);
0040   Bsup = TheCurveTool::LastParameter(C);
0041   Init(C); 
0042 }
0043 
0044 
0045 
0046 IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve&        C,
0047                                                  const Standard_Real    U1,
0048                                                  const Standard_Real    U2,
0049                                                  const Standard_Integer tNbPts):
0050        ThePnts(1,(tNbPts<5)? 5 : tNbPts) , Binf(U1) , Bsup(U2)
0051 { 
0052   
0053   
0054   Standard_Integer NbPts = (tNbPts<5)? 5 : tNbPts;
0055   NbPntIn = NbPts;
0056   Init(C);
0057 }
0058 
0059 //=======================================================================
0060 //function : IntCurveSurface_Polygon
0061 //purpose  : 
0062 //=======================================================================
0063 
0064 IntCurveSurface_Polygon::IntCurveSurface_Polygon(const TheCurve&        C,
0065                                                  const TColStd_Array1OfReal& Upars):
0066        ThePnts(1,Upars.Length()) , Binf(Upars(Upars.Lower())) , Bsup(Upars(Upars.Upper()))
0067 { 
0068   
0069   //ddout << "IntCurveSurface_Polygon::IntCurveSurface_Polygon" << endl;
0070   Standard_Integer NbPts = Upars.Length();
0071   //ddout << "NbPts :" << NbPts << endl;
0072   NbPntIn = NbPts;
0073   Init(C, Upars);
0074 }
0075 
0076 
0077 void IntCurveSurface_Polygon::Init(const TheCurve&        C) { 
0078   
0079   Standard_Real u=Binf; 
0080   Standard_Real u1=Bsup;
0081   Standard_Real du=(u1-u)/(Standard_Real)(NbPntIn-1);
0082   Standard_Integer i=1;
0083   gp_Pnt P;
0084   do {
0085     TheCurveTool::D0(C,u,P);
0086     TheBnd.Add(P);
0087     ThePnts.SetValue(i,P);             
0088     u+=du;
0089     i++;
0090   }
0091   while(i<=NbPntIn);
0092 
0093 
0094   //-----------------------------------------------------
0095   //--- Calcul d un majorant de fleche approche
0096   //---
0097   TheDeflection = 0.0;
0098 
0099   if(NbPntIn>3) { 
0100     
0101     i=1;
0102     u=Binf;
0103     u+=du * 0.5;
0104     
0105     do {
0106       gp_Pnt Pm=TheCurveTool::Value(C,u);
0107       gp_Pnt P1=ThePnts.Value(i);
0108       gp_Pnt P2=ThePnts.Value(i+1);
0109       gp_Lin L(P1,gp_Dir(gp_Vec(P1,P2)));
0110       Standard_Real t=L.Distance(Pm);
0111       
0112       if(t>TheDeflection) {
0113         TheDeflection = t;
0114       }
0115       u+=du;
0116       i++;
0117     }
0118     while(i<NbPntIn);
0119     
0120     TheBnd.Enlarge(1.5*TheDeflection);
0121   }
0122   else { 
0123     TheBnd.Enlarge(1e-10);
0124   }
0125   ClosedPolygon = Standard_False;
0126 }
0127 
0128 //=======================================================================
0129 //function : Init
0130 //purpose  : 
0131 //=======================================================================
0132 
0133 void IntCurveSurface_Polygon::Init(const TheCurve&        C,
0134                                    const TColStd_Array1OfReal& Upars) { 
0135 
0136   //ddout << "IntCurveSurface_Polygon::Init" << endl;
0137   Standard_Real u=Binf; 
0138   Standard_Integer i=1, i0 = Upars.Lower()-1;
0139   gp_Pnt P;
0140 
0141   myParams = new TColStd_HArray1OfReal(1, Upars.Length());
0142   do {
0143     //ddout << "-------------Parameter : " << i << " " << Upars(i+i0) << endl;
0144     myParams->SetValue(i, Upars(i+i0));
0145     TheCurveTool::D0(C,Upars(i+i0),P);
0146     //ddout << "P : " << P.X() << " " << P.Y() << " " << P.Z() << endl;
0147     TheBnd.Add(P);
0148     ThePnts.SetValue(i,P);             
0149     i++;
0150   }
0151   while(i<=NbPntIn);
0152 
0153 
0154   //-----------------------------------------------------
0155   //--- Calcul d un majorant de fleche approche
0156   //---
0157   TheDeflection = 0.0;
0158 
0159   if(NbPntIn>3) { 
0160     
0161     i=1;
0162     //ddout << "Deflection estimation" << endl;
0163     do {
0164       u = 0.5*(Upars(i0+i)+Upars(i0+i+1));
0165       //ddout << "===========Parameter : " << i << " " << u << endl;
0166       gp_Pnt Pm=TheCurveTool::Value(C,u);
0167       //ddout << "Pm : " << Pm.X() << " " << Pm.Y() << " " << Pm.Z() << endl;
0168       gp_Pnt P1=ThePnts.Value(i);
0169       //ddout << "P1 : " << P1.X() << " " << P1.Y() << " " << P1.Z() << endl;
0170       gp_Pnt P2=ThePnts.Value(i+1);
0171       //ddout << "P2 : " << P2.X() << " " << P2.Y() << " " << P2.Z() << endl;
0172       gp_Lin L(P1,gp_Dir(gp_Vec(P1,P2)));
0173       Standard_Real t=L.Distance(Pm);
0174       //ddout << "Distance " << t << endl;
0175       if(t>TheDeflection) {
0176         TheDeflection = t;
0177       }
0178       i++;
0179     }
0180     while(i<NbPntIn);
0181     //ddout << " TheDeflection = " << TheDeflection << endl;
0182     TheBnd.Enlarge(1.5*TheDeflection);
0183   }
0184   else { 
0185     TheBnd.Enlarge(1e-10);
0186   }
0187   ClosedPolygon = Standard_False;
0188 }
0189 
0190 
0191 //======================================================================
0192 Standard_Real IntCurveSurface_Polygon::ApproxParamOnCurve(const Standard_Integer TheIndex,
0193                                                           const Standard_Real    TheParamOnLine) const
0194 {
0195   //ddout << "IntCurveSurface_Polygon::ApproxParamOnCurve" << endl;
0196   if(TheParamOnLine < 0.0 || TheParamOnLine >1.0) { 
0197 #ifdef OCCT_DEBUG
0198     std::cout<<" ParamOnLine  =  "<<TheParamOnLine<<"  avec Index = "
0199       <<TheIndex<<"  dans IntCurveSurface_Polygon::ApproxParamOnCurve"<<std::endl;
0200 #endif
0201     return(Binf+(TheParamOnLine*(Bsup-Binf))/(Standard_Real)(NbPntIn-1));
0202   }
0203 
0204   Standard_Integer Index = TheIndex;
0205   Standard_Real    ParamOnLine = TheParamOnLine;
0206 #ifdef OCCT_DEBUG
0207   if (Index > NbPntIn) {
0208     std::cout << "OutOfRange Polygon::ApproxParamOnCurve " <<std::endl;
0209   }
0210 #endif
0211   if((Index == NbPntIn) && (ParamOnLine == 0.0)) { 
0212     Index--; ParamOnLine=1.0;
0213   }
0214 
0215   Standard_Real du, u;
0216   if (myParams.IsNull())
0217     {
0218       du = (Bsup-Binf)/(Standard_Real)(NbPntIn-1);
0219       u  = Binf + du * (Standard_Real)(Index-1);
0220     }
0221   else
0222     {
0223       du = myParams->Value(Index+1) - myParams->Value(Index);
0224       u  = myParams->Value(Index);
0225     }
0226 
0227   u += du * ParamOnLine;
0228   return (u);
0229 }
0230  
0231 
0232 //======================================================================
0233 void IntCurveSurface_Polygon::Dump(void) const {
0234 #if 0  
0235   static Standard_Integer Compteur=0;
0236   char tamp[100];
0237   Compteur++;
0238   sprintf(tamp,"Poly%d",Compteur);
0239   std::cout<<"  @@@@@@@@@@@ F i c h i e r   :   "<<tamp<<" @@@@@@@@@@"<<std::endl;
0240   FILE *fp;
0241   fp=fopen(tamp,"w");
0242   if(fp==NULL) {
0243     std::cout<<"PolyGonGen::Erreur en Ouverture Fichier"<<tamp<<std::endl;
0244     return;
0245   }
0246   fprintf(fp,"\n#Discretisation de : %f ---> %f \n",Binf,Bsup);
0247   fprintf(fp,"\npol %d %d %f",Compteur,NbPntIn,TheDeflection);
0248   gp_Pnt p1,p2;
0249   for (Standard_Integer iObje=1; iObje<=NbSegments(); iObje++) {
0250     p1=BeginOfSeg(iObje);
0251     fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y());
0252   }
0253   p1=EndOfSeg(NbSegments());
0254   fprintf(fp,"\npnt %d %f %f",Compteur,p1.X(),p1.Y());
0255   fprintf(fp,"\ndispol %d\n#\n",Compteur);
0256   fclose(fp);
0257 #endif
0258 }
0259 //======================================================================
0260 //======================================================================