0026106: BRepMesh - revision of data model
[occt.git] / src / BRepMesh / BRepMesh_CylinderRangeSplitter.cxx
1 // Created on: 2016-07-07
2 // Copyright (c) 2016 OPEN CASCADE SAS
3 // Created by: Oleg AGASHIN
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <BRepMesh_CylinderRangeSplitter.hxx>
17 #include <GCPnts_TangentialDeflection.hxx>
18
19 //=======================================================================
20 // Function: Reset
21 // Purpose : 
22 //=======================================================================
23 void BRepMesh_CylinderRangeSplitter::Reset(const IMeshData::IFaceHandle& theDFace,
24                                            const IMeshTools_Parameters&  theParameters)
25 {
26   BRepMesh_DefaultRangeSplitter::Reset(theDFace, theParameters);
27
28   const Standard_Real aRadius = GetDFace()->GetSurface()->Cylinder().Radius();
29   myDu = GCPnts_TangentialDeflection::ArcAngularStep(
30     aRadius, GetDFace()->GetDeflection(),
31     theParameters.Angle, theParameters.MinSize);
32 }
33
34 //=======================================================================
35 // Function: GenerateSurfaceNodes
36 // Purpose : 
37 //=======================================================================
38 Handle(IMeshData::ListOfPnt2d) BRepMesh_CylinderRangeSplitter::GenerateSurfaceNodes(
39   const IMeshTools_Parameters& /*theParameters*/) const
40 {
41   const std::pair<Standard_Real, Standard_Real>& aRangeU = GetRangeU();
42   const std::pair<Standard_Real, Standard_Real>& aRangeV = GetRangeV();
43
44   const Standard_Real aRadius = GetDFace()->GetSurface()->Cylinder().Radius();
45
46   Standard_Integer nbU = 0;
47   Standard_Integer nbV = 0;
48   const Standard_Real su = aRangeU.second - aRangeU.first;
49   const Standard_Real sv = aRangeV.second - aRangeV.first;
50   const Standard_Real aArcLen = su * aRadius;
51   if (aArcLen > GetDFace()->GetDeflection())
52   {
53     // Calculate parameters for iteration in U direction
54     nbU = (Standard_Integer) (su / myDu);
55
56     /*
57     // Calculate parameters for iteration in V direction
58     const Standard_Real aDv = nbU*sv / aArcLen;
59     // Protection against overflow during casting to int in case 
60     // of long cylinder with small radius.
61     nbV = aDv > static_cast<Standard_Real> (IntegerLast()) ?
62       0 : (Standard_Integer) (aDv);
63     nbV = Min(nbV, 100 * nbU);
64     */
65   }
66
67   const Standard_Real Du = su / (nbU + 1);
68   const Standard_Real Dv = sv / (nbV + 1);
69
70   const Handle(NCollection_IncAllocator) aTmpAlloc =
71     new NCollection_IncAllocator(IMeshData::MEMORY_BLOCK_SIZE_HUGE);
72   Handle(IMeshData::ListOfPnt2d) aNodes = new IMeshData::ListOfPnt2d(aTmpAlloc);
73
74   const Standard_Real aPasMaxV = aRangeV.second - Dv*0.5;
75   const Standard_Real aPasMaxU = aRangeU.second - Du*0.5;
76   for (Standard_Real aPasV = aRangeV.first + Dv; aPasV < aPasMaxV; aPasV += Dv)
77   {
78     for (Standard_Real aPasU = aRangeU.first + Du; aPasU < aPasMaxU; aPasU += Du)
79     {
80       aNodes->Append(gp_Pnt2d(aPasU, aPasV));
81     }
82   }
83
84   return aNodes;
85 }
86
87 //=======================================================================
88 // Function: computeDelta
89 // Purpose : 
90 //=======================================================================
91 void BRepMesh_CylinderRangeSplitter::computeDelta(
92   const Standard_Real /*theLengthU*/,
93   const Standard_Real theLengthV)
94 {
95   const std::pair<double, double>& aRangeV = GetRangeV();
96   myDelta.first  = myDu / Max(theLengthV, aRangeV.second - aRangeV.first);
97   myDelta.second = 1.;
98 }