Warnings on vc14 were eliminated
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_ClosedEdgeDivide.cxx
1 // Created on: 2000-05-25
2 // Created by: data exchange team
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16
17 #include <BRep_Tool.hxx>
18 #include <Geom2d_Curve.hxx>
19 #include <Geom_Curve.hxx>
20 #include <Geom_Surface.hxx>
21 #include <gp_Pnt.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>
31
32 IMPLEMENT_STANDARD_RTTIEXT(ShapeUpgrade_ClosedEdgeDivide,ShapeUpgrade_EdgeDivide)
33
34 //=======================================================================
35 //function : ShapeUpgrade_ClosedEdgeDivide
36 //purpose  : 
37 //=======================================================================
38 ShapeUpgrade_ClosedEdgeDivide::ShapeUpgrade_ClosedEdgeDivide():
39       ShapeUpgrade_EdgeDivide()
40 {
41 }
42
43 //=======================================================================
44 //function : Compute
45 //purpose  : 
46 //=======================================================================
47
48 Standard_Boolean ShapeUpgrade_ClosedEdgeDivide::Compute(const TopoDS_Edge& anEdge)
49 {
50   Clear();
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) );
58     TolV1=TolV1*TolV1;
59     Standard_Real f, l;
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);
66     }
67     myHasCurve2d = !pcurve1.IsNull();
68     
69     if ( myHasCurve3d ) {
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);
76         if(dist > dMax) {
77           maxPar = param;
78           dMax = dist;
79         }
80       }
81       if(dMax > TolV1) {
82         Handle(ShapeUpgrade_SplitCurve3d) theSplit3dTool = GetSplitCurve3dTool();
83         theSplit3dTool->Init(curve3d,f,l);
84         
85         Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
86         values->Append(maxPar);
87         theSplit3dTool->SetSplitValues(values);
88         myKnots3d = theSplit3dTool->SplitValues();
89       
90         if(myHasCurve2d) {
91           Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
92           theSplit2dTool->Init(pcurve1,f2d,l2d);
93           myKnots2d = theSplit2dTool->SplitValues();
94         }
95         return Standard_True;
96       }
97       else
98         return Standard_False;
99     }
100     
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);
110         if(dist > dMax) {
111           maxPar = param;
112           dMax = dist;
113         }
114       }
115       if(dMax > TolV1) {
116         
117         Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
118         theSplit2dTool->Init(pcurve1,f2d,l2d);
119       
120         Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
121         values->Append(maxPar);
122         theSplit2dTool->SetSplitValues(values);
123         myKnots2d = theSplit2dTool->SplitValues();
124         return Standard_True;
125       }
126       else
127         return Standard_False;
128     }
129     
130     return Standard_False;
131     
132   }
133   else
134     return Standard_False;
135 }