fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / Action / IntersectAction / OSGIntersectAction.h
blob3eabacb8160db7263047af821e95dcf05b6d7e77
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 #ifndef _OSGINTERSECTACTION_H_
40 #define _OSGINTERSECTACTION_H_
41 #ifdef __sgi
42 #pragma once
43 #endif
45 //---------------------------------------------------------------------------
46 // Includes
47 //---------------------------------------------------------------------------
49 #include <vector>
51 #include "OSGSystemDef.h"
52 #include "OSGBaseTypes.h"
53 #include "OSGAction.h"
54 #include "OSGLine.h"
55 #include "OSGStatCollector.h"
57 OSG_BEGIN_NAMESPACE
59 //---------------------------------------------------------------------------
60 // Forward References
61 //---------------------------------------------------------------------------
63 class Node;
65 //---------------------------------------------------------------------------
66 // Types
67 //---------------------------------------------------------------------------
69 //---------------------------------------------------------------------------
70 // Class
71 //---------------------------------------------------------------------------
73 /*! \brief IntersectAction class
74 \ingroup GrpSystemIntersectAction
75 \ingroup GrpLibOSGSystem
78 class OSG_SYSTEM_DLLMAPPING IntersectAction : public Action
80 public:
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 //-----------------------------------------------------------------------
91 // class functions
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);
99 // prototype access
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 */
113 /*! \{ */
115 StatCollector *getStatCollector(void ) const;
116 void setStatCollector(StatCollector *sc);
118 bool getResetStatistics(void ) const;
119 void setResetStatistics(bool value);
121 /*! \} */
122 /*---------------------------------------------------------------------*/
124 /*------------------------- your_category -------------------------------*/
127 // set input data
128 void setLine( const Line &line,
129 const Real32 maxdist = Inf);
130 void setTestLines ( bool value );
131 void setTestLineWidth (Real32 width);
134 // get input data
135 const Line &getLine ( void ) const;
136 Real32 getMaxDist ( void ) const;
137 bool getTestLines ( void ) const;
138 Real32 getTestLineWidth( void ) const;
140 // get result data
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,
155 Real32 leave );
156 void setHit ( Real32 t,
157 Node *obj,
158 Int32 triIndex,
159 const Vec3f &normal,
160 Int32 lineIndex );
162 // when entering/leaving a different coordinate system, the values might
163 // have to be scaled
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);
185 protected:
187 //-----------------------------------------------------------------------
188 // enums
189 //-----------------------------------------------------------------------
191 //-----------------------------------------------------------------------
192 // types
193 //-----------------------------------------------------------------------
195 //-----------------------------------------------------------------------
196 // class variables
197 //-----------------------------------------------------------------------
199 //-----------------------------------------------------------------------
200 // class functions
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);
230 private:
232 //-----------------------------------------------------------------------
233 // enums
234 //-----------------------------------------------------------------------
236 //-----------------------------------------------------------------------
237 // types
238 //-----------------------------------------------------------------------
240 typedef Action Inherited;
242 //-----------------------------------------------------------------------
243 // friend classes
244 //-----------------------------------------------------------------------
246 //-----------------------------------------------------------------------
247 // friend functions
248 //-----------------------------------------------------------------------
250 //-----------------------------------------------------------------------
251 // class variables
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 //-----------------------------------------------------------------------
262 // class functions
263 //-----------------------------------------------------------------------
265 //-----------------------------------------------------------------------
266 // instance variables
267 //-----------------------------------------------------------------------
269 // the line to be tested
270 Line _line;
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
275 Real32 _maxdist;
277 // Results (also intermediate)
278 // hit at all (either bv or face)
279 bool _hit;
280 // enter leave distance for bounding volume
281 Real32 _enterT;
282 Real32 _leaveT;
283 NodeStore _path;
285 // Hit distance
286 Real32 _hitT;
288 // Hit object
289 Node *_hitObject;
290 NodeStore _hitPath;
292 // Index of the hit triangle ( from TriangleIterator::getIndex() )
293 Int32 _hitTriangle;
295 // Normal of the hit triangle
296 Vec3f _hitNormal;
298 // Index of the hit line ( from LineInterator::getIndex() )
299 Int32 _hitLine;
301 StatCollectorRefPtr _statistics;
302 bool _resetStatistics;
304 //-----------------------------------------------------------------------
305 // instance functions
306 //-----------------------------------------------------------------------
309 //---------------------------------------------------------------------------
310 // Exported Types
311 //---------------------------------------------------------------------------
313 // class pointer
315 typedef IntersectAction *IntersectActionP;
317 OSG_GEN_MEMOBJPTR(IntersectAction);
319 OSG_END_NAMESPACE
321 #include "OSGIntersectAction.inl"
323 #endif /* _OSGRENDERACTION_H_ */