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