b311480e |
1 | // Created on: 1997-05-15 |
2 | // Created by: Robert COUBLANC |
3 | // Copyright (c) 1997-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 | |
f751596e |
17 | #include <algorithm> |
7fd59977 |
18 | |
4bf18dff |
19 | #include <Poly.hxx> |
7fd59977 |
20 | #include <Poly_Connect.hxx> |
7fd59977 |
21 | #include <TColStd_Array1OfInteger.hxx> |
22 | #include <Select3D_SensitiveTriangle.hxx> |
23 | #include <Precision.hxx> |
f751596e |
24 | #include <Select3D_TypeOfSensitivity.hxx> |
7fd59977 |
25 | |
f751596e |
26 | #include <Select3D_SensitiveTriangulation.hxx> |
7fd59977 |
27 | |
7fd59977 |
28 | |
f751596e |
29 | static Standard_Integer NbOfFreeEdges (const Handle(Poly_Triangulation)& theTriangulation) |
7fd59977 |
30 | { |
f751596e |
31 | Standard_Integer aNbFree = 0; |
32 | Poly_Connect aPoly (theTriangulation); |
33 | Standard_Integer aTriangleNodes[3]; |
34 | for (Standard_Integer aTrgIdx = 1; aTrgIdx <= theTriangulation->NbTriangles(); aTrgIdx++) |
35 | { |
36 | aPoly.Triangles (aTrgIdx, aTriangleNodes[0], aTriangleNodes[1], aTriangleNodes[2]); |
37 | for (Standard_Integer aNodeIdx = 0; aNodeIdx < 3; aNodeIdx++) |
38 | if (aTriangleNodes[aNodeIdx] == 0) |
39 | aNbFree++; |
40 | } |
41 | return aNbFree; |
7fd59977 |
42 | } |
43 | |
7fd59977 |
44 | //======================================================================= |
45 | //function : Select3D_SensitiveTriangulation |
4bf18dff |
46 | //purpose : |
7fd59977 |
47 | //======================================================================= |
f751596e |
48 | Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(SelectBasics_EntityOwner)& theOwnerId, |
49 | const Handle(Poly_Triangulation)& theTrg, |
50 | const TopLoc_Location& theInitLoc, |
51 | const Standard_Boolean theIsInterior) |
52 | : Select3D_SensitiveSet (theOwnerId), |
53 | myTriangul (theTrg), |
54 | myInitLocation (theInitLoc), |
55 | myDetectedTr (-1) |
7fd59977 |
56 | { |
f751596e |
57 | mySensType = theIsInterior ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY; |
58 | const Poly_Array1OfTriangle& aTriangles = myTriangul->Triangles(); |
59 | const TColgp_Array1OfPnt& aNodes = myTriangul->Nodes(); |
60 | Standard_Integer aNbTriangles (myTriangul->NbTriangles()); |
61 | gp_XYZ aCenter (0.0, 0.0, 0.0); |
62 | |
63 | myPrimitivesNb = theIsInterior ? aNbTriangles : NbOfFreeEdges (theTrg); |
64 | myBVHPrimIndexes = new TColStd_HArray1OfInteger(0, myPrimitivesNb - 1); |
65 | TColStd_Array1OfInteger& aBVHPrimIdxs = myBVHPrimIndexes->ChangeArray1(); |
66 | |
67 | if (!theIsInterior) |
ac04d101 |
68 | { |
f751596e |
69 | Standard_Integer anEdgeIdx = 1; |
70 | myFreeEdges = new TColStd_HArray1OfInteger (1, 2 * myPrimitivesNb); |
71 | TColStd_Array1OfInteger& aFreeEdges = myFreeEdges->ChangeArray1(); |
72 | Poly_Connect aPoly (myTriangul); |
73 | Standard_Integer aTriangle[3]; |
74 | Standard_Integer aTrNodeIdx[3]; |
75 | for (Standard_Integer aTriangleIdx = 1; aTriangleIdx <= aNbTriangles; aTriangleIdx++) |
ac04d101 |
76 | { |
f751596e |
77 | aPoly.Triangles (aTriangleIdx, aTriangle[0], aTriangle[1], aTriangle[2]); |
78 | aTriangles (aTriangleIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]); |
79 | aCenter += (aNodes (aTrNodeIdx[0]).XYZ() + aNodes (aTrNodeIdx[1]).XYZ()+ aNodes (aTrNodeIdx[2]).XYZ()) / 3.0; |
80 | for (Standard_Integer aVertIdx = 0; aVertIdx < 3; aVertIdx++) |
ac04d101 |
81 | { |
f751596e |
82 | Standard_Integer aNextVert = (aVertIdx + 1) % 3; |
83 | if (aTriangle[aVertIdx] == 0) |
ac04d101 |
84 | { |
f751596e |
85 | aFreeEdges (anEdgeIdx) = aTrNodeIdx[aVertIdx]; |
86 | aFreeEdges (anEdgeIdx+1) = aTrNodeIdx[aNextVert]; |
87 | anEdgeIdx += 2; |
ac04d101 |
88 | } |
7fd59977 |
89 | } |
90 | } |
91 | } |
f751596e |
92 | else |
93 | { |
94 | Standard_Integer aTrNodeIdx[3]; |
95 | for (Standard_Integer aTrIdx = 1; aTrIdx <= aNbTriangles; aTrIdx++) |
ac04d101 |
96 | { |
f751596e |
97 | aTriangles (aTrIdx).Get (aTrNodeIdx[0], aTrNodeIdx[1], aTrNodeIdx[2]); |
98 | aCenter += (aNodes (aTrNodeIdx[0]).XYZ() + aNodes (aTrNodeIdx[1]).XYZ()+ aNodes (aTrNodeIdx[2]).XYZ()) / 3.0; |
7fd59977 |
99 | } |
100 | } |
f751596e |
101 | if (aNbTriangles != 0) |
102 | aCenter /= aNbTriangles; |
103 | myCDG3D = gp_Pnt (aCenter); |
7fd59977 |
104 | |
f751596e |
105 | myBndBox.Clear(); |
106 | for (Standard_Integer aNodeIdx = 1; aNodeIdx <= myTriangul->NbNodes(); ++aNodeIdx) |
107 | { |
108 | myBndBox.Add (SelectMgr_Vec3 (aNodes (aNodeIdx).X(), |
109 | aNodes (aNodeIdx).Y(), |
110 | aNodes (aNodeIdx).Z())); |
7fd59977 |
111 | } |
4bf18dff |
112 | |
f751596e |
113 | if (theIsInterior) |
114 | { |
115 | for (Standard_Integer aTriangleIdx = 1; aTriangleIdx <= aNbTriangles; ++aTriangleIdx) |
116 | { |
117 | aBVHPrimIdxs (aTriangleIdx - 1) = aTriangleIdx - 1; |
118 | } |
119 | } |
120 | else |
121 | { |
122 | Standard_Integer aStartIdx = myFreeEdges->Lower(); |
123 | Standard_Integer anEndIdx = myFreeEdges->Upper(); |
124 | for (Standard_Integer aFreeEdgesIdx = aStartIdx; aFreeEdgesIdx <= anEndIdx; aFreeEdgesIdx += 2) |
125 | { |
126 | aBVHPrimIdxs ((aFreeEdgesIdx - aStartIdx) / 2) = (aFreeEdgesIdx - aStartIdx) / 2; |
127 | } |
128 | } |
7fd59977 |
129 | } |
130 | |
7fd59977 |
131 | |
7fd59977 |
132 | //======================================================================= |
f751596e |
133 | //function : Select3D_SensitiveTriangulation |
4bf18dff |
134 | //purpose : |
7fd59977 |
135 | //======================================================================= |
f751596e |
136 | Select3D_SensitiveTriangulation::Select3D_SensitiveTriangulation (const Handle(SelectBasics_EntityOwner)& theOwnerId, |
137 | const Handle(Poly_Triangulation)& theTrg, |
138 | const TopLoc_Location& theInitLoc, |
139 | const Handle(TColStd_HArray1OfInteger)& theFreeEdges, |
140 | const gp_Pnt& theCOG, |
141 | const Standard_Boolean theIsInterior) |
142 | : Select3D_SensitiveSet (theOwnerId), |
143 | myTriangul (theTrg), |
144 | myInitLocation (theInitLoc), |
145 | myCDG3D (theCOG), |
146 | myFreeEdges (theFreeEdges), |
147 | myDetectedTr (-1) |
4269bd1b |
148 | { |
f751596e |
149 | mySensType = theIsInterior ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY; |
150 | myPrimitivesNb = theIsInterior ? theTrg->Triangles().Length() : theFreeEdges->Length() / 2; |
151 | myBVHPrimIndexes = new TColStd_HArray1OfInteger(0, myPrimitivesNb - 1); |
152 | if (theIsInterior) |
7fd59977 |
153 | { |
f751596e |
154 | for (Standard_Integer aTriangleIdx = 1; aTriangleIdx <= myPrimitivesNb; ++aTriangleIdx) |
7fd59977 |
155 | { |
f751596e |
156 | myBVHPrimIndexes->SetValue (aTriangleIdx - 1, aTriangleIdx - 1); |
7fd59977 |
157 | } |
158 | } |
7fd59977 |
159 | else |
160 | { |
f751596e |
161 | Standard_Integer aStartIdx = myFreeEdges->Lower(); |
162 | Standard_Integer anEndIdx = myFreeEdges->Upper(); |
163 | for (Standard_Integer aFreeEdgesIdx = aStartIdx; aFreeEdgesIdx <= anEndIdx; aFreeEdgesIdx += 2) |
7fd59977 |
164 | { |
f751596e |
165 | myBVHPrimIndexes->SetValue ((aFreeEdgesIdx - aStartIdx) / 2, (aFreeEdgesIdx - aStartIdx) / 2); |
7fd59977 |
166 | } |
4bf18dff |
167 | } |
4269bd1b |
168 | } |
7fd59977 |
169 | |
170 | //======================================================================= |
f751596e |
171 | // function : Size |
172 | // purpose : Returns the length of array of triangles or edges |
7fd59977 |
173 | //======================================================================= |
f751596e |
174 | Standard_Integer Select3D_SensitiveTriangulation::Size() const |
7fd59977 |
175 | { |
f751596e |
176 | return myPrimitivesNb; |
7fd59977 |
177 | } |
178 | |
7fd59977 |
179 | //======================================================================= |
f751596e |
180 | // function : Box |
181 | // purpose : Returns bounding box of triangle/edge with index theIdx |
7fd59977 |
182 | //======================================================================= |
f751596e |
183 | Select3D_BndBox3d Select3D_SensitiveTriangulation::Box (const Standard_Integer theIdx) const |
4bf18dff |
184 | { |
f751596e |
185 | Standard_Integer aPrimIdx = myBVHPrimIndexes->Value (theIdx); |
186 | SelectMgr_Vec3 aMinPnt (RealLast()); |
187 | SelectMgr_Vec3 aMaxPnt (RealFirst()); |
188 | Standard_Boolean hasInitLoc = HasInitLocation(); |
7fd59977 |
189 | |
f751596e |
190 | if (mySensType == Select3D_TOS_INTERIOR) |
ac04d101 |
191 | { |
f751596e |
192 | Standard_Integer aNode1, aNode2, aNode3; |
193 | myTriangul->Triangles() (aPrimIdx + 1).Get (aNode1, aNode2, aNode3); |
194 | |
195 | gp_Pnt aPnt1 = hasInitLoc ? myTriangul->Nodes().Value (aNode1).Transformed (myInitLocation.Transformation()) |
196 | : myTriangul->Nodes().Value (aNode1); |
197 | gp_Pnt aPnt2 = hasInitLoc ? myTriangul->Nodes().Value (aNode2).Transformed (myInitLocation.Transformation()) |
198 | : myTriangul->Nodes().Value (aNode2); |
199 | gp_Pnt aPnt3 = hasInitLoc ? myTriangul->Nodes().Value (aNode3).Transformed (myInitLocation.Transformation()) |
200 | : myTriangul->Nodes().Value (aNode3); |
201 | |
202 | aMinPnt = SelectMgr_Vec3 (Min (aPnt1.X(), Min (aPnt2.X(), aPnt3.X())), |
203 | Min (aPnt1.Y(), Min (aPnt2.Y(), aPnt3.Y())), |
204 | Min (aPnt1.Z(), Min (aPnt2.Z(), aPnt3.Z()))); |
205 | aMaxPnt = SelectMgr_Vec3 (Max (aPnt1.X(), Max (aPnt2.X(), aPnt3.X())), |
206 | Max (aPnt1.Y(), Max (aPnt2.Y(), aPnt3.Y())), |
207 | Max (aPnt1.Z(), Max (aPnt2.Z(), aPnt3.Z()))); |
208 | } |
209 | else |
210 | { |
211 | Standard_Integer aNodeIdx1 = myFreeEdges->Value (myFreeEdges->Lower() + aPrimIdx); |
212 | Standard_Integer aNodeIdx2 = myFreeEdges->Value (myFreeEdges->Lower() + aPrimIdx + 1); |
213 | gp_Pnt aNode1 = hasInitLoc ? myTriangul->Nodes().Value (aNodeIdx1).Transformed (myInitLocation.Transformation()) |
214 | : myTriangul->Nodes().Value (aNodeIdx1); |
215 | gp_Pnt aNode2 = hasInitLoc ? myTriangul->Nodes().Value (aNodeIdx2).Transformed (myInitLocation.Transformation()) |
216 | : myTriangul->Nodes().Value (aNodeIdx2); |
217 | |
218 | aMinPnt = SelectMgr_Vec3 (Min (aNode1.X(), aNode2.X()), |
219 | Min (aNode1.Y(), aNode2.Y()), |
220 | Min (aNode1.Z(), aNode2.Z())); |
221 | aMaxPnt = SelectMgr_Vec3 (Max (aNode1.X(), aNode2.X()), |
222 | Max (aNode1.Y(), aNode2.Y()), |
223 | Max (aNode1.Z(), aNode2.Z())); |
7fd59977 |
224 | } |
7fd59977 |
225 | |
f751596e |
226 | return Select3D_BndBox3d (aMinPnt, aMaxPnt); |
7fd59977 |
227 | } |
228 | |
229 | //======================================================================= |
f751596e |
230 | // function : Center |
231 | // purpose : Returns geometry center of triangle/edge with index theIdx |
232 | // in array along the given axis theAxis |
7fd59977 |
233 | //======================================================================= |
f751596e |
234 | Standard_Real Select3D_SensitiveTriangulation::Center (const Standard_Integer theIdx, |
235 | const Standard_Integer theAxis) const |
7fd59977 |
236 | { |
f751596e |
237 | const Select3D_BndBox3d& aBox = Box (theIdx); |
238 | SelectMgr_Vec3 aCenter = (aBox.CornerMin () + aBox.CornerMax ()) * 0.5; |
239 | |
240 | return theAxis == 0 ? aCenter.x() : (theAxis == 1 ? aCenter.y() : aCenter.z()); |
7fd59977 |
241 | } |
242 | |
7fd59977 |
243 | //======================================================================= |
f751596e |
244 | // function : Swap |
245 | // purpose : Swaps items with indexes theIdx1 and theIdx2 in array |
7fd59977 |
246 | //======================================================================= |
f751596e |
247 | void Select3D_SensitiveTriangulation::Swap (const Standard_Integer theIdx1, |
248 | const Standard_Integer theIdx2) |
7fd59977 |
249 | { |
f751596e |
250 | Standard_Integer anElemIdx1 = myBVHPrimIndexes->Value (theIdx1); |
251 | Standard_Integer anElemIdx2 = myBVHPrimIndexes->Value (theIdx2); |
4bf18dff |
252 | |
f751596e |
253 | myBVHPrimIndexes->ChangeValue (theIdx1) = anElemIdx2; |
254 | myBVHPrimIndexes->ChangeValue (theIdx2) = anElemIdx1; |
7fd59977 |
255 | } |
256 | |
7fd59977 |
257 | //======================================================================= |
f751596e |
258 | // function : overlapsElement |
259 | // purpose : Checks whether the element with index theIdx overlaps the |
260 | // current selecting volume |
7fd59977 |
261 | //======================================================================= |
f751596e |
262 | Standard_Boolean Select3D_SensitiveTriangulation::overlapsElement (SelectBasics_SelectingVolumeManager& theMgr, |
263 | Standard_Integer theElemIdx, |
264 | Standard_Real& theMatchDepth) |
7fd59977 |
265 | { |
f751596e |
266 | const Standard_Integer& aPrimitiveIdx = myBVHPrimIndexes->Value (theElemIdx); |
267 | Standard_Boolean hasInitLoc = HasInitLocation(); |
268 | |
269 | if (mySensType == Select3D_TOS_BOUNDARY) |
270 | { |
271 | Standard_Integer aSegmStartIdx = myFreeEdges->Value (aPrimitiveIdx * 2 + 1); |
272 | Standard_Integer aSegmEndIdx = myFreeEdges->Value (aPrimitiveIdx * 2 + 2); |
273 | Handle(TColgp_HArray1OfPnt) anEdgePnts = new TColgp_HArray1OfPnt (1, 2); |
274 | gp_Pnt aSegmStart = hasInitLoc ? myTriangul->Nodes().Value (aSegmStartIdx).Transformed (myInitLocation.Transformation()) |
275 | : myTriangul->Nodes().Value (aSegmStartIdx); |
276 | gp_Pnt aSegmEnd = hasInitLoc ? myTriangul->Nodes().Value (aSegmEndIdx).Transformed (myInitLocation.Transformation()) |
277 | : myTriangul->Nodes().Value (aSegmEndIdx); |
278 | anEdgePnts->SetValue (1, aSegmStart); |
279 | anEdgePnts->SetValue (2, aSegmEnd); |
280 | Standard_Boolean isMatched = theMgr.Overlaps (anEdgePnts, Select3D_TOS_BOUNDARY, theMatchDepth); |
281 | anEdgePnts.Nullify(); |
282 | return isMatched; |
283 | } |
284 | else |
285 | { |
286 | const Poly_Array1OfTriangle& aTriangles = myTriangul->Triangles(); |
287 | Standard_Integer aNode1, aNode2, aNode3; |
288 | aTriangles (aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3); |
289 | gp_Pnt aPnt1 = hasInitLoc ? myTriangul->Nodes().Value (aNode1).Transformed (myInitLocation.Transformation()) |
290 | : myTriangul->Nodes().Value (aNode1); |
291 | gp_Pnt aPnt2 = hasInitLoc ? myTriangul->Nodes().Value (aNode2).Transformed (myInitLocation.Transformation()) |
292 | : myTriangul->Nodes().Value (aNode2); |
293 | gp_Pnt aPnt3 = hasInitLoc ? myTriangul->Nodes().Value (aNode3).Transformed (myInitLocation.Transformation()) |
294 | : myTriangul->Nodes().Value (aNode3); |
295 | return theMgr.Overlaps (aPnt1, aPnt2, aPnt3, Select3D_TOS_INTERIOR, theMatchDepth); |
296 | } |
7fd59977 |
297 | } |
ac04d101 |
298 | |
2157d6ac |
299 | //================================================== |
300 | // Function : elementIsInside |
301 | // Purpose : |
302 | //================================================== |
303 | Standard_Boolean Select3D_SensitiveTriangulation::elementIsInside (SelectBasics_SelectingVolumeManager& theMgr, |
304 | const Standard_Integer theElemIdx) |
305 | { |
306 | Standard_Real aDummy; |
307 | |
308 | const Standard_Integer& aPrimitiveIdx = myBVHPrimIndexes->Value (theElemIdx); |
309 | |
310 | if (mySensType == Select3D_TOS_BOUNDARY) |
311 | { |
312 | gp_Pnt aSegmPnt1 = myTriangul->Nodes().Value (myFreeEdges->Value (aPrimitiveIdx * 2 + 1)); |
313 | gp_Pnt aSegmPnt2 = myTriangul->Nodes().Value (myFreeEdges->Value (aPrimitiveIdx * 2 + 2)); |
314 | |
315 | if (HasInitLocation()) // Note: Should be removed (by transforming frustum) |
316 | { |
317 | aSegmPnt1.Transform (myInitLocation.Transformation()); |
318 | aSegmPnt2.Transform (myInitLocation.Transformation()); |
319 | } |
320 | |
321 | return theMgr.Overlaps (aSegmPnt1, aDummy) && theMgr.Overlaps (aSegmPnt2, aDummy); |
322 | } |
323 | else |
324 | { |
325 | Standard_Integer aNode1; |
326 | Standard_Integer aNode2; |
327 | Standard_Integer aNode3; |
328 | |
329 | myTriangul->Triangles() (aPrimitiveIdx + 1).Get (aNode1, aNode2, aNode3); |
330 | |
331 | gp_Pnt aPnt1 = myTriangul->Nodes().Value (aNode1); |
332 | gp_Pnt aPnt2 = myTriangul->Nodes().Value (aNode2); |
333 | gp_Pnt aPnt3 = myTriangul->Nodes().Value (aNode3); |
334 | |
335 | if (HasInitLocation()) // Note: Should be removed (by transforming frustum) |
336 | { |
337 | aPnt1.Transform (myInitLocation.Transformation()); |
338 | aPnt2.Transform (myInitLocation.Transformation()); |
339 | aPnt3.Transform (myInitLocation.Transformation()); |
340 | } |
341 | |
342 | return theMgr.Overlaps (aPnt1, aDummy) |
343 | && theMgr.Overlaps (aPnt2, aDummy) |
344 | && theMgr.Overlaps (aPnt3, aDummy); |
345 | } |
346 | } |
347 | |
ac04d101 |
348 | //======================================================================= |
f751596e |
349 | // function : distanceToCOG |
350 | // purpose : Calculates distance from the 3d projection of used-picked |
351 | // screen point to center of the geometry |
ac04d101 |
352 | //======================================================================= |
f751596e |
353 | Standard_Real Select3D_SensitiveTriangulation::distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) |
7fd59977 |
354 | { |
f751596e |
355 | return theMgr.DistToGeometryCenter (myCDG3D); |
7fd59977 |
356 | } |
357 | |
7fd59977 |
358 | //======================================================================= |
f751596e |
359 | //function : GetConnected |
4bf18dff |
360 | //purpose : |
7fd59977 |
361 | //======================================================================= |
f751596e |
362 | Handle(Select3D_SensitiveEntity) Select3D_SensitiveTriangulation::GetConnected() |
7fd59977 |
363 | { |
f751596e |
364 | Standard_Boolean isInterior = mySensType == Select3D_TOS_INTERIOR; |
365 | Handle(Select3D_SensitiveTriangulation) aNewEntity = |
366 | new Select3D_SensitiveTriangulation (myOwnerId, myTriangul, myInitLocation, myFreeEdges, myCDG3D, isInterior); |
7fd59977 |
367 | |
f751596e |
368 | return aNewEntity; |
7fd59977 |
369 | } |
370 | |
371 | //======================================================================= |
f751596e |
372 | // function : applyTransformation |
373 | // purpose : Inner function for transformation application to bounding |
374 | // box of the triangulation |
7fd59977 |
375 | //======================================================================= |
f751596e |
376 | Select3D_BndBox3d Select3D_SensitiveTriangulation::applyTransformation() |
7fd59977 |
377 | { |
f751596e |
378 | if (!HasInitLocation()) |
379 | return myBndBox; |
aec37c15 |
380 | |
f751596e |
381 | Select3D_BndBox3d aBndBox; |
382 | for (Standard_Integer aX = 0; aX <=1; ++aX) |
ac04d101 |
383 | { |
f751596e |
384 | for (Standard_Integer aY = 0; aY <=1; ++aY) |
4269bd1b |
385 | { |
f751596e |
386 | for (Standard_Integer aZ = 0; aZ <= 1; ++aZ) |
387 | { |
388 | gp_Pnt aVertex = gp_Pnt (aX == 0 ? myBndBox.CornerMin().x() : myBndBox.CornerMax().x(), |
389 | aY == 0 ? myBndBox.CornerMin().y() : myBndBox.CornerMax().y(), |
390 | aZ == 0 ? myBndBox.CornerMin().z() : myBndBox.CornerMax().z()); |
391 | aVertex.Transform (myInitLocation); |
392 | aBndBox.Add (Select3D_Vec3 (aVertex.X(), aVertex.Y(), aVertex.Z())); |
393 | } |
4269bd1b |
394 | } |
4bf18dff |
395 | } |
4269bd1b |
396 | |
f751596e |
397 | return aBndBox; |
7fd59977 |
398 | } |
399 | |
400 | //======================================================================= |
f751596e |
401 | // function : BoundingBox |
402 | // purpose : Returns bounding box of the triangulation. If location |
403 | // transformation is set, it will be applied |
7fd59977 |
404 | //======================================================================= |
f751596e |
405 | Select3D_BndBox3d Select3D_SensitiveTriangulation::BoundingBox() |
7fd59977 |
406 | { |
f751596e |
407 | if (myBndBox.IsValid()) |
408 | return applyTransformation(); |
409 | |
410 | const Standard_Integer aLower = myTriangul->Nodes().Lower(); |
411 | const Standard_Integer anUpper = myTriangul->Nodes().Upper(); |
412 | Select3D_BndBox3d aBndBox; |
413 | for (Standard_Integer aNodeIdx = aLower; aNodeIdx <= anUpper; ++aNodeIdx) |
ac04d101 |
414 | { |
f751596e |
415 | const gp_Pnt& aNode = myTriangul->Nodes().Value (aNodeIdx); |
416 | const SelectMgr_Vec3 aNodeTransf = SelectMgr_Vec3 (aNode.X(), aNode.Y(), aNode.Z()); |
417 | aBndBox.Add (aNodeTransf); |
7fd59977 |
418 | } |
4bf18dff |
419 | |
f751596e |
420 | myBndBox = aBndBox; |
7fd59977 |
421 | |
f751596e |
422 | return applyTransformation(); |
423 | } |
ac04d101 |
424 | |
f751596e |
425 | //======================================================================= |
426 | // function : CenterOfGeometry |
427 | // purpose : Returns center of triangulation. If location transformation |
428 | // is set, it will be applied |
429 | //======================================================================= |
430 | gp_Pnt Select3D_SensitiveTriangulation::CenterOfGeometry() const |
7fd59977 |
431 | { |
f751596e |
432 | return HasInitLocation() ? myCDG3D.Transformed (myInitLocation) : myCDG3D; |
7fd59977 |
433 | } |
434 | |
f751596e |
435 | //======================================================================= |
436 | // function : NbSubElements |
437 | // purpose : Returns the amount of nodes in triangulation |
438 | //======================================================================= |
439 | Standard_Integer Select3D_SensitiveTriangulation::NbSubElements() |
7fd59977 |
440 | { |
f751596e |
441 | return myTriangul->Nodes().Length(); |
2157d6ac |
442 | } |