0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / HLRBRep / HLRBRep_EdgeFaceTool.cxx
CommitLineData
b311480e 1// Created on: 1993-10-18
2// Created by: Christophe MARION
3// Copyright (c) 1993-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
7fd59977 18#include <BRep_Tool.hxx>
19#include <BRepAdaptor_Curve2d.hxx>
42cf5bc1 20#include <BRepExtrema_ExtPF.hxx>
21#include <BRepLib_MakeVertex.hxx>
7fd59977 22#include <gp.hxx>
42cf5bc1 23#include <gp_Dir.hxx>
24#include <HLRBRep_Curve.hxx>
25#include <HLRBRep_EdgeFaceTool.hxx>
26#include <HLRBRep_Surface.hxx>
27#include <TopoDS_Vertex.hxx>
7fd59977 28
29//=======================================================================
30//function : CurvatureDirection
31//purpose :
32//=======================================================================
733a0e55
S
33Standard_Real HLRBRep_EdgeFaceTool::CurvatureValue
34 (const Standard_Address F,
35 const Standard_Real U,
36 const Standard_Real V,
37 const gp_Dir& Tg)
7fd59977 38{
39 gp_Pnt P;
40 gp_Vec D1U,D1V,D2U,D2V,D2UV;
41 ((HLRBRep_Surface*)F)->D2(U,V,P,D1U,D1V,D2U,D2V,D2UV);
42 Standard_Real d1ut = D1U*Tg;
43 Standard_Real d1vt = D1V*Tg;
44 Standard_Real d1ud1v = D1U*D1V;
45 Standard_Real nmu2 = D1U*D1U;
46 Standard_Real nmv2 = D1V*D1V;
47 Standard_Real det = nmu2 * nmv2 - d1ud1v * d1ud1v;
48 Standard_Real alfa = ( d1ut * nmv2 - d1vt * d1ud1v ) / det;
49 Standard_Real beta = ( d1vt * nmu2 - d1ut * d1ud1v ) / det;
50 gp_Vec Nm = D1U ^ D1V;
51 if (Nm.Magnitude() > gp::Resolution()) {
52 Nm.Normalize();
53 Standard_Real alfa2 = alfa*alfa;
54 Standard_Real beta2 = beta*beta;
55 Standard_Real alfabeta = alfa*beta;
56 Standard_Real N = (Nm*D2U)*alfa2 + 2*(Nm*D2UV)*alfabeta + (Nm*D2V)*beta2;
57 Standard_Real D = nmu2 *alfa2 + 2*d1ud1v *alfabeta + nmv2 *beta2;
58 return N/D;
59 }
733a0e55 60 return 0.;
7fd59977 61}
62
63//=======================================================================
64//function : UVPoint
65//purpose :
66//=======================================================================
67
733a0e55
S
68Standard_Boolean HLRBRep_EdgeFaceTool::UVPoint(const Standard_Real Par,
69 const Standard_Address E,
70 const Standard_Address F,
71 Standard_Real& U,
72 Standard_Real& V)
7fd59977 73{
74 Standard_Real pfbid,plbid;
7fd59977 75 if (BRep_Tool::CurveOnSurface
76 (((HLRBRep_Curve *)E)->Curve().Edge(),
733a0e55
S
77 ((HLRBRep_Surface*)F)->Surface().Face(),pfbid,plbid).IsNull())
78 {
7fd59977 79 BRepExtrema_ExtPF proj
80 (BRepLib_MakeVertex(((HLRBRep_Curve*)E)->Value3D(Par)),
81 ((HLRBRep_Surface*)F)->Surface().Face());
733a0e55 82 Standard_Integer i, index = 0;
7fd59977 83 Standard_Real dist2 = RealLast();
733a0e55
S
84 const Standard_Integer n = proj.NbExt();
85 for (i = 1; i <= n; i++) {
86 const Standard_Real newdist2 = proj.SquareDistance(i);
7fd59977 87 if (newdist2 < dist2) {
733a0e55
S
88 dist2 = newdist2;
89 index = i;
7fd59977 90 }
91 }
733a0e55
S
92 if (index == 0)
93 return Standard_False;
94
95 proj.Parameter(index,U,V);
7fd59977 96 }
97 else {
98 BRepAdaptor_Curve2d PC
99 (((HLRBRep_Curve *)E)->Curve().Edge(),
100 ((HLRBRep_Surface*)F)->Surface().Face());
101 gp_Pnt2d P2d;
102 PC.D0(Par,P2d);
103 U = P2d.X();
104 V = P2d.Y();
105 }
733a0e55 106 return Standard_True;
7fd59977 107}