fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Groups / Misc / OSGDistanceLODBase.cpp
blobed1a3fdf0afe601330066e0e10569a2aaa4e60f8
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2013 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, carsten_neumann@gmx.net *
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 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 /*****************************************************************************\
40 *****************************************************************************
41 ** **
42 ** This file is automatically generated. **
43 ** **
44 ** Any changes made to this file WILL be lost when it is **
45 ** regenerated, which can become necessary at any time. **
46 ** **
47 ** Do not change this file, changes should be done in the derived **
48 ** class DistanceLOD!
49 ** **
50 *****************************************************************************
51 \*****************************************************************************/
53 #include <cstdlib>
54 #include <cstdio>
56 #ifdef WIN32
57 #pragma warning(disable: 4355) // turn off 'this' : used in base member initializer list warning
58 #pragma warning(disable: 4290) // disable exception specification warning
59 #endif
61 #include "OSGConfig.h"
66 #include "OSGDistanceLODBase.h"
67 #include "OSGDistanceLOD.h"
69 #include <boost/bind.hpp>
71 OSG_BEGIN_NAMESPACE
73 /***************************************************************************\
74 * Description *
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
81 standard.
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.
102 \code
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);
112 \endcode
113 \endexample
116 /***************************************************************************\
117 * Field Documentation *
118 \***************************************************************************/
120 /*! \var Pnt3f DistanceLODBase::_sfCenter
121 The center for distance calculation.
124 /*! \var Real32 DistanceLODBase::_mfRange
125 The range intervals.
129 /***************************************************************************\
130 * FieldType/FieldTrait Instantiation *
131 \***************************************************************************/
133 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
134 PointerType FieldTraits<DistanceLOD *, nsOSG>::_type(
135 "DistanceLODPtr",
136 "GroupPtr",
137 DistanceLOD::getClassType(),
138 nsOSG);
139 #endif
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(),
154 "center",
155 "The center for distance calculation.\n",
156 CenterFieldId, CenterFieldMask,
157 false,
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(),
166 "range",
167 "The range intervals.\n",
168 RangeFieldId, RangeFieldMask,
169 false,
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(),
181 "NULL",
182 nsOSG, //Namespace
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)),
188 false,
190 "<?xml version=\"1.0\"?>\n"
191 "\n"
192 "<FieldContainer\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"
202 " ><![CDATA[\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"
206 "standard. \n"
207 "\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"
213 "\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"
221 "\n"
222 "\\example Setting up a OSG::DistanceLOD\n"
223 "\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"
226 "\n"
227 "\\code\n"
228 "DistanceLOD lod = DistanceLOD::create();\n"
229 "\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"
237 "\\endcode\n"
238 "\\endexample]]>\n"
239 " <Field\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"
245 "\t >\n"
246 "\tThe center for distance calculation.\n"
247 " </Field>\n"
248 " <Field\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"
254 "\t >\n"
255 "\tThe range intervals.\n"
256 " </Field>\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"
261 "standard. \n"
262 "\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"
268 "\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"
276 "\n"
277 "\\example Setting up a OSG::DistanceLOD\n"
278 "\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"
281 "\n"
282 "\\code\n"
283 "DistanceLOD lod = DistanceLOD::create();\n"
284 "\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"
292 "\\endcode\n"
293 "\\endexample\n"
296 /*------------------------------ get -----------------------------------*/
298 FieldContainerType &DistanceLODBase::getType(void)
300 return _type;
303 const FieldContainerType &DistanceLODBase::getType(void) const
305 return _type;
308 UInt32 DistanceLODBase::getContainerSize(void) const
310 return sizeof(DistanceLOD);
313 /*------------------------- decorator get ------------------------------*/
316 SFPnt3f *DistanceLODBase::editSFCenter(void)
318 editSField(CenterFieldMask);
320 return &_sfCenter;
323 const SFPnt3f *DistanceLODBase::getSFCenter(void) const
325 return &_sfCenter;
329 MFReal32 *DistanceLODBase::editMFRange(void)
331 editMField(RangeFieldMask, _mfRange);
333 return &_mfRange;
336 const MFReal32 *DistanceLODBase::getMFRange(void) const
338 return &_mfRange;
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();
361 return returnValue;
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);
409 return fc;
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);
425 return fc;
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);
441 return fc;
444 DistanceLOD *DistanceLODBase::createEmptyLocal(BitVector bFlags)
446 DistanceLOD *returnValue;
448 newPtr<DistanceLOD>(returnValue, bFlags);
450 returnValue->_pFieldFlags->_bNamespaceMask &= ~bFlags;
452 return returnValue;
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();
465 return returnValue;
469 FieldContainerTransitPtr DistanceLODBase::shallowCopyLocal(
470 BitVector bFlags) const
472 DistanceLOD *tmpPtr;
474 newPtr(tmpPtr, dynamic_cast<const DistanceLOD *>(this), bFlags);
476 FieldContainerTransitPtr returnValue(tmpPtr);
478 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~bFlags;
480 return returnValue;
483 FieldContainerTransitPtr DistanceLODBase::shallowCopyDependent(
484 BitVector bFlags) const
486 DistanceLOD *tmpPtr;
488 newPtr(tmpPtr, dynamic_cast<const DistanceLOD *>(this), ~bFlags);
490 FieldContainerTransitPtr returnValue(tmpPtr);
492 tmpPtr->_pFieldFlags->_bNamespaceMask = bFlags;
494 return returnValue;
497 FieldContainerTransitPtr DistanceLODBase::shallowCopy(void) const
499 DistanceLOD *tmpPtr;
501 newPtr(tmpPtr,
502 dynamic_cast<const DistanceLOD *>(this),
503 Thread::getCurrentLocalFlags());
505 tmpPtr->_pFieldFlags->_bNamespaceMask &= ~Thread::getCurrentLocalFlags();
507 FieldContainerTransitPtr returnValue(tmpPtr);
509 return returnValue;
515 /*------------------------- constructors ----------------------------------*/
517 DistanceLODBase::DistanceLODBase(void) :
518 Inherited(),
519 _sfCenter (),
520 _mfRange ()
524 DistanceLODBase::DistanceLODBase(const DistanceLODBase &source) :
525 Inherited(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(
543 &_sfCenter,
544 this->getType().getFieldDesc(CenterFieldId),
545 const_cast<DistanceLODBase *>(this)));
547 return returnValue;
550 EditFieldHandlePtr DistanceLODBase::editHandleCenter (void)
552 SFPnt3f::EditHandlePtr returnValue(
553 new SFPnt3f::EditHandle(
554 &_sfCenter,
555 this->getType().getFieldDesc(CenterFieldId),
556 this));
559 editSField(CenterFieldMask);
561 return returnValue;
564 GetFieldHandlePtr DistanceLODBase::getHandleRange (void) const
566 MFReal32::GetHandlePtr returnValue(
567 new MFReal32::GetHandle(
568 &_mfRange,
569 this->getType().getFieldDesc(RangeFieldId),
570 const_cast<DistanceLODBase *>(this)));
572 return returnValue;
575 EditFieldHandlePtr DistanceLODBase::editHandleRange (void)
577 MFReal32::EditHandlePtr returnValue(
578 new MFReal32::EditHandle(
579 &_mfRange,
580 this->getType().getFieldDesc(RangeFieldId),
581 this));
584 editMField(RangeFieldMask, _mfRange);
586 return returnValue;
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),
600 whichField,
601 oOffsets,
602 syncMode,
603 uiSyncInfo);
605 #endif
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));
618 return returnValue;
620 #endif
622 void DistanceLODBase::resolveLinks(void)
624 Inherited::resolveLinks();
626 #ifdef OSG_MT_CPTR_ASPECT
627 AspectOffsetStore oOffsets;
629 _pAspectStore->fillOffsetArray(oOffsets, this);
630 #endif
632 #ifdef OSG_MT_CPTR_ASPECT
633 _mfRange.terminateShare(Thread::getCurrentAspect(),
634 oOffsets);
635 #endif
639 OSG_END_NAMESPACE