0027085: ShapeUpgrade_UnifySameDomain very large performance difference for seemingly...
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_SplitCurve.cxx
1 // Created on: 1998-03-12
2 // Created by: Pierre BARRAS
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 //    gka 30.04.99 S4137: re-worked
18
19 #include <Geom_BSplineCurve.hxx>
20 #include <Precision.hxx>
21 #include <ShapeExtend.hxx>
22 #include <ShapeUpgrade.hxx>
23 #include <ShapeUpgrade_SplitCurve.hxx>
24 #include <Standard_Type.hxx>
25 #include <TColGeom_HArray1OfCurve.hxx>
26 #include <TColStd_HSequenceOfReal.hxx>
27 #include <TColStd_ListIteratorOfListOfReal.hxx>
28
29 IMPLEMENT_STANDARD_RTTIEXT(ShapeUpgrade_SplitCurve,MMgt_TShared)
30
31 //=======================================================================
32 //function : ShapeUpgrade_SplitCurve
33 //purpose  : 
34 //=======================================================================
35 ShapeUpgrade_SplitCurve::ShapeUpgrade_SplitCurve() : myStatus(0)
36 {
37 }
38
39 //=======================================================================
40 //function : Init
41 //purpose  : 
42 //=======================================================================
43
44  void ShapeUpgrade_SplitCurve::Init(const Standard_Real First,
45                                     const Standard_Real Last) 
46 {
47   myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
48 //  if (ShapeUpgrade::Debug()) cout << "SplitCurve::Init"<<endl;
49
50   myNbCurves = 1;
51  // mySplitValues.Clear();
52   mySplitValues = new TColStd_HSequenceOfReal;
53   mySplitValues->Append(First);
54   mySplitValues->Append(Last);
55 }
56
57 //=======================================================================
58 //function : SetSplitValues
59 //purpose  : 
60 //=======================================================================
61
62  void ShapeUpgrade_SplitCurve::SetSplitValues (const Handle(TColStd_HSequenceOfReal)& SplitValues)
63 {
64   Standard_Real precision = Precision::PConfusion();
65   if(SplitValues.IsNull()) return;
66   if(SplitValues->Length()==0) return;
67     
68   Standard_Real First = mySplitValues->Value(1), 
69   Last = mySplitValues->Value(mySplitValues->Length()); 
70   Standard_Integer i =1;
71   Standard_Integer len = SplitValues->Length();
72    for( Standard_Integer k = 2;k <= mySplitValues->Length();k++) {
73      Last = mySplitValues->Value(k);
74      for(; i <=  len; i++) {
75        if( (First + precision) >= SplitValues->Value(i)) continue;
76        if((Last - precision) <= SplitValues->Value(i)) break;
77        mySplitValues->InsertBefore(k++,SplitValues->Value(i));
78      }
79      First = Last;
80    }
81 }
82
83
84 //=======================================================================
85 //function : Build
86 //purpose  : 
87 //=======================================================================
88
89  void ShapeUpgrade_SplitCurve::Build(const Standard_Boolean /*Segment*/) 
90 {
91   myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
92 }
93
94
95 //=======================================================================
96 //function : GlobalKnots
97 //purpose  : 
98 //=======================================================================
99
100 const Handle(TColStd_HSequenceOfReal)& ShapeUpgrade_SplitCurve::SplitValues() const
101 {
102   return mySplitValues;
103 }
104
105 //=======================================================================
106 //function : Perform
107 //purpose  : 
108 //=======================================================================
109
110 void ShapeUpgrade_SplitCurve::Perform(const Standard_Boolean Segment)
111 {
112   Compute();
113   //if ( ! mySplitValues.IsNull() ) 
114   //  SetSplitValues(mySplitValues);
115   Build(Segment);
116
117 }
118 //=======================================================================
119 //function : Compute
120 //purpose  : 
121 //===================================================================
122 void ShapeUpgrade_SplitCurve::Compute()  
123 {  
124   myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
125 }
126 //=======================================================================
127 //function : Status
128 //purpose  : 
129 //=======================================================================
130
131 Standard_Boolean ShapeUpgrade_SplitCurve::Status(const ShapeExtend_Status status) const
132 {
133   return ShapeExtend::DecodeStatus (myStatus, status);
134 }