Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-13 09:17:39

0001 // Created on: 2016-02-25
0002 // Created by: Kirill Gavrilov
0003 // Copyright (c) 2016 OPEN CASCADE SAS
0004 //
0005 // This file is part of Open CASCADE Technology software library.
0006 //
0007 // This library is free software; you can redistribute it and/or modify it under
0008 // the terms of the GNU Lesser General Public License version 2.1 as published
0009 // by the Free Software Foundation, with special exception defined in the file
0010 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0011 // distribution for complete text of the license and disclaimer of any warranty.
0012 //
0013 // Alternatively, this file may be used under the terms of Open CASCADE
0014 // commercial license or contractual agreement.
0015 
0016 #ifndef _Select3D_BVHIndexBuffer_Header
0017 #define _Select3D_BVHIndexBuffer_Header
0018 
0019 #include <Graphic3d_Buffer.hxx>
0020 
0021 //! Index buffer for BVH tree.
0022 class Select3D_BVHIndexBuffer : public Graphic3d_Buffer
0023 {
0024 public:
0025   //! Empty constructor.
0026   Select3D_BVHIndexBuffer(const occ::handle<NCollection_BaseAllocator>& theAlloc)
0027       : Graphic3d_Buffer(theAlloc),
0028         myHasPatches(false)
0029   {
0030   }
0031 
0032   bool HasPatches() const { return myHasPatches; }
0033 
0034   //! Allocates new empty index array
0035   bool Init(const int theNbElems, const bool theHasPatches)
0036   {
0037     release();
0038     Stride       = sizeof(unsigned int);
0039     myHasPatches = theHasPatches;
0040     if (theHasPatches)
0041     {
0042       Stride += sizeof(unsigned int);
0043     }
0044 
0045     NbElements   = theNbElems;
0046     NbAttributes = 0;
0047     if (NbElements != 0 && !Allocate(size_t(Stride) * size_t(NbElements)))
0048     {
0049       release();
0050       return false;
0051     }
0052     return true;
0053   }
0054 
0055   //! Access index at specified position
0056   int Index(const int theIndex) const
0057   {
0058     return int(*reinterpret_cast<const unsigned int*>(value(theIndex)));
0059   }
0060 
0061   //! Access index at specified position
0062   int PatchSize(const int theIndex) const
0063   {
0064     return myHasPatches
0065              ? int(*reinterpret_cast<const unsigned int*>(value(theIndex) + sizeof(unsigned int)))
0066              : 1;
0067   }
0068 
0069   //! Change index at specified position
0070   void SetIndex(const int theIndex, const int theValue)
0071   {
0072     *reinterpret_cast<unsigned int*>(changeValue(theIndex)) = (unsigned int)theValue;
0073   }
0074 
0075   //! Change index at specified position
0076   void SetIndex(const int theIndex, const int theValue, const int thePatchSize)
0077   {
0078     *reinterpret_cast<unsigned int*>(changeValue(theIndex)) = (unsigned int)theValue;
0079     *reinterpret_cast<unsigned int*>(changeValue(theIndex) + sizeof(unsigned int)) =
0080       (unsigned int)thePatchSize;
0081   }
0082 
0083 private:
0084   bool myHasPatches;
0085 
0086 public:
0087   DEFINE_STANDARD_RTTI_INLINE(Select3D_BVHIndexBuffer, Graphic3d_Buffer)
0088 };
0089 
0090 #endif // _Select3D_BVHIndexBuffer_Header