0024157: Parallelization of assembly part of BO
[occt.git] / src / TopOpeBRepTool / TopOpeBRepTool_matter.cxx
1 // Created on: 1998-11-20
2 // Created by: Xuan PHAM PHU
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 #include <gp_Dir.hxx>
24 #include <gp_Dir2d.hxx>
25 #include <gp_Vec.hxx>
26 #include <gp_Pnt2d.hxx>
27 #include <BRep_Tool.hxx>
28 #include <TopOpeBRepTool_define.hxx>
29 #include <TopOpeBRepTool_EXPORT.hxx>
30 #include <TopOpeBRepTool_TOOL.hxx>
31
32 #define  M_FORWARD(ori) (ori == TopAbs_FORWARD) 
33 #define M_REVERSED(ori) (ori == TopAbs_REVERSED) 
34 #define M_INTERNAL(ori) (ori == TopAbs_INTERNAL) 
35 #define M_EXTERNAL(ori) (ori == TopAbs_EXTERNAL) 
36
37 // ----------------------------------------------------------------------
38 // oriented vectors :
39 // ----------------------------------------------------------------------
40
41 // ----------------------------------------------------------------------
42 Standard_EXPORT gp_Dir FUN_tool_nCinsideS(const gp_Dir& tgC,const gp_Dir& ngS)
43 {
44   // Give us a curve C on suface S,<parOnC>,a parameter
45   // Purpose : compute normal vector to C,tangent to S at
46   //           given point,oriented INSIDE S  
47   // <tgC> : geometric tangent at point of <parOnC>
48   // <ngS> : geometric normal at point of <parOnC> 
49   gp_Dir XX(ngS^tgC);
50   return XX;  
51 }
52 // ----------------------------------------------------------------------
53 Standard_EXPORT gp_Dir2d FUN_tool_nC2dINSIDES(const gp_Dir2d& tgC2d)
54 {
55   // ------------------------------------------------------------
56   // Give us an edge E of 2d rep. on a face F C2d.
57   // E is oriented FORWARD in F,then the matter described by
58   // the restriction of E on the surface of F is on the left.
59   // Give us UV on S,<ngS> is the normal to S at point given by UV
60   //                  <tgC2d> is the tangent to C2d at point UV,
61   // (X,Y,Z) describes a RONd with :
62   // X = (tgC2d,0),Y = (xx,0),Z =(0,0,1)
63   // ------------------------------------------------------------
64   gp_Dir X,Y,Z;
65   Z = gp_Dir(0.,0.,1.);
66   X = gp_Dir(tgC2d.X(),tgC2d.Y(),0.);
67   Y = Z^X;
68   gp_Dir2d xx(Y.X(),Y.Y());
69   return xx;
70 }
71
72 // ----------------------------------------------------------------------
73 //Standard_EXPORT gp_Vec FUN_tool_getgeomxx(const TopoDS_Face& Fi,
74 Standard_EXPORT gp_Vec FUN_tool_getgeomxx(const TopoDS_Face& ,
75                                           const TopoDS_Edge& Ei,
76                                           const Standard_Real parEi,
77                                           const gp_Dir& ngFi)
78 {
79   // <Ei> is an edge of <Fi>,
80   // computing XX a vector normal to <ngFi>,
81   // oriented IN the face <Fi>.
82   // (<ngFi> normal geometric to <Fi> at point of parameter
83   // <parEi> on edge <Ei>)
84   // <XX> is oriented inside 2d <F> if <E> is FORWARD in <F>
85   
86   gp_Vec tgEi; Standard_Boolean ok = TopOpeBRepTool_TOOL::TggeomE(parEi,Ei,tgEi);  
87   if (!ok) return gp_Vec(0.,0.,0.); //NYIRAISE
88   gp_Dir XX = FUN_tool_nCinsideS(tgEi,ngFi);
89   return XX;
90 }
91
92 // ----------------------------------------------------------------------
93 Standard_EXPORT gp_Vec FUN_tool_getgeomxx(const TopoDS_Face& Fi,const TopoDS_Edge& Ei,
94                                           const Standard_Real parOnEi)
95 {
96   gp_Vec xx(1.,0.,0.);
97   gp_Pnt2d uvi; Standard_Boolean ok = FUN_tool_paronEF(Ei,parOnEi,Fi,uvi);
98   if (!ok) return xx; // nyiRaise
99   gp_Vec ngFi = FUN_tool_nggeomF(uvi,Fi);
100   xx = FUN_tool_getgeomxx(Fi,Ei,parOnEi,ngFi);
101   return xx;
102 }
103
104 // ----------------------------------------------------------------------
105 Standard_EXPORT Standard_Boolean FUN_tool_getxx(const TopoDS_Face& Fi,const TopoDS_Edge& Ei,
106                                    const Standard_Real parEi,const gp_Dir& ngFi,
107                                    gp_Dir& XX)
108 {
109   gp_Vec xx = FUN_tool_getgeomxx(Fi,Ei,parEi,ngFi);
110   if (xx.Magnitude() < gp::Resolution()) return Standard_False;
111   XX = gp_Dir(xx);
112   TopAbs_Orientation oriEinF; Standard_Boolean ok = FUN_tool_orientEinFFORWARD(Ei,Fi,oriEinF);
113   if (!ok) return Standard_False;
114   if (M_REVERSED(oriEinF)) XX.Reverse();
115   return Standard_True;
116 }
117
118 // ----------------------------------------------------------------------
119 Standard_EXPORT Standard_Boolean FUN_tool_getxx(const TopoDS_Face& Fi,const TopoDS_Edge& Ei, const Standard_Real parEi,
120                                    gp_Dir& XX)
121
122   Standard_Real tolFi = BRep_Tool::Tolerance(Fi)*1.e2; // nyitol
123   gp_Pnt2d uv; Standard_Boolean ok = FUN_tool_parF(Ei,parEi,Fi,uv,tolFi);
124   if (!ok) return Standard_False;
125   gp_Vec ng = FUN_tool_nggeomF(uv,Fi);
126   ok = FUN_tool_getxx(Fi,Ei,parEi,ng,XX); 
127   return ok;
128 }
129
130 // ----------------------------------------------------------------------
131 Standard_EXPORT Standard_Boolean FUN_tool_getdxx(const TopoDS_Face& F,
132                                                  const TopoDS_Edge& E,
133 //                                                 const Standard_Real parE,
134                                                  const Standard_Real ,
135                                                  gp_Vec2d& dxx)
136 // E xiso (x=u,v)
137 // points between uvparE and uvparE+dxx are IN F2d
138 {  
139   dxx = gp_Vec2d(0.,0.);
140   TopAbs_Orientation oEinFF; Standard_Boolean ok = FUN_tool_orientEinFFORWARD(E,F,oEinFF);
141   if (!ok) return Standard_False;
142   if (M_INTERNAL(oEinFF) || M_EXTERNAL(oEinFF)) return Standard_False;
143
144   Standard_Boolean isoU,isoV; gp_Dir2d d2d; gp_Pnt2d o2d;
145   Standard_Boolean iso = TopOpeBRepTool_TOOL::UVISO(E,F,isoU,isoV,d2d,o2d);
146   if (!iso) return Standard_False;
147   Standard_Real u1,u2,v1,v2; ok = FUN_tool_isobounds(F,u1,u2,v1,v2);
148   if (!ok) return Standard_False;
149
150   Standard_Real xpar = isoU ? o2d.X() : o2d.Y();
151   Standard_Real xinf = isoU ? u1 : v1;
152   Standard_Real xsup = isoU ? u2 : v2;
153
154   ok = ::FUN_nearestISO(F,xpar,isoU,xinf,xsup);
155   if (!ok) return Standard_False;
156
157   Standard_Real ypar = isoU? d2d.Y() : d2d.X();
158   Standard_Boolean matterAFTERxpar = Standard_False;
159   if (isoU) matterAFTERxpar = (ypar < 0.);
160   if (isoV) matterAFTERxpar = (ypar > 0.);
161   if (oEinFF == TopAbs_REVERSED) matterAFTERxpar = !matterAFTERxpar;
162
163   Standard_Real dx = 0.;
164   if (matterAFTERxpar) dx = xsup-xpar;
165   else                 dx = xinf-xpar;
166
167   if (isoU) dxx = gp_Vec2d(dx,0.);
168   if (isoV) dxx = gp_Vec2d(0.,dx);
169   return Standard_True;
170 }
171