Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:52

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 
0026   //! Empty constructor.
0027   Select3D_BVHIndexBuffer (const Handle(NCollection_BaseAllocator)& theAlloc)
0028   : Graphic3d_Buffer (theAlloc), myHasPatches (false) {}
0029 
0030   bool HasPatches() const { return myHasPatches; }
0031 
0032   //! Allocates new empty index array
0033   bool Init (const Standard_Integer theNbElems,
0034              const bool theHasPatches)
0035   {
0036     release();
0037     Stride = sizeof(unsigned int);
0038     myHasPatches = theHasPatches;
0039     if (theHasPatches)
0040     {
0041       Stride += sizeof(unsigned int);
0042     }
0043 
0044     NbElements   = theNbElems;
0045     NbAttributes = 0;
0046     if (NbElements != 0
0047     && !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   Standard_Integer Index (const Standard_Integer theIndex) const
0057   {
0058     return Standard_Integer(*reinterpret_cast<const unsigned int* >(value (theIndex)));
0059   }
0060 
0061   //! Access index at specified position
0062   Standard_Integer PatchSize (const Standard_Integer theIndex) const
0063   {
0064     return myHasPatches
0065          ? Standard_Integer(*reinterpret_cast<const unsigned int* >(value (theIndex) + sizeof(unsigned int)))
0066          : 1;
0067   }
0068 
0069   //! Change index at specified position
0070   void SetIndex (const Standard_Integer theIndex,
0071                  const Standard_Integer theValue)
0072   {
0073     *reinterpret_cast<unsigned int* >(changeValue (theIndex)) = (unsigned int )theValue;
0074   }
0075 
0076   //! Change index at specified position
0077   void SetIndex (const Standard_Integer theIndex,
0078                  const Standard_Integer theValue,
0079                  const Standard_Integer thePatchSize)
0080   {
0081     *reinterpret_cast<unsigned int* >(changeValue (theIndex))                        = (unsigned int )theValue;
0082     *reinterpret_cast<unsigned int* >(changeValue (theIndex) + sizeof(unsigned int)) = (unsigned int )thePatchSize;
0083   }
0084 
0085 private:
0086 
0087   bool myHasPatches;
0088   
0089 public:
0090 
0091   DEFINE_STANDARD_RTTI_INLINE(Select3D_BVHIndexBuffer,Graphic3d_Buffer)
0092 
0093 };
0094 
0095 DEFINE_STANDARD_HANDLE(Select3D_BVHIndexBuffer, Graphic3d_Buffer)
0096 
0097 #endif // _Select3D_BVHIndexBuffer_Header