1 // Created on: 2005-01-21
2 // Created by: Alexander SOLOVYOV
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <MeshVS_SensitivePolyhedron.hxx>
17
18 #include <gp_Lin.hxx>
19 #include <MeshVS_HArray1OfSequenceOfInteger.hxx>
20 #include <MeshVS_Tool.hxx>
21 #include <NCollection_Vec4.hxx>
22 #include <Select3D_SensitiveEntity.hxx>
23 #include <TColgp_Array1OfPnt.hxx>
24 #include <TColgp_HArray1OfPnt.hxx>
25 #include <TColgp_Array1OfPnt2d.hxx>
26 #include <TColStd_SequenceOfInteger.hxx>
27
28
IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitivePolyhedron,Select3D_SensitiveEntity)29 IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitivePolyhedron,Select3D_SensitiveEntity)
30
31 //================================================================
32 // Function : Constructor MeshVS_SensitivePolyhedron
33 // Purpose :
34 //================================================================
35 MeshVS_SensitivePolyhedron::MeshVS_SensitivePolyhedron (const Handle(SelectMgr_EntityOwner)& theOwner,
36 const TColgp_Array1OfPnt& theNodes,
37 const Handle(MeshVS_HArray1OfSequenceOfInteger)& theTopo)
38 : Select3D_SensitiveEntity (theOwner),
39 myTopo (theTopo)
40 {
41 Standard_Integer aPlaneLowIdx = theTopo->Lower();
42 Standard_Integer aPlaneUpIdx = theTopo->Upper();
43 Standard_Integer aNodesLowerIdx = theNodes.Lower();
44 myNodes = new TColgp_HArray1OfPnt (aNodesLowerIdx, theNodes.Upper());
45 myCenter = gp_XYZ (0.0, 0.0, 0.0);
46
47 for (Standard_Integer aPlaneIdx = aPlaneLowIdx; aPlaneIdx <= aPlaneUpIdx; ++aPlaneIdx)
48 {
49 Standard_Integer aVertNb = theTopo->Value (aPlaneIdx).Length();
50 Handle(TColgp_HArray1OfPnt) aVertArray = new TColgp_HArray1OfPnt (0, aVertNb - 1);
51 for (Standard_Integer aVertIdx = 1; aVertIdx <= aVertNb; ++aVertIdx)
52 {
53 Standard_Integer aNodeIdx = theTopo->Value (aPlaneIdx).Value (aVertIdx);
54 const gp_Pnt& aVert = theNodes.Value (aNodeIdx + aNodesLowerIdx);
55 aVertArray->SetValue (aVertIdx - 1, aVert);
56 myNodes->SetValue (aNodeIdx + aNodesLowerIdx, aVert);
57 myBndBox.Add (SelectMgr_Vec3 (aVert.X(), aVert.Y(), aVert.Z()));
58 myCenter += aVert.XYZ();
59 }
60
61 myTopology.Append (aVertArray);
62 }
63
64 myCenter.Divide (theNodes.Length());
65 }
66
67 //================================================================
68 // Function : GetConnected
69 // Purpose :
70 //================================================================
Handle(Select3D_SensitiveEntity)71 Handle(Select3D_SensitiveEntity) MeshVS_SensitivePolyhedron::GetConnected()
72 {
73 Handle(MeshVS_SensitivePolyhedron) aNewEnt = new
74 MeshVS_SensitivePolyhedron (myOwnerId, myNodes->Array1(), myTopo);
75
76 return aNewEnt;
77 }
78
79 //=======================================================================
80 // function : Matches
81 // purpose :
82 //=======================================================================
Matches(SelectBasics_SelectingVolumeManager & theMgr,SelectBasics_PickResult & thePickResult)83 Standard_Boolean MeshVS_SensitivePolyhedron::Matches (SelectBasics_SelectingVolumeManager& theMgr,
84 SelectBasics_PickResult& thePickResult)
85 {
86 SelectBasics_PickResult aPickResult;
87 for (MeshVS_PolyhedronVertsIter aIter (myTopology); aIter.More(); aIter.Next())
88 {
89 if (theMgr.OverlapsPolygon (aIter.Value()->Array1(), Select3D_TOS_INTERIOR, aPickResult))
90 {
91 thePickResult = SelectBasics_PickResult::Min (thePickResult, aPickResult);
92 }
93 }
94 if (!thePickResult.IsValid())
95 {
96 return Standard_False;
97 }
98
99 thePickResult.SetDistToGeomCenter (theMgr.DistToGeometryCenter (CenterOfGeometry()));
100 return Standard_True;
101 }
102
103 //=======================================================================
104 // function : NbSubElements
105 // purpose : Returns the amount of nodes of polyhedron
106 //=======================================================================
NbSubElements() const107 Standard_Integer MeshVS_SensitivePolyhedron::NbSubElements() const
108 {
109 return myNodes->Length();
110 }
111
112 //=======================================================================
113 // function : BoundingBox
114 // purpose :
115 //=======================================================================
BoundingBox()116 Select3D_BndBox3d MeshVS_SensitivePolyhedron::BoundingBox()
117 {
118 return myBndBox;
119 }
120
121 //=======================================================================
122 // function : CenterOfGeometry
123 // purpose :
124 //=======================================================================
CenterOfGeometry() const125 gp_Pnt MeshVS_SensitivePolyhedron::CenterOfGeometry() const
126 {
127 return myCenter;
128 }
129