0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_ClosedEdgeDivide.cxx
CommitLineData
b311480e 1// Created on: 2000-05-25
2// Created by: data exchange team
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <ShapeUpgrade_ClosedEdgeDivide.ixx>
17#include <ShapeAnalysis_Edge.hxx>
18#include <TopoDS_Vertex.hxx>
19#include <Geom_Curve.hxx>
20#include <Geom2d_Curve.hxx>
21#include <BRep_Tool.hxx>
22#include <TColStd_HSequenceOfReal.hxx>
23#include <ShapeUpgrade_SplitCurve3d.hxx>
24#include <ShapeUpgrade_SplitCurve2d.hxx>
25#include <gp_Pnt.hxx>
26#include <Geom_Surface.hxx>
27#include <gp_Pnt2d.hxx>
28
29//=======================================================================
30//function : ShapeUpgrade_ClosedEdgeDivide
31//purpose :
32//=======================================================================
33
34ShapeUpgrade_ClosedEdgeDivide::ShapeUpgrade_ClosedEdgeDivide():
35 ShapeUpgrade_EdgeDivide()
36{
37}
38
39//=======================================================================
40//function : Compute
41//purpose :
42//=======================================================================
43
44Standard_Boolean ShapeUpgrade_ClosedEdgeDivide::Compute(const TopoDS_Edge& anEdge)
45{
46 Clear();
47 ShapeAnalysis_Edge sae;
48 TopoDS_Vertex V1 = sae.FirstVertex(anEdge);
49 TopoDS_Vertex V2 = sae.LastVertex(anEdge);
50 if( V1.IsSame(V2) && !BRep_Tool::Degenerated ( anEdge ) ) {
51 const Standard_Integer nbPoints = 23;
52 gp_Pnt pntV = BRep_Tool::Pnt(V1);
53 Standard_Real TolV1 = LimitTolerance( BRep_Tool::Tolerance(V1) );
54 TolV1=TolV1*TolV1;
55 Standard_Real f, l;
56 Handle(Geom_Curve) curve3d = BRep_Tool::Curve (anEdge, f, l);
57 myHasCurve3d = !curve3d.IsNull();
1d47d8d0 58 Standard_Real f2d = 0., l2d = 0.;
7fd59977 59 Handle(Geom2d_Curve) pcurve1;
60 if ( ! myFace.IsNull() ) { // process free edges
61 sae.PCurve (anEdge, myFace, pcurve1, f2d, l2d, Standard_False);
62 }
63 myHasCurve2d = !pcurve1.IsNull();
64
65 if ( myHasCurve3d ) {
66 Standard_Real maxPar = f, dMax = 0;
67 Standard_Real step = (l-f)/(nbPoints-1);
68 Standard_Real param = f+step;
69 for (Standard_Integer i = 1; i < 23; i++, param+=step) {
70 gp_Pnt curPnt = curve3d->Value(param);
71 Standard_Real dist = pntV.SquareDistance(curPnt);
72 if(dist > dMax) {
73 maxPar = param;
74 dMax = dist;
75 }
76 }
77 if(dMax > TolV1) {
78 Handle(ShapeUpgrade_SplitCurve3d) theSplit3dTool = GetSplitCurve3dTool();
79 theSplit3dTool->Init(curve3d,f,l);
80
81 Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
82 values->Append(maxPar);
83 theSplit3dTool->SetSplitValues(values);
84 myKnots3d = theSplit3dTool->SplitValues();
85
86 if(myHasCurve2d) {
87 Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
88 theSplit2dTool->Init(pcurve1,f2d,l2d);
89 myKnots2d = theSplit2dTool->SplitValues();
90 }
91 return Standard_True;
92 }
93 else
94 return Standard_False;
95 }
96
97 if ( myHasCurve2d ) {
98 Handle(Geom_Surface) surf = BRep_Tool::Surface(myFace);
99 Standard_Real maxPar = f2d, dMax = 0;
100 Standard_Real step = (l2d-f2d)/(nbPoints-1);
101 Standard_Real param = f2d+step;
102 for (Standard_Integer i = 1; i < 23; i++, param+=step) {
103 gp_Pnt2d p2d = pcurve1->Value(param);
104 gp_Pnt curPnt = surf->Value(p2d.X(),p2d.Y());
105 Standard_Real dist = pntV.SquareDistance(curPnt);
106 if(dist > dMax) {
107 maxPar = param;
108 dMax = dist;
109 }
110 }
111 if(dMax > TolV1) {
112
113 Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
114 theSplit2dTool->Init(pcurve1,f2d,l2d);
115
116 Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
117 values->Append(maxPar);
118 theSplit2dTool->SetSplitValues(values);
119 myKnots2d = theSplit2dTool->SplitValues();
120 return Standard_True;
121 }
122 else
123 return Standard_False;
124 }
125
126 return Standard_False;
127
128 }
129 else
130 return Standard_False;
131}