1 // Created on: 2000-05-25
2 // Created by: data exchange team
3 // Copyright (c) 2000-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.
22 #include <ShapeUpgrade_ClosedEdgeDivide.ixx>
23 #include <ShapeAnalysis_Edge.hxx>
24 #include <TopoDS_Vertex.hxx>
25 #include <Geom_Curve.hxx>
26 #include <Geom2d_Curve.hxx>
27 #include <BRep_Tool.hxx>
28 #include <TColStd_HSequenceOfReal.hxx>
29 #include <ShapeUpgrade_SplitCurve3d.hxx>
30 #include <ShapeUpgrade_SplitCurve2d.hxx>
32 #include <Geom_Surface.hxx>
33 #include <gp_Pnt2d.hxx>
35 //=======================================================================
36 //function : ShapeUpgrade_ClosedEdgeDivide
38 //=======================================================================
40 ShapeUpgrade_ClosedEdgeDivide::ShapeUpgrade_ClosedEdgeDivide():
41 ShapeUpgrade_EdgeDivide()
45 //=======================================================================
48 //=======================================================================
50 Standard_Boolean ShapeUpgrade_ClosedEdgeDivide::Compute(const TopoDS_Edge& anEdge)
53 ShapeAnalysis_Edge sae;
54 TopoDS_Vertex V1 = sae.FirstVertex(anEdge);
55 TopoDS_Vertex V2 = sae.LastVertex(anEdge);
56 if( V1.IsSame(V2) && !BRep_Tool::Degenerated ( anEdge ) ) {
57 const Standard_Integer nbPoints = 23;
58 gp_Pnt pntV = BRep_Tool::Pnt(V1);
59 Standard_Real TolV1 = LimitTolerance( BRep_Tool::Tolerance(V1) );
62 Handle(Geom_Curve) curve3d = BRep_Tool::Curve (anEdge, f, l);
63 myHasCurve3d = !curve3d.IsNull();
64 Standard_Real f2d = 0., l2d = 0.;
65 Handle(Geom2d_Curve) pcurve1;
66 if ( ! myFace.IsNull() ) { // process free edges
67 sae.PCurve (anEdge, myFace, pcurve1, f2d, l2d, Standard_False);
69 myHasCurve2d = !pcurve1.IsNull();
72 Standard_Real maxPar = f, dMax = 0;
73 Standard_Real step = (l-f)/(nbPoints-1);
74 Standard_Real param = f+step;
75 for (Standard_Integer i = 1; i < 23; i++, param+=step) {
76 gp_Pnt curPnt = curve3d->Value(param);
77 Standard_Real dist = pntV.SquareDistance(curPnt);
84 Handle(ShapeUpgrade_SplitCurve3d) theSplit3dTool = GetSplitCurve3dTool();
85 theSplit3dTool->Init(curve3d,f,l);
87 Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
88 values->Append(maxPar);
89 theSplit3dTool->SetSplitValues(values);
90 myKnots3d = theSplit3dTool->SplitValues();
93 Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
94 theSplit2dTool->Init(pcurve1,f2d,l2d);
95 myKnots2d = theSplit2dTool->SplitValues();
100 return Standard_False;
103 if ( myHasCurve2d ) {
104 Handle(Geom_Surface) surf = BRep_Tool::Surface(myFace);
105 Standard_Real maxPar = f2d, dMax = 0;
106 Standard_Real step = (l2d-f2d)/(nbPoints-1);
107 Standard_Real param = f2d+step;
108 for (Standard_Integer i = 1; i < 23; i++, param+=step) {
109 gp_Pnt2d p2d = pcurve1->Value(param);
110 gp_Pnt curPnt = surf->Value(p2d.X(),p2d.Y());
111 Standard_Real dist = pntV.SquareDistance(curPnt);
119 Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
120 theSplit2dTool->Init(pcurve1,f2d,l2d);
122 Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
123 values->Append(maxPar);
124 theSplit2dTool->SetSplitValues(values);
125 myKnots2d = theSplit2dTool->SplitValues();
126 return Standard_True;
129 return Standard_False;
132 return Standard_False;
136 return Standard_False;