0024157: Parallelization of assembly part of BO
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_ClosedEdgeDivide.cxx
1 // Created on: 2000-05-25
2 // Created by: data exchange team
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
4 //
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.
9 //
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.
12 //
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.
19
20
21
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>
31 #include <gp_Pnt.hxx>
32 #include <Geom_Surface.hxx>
33 #include <gp_Pnt2d.hxx>
34
35 //=======================================================================
36 //function : ShapeUpgrade_ClosedEdgeDivide
37 //purpose  : 
38 //=======================================================================
39
40 ShapeUpgrade_ClosedEdgeDivide::ShapeUpgrade_ClosedEdgeDivide():
41       ShapeUpgrade_EdgeDivide()
42 {
43 }
44
45 //=======================================================================
46 //function : Compute
47 //purpose  : 
48 //=======================================================================
49
50 Standard_Boolean ShapeUpgrade_ClosedEdgeDivide::Compute(const TopoDS_Edge& anEdge)
51 {
52   Clear();
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) );
60     TolV1=TolV1*TolV1;
61     Standard_Real f, l;
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);
68     }
69     myHasCurve2d = !pcurve1.IsNull();
70     
71     if ( myHasCurve3d ) {
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);
78         if(dist > dMax) {
79           maxPar = param;
80           dMax = dist;
81         }
82       }
83       if(dMax > TolV1) {
84         Handle(ShapeUpgrade_SplitCurve3d) theSplit3dTool = GetSplitCurve3dTool();
85         theSplit3dTool->Init(curve3d,f,l);
86         
87         Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
88         values->Append(maxPar);
89         theSplit3dTool->SetSplitValues(values);
90         myKnots3d = theSplit3dTool->SplitValues();
91       
92         if(myHasCurve2d) {
93           Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
94           theSplit2dTool->Init(pcurve1,f2d,l2d);
95           myKnots2d = theSplit2dTool->SplitValues();
96         }
97         return Standard_True;
98       }
99       else
100         return Standard_False;
101     }
102     
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);
112         if(dist > dMax) {
113           maxPar = param;
114           dMax = dist;
115         }
116       }
117       if(dMax > TolV1) {
118         
119         Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
120         theSplit2dTool->Init(pcurve1,f2d,l2d);
121       
122         Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
123         values->Append(maxPar);
124         theSplit2dTool->SetSplitValues(values);
125         myKnots2d = theSplit2dTool->SplitValues();
126         return Standard_True;
127       }
128       else
129         return Standard_False;
130     }
131     
132     return Standard_False;
133     
134   }
135   else
136     return Standard_False;
137 }