1 // Created on: 2016-02-25
2 // Created by: Kirill Gavrilov
3 // Copyright (c) 2016 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 #ifndef _Select3D_BVHIndexBuffer_Header
17 #define _Select3D_BVHIndexBuffer_Header
19 #include <Graphic3d_Buffer.hxx>
20 #include <Graphic3d_IndexBuffer.hxx>
21 #include <Select3D_SensitiveSet.hxx>
22 #include <TColStd_HArray1OfInteger.hxx>
24 //! Index buffer for BVH tree.
25 class Select3D_BVHIndexBuffer : public Graphic3d_Buffer
29 //! Empty constructor.
30 Select3D_BVHIndexBuffer (const Handle(NCollection_BaseAllocator)& theAlloc)
31 : Graphic3d_Buffer (theAlloc), myHasPatches (false) {}
33 bool HasPatches() const { return myHasPatches; }
35 //! Allocates new empty index array
36 bool Init (const Standard_Integer theNbElems,
37 const bool theHasPatches)
40 Stride = sizeof(unsigned int);
41 myHasPatches = theHasPatches;
44 Stride += sizeof(unsigned int);
47 NbElements = theNbElems;
50 && !Allocate (size_t(Stride) * size_t(NbElements)))
58 //! Access index at specified position
59 Standard_Integer Index (const Standard_Integer theIndex) const
61 return Standard_Integer(*reinterpret_cast<const unsigned int* >(value (theIndex)));
64 //! Access index at specified position
65 Standard_Integer PatchSize (const Standard_Integer theIndex) const
68 ? Standard_Integer(*reinterpret_cast<const unsigned int* >(value (theIndex) + sizeof(unsigned int)))
72 //! Change index at specified position
73 void SetIndex (const Standard_Integer theIndex,
74 const Standard_Integer theValue)
76 *reinterpret_cast<unsigned int* >(changeValue (theIndex)) = (unsigned int )theValue;
79 //! Change index at specified position
80 void SetIndex (const Standard_Integer theIndex,
81 const Standard_Integer theValue,
82 const Standard_Integer thePatchSize)
84 *reinterpret_cast<unsigned int* >(changeValue (theIndex)) = (unsigned int )theValue;
85 *reinterpret_cast<unsigned int* >(changeValue (theIndex) + sizeof(unsigned int)) = (unsigned int )thePatchSize;
94 DEFINE_STANDARD_RTTI_INLINE(Select3D_BVHIndexBuffer,Graphic3d_Buffer)
98 DEFINE_STANDARD_HANDLE(Select3D_BVHIndexBuffer, Graphic3d_Buffer)
100 #endif // _Select3D_BVHIndexBuffer_Header