// Created on: 1996-08-22 // Created by: Stagiaire Mary FABIEN // Copyright (c) 1996-1999 Matra Datavision // Copyright (c) 1999-2014 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. //======================================================================= //function : GCPnts_QuasiUniformAbscissa //purpose : //======================================================================= GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(const TheCurve& C, const Standard_Integer NbPoints) { Initialize(C, NbPoints); } //======================================================================= //function : GCPnts_QuasiUniformAbscissa //purpose : //======================================================================= GCPnts_QuasiUniformAbscissa::GCPnts_QuasiUniformAbscissa(const TheCurve& C, const Standard_Integer NbPoints, const Standard_Real U1, const Standard_Real U2) { Initialize(C, NbPoints, U1, U2); } //======================================================================= //function : Initialize //purpose : //======================================================================= void GCPnts_QuasiUniformAbscissa::Initialize(const TheCurve& C, const Standard_Integer NbPoints) { Initialize(C, NbPoints, C.FirstParameter(), C.LastParameter()); } //======================================================================= //function : Initialize //purpose : This function divides given curve on the several parts with // equal length. It returns array of parameters in the // control points. //======================================================================= void GCPnts_QuasiUniformAbscissa::Initialize(const TheCurve& C, const Standard_Integer NbPoints, const Standard_Real U1, const Standard_Real U2) { Standard_Integer i; if ((C.GetType() != GeomAbs_BezierCurve) && (C.GetType() != GeomAbs_BSplineCurve)) { GCPnts_UniformAbscissa UA(C,NbPoints,U1,U2); myDone = UA.IsDone(); myNbPoints = UA.NbPoints(); myParams = new TColStd_HArray1OfReal(1,myNbPoints); for( i = 1 ; i <= myNbPoints ; i++ ) myParams->SetValue(i,UA.Parameter(i)); #ifdef OCCT_DEBUG // char name [100]; // for( i = 1 ; i <= NbPoints ; i++ ) { // sprintf(name,"%s_%d","pnt2d",i+(compteur++)); // DrawTrSurf::Set(name,C->Value(UA.Parameter(i))); // } #endif } else { Standard_ConstructionError_Raise_if(NbPoints <= 1, ""); // evaluate the approximative length of the 3dCurve myNbPoints = NbPoints; Standard_Real Length = 0.; Standard_Real Dist, dU = (U2 - U1) / ( 2*NbPoints - 1); TColgp_Array1OfPnt2d LP(1,2*NbPoints); // tableau Longueur <-> Param ThePnt P1, P2; P1 = C.Value(U1); // On additionne toutes les distances for ( i = 0; i < 2*NbPoints ; i++) { P2 = C.Value(U1 + i*dU); Dist = P1.Distance(P2); Length += Dist; LP(i+1) = gp_Pnt2d( Length, U1 + (i*dU)); P1 = P2; } // On cherche a mettre NbPoints dans la curve. // on met les points environ a Length/NbPoints. if(IsEqual(Length, 0.0)) {//use usual analytical grid Standard_Real aStep = (U2 - U1) / (NbPoints - 1); myParams = new TColStd_HArray1OfReal(1,NbPoints); myParams->SetValue(1,U1); for ( i = 2; i < NbPoints; i++) { myParams->SetValue(i, U1 + aStep*(i-1)); } } else { Standard_Real DCorde = Length / ( NbPoints - 1); Standard_Real Corde = DCorde; Standard_Integer Index = 1; Standard_Real U, Alpha; myParams = new TColStd_HArray1OfReal(1,NbPoints); myParams->SetValue(1,U1); for ( i = 2; i < NbPoints; i++) { while ( LP(Index).X() < Corde) Index ++; Alpha = (Corde - LP(Index-1).X()) / (LP(Index).X() - LP(Index-1).X()); U = LP(Index-1).Y() + Alpha * ( LP(Index).Y() - LP(Index-1).Y()); myParams->SetValue(i,U); Corde = i*DCorde; } } myParams->SetValue(NbPoints,U2); myDone = Standard_True; } }