File indexing completed on 2025-01-18 10:04:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _Select3D_SensitivePrimitiveArray_Header
0017 #define _Select3D_SensitivePrimitiveArray_Header
0018
0019 #include <Graphic3d_IndexBuffer.hxx>
0020 #include <Graphic3d_TypeOfPrimitiveArray.hxx>
0021 #include <Select3D_SensitiveSet.hxx>
0022 #include <Select3D_BVHIndexBuffer.hxx>
0023 #include <TColStd_HPackedMapOfInteger.hxx>
0024
0025
0026
0027
0028 class Select3D_SensitivePrimitiveArray : public Select3D_SensitiveSet
0029 {
0030
0031 public:
0032
0033
0034 Standard_EXPORT Select3D_SensitivePrimitiveArray (const Handle(SelectMgr_EntityOwner)& theOwnerId);
0035
0036
0037 Standard_Integer PatchSizeMax() const { return myPatchSizeMax; }
0038
0039
0040
0041 void SetPatchSizeMax (const Standard_Integer thePatchSizeMax) { myPatchSizeMax = thePatchSizeMax; }
0042
0043
0044
0045 float PatchDistance() const { return myPatchDistance; }
0046
0047
0048
0049 void SetPatchDistance (const float thePatchDistMax) { myPatchDistance = thePatchDistMax; }
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061 Standard_EXPORT bool InitTriangulation (const Handle(Graphic3d_Buffer)& theVerts,
0062 const Handle(Graphic3d_IndexBuffer)& theIndices,
0063 const TopLoc_Location& theInitLoc,
0064 const Standard_Integer theIndexLower,
0065 const Standard_Integer theIndexUpper,
0066 const bool theToEvalMinMax = true,
0067 const Standard_Integer theNbGroups = 1);
0068
0069
0070
0071
0072
0073
0074
0075 bool InitTriangulation (const Handle(Graphic3d_Buffer)& theVerts,
0076 const Handle(Graphic3d_IndexBuffer)& theIndices,
0077 const TopLoc_Location& theInitLoc,
0078 const bool theToEvalMinMax = true,
0079 const Standard_Integer theNbGroups = 1)
0080 {
0081 const Standard_Integer anUpper = !theIndices.IsNull() ? (theIndices->NbElements - 1)
0082 : (!theVerts.IsNull() ? (theVerts->NbElements - 1) : 0);
0083 return InitTriangulation (theVerts, theIndices, theInitLoc, 0, anUpper, theToEvalMinMax, theNbGroups);
0084 }
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 Standard_EXPORT bool InitPoints (const Handle(Graphic3d_Buffer)& theVerts,
0097 const Handle(Graphic3d_IndexBuffer)& theIndices,
0098 const TopLoc_Location& theInitLoc,
0099 const Standard_Integer theIndexLower,
0100 const Standard_Integer theIndexUpper,
0101 const bool theToEvalMinMax = true,
0102 const Standard_Integer theNbGroups = 1);
0103
0104
0105
0106
0107
0108
0109
0110 bool InitPoints (const Handle(Graphic3d_Buffer)& theVerts,
0111 const Handle(Graphic3d_IndexBuffer)& theIndices,
0112 const TopLoc_Location& theInitLoc,
0113 const bool theToEvalMinMax = true,
0114 const Standard_Integer theNbGroups = 1)
0115 {
0116 const Standard_Integer anUpper = !theIndices.IsNull() ? (theIndices->NbElements - 1)
0117 : (!theVerts.IsNull() ? (theVerts->NbElements - 1) : 0);
0118 return InitPoints (theVerts, theIndices, theInitLoc, 0, anUpper, theToEvalMinMax, theNbGroups);
0119 }
0120
0121
0122
0123
0124
0125
0126 bool InitPoints (const Handle(Graphic3d_Buffer)& theVerts,
0127 const TopLoc_Location& theInitLoc,
0128 const bool theToEvalMinMax = true,
0129 const Standard_Integer theNbGroups = 1)
0130 {
0131 const Standard_Integer anUpper = !theVerts.IsNull() ? (theVerts->NbElements - 1) : 0;
0132 return InitPoints (theVerts, Handle(Graphic3d_IndexBuffer)(), theInitLoc, 0, anUpper, theToEvalMinMax, theNbGroups);
0133 }
0134
0135
0136 void SetMinMax (double theMinX, double theMinY, double theMinZ,
0137 double theMaxX, double theMaxY, double theMaxZ)
0138 {
0139 myBndBox = Select3D_BndBox3d (SelectMgr_Vec3 (theMinX, theMinY, theMinZ),
0140 SelectMgr_Vec3 (theMaxX, theMaxY, theMaxZ));
0141 if (!myGroups.IsNull())
0142 {
0143 for (Select3D_PrimArraySubGroupArray::Iterator aGroupIter (*myGroups); aGroupIter.More(); aGroupIter.Next())
0144 {
0145 aGroupIter.Value()->myBndBox = myBndBox;
0146 }
0147 }
0148 }
0149
0150
0151 bool ToDetectElements() const { return myToDetectElem; }
0152
0153
0154 void SetDetectElements (bool theToDetect) { myToDetectElem = theToDetect; }
0155
0156
0157 bool ToDetectElementMap() const { return !myDetectedElemMap.IsNull(); }
0158
0159
0160 Standard_EXPORT void SetDetectElementMap (bool theToDetect);
0161
0162
0163 bool ToDetectNodes() const { return myToDetectNode; }
0164
0165
0166 void SetDetectNodes (bool theToDetect) { myToDetectNode = theToDetect; }
0167
0168
0169 bool ToDetectNodeMap() const { return !myDetectedNodeMap.IsNull(); }
0170
0171
0172 Standard_EXPORT void SetDetectNodeMap (bool theToDetect);
0173
0174
0175 bool ToDetectEdges() const { return myToDetectEdge; }
0176
0177
0178 void SetDetectEdges (bool theToDetect) { myToDetectEdge = theToDetect; }
0179
0180
0181 Standard_Integer LastDetectedElement() const { return myDetectedElem; }
0182
0183
0184 const Handle(TColStd_HPackedMapOfInteger)& LastDetectedElementMap() const { return myDetectedElemMap; }
0185
0186
0187 Standard_Integer LastDetectedNode() const { return myDetectedNode; }
0188
0189
0190 const Handle(TColStd_HPackedMapOfInteger)& LastDetectedNodeMap() const { return myDetectedNodeMap; }
0191
0192
0193 Standard_Integer LastDetectedEdgeNode1() const { return myDetectedEdgeNode1; }
0194
0195
0196 Standard_Integer LastDetectedEdgeNode2() const { return myDetectedEdgeNode2; }
0197
0198
0199 Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
0200
0201 public:
0202
0203
0204 Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
0205 SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
0206
0207 Standard_EXPORT virtual Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
0208
0209
0210 Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
0211
0212
0213 virtual Standard_Integer NbSubElements() const Standard_OVERRIDE
0214 {
0215 return !myGroups.IsNull() ? myGroups->Size() : myBvhIndices.NbElements;
0216 }
0217
0218
0219 Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
0220
0221
0222
0223 Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
0224 const Standard_Integer theAxis) const Standard_OVERRIDE;
0225
0226
0227 Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
0228 const Standard_Integer theIdx2) Standard_OVERRIDE;
0229
0230
0231
0232 Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
0233
0234
0235
0236 virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE
0237 {
0238 return myCDG3D;
0239 }
0240
0241
0242 virtual Standard_Boolean HasInitLocation() const Standard_OVERRIDE
0243 {
0244 return !myInitLocation.IsIdentity();
0245 }
0246
0247
0248
0249 virtual gp_GTrsf InvInitLocation() const Standard_OVERRIDE
0250 {
0251 return myInvInitLocation;
0252 }
0253
0254
0255 Standard_EXPORT virtual void Set (const Handle(SelectMgr_EntityOwner)& theOwnerId) Standard_OVERRIDE;
0256
0257
0258 Standard_EXPORT virtual void BVH() Standard_OVERRIDE;
0259
0260 protected:
0261
0262
0263 Standard_EXPORT void computeBoundingBox();
0264
0265
0266
0267 Standard_EXPORT Select3D_BndBox3d applyTransformation();
0268
0269
0270 const Graphic3d_Vec3& getPosVec3 (const Standard_Integer theIndex) const
0271 {
0272 return *reinterpret_cast<const Graphic3d_Vec3* >(myPosData + myPosStride * theIndex);
0273 }
0274
0275
0276 const Graphic3d_Vec2& getPosVec2 (const Standard_Integer theIndex) const
0277 {
0278 return *reinterpret_cast<const Graphic3d_Vec2* >(myPosData + myPosStride * theIndex);
0279 }
0280
0281
0282 Standard_EXPORT virtual Standard_Boolean overlapsElement (SelectBasics_PickResult& thePickResult,
0283 SelectBasics_SelectingVolumeManager& theMgr,
0284 Standard_Integer theElemIdx,
0285 Standard_Boolean theIsFullInside) Standard_OVERRIDE;
0286
0287
0288 Standard_EXPORT virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) Standard_OVERRIDE;
0289
0290
0291 Standard_EXPORT virtual Standard_Boolean elementIsInside (SelectBasics_SelectingVolumeManager& theMgr,
0292 Standard_Integer theElemIdx,
0293 Standard_Boolean theIsFullInside) Standard_OVERRIDE;
0294
0295 private:
0296
0297 typedef NCollection_Shared<NCollection_Array1<Handle(Select3D_SensitivePrimitiveArray)> > Select3D_PrimArraySubGroupArray;
0298 struct Select3D_SensitivePrimitiveArray_InitFunctor;
0299 struct Select3D_SensitivePrimitiveArray_BVHFunctor;
0300
0301 private:
0302
0303 Handle(Select3D_PrimArraySubGroupArray) myGroups;
0304
0305 Handle(Graphic3d_Buffer) myVerts;
0306 Handle(Graphic3d_IndexBuffer) myIndices;
0307 const Standard_Byte* myPosData;
0308 Standard_Size myPosStride;
0309 Graphic3d_TypeOfPrimitiveArray myPrimType;
0310 Standard_Integer myIndexLower;
0311 Standard_Integer myIndexUpper;
0312 Standard_Integer myPatchSizeMax;
0313 float myPatchDistance;
0314 bool myIs3d;
0315 TopLoc_Location myInitLocation;
0316 gp_Pnt myCDG3D;
0317 Select3D_BVHIndexBuffer myBvhIndices;
0318 mutable Select3D_BndBox3d myBndBox;
0319 gp_GTrsf myInvInitLocation;
0320 Handle(TColStd_HPackedMapOfInteger) myDetectedElemMap;
0321 Handle(TColStd_HPackedMapOfInteger) myDetectedNodeMap;
0322 Standard_Real myMinDepthElem;
0323 Standard_Real myMinDepthNode;
0324 Standard_Real myMinDepthEdge;
0325 Standard_Integer myDetectedElem;
0326 Standard_Integer myDetectedNode;
0327 Standard_Integer myDetectedEdgeNode1;
0328 Standard_Integer myDetectedEdgeNode2;
0329 bool myToDetectElem;
0330 bool myToDetectNode;
0331 bool myToDetectEdge;
0332
0333 public:
0334
0335 DEFINE_STANDARD_RTTIEXT(Select3D_SensitivePrimitiveArray, Select3D_SensitiveSet)
0336
0337 };
0338
0339 DEFINE_STANDARD_HANDLE(Select3D_SensitivePrimitiveArray, Select3D_SensitiveSet)
0340
0341 #endif