changed: gcc8 base update
[opensg.git] / Source / System / NodeCores / Drawables / Geometry / Util / OSGKDTreeIntersectProxyAttachment.cpp
blobaddd427d45115a2413beb85c926aaa14efd7fd25
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2006 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 //---------------------------------------------------------------------------
40 // Includes
41 //---------------------------------------------------------------------------
43 #include <cstdlib>
44 #include <cstdio>
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"
54 OSG_BEGIN_NAMESPACE
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 /***************************************************************************\
62 * Class variables *
63 \***************************************************************************/
65 /***************************************************************************\
66 * Class methods *
67 \***************************************************************************/
69 void KDTreeIntersectProxyAttachment::initMethod(InitPhase ePhase)
71 Inherited::initMethod(ePhase);
73 if(ePhase == TypeObject::SystemPost)
79 /***************************************************************************\
80 * Instance methods *
81 \***************************************************************************/
83 /*-------------------------------------------------------------------------*\
84 - private -
85 \*-------------------------------------------------------------------------*/
87 /*----------------------- constructors & destructors ----------------------*/
89 KDTreeIntersectProxyAttachment::KDTreeIntersectProxyAttachment(void) :
90 Inherited()
94 KDTreeIntersectProxyAttachment::KDTreeIntersectProxyAttachment(const KDTreeIntersectProxyAttachment &source) :
95 Inherited(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();
113 Vec3f hitNormal;
114 UInt32 hitTriangle;
116 if(_mfTreeNodes.empty() == false)
118 UInt32 numTris = 0;
119 bool hit = intersectIntersectKDTree(iact->getLine(),
120 node->getVolume(),
121 _sfGeometry.getValue(),
122 &_mfTreeNodes,
123 &_mfTriIndices,
124 closestHitT,
125 hitNormal,
126 hitTriangle,
127 &numTris );
129 if(hit == true)
131 iact->setHit(closestHitT,
132 node,
133 hitTriangle,
134 hitNormal, 0);
137 iact->getStatCollector()->getElem(
138 IntersectAction::statNTriangles)->add(numTris);
140 else
142 // tree was empty - skip this proxy and use conventional
143 // intersect
144 res = Action::Continue;
147 return res;
150 void KDTreeIntersectProxyAttachment::changed(ConstFieldMaskArg whichField,
151 UInt32 origin,
152 BitVector details)
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(),
164 &_mfTreeNodes,
165 &_mfTriIndices );
168 Inherited::changed(whichField, origin, details);
171 void KDTreeIntersectProxyAttachment::dump( UInt32 ,
172 const BitVector ) const
174 SLOG << "Dump KDTreeIntersectProxyAttachment NI" << std::endl;
177 OSG_END_NAMESPACE