1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2011 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
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. *
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. *
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. *
28 \*---------------------------------------------------------------------------*/
30 #include "OSGIntersectKDTreeNodeFields.h"
32 #include "OSGExportDefines.h"
33 #include "OSGFieldContainer.h"
34 #include "OSGMField.ins"
35 #include "OSGSField.ins"
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";
59 SizeT FieldTraits
<IntersectKDTreeNode
>::getBinSize(const IntersectKDTreeNode
&)
61 return 2 * sizeof(UInt32
);
65 SizeT FieldTraits
<IntersectKDTreeNode
>::getBinSize(
66 const IntersectKDTreeNode
*pObjectStore
,
69 return uiNumObjects
* 2 * sizeof(UInt32
);
73 FieldTraits
<IntersectKDTreeNode
>::copyToBin(
74 BinaryDataHandler
&pMem
,
75 const IntersectKDTreeNode
&oObject
)
79 UInt32 count
= oObject
.getTriCount() << 2;
80 count
|= IntersectKDTreeNode::Leaf
;
82 UInt32 triOffset
= oObject
.getTriOffset();
84 pMem
.putValue(count
);
85 pMem
.putValue(triOffset
);
89 UInt32 childOffset
= oObject
.getChildOffset() << 2;
90 childOffset
|= oObject
.getSplitAxis();
92 Real32 split
= oObject
.getSplit();
94 pMem
.putValue(childOffset
);
95 pMem
.putValue(split
);
100 FieldTraits
<IntersectKDTreeNode
>::copyToBin(
101 BinaryDataHandler
&pMem
,
102 const IntersectKDTreeNode
*pObjectStore
,
105 for(SizeT i
= 0; i
< uiNumObjects
; ++i
)
107 copyToBin(pMem
, pObjectStore
[i
]);
112 FieldTraits
<IntersectKDTreeNode
>::copyFromBin(
113 BinaryDataHandler
&pMem
,
114 IntersectKDTreeNode
&oObject
)
118 pMem
.getValue(count
);
120 UInt32 flags
= count
& 0x03;
123 if(flags
== IntersectKDTreeNode::Leaf
)
126 pMem
.getValue(triOffset
);
128 oObject
.setLeaf(count
, triOffset
);
133 pMem
.getValue(split
);
135 oObject
.setInterior(static_cast<IntersectKDTreeNode::FlagsE
>(flags
),
141 FieldTraits
<IntersectKDTreeNode
>::copyFromBin(
142 BinaryDataHandler
&pMem
,
143 IntersectKDTreeNode
*pObjectStore
,
146 for(SizeT i
= 0; i
< uiNumObjects
; ++i
)
148 copyFromBin(pMem
, pObjectStore
[i
]);