summaryrefslogtreecommitdiff
path: root/src/ShapeUpgrade/ShapeUpgrade_SplitSurfaceArea.cxx
blob: e5653113e7bb12046aa818810d00d32036888a03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <ShapeUpgrade_SplitSurfaceArea.ixx>
#include <TColStd_HSequenceOfReal.hxx>
#include <GeomAdaptor_Surface.hxx>
  
//=======================================================================
//function : ShapeUpgrade_SplitSurfaceArea
//purpose  : 
//=======================================================================

ShapeUpgrade_SplitSurfaceArea::ShapeUpgrade_SplitSurfaceArea():
       ShapeUpgrade_SplitSurface()
{
  myNbParts =1;
}

//=======================================================================
//function : Compute
//purpose  : 
//=======================================================================

 void ShapeUpgrade_SplitSurfaceArea::Compute(const Standard_Boolean /*Segment*/) 
{
  if(myNbParts <= 1)
    return;
  
  GeomAdaptor_Surface ads(mySurface,myUSplitValues->Value(1),myUSplitValues->Value(2),
                          myVSplitValues->Value(1),myVSplitValues->Value(2));
  Standard_Real aKoefU = ads.UResolution(1.);
  Standard_Real aKoefV = ads.VResolution(1.);
  if(aKoefU ==0)
    aKoefU =1.;
  if(aKoefV ==0)
    aKoefV =1.;
  Standard_Real aUSize = fabs(myUSplitValues->Value(2) - myUSplitValues->Value(1))/aKoefU;
  Standard_Real aVSize = fabs(myVSplitValues->Value(2) - myVSplitValues->Value(1))/aKoefV;
  Standard_Real  aNbUV =  aUSize/aVSize;
  Handle(TColStd_HSequenceOfReal) aFirstSplit = (aNbUV <1. ? myVSplitValues : myUSplitValues);
  Handle(TColStd_HSequenceOfReal) aSecondSplit = (aNbUV <1. ? myUSplitValues : myVSplitValues);
  if(aNbUV<1)
    aNbUV = 1./aNbUV;
  
  Standard_Integer nbSplitF = (aNbUV >=  myNbParts ? myNbParts : RealToInt(ceil(sqrt(myNbParts*ceil(aNbUV)))));
  Standard_Integer nbSplitS = (aNbUV >=  myNbParts ? 0  : RealToInt(ceil((Standard_Real)myNbParts/(Standard_Real)nbSplitF)));
  if(nbSplitS ==1)
    nbSplitS++;
  if(!nbSplitF)
    return;
  Standard_Real aStep = (aFirstSplit->Value(2) - aFirstSplit->Value(1))/nbSplitF;
  Standard_Real aPrevPar = aFirstSplit->Value(1);
  Standard_Integer i =1;
  for( ; i < nbSplitF; i++) {
    Standard_Real aNextPar = aPrevPar + aStep;
    aFirstSplit->InsertBefore(i+1,aNextPar);
    aPrevPar = aNextPar;
  }
  
  if(nbSplitS) {
    aStep = (aSecondSplit->Value(2) - aSecondSplit->Value(1))/nbSplitS;
    aPrevPar = aSecondSplit->Value(1);
    for(i =1 ; i < nbSplitS; i++) {
      Standard_Real aNextPar = aPrevPar + aStep;
      aSecondSplit->InsertBefore(i+1,aNextPar);
      aPrevPar = aNextPar;
    }
  }
}