0025266: Debug statements in the source are getting flushed on to the console
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_SplitCurve3dContinuity.cxx
CommitLineData
b311480e 1// Created on: 1999-04-15
2// Created by: Roman LYGIN
3// Copyright (c) 1999-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <ShapeUpgrade_SplitCurve3dContinuity.ixx>
18#include <Standard_ErrorHandler.hxx>
19#include <Standard_Failure.hxx>
20#include <Geom_BSplineCurve.hxx>
21#include <Precision.hxx>
22#include <ShapeUpgrade.hxx>
23#include <Geom_TrimmedCurve.hxx>
24#include <Geom_TrimmedCurve.hxx>
25#include <Geom_OffsetCurve.hxx>
26#include <Geom_Curve.hxx>
27#include <TColStd_HSequenceOfReal.hxx>
28#include <TColGeom_HArray1OfCurve.hxx>
29#include <ShapeExtend.hxx>
30
31//=======================================================================
32//function : ShapeUpgrade_SplitCurve3dContinuity
33//purpose :
34//=======================================================================
35
36ShapeUpgrade_SplitCurve3dContinuity::ShapeUpgrade_SplitCurve3dContinuity()
37{
38 myCriterion = GeomAbs_C1;
39 myTolerance = Precision::Confusion();
40 myCont =1;
41}
42
43//=======================================================================
44//function : SetCriterion
45//purpose :
46//=======================================================================
47
48 void ShapeUpgrade_SplitCurve3dContinuity::SetCriterion(const GeomAbs_Shape Criterion)
49{
50 myCriterion = Criterion;
51 switch (myCriterion) {
52 case GeomAbs_C0 : myCont = 0; break;
53 case GeomAbs_C1 : myCont = 1; break;
54 case GeomAbs_C2 : myCont = 2; break;
55 case GeomAbs_C3 : myCont = 3; break;
56 case GeomAbs_CN : myCont = 4; break;
57 default : myCont = 1;
58 }
59}
60
61//=======================================================================
62//function : SetTolerance
63//purpose :
64//=======================================================================
65
66 void ShapeUpgrade_SplitCurve3dContinuity::SetTolerance(const Standard_Real Tol)
67{
68 myTolerance = Tol;
69}
70
71//=======================================================================
72//function : Compute
73//purpose :
74//===================================================================
75void ShapeUpgrade_SplitCurve3dContinuity::Compute()
76{
77 Standard_Real First = mySplitValues->Value(1);
78 Standard_Real Last = mySplitValues->Value(mySplitValues->Length());
79 Standard_Real precision = Precision::PConfusion();
80 if(myCurve->Continuity() < myCriterion)
81 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE2);
82 if (mySplitValues->Length() > 2)
83 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
84 if (myCurve->IsKind(STANDARD_TYPE(Geom_TrimmedCurve))) {
85 Handle(Geom_TrimmedCurve) tmp = Handle(Geom_TrimmedCurve)::DownCast (myCurve);
86 Handle(Geom_Curve) BasCurve = tmp->BasisCurve();
87 ShapeUpgrade_SplitCurve3dContinuity spc;
88// spc.Init(BasCurve,Max(tmp->FirstParameter(),First),Min(tmp->LastParameter(),Last));
89 spc.Init(BasCurve,First,Last);
90 spc.SetSplitValues(mySplitValues);
91 spc.SetTolerance(myTolerance);
92 spc.SetCriterion(myCriterion);
93 spc.Compute();
94 mySplitValues->Clear();
95 mySplitValues->ChangeSequence() = spc.SplitValues()->Sequence();
96 myStatus |= spc.myStatus;
97 return;
98 }
99 else if (myCurve->IsKind(STANDARD_TYPE(Geom_OffsetCurve))) {
100 GeomAbs_Shape BasCriterion;
101 switch (myCriterion) {
102 default :
103 case GeomAbs_C1 : BasCriterion = GeomAbs_C2; break;
104 case GeomAbs_C2 : BasCriterion = GeomAbs_C3; break;
105 case GeomAbs_C3 : // if (ShapeUpgrade::Debug()) cout<<". this criterion is not suitable for a Offset curve"<<endl;
63c629aa 106#ifdef SHAPEUPGRADE_DEB
7fd59977 107 cout << "Warning: ShapeUpgrade_SplitCurve3dContinuity: criterion C3 for Offset curve" << endl;
108#endif
109 case GeomAbs_CN : BasCriterion = GeomAbs_CN; break;
110 }
111 Handle(Geom_OffsetCurve) tmp = Handle(Geom_OffsetCurve)::DownCast (myCurve);
112 Handle(Geom_Curve) BasCurve = tmp->BasisCurve();
113 //Standard_Real Offset = tmp->Offset(); // Offset not used (skl)
114 //gp_Dir Direct = tmp->Direction(); // Direct not used (skl)
115 ShapeUpgrade_SplitCurve3dContinuity spc;
116// spc.Init(BasCurve,Max(tmp->FirstParameter(),First),Min(tmp->LastParameter(),Last));
117 spc.Init(BasCurve,First,Last);
118 spc.SetSplitValues(mySplitValues);
119 spc.SetTolerance(myTolerance);
120 spc.SetCriterion(BasCriterion);
121 spc.Compute();
122 mySplitValues->Clear();
123 mySplitValues->ChangeSequence() = spc.SplitValues()->Sequence();
124 myStatus |= spc.myStatus;
125 return ;
126 }
127
128 Handle(Geom_BSplineCurve) MyBSpline = Handle(Geom_BSplineCurve)::DownCast (myCurve);
129 if (MyBSpline.IsNull()) {
130// if (ShapeUpgrade::Debug()) cout<<". curve is not a Bspline"<<endl;
131 return ;
132 }
133 // it is a BSplineCurve
134// if (ShapeUpgrade::Debug()) cout<<". curve is a Bspline"<<endl;
135
136 myNbCurves=1;
137 Standard_Integer Deg=MyBSpline->Degree();
138 Standard_Integer NbKnots= MyBSpline->NbKnots();
139// if (ShapeUpgrade::Debug()) cout<<". NbKnots="<<NbKnots<<endl;
140 if (NbKnots <= 2) {
141 return;
142 }
143 // Only the internal knots are checked.
144 Standard_Integer FirstInd =MyBSpline->FirstUKnotIndex()+1,
145 LastInd = MyBSpline->LastUKnotIndex()-1;
146 for(Standard_Integer j =2; j <= mySplitValues->Length(); j++) {
147 Last = mySplitValues->Value(j);
148 for (Standard_Integer iknot = FirstInd; iknot <= LastInd; iknot++) {
149 Standard_Real valknot = MyBSpline->Knot(iknot);
150 if(valknot <= First + precision) continue;
151 if(valknot > Last - precision) break;
152 Standard_Integer Continuity=Deg-MyBSpline->Multiplicity(iknot);
153 if (Continuity < myCont) {
154 // At this knot, the curve is C0; try to remove Knot.
155 Standard_Boolean corrected = Standard_False;
156 Standard_Integer newMultiplicity = Deg - myCont;
157 if (newMultiplicity < 0) newMultiplicity = 0;
158 {
159 try {
160 OCC_CATCH_SIGNALS
161 corrected = MyBSpline->RemoveKnot(iknot, newMultiplicity, myTolerance);
162 }
163 catch (Standard_Failure) {
164 corrected = Standard_False;
165 }
166 }
167
168
169 if (corrected && newMultiplicity > 0) {
170 Continuity=Deg-MyBSpline->Multiplicity(iknot);
171 corrected = (Continuity >= myCont);
172 }
173 if (corrected) {
174 // at this knot, the continuity is now C1. Nothing else to do.
175// if (ShapeUpgrade::Debug()) cout<<". Correction at Knot "<<iknot<<endl;
176 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE3 );
177 if(newMultiplicity == 0) {
178 //in case if knot is completelly removed
179 //it is necessary to modify last idex and decrease current knot index
180 LastInd = MyBSpline->LastUKnotIndex()-1;
181 iknot--;
182 }
183 }
184 else {
185 // impossible to force C1 within the tolerance:
186 // this knot will be a splitting value.
187 mySplitValues->InsertBefore(j++,MyBSpline->Knot(iknot));
188 myNbCurves++;
189// if (ShapeUpgrade::Debug()) cout<<". Splitting at Knot "<<iknot<<endl;
190 }
191 }
192 }
193 First = Last;
194 }
195
196 if (mySplitValues->Length() > 2)
197 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_DONE1);
198}
199
200//=======================================================================
201//function : GetCurve
202//purpose :
203//=======================================================================
204
205const Handle(Geom_Curve)& ShapeUpgrade_SplitCurve3dContinuity::GetCurve() const
206{
207 return myCurve;
208}