0024002: Overall code and build procedure refactoring -- automatic
[occt.git] / src / BRepClass3d / BRepClass3d_Intersector3d.cxx
CommitLineData
b311480e 1// Created on: 1994-04-01
2// Created by: Laurent BUCHARD
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.
b311480e 16
7fd59977 17
7fd59977 18#include <BRepAdaptor_HSurface.hxx>
42cf5bc1 19#include <BRepClass3d_Intersector3d.hxx>
7fd59977 20#include <BRepClass_FaceClassifier.hxx>
42cf5bc1 21#include <Geom_Line.hxx>
7fd59977 22#include <GeomAdaptor_Curve.hxx>
7fd59977 23#include <GeomAdaptor_HCurve.hxx>
42cf5bc1 24#include <gp_Lin.hxx>
25#include <gp_Pnt.hxx>
26#include <gp_Pnt2d.hxx>
27#include <IntCurveSurface_HInter.hxx>
28#include <IntCurveSurface_IntersectionPoint.hxx>
29#include <TopAbs.hxx>
30#include <TopoDS_Face.hxx>
7fd59977 31
32//============================================================================
33BRepClass3d_Intersector3d::BRepClass3d_Intersector3d()
34 : done(Standard_False),hasapoint(Standard_False)
35{
36}
37//============================================================================
38void BRepClass3d_Intersector3d::Perform(const gp_Lin& L,
39 const Standard_Real /*Prm*/,
40 const Standard_Real Tol,
41 const TopoDS_Face& Face) {
42
41194117
K
43 IntCurveSurface_HInter HICS;
44 BRepAdaptor_Surface surface;
45 BRepClass_FaceClassifier classifier2d;
7fd59977 46
47 Handle(Geom_Line) geomline = new Geom_Line(L);
48 GeomAdaptor_Curve LL(geomline);
49
50 surface.Initialize(Face,Standard_True);
51
773f53f1 52 const Standard_Boolean IsUPer = surface.IsUPeriodic();
53 const Standard_Boolean IsVPer = surface.IsVPeriodic();
54 const Standard_Real uperiod = IsUPer ? surface.UPeriod() : 0.0;
55 const Standard_Real vperiod = IsVPer ? surface.VPeriod() : 0.0;
56
57 Standard_Real U1 = surface.FirstUParameter();
58 Standard_Real U2 = surface.LastUParameter();
59 Standard_Real V1 = surface.FirstVParameter();
60 Standard_Real V2 = surface.LastVParameter();
7fd59977 61
62 //--
63 Handle(GeomAdaptor_HCurve) HLL = new GeomAdaptor_HCurve(LL);
64 Handle(BRepAdaptor_HSurface) Hsurface = new BRepAdaptor_HSurface(surface);
65 //--
66 HICS.Perform(HLL,Hsurface);
67
68 W=RealLast();
69 if(HICS.IsDone()) {
70 for(Standard_Integer index=HICS.NbPoints(); index>=1; index--) {
71 gp_Pnt2d Puv(HICS.Point(index).U(),HICS.Point(index).V());
72
73 Standard_Integer N1 = 0;
74 Standard_Integer N2 = 0;
75
76 Standard_Real X = Puv.X();
77 Standard_Real Y = Puv.Y();
78
79 if(IsUPer) {
80 if(X > U2) {
81 N1 = RealToInt( (X - U1) / uperiod );
82 }
83 if(X < U1) {
84 N1 = RealToInt( (X - U2) / uperiod );
85 }
86 Puv.SetX(X - uperiod * N1);
87 }
88
89 if(IsVPer) {
90 if(Y > V2) {
91 N2 = RealToInt ( (Y - V1) / vperiod );
92 }
93 if(Y < V1) {
94 N2 = RealToInt ( (Y - V2) / vperiod );
95 }
96 Puv.SetY(Y - vperiod * N2);
97 }
98
99 classifier2d.Perform(Face,Puv,Tol);
100 TopAbs_State currentstate = classifier2d.State();
101 if(currentstate==TopAbs_IN || currentstate==TopAbs_ON) {
102 const IntCurveSurface_IntersectionPoint& HICSPoint = HICS.Point(index);
103 Standard_Real HICSW = HICSPoint.W();
104// Modified by skv - Fri Mar 4 12:07:34 2005 OCC7966 Begin
105 if((W > HICSW) && (HICSW>-Tol)) {
106// if(W > HICSW) {
107// Modified by skv - Fri Mar 4 12:07:34 2005 OCC7966 End
108 hasapoint = Standard_True;
109 U = HICSPoint.U();
110 V = HICSPoint.V();
111 W = HICSW;
112 transition = HICSPoint.Transition();
113 pnt = HICSPoint.Pnt();
114 state = currentstate;
115 face = Face;
116 if(Face.Orientation()==TopAbs_REVERSED) {
117 if(transition == IntCurveSurface_In)
118 transition = IntCurveSurface_Out;
119 else
120 transition = IntCurveSurface_In;
121 }
122 }
123 } //-- classifier state is IN or ON
124 done = Standard_True;
125 } //-- Loop on Intersection points.
126 } //-- HICS.IsDone()
127}