0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / BRepBlend / BRepBlend_BlendTool.cxx
... / ...
CommitLineData
1// Created on: 1993-12-06
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1993-1999 Matra Datavision
4// Copyright (c) 1999-2014 OPEN CASCADE SAS
5//
6// This file is part of Open CASCADE Technology software library.
7//
8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
13//
14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
16
17#include <BRepBlend_BlendTool.hxx>
18
19#include <Adaptor2d_Curve2d.hxx>
20#include <Adaptor3d_Surface.hxx>
21#include <BRep_Tool.hxx>
22#include <BRepBlend_HCurve2dTool.hxx>
23#include <Extrema_EPCOfExtPC2d.hxx>
24#include <Extrema_POnCurv2d.hxx>
25#include <Geom2d_Line.hxx>
26#include <Geom2dAdaptor_Curve.hxx>
27#include <Geom2dInt_GInter.hxx>
28#include <gp_Dir2d.hxx>
29#include <gp_Pnt2d.hxx>
30#include <gp_Vec2d.hxx>
31#include <IntRes2d_IntersectionPoint.hxx>
32
33//=======================================================================
34//function : Project
35//purpose : Projection orthogonal d'un point sur une courbe
36// pmn 8/10/98 : On retourne toujours une distance. (BUC60360)
37//=======================================================================
38Standard_Boolean BRepBlend_BlendTool::Project(const gp_Pnt2d& P,
39 const Handle(Adaptor3d_Surface)&,
40 const Handle(Adaptor2d_Curve2d)& C,
41 Standard_Real& Paramproj,
42 Standard_Real& Dist)
43{
44 Paramproj = BRepBlend_HCurve2dTool::FirstParameter(C);
45 gp_Pnt2d P2d;
46 BRepBlend_HCurve2dTool::D0(C, Paramproj, P2d);
47 Dist = P2d.Distance(P);
48
49 const Standard_Real t = BRepBlend_HCurve2dTool::LastParameter(C);
50 BRepBlend_HCurve2dTool::D0(C, t, P2d);
51 if (P2d.Distance(P) < Dist) {
52 Paramproj = t;
53 Dist = P2d.Distance(P);
54 }
55
56 const Standard_Real epsX = 1.e-8;
57 const Standard_Integer Nbu = 20;
58 const Standard_Real Tol = 1.e-5;
59 Extrema_EPCOfExtPC2d extrema(P, *C, Nbu, epsX, Tol);
60 if (!extrema.IsDone())
61 return Standard_True;
62
63 const Standard_Integer Nbext = extrema.NbExt();
64 Standard_Real aDist2 = Dist * Dist;
65 for (Standard_Integer i=1; i<=Nbext; i++) {
66 if (extrema.SquareDistance(i) < aDist2) {
67 aDist2 = extrema.SquareDistance(i);
68 Paramproj = extrema.Point(i).Parameter();
69 }
70 }
71 Dist = sqrt (aDist2);
72
73 return Standard_True;
74}
75
76//=======================================================================
77//function : Inters
78//purpose : Intersection d'un segment avec une courbe
79//=======================================================================
80Standard_Boolean BRepBlend_BlendTool::Inters(const gp_Pnt2d& P1,
81 const gp_Pnt2d& P2,
82 const Handle(Adaptor3d_Surface)&,
83 const Handle(Adaptor2d_Curve2d)& C,
84 Standard_Real& Param,
85 Standard_Real& Dist)
86{
87 const Standard_Real Tol = 1.e-8;
88 const gp_Vec2d v(P1,P2);
89 const Standard_Real mag = v.Magnitude();
90 if(mag < Tol) return Standard_False;
91
92 gp_Dir2d d(v);
93 Handle(Geom2d_Line) bid = new Geom2d_Line(P1,d);
94 Geom2dAdaptor_Curve seg(bid,-0.01*mag,1.01*mag);
95
96 Geom2dInt_GInter inter (seg, *C, Tol, Tol);
97 if (!inter.IsDone())
98 return Standard_False;
99
100 const Standard_Integer Nbint = inter.NbPoints();
101 if (Nbint == 0)
102 return Standard_False;
103
104 IntRes2d_IntersectionPoint ip = inter.Point(1);
105 Param = ip.ParamOnSecond();
106 Dist = P1.Distance(ip.Value());
107 return Standard_True;
108}
109
110Standard_Integer BRepBlend_BlendTool::NbSamplesV
111 (const Handle(Adaptor3d_Surface)&,
112 const Standard_Real,
113 const Standard_Real)
114{
115 return 10;
116}
117
118Standard_Integer BRepBlend_BlendTool::NbSamplesU
119 (const Handle(Adaptor3d_Surface)&,
120 const Standard_Real,
121 const Standard_Real)
122{
123 return 10;
124}
125
126void BRepBlend_BlendTool::Bounds(const Handle(Adaptor2d_Curve2d)& A,
127 Standard_Real& Ufirst,
128 Standard_Real& Ulast)
129{
130 Ufirst = BRepBlend_HCurve2dTool::FirstParameter(A);
131 Ulast = BRepBlend_HCurve2dTool::LastParameter(A);
132}