Warning, /include/opencascade/IntWalk_IWalking_1.gxx is written in an unsupported language. File is not indexed.
0001 // Copyright (c) 1995-1999 Matra Datavision
0002 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0003 //
0004 // This file is part of Open CASCADE Technology software library.
0005 //
0006 // This library is free software; you can redistribute it and/or modify it under
0007 // the terms of the GNU Lesser General Public License version 2.1 as published
0008 // by the Free Software Foundation, with special exception defined in the file
0009 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0010 // distribution for complete text of the license and disclaimer of any warranty.
0011 //
0012 // Alternatively, this file may be used under the terms of Open CASCADE
0013 // commercial license or contractual agreement.
0014
0015 #ifdef CHRONO
0016 #include <OSD_Chronometer.hxx>
0017 OSD_Chronometer Chronrsnld;
0018
0019 #endif
0020
0021 #include <NCollection_IncAllocator.hxx>
0022 #include <Precision.hxx>
0023
0024 //==================================================================================
0025 // function : IsTangentExtCheck
0026 // purpose : Additional check if the point (theU, theV) in parametric surface
0027 // is a tangent point.
0028 // If that is TRUE then we can go along any (!) direction in order to
0029 // obtain next intersection point. At present, this case is difficult
0030 // for processing. Therefore, we will return an empty intersection line
0031 // in this case.
0032 //==================================================================================
0033 static Standard_Boolean IsTangentExtCheck(TheIWFunction& theFunc,
0034 const Standard_Real theU,
0035 const Standard_Real theV,
0036 const Standard_Real theStepU,
0037 const Standard_Real theStepV,
0038 const Standard_Real theUinf,
0039 const Standard_Real theUsup,
0040 const Standard_Real theVinf,
0041 const Standard_Real theVsup)
0042 {
0043 const Standard_Real aTol = theFunc.Tolerance();
0044 const Standard_Integer aNbItems = 4;
0045 const Standard_Real aParU[aNbItems] = { Min(theU + theStepU, theUsup),
0046 Max(theU - theStepU, theUinf),
0047 theU, theU};
0048 const Standard_Real aParV[aNbItems] = { theV, theV,
0049 Min(theV + theStepV, theVsup),
0050 Max(theV - theStepV, theVinf)};
0051
0052 math_Vector aX(1, 2), aVal(1, 1);
0053
0054 for(Standard_Integer i = 0; i < aNbItems; i++)
0055 {
0056 aX.Value(1) = aParU[i];
0057 aX.Value(2) = aParV[i];
0058
0059 if(!theFunc.Value(aX, aVal))
0060 continue;
0061
0062 if(Abs(theFunc.Root()) > aTol)
0063 return Standard_False;
0064 }
0065
0066 return Standard_True;
0067 }
0068
0069
0070
0071 IntWalk_IWalking::IntWalk_IWalking (const Standard_Real Epsilon,
0072 const Standard_Real Deflection,
0073 const Standard_Real Increment,
0074 const Standard_Boolean theToFillHoles) :
0075 done(Standard_False),
0076 fleche(Deflection),
0077 pas(Increment),
0078 tolerance(1,2),
0079 epsilon(Epsilon*Epsilon),
0080 reversed(Standard_False),
0081 wd1 (IntWalk_VectorOfWalkingData::allocator_type (new NCollection_IncAllocator)),
0082 wd2 (wd1.get_allocator()),
0083 nbMultiplicities (wd1.get_allocator()),
0084 Um(0.0),
0085 UM(0.0),
0086 Vm(0.0),
0087 VM(0.0),
0088 ToFillHoles(theToFillHoles)
0089 {
0090 }
0091
0092
0093 //=======================================================================
0094 //function : Reset
0095 //purpose : Clears NCollection_Vector-based containers and adds
0096 // dummy data to maintain start index of 1 and consistent with
0097 // previous TCollection_Sequence-based implementation and other
0098 // used TCollection-based containers
0099 //=======================================================================
0100
0101 void IntWalk_IWalking::Clear()
0102 {
0103 wd1.clear();
0104 wd2.clear();
0105 IntWalk_WalkingData aDummy;
0106 aDummy.etat = -10;
0107 aDummy.ustart = aDummy.vstart = 0.;
0108 wd1.push_back (aDummy);
0109 wd2.push_back (aDummy);
0110 nbMultiplicities.clear();
0111 nbMultiplicities.push_back (-1);
0112
0113 done = Standard_False;
0114 seqAjout.Clear();
0115 lines.Clear();
0116 }
0117
0118 // ***************************************************************************
0119 // etat1=12 not tangent, not passes
0120 // etat1=11 tangent, not passes
0121 // etat1=2 not tangent, passes
0122 // etat1=1 tangent, passes
0123 // after a point is processed its state becomes negative.
0124 // ***************************************************************************
0125 // etat2=13 interior start point on closed line
0126 // etat2=12 interior start point on open line
0127 // (line initially closed -> la line s is open)
0128 // after a point is processed (or if it is passed over during
0129 // routing) its state becomes negative.
0130 // ****************************************************************************
0131
0132 //
0133 // Perform with interior points
0134 //
0135 void IntWalk_IWalking::Perform(const ThePOPIterator& Pnts1,
0136 const ThePOLIterator& Pnts2,
0137 TheIWFunction& Func,
0138 const ThePSurface& Caro,
0139 const Standard_Boolean Reversed)
0140
0141 {
0142 Standard_Integer I;
0143 Standard_Boolean Rajout = Standard_False;
0144 Standard_Integer nbPnts1 = Pnts1.Length();
0145 Standard_Integer nbPnts2 = Pnts2.Length();
0146 Standard_Real U,V;
0147
0148 Clear();
0149 reversed = Reversed;
0150
0151 Um = ThePSurfaceTool::FirstUParameter(Caro);
0152 Vm = ThePSurfaceTool::FirstVParameter(Caro);
0153 UM = ThePSurfaceTool::LastUParameter(Caro);
0154 VM = ThePSurfaceTool::LastVParameter(Caro);
0155
0156 if (UM < Um) {
0157 Standard_Real utemp = UM;
0158 UM = Um;
0159 Um = utemp;
0160 }
0161 if (VM < Vm) {
0162 Standard_Real vtemp = VM;
0163 VM = Vm;
0164 Vm = vtemp;
0165 }
0166
0167 const Standard_Real aStepU = pas*(UM-Um), aStepV = pas*(VM-Vm);
0168
0169 // Loading of etat1 and etat2 as well as ustart and vstart.
0170
0171 TColStd_SequenceOfReal Umult;
0172 TColStd_SequenceOfReal Vmult;
0173
0174 Standard_Integer decal=0;
0175 wd1.reserve (nbPnts1+decal);
0176 nbMultiplicities.reserve (nbPnts1+decal);
0177 for (I=1;I <= nbPnts1+decal; I++) {
0178 const ThePointOfPath& PathPnt = Pnts1.Value(I-decal);
0179 IntWalk_WalkingData aWD1;
0180 aWD1.etat = 1;
0181 if (!ThePointOfPathTool::IsPassingPnt(PathPnt))
0182 aWD1.etat = 11;
0183 if (!ThePointOfPathTool::IsTangent(PathPnt))
0184 ++aWD1.etat;
0185
0186 if(aWD1.etat==2) {
0187 aWD1.etat=11;
0188 }
0189
0190 ThePointOfPathTool::Value2d(PathPnt, aWD1.ustart, aWD1.vstart);
0191 mySRangeU.Add(aWD1.ustart);
0192 mySRangeV.Add(aWD1.vstart);
0193
0194 wd1.push_back (aWD1);
0195 Standard_Integer aNbMult = ThePointOfPathTool::Multiplicity(PathPnt);
0196 nbMultiplicities.push_back(aNbMult);
0197
0198 for (Standard_Integer J = 1; J <= aNbMult; J++) {
0199 ThePointOfPathTool::Parameters(PathPnt, J, U, V);
0200 Umult.Append(U);
0201 Vmult.Append(V);
0202 }
0203 }
0204
0205 wd2.reserve (nbPnts2);
0206 for (I = 1; I <= nbPnts2; I++) {
0207 IntWalk_WalkingData aWD2;
0208 aWD2.etat = 1;
0209 const IntSurf_InteriorPoint& anIP = Pnts2.Value(I);
0210 ThePointOfLoopTool::Value2d(anIP, aWD2.ustart, aWD2.vstart);
0211 mySRangeU.Add(aWD2.ustart);
0212 mySRangeV.Add(aWD2.vstart);
0213
0214 if (!IsTangentExtCheck(Func, aWD2.ustart, aWD2.vstart, aStepU, aStepV, Um, UM, Vm, VM))
0215 aWD2.etat = 13;
0216
0217 wd2.push_back (aWD2);
0218 }
0219
0220 tolerance(1) = ThePSurfaceTool::UResolution(Caro,Precision::Confusion());
0221 tolerance(2) = ThePSurfaceTool::VResolution(Caro,Precision::Confusion());
0222
0223 Func.Set(Caro);
0224
0225 if (mySRangeU.Delta() > Max(tolerance(1), Precision::PConfusion()))
0226 {
0227 mySRangeU.Enlarge(mySRangeU.Delta());
0228 mySRangeU.Common(Bnd_Range(Um, UM));
0229 }
0230 else
0231 {
0232 mySRangeU = Bnd_Range(Um, UM);
0233 }
0234
0235 if (mySRangeV.Delta() > Max(tolerance(2), Precision::PConfusion()))
0236 {
0237 mySRangeV.Enlarge(mySRangeV.Delta());
0238 mySRangeV.Common(Bnd_Range(Vm, VM));
0239 }
0240 else
0241 {
0242 mySRangeV = Bnd_Range(Vm, VM);
0243 }
0244
0245 // calculation of all open lines
0246 if (nbPnts1 != 0)
0247 ComputeOpenLine(Umult,Vmult,Pnts1,Func,Rajout);
0248
0249 // calculation of all closed lines
0250 if (nbPnts2 != 0)
0251 ComputeCloseLine(Umult,Vmult,Pnts1,Pnts2,Func,Rajout);
0252
0253 if (ToFillHoles)
0254 {
0255 Standard_Integer MaxNbIter = 10, nb_iter = 0;
0256 while (seqAlone.Length() > 1 && nb_iter < MaxNbIter)
0257 {
0258 nb_iter++;
0259 IntSurf_SequenceOfInteriorPoint PntsInHoles;
0260 TColStd_SequenceOfInteger CopySeqAlone = seqAlone;
0261 FillPntsInHoles(Func, CopySeqAlone, PntsInHoles);
0262 wd2.clear();
0263 IntWalk_WalkingData aDummy;
0264 aDummy.etat = -10;
0265 aDummy.ustart = aDummy.vstart = 0.;
0266 wd2.push_back (aDummy);
0267 Standard_Integer nbHoles = PntsInHoles.Length();
0268 wd2.reserve(nbHoles);
0269 for (I = 1; I <= nbHoles; I++)
0270 {
0271 IntWalk_WalkingData aWD2;
0272 aWD2.etat = 13;
0273 const IntSurf_InteriorPoint& anIP = PntsInHoles.Value(I);
0274 ThePointOfLoopTool::Value2d(anIP, aWD2.ustart, aWD2.vstart);
0275 wd2.push_back (aWD2);
0276 }
0277 ComputeCloseLine(Umult,Vmult,Pnts1,PntsInHoles,Func,Rajout);
0278 }
0279 }
0280
0281 for (I = 1; I <= nbPnts1; I++) {
0282 if (wd1[I].etat >0) seqSingle.Append(Pnts1(I));
0283 }
0284 done = Standard_True;
0285 }
0286
0287
0288
0289 //
0290 // Perform without interior point
0291 //
0292
0293 void IntWalk_IWalking::Perform(const ThePOPIterator& Pnts1,
0294 TheIWFunction& Func,
0295 const ThePSurface& Caro,
0296 const Standard_Boolean Reversed)
0297
0298 {
0299 Standard_Integer I;
0300 Standard_Boolean Rajout = Standard_False;
0301 Standard_Integer nbPnts1 = Pnts1.Length();
0302 Standard_Real U,V;
0303
0304 reversed = Reversed;
0305
0306
0307 // Loading of etat1 as well as ustart1 and vstart1.
0308
0309 TColStd_SequenceOfReal Umult;
0310 TColStd_SequenceOfReal Vmult;
0311
0312 wd1.reserve (nbPnts1);
0313 for (I=1;I <= nbPnts1; I++) {
0314 const ThePointOfPath& PathPnt = Pnts1.Value(I);
0315 IntWalk_WalkingData aWD1;
0316 aWD1.etat = 1;
0317 if (!ThePointOfPathTool::IsPassingPnt(PathPnt)) aWD1.etat = 11;
0318 if (!ThePointOfPathTool::IsTangent(PathPnt)) ++aWD1.etat;
0319 ThePointOfPathTool::Value2d(PathPnt, aWD1.ustart, aWD1.vstart);
0320 wd1.push_back (aWD1);
0321 Standard_Integer aNbMult = ThePointOfPathTool::Multiplicity(PathPnt);
0322 nbMultiplicities.push_back(aNbMult);
0323
0324 for (Standard_Integer J = 1; J <= aNbMult; J++) {
0325 ThePointOfPathTool::Parameters(PathPnt, J, U, V);
0326 Umult.Append(U);
0327 Vmult.Append(V);
0328 }
0329 }
0330
0331 tolerance(1) = ThePSurfaceTool::UResolution(Caro,Precision::Confusion());
0332 tolerance(2) = ThePSurfaceTool::VResolution(Caro,Precision::Confusion());
0333
0334 Um = ThePSurfaceTool::FirstUParameter(Caro);
0335 Vm = ThePSurfaceTool::FirstVParameter(Caro);
0336 UM = ThePSurfaceTool::LastUParameter(Caro);
0337 VM = ThePSurfaceTool::LastVParameter(Caro);
0338
0339 if (UM < Um) {
0340 Standard_Real utemp = UM;
0341 UM = Um;
0342 Um = utemp;
0343 }
0344 if (VM < Vm) {
0345 Standard_Real vtemp = VM;
0346 VM = Vm;
0347 Vm = vtemp;
0348 }
0349
0350 Func.Set(Caro);
0351
0352 // calcul de toutes les lignes ouvertes
0353 if (nbPnts1 != 0) ComputeOpenLine(Umult,Vmult,Pnts1,Func,Rajout);
0354
0355 for (I = 1; I <= nbPnts1; I++) {
0356 if (wd1[I].etat >0) seqSingle.Append(Pnts1(I));
0357 }
0358 done = Standard_True;
0359 }
0360
0361
0362