1 // Created on: 2000-05-25
2 // Created by: data exchange team
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BRep_Tool.hxx>
18 #include <Geom2d_Curve.hxx>
19 #include <Geom_Curve.hxx>
20 #include <Geom_Surface.hxx>
22 #include <gp_Pnt2d.hxx>
23 #include <ShapeAnalysis_Edge.hxx>
24 #include <ShapeUpgrade_ClosedEdgeDivide.hxx>
25 #include <ShapeUpgrade_SplitCurve2d.hxx>
26 #include <ShapeUpgrade_SplitCurve3d.hxx>
27 #include <Standard_Type.hxx>
28 #include <TColStd_HSequenceOfReal.hxx>
29 #include <TopoDS_Edge.hxx>
30 #include <TopoDS_Vertex.hxx>
32 IMPLEMENT_STANDARD_RTTIEXT(ShapeUpgrade_ClosedEdgeDivide,ShapeUpgrade_EdgeDivide)
34 //=======================================================================
35 //function : ShapeUpgrade_ClosedEdgeDivide
37 //=======================================================================
38 ShapeUpgrade_ClosedEdgeDivide::ShapeUpgrade_ClosedEdgeDivide():
39 ShapeUpgrade_EdgeDivide()
43 //=======================================================================
46 //=======================================================================
48 Standard_Boolean ShapeUpgrade_ClosedEdgeDivide::Compute(const TopoDS_Edge& anEdge)
51 ShapeAnalysis_Edge sae;
52 TopoDS_Vertex V1 = sae.FirstVertex(anEdge);
53 TopoDS_Vertex V2 = sae.LastVertex(anEdge);
54 if( V1.IsSame(V2) && !BRep_Tool::Degenerated ( anEdge ) ) {
55 const Standard_Integer nbPoints = 23;
56 gp_Pnt pntV = BRep_Tool::Pnt(V1);
57 Standard_Real TolV1 = LimitTolerance( BRep_Tool::Tolerance(V1) );
60 Handle(Geom_Curve) curve3d = BRep_Tool::Curve (anEdge, f, l);
61 myHasCurve3d = !curve3d.IsNull();
62 Standard_Real f2d = 0., l2d = 0.;
63 Handle(Geom2d_Curve) pcurve1;
64 if ( ! myFace.IsNull() ) { // process free edges
65 sae.PCurve (anEdge, myFace, pcurve1, f2d, l2d, Standard_False);
67 myHasCurve2d = !pcurve1.IsNull();
70 Standard_Real maxPar = f, dMax = 0;
71 Standard_Real step = (l-f)/(nbPoints-1);
72 Standard_Real param = f+step;
73 for (Standard_Integer i = 1; i < 23; i++, param+=step) {
74 gp_Pnt curPnt = curve3d->Value(param);
75 Standard_Real dist = pntV.SquareDistance(curPnt);
82 Handle(ShapeUpgrade_SplitCurve3d) theSplit3dTool = GetSplitCurve3dTool();
83 theSplit3dTool->Init(curve3d,f,l);
85 Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
86 values->Append(maxPar);
87 theSplit3dTool->SetSplitValues(values);
88 myKnots3d = theSplit3dTool->SplitValues();
91 Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
92 theSplit2dTool->Init(pcurve1,f2d,l2d);
93 myKnots2d = theSplit2dTool->SplitValues();
98 return Standard_False;
101 if ( myHasCurve2d ) {
102 Handle(Geom_Surface) surf = BRep_Tool::Surface(myFace);
103 Standard_Real maxPar = f2d, dMax = 0;
104 Standard_Real step = (l2d-f2d)/(nbPoints-1);
105 Standard_Real param = f2d+step;
106 for (Standard_Integer i = 1; i < 23; i++, param+=step) {
107 gp_Pnt2d p2d = pcurve1->Value(param);
108 gp_Pnt curPnt = surf->Value(p2d.X(),p2d.Y());
109 Standard_Real dist = pntV.SquareDistance(curPnt);
117 Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
118 theSplit2dTool->Init(pcurve1,f2d,l2d);
120 Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
121 values->Append(maxPar);
122 theSplit2dTool->SetSplitValues(values);
123 myKnots2d = theSplit2dTool->SplitValues();
124 return Standard_True;
127 return Standard_False;
130 return Standard_False;
134 return Standard_False;