1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2002 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 \*---------------------------------------------------------------------------*/
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"
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 /*-------------------------------------------------------------------------*/
68 void VisitSubTree::changed(ConstFieldMaskArg whichField
,
72 Inherited::changed(whichField
, origin
, details
);
74 if(whichField
& SubTreeRootFieldMask
)
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
));
93 value
->addChangedFunctor(
94 boost::bind(&VisitSubTree::rootChanged
, this, _1
, _2
, _3
),
98 _sfSubTreeRoot
.setValue(value
);
101 void VisitSubTree::rootChanged(FieldContainer
*pFC
,
102 ConstFieldMaskArg whichField
,
105 if(0x0000 != (whichField
& Node::VolumeFieldMask
))
107 this->invalidateVolume();
111 /*-------------------------------------------------------------------------*/
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 /*-------------------------------------------------------------------------*/
123 VisitSubTree::VisitSubTree(void) :
128 VisitSubTree::VisitSubTree(const VisitSubTree
&source
) :
133 /*-------------------------------------------------------------------------*/
136 VisitSubTree::~VisitSubTree(void)
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 /*-------------------------------------------------------------------------*/
158 Action::ResultE
VisitSubTree::renderEnter(Action
*action
)
160 RenderAction
*a
= dynamic_cast<RenderAction
*>(action
);
166 switch(_sfTravMaskMode
.getValue())
168 case VisitSubTree::AndTravMask
:
169 a
->andTravMask(_sfSubTreeTravMask
.getValue());
171 case VisitSubTree::OrTravMask
:
172 a
->orTravMask(_sfSubTreeTravMask
.getValue());
174 case VisitSubTree::ReplaceTravMask
:
175 a
->setTravMask(_sfSubTreeTravMask
.getValue());
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 /*-------------------------------------------------------------------------*/
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 /*-------------------------------------------------------------------------*/
218 /*-------------------------------------------------------------------------*/
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(
237 reinterpret_cast<Action::Callback
>(&VisitSubTree::intersectEnter
));