b311480e |
1 | // Created on: 2005-01-21 |
2 | // Created by: Alexander SOLOVYOV |
973c2be1 |
3 | // Copyright (c) 2005-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
f751596e |
16 | #include <MeshVS_SensitivePolyhedron.hxx> |
7fd59977 |
17 | |
f751596e |
18 | #include <gp_Lin.hxx> |
19 | #include <MeshVS_HArray1OfSequenceOfInteger.hxx> |
7fd59977 |
20 | #include <MeshVS_Tool.hxx> |
f751596e |
21 | #include <NCollection_Vec4.hxx> |
22 | #include <Select3D_SensitiveEntity.hxx> |
23 | #include <SelectBasics_EntityOwner.hxx> |
24 | #include <TColgp_Array1OfPnt.hxx> |
25 | #include <TColgp_HArray1OfPnt.hxx> |
26 | #include <TColgp_Array1OfPnt2d.hxx> |
27 | #include <TColStd_SequenceOfInteger.hxx> |
7fd59977 |
28 | |
7fd59977 |
29 | |
30 | //================================================================ |
f751596e |
31 | // Function : Constructor MeshVS_SensitivePolyhedron |
7fd59977 |
32 | // Purpose : |
33 | //================================================================ |
f751596e |
34 | MeshVS_SensitivePolyhedron::MeshVS_SensitivePolyhedron (const Handle(SelectBasics_EntityOwner)& theOwner, |
35 | const TColgp_Array1OfPnt& theNodes, |
36 | const Handle(MeshVS_HArray1OfSequenceOfInteger)& theTopo) |
37 | : Select3D_SensitiveEntity (theOwner), |
38 | myTopo (theTopo) |
7fd59977 |
39 | { |
f751596e |
40 | Standard_Integer aPlaneLowIdx = theTopo->Lower(); |
41 | Standard_Integer aPlaneUpIdx = theTopo->Upper(); |
42 | Standard_Integer aNodesLowerIdx = theNodes.Lower(); |
43 | myNodes = new TColgp_HArray1OfPnt (aNodesLowerIdx, theNodes.Upper()); |
44 | myCenter = gp_XYZ (0.0, 0.0, 0.0); |
7fd59977 |
45 | |
f751596e |
46 | for (Standard_Integer aPlaneIdx = aPlaneLowIdx; aPlaneIdx <= aPlaneUpIdx; ++aPlaneIdx) |
7fd59977 |
47 | { |
f751596e |
48 | Standard_Integer aVertNb = theTopo->Value (aPlaneIdx).Length(); |
49 | Handle(TColgp_HArray1OfPnt) aVertArray = new TColgp_HArray1OfPnt (0, aVertNb - 1); |
50 | for (Standard_Integer aVertIdx = 1; aVertIdx <= aVertNb; ++aVertIdx) |
51 | { |
52 | Standard_Integer aNodeIdx = theTopo->Value (aPlaneIdx).Value (aVertIdx); |
53 | const gp_Pnt& aVert = theNodes.Value (aNodeIdx + aNodesLowerIdx); |
54 | aVertArray->SetValue (aVertIdx - 1, aVert); |
55 | myNodes->SetValue (aNodeIdx + aNodesLowerIdx, aVert); |
56 | myBndBox.Add (SelectMgr_Vec3 (aVert.X(), aVert.Y(), aVert.Z())); |
57 | myCenter += aVert.XYZ(); |
58 | } |
7fd59977 |
59 | |
f751596e |
60 | myTopology.Append (aVertArray); |
7fd59977 |
61 | } |
62 | |
f751596e |
63 | myCenter.Divide (theNodes.Length()); |
7fd59977 |
64 | } |
65 | |
66 | //================================================================ |
67 | // Function : GetConnected |
68 | // Purpose : |
69 | //================================================================ |
f751596e |
70 | Handle(Select3D_SensitiveEntity) MeshVS_SensitivePolyhedron::GetConnected() |
7fd59977 |
71 | { |
f751596e |
72 | Handle(MeshVS_SensitivePolyhedron) aNewEnt = new |
73 | MeshVS_SensitivePolyhedron (myOwnerId, myNodes->Array1(), myTopo); |
7fd59977 |
74 | |
f751596e |
75 | return aNewEnt; |
7fd59977 |
76 | } |
77 | |
f751596e |
78 | //======================================================================= |
79 | // function : Matches |
80 | // purpose : |
81 | //======================================================================= |
82 | Standard_Boolean MeshVS_SensitivePolyhedron::Matches (SelectBasics_SelectingVolumeManager& theMgr, |
83 | SelectBasics_PickResult& thePickResult) |
7fd59977 |
84 | { |
f751596e |
85 | Standard_Real aDepthMin = RealLast(); |
86 | Standard_Real aDistToCOG = RealLast(); |
7fd59977 |
87 | |
f751596e |
88 | for (MeshVS_PolyhedronVertsIter aIter (myTopology); aIter.More(); aIter.Next()) |
7fd59977 |
89 | { |
f751596e |
90 | Standard_Real aDepth = RealLast(); |
91 | if (theMgr.Overlaps (aIter.Value(), Select3D_TOS_INTERIOR, aDepth)) |
7fd59977 |
92 | { |
f751596e |
93 | aDepthMin = Min (aDepth, aDepthMin); |
7fd59977 |
94 | } |
4952a30a |
95 | } |
4269bd1b |
96 | |
f751596e |
97 | aDistToCOG = aDepthMin == RealLast() ? RealLast() : theMgr.DistToGeometryCenter (myCenter); |
98 | thePickResult = SelectBasics_PickResult (aDepthMin, aDistToCOG); |
7fd59977 |
99 | |
f751596e |
100 | return aDepthMin != RealLast(); |
7fd59977 |
101 | } |
102 | |
f751596e |
103 | //======================================================================= |
104 | // function : NbSubElements |
105 | // purpose : Returns the amount of nodes of polyhedron |
106 | //======================================================================= |
107 | Standard_Integer MeshVS_SensitivePolyhedron::NbSubElements() |
7fd59977 |
108 | { |
f751596e |
109 | return myNodes->Length(); |
7fd59977 |
110 | } |
111 | |
f751596e |
112 | //======================================================================= |
113 | // function : BoundingBox |
114 | // purpose : |
115 | //======================================================================= |
116 | Select3D_BndBox3d MeshVS_SensitivePolyhedron::BoundingBox() |
7fd59977 |
117 | { |
f751596e |
118 | return myBndBox; |
7fd59977 |
119 | } |
120 | |
f751596e |
121 | //======================================================================= |
122 | // function : CenterOfGeometry |
123 | // purpose : |
124 | //======================================================================= |
125 | gp_Pnt MeshVS_SensitivePolyhedron::CenterOfGeometry() const |
7fd59977 |
126 | { |
f751596e |
127 | return myCenter; |
7fd59977 |
128 | } |