0023948: Wrong intersection between a surface of revolution and a plane.
[occt.git] / src / ChFi3d / ChFi3d_Debug.cxx
CommitLineData
b311480e 1// Created on: 1994-09-21
2// Created by: Laurent BOURESCHE
3// Copyright (c) 1994-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
17#include <stdio.h>
18
19#include <TopOpeBRepDS_DataStructure.hxx>
20#include <ChFiDS_SurfData.hxx>
21#include <TopOpeBRepDS_Surface.hxx>
22#include <BRep_Builder.hxx>
23#include <TopoDS_Vertex.hxx>
24#include <TopoDS_Edge.hxx>
25#include <TopoDS_Wire.hxx>
26#include <TopoDS_Face.hxx>
27#include <Geom_Surface.hxx>
28#include <Geom2d_Line.hxx>
29#include <gp_Pnt.hxx>
30#include <gp_Pnt2d.hxx>
31#include <gp_Dir.hxx>
32#include <gp_Dir2d.hxx>
33#include <gp_Vec.hxx>
34#include <gp_Vec2d.hxx>
35#include <gp_Ax1.hxx>
36#include <OSD_Chronometer.hxx>
37
38#ifdef DRAW
39#include <DBRep.hxx>
40#endif
41
42#ifdef DEB
43OSD_Chronometer simul,elspine,chemine;
44#endif
45
46//*********************************
81bba717 47// timing of the simulation
7fd59977 48//*********************************
49
50static Standard_Boolean ChFi3d_traceCHRON = Standard_False;
51void ChFi3d_SettraceCHRON(const Standard_Boolean b)
52{ ChFi3d_traceCHRON = b; }
53Standard_Boolean ChFi3d_GettraceCHRON()
54{ return ChFi3d_traceCHRON; }
55
56//*********************************
81bba717 57// trace a line of path
7fd59977 58//*********************************
59
60static Standard_Boolean ChFi3d_traceDRAWWALK = Standard_False;
61void ChFi3d_SettraceDRAWWALK(const Standard_Boolean b)
62{ ChFi3d_traceDRAWWALK = b; }
63Standard_Boolean ChFi3d_GettraceDRAWWALK()
64{ return ChFi3d_traceDRAWWALK; }
65
66//**********************************
81bba717 67// trace a line of intersection
7fd59977 68//**********************************
69
70static Standard_Boolean ChFi3d_traceDRAWINT = Standard_False;
71void ChFi3d_SettraceDRAWINT(const Standard_Boolean b)
72{ ChFi3d_traceDRAWINT = b; }
73Standard_Boolean ChFi3d_GettraceDRAWINT()
74{ return ChFi3d_traceDRAWINT; }
75
76//*************************************************
81bba717 77// return surfaces of approximated fillets.
7fd59977 78//*************************************************
79
80static Standard_Boolean ChFi3d_traceDRAWFIL = Standard_False;
81void ChFi3d_SettraceDRAWFIL(const Standard_Boolean b)
82{ ChFi3d_traceDRAWFIL = b; }
83Standard_Boolean ChFi3d_GettraceDRAWFIL()
84{ return ChFi3d_traceDRAWFIL; }
85
86
87//*************************************************
81bba717 88// return extended faces for the path.
7fd59977 89//*************************************************
90
91static Standard_Boolean ChFi3d_traceDRAWENLARGE = Standard_False;
92void ChFi3d_SettraceDRAWENLARGE(const Standard_Boolean b)
93{ ChFi3d_traceDRAWENLARGE = b; }
94Standard_Boolean ChFi3d_GettraceDRAWENLARGE()
95{ return ChFi3d_traceDRAWENLARGE; }
96
97//*************************************************
81bba717 98// return the guideline for the triple corners.
7fd59977 99//*************************************************
100
101static Standard_Boolean ChFi3d_traceDRAWSPINE = Standard_False;
102void ChFi3d_SettraceDRAWSPINE(const Standard_Boolean b)
103{ ChFi3d_traceDRAWSPINE = b; }
104Standard_Boolean ChFi3d_GettraceDRAWSPINE()
105{ return ChFi3d_traceDRAWSPINE; }
106
107//*************************************************
81bba717 108// set the type of guideline for the triple corners.
7fd59977 109//*************************************************
110
111void ChFi3d_SetcontextSPINEBEZIER(const Standard_Boolean b);
112void ChFi3d_SetcontextSPINECIRCLE(const Standard_Boolean b);
113void ChFi3d_SetcontextSPINECE(const Standard_Boolean b);
114
115static Standard_Boolean ChFi3d_contextSPINEBEZIER = Standard_False;
116void ChFi3d_SetcontextSPINEBEZIER(const Standard_Boolean b){
117 ChFi3d_contextSPINEBEZIER = b;
118 if(b){
119 ChFi3d_SetcontextSPINECIRCLE(Standard_False);
120 ChFi3d_SetcontextSPINECE(Standard_False);
121 }
122}
123Standard_Boolean ChFi3d_GetcontextSPINEBEZIER()
124{ return ChFi3d_contextSPINEBEZIER; }
125
126static Standard_Boolean ChFi3d_contextSPINECIRCLE = Standard_False;
127void ChFi3d_SetcontextSPINECIRCLE(const Standard_Boolean b){
128 ChFi3d_contextSPINECIRCLE = b;
129 if(b){
130 ChFi3d_SetcontextSPINEBEZIER(Standard_False);
131 ChFi3d_SetcontextSPINECE(Standard_False);
132 }
133}
134Standard_Boolean ChFi3d_GetcontextSPINECIRCLE()
135{ return ChFi3d_contextSPINECIRCLE; }
136
137static Standard_Boolean ChFi3d_contextSPINECE = Standard_False;
138void ChFi3d_SetcontextSPINECE(const Standard_Boolean b){
139 ChFi3d_contextSPINECE = b;
140 if(b){
141 ChFi3d_SetcontextSPINEBEZIER(Standard_False);
142 ChFi3d_SetcontextSPINECIRCLE(Standard_False);
143 }
144}
145Standard_Boolean ChFi3d_GetcontextSPINECE()
146{ return ChFi3d_contextSPINECE; }
147
148//*************************************************
81bba717 149// Forced passage by the path for KPart
7fd59977 150//*************************************************
151static Standard_Boolean ChFi3d_contextFORCEBLEND = Standard_False;
152void ChFi3d_SetcontextFORCEBLEND(const Standard_Boolean b)
153{ ChFi3d_contextFORCEBLEND = b; }
154Standard_Boolean ChFi3d_GetcontextFORCEBLEND()
155{ return ChFi3d_contextFORCEBLEND; }
156
157static Standard_Boolean ChFi3d_contextFORCEFILLING = Standard_False;
158void ChFi3d_SetcontextFORCEFILLING(const Standard_Boolean b)
159{ ChFi3d_contextFORCEFILLING = b; }
160Standard_Boolean ChFi3d_GetcontextFORCEFILLING()
161{ return ChFi3d_contextFORCEFILLING; }
162
163//*************************************************
81bba717 164// No optimization for approx
7fd59977 165//*************************************************
166static Standard_Boolean ChFi3d_contextNOOPT = Standard_False;
167void ChFi3d_SetcontextNOOPT(const Standard_Boolean b)
168{ ChFi3d_contextNOOPT = b; }
169Standard_Boolean ChFi3d_GetcontextNOOPT()
170{ return ChFi3d_contextNOOPT; }
171
172// ***********************************************
81bba717 173// initialization and result of a chrono
7fd59977 174//************************************************
175Standard_EXPORT void ChFi3d_InitChron(OSD_Chronometer& ch)
176{
177 ch.Reset();
178 ch.Start();
179}
180
181Standard_EXPORT void ChFi3d_ResultChron( OSD_Chronometer & ch,
182 Standard_Real & time)
183{
184 Standard_Real tch ;
185 ch.Stop();
186 ch.Show(tch);
187 time=time +tch;
188}
189
190
191//==============================================================
192// function : ChFi3d_CheckSurfData
81bba717 193// purpose : function allows to trace SurfData to check
194// construction of all elements, namely pcurves
7fd59977 195//==============================================================
196#ifdef DRAW
197static Standard_Integer NbSD = 0;
198#endif
199void ChFi3d_CheckSurfData(const TopOpeBRepDS_DataStructure& DStr,
200 const Handle(ChFiDS_SurfData)& Data)
201{
81bba717 202 //trace of the surface defined by the chamfer or the fillet
203 // corresponding to SurfData
7fd59977 204
205 Handle(Geom_Surface) surf = (DStr.Surface( Data->Surf())).Surface();
206 if (!surf.IsNull()){
207 BRep_Builder B;
208 TopoDS_Face F;
209 B.MakeFace(F,surf,0.);
210 TopoDS_Wire W;
211 B.MakeWire(W);
212
213 TopoDS_Vertex V1,V2,V3,V4;
214 B.MakeVertex(V1,Data->VertexFirstOnS1().Point(),0.);
215 B.MakeVertex(V2,Data->VertexLastOnS1().Point(),0.);
216 B.MakeVertex(V3,Data->VertexLastOnS2().Point(),0.);
217 B.MakeVertex(V4,Data->VertexFirstOnS2().Point(),0.);
218
219 TopoDS_Edge E1,E2,E3,E4;
220 B.MakeEdge(E1);
221 B.MakeEdge(E2);
222 B.MakeEdge(E3);
223 B.MakeEdge(E4);
224
225 B.UpdateEdge(E1,Data->InterferenceOnS1().PCurveOnSurf(),F,0.);
226 B.UpdateEdge(E3,Data->InterferenceOnS2().PCurveOnSurf(),F,0.);
227 V1.Orientation(TopAbs_FORWARD);
228 B.Add(E1,V1);
229 B.UpdateVertex(V1,Data->InterferenceOnS1().FirstParameter(),E1,0.);
230 V2.Orientation(TopAbs_REVERSED);
231 B.Add(E1,V2);
232 B.UpdateVertex(V2,Data->InterferenceOnS1().LastParameter(),E1,0.);
233
234
235 V4.Orientation(TopAbs_FORWARD);
236 B.Add(E3,V4);
237 B.UpdateVertex(V4,Data->InterferenceOnS2().FirstParameter(),E3,0.);
238 V3.Orientation(TopAbs_REVERSED);
239 B.Add(E3,V3);
240 B.UpdateVertex(V3,Data->InterferenceOnS2().LastParameter(),E3,0.);
241
242 gp_Pnt2d pp1,pp2,pp3,pp4;
243 pp1 = Data->InterferenceOnS1().PCurveOnSurf()->
244 Value(Data->InterferenceOnS1().FirstParameter());
245 pp2 = Data->InterferenceOnS1().PCurveOnSurf()->
246 Value(Data->InterferenceOnS1().LastParameter());
247 pp3 = Data->InterferenceOnS2().PCurveOnSurf()->
248 Value(Data->InterferenceOnS2().LastParameter());
249 pp4 = Data->InterferenceOnS2().PCurveOnSurf()->
250 Value(Data->InterferenceOnS2().FirstParameter());
251 gp_Dir2d d1(gp_Vec2d(pp1,pp4));
252 gp_Dir2d d2(gp_Vec2d(pp2,pp3));
253 Handle(Geom2d_Line) l1 = new Geom2d_Line(pp1,d1);
254 Handle(Geom2d_Line) l2 = new Geom2d_Line(pp2,d2);
255
256 B.UpdateEdge(E4,l1,F,0.);
257 V1.Orientation(TopAbs_FORWARD);
258 B.Add(E4,V1);
259 B.UpdateVertex(V1,0.,E4,0.);
260 V4.Orientation(TopAbs_REVERSED);
261 B.Add(E4,V4);
262 B.UpdateVertex(V4,pp4.Distance(pp1),E4,0.);
263
264 B.UpdateEdge(E2,l2,F,0.);
265 V2.Orientation(TopAbs_FORWARD);
266 B.Add(E2,V2);
267 B.UpdateVertex(V2,0.,E2,0.);
268 V3.Orientation(TopAbs_REVERSED);
269 B.Add(E2,V3);
270 B.UpdateVertex(V3,pp3.Distance(pp2),E2,0.);
271
272 gp_Pnt pw1,pw2,ppp;
273 ppp = surf->Value(pp1.X(),pp1.Y());
274 pw1 = surf->Value(0.9*pp1.X()+0.1*pp2.X(),0.9*pp1.Y()+0.1*pp2.Y());
275 pw2 = surf->Value(0.9*pp1.X()+0.1*pp4.X(),0.9*pp1.Y()+0.1*pp4.Y());
276 gp_Vec vv1(ppp,pw1);
277 gp_Vec vv2(ppp,pw2);
278 gp_Vec Vwire = vv1^vv2;
279
280 surf->D1(pp1.X(),pp1.Y(),pw1,vv1,vv2);
281 gp_Vec Vsurf = vv1^vv2;
282 Standard_Boolean rev = Vsurf.Dot(Vwire)<=0.;
283
284 E1.Orientation(TopAbs_FORWARD);
285 E2.Orientation(TopAbs_FORWARD);
286 E3.Orientation(TopAbs_REVERSED);
287 E4.Orientation(TopAbs_REVERSED);
288 if(rev){
289 E1.Orientation(TopAbs_REVERSED);
290 E2.Orientation(TopAbs_REVERSED);
291 E3.Orientation(TopAbs_FORWARD);
292 E4.Orientation(TopAbs_FORWARD);
293 }
294 B.Add(W,E1);
295 B.Add(W,E2);
296 B.Add(W,E3);
297 B.Add(W,E4);
298
299 W.Orientation(TopAbs_FORWARD);
300 B.Add(F,W);
301
302#ifdef DRAW
303// char name[100];
304 char* name = new char[100];
305 sprintf(name,"fillet_%d",NbSD++);
306 DBRep::Set(name,F);
307#endif
308 }
309}