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 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGINTERSECTACTION_H_
40 #define _OSGINTERSECTACTION_H_
45 //---------------------------------------------------------------------------
47 //---------------------------------------------------------------------------
51 #include "OSGSystemDef.h"
52 #include "OSGBaseTypes.h"
53 #include "OSGAction.h"
55 #include "OSGStatCollector.h"
59 //---------------------------------------------------------------------------
61 //---------------------------------------------------------------------------
65 //---------------------------------------------------------------------------
67 //---------------------------------------------------------------------------
69 //---------------------------------------------------------------------------
71 //---------------------------------------------------------------------------
73 /*! \brief IntersectAction class
74 \ingroup GrpSystemIntersectAction
75 \ingroup GrpLibOSGSystem
78 class OSG_SYSTEM_DLLMAPPING IntersectAction
: public Action
82 OSG_GEN_INTERNAL_MEMOBJPTR(IntersectAction
);
84 static StatElemDesc
<StatTimeElem
> statTravTime
;
85 static StatElemDesc
<StatIntElem
> statNNodes
;
86 static StatElemDesc
<StatIntElem
> statNTriangles
;
88 typedef std::vector
<Node
*> NodeStore
;
90 //-----------------------------------------------------------------------
92 //-----------------------------------------------------------------------
94 // create a new IntersectAction by cloning the prototype
95 static ObjTransitPtr
create( void );
96 static ObjTransitPtr
create(const Line
&line
,
97 const Real32 maxdist
= Inf
);
100 // after setting the prototype all new IntersectActions are clones of it
102 static void setPrototype(IntersectAction
*proto
);
103 static IntersectAction
*getPrototype(void );
105 //-----------------------------------------------------------------------
106 // instance functions
107 //-----------------------------------------------------------------------
109 IntersectAction
& operator =(const IntersectAction
&source
);
111 /*---------------------------------------------------------------------*/
112 /*! \name Statistics */
115 StatCollector
*getStatCollector(void ) const;
116 void setStatCollector(StatCollector
*sc
);
118 bool getResetStatistics(void ) const;
119 void setResetStatistics(bool value
);
122 /*---------------------------------------------------------------------*/
124 /*------------------------- your_category -------------------------------*/
128 void setLine( const Line
&line
,
129 const Real32 maxdist
= Inf
);
130 void setTestLines ( bool value
);
131 void setTestLineWidth (Real32 width
);
135 const Line
&getLine ( void ) const;
136 Real32
getMaxDist ( void ) const;
137 bool getTestLines ( void ) const;
138 Real32
getTestLineWidth( void ) const;
141 bool didHit (void) const;
142 Real32
getHitT (void) const;
143 Pnt3f
getHitPoint (void) const;
144 const Vec3f
&getHitNormal (void) const;
145 Node
*getHitObject (void) const;
146 const NodeStore
&getHitPath (void) const;
147 Int32
getHitTriangle(void) const;
148 Int32
getHitLine (void) const;
150 /*------------------------- access ------------------------------*/
152 // to be used by the traversed nodes
153 // set (temporary) results
154 Action::ResultE
setEnterLeave( Real32 enter
,
156 void setHit ( Real32 t
,
162 // when entering/leaving a different coordinate system, the values might
164 void scale(Real32 s
);
166 /*------------------------- your_operators ------------------------------*/
168 /*------------------------- assignment ----------------------------------*/
170 /*------------------------- comparison ----------------------------------*/
172 bool operator < (const IntersectAction
&other
) const;
174 bool operator == (const IntersectAction
&other
) const;
175 bool operator != (const IntersectAction
&other
) const;
178 // default registration. static, so it can be called during static init
179 static void registerEnterDefault(const FieldContainerType
&type
,
180 const Action::Functor
&func
);
182 static void registerLeaveDefault(const FieldContainerType
&type
,
183 const Action::Functor
&func
);
187 //-----------------------------------------------------------------------
189 //-----------------------------------------------------------------------
191 //-----------------------------------------------------------------------
193 //-----------------------------------------------------------------------
195 //-----------------------------------------------------------------------
197 //-----------------------------------------------------------------------
199 //-----------------------------------------------------------------------
201 //-----------------------------------------------------------------------
203 static bool terminateEnter(void);
204 static bool terminateLeave(void);
206 //-----------------------------------------------------------------------
207 // instance variables
208 //-----------------------------------------------------------------------
210 //-----------------------------------------------------------------------
211 // instance functions
212 //-----------------------------------------------------------------------
214 IntersectAction(void);
215 IntersectAction(const IntersectAction
&source
);
217 virtual ~IntersectAction(void);
219 virtual Action::ResultE
start(void );
220 virtual Action::ResultE
stop (Action::ResultE res
);
222 // access default functors
224 virtual FunctorStore
*getDefaultEnterFunctors(void);
225 virtual FunctorStore
*getDefaultLeaveFunctors(void);
227 ResultE
onEnterNode(Node
* node
, Action
* action
);
228 ResultE
onLeaveNode(Node
* node
, Action
* action
);
232 //-----------------------------------------------------------------------
234 //-----------------------------------------------------------------------
236 //-----------------------------------------------------------------------
238 //-----------------------------------------------------------------------
240 typedef Action Inherited
;
242 //-----------------------------------------------------------------------
244 //-----------------------------------------------------------------------
246 //-----------------------------------------------------------------------
248 //-----------------------------------------------------------------------
250 //-----------------------------------------------------------------------
252 //-----------------------------------------------------------------------
254 // the prototype which is copied to create new actions
255 static IntersectAction
* _prototype
;
257 // default functors for instantiation
258 static FunctorStore
*_defaultEnterFunctors
;
259 static FunctorStore
*_defaultLeaveFunctors
;
261 //-----------------------------------------------------------------------
263 //-----------------------------------------------------------------------
265 //-----------------------------------------------------------------------
266 // instance variables
267 //-----------------------------------------------------------------------
269 // the line to be tested
271 bool _testLines
; /**< If true, attempt to intersect lines as well as geom. */
272 float _lineTestWidth
; /**< The width to assume for all lines we intersect against. */
274 // the maximum distance along the line
277 // Results (also intermediate)
278 // hit at all (either bv or face)
280 // enter leave distance for bounding volume
292 // Index of the hit triangle ( from TriangleIterator::getIndex() )
295 // Normal of the hit triangle
298 // Index of the hit line ( from LineInterator::getIndex() )
301 StatCollectorRefPtr _statistics
;
302 bool _resetStatistics
;
304 //-----------------------------------------------------------------------
305 // instance functions
306 //-----------------------------------------------------------------------
309 //---------------------------------------------------------------------------
311 //---------------------------------------------------------------------------
315 typedef IntersectAction
*IntersectActionP
;
317 OSG_GEN_MEMOBJPTR(IntersectAction
);
321 #include "OSGIntersectAction.inl"
323 #endif /* _OSGRENDERACTION_H_ */