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 //---------------------------------------------------------------------------
41 //---------------------------------------------------------------------------
45 #include <boost/cast.hpp>
47 #include "OSGConfig.h"
48 #include "OSGKDTreeIntersectProxyAttachment.h"
50 #include "OSGIntersectAction.h"
51 #include "OSGIntersectKDTree.h"
52 #include "OSGGeometry.h"
56 // Documentation for this class is emitted in the
57 // OSGKDTreeIntersectProxyAttachmentBase.cpp file.
58 // To modify it, please change the .fcd file (OSGKDTreeIntersectProxyAttachment.fcd) and
59 // regenerate the base file.
61 /***************************************************************************\
63 \***************************************************************************/
65 /***************************************************************************\
67 \***************************************************************************/
69 void KDTreeIntersectProxyAttachment::initMethod(InitPhase ePhase
)
71 Inherited::initMethod(ePhase
);
73 if(ePhase
== TypeObject::SystemPost
)
79 /***************************************************************************\
81 \***************************************************************************/
83 /*-------------------------------------------------------------------------*\
85 \*-------------------------------------------------------------------------*/
87 /*----------------------- constructors & destructors ----------------------*/
89 KDTreeIntersectProxyAttachment::KDTreeIntersectProxyAttachment(void) :
94 KDTreeIntersectProxyAttachment::KDTreeIntersectProxyAttachment(const KDTreeIntersectProxyAttachment
&source
) :
99 KDTreeIntersectProxyAttachment::~KDTreeIntersectProxyAttachment(void)
103 /*----------------------------- class specific ----------------------------*/
105 /* virtual */ Action::ResultE
106 KDTreeIntersectProxyAttachment::intersectEnter(Node
*node
, Action
*action
)
108 Action::ResultE res
= Inherited::intersectEnter(node
, action
);
109 IntersectAction
*iact
=
110 boost::polymorphic_downcast
<IntersectAction
*>(action
);
112 Real32 closestHitT
= iact
->didHit() ? iact
->getHitT() : iact
->getMaxDist();
116 if(_mfTreeNodes
.empty() == false)
119 bool hit
= intersectIntersectKDTree(iact
->getLine(),
121 _sfGeometry
.getValue(),
131 iact
->setHit(closestHitT
,
137 iact
->getStatCollector()->getElem(
138 IntersectAction::statNTriangles
)->add(numTris
);
142 // tree was empty - skip this proxy and use conventional
144 res
= Action::Continue
;
150 void KDTreeIntersectProxyAttachment::changed(ConstFieldMaskArg whichField
,
154 if(whichField
& GeometryFieldMask
)
156 editMField(TreeNodesFieldMask
, _mfTreeNodes
);
157 editMField(TriIndicesFieldMask
, _mfTriIndices
);
159 _mfTreeNodes
.clear();
160 _mfTriIndices
.clear();
162 buildIntersectKDTree(_sfGeometry
.getValue(),
163 _sfMaxDepth
.getValue(),
168 Inherited::changed(whichField
, origin
, details
);
171 void KDTreeIntersectProxyAttachment::dump( UInt32
,
172 const BitVector
) const
174 SLOG
<< "Dump KDTreeIntersectProxyAttachment NI" << std::endl
;