fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Drawables / Geometry / Util / OSGIntersectKDTreeNodeFields.cpp
blobc7916a8d643b3603e3bb5b1838578d759ff06e79
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2011 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
30 #include "OSGIntersectKDTreeNodeFields.h"
32 #include "OSGExportDefines.h"
33 #include "OSGFieldContainer.h"
34 #include "OSGMField.ins"
35 #include "OSGSField.ins"
37 OSG_BEGIN_NAMESPACE
39 DataType FieldTraits<IntersectKDTreeNode>::_type("IntersectKDTreeNode", NULL);
41 OSG_FIELD_DLLEXPORT_DEF1(SField, IntersectKDTreeNode)
42 OSG_FIELD_DLLEXPORT_DEF1(MField, IntersectKDTreeNode)
44 OSG_FIELDTRAITS_GETTYPE(IntersectKDTreeNode)
46 /* static */ const Char8 *
47 FieldTraits<IntersectKDTreeNode>::getSName(void)
49 return "SFIntersectKDTreeNode";
52 /* static */ const Char8 *
53 FieldTraits<IntersectKDTreeNode>::getMName(void)
55 return "MFIntersectKDTreeNode";
58 /* static */
59 SizeT FieldTraits<IntersectKDTreeNode>::getBinSize(const IntersectKDTreeNode &)
61 return 2 * sizeof(UInt32);
64 /* static */
65 SizeT FieldTraits<IntersectKDTreeNode>::getBinSize(
66 const IntersectKDTreeNode *pObjectStore,
67 SizeT uiNumObjects)
69 return uiNumObjects * 2 * sizeof(UInt32);
72 /* static */ void
73 FieldTraits<IntersectKDTreeNode>::copyToBin(
74 BinaryDataHandler &pMem,
75 const IntersectKDTreeNode &oObject)
77 if(oObject.isLeaf())
79 UInt32 count = oObject.getTriCount() << 2;
80 count |= IntersectKDTreeNode::Leaf;
82 UInt32 triOffset = oObject.getTriOffset();
84 pMem.putValue(count );
85 pMem.putValue(triOffset);
87 else
89 UInt32 childOffset = oObject.getChildOffset() << 2;
90 childOffset |= oObject.getSplitAxis();
92 Real32 split = oObject.getSplit();
94 pMem.putValue(childOffset);
95 pMem.putValue(split );
99 /* static */ void
100 FieldTraits<IntersectKDTreeNode>::copyToBin(
101 BinaryDataHandler &pMem,
102 const IntersectKDTreeNode *pObjectStore,
103 SizeT uiNumObjects)
105 for(SizeT i = 0; i < uiNumObjects; ++i)
107 copyToBin(pMem, pObjectStore[i]);
111 /* static */ void
112 FieldTraits<IntersectKDTreeNode>::copyFromBin(
113 BinaryDataHandler &pMem,
114 IntersectKDTreeNode &oObject)
116 UInt32 count;
118 pMem.getValue(count);
120 UInt32 flags = count & 0x03;
121 count >>= 2;
123 if(flags == IntersectKDTreeNode::Leaf)
125 UInt32 triOffset;
126 pMem.getValue(triOffset);
128 oObject.setLeaf(count, triOffset);
130 else
132 Real32 split;
133 pMem.getValue(split);
135 oObject.setInterior(static_cast<IntersectKDTreeNode::FlagsE>(flags),
136 count, split);
140 /* static */ void
141 FieldTraits<IntersectKDTreeNode>::copyFromBin(
142 BinaryDataHandler &pMem,
143 IntersectKDTreeNode *pObjectStore,
144 SizeT uiNumObjects )
146 for(SizeT i = 0; i < uiNumObjects; ++i)
148 copyFromBin(pMem, pObjectStore[i]);
152 OSG_END_NAMESPACE