0026489: The class ShapeUpgrade_UnifySameDomain provides the results that are wrong...
[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
42cf5bc1 16
7fd59977 17#include <BRep_Tool.hxx>
42cf5bc1 18#include <Geom2d_Curve.hxx>
19#include <Geom_Curve.hxx>
7fd59977 20#include <Geom_Surface.hxx>
42cf5bc1 21#include <gp_Pnt.hxx>
7fd59977 22#include <gp_Pnt2d.hxx>
42cf5bc1 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>
7fd59977 31
32//=======================================================================
33//function : ShapeUpgrade_ClosedEdgeDivide
34//purpose :
35//=======================================================================
7fd59977 36ShapeUpgrade_ClosedEdgeDivide::ShapeUpgrade_ClosedEdgeDivide():
37 ShapeUpgrade_EdgeDivide()
38{
39}
40
41//=======================================================================
42//function : Compute
43//purpose :
44//=======================================================================
45
46Standard_Boolean ShapeUpgrade_ClosedEdgeDivide::Compute(const TopoDS_Edge& anEdge)
47{
48 Clear();
49 ShapeAnalysis_Edge sae;
50 TopoDS_Vertex V1 = sae.FirstVertex(anEdge);
51 TopoDS_Vertex V2 = sae.LastVertex(anEdge);
52 if( V1.IsSame(V2) && !BRep_Tool::Degenerated ( anEdge ) ) {
53 const Standard_Integer nbPoints = 23;
54 gp_Pnt pntV = BRep_Tool::Pnt(V1);
55 Standard_Real TolV1 = LimitTolerance( BRep_Tool::Tolerance(V1) );
56 TolV1=TolV1*TolV1;
57 Standard_Real f, l;
58 Handle(Geom_Curve) curve3d = BRep_Tool::Curve (anEdge, f, l);
59 myHasCurve3d = !curve3d.IsNull();
1d47d8d0 60 Standard_Real f2d = 0., l2d = 0.;
7fd59977 61 Handle(Geom2d_Curve) pcurve1;
62 if ( ! myFace.IsNull() ) { // process free edges
63 sae.PCurve (anEdge, myFace, pcurve1, f2d, l2d, Standard_False);
64 }
65 myHasCurve2d = !pcurve1.IsNull();
66
67 if ( myHasCurve3d ) {
68 Standard_Real maxPar = f, dMax = 0;
69 Standard_Real step = (l-f)/(nbPoints-1);
70 Standard_Real param = f+step;
71 for (Standard_Integer i = 1; i < 23; i++, param+=step) {
72 gp_Pnt curPnt = curve3d->Value(param);
73 Standard_Real dist = pntV.SquareDistance(curPnt);
74 if(dist > dMax) {
75 maxPar = param;
76 dMax = dist;
77 }
78 }
79 if(dMax > TolV1) {
80 Handle(ShapeUpgrade_SplitCurve3d) theSplit3dTool = GetSplitCurve3dTool();
81 theSplit3dTool->Init(curve3d,f,l);
82
83 Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
84 values->Append(maxPar);
85 theSplit3dTool->SetSplitValues(values);
86 myKnots3d = theSplit3dTool->SplitValues();
87
88 if(myHasCurve2d) {
89 Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
90 theSplit2dTool->Init(pcurve1,f2d,l2d);
91 myKnots2d = theSplit2dTool->SplitValues();
92 }
93 return Standard_True;
94 }
95 else
96 return Standard_False;
97 }
98
99 if ( myHasCurve2d ) {
100 Handle(Geom_Surface) surf = BRep_Tool::Surface(myFace);
101 Standard_Real maxPar = f2d, dMax = 0;
102 Standard_Real step = (l2d-f2d)/(nbPoints-1);
103 Standard_Real param = f2d+step;
104 for (Standard_Integer i = 1; i < 23; i++, param+=step) {
105 gp_Pnt2d p2d = pcurve1->Value(param);
106 gp_Pnt curPnt = surf->Value(p2d.X(),p2d.Y());
107 Standard_Real dist = pntV.SquareDistance(curPnt);
108 if(dist > dMax) {
109 maxPar = param;
110 dMax = dist;
111 }
112 }
113 if(dMax > TolV1) {
114
115 Handle(ShapeUpgrade_SplitCurve2d) theSplit2dTool = GetSplitCurve2dTool();
116 theSplit2dTool->Init(pcurve1,f2d,l2d);
117
118 Handle(TColStd_HSequenceOfReal) values = new TColStd_HSequenceOfReal;
119 values->Append(maxPar);
120 theSplit2dTool->SetSplitValues(values);
121 myKnots2d = theSplit2dTool->SplitValues();
122 return Standard_True;
123 }
124 else
125 return Standard_False;
126 }
127
128 return Standard_False;
129
130 }
131 else
132 return Standard_False;
133}