4e57c75e |
1 | // Created by: Peter KURNEV |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
19 | |
20 | #include <BOPInt_Tools.ixx> |
21 | |
22 | #include <gp_Pnt.hxx> |
23 | #include <BndLib_Add3dCurve.hxx> |
24 | #include <Bnd_Box.hxx> |
25 | #include <Geom_Curve.hxx> |
26 | #include <GeomAdaptor_Curve.hxx> |
27 | |
28 | //======================================================================= |
29 | //function : CheckCurve |
30 | //purpose : |
31 | //======================================================================= |
32 | Standard_Boolean BOPInt_Tools::CheckCurve(const Handle (Geom_Curve)& aC3D, |
33 | const Standard_Real aTolR3D, |
34 | Bnd_Box& aBox) |
35 | { |
36 | Standard_Boolean bRet; |
37 | Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax, dX, dY, dZ; |
38 | Standard_Real dS, aTol; |
39 | GeomAdaptor_Curve aGAC; |
40 | // |
41 | aGAC.Load(aC3D); |
42 | BndLib_Add3dCurve::Add(aGAC, aTolR3D, aBox); |
43 | // 910/B1 |
44 | aBox.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); |
45 | dX=aXmax-aXmin; |
46 | dY=aYmax-aYmin; |
47 | dZ=aZmax-aZmin; |
48 | dS=1.e-12; |
49 | aTol=2.*aTolR3D+dS; |
50 | bRet=(dX>aTol || dY>aTol || dZ>aTol); |
51 | // |
52 | return bRet; |
53 | } |
54 | |
55 | |
56 | //======================================================================= |
57 | //function : IsOnPave |
58 | //purpose : |
59 | //======================================================================= |
60 | Standard_Boolean BOPInt_Tools::IsOnPave(const Standard_Real aT1, |
61 | const IntTools_Range& aRange, |
62 | const Standard_Real aTolerance) |
63 | { |
64 | Standard_Boolean firstisonpave1, firstisonpave2, bIsOnPave; |
65 | // |
66 | firstisonpave1 = (Abs(aRange.First() - aT1) < aTolerance); |
67 | firstisonpave2 = (Abs(aRange.Last() - aT1) < aTolerance); |
68 | bIsOnPave=(firstisonpave1 || firstisonpave2); |
69 | return bIsOnPave; |
70 | } |
71 | //======================================================================= |
72 | // function: VertexParameters |
73 | // purpose: |
74 | //======================================================================= |
75 | void BOPInt_Tools::VertexParameters(const IntTools_CommonPrt& aCPart, |
76 | Standard_Real& aT1, |
77 | Standard_Real& aT2) |
78 | { |
79 | const IntTools_Range& aR1=aCPart.Range1(); |
80 | aT1=0.5*(aR1.First()+aR1.Last()); |
81 | // |
82 | if((aCPart.VertexParameter1() >= aR1.First()) && |
83 | (aCPart.VertexParameter1() <= aR1.Last())) { |
84 | aT1 = aCPart.VertexParameter1(); |
85 | } |
86 | // |
87 | const IntTools_SequenceOfRanges& aRanges2=aCPart.Ranges2(); |
88 | const IntTools_Range& aR2=aRanges2(1); |
89 | aT2=0.5*(aR2.First()+aR2.Last()); |
90 | // |
91 | if((aCPart.VertexParameter2() >= aR2.First()) && |
92 | (aCPart.VertexParameter2() <= aR2.Last())) { |
93 | aT2 = aCPart.VertexParameter2(); |
94 | } |
95 | } |
96 | //======================================================================= |
97 | // function: VertexParameter |
98 | // purpose: |
99 | //======================================================================= |
100 | void BOPInt_Tools::VertexParameter(const IntTools_CommonPrt& aCPart, |
101 | Standard_Real& aT) |
102 | { |
103 | const IntTools_Range& aR=aCPart.Range1(); |
104 | aT=0.5*(aR.First()+aR.Last()); |
105 | if((aCPart.VertexParameter1() >= aR.First()) && |
106 | (aCPart.VertexParameter1() <= aR.Last())) { |
107 | aT = aCPart.VertexParameter1(); |
108 | } |
109 | } |
110 | //======================================================================= |
111 | // function: IsOnPave1 |
112 | // purpose: |
113 | //======================================================================= |
114 | Standard_Boolean BOPInt_Tools::IsOnPave1(const Standard_Real aTR, |
115 | const IntTools_Range& aCPRange, |
116 | const Standard_Real aTolerance) |
117 | { |
118 | Standard_Boolean bIsOnPave; |
119 | Standard_Real aT1, aT2, dT1, dT2; |
120 | // |
121 | aT1=aCPRange.First(); |
122 | aT2=aCPRange.Last(); |
123 | bIsOnPave=(aTR>=aT1 && aTR<=aT1); |
124 | if (bIsOnPave) { |
125 | return bIsOnPave; |
126 | } |
127 | // |
128 | dT1=Abs(aTR-aT1); |
129 | dT2=Abs(aTR-aT2); |
130 | bIsOnPave=(dT1<=aTolerance || dT2<=aTolerance); |
131 | return bIsOnPave; |
132 | } |
133 | |
134 | |
135 | |
136 | |
137 | |
138 | |
139 | |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | //======================================================================= |
146 | //function : SegPln |
147 | //purpose : |
148 | //======================================================================= |
149 | Standard_Integer BOPInt_Tools::SegPln(const gp_Lin& theLin, |
150 | const Standard_Real theTLin1, |
151 | const Standard_Real theTLin2, |
152 | const Standard_Real theTolLin, |
153 | const gp_Pln& thePln, |
154 | const Standard_Real theTolPln, |
155 | gp_Pnt& theP, |
156 | Standard_Real& theTP, |
157 | Standard_Real& theTolP, |
158 | Standard_Real& theTPmin, |
159 | Standard_Real& theTPmax) |
160 | { |
161 | Standard_Integer iRet; |
162 | Standard_Real aTol, aA, aB, aC, aD, aE, aH, aTP, aDist1, aDist2; |
163 | gp_Pnt aP1, aP2; |
164 | // |
165 | iRet=0; |
166 | aTol=theTolLin+theTolPln; |
167 | // |
168 | const gp_Ax3& aPosPln=thePln.Position(); |
169 | const gp_Dir& aDirPln=aPosPln.Direction(); |
170 | const gp_Pnt& aLocPln=aPosPln.Location(); |
171 | // |
172 | const gp_Dir& aDirLin=theLin.Direction(); |
173 | const gp_Pnt& aLocLin=theLin.Location(); |
174 | // |
175 | aP1.SetXYZ(aLocLin.XYZ()+theTLin1*aDirLin.XYZ()); |
176 | aDist1=aDirPln.X()*(aP1.X()-aLocPln.X())+ |
177 | aDirPln.Y()*(aP1.Y()-aLocPln.Y())+ |
178 | aDirPln.Z()*(aP1.Z()-aLocPln.Z()); |
179 | // |
180 | aP2.SetXYZ(aLocLin.XYZ()+theTLin2*aDirLin.XYZ()); |
181 | aDist2=aDirPln.X()*(aP2.X()-aLocPln.X())+ |
182 | aDirPln.Y()*(aP2.Y()-aLocPln.Y())+ |
183 | aDirPln.Z()*(aP2.Z()-aLocPln.Z()); |
184 | // |
185 | if (aDist1<aTol && aDist2<aTol){ |
186 | iRet=1; // common block |
187 | return iRet; |
188 | } |
189 | // |
190 | if (aDist1*aDist2 > 0.) { |
191 | iRet=2; // segment lays on one side to the Plane |
192 | return iRet; |
193 | } |
194 | // |
195 | thePln.Coefficients(aA, aB, aC, aD); |
196 | aE=aA*aLocLin.X()+aB*aLocLin.Y()+aC*aLocLin.Z()+aD; |
197 | aH=aA*aDirLin.X()+aB*aDirLin.Y()+aC*aDirLin.Z(); |
198 | aTP=-aE/aH; |
199 | if (aTP < theTLin1-aTol || aTP > theTLin2+aTol) { |
200 | iRet=3; // no intersections due to range of the Line |
201 | return iRet; |
202 | } |
203 | // |
204 | theTP=aTP; |
205 | theP.SetXYZ(aLocLin.XYZ()+aTP*aDirLin.XYZ()); |
206 | theTolP=aTol; |
207 | theTPmin=theTP-theTolPln; |
208 | theTPmax=theTP+theTolPln; |
209 | iRet=0; // intersection point |
210 | return iRet; |
211 | } |