// Created on: 2016-02-25 // Created by: Kirill Gavrilov // Copyright (c) 2016 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // // This library is free software; you can redistribute it and/or modify it under // the terms of the GNU Lesser General Public License version 2.1 as published // by the Free Software Foundation, with special exception defined in the file // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT // distribution for complete text of the license and disclaimer of any warranty. // // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. #ifndef _Select3D_BVHIndexBuffer_Header #define _Select3D_BVHIndexBuffer_Header #include "Graphic3d_Buffer.hxx" //! Index buffer for BVH tree. class Select3D_BVHIndexBuffer : public Graphic3d_Buffer { public: //! Empty constructor. Select3D_BVHIndexBuffer(const occ::handle& theAlloc) : Graphic3d_Buffer(theAlloc), myHasPatches(false) { } bool HasPatches() const { return myHasPatches; } //! Allocates new empty index array bool Init(const int theNbElems, const bool theHasPatches) { release(); Stride = sizeof(unsigned int); myHasPatches = theHasPatches; if (theHasPatches) { Stride += sizeof(unsigned int); } NbElements = theNbElems; NbAttributes = 0; if (NbElements != 0 && !Allocate(size_t(Stride) * size_t(NbElements))) { release(); return false; } return true; } //! Access index at specified position int Index(const int theIndex) const { return int(*reinterpret_cast(value(theIndex))); } //! Access index at specified position int PatchSize(const int theIndex) const { return myHasPatches ? int(*reinterpret_cast(value(theIndex) + sizeof(unsigned int))) : 1; } //! Change index at specified position void SetIndex(const int theIndex, const int theValue) { *reinterpret_cast(changeValue(theIndex)) = (unsigned int)theValue; } //! Change index at specified position void SetIndex(const int theIndex, const int theValue, const int thePatchSize) { *reinterpret_cast(changeValue(theIndex)) = (unsigned int)theValue; *reinterpret_cast(changeValue(theIndex) + sizeof(unsigned int)) = (unsigned int)thePatchSize; } private: bool myHasPatches; public: DEFINE_STANDARD_RTTI_INLINE(Select3D_BVHIndexBuffer, Graphic3d_Buffer) }; #endif // _Select3D_BVHIndexBuffer_Header