1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2006 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 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGVALUEACCUMULATOR_H_
40 #define _OSGVALUEACCUMULATOR_H_
46 #include "OSGConfig.h"
47 #include "OSGContribCSMDef.h"
49 #include "OSGCounter.h" // Parent
51 #include "OSGSysFields.h" // Step type
52 #include "OSGBaseFields.h"
53 #include "OSGMathFields.h"
54 #include "OSGVecFields.h"
58 //! \brief Real32Counter Base Class.
61 class SValueAccumulator
: public NodeCore
65 typedef NodeCore Inherited
;
66 typedef NodeCore ParentContainer
;
67 typedef SValueAccumulator Self
;
69 typedef Inherited::TypeObject TypeObject
;
70 typedef TypeObject::InitPhase InitPhase
;
72 OSG_GEN_INTERNALPTR(Self
);
74 /*========================== PUBLIC =================================*/
80 ValueFieldId
= Inherited::NextFieldId
,
81 RhsFieldId
= ValueFieldId
+ 1,
82 NextFieldId
= RhsFieldId
+ 1
85 static const OSG::BitVector ValueFieldMask
=
86 (TypeTraits
<BitVector
>::One
<< ValueFieldId
);
88 static const OSG::BitVector RhsFieldMask
=
89 (TypeTraits
<BitVector
>::One
<< RhsFieldId
);
91 typedef typename
Desc::SFValueType SFValueType
;
92 typedef typename
SFValueType::StoredType ValueType
;
94 /*---------------------------------------------------------------------*/
95 /*! \name Class Get */
98 static FieldContainerType
&getClassType (void);
99 static UInt32
getClassTypeId (void);
100 static UInt16
getClassGroupId(void);
101 static const Char8
*getClassname (void);
104 /*---------------------------------------------------------------------*/
105 /*! \name FieldContainer Get */
108 virtual FieldContainerType
&getType (void);
109 virtual const FieldContainerType
&getType (void) const;
111 virtual UInt32
getContainerSize(void) const;
114 /*---------------------------------------------------------------------*/
115 /*! \name Field Get */
119 SFValueType
*editSFValue (void);
120 const SFValueType
*getSFValue (void) const;
122 ValueType
&editValue (void);
123 ValueType
getValue (void) const;
125 SFValueType
*editSFRhs (void);
126 const SFValueType
*getSFRhs (void) const;
128 ValueType
&editRhs (void);
129 ValueType
getRhs (void) const;
132 /*---------------------------------------------------------------------*/
133 /*! \name Field Set */
136 void setValue(const ValueType value
);
137 void setRhs (const ValueType value
);
140 /*---------------------------------------------------------------------*/
141 /*! \name Ptr MField Set */
144 virtual void changed(ConstFieldMaskArg whichField
,
149 /*---------------------------------------------------------------------*/
150 /*! \name Binary Access */
153 virtual SizeT
getBinSize (ConstFieldMaskArg whichField
);
154 virtual void copyToBin (BinaryDataHandler
&pMem
,
155 ConstFieldMaskArg whichField
);
156 virtual void copyFromBin(BinaryDataHandler
&pMem
,
157 ConstFieldMaskArg whichField
);
161 /*---------------------------------------------------------------------*/
162 /*! \name Construction */
165 static ObjTransitPtr
create (void );
166 static Self
*createEmpty (void );
168 static ObjTransitPtr
createLocal (BitVector bFlags
= FCLocal::All
);
169 static ObjTransitPtr
createDependent (BitVector bFlags
= FCLocal::All
);
171 static Self
*createEmptyLocal(BitVector bFlags
= FCLocal::All
);
174 /*---------------------------------------------------------------------*/
178 virtual FieldContainerTransitPtr
shallowCopy (void) const;
179 virtual FieldContainerTransitPtr
shallowCopyLocal(
180 BitVector bFlags
= FCLocal::All
) const;
181 virtual FieldContainerTransitPtr
shallowCopyDependent(
182 BitVector bFlags
) const;
185 /*========================= PROTECTED ===============================*/
189 static TypeObject _type
;
191 static void classDescInserter(TypeObject
&oType
);
193 /*---------------------------------------------------------------------*/
197 SFValueType _sfValue
;
201 /*---------------------------------------------------------------------*/
202 /*! \name Constructors */
205 SValueAccumulator(void);
206 SValueAccumulator(const SValueAccumulator
&source
);
209 /*---------------------------------------------------------------------*/
210 /*! \name Destructors */
213 virtual ~SValueAccumulator(void);
216 /*---------------------------------------------------------------------*/
217 /*! \name onCreate */
221 /*---------------------------------------------------------------------*/
222 /*! \name Generic Field Access */
225 GetFieldHandlePtr
getHandleValue (void) const;
226 EditFieldHandlePtr
editHandleValue (void);
228 GetFieldHandlePtr
getHandleRhs (void) const;
229 EditFieldHandlePtr
editHandleRhs (void);
233 /*---------------------------------------------------------------------*/
237 #ifdef OSG_MT_CPTR_ASPECT
238 virtual void execSyncV( FieldContainer
&oFrom
,
239 ConstFieldMaskArg whichField
,
240 AspectOffsetStore
&oOffsets
,
241 ConstFieldMaskArg syncMode
,
242 const UInt32 uiSyncInfo
);
244 void execSync ( Self
*pFrom
,
245 ConstFieldMaskArg whichField
,
246 AspectOffsetStore
&oOffsets
,
247 ConstFieldMaskArg syncMode
,
248 const UInt32 uiSyncInfo
);
252 /*---------------------------------------------------------------------*/
257 /*---------------------------------------------------------------------*/
258 /*! \name Aspect Create */
261 #ifdef OSG_MT_CPTR_ASPECT
262 virtual FieldContainer
*createAspectCopy(
263 const FieldContainer
*pRefAspect
) const;
267 /*---------------------------------------------------------------------*/
271 /*---------------------------------------------------------------------*/
275 virtual void resolveLinks(void);
278 /*---------------------------------------------------------------------*/
282 static void initMethod(InitPhase ePhase
);
285 /*========================== PRIVATE ================================*/
289 friend class FieldContainer
;
291 /*---------------------------------------------------------------------*/
293 // prohibit default functions (move to 'public' if you need one)
294 void operator =(const SValueAccumulator
&source
);
298 struct Int32EmitterDesc
300 typedef SFInt32 SFValueType
;
302 static const Char8
*getClassname(void)
304 return "Int32Emitter";
307 static Int32
getDefault(void)
314 struct Real32AccumulatorDesc
316 typedef SFReal32 SFValueType
;
318 static const Char8
*getClassname(void)
320 return "Real32Accumulator";
323 static Real32
getDefault(void)
328 static void accumulate( Real32
&result
,
335 struct Vec2fAccumulatorDesc
337 typedef SFVec2f SFValueType
;
339 static const Char8
*getClassname(void)
341 return "Vec2fAccumulator";
344 static Vec2f
getDefault(void)
346 return Vec2f(0.f
, 0.f
);
349 static void accumulate( Vec2f
&result
,
354 fprintf(stderr
, "step : %f %f, res : %f %f\n",
362 struct MatrixAccumulatorDesc
364 typedef SFMatrix SFValueType
;
366 static const Char8
*getClassname(void)
368 return "MatrixAccumulator";
371 static Matrix
getDefault(void)
380 static void accumulate( Matrix
&result
,
387 //typedef SValueEmitter<Int32EmitterDesc > Int32Emitter;
388 typedef SValueAccumulator
<Real32AccumulatorDesc
> Real32Accumulator
;
389 typedef SValueAccumulator
<Vec2fAccumulatorDesc
> Vec2fAccumulator
;
390 typedef SValueAccumulator
<MatrixAccumulatorDesc
> MatrixAccumulator
;
394 #include "OSGValueAccumulator.inl"
396 #endif /* _OSGVALUEACCUMULATOR_H_ */