0030349: Coding - add usage of Standard_EXPORT for some not inline methods in Select3D
[occt.git] / src / Select3D / Select3D_BVHIndexBuffer.hxx
1 // Created on: 2016-02-25
2 // Created by: Kirill Gavrilov
3 // Copyright (c) 2016 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _Select3D_BVHIndexBuffer_Header
17 #define _Select3D_BVHIndexBuffer_Header
18
19 #include <Graphic3d_Buffer.hxx>
20 #include <Graphic3d_IndexBuffer.hxx>
21 #include <Select3D_SensitiveSet.hxx>
22 #include <TColStd_HArray1OfInteger.hxx>
23
24 //! Index buffer for BVH tree.
25 class Select3D_BVHIndexBuffer : public Graphic3d_Buffer
26 {
27 public:
28
29   //! Empty constructor.
30   Select3D_BVHIndexBuffer (const Handle(NCollection_BaseAllocator)& theAlloc)
31   : Graphic3d_Buffer (theAlloc), myHasPatches (false) {}
32
33   bool HasPatches() const { return myHasPatches; }
34
35   //! Allocates new empty index array
36   bool Init (const Standard_Integer theNbElems,
37              const bool theHasPatches)
38   {
39     release();
40     Stride = sizeof(unsigned int);
41     myHasPatches = theHasPatches;
42     if (theHasPatches)
43     {
44       Stride += sizeof(unsigned int);
45     }
46
47     NbElements   = theNbElems;
48     NbAttributes = 0;
49     if (NbElements != 0
50     && !Allocate (size_t(Stride) * size_t(NbElements)))
51     {
52       release();
53       return false;
54     }
55     return true;
56   }
57
58   //! Access index at specified position
59   Standard_Integer Index (const Standard_Integer theIndex) const
60   {
61     return Standard_Integer(*reinterpret_cast<const unsigned int* >(value (theIndex)));
62   }
63
64   //! Access index at specified position
65   Standard_Integer PatchSize (const Standard_Integer theIndex) const
66   {
67     return myHasPatches
68          ? Standard_Integer(*reinterpret_cast<const unsigned int* >(value (theIndex) + sizeof(unsigned int)))
69          : 1;
70   }
71
72   //! Change index at specified position
73   void SetIndex (const Standard_Integer theIndex,
74                  const Standard_Integer theValue)
75   {
76     *reinterpret_cast<unsigned int* >(changeValue (theIndex)) = (unsigned int )theValue;
77   }
78
79   //! Change index at specified position
80   void SetIndex (const Standard_Integer theIndex,
81                  const Standard_Integer theValue,
82                  const Standard_Integer thePatchSize)
83   {
84     *reinterpret_cast<unsigned int* >(changeValue (theIndex))                        = (unsigned int )theValue;
85     *reinterpret_cast<unsigned int* >(changeValue (theIndex) + sizeof(unsigned int)) = (unsigned int )thePatchSize;
86   }
87
88 private:
89
90   bool myHasPatches;
91   
92 public:
93
94   DEFINE_STANDARD_RTTI_INLINE(Select3D_BVHIndexBuffer,Graphic3d_Buffer)
95
96 };
97
98 DEFINE_STANDARD_HANDLE(Select3D_BVHIndexBuffer, Graphic3d_Buffer)
99
100 #endif // _Select3D_BVHIndexBuffer_Header