summaryrefslogtreecommitdiff
path: root/src/TopOpeBRepTool/TopOpeBRepTool_matter.cxx
blob: 30f9d1f694fc351c83820aff19fd98db24738805 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// File:	TopOpeBRepTool_matter.cxx
// Created:	Fri Nov 20 10:35:10 1998
// Author:	Xuan PHAM PHU
//		<xpu@poulopox.paris1.matra-dtv.fr>


#include <gp_Dir.hxx>
#include <gp_Dir2d.hxx>
#include <gp_Vec.hxx>
#include <gp_Pnt2d.hxx>
#include <BRep_Tool.hxx>
#include <TopOpeBRepTool_define.hxx>
#include <TopOpeBRepTool_EXPORT.hxx>
#include <TopOpeBRepTool_TOOL.hxx>

#define  M_FORWARD(ori) (ori == TopAbs_FORWARD) 
#define M_REVERSED(ori) (ori == TopAbs_REVERSED) 
#define M_INTERNAL(ori) (ori == TopAbs_INTERNAL) 
#define M_EXTERNAL(ori) (ori == TopAbs_EXTERNAL) 

// ----------------------------------------------------------------------
// oriented vectors :
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
Standard_EXPORT gp_Dir FUN_tool_nCinsideS(const gp_Dir& tgC,const gp_Dir& ngS)
{
  // Give us a curve C on suface S,<parOnC>,a parameter
  // Purpose : compute normal vector to C,tangent to S at
  //           given point,oriented INSIDE S  
  // <tgC> : geometric tangent at point of <parOnC>
  // <ngS> : geometric normal at point of <parOnC> 
  gp_Dir XX(ngS^tgC);
  return XX;  
}
// ----------------------------------------------------------------------
Standard_EXPORT gp_Dir2d FUN_tool_nC2dINSIDES(const gp_Dir2d& tgC2d)
{
  // ------------------------------------------------------------
  // Give us an edge E of 2d rep. on a face F C2d.
  // E is oriented FORWARD in F,then the matter described by
  // the restriction of E on the surface of F is on the left.
  // Give us UV on S,<ngS> is the normal to S at point given by UV
  //                  <tgC2d> is the tangent to C2d at point UV,
  // (X,Y,Z) describes a RONd with :
  // X = (tgC2d,0),Y = (xx,0),Z =(0,0,1)
  // ------------------------------------------------------------
  gp_Dir X,Y,Z;
  Z = gp_Dir(0.,0.,1.);
  X = gp_Dir(tgC2d.X(),tgC2d.Y(),0.);
  Y = Z^X;
  gp_Dir2d xx(Y.X(),Y.Y());
  return xx;
}

// ----------------------------------------------------------------------
//Standard_EXPORT gp_Vec FUN_tool_getgeomxx(const TopoDS_Face& Fi,
Standard_EXPORT gp_Vec FUN_tool_getgeomxx(const TopoDS_Face& ,
                                          const TopoDS_Edge& Ei,
					  const Standard_Real parEi,
                                          const gp_Dir& ngFi)
{
  // <Ei> is an edge of <Fi>,
  // computing XX a vector normal to <ngFi>,
  // oriented IN the face <Fi>.
  // (<ngFi> normal geometric to <Fi> at point of parameter
  // <parEi> on edge <Ei>)
  // <XX> is oriented inside 2d <F> if <E> is FORWARD in <F>
  
  gp_Vec tgEi; Standard_Boolean ok = TopOpeBRepTool_TOOL::TggeomE(parEi,Ei,tgEi);  
  if (!ok) return gp_Vec(0.,0.,0.); //NYIRAISE
  gp_Dir XX = FUN_tool_nCinsideS(tgEi,ngFi);
  return XX;
}

// ----------------------------------------------------------------------
Standard_EXPORT gp_Vec FUN_tool_getgeomxx(const TopoDS_Face& Fi,const TopoDS_Edge& Ei,
					  const Standard_Real parOnEi)
{
  gp_Vec xx(1.,0.,0.);
  gp_Pnt2d uvi; Standard_Boolean ok = FUN_tool_paronEF(Ei,parOnEi,Fi,uvi);
  if (!ok) return xx; // nyiRaise
  gp_Vec ngFi = FUN_tool_nggeomF(uvi,Fi);
  xx = FUN_tool_getgeomxx(Fi,Ei,parOnEi,ngFi);
  return xx;
}

// ----------------------------------------------------------------------
Standard_EXPORT Standard_Boolean FUN_tool_getxx(const TopoDS_Face& Fi,const TopoDS_Edge& Ei,
				   const Standard_Real parEi,const gp_Dir& ngFi,
				   gp_Dir& XX)
{
  gp_Vec xx = FUN_tool_getgeomxx(Fi,Ei,parEi,ngFi);
  if (xx.Magnitude() < gp::Resolution()) return Standard_False;
  XX = gp_Dir(xx);
  TopAbs_Orientation oriEinF; Standard_Boolean ok = FUN_tool_orientEinFFORWARD(Ei,Fi,oriEinF);
  if (!ok) return Standard_False;
  if (M_REVERSED(oriEinF)) XX.Reverse();
  return Standard_True;
}

// ----------------------------------------------------------------------
Standard_EXPORT Standard_Boolean FUN_tool_getxx(const TopoDS_Face& Fi,const TopoDS_Edge& Ei, const Standard_Real parEi,
				   gp_Dir& XX)
{ 
  Standard_Real tolFi = BRep_Tool::Tolerance(Fi)*1.e2; // nyitol
  gp_Pnt2d uv; Standard_Boolean ok = FUN_tool_parF(Ei,parEi,Fi,uv,tolFi);
  if (!ok) return Standard_False;
  gp_Vec ng = FUN_tool_nggeomF(uv,Fi);
  ok = FUN_tool_getxx(Fi,Ei,parEi,ng,XX); 
  return ok;
}

// ----------------------------------------------------------------------
Standard_EXPORT Standard_Boolean FUN_tool_getdxx(const TopoDS_Face& F,
                                                 const TopoDS_Edge& E,
//                                                 const Standard_Real parE,
                                                 const Standard_Real ,
				                 gp_Vec2d& dxx)
// E xiso (x=u,v)
// points between uvparE and uvparE+dxx are IN F2d
{  
  dxx = gp_Vec2d(0.,0.);
  TopAbs_Orientation oEinFF; Standard_Boolean ok = FUN_tool_orientEinFFORWARD(E,F,oEinFF);
  if (!ok) return Standard_False;
  if (M_INTERNAL(oEinFF) || M_EXTERNAL(oEinFF)) return Standard_False;

  Standard_Boolean isoU,isoV; gp_Dir2d d2d; gp_Pnt2d o2d;
  Standard_Boolean iso = TopOpeBRepTool_TOOL::UVISO(E,F,isoU,isoV,d2d,o2d);
  if (!iso) return Standard_False;
  Standard_Real u1,u2,v1,v2; ok = FUN_tool_isobounds(F,u1,u2,v1,v2);
  if (!ok) return Standard_False;

  Standard_Real xpar = isoU ? o2d.X() : o2d.Y();
  Standard_Real xinf = isoU ? u1 : v1;
  Standard_Real xsup = isoU ? u2 : v2;

  ok = ::FUN_nearestISO(F,xpar,isoU,xinf,xsup);
  if (!ok) return Standard_False;

  Standard_Real ypar = isoU? d2d.Y() : d2d.X();
  Standard_Boolean matterAFTERxpar = Standard_False;
  if (isoU) matterAFTERxpar = (ypar < 0.);
  if (isoV) matterAFTERxpar = (ypar > 0.);
  if (oEinFF == TopAbs_REVERSED) matterAFTERxpar = !matterAFTERxpar;

  Standard_Real dx = 0.;
  if (matterAFTERxpar) dx = xsup-xpar;
  else                 dx = xinf-xpar;

  if (isoU) dxx = gp_Vec2d(dx,0.);
  if (isoV) dxx = gp_Vec2d(0.,dx);
  return Standard_True;
}