VR-Forces 4.0.4 Class Documentation
include/geometry/ssAccumulationFunctor.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 2005 MAK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: ssAccumulationFunctor.h,v $ $Revision: 1.8 $ $State: Exp $
00007 *********************************************************************/
00008 #ifndef ssAccumulationFunctor_H_
00009 #define ssAccumulationFunctor_H_
00010 
00011 #include <vlutil/vlConfig.h> 
00012 #include "geometry/spatialSubdivision.h"
00013 #include "geometry/ssFunctor.h"
00014 
00015 //
00016 // A functor intended for use with the spatial subdivision set of classes.  It's 
00017 // primary usage is to accumulate pointers to elements in its internal container, 
00018 // The type pointed to is the second template parameter of the functor.  
00019 // Expected usage:
00020 // When passed to the intersection functions, it accumulates pointers to the 
00021 // second parameter to its function operator in its internal container. For example
00022 // it will build up a list of all cells that intersect a given primitive when 
00023 // passed into an ss intersection object.  (for example, in the terrain inserter 
00024 // class.)
00025 // 
00026 template <typename IgnoredType, typename ContainedType>
00027 class DtSsAccumulationFunctor: public DtSsFunctor<IgnoredType, ContainedType>
00028 {
00029 public:
00030    // Typedefs used by the functor
00031    // This functor currently uses a vector as container of accumulated elements.
00032    typedef std::vector<ContainedType*> DtAccumulationContainer;
00033    
00034    // Constructor
00035    DtSsAccumulationFunctor();
00036 
00037    // Destructor
00038    virtual ~DtSsAccumulationFunctor();
00039 
00040 private:
00041    // not implemented
00042    DtSsAccumulationFunctor(const DtSsAccumulationFunctor& original);
00043    DtSsAccumulationFunctor& operator=(const DtSsAccumulationFunctor& original);
00044 
00045 public:
00046    // Accumulates the second parameter in the internal container
00047    // The first parameter, ignoredItem, is ignored by this functor.
00048    // 
00049    // @returns This functor is never "done processing" and so it always returns false.
00050    // 
00051    // @note This is intended to be used with the spatial subdivision intersectors,
00052    // where the second parameter is the subdivision cell result from an intersection test.
00053    virtual bool operator()(IgnoredType& ignoredItem, ContainedType& itemToAccumulate);
00054 
00055    // Get/Set the container of accumulated items
00056    // @{
00057    virtual DtAccumulationContainer& container();
00058    virtual void setContainer(DtAccumulationContainer& newContainer);
00059    // @}
00060 
00061 private:
00062    DtAccumulationContainer myContainer;
00063 };
00064 
00065 
00066 //------------------------------------------------------
00067 //  INLINE METHODS
00068 //------------------------------------------------------
00069 template <typename IgnoredType, typename ContainedType>
00070 DtSsAccumulationFunctor<IgnoredType, ContainedType>::DtSsAccumulationFunctor()
00071 : DtSsFunctor<IgnoredType, ContainedType>()
00072 , myContainer()
00073 {
00074 }
00075 
00076 
00077 template <typename IgnoredType, typename ContainedType>
00078 DtSsAccumulationFunctor<IgnoredType, ContainedType>::~DtSsAccumulationFunctor()
00079 {
00080 }
00081 
00082 
00083 template <typename IgnoredType, typename ContainedType>
00084 bool DtSsAccumulationFunctor<IgnoredType, ContainedType>::operator()(IgnoredType& ignoredItem, ContainedType& itemToAccumulate)
00085 {
00086    // Ignore the first parameter as this functor only accumulates the second.
00087    container().insert(container().end(), &itemToAccumulate);
00088    
00089    // Always returns false, as it is never "done" processing.
00090    return false;
00091 }
00092 
00093 
00094 template <typename IgnoredType, typename ContainedType>
00095 typename DtSsAccumulationFunctor<IgnoredType, ContainedType>::DtAccumulationContainer& DtSsAccumulationFunctor<IgnoredType, ContainedType>::container() 
00096 { 
00097    return myContainer; 
00098 };
00099 
00100 
00101 template <typename IgnoredType, typename ContainedType>
00102 void DtSsAccumulationFunctor<IgnoredType, ContainedType>::setContainer(typename DtSsAccumulationFunctor<IgnoredType, ContainedType>::DtAccumulationContainer& newContainer) 
00103 { 
00104    myContainer = newContainer; 
00105 };
00106 
00107 #endif
00108 
00109 

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)