IteratorSDS.cc

Go to the documentation of this file.
00001 #include <esg/iterator/IteratorSDS.h>
00002 
00003 using namespace esg;
00004 
00005 IteratorSDS::IteratorSDS(SDS* ss)
00006 {
00007     _riAttr          = NULL;
00008     _hsAttr          = NULL;
00009     _arAttr          = NULL;
00010     _traverse        = NONE;
00011     _pAggregate      = ss;
00012     //_iterateTangible =  false;
00013 }
00014 
00015 IteratorSDS::~IteratorSDS()
00016 {
00017   if (_riAttr) delete _riAttr;
00018   if (_hsAttr) delete _hsAttr;
00019   if (_arAttr) delete _arAttr;
00020 }
00021 
00022 void IteratorSDS::initRayIntersection(const Vector3& o,
00023                                       const Vector3& d,
00024                                       bool           clearCache,
00025                                       float          distLimit,
00026                                       const void*    parentElement)
00027 {
00028     if (_riAttr) {
00029         _riAttr->origin.set(o);
00030         _riAttr->direction.set(d);
00031         _riAttr->distLimit = distLimit;
00032         _riAttr->parentElement = parentElement;
00033         if (clearCache && _riAttr->iEnv.pCache) {
00034             delete _riAttr->iEnv.pCache;
00035             _riAttr->iEnv.pCache = NULL;
00036         }
00037     } else
00038         _riAttr = new RIAttr(o, d, distLimit, parentElement);
00039     
00040     _traverse = RAY_INTERSECTION;
00041 }
00042 
00043 void IteratorSDS::initHalfSpaceSearch(const Vector3& origin,
00044                                       const Vector3& direction)
00045 {
00046     if (_hsAttr) {
00047         _hsAttr->origin.set(origin);
00048         _hsAttr->direction.set(direction);
00049     } else 
00050         _hsAttr = new HSAttr(origin, direction);
00051 
00052     _traverse = HALF_SPACE;
00053 }
00054 
00055 void IteratorSDS::initAreaSearch(Geometry* area)
00056 {
00057     if (_arAttr) _arAttr->area = area;
00058     else _arAttr = new ARAttr(area);
00059     _traverse = AREA;
00060 }
00061 
00062 void IteratorSDS::initChildrenSearch()
00063 {
00064     _traverse = CHILDREN;
00065 }
00066 
00067 SceneGraphObject* IteratorSDS::firstChild()
00068 {
00069     if (!_pAggregate) return NULL;
00070 
00071     _iterateTangible = false;
00072 
00073     // curently the children search is the only one traversal returning
00074     // intangible objects
00075     if (_traverse == CHILDREN) {
00076         SceneGraphObject* pObj = _pAggregate->_intangibleChildren.firstItem();
00077         if (pObj) return pObj;
00078     }
00079 
00080     _iterateTangible = true;
00081     return _first_child();
00082 }
00083 
00084 SceneGraphObject* IteratorSDS::nextChild()
00085 {
00086     if (!_pAggregate) return NULL;
00087 
00088     if (_iterateTangible) return _next_child();
00089         
00090     // Still returning intangible objects.
00091     if (_traverse == CHILDREN) {
00092         // Currently the children search is the only one traversal
00093         // returning intangible objects.
00094         SceneGraphObject* pObj=_pAggregate->_intangibleChildren.nextItem();
00095         if (pObj) return pObj;
00096     }
00097 
00098     _iterateTangible = true;
00099     return _first_child();
00100 }
00101 
00102 
00103 

Generated on Wed Jun 28 12:24:31 2006 for esg by  doxygen 1.4.6