1 // Created on: 2005-01-21
2 // Created by: Alexander SOLOVYOV
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <MeshVS_SensitivePolyhedron.hxx>
19 #include <MeshVS_HArray1OfSequenceOfInteger.hxx>
20 #include <MeshVS_Tool.hxx>
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>
30 IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitivePolyhedron,Select3D_SensitiveEntity)
32 //================================================================
33 // Function : Constructor MeshVS_SensitivePolyhedron
35 //================================================================
36 MeshVS_SensitivePolyhedron::MeshVS_SensitivePolyhedron (const Handle(SelectBasics_EntityOwner)& theOwner,
37 const TColgp_Array1OfPnt& theNodes,
38 const Handle(MeshVS_HArray1OfSequenceOfInteger)& theTopo)
39 : Select3D_SensitiveEntity (theOwner),
42 Standard_Integer aPlaneLowIdx = theTopo->Lower();
43 Standard_Integer aPlaneUpIdx = theTopo->Upper();
44 Standard_Integer aNodesLowerIdx = theNodes.Lower();
45 myNodes = new TColgp_HArray1OfPnt (aNodesLowerIdx, theNodes.Upper());
46 myCenter = gp_XYZ (0.0, 0.0, 0.0);
48 for (Standard_Integer aPlaneIdx = aPlaneLowIdx; aPlaneIdx <= aPlaneUpIdx; ++aPlaneIdx)
50 Standard_Integer aVertNb = theTopo->Value (aPlaneIdx).Length();
51 Handle(TColgp_HArray1OfPnt) aVertArray = new TColgp_HArray1OfPnt (0, aVertNb - 1);
52 for (Standard_Integer aVertIdx = 1; aVertIdx <= aVertNb; ++aVertIdx)
54 Standard_Integer aNodeIdx = theTopo->Value (aPlaneIdx).Value (aVertIdx);
55 const gp_Pnt& aVert = theNodes.Value (aNodeIdx + aNodesLowerIdx);
56 aVertArray->SetValue (aVertIdx - 1, aVert);
57 myNodes->SetValue (aNodeIdx + aNodesLowerIdx, aVert);
58 myBndBox.Add (SelectMgr_Vec3 (aVert.X(), aVert.Y(), aVert.Z()));
59 myCenter += aVert.XYZ();
62 myTopology.Append (aVertArray);
65 myCenter.Divide (theNodes.Length());
68 //================================================================
69 // Function : GetConnected
71 //================================================================
72 Handle(Select3D_SensitiveEntity) MeshVS_SensitivePolyhedron::GetConnected()
74 Handle(MeshVS_SensitivePolyhedron) aNewEnt = new
75 MeshVS_SensitivePolyhedron (myOwnerId, myNodes->Array1(), myTopo);
80 //=======================================================================
83 //=======================================================================
84 Standard_Boolean MeshVS_SensitivePolyhedron::Matches (SelectBasics_SelectingVolumeManager& theMgr,
85 SelectBasics_PickResult& thePickResult)
87 Standard_Real aDepthMin = RealLast();
88 Standard_Real aDistToCOG = RealLast();
90 for (MeshVS_PolyhedronVertsIter aIter (myTopology); aIter.More(); aIter.Next())
92 Standard_Real aDepth = RealLast();
93 if (theMgr.Overlaps (aIter.Value(), Select3D_TOS_INTERIOR, aDepth))
95 aDepthMin = Min (aDepth, aDepthMin);
99 aDistToCOG = aDepthMin == RealLast() ? RealLast() : theMgr.DistToGeometryCenter (myCenter);
100 thePickResult = SelectBasics_PickResult (aDepthMin, aDistToCOG);
102 return aDepthMin != RealLast();
105 //=======================================================================
106 // function : NbSubElements
107 // purpose : Returns the amount of nodes of polyhedron
108 //=======================================================================
109 Standard_Integer MeshVS_SensitivePolyhedron::NbSubElements()
111 return myNodes->Length();
114 //=======================================================================
115 // function : BoundingBox
117 //=======================================================================
118 Select3D_BndBox3d MeshVS_SensitivePolyhedron::BoundingBox()
123 //=======================================================================
124 // function : CenterOfGeometry
126 //=======================================================================
127 gp_Pnt MeshVS_SensitivePolyhedron::CenterOfGeometry() const