1 // Created on: 2012-11-29
2 // Created by: Peter KURNEV
3 // Copyright (c) 2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <IntTools_EdgeEdge.ixx>
23 #include <gp_Elips.hxx>
30 #include <Geom_Curve.hxx>
31 #include <Geom_Line.hxx>
32 #include <Geom_Circle.hxx>
33 #include <Geom_Ellipse.hxx>
34 #include <Geom_Parabola.hxx>
35 #include <Geom_Hyperbola.hxx>
36 #include <Geom_BezierCurve.hxx>
37 #include <Geom_BSplineCurve.hxx>
38 #include <Geom_TrimmedCurve.hxx>
39 #include <Geom_OffsetCurve.hxx>
41 #include <BRep_Tool.hxx>
42 #include <BRepAdaptor_Curve.hxx>
44 //=======================================================================
45 //class : IntTools_ComparatorCurve
47 //=======================================================================
48 class IntTools_ComparatorCurve {
50 IntTools_ComparatorCurve() {
55 myIsSame=Standard_False;
58 virtual ~IntTools_ComparatorCurve(){
61 void SetCurve1(const BRepAdaptor_Curve& aBC3D) {
65 const BRepAdaptor_Curve& Curve1()const {
69 void SetRange1(const Standard_Real aT1,
70 const Standard_Real aT2) {
75 void Range1(Standard_Real& aT1, Standard_Real& aT2)const {
80 void SetCurve2(const BRepAdaptor_Curve& aBC3D){
84 const BRepAdaptor_Curve& Curve2()const{
88 void SetRange2(const Standard_Real aT1,
89 const Standard_Real aT2){
94 void Range2(Standard_Real& aT1,
95 Standard_Real& aT2)const {
100 Standard_Boolean IsSame()const {
106 //--------------------------------------
111 void IsSameBSplineCurve();
115 IsSameReal(const Standard_Real aR1,
116 const Standard_Real aR2);
120 IsSameAx2(const gp_Ax2& aAx21,
121 const gp_Ax2& aAx22);
125 IsSameAx1(const gp_Ax1& aAx1,
130 IsSamePnt(const gp_Pnt& aP1,
134 IsSameDir(const gp_Dir& aDir1,
135 const gp_Dir& aDir2);
139 IsSameXYZ(const gp_XYZ& aXYZ1,
140 const gp_XYZ& aXYZ2);
143 void GetCurveBase(const Handle(Geom_Curve)& aC3D,
144 GeomAbs_CurveType& aTypeBase,
145 Handle(Geom_Curve)& aCurveBase);
149 IsTypeBase(const Handle(Geom_Curve)& aC,
150 GeomAbs_CurveType& aTypeB);
153 BRepAdaptor_Curve myBC1;
157 BRepAdaptor_Curve myBC2;
161 Standard_Boolean myIsSame;
163 //=======================================================================
166 //=======================================================================
167 void IntTools_ComparatorCurve::Perform()
169 GeomAbs_CurveType aCurveType1, aCurveType2;
171 myIsSame=Standard_False;
173 aCurveType1=myBC1.GetType();
174 aCurveType2=myBC2.GetType();
176 myIsSame=(aCurveType1==aCurveType2);
181 myIsSame=IsSameReal(myT11, myT21);
186 myIsSame=IsSameReal(myT12, myT22);
191 if (aCurveType1==GeomAbs_Ellipse) {
195 else if (aCurveType1==GeomAbs_BSplineCurve) {
196 IsSameBSplineCurve();
200 myIsSame=Standard_False;
204 //=======================================================================
205 //function : IsSameBSplineCurve
207 //=======================================================================
208 void IntTools_ComparatorCurve::IsSameBSplineCurve()
210 Standard_Boolean bIsRational, bIsPreiodic;
211 Standard_Integer iNbPoles, iNbKnots, iDegree;
213 bIsRational=myBC1.IsRational();
214 myIsSame=(bIsRational==myBC2.IsRational());
219 iNbPoles=myBC1.NbPoles();
220 myIsSame=(iNbPoles==myBC2.NbPoles());
225 iNbKnots=myBC1.NbKnots();
226 myIsSame=(iNbKnots==myBC2.NbKnots());
231 iDegree=myBC1.Degree();
232 myIsSame=(iDegree==myBC2.Degree());
237 bIsPreiodic=myBC1.IsPeriodic();
238 myIsSame=(bIsPreiodic==myBC2.IsPeriodic());
243 //-------------------------------------------
244 Standard_Integer i, j, aM[2];
245 Standard_Real aT1, aT2, aX0[4], aX1[4];
246 GeomAbs_CurveType aTypeBase;
248 Handle(Geom_Curve) aC;
249 Handle(Geom_BSplineCurve) aBSp[2];
250 TopoDS_Edge aE1, aE2;
255 aC=BRep_Tool::Curve (aE1, aT1, aT2);
256 GetCurveBase(aC, aTypeBase, aBSp[0]);
258 aC=BRep_Tool::Curve (aE2, aT1, aT2);
259 GetCurveBase(aC, aTypeBase, aBSp[1]);
262 for(i=1; i<=iNbPoles; ++i) {
264 aP.Coord(aX0[0], aX0[1], aX0[2]);
265 aX0[3]=aBSp[0]->Weight(i);
268 aP.Coord(aX1[0], aX1[1], aX1[2]);
269 aX1[3]=aBSp[1]->Weight(i);
271 for (j=0; j<4; ++j) {
272 myIsSame=IsSameReal(aX0[j], aX1[j]);
277 }//for(i=1; i<iNbPoles; ++i) {
279 // Knots / Multiplicities
280 for(i=1; i<=iNbKnots; ++i) {
281 aX0[0]=aBSp[0]->Knot(i);
282 aX0[1]=aBSp[1]->Knot(i);
283 myIsSame=IsSameReal(aX0[0], aX0[1]);
288 aM[0]=aBSp[0]->Multiplicity(i);
289 aM[1]=aBSp[1]->Multiplicity(i);
290 myIsSame=(aM[0]==aM[1]);
296 //=======================================================================
297 //function : GetCurveBase
299 //=======================================================================
300 void IntTools_ComparatorCurve::GetCurveBase(const Handle(Geom_Curve)& aC3D,
301 GeomAbs_CurveType& aTypeBase,
302 Handle(Geom_Curve)& aCurveBase)
304 Standard_Boolean bIsTypeBase;
305 Standard_Integer iTrimmed, iOffset;
306 Standard_Real aOffsetBase;
307 GeomAbs_CurveType aTypeB;
308 Handle(Geom_Curve) aC3DB;
309 Handle(Geom_TrimmedCurve) aCT3D;
310 Handle(Geom_OffsetCurve) aCF3D;
312 aTypeBase=GeomAbs_OtherCurve;
316 bIsTypeBase=IsTypeBase(aC3DB, aTypeB);
326 aCT3D=Handle(Geom_TrimmedCurve)::DownCast(aC3DB);
327 if (!aCT3D.IsNull()) {
328 aC3DB=aCT3D->BasisCurve();
332 aCF3D=Handle(Geom_OffsetCurve)::DownCast(aC3DB);
333 if (!aCF3D.IsNull()) {
334 Standard_Real aOffset;
336 aOffset=aCF3D->Offset();
337 aOffsetBase=aOffsetBase+aOffset;
339 aC3DB=aCF3D->BasisCurve();
343 if (!(iTrimmed || iOffset)) {
347 bIsTypeBase=IsTypeBase(aC3DB, aTypeB);
355 //=======================================================================
356 //function : IsTypeBase
358 //=======================================================================
360 IntTools_ComparatorCurve::IsTypeBase(const Handle(Geom_Curve)& aC,
361 GeomAbs_CurveType& aTypeB)
363 Standard_Boolean bRet;
364 Handle(Standard_Type) aType;
368 aType=aC->DynamicType();
369 if (aType==STANDARD_TYPE(Geom_Line)) {
372 else if (aType==STANDARD_TYPE(Geom_Circle)) {
373 aTypeB=GeomAbs_Circle;
375 else if (aType==STANDARD_TYPE(Geom_Ellipse)) {
376 aTypeB=GeomAbs_Ellipse;
378 else if (aType==STANDARD_TYPE(Geom_Parabola)) {
379 aTypeB=GeomAbs_Parabola;
381 else if (aType==STANDARD_TYPE(Geom_Hyperbola)) {
382 aTypeB=GeomAbs_Hyperbola;
384 else if (aType==STANDARD_TYPE(Geom_BezierCurve)) {
385 aTypeB=GeomAbs_BezierCurve;
387 else if (aType==STANDARD_TYPE(Geom_BSplineCurve)) {
388 aTypeB=GeomAbs_BSplineCurve;
391 aTypeB=GeomAbs_OtherCurve;
396 //=======================================================================
397 //function : IsSameElipse
399 //=======================================================================
400 void IntTools_ComparatorCurve::IsSameElipse()
402 Standard_Real aR1, aR2;
403 gp_Elips aElips1, aElips2;
405 myIsSame=Standard_False;
407 aElips1=myBC1.Ellipse();
408 aElips2=myBC2.Ellipse();
410 aR1=aElips1.MajorRadius();
411 aR2=aElips2.MajorRadius();
412 myIsSame=IsSameReal(aR1, aR2);
417 aR1=aElips1.MinorRadius();
418 aR2=aElips2.MinorRadius();
419 myIsSame=IsSameReal(aR1, aR2);
424 const gp_Ax2& aAx21=aElips1.Position();
425 const gp_Ax2& aAx22=aElips2.Position();
426 myIsSame=IsSameAx2(aAx21, aAx22);
428 //=======================================================================
429 //function : IsSameAx2
431 //=======================================================================
433 IntTools_ComparatorCurve::IsSameAx2(const gp_Ax2& aAx21,
436 Standard_Boolean bRet;
438 const gp_Ax1& aAx1=aAx21.Axis();
439 const gp_Ax1& aAx2=aAx22.Axis();
441 bRet=IsSameAx1(aAx1, aAx2);
446 const gp_Dir& aDirX1=aAx21.XDirection();
447 const gp_Dir& aDirX2=aAx22.XDirection();
449 bRet=IsSameDir(aDirX1, aDirX2);
455 const gp_Dir& aDirY1=aAx21.YDirection();
456 const gp_Dir& aDirY2=aAx22.YDirection();
458 bRet=IsSameDir(aDirY1, aDirY2);
462 //=======================================================================
463 //function : IsSamePnt
465 //=======================================================================
467 IntTools_ComparatorCurve::IsSamePnt(const gp_Pnt& aP1,
470 const gp_XYZ& aXYZ1=aP1.XYZ();
471 const gp_XYZ& aXYZ2=aP2.XYZ();
472 return IsSameXYZ(aXYZ1, aXYZ2);
474 //=======================================================================
475 //function : IsSameAx1
477 //=======================================================================
479 IntTools_ComparatorCurve::IsSameAx1(const gp_Ax1& aAx1,
482 Standard_Boolean bRet;
484 const gp_Pnt& aP1=aAx1.Location();
485 const gp_Pnt& aP2=aAx2.Location();
487 bRet=IsSamePnt(aP1, aP2);
492 const gp_Dir& aDir1=aAx1.Direction();
493 const gp_Dir& aDir2=aAx2.Direction();
495 bRet=IsSameDir(aDir1, aDir2);
498 //=======================================================================
499 //function : IsSameDir
501 //=======================================================================
503 IntTools_ComparatorCurve::IsSameDir(const gp_Dir& aDir1,
506 const gp_XYZ& aXYZ1=aDir1.XYZ();
507 const gp_XYZ& aXYZ2=aDir2.XYZ();
508 return IsSameXYZ(aXYZ1, aXYZ2);
510 //=======================================================================
511 //function : IsSameXYZ
513 //=======================================================================
515 IntTools_ComparatorCurve::IsSameXYZ(const gp_XYZ& aXYZ1,
518 Standard_Boolean bRet;
520 Standard_Real aX1[3], aX2[3];
522 aXYZ1.Coord(aX1[0], aX1[1], aX1[2]);
523 aXYZ2.Coord(aX2[0], aX2[1], aX2[2]);
525 for (i=0; i<3; ++i) {
526 bRet=IsSameReal(aX1[i], aX2[i]);
533 //=======================================================================
534 //function : IsSameReal
536 //=======================================================================
538 IntTools_ComparatorCurve::IsSameReal(const Standard_Real aR1,
539 const Standard_Real aR2)
541 Standard_Boolean bRet;
542 Standard_Real aEpsilon;
544 aEpsilon=Epsilon(aR1);
545 bRet=(fabs(aR1-aR2)<aEpsilon);
548 //=======================================================================
549 //function : IsSameCurves
551 //=======================================================================
552 Standard_Boolean IntTools_EdgeEdge::IsSameCurves()
554 Standard_Boolean bRet;
555 IntTools_ComparatorCurve aICC;
557 aICC.SetCurve1(myCFrom);
558 aICC.SetRange1(myTminFrom, myTmaxFrom);
560 aICC.SetCurve2(myCTo);
561 aICC.SetRange2(myTminTo, myTmaxTo);