fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / NodeCores / Groups / Misc / OSGVisitSubTree.cpp
blob34340cf1f9e88d80d5571b9a574e562e2e29f0fc
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2002 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 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include <cstdlib>
40 #include <cstdio>
42 #include <sstream>
43 #include <fstream>
45 #include <boost/bind.hpp>
47 #include "OSGConfig.h"
49 #include "OSGAction.h"
50 #include "OSGCamera.h"
51 #include "OSGRenderAction.h"
52 #include "OSGSceneFileHandler.h"
53 #include "OSGVolumeDraw.h"
54 #include "OSGIntersectAction.h"
56 #include "OSGVisitSubTree.h"
58 OSG_USING_NAMESPACE
60 // Documentation for this class is emited in the
61 // OSGVisitSubTreeBase.cpp file.
62 // To modify it, please change the .fcd file (OSGVisitSubTree.fcd) and
63 // regenerate the base file.
65 /*-------------------------------------------------------------------------*/
66 /* Sync */
68 void VisitSubTree::changed(ConstFieldMaskArg whichField,
69 UInt32 origin,
70 BitVector details)
72 Inherited::changed(whichField, origin, details);
74 if(whichField & SubTreeRootFieldMask)
76 invalidateVolume();
80 //! Set the value of the VisitSubTree::_sfSubTreeRoot field.
81 void VisitSubTree::setSubTreeRoot(Node * const value)
83 editSField(SubTreeRootFieldMask);
85 if(_sfSubTreeRoot.getValue() != NULL)
87 _sfSubTreeRoot.getValue()->subChangedFunctor(
88 boost::bind(&VisitSubTree::rootChanged, this, _1, _2, _3));
91 if(value != NULL)
93 value->addChangedFunctor(
94 boost::bind(&VisitSubTree::rootChanged, this, _1, _2, _3),
95 "");
98 _sfSubTreeRoot.setValue(value);
101 void VisitSubTree::rootChanged(FieldContainer *pFC,
102 ConstFieldMaskArg whichField,
103 UInt32 origin )
105 if(0x0000 != (whichField & Node::VolumeFieldMask))
107 this->invalidateVolume();
111 /*-------------------------------------------------------------------------*/
112 /* Dump */
114 void VisitSubTree::dump( UInt32 OSG_CHECK_ARG(uiIndent),
115 const BitVector OSG_CHECK_ARG(bvFlags )) const
117 SLOG << "Dump VisitSubTree NI" << std::endl;
120 /*-------------------------------------------------------------------------*/
121 /* Constructors */
123 VisitSubTree::VisitSubTree(void) :
124 Inherited()
128 VisitSubTree::VisitSubTree(const VisitSubTree &source) :
129 Inherited(source)
133 /*-------------------------------------------------------------------------*/
134 /* Destructor */
136 VisitSubTree::~VisitSubTree(void)
140 /*!
141 If url was loaded, extend volume by loaded geometry. Otherwise
142 extend volume by the volume given in the proxy object
145 void VisitSubTree::adjustVolume(Volume &volume)
147 if(getSubTreeRoot() != NULL)
149 getSubTreeRoot()->updateVolume();
151 volume.extendBy(getSubTreeRoot()->getVolume());
155 /*-------------------------------------------------------------------------*/
156 /* Draw */
158 Action::ResultE VisitSubTree::renderEnter(Action *action)
160 RenderAction *a = dynamic_cast<RenderAction *>(action);
162 a->useNodeList();
164 a->pushTravMask();
166 switch(_sfTravMaskMode.getValue())
168 case VisitSubTree::AndTravMask:
169 a->andTravMask(_sfSubTreeTravMask.getValue());
170 break;
171 case VisitSubTree::OrTravMask:
172 a->orTravMask(_sfSubTreeTravMask.getValue());
173 break;
174 case VisitSubTree::ReplaceTravMask:
175 a->setTravMask(_sfSubTreeTravMask.getValue());
176 break;
177 default:
178 break;
181 if(this->getSubTreeRoot() != NULL && a->isVisible(this->getSubTreeRoot()))
183 a->addNode(this->getSubTreeRoot());
186 return Action::Continue;
189 Action::ResultE VisitSubTree::renderLeave(Action *action)
191 action->popTravMask();
193 return Action::Continue;
196 /*-------------------------------------------------------------------------*/
197 /* Intersect */
199 Action::ResultE VisitSubTree::intersectEnter(Action *action)
201 IntersectAction *ia = dynamic_cast<IntersectAction *>(action);
202 const BoxVolume &bv = ia->getActNode()->getVolume();
204 if(bv.isValid() && ! bv.intersect(ia->getLine()))
206 return Action::Skip; //bv missed -> can not hit children
209 ia->addNode(this->getSubTreeRoot());
211 return Action::Continue;
215 /*-------------------------------------------------------------------------*/
216 /* loading */
218 /*-------------------------------------------------------------------------*/
219 /* Init */
221 void VisitSubTree::initMethod(InitPhase ePhase)
223 Inherited::initMethod(ePhase);
225 if(ePhase == TypeObject::SystemPost)
227 RenderAction::registerEnterDefault(
228 VisitSubTree::getClassType(),
229 reinterpret_cast<Action::Callback>(&VisitSubTree::renderEnter));
231 RenderAction::registerLeaveDefault(
232 VisitSubTree::getClassType(),
233 reinterpret_cast<Action::Callback>(&VisitSubTree::renderLeave));
235 IntersectAction::registerEnterDefault(
236 getClassType(),
237 reinterpret_cast<Action::Callback>(&VisitSubTree::intersectEnter));