1 // Created on: 1993-02-05
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
22 #define Tolpetit 1.e-10 // pour dist au carre
26 #include <TColStd_SequenceOfInteger.hxx>
28 static Standard_Boolean FindLine(Contap_TheLine& Line,
29 const TheSurface& Surf,
32 Standard_Real& Paramin,
36 // Standard_Integer i;
39 Standard_Real para,dist;
40 Standard_Real dismin = RealLast();
42 Contap_TheSurfProps::Normale(Surf,Pt2d.X(),Pt2d.Y(),Ptref,Norm);
44 if (Line.TypeContour() == Contap_Lin) {
45 gp_Lin lin(Line.Line());
46 para = ElCLib::Parameter(lin,Ptref);
47 ElCLib::D1(para,lin,pt,tg);
48 dist = pt.Distance(Ptref) + Abs(Norm.Dot(lin.Direction()));
50 else { // Contap__Circle
51 gp_Circ cir(Line.Circle());
52 para = ElCLib::Parameter(cir,Ptref);
53 ElCLib::D1(para,cir,pt,tg);
54 dist = pt.Distance(Ptref)+Abs(Norm.Dot(tg/cir.Radius()));
62 if (ptmin.SquareDistance(Ptref) <= Tolpetit) {
66 return Standard_False;
71 static void PutPointsOnLine (const Contap_TheSearch& solrst,
72 const TheSurface& Surf,
73 Contap_TheSequenceOfLine& slin)
76 Standard_Integer i,l;//,index;
77 Standard_Integer NbPoints = solrst.NbPoints();
79 Standard_Real theparam;
81 IntSurf_Transition TLine,TArc;
82 Standard_Boolean goon;
88 gp_Vec vectg,normale,tgtrst;
89 Standard_Real paramlin;
92 Standard_Integer nbLin = slin.Length();
93 for(l=1;l<=nbLin;l++) {
94 Contap_TheLine& Line=slin.ChangeValue(l);
95 for (i=1; i<= NbPoints; i++) {
97 const Contap_ThePathPointOfTheSearch& PStart = solrst.Point(i);
98 const TheArc& thearc = PStart.Arc();
99 theparam = PStart.Parameter();
101 TheArcTool::D1(thearc,theparam,pt2d,d2d);
102 goon = FindLine(Line,Surf,pt2d,ptonsurf,paramlin,vectg,normale);
104 Contap_ThePoint PPoint;
109 TheSurfaceTool::D1(Surf,pt2d.X(),pt2d.Y(),bidpt,d1u,d1v);
110 PPoint.SetValue(ptonsurf,pt2d.X(),pt2d.Y());
111 if (normale.Magnitude() < RealEpsilon()) {
116 // Petit test qui devrait permettre de bien traiter les pointes
117 // des cones, et les sommets d`une sphere. Il faudrait peut-etre
118 // rajouter une methode dans SurfProps
120 if (Abs(d2d.Y()) <= Precision::Confusion()) {
121 tgtrst = d1v.Crossed(normale);
126 tgtrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
128 IntSurf::MakeTransition(vectg,tgtrst,normale,TLine,TArc);
131 PPoint.SetArc(thearc,theparam, TLine, TArc);
132 PPoint.SetParameter(paramlin);
133 if (!PStart.IsNew()) {
134 PPoint.SetVertex(PStart.Vertex());
143 //----------------------------------------------------------------------------------
144 //-- Orientation des contours Apparents quand ceux-ci sont des lignes ou des cercles
145 //-- On prend un point de la ligne ou du cercle ---> P
146 //-- On projete ce point sur la surface P ---> u,v
147 //-- et on evalue la transition au point u,v
148 //----------------------------------------------------------------------------------
150 IntSurf_TypeTrans ComputeTransitionOngpLine
151 (Contap_TheSurfFunction& SFunc,
154 const TheSurface& Surf=SFunc.Surface();
155 GeomAbs_SurfaceType typS = TheSurfaceTool::GetType(Surf);
158 ElCLib::D1(0.0,L,P,T);
161 case GeomAbs_Cylinder: {
162 ElSLib::Parameters(TheSurfaceTool::Cylinder(Surf),P,u,v);
166 ElSLib::Parameters(TheSurfaceTool::Cone(Surf),P,u,v);
169 case GeomAbs_Sphere: {
170 ElSLib::Parameters(TheSurfaceTool::Sphere(Surf),P,u,v);
176 return(ComputeTransitionOnLine(SFunc,u,v,T));
180 IntSurf_TypeTrans ComputeTransitionOngpCircle
181 (Contap_TheSurfFunction& SFunc,
184 const TheSurface& Surf=SFunc.Surface();
185 GeomAbs_SurfaceType typS = TheSurfaceTool::GetType(Surf);
188 ElCLib::D1(0.0,C,P,T);
191 case GeomAbs_Cylinder: {
192 ElSLib::Parameters(TheSurfaceTool::Cylinder(Surf),P,u,v);
196 ElSLib::Parameters(TheSurfaceTool::Cone(Surf),P,u,v);
199 case GeomAbs_Sphere: {
200 ElSLib::Parameters(TheSurfaceTool::Sphere(Surf),P,u,v);
206 return(ComputeTransitionOnLine(SFunc,u,v,T));
210 void Contap_ContourGen::PerformAna(const Handle(TheTopolTool)& Domain)
213 done = Standard_False;
216 Standard_Real TolArc = 1.e-5;
218 Standard_Integer nbCont, nbPointRst, i;
221 Contap_ContAna contana;
222 Contap_TheLine theline;
223 const TheSurface& Surf = mySFunc.Surface();
224 Contap_TFunction TypeFunc(mySFunc.FunctionType());
225 Standard_Boolean PerformSolRst = Standard_True;
227 GeomAbs_SurfaceType typS = TheSurfaceTool::GetType(Surf);
232 gp_Pln pl(TheSurfaceTool::Plane(Surf));
234 case Contap_ContourStd:
236 gp_Dir Dirpln(pl.Axis().Direction());
237 if (Abs(mySFunc.Direction().Dot(Dirpln)) > Precision::Angular()) {
238 // Aucun point du plan n`est solution, en particulier aucun point
240 PerformSolRst = Standard_False;
244 case Contap_ContourPrs:
246 gp_Pnt Eye(mySFunc.Eye());
247 if (pl.Distance(Eye) > Precision::Confusion()) {
248 // Aucun point du plan n`est solution, en particulier aucun point
250 PerformSolRst = Standard_False;
254 case Contap_DraftStd:
256 gp_Dir Dirpln(pl.Axis().Direction());
257 Standard_Real Sina = Sin(mySFunc.Angle());
258 if (Abs(mySFunc.Direction().Dot(Dirpln)+ Sina) > //voir SurfFunction
259 Precision::Angular()) {
261 PerformSolRst = Standard_False;
265 case Contap_DraftPrs:
276 case Contap_ContourStd:
278 contana.Perform(TheSurfaceTool::Sphere(Surf),mySFunc.Direction());
281 case Contap_ContourPrs:
283 contana.Perform(TheSurfaceTool::Sphere(Surf),mySFunc.Eye());
286 case Contap_DraftStd:
288 contana.Perform(TheSurfaceTool::Sphere(Surf),
289 mySFunc.Direction(),mySFunc.Angle());
292 case Contap_DraftPrs:
300 case GeomAbs_Cylinder:
303 case Contap_ContourStd:
305 contana.Perform(TheSurfaceTool::Cylinder(Surf),mySFunc.Direction());
308 case Contap_ContourPrs:
310 contana.Perform(TheSurfaceTool::Cylinder(Surf),mySFunc.Eye());
313 case Contap_DraftStd:
315 contana.Perform(TheSurfaceTool::Cylinder(Surf),
316 mySFunc.Direction(),mySFunc.Angle());
319 case Contap_DraftPrs:
330 case Contap_ContourStd:
332 contana.Perform(TheSurfaceTool::Cone(Surf),mySFunc.Direction());
335 case Contap_ContourPrs:
337 contana.Perform(TheSurfaceTool::Cone(Surf),mySFunc.Eye());
340 case Contap_DraftStd:
342 contana.Perform(TheSurfaceTool::Cone(Surf),
343 mySFunc.Direction(),mySFunc.Angle());
346 case Contap_DraftPrs:
357 if (typS != GeomAbs_Plane) {
359 if (!contana.IsDone()) {
363 nbCont = contana.NbContours();
365 if (contana.NbContours() == 0) {
366 done = Standard_True;
370 GeomAbs_CurveType typL = contana.TypeContour();
371 if (typL == GeomAbs_Circle) {
372 theline.SetValue(contana.Circle());
373 IntSurf_TypeTrans TransCircle;
374 TransCircle = ComputeTransitionOngpCircle(mySFunc,contana.Circle());
375 theline.SetTransitionOnS(TransCircle);
376 slin.Append(theline);
378 else if (typL == GeomAbs_Line) {
379 for (i=1; i<=nbCont; i++) {
380 theline.SetValue(contana.Line(i));
381 IntSurf_TypeTrans TransLine;
382 TransLine = ComputeTransitionOngpLine(mySFunc,contana.Line(i));
383 theline.SetTransitionOnS(TransLine);
384 slin.Append(theline);
389 if (typS == GeomAbs_Cone) {
391 gp_Cone thecone(TheSurfaceTool::Cone(Surf));
392 ElSLib::Parameters(thecone,thecone.Apex(),u,v);
393 Contap_ThePoint vtxapex(thecone.Apex(),u,v);
394 vtxapex.SetInternal();
395 vtxapex.SetMultiple();
396 for (i=1; i<=nbCont i++) {
397 slin.ChangeValue(i).Add(vtxapex);
406 solrst.Perform(myAFunc,Domain,TolArc,TolArc);
407 if (!solrst.IsDone()) {
410 nbPointRst = solrst.NbPoints();
412 if (nbPointRst != 0) {
413 PutPointsOnLine(solrst,Surf,slin);
416 if (solrst.NbSegments() !=0) {
417 ProcessSegments(solrst,slin,TolArc,mySFunc,Domain);
422 //Standard_Boolean oneremov;
423 Standard_Integer nblinto = slin.Length();
424 TColStd_SequenceOfInteger SeqToDestroy;
426 //-- cout<<" Construct Contour_3 nblin = "<<nblinto<<endl;
427 for(i=1; i<= nblinto ; i++) {
428 //-- cout<<" nbvtx : "<<slin.Value(i).NbVertex()<<endl;
429 //--if(slin.Value(i).NbVertex() > 1) {
430 if(slin.Value(i).TypeContour() != Contap_Restriction) {
431 LineConstructor(slin,Domain,slin.ChangeValue(i),Surf);
432 SeqToDestroy.Append(i);
436 for(i=SeqToDestroy.Length(); i>=1; i--) {
437 slin.Remove(SeqToDestroy.Value(i));
441 done = Standard_True;