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_ConeRangeSplitter.hxx>
17 #include <GCPnts_TangentialDeflection.hxx>
18 
19 //=======================================================================
20 // Function: GetSplitSteps
21 // Purpose :
22 //=======================================================================
GetSplitSteps(const IMeshTools_Parameters & theParameters,std::pair<Standard_Integer,Standard_Integer> & theStepsNb) const23 std::pair<Standard_Real, Standard_Real> BRepMesh_ConeRangeSplitter::GetSplitSteps(
24   const IMeshTools_Parameters&                   theParameters,
25   std::pair<Standard_Integer, Standard_Integer>& theStepsNb) const
26 {
27   const std::pair<Standard_Real, Standard_Real>& aRangeU = GetRangeU();
28   const std::pair<Standard_Real, Standard_Real>& aRangeV = GetRangeV();
29 
30   gp_Cone aCone = GetDFace()->GetSurface()->Cone();
31   Standard_Real aRefR = aCone.RefRadius();
32   Standard_Real aSAng = aCone.SemiAngle();
33   Standard_Real aRadius = Max(Abs(aRefR + aRangeV.first  * Sin(aSAng)),
34                               Abs(aRefR + aRangeV.second * Sin(aSAng)));
35 
36   Standard_Real Dv, Du = GCPnts_TangentialDeflection::ArcAngularStep(
37     aRadius, GetDFace()->GetDeflection(),
38     theParameters.Angle, theParameters.MinSize);
39 
40   const Standard_Real aDiffU = aRangeU.second - aRangeU.first;
41   const Standard_Real aDiffV = aRangeV.second - aRangeV.first;
42   Standard_Integer nbU = (Standard_Integer) (aDiffU / Du);
43   Standard_Integer nbV = (Standard_Integer) (nbU * (aDiffV) / (aDiffU * aRadius));
44   Du = aDiffU / (nbU + 1);
45   Dv = aDiffV / (nbV + 1);
46 
47   theStepsNb.first  = nbU;
48   theStepsNb.second = nbV;
49   return std::make_pair (Du, Dv);
50 }
51 
52 //=======================================================================
53 // Function: GenerateSurfaceNodes
54 // Purpose :
55 //=======================================================================
Handle(IMeshData::ListOfPnt2d)56 Handle(IMeshData::ListOfPnt2d) BRepMesh_ConeRangeSplitter::GenerateSurfaceNodes(
57   const IMeshTools_Parameters& theParameters) const
58 {
59   const std::pair<Standard_Real, Standard_Real>& aRangeU = GetRangeU();
60   const std::pair<Standard_Real, Standard_Real>& aRangeV = GetRangeV();
61 
62   std::pair<Standard_Integer, Standard_Integer> aStepsNb;
63   std::pair<Standard_Real, Standard_Real> aSteps = GetSplitSteps (theParameters, aStepsNb);
64 
65   const Handle(NCollection_IncAllocator) aTmpAlloc =
66     new NCollection_IncAllocator(IMeshData::MEMORY_BLOCK_SIZE_HUGE);
67   Handle(IMeshData::ListOfPnt2d) aNodes = new IMeshData::ListOfPnt2d(aTmpAlloc);
68 
69   const Standard_Real aPasMaxV = aRangeV.second - aSteps.second*0.5;
70   const Standard_Real aPasMaxU = aRangeU.second - aSteps.first *0.5;
71   for (Standard_Real aPasV = aRangeV.first + aSteps.second; aPasV < aPasMaxV; aPasV += aSteps.second)
72   {
73     for (Standard_Real aPasU = aRangeU.first + aSteps.first; aPasU < aPasMaxU; aPasU += aSteps.first)
74     {
75       aNodes->Append(gp_Pnt2d(aPasU, aPasV));
76     }
77   }
78 
79   return aNodes;
80 }
81