2 // Created: Tue Dec 21 16:19:36 1993
3 // Author: Isabelle GRIGNON
8 #include <ChFi3d_Builder_0.hxx>
9 #include <BRepAdaptor_Surface.hxx>
10 #include <BRepAdaptor_Curve2d.hxx>
11 #include <BRepAdaptor_Curve.hxx>
12 #include <BRep_Tool.hxx>
16 #include <gp_Pnt2d.hxx>
17 #include <gp_Vec2d.hxx>
18 #include <Precision.hxx>
19 #include <TopExp_Explorer.hxx>
23 //=======================================================================
24 //function : ConcaveSide
25 //purpose : calcule le cote concave au voisinage de la frontiere
27 //=======================================================================
29 Standard_Integer ChFi3d::ConcaveSide(const BRepAdaptor_Surface& S1,
30 const BRepAdaptor_Surface& S2,
32 TopAbs_Orientation& Or1,
33 TopAbs_Orientation& Or2)
36 Standard_Integer ChoixConge;
37 Or1 = Or2 = TopAbs_FORWARD;
38 BRepAdaptor_Curve CE(E);
39 Standard_Real first = CE.FirstParameter();
40 Standard_Real last = CE.LastParameter();
41 Standard_Real par = 0.691254*first + 0.308746*last;
43 gp_Pnt pt, pt1, pt2; gp_Vec tgE, tgE1, tgE2, ns1, ns2, dint1, dint2;
44 TopoDS_Face F1 = S1.Face();
45 TopoDS_Face F2 = S2.Face();
46 F1.Orientation(TopAbs_FORWARD);
47 F2.Orientation(TopAbs_FORWARD);
52 if(E.Orientation() == TopAbs_REVERSED) tgE.Reverse();
54 TopoDS_Edge E1 = E, E2 = E;
55 E1.Orientation(TopAbs_FORWARD);
56 E2.Orientation(TopAbs_FORWARD);
58 if(F1.IsSame(F2) && BRep_Tool::IsClosed(E,F1)) {
59 E2.Orientation(TopAbs_REVERSED);
64 Standard_Boolean found = 0;
65 for (Exp.Init(F1,TopAbs_EDGE);
68 if (E.IsSame(TopoDS::Edge(Exp.Current()))){
69 if(Exp.Current().Orientation() == TopAbs_REVERSED) tgE1.Reverse();
70 found = Standard_True;
73 if (!found) { return 0; }
75 for (Exp.Init(F2,TopAbs_EDGE);
78 if (E.IsSame(TopoDS::Edge(Exp.Current()))){
79 if(Exp.Current().Orientation() == TopAbs_REVERSED) tgE2.Reverse();
80 found = Standard_True;
83 if (!found) { return 0; }
85 BRepAdaptor_Curve2d pc1(E1,F1);
86 BRepAdaptor_Curve2d pc2(E2,F2);
88 gp_Vec DU1,DV1,DU2,DV2;
89 p2d1 = pc1.Value(par);
90 p2d2 = pc2.Value(par);
91 S1.D1(p2d1.X(),p2d1.Y(),pt1,DU1,DV1);
92 ns1 = DU1.Crossed(DV1);
94 S2.D1(p2d2.X(),p2d2.Y(),pt2,DU2,DV2);
95 ns2 = DU2.Crossed(DV2);
98 dint1 = ns1.Crossed(tgE1);
99 dint2 = ns2.Crossed(tgE2);
100 Standard_Real ang = ns1.CrossMagnitude(ns2);
102 Standard_Real scal = ns2.Dot(dint1);
105 Or2 = TopAbs_REVERSED;
107 scal = ns1.Dot(dint2);
110 Or1 = TopAbs_REVERSED;
114 //les faces sont localement tangentes on bidouille!!
115 if(dint1.Dot(dint2) < 0.){
116 //ici c'est une regularite oubliee
117 gp_Vec DDU, DDV, DDUV;
118 S1.D2(p2d1.X(),p2d1.Y(),pt1,DU1,DV1,DDU,DDV,DDUV);
119 DU1 += ( DU1 * dint1 < 0) ? -DDU : DDU;
120 DV1 += ( DV1 * dint1 < 0) ? -DDV : DDV;
121 ns1 = DU1.Crossed(DV1);
123 S2.D2(p2d2.X(),p2d2.Y(),pt2,DU2,DV2,DDU,DDV,DDUV);
124 DU2 += ( DU2 * dint2 < 0) ? -DDU : DDU;
125 DV2 += ( DV2 * dint2 < 0) ? -DDV : DDV;
126 ns2 = DU2.Crossed(DV2);
129 dint1 = ns1.Crossed(tgE1);
130 dint2 = ns2.Crossed(tgE2);
131 ang = ns1.CrossMagnitude(ns2);
133 Standard_Real scal = ns2.Dot(dint1);
136 Or2 = TopAbs_REVERSED;
138 scal = ns1.Dot(dint2);
141 Or1 = TopAbs_REVERSED;
146 cout<<"ConcaveSide : pas de cote concave"<<endl;
148 //ce 10 montre que la face en bout est dans le prolongement de l'une des deux faces d'appui
153 //ici ca rebrousse, on prend des points dans les faces
154 //ni trop pres ni trop loin, comme on peut.
157 // Standard_Real deport = 1000*BRep_Tool::Tolerance(E);
159 ChFi3d_Coefficient(dint1,DU1,DV1,u,v);
160 p2d1.SetX(p2d1.X() + u); p2d1.SetY(p2d1.Y() + v);
161 ChFi3d_Coefficient(dint1,DU2,DV2,u,v);
162 p2d2.SetX(p2d2.X() + u); p2d2.SetY(p2d2.Y() + v);
163 S1.D1(p2d1.X(),p2d1.Y(),pt1,DU1,DV1);
164 ns1 = DU1.Crossed(DV1);
165 S2.D1(p2d2.X(),p2d2.Y(),pt2,DU2,DV2);
166 ns2 = DU2.Crossed(DV2);
167 gp_Vec vref(pt1,pt2);
168 if(ns1.Dot(vref) < 0.){
169 Or1 = TopAbs_REVERSED;
171 if(ns2.Dot(vref) > 0.){
172 Or2 = TopAbs_REVERSED;
178 if (Or1 == TopAbs_FORWARD) {
179 if (Or2 == TopAbs_FORWARD) ChoixConge = 1;
183 if (Or2 == TopAbs_FORWARD) ChoixConge = 3;
186 if ((ns1.Crossed(ns2)).Dot(tgE) >= 0.) ChoixConge++ ;
190 //=======================================================================
191 //function : NextSide
194 //=======================================================================
196 Standard_Integer ChFi3d::NextSide(TopAbs_Orientation& Or1,
197 TopAbs_Orientation& Or2,
198 const TopAbs_Orientation OrSave1,
199 const TopAbs_Orientation OrSave2,
200 const Standard_Integer ChoixSave)
202 if (Or1 == TopAbs_FORWARD){Or1 = OrSave1;}
204 Or1 = TopAbs::Reverse(OrSave1);
206 if (Or2 == TopAbs_FORWARD){Or2 = OrSave2;}
208 Or2 = TopAbs::Reverse(OrSave2);
211 Standard_Integer ChoixConge;
212 if (Or1 == TopAbs_FORWARD) {
213 if (Or2 == TopAbs_FORWARD) ChoixConge = 1;
215 if(ChoixSave < 0) ChoixConge = 3;
220 if (Or2 == TopAbs_FORWARD) {
221 if(ChoixSave < 0) ChoixConge = 7;
226 if (Abs(ChoixSave)%2 == 0) ChoixConge++;
231 //=======================================================================
232 //function : NextSide
235 //=======================================================================
237 void ChFi3d::NextSide(TopAbs_Orientation& Or,
238 const TopAbs_Orientation OrSave,
239 const TopAbs_Orientation OrFace)
241 if (Or == OrFace){Or = OrSave;}
243 Or = TopAbs::Reverse(OrSave);
249 //=======================================================================
250 //function : SameSide
253 //=======================================================================
255 Standard_Boolean ChFi3d::SameSide(const TopAbs_Orientation Or,
256 const TopAbs_Orientation OrSave1,
257 const TopAbs_Orientation OrSave2,
258 const TopAbs_Orientation OrFace1,
259 const TopAbs_Orientation OrFace2)
261 TopAbs_Orientation o1,o2;
262 if (Or == OrFace1){o1 = OrSave1;}
264 o1 = TopAbs::Reverse(OrSave1);
266 if (Or == OrFace2){o2 = OrSave2;}
268 o2 = TopAbs::Reverse(OrSave2);