b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | |
42cf5bc1 |
16 | #include <IntSurf_LineOn2S.hxx> |
17 | #include <IntSurf_PntOn2S.hxx> |
18 | #include <Standard_OutOfRange.hxx> |
19 | #include <Standard_Type.hxx> |
7fd59977 |
20 | |
25e59720 |
21 | IMPLEMENT_STANDARD_RTTIEXT(IntSurf_LineOn2S,Standard_Transient) |
92efcf78 |
22 | |
92a55b01 |
23 | IntSurf_LineOn2S:: |
24 | IntSurf_LineOn2S(const IntSurf_Allocator& theAllocator) : mySeq(theAllocator) |
25 | { |
26 | myBuv1.SetWhole(); |
27 | myBuv2.SetWhole(); |
28 | myBxyz.SetWhole(); |
29 | } |
7fd59977 |
30 | |
31 | |
32 | Handle(IntSurf_LineOn2S) IntSurf_LineOn2S::Split (const Standard_Integer Index) |
33 | { |
34 | IntSurf_SequenceOfPntOn2S SS; |
35 | mySeq.Split(Index,SS); |
36 | Handle(IntSurf_LineOn2S) NS = new IntSurf_LineOn2S (); |
37 | Standard_Integer i; |
38 | Standard_Integer leng = SS.Length(); |
39 | for (i=1; i<=leng; i++) { |
40 | NS->Add(SS(i)); |
41 | } |
42 | return NS; |
43 | } |
44 | |
45 | |
46 | void IntSurf_LineOn2S::InsertBefore(const Standard_Integer index, const IntSurf_PntOn2S& P) { |
47 | if(index>mySeq.Length()) { |
48 | mySeq.Append(P); |
49 | } |
50 | else { |
51 | mySeq.InsertBefore(index,P); |
52 | } |
92a55b01 |
53 | |
54 | if (!myBxyz.IsWhole()) |
55 | { |
56 | myBxyz.Add(P.Value()); |
57 | } |
58 | |
59 | if (!myBuv1.IsWhole()) |
60 | { |
61 | myBuv1.Add(P.ValueOnSurface(Standard_True)); |
62 | } |
63 | |
64 | if (!myBuv2.IsWhole()) |
65 | { |
66 | myBuv2.Add(P.ValueOnSurface(Standard_False)); |
67 | } |
7fd59977 |
68 | } |
69 | |
70 | void IntSurf_LineOn2S::RemovePoint(const Standard_Integer index) { |
71 | mySeq.Remove(index); |
92a55b01 |
72 | myBuv1.SetWhole(); |
73 | myBuv2.SetWhole(); |
74 | myBxyz.SetWhole(); |
7fd59977 |
75 | } |
92a55b01 |
76 | |
77 | Standard_Boolean IntSurf_LineOn2S::IsOutBox(const gp_Pnt& Pxyz) |
78 | { |
79 | if (myBxyz.IsWhole()) |
80 | { |
81 | Standard_Integer n = NbPoints(); |
82 | myBxyz.SetVoid(); |
83 | for (Standard_Integer i = 1; i <= n; i++) |
84 | { |
85 | gp_Pnt P = mySeq(i).Value(); |
86 | myBxyz.Add(P); |
87 | } |
88 | Standard_Real x0, y0, z0, x1, y1, z1; |
89 | myBxyz.Get(x0, y0, z0, x1, y1, z1); |
90 | x1 -= x0; y1 -= y0; z1 -= z0; |
91 | if (x1>y1) |
92 | { |
93 | if (x1>z1) |
94 | { |
95 | myBxyz.Enlarge(x1*0.01); |
96 | } |
97 | else |
98 | { |
99 | myBxyz.Enlarge(z1*0.01); |
100 | } |
101 | } |
102 | else |
103 | { |
104 | if (y1>z1) |
105 | { |
106 | myBxyz.Enlarge(y1*0.01); |
107 | } |
108 | else |
109 | { |
110 | myBxyz.Enlarge(z1*0.01); |
111 | } |
112 | } |
113 | } |
114 | Standard_Boolean out = myBxyz.IsOut(Pxyz); |
115 | return(out); |
116 | } |
117 | |
118 | Standard_Boolean IntSurf_LineOn2S::IsOutSurf1Box(const gp_Pnt2d& P1uv) |
119 | { |
120 | if (myBuv1.IsWhole()) |
121 | { |
122 | Standard_Integer n = NbPoints(); |
123 | Standard_Real pu1, pu2, pv1, pv2; |
124 | myBuv1.SetVoid(); |
125 | for (Standard_Integer i = 1; i <= n; i++) |
126 | { |
127 | mySeq(i).Parameters(pu1, pv1, pu2, pv2); |
128 | myBuv1.Add(gp_Pnt2d(pu1, pv1)); |
129 | } |
130 | myBuv1.Get(pu1, pv1, pu2, pv2); |
131 | pu2 -= pu1; |
132 | pv2 -= pv1; |
133 | if (pu2>pv2) |
134 | { |
135 | myBuv1.Enlarge(pu2*0.01); |
136 | } |
137 | else |
138 | { |
139 | myBuv1.Enlarge(pv2*0.01); |
140 | } |
141 | } |
142 | Standard_Boolean out = myBuv1.IsOut(P1uv); |
143 | return(out); |
144 | } |
145 | |
146 | Standard_Boolean IntSurf_LineOn2S::IsOutSurf2Box(const gp_Pnt2d& P2uv) |
147 | { |
148 | if (myBuv2.IsWhole()) |
149 | { |
150 | Standard_Integer n = NbPoints(); |
151 | Standard_Real pu1, pu2, pv1, pv2; |
152 | myBuv2.SetVoid(); |
153 | for (Standard_Integer i = 1; i <= n; i++) |
154 | { |
155 | mySeq(i).Parameters(pu1, pv1, pu2, pv2); |
156 | myBuv2.Add(gp_Pnt2d(pu2, pv2)); |
157 | } |
158 | myBuv2.Get(pu1, pv1, pu2, pv2); |
159 | pu2 -= pu1; |
160 | pv2 -= pv1; |
161 | if (pu2>pv2) |
162 | { |
163 | myBuv2.Enlarge(pu2*0.01); |
164 | } |
165 | else |
166 | { |
167 | myBuv2.Enlarge(pv2*0.01); |
168 | } |
169 | } |
170 | Standard_Boolean out = myBuv2.IsOut(P2uv); |
171 | return(out); |
172 | } |
173 | |
98974dcc |
174 | //======================================================================= |
175 | //function : Add |
176 | //purpose : |
177 | //======================================================================= |
178 | void IntSurf_LineOn2S::Add(const IntSurf_PntOn2S& P) |
179 | { |
180 | mySeq.Append(P); |
181 | if (!myBxyz.IsWhole()) |
182 | { |
183 | myBxyz.Add(P.Value()); |
184 | } |
185 | |
186 | if (!myBuv1.IsWhole()) |
187 | { |
188 | myBuv1.Add(P.ValueOnSurface(Standard_True)); |
189 | } |
190 | |
191 | if (!myBuv2.IsWhole()) |
192 | { |
193 | myBuv2.Add(P.ValueOnSurface(Standard_False)); |
194 | } |
195 | } |
196 | |
197 | //======================================================================= |
198 | //function : SetUV |
199 | //purpose : |
200 | //======================================================================= |
201 | void IntSurf_LineOn2S::SetUV(const Standard_Integer Index, |
202 | const Standard_Boolean OnFirst, |
203 | const Standard_Real U, |
204 | const Standard_Real V) |
205 | { |
206 | mySeq(Index).SetValue(OnFirst, U, V); |
207 | |
208 | if (OnFirst && !myBuv1.IsWhole()) |
209 | { |
210 | myBuv1.Add(gp_Pnt2d(U, V)); |
211 | } |
212 | else if (!OnFirst && !myBuv2.IsWhole()) |
213 | { |
214 | myBuv2.Add(gp_Pnt2d(U, V)); |
215 | } |
216 | } |