0023367: New functionality restoring the middle path of pipe-like shape
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_SplitSurfaceArea.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #include <ShapeUpgrade_SplitSurfaceArea.ixx>
19 #include <TColStd_HSequenceOfReal.hxx>
20 #include <GeomAdaptor_Surface.hxx>
21
22 //=======================================================================
23 //function : ShapeUpgrade_SplitSurfaceArea
24 //purpose  : 
25 //=======================================================================
26
27 ShapeUpgrade_SplitSurfaceArea::ShapeUpgrade_SplitSurfaceArea():
28        ShapeUpgrade_SplitSurface()
29 {
30   myNbParts =1;
31 }
32
33 //=======================================================================
34 //function : Compute
35 //purpose  : 
36 //=======================================================================
37
38  void ShapeUpgrade_SplitSurfaceArea::Compute(const Standard_Boolean /*Segment*/) 
39 {
40   if(myNbParts <= 1)
41     return;
42   
43   GeomAdaptor_Surface ads(mySurface,myUSplitValues->Value(1),myUSplitValues->Value(2),
44                           myVSplitValues->Value(1),myVSplitValues->Value(2));
45   Standard_Real aKoefU = ads.UResolution(1.);
46   Standard_Real aKoefV = ads.VResolution(1.);
47   if(aKoefU ==0)
48     aKoefU =1.;
49   if(aKoefV ==0)
50     aKoefV =1.;
51   Standard_Real aUSize = fabs(myUSplitValues->Value(2) - myUSplitValues->Value(1))/aKoefU;
52   Standard_Real aVSize = fabs(myVSplitValues->Value(2) - myVSplitValues->Value(1))/aKoefV;
53   Standard_Real  aNbUV =  aUSize/aVSize;
54   Handle(TColStd_HSequenceOfReal) aFirstSplit = (aNbUV <1. ? myVSplitValues : myUSplitValues);
55   Handle(TColStd_HSequenceOfReal) aSecondSplit = (aNbUV <1. ? myUSplitValues : myVSplitValues);
56   if(aNbUV<1)
57     aNbUV = 1./aNbUV;
58   
59   Standard_Integer nbSplitF = (aNbUV >=  myNbParts ? myNbParts : RealToInt(ceil(sqrt(myNbParts*ceil(aNbUV)))));
60   Standard_Integer nbSplitS = (aNbUV >=  myNbParts ? 0  : RealToInt(ceil((Standard_Real)myNbParts/(Standard_Real)nbSplitF)));
61   if(nbSplitS ==1)
62     nbSplitS++;
63   if(!nbSplitF)
64     return;
65   Standard_Real aStep = (aFirstSplit->Value(2) - aFirstSplit->Value(1))/nbSplitF;
66   Standard_Real aPrevPar = aFirstSplit->Value(1);
67   Standard_Integer i =1;
68   for( ; i < nbSplitF; i++) {
69     Standard_Real aNextPar = aPrevPar + aStep;
70     aFirstSplit->InsertBefore(i+1,aNextPar);
71     aPrevPar = aNextPar;
72   }
73   
74   if(nbSplitS) {
75     aStep = (aSecondSplit->Value(2) - aSecondSplit->Value(1))/nbSplitS;
76     aPrevPar = aSecondSplit->Value(1);
77     for(i =1 ; i < nbSplitS; i++) {
78       Standard_Real aNextPar = aPrevPar + aStep;
79       aSecondSplit->InsertBefore(i+1,aNextPar);
80       aPrevPar = aNextPar;
81     }
82   }
83 }
84