Warnings on vc14 were eliminated
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_SplitSurfaceArea.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14
15 #include <GeomAdaptor_Surface.hxx>
16 #include <ShapeUpgrade_SplitSurfaceArea.hxx>
17 #include <Standard_Type.hxx>
18 #include <TColStd_HSequenceOfReal.hxx>
19
20 IMPLEMENT_STANDARD_RTTIEXT(ShapeUpgrade_SplitSurfaceArea,ShapeUpgrade_SplitSurface)
21
22 //=======================================================================
23 //function : ShapeUpgrade_SplitSurfaceArea
24 //purpose  : 
25 //=======================================================================
26 ShapeUpgrade_SplitSurfaceArea::ShapeUpgrade_SplitSurfaceArea():
27        ShapeUpgrade_SplitSurface()
28 {
29   myNbParts =1;
30 }
31
32 //=======================================================================
33 //function : Compute
34 //purpose  : 
35 //=======================================================================
36
37  void ShapeUpgrade_SplitSurfaceArea::Compute(const Standard_Boolean /*Segment*/) 
38 {
39   if(myNbParts <= 1)
40     return;
41   
42   GeomAdaptor_Surface ads(mySurface,myUSplitValues->Value(1),myUSplitValues->Value(2),
43                           myVSplitValues->Value(1),myVSplitValues->Value(2));
44   Standard_Real aKoefU = ads.UResolution(1.);
45   Standard_Real aKoefV = ads.VResolution(1.);
46   if(aKoefU ==0)
47     aKoefU =1.;
48   if(aKoefV ==0)
49     aKoefV =1.;
50   Standard_Real aUSize = fabs(myUSplitValues->Value(2) - myUSplitValues->Value(1))/aKoefU;
51   Standard_Real aVSize = fabs(myVSplitValues->Value(2) - myVSplitValues->Value(1))/aKoefV;
52   Standard_Real  aNbUV =  aUSize/aVSize;
53   Handle(TColStd_HSequenceOfReal) aFirstSplit = (aNbUV <1. ? myVSplitValues : myUSplitValues);
54   Handle(TColStd_HSequenceOfReal) aSecondSplit = (aNbUV <1. ? myUSplitValues : myVSplitValues);
55   if(aNbUV<1)
56     aNbUV = 1./aNbUV;
57   
58   Standard_Integer nbSplitF = (aNbUV >=  myNbParts ? myNbParts : RealToInt(ceil(sqrt(myNbParts*ceil(aNbUV)))));
59   Standard_Integer nbSplitS = (aNbUV >=  myNbParts ? 0  : RealToInt(ceil((Standard_Real)myNbParts/(Standard_Real)nbSplitF)));
60   if(nbSplitS ==1)
61     nbSplitS++;
62   if(!nbSplitF)
63     return;
64   Standard_Real aStep = (aFirstSplit->Value(2) - aFirstSplit->Value(1))/nbSplitF;
65   Standard_Real aPrevPar = aFirstSplit->Value(1);
66   Standard_Integer i =1;
67   for( ; i < nbSplitF; i++) {
68     Standard_Real aNextPar = aPrevPar + aStep;
69     aFirstSplit->InsertBefore(i+1,aNextPar);
70     aPrevPar = aNextPar;
71   }
72   
73   if(nbSplitS) {
74     aStep = (aSecondSplit->Value(2) - aSecondSplit->Value(1))/nbSplitS;
75     aPrevPar = aSecondSplit->Value(1);
76     for(i =1 ; i < nbSplitS; i++) {
77       Standard_Real aNextPar = aPrevPar + aStep;
78       aSecondSplit->InsertBefore(i+1,aNextPar);
79       aPrevPar = aNextPar;
80     }
81   }
82 }
83