871fa103 |
1 | // Copyright (c) 2014 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #ifndef _Graphic3d_BoundBuffer_HeaderFile |
15 | #define _Graphic3d_BoundBuffer_HeaderFile |
16 | |
17 | #include <Graphic3d_Buffer.hxx> |
18 | |
19 | //! Bounds buffer. |
20 | class Graphic3d_BoundBuffer : public NCollection_Buffer |
21 | { |
34253146 |
22 | DEFINE_STANDARD_RTTIEXT(Graphic3d_BoundBuffer, NCollection_Buffer) |
871fa103 |
23 | public: |
24 | |
25 | //! Empty constructor. |
26 | Graphic3d_BoundBuffer (const Handle(NCollection_BaseAllocator)& theAlloc) |
27 | : NCollection_Buffer (theAlloc), |
28 | Colors (NULL), |
29 | Bounds (NULL), |
34253146 |
30 | NbBounds (0), |
31 | NbMaxBounds (0) {} |
871fa103 |
32 | |
33 | //! Allocates new empty array |
34 | bool Init (const Standard_Integer theNbBounds, |
35 | const Standard_Boolean theHasColors) |
36 | { |
37 | Colors = NULL; |
38 | Bounds = NULL; |
39 | NbBounds = 0; |
34253146 |
40 | NbMaxBounds = 0; |
871fa103 |
41 | Free(); |
42 | if (theNbBounds < 1) |
43 | { |
44 | return false; |
45 | } |
46 | |
47 | const size_t aBoundsSize = sizeof(Standard_Integer) * theNbBounds; |
48 | const size_t aColorsSize = theHasColors |
49 | ? sizeof(Graphic3d_Vec4) * theNbBounds |
50 | : 0; |
51 | if (!Allocate (aColorsSize + aBoundsSize)) |
52 | { |
53 | Free(); |
54 | return false; |
55 | } |
56 | |
57 | NbBounds = theNbBounds; |
34253146 |
58 | NbMaxBounds = theNbBounds; |
871fa103 |
59 | Colors = theHasColors ? reinterpret_cast<Graphic3d_Vec4* >(myData) : NULL; |
60 | Bounds = reinterpret_cast<Standard_Integer* >(theHasColors ? (myData + aColorsSize) : myData); |
61 | return true; |
62 | } |
63 | |
bc73b006 |
64 | //! Dumps the content of me into the stream |
65 | virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE |
66 | { |
67 | OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream) |
68 | OCCT_DUMP_BASE_CLASS (theOStream, theDepth, NCollection_Buffer) |
69 | |
70 | OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, Colors) |
71 | OCCT_DUMP_FIELD_VALUE_POINTER (theOStream, Bounds) |
72 | |
73 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, NbBounds) |
74 | OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, NbMaxBounds) |
75 | } |
76 | |
871fa103 |
77 | public: |
78 | |
34253146 |
79 | Graphic3d_Vec4* Colors; //!< pointer to facet color values |
80 | Standard_Integer* Bounds; //!< pointer to bounds array |
81 | Standard_Integer NbBounds; //!< number of bounds |
82 | Standard_Integer NbMaxBounds; //!< number of allocated bounds |
7d3e64ef |
83 | |
871fa103 |
84 | }; |
85 | |
7d3e64ef |
86 | DEFINE_STANDARD_HANDLE(Graphic3d_BoundBuffer, NCollection_Buffer) |
871fa103 |
87 | |
88 | #endif // _Graphic3d_BoundBuffer_HeaderFile |