1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
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 /*****************************************************************************\
40 *****************************************************************************
42 ** This file is automatically generated. **
44 ** Any changes made to this file WILL be lost when it is **
45 ** regenerated, which can become necessary at any time. **
47 ** Do not change this file, changes should be done in the derived **
50 *****************************************************************************
51 \*****************************************************************************/
57 #pragma warning(disable: 4355) // turn off 'this' : used in base member initializer list warning
58 #pragma warning(disable: 4290) // disable exception specification warning
61 #include "OSGConfig.h"
66 #include "OSGDistanceLODBase.h"
67 #include "OSGDistanceLOD.h"
69 #include <boost/bind.hpp>
73 /***************************************************************************\
75 \***************************************************************************/
77 /*! \class OSG::DistanceLOD
78 This Node manages the different levels of detail available for a Geometry
79 and decides which one should be rendered, according to the distance from the
80 current camera. The details of the selection process are taken from VRML97
83 The node chooses which child to render based on the range values in the Range
84 multi-field and the current distance of the camera from the object.
85 The children should be ordered from the highest level of detail to the
86 lowest level of detail. The range values specify the distances at which to
87 switch between the different children.
89 The center field is a translation offset in the local coordinate system that
90 specifies the center of the object for distance calculations. In order to
91 calculate which level to display, first the distance from the
92 viewpoint to the center point of the LOD node (with corresponding
93 transformations) is computed. If the distance is less than the first range
94 value, then the first LOD is drawn. If it is between the first and the second
95 values, then the second LOD is drawn, and so on.
97 \example Setting up a OSG::DistanceLOD
99 Here is an example of setting up an lod core with a center and a range.
100 You would also need to add children for the 4 LODs.
103 DistanceLOD lod = DistanceLOD::create();
105 // this is supposed to be the center of the LOD model,
106 // that is, this is the point the distance is measured from
107 lod->setCenter(12,1,5);
108 // now we add the distances when models will change
109 lod->editMFRange()->push_back(6.0);
110 lod->editMFRange()->push_back(12.0);
111 lod->editMFRange()->push_back(24.0);
116 /***************************************************************************\
117 * Field Documentation *
118 \***************************************************************************/
120 /*! \var Pnt3f DistanceLODBase::_sfCenter
121 The center for distance calculation.
124 /*! \var Real32 DistanceLODBase::_mfRange
129 /***************************************************************************\
130 * FieldType/FieldTrait Instantiation *
131 \***************************************************************************/
133 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
134 PointerType FieldTraits
<DistanceLOD
*, nsOSG
>::_type(
137 DistanceLOD::getClassType(),
141 OSG_FIELDTRAITS_GETTYPE_NS(DistanceLOD
*, nsOSG
)
143 /***************************************************************************\
144 * Field Description *
145 \***************************************************************************/
147 void DistanceLODBase::classDescInserter(TypeObject
&oType
)
149 FieldDescriptionBase
*pDesc
= NULL
;
152 pDesc
= new SFPnt3f::Description(
153 SFPnt3f::getClassType(),
155 "The center for distance calculation.\n",
156 CenterFieldId
, CenterFieldMask
,
158 (Field::SFDefaultFlags
| Field::FStdAccess
),
159 static_cast<FieldEditMethodSig
>(&DistanceLOD::editHandleCenter
),
160 static_cast<FieldGetMethodSig
>(&DistanceLOD::getHandleCenter
));
162 oType
.addInitialDesc(pDesc
);
164 pDesc
= new MFReal32::Description(
165 MFReal32::getClassType(),
167 "The range intervals.\n",
168 RangeFieldId
, RangeFieldMask
,
170 (Field::MFDefaultFlags
| Field::FStdAccess
),
171 static_cast<FieldEditMethodSig
>(&DistanceLOD::editHandleRange
),
172 static_cast<FieldGetMethodSig
>(&DistanceLOD::getHandleRange
));
174 oType
.addInitialDesc(pDesc
);
178 DistanceLODBase::TypeObject
DistanceLODBase::_type(
179 DistanceLODBase::getClassname(),
180 Inherited::getClassname(),
183 reinterpret_cast<PrototypeCreateF
>(&DistanceLODBase::createEmptyLocal
),
184 reinterpret_cast<InitContainerF
>(&DistanceLOD::initMethod
),
185 reinterpret_cast<ExitContainerF
>(&DistanceLOD::exitMethod
),
186 reinterpret_cast<InitalInsertDescFunc
>(
187 reinterpret_cast<void *>(&DistanceLOD::classDescInserter
)),
190 "<?xml version=\"1.0\"?>\n"
193 " name=\"DistanceLOD\"\n"
194 " parent=\"Group\"\n"
195 " library=\"Group\"\n"
196 " pointerfieldtypes=\"none\"\n"
197 " structure=\"concrete\"\n"
198 " systemcomponent=\"true\"\n"
199 " parentsystemcomponent=\"true\"\n"
200 " isNodeCore=\"true\"\n"
201 " docGroupBase=\"GrpGroupMisc\"\n"
203 "This Node manages the different levels of detail available for a Geometry\n"
204 "and decides which one should be rendered, according to the distance from the\n"
205 "current camera. The details of the selection process are taken from VRML97\n"
208 "The node chooses which child to render based on the range values in the Range\n"
209 "multi-field and the current distance of the camera from the object. \n"
210 "The children should be ordered from the highest level of detail to the \n"
211 "lowest level of detail. The range values specify the distances at which to \n"
212 "switch between the different children.\n"
214 "The center field is a translation offset in the local coordinate system that\n"
215 "specifies the center of the object for distance calculations. In order to\n"
216 "calculate which level to display, first the distance from the \n"
217 "viewpoint to the center point of the LOD node (with corresponding \n"
218 "transformations) is computed. If the distance is less than the first range\n"
219 "value, then the first LOD is drawn. If it is between the first and the second\n"
220 "values, then the second LOD is drawn, and so on.\n"
222 "\\example Setting up a OSG::DistanceLOD\n"
224 "Here is an example of setting up an lod core with a center and a range.\n"
225 "You would also need to add children for the 4 LODs.\n"
228 "DistanceLOD lod = DistanceLOD::create();\n"
230 "// this is supposed to be the center of the LOD model,\n"
231 "// that is, this is the point the distance is measured from\n"
232 "lod->setCenter(12,1,5);\n"
233 "// now we add the distances when models will change\n"
234 "lod->editMFRange()->push_back(6.0);\n"
235 "lod->editMFRange()->push_back(12.0);\n"
236 "lod->editMFRange()->push_back(24.0);\n"
240 "\t name=\"center\"\n"
241 "\t type=\"Pnt3f\"\n"
242 "\t cardinality=\"single\"\n"
243 "\t visibility=\"external\"\n"
244 "\t access=\"public\"\n"
246 "\tThe center for distance calculation.\n"
249 "\t name=\"range\"\n"
250 "\t type=\"Real32\"\n"
251 "\t cardinality=\"multi\"\n"
252 "\t visibility=\"external\"\n"
253 "\t access=\"public\"\n"
255 "\tThe range intervals.\n"
257 "</FieldContainer>\n",
258 "This Node manages the different levels of detail available for a Geometry\n"
259 "and decides which one should be rendered, according to the distance from the\n"
260 "current camera. The details of the selection process are taken from VRML97\n"
263 "The node chooses which child to render based on the range values in the Range\n"
264 "multi-field and the current distance of the camera from the object. \n"
265 "The children should be ordered from the highest level of detail to the \n"
266 "lowest level of detail. The range values specify the distances at which to \n"
267 "switch between the different children.\n"
269 "The center field is a translation offset in the local coordinate system that\n"
270 "specifies the center of the object for distance calculations. In order to\n"
271 "calculate which level to display, first the distance from the \n"
272 "viewpoint to the center point of the LOD node (with corresponding \n"
273 "transformations) is computed. If the distance is less than the first range\n"
274 "value, then the first LOD is drawn. If it is between the first and the second\n"
275 "values, then the second LOD is drawn, and so on.\n"
277 "\\example Setting up a OSG::DistanceLOD\n"
279 "Here is an example of setting up an lod core with a center and a range.\n"
280 "You would also need to add children for the 4 LODs.\n"
283 "DistanceLOD lod = DistanceLOD::create();\n"
285 "// this is supposed to be the center of the LOD model,\n"
286 "// that is, this is the point the distance is measured from\n"
287 "lod->setCenter(12,1,5);\n"
288 "// now we add the distances when models will change\n"
289 "lod->editMFRange()->push_back(6.0);\n"
290 "lod->editMFRange()->push_back(12.0);\n"
291 "lod->editMFRange()->push_back(24.0);\n"
296 /*------------------------------ get -----------------------------------*/
298 FieldContainerType
&DistanceLODBase::getType(void)
303 const FieldContainerType
&DistanceLODBase::getType(void) const
308 UInt32
DistanceLODBase::getContainerSize(void) const
310 return sizeof(DistanceLOD
);
313 /*------------------------- decorator get ------------------------------*/
316 SFPnt3f
*DistanceLODBase::editSFCenter(void)
318 editSField(CenterFieldMask
);
323 const SFPnt3f
*DistanceLODBase::getSFCenter(void) const
329 MFReal32
*DistanceLODBase::editMFRange(void)
331 editMField(RangeFieldMask
, _mfRange
);
336 const MFReal32
*DistanceLODBase::getMFRange(void) const
346 /*------------------------------ access -----------------------------------*/
348 SizeT
DistanceLODBase::getBinSize(ConstFieldMaskArg whichField
)
350 SizeT returnValue
= Inherited::getBinSize(whichField
);
352 if(FieldBits::NoField
!= (CenterFieldMask
& whichField
))
354 returnValue
+= _sfCenter
.getBinSize();
356 if(FieldBits::NoField
!= (RangeFieldMask
& whichField
))
358 returnValue
+= _mfRange
.getBinSize();
364 void DistanceLODBase::copyToBin(BinaryDataHandler
&pMem
,
365 ConstFieldMaskArg whichField
)
367 Inherited::copyToBin(pMem
, whichField
);
369 if(FieldBits::NoField
!= (CenterFieldMask
& whichField
))
371 _sfCenter
.copyToBin(pMem
);
373 if(FieldBits::NoField
!= (RangeFieldMask
& whichField
))
375 _mfRange
.copyToBin(pMem
);
379 void DistanceLODBase::copyFromBin(BinaryDataHandler
&pMem
,
380 ConstFieldMaskArg whichField
)
382 Inherited::copyFromBin(pMem
, whichField
);
384 if(FieldBits::NoField
!= (CenterFieldMask
& whichField
))
386 editSField(CenterFieldMask
);
387 _sfCenter
.copyFromBin(pMem
);
389 if(FieldBits::NoField
!= (RangeFieldMask
& whichField
))
391 editMField(RangeFieldMask
, _mfRange
);
392 _mfRange
.copyFromBin(pMem
);
396 //! create a new instance of the class
397 DistanceLODTransitPtr
DistanceLODBase::createLocal(BitVector bFlags
)
399 DistanceLODTransitPtr fc
;
401 if(getClassType().getPrototype() != NULL
)
403 FieldContainerTransitPtr tmpPtr
=
404 getClassType().getPrototype()-> shallowCopyLocal(bFlags
);
406 fc
= dynamic_pointer_cast
<DistanceLOD
>(tmpPtr
);
412 //! create a new instance of the class, copy the container flags
413 DistanceLODTransitPtr
DistanceLODBase::createDependent(BitVector bFlags
)
415 DistanceLODTransitPtr fc
;
417 if(getClassType().getPrototype() != NULL
)
419 FieldContainerTransitPtr tmpPtr
=
420 getClassType().getPrototype()-> shallowCopyDependent(bFlags
);
422 fc
= dynamic_pointer_cast
<DistanceLOD
>(tmpPtr
);
428 //! create a new instance of the class
429 DistanceLODTransitPtr
DistanceLODBase::create(void)
431 DistanceLODTransitPtr fc
;
433 if(getClassType().getPrototype() != NULL
)
435 FieldContainerTransitPtr tmpPtr
=
436 getClassType().getPrototype()-> shallowCopy();
438 fc
= dynamic_pointer_cast
<DistanceLOD
>(tmpPtr
);
444 DistanceLOD
*DistanceLODBase::createEmptyLocal(BitVector bFlags
)
446 DistanceLOD
*returnValue
;
448 newPtr
<DistanceLOD
>(returnValue
, bFlags
);
450 returnValue
->_pFieldFlags
->_bNamespaceMask
&= ~bFlags
;
455 //! create an empty new instance of the class, do not copy the prototype
456 DistanceLOD
*DistanceLODBase::createEmpty(void)
458 DistanceLOD
*returnValue
;
460 newPtr
<DistanceLOD
>(returnValue
, Thread::getCurrentLocalFlags());
462 returnValue
->_pFieldFlags
->_bNamespaceMask
&=
463 ~Thread::getCurrentLocalFlags();
469 FieldContainerTransitPtr
DistanceLODBase::shallowCopyLocal(
470 BitVector bFlags
) const
474 newPtr(tmpPtr
, dynamic_cast<const DistanceLOD
*>(this), bFlags
);
476 FieldContainerTransitPtr
returnValue(tmpPtr
);
478 tmpPtr
->_pFieldFlags
->_bNamespaceMask
&= ~bFlags
;
483 FieldContainerTransitPtr
DistanceLODBase::shallowCopyDependent(
484 BitVector bFlags
) const
488 newPtr(tmpPtr
, dynamic_cast<const DistanceLOD
*>(this), ~bFlags
);
490 FieldContainerTransitPtr
returnValue(tmpPtr
);
492 tmpPtr
->_pFieldFlags
->_bNamespaceMask
= bFlags
;
497 FieldContainerTransitPtr
DistanceLODBase::shallowCopy(void) const
502 dynamic_cast<const DistanceLOD
*>(this),
503 Thread::getCurrentLocalFlags());
505 tmpPtr
->_pFieldFlags
->_bNamespaceMask
&= ~Thread::getCurrentLocalFlags();
507 FieldContainerTransitPtr
returnValue(tmpPtr
);
515 /*------------------------- constructors ----------------------------------*/
517 DistanceLODBase::DistanceLODBase(void) :
524 DistanceLODBase::DistanceLODBase(const DistanceLODBase
&source
) :
526 _sfCenter (source
._sfCenter
),
527 _mfRange (source
._mfRange
)
532 /*-------------------------- destructors ----------------------------------*/
534 DistanceLODBase::~DistanceLODBase(void)
539 GetFieldHandlePtr
DistanceLODBase::getHandleCenter (void) const
541 SFPnt3f::GetHandlePtr
returnValue(
542 new SFPnt3f::GetHandle(
544 this->getType().getFieldDesc(CenterFieldId
),
545 const_cast<DistanceLODBase
*>(this)));
550 EditFieldHandlePtr
DistanceLODBase::editHandleCenter (void)
552 SFPnt3f::EditHandlePtr
returnValue(
553 new SFPnt3f::EditHandle(
555 this->getType().getFieldDesc(CenterFieldId
),
559 editSField(CenterFieldMask
);
564 GetFieldHandlePtr
DistanceLODBase::getHandleRange (void) const
566 MFReal32::GetHandlePtr
returnValue(
567 new MFReal32::GetHandle(
569 this->getType().getFieldDesc(RangeFieldId
),
570 const_cast<DistanceLODBase
*>(this)));
575 EditFieldHandlePtr
DistanceLODBase::editHandleRange (void)
577 MFReal32::EditHandlePtr
returnValue(
578 new MFReal32::EditHandle(
580 this->getType().getFieldDesc(RangeFieldId
),
584 editMField(RangeFieldMask
, _mfRange
);
590 #ifdef OSG_MT_CPTR_ASPECT
591 void DistanceLODBase::execSyncV( FieldContainer
&oFrom
,
592 ConstFieldMaskArg whichField
,
593 AspectOffsetStore
&oOffsets
,
594 ConstFieldMaskArg syncMode
,
595 const UInt32 uiSyncInfo
)
597 DistanceLOD
*pThis
= static_cast<DistanceLOD
*>(this);
599 pThis
->execSync(static_cast<DistanceLOD
*>(&oFrom
),
608 #ifdef OSG_MT_CPTR_ASPECT
609 FieldContainer
*DistanceLODBase::createAspectCopy(
610 const FieldContainer
*pRefAspect
) const
612 DistanceLOD
*returnValue
;
614 newAspectCopy(returnValue
,
615 dynamic_cast<const DistanceLOD
*>(pRefAspect
),
616 dynamic_cast<const DistanceLOD
*>(this));
622 void DistanceLODBase::resolveLinks(void)
624 Inherited::resolveLinks();
626 #ifdef OSG_MT_CPTR_ASPECT
627 AspectOffsetStore oOffsets
;
629 _pAspectStore
->fillOffsetArray(oOffsets
, this);
632 #ifdef OSG_MT_CPTR_ASPECT
633 _mfRange
.terminateShare(Thread::getCurrentAspect(),