00001
00002
00003 #define _VOXEL_SPACE_ VoxelSpace<_dimension_, _TObject_, _BoundingBoxGetter_>
00004
00005 namespace jafar {
00006 namespace geom {
00007
00008 template<int _dimension_, class _TObject_, class _BoundingBoxGetter_>
00009 _VOXEL_SPACE_::VoxelSpace(double voxelSize_)
00010 : m_voxelSize(voxelSize_)
00011 {
00012
00013 }
00014 template<int _dimension_, class _TObject_, class _BoundingBoxGetter_>
00015 _VOXEL_SPACE_::~VoxelSpace()
00016 {
00017
00018 }
00019 template<int _dimension_, class _TObject_, class _BoundingBoxGetter_>
00020 void _VOXEL_SPACE_::insertObject(_TObject_* object)
00021 {
00022 InsertFunctor insertFunctor;
00023 insertFunctor.object = object;
00024 BoundingBoxD bb = _BoundingBoxGetter_::boundingBox(object);
00025 m_voxels.iterateCreateVoxels( indexFor( bb.corner1()), indexFor( bb.corner2() ), &insertFunctor );
00026 }
00027 template<int _dimension_, class _TObject_, class _BoundingBoxGetter_>
00028 void _VOXEL_SPACE_::removeObject(_TObject_* object)
00029 {
00030 RemoveFunctor removeFunctor;
00031 removeFunctor.object = object;
00032 BoundingBoxD bb = _BoundingBoxGetter_::boundingBox(object);
00033 m_voxels.iterateAllVoxels( &removeFunctor );
00034
00035 }
00036 template<int _dimension_, class _TObject_, class _BoundingBoxGetter_>
00037 std::list<const typename _VOXEL_SPACE_::Voxel*> _VOXEL_SPACE_::voxelsCountaining( const _TObject_* object) const
00038 {
00039 FindVoxelsFunctor findFunctor;
00040 BoundingBoxD bb = _BoundingBoxGetter_::boundingBox(object);
00041 m_voxels.iterateVoxels( indexFor( bb.corner1()), indexFor( bb.corner2() ), &findFunctor );
00042 return findFunctor.voxels;
00043 }
00044 template<int _dimension_, class _TObject_, class _BoundingBoxGetter_>
00045 std::list<_TObject_*> _VOXEL_SPACE_::objectsIn( const BoundingBoxD& bb) const
00046 {
00047 FindObjectsFunctor findFunctor;
00048 findFunctor.boundingBox = bb;
00049 m_voxels.iterateVoxels( indexFor( bb.corner1()), indexFor( bb.corner2() ), &findFunctor );
00050 return findFunctor.objects;
00051 }
00052 template<int _dimension_, class _TObject_, class _BoundingBoxGetter_>
00053 std::ostream& operator<<(std::ostream& s, const VoxelSpace<_dimension_, _TObject_, _BoundingBoxGetter_>& _vs)
00054 {
00055 typename VoxelSpace<_dimension_, _TObject_, _BoundingBoxGetter_>::StreamFunctor streamFunctor( s );
00056 _vs.m_voxels.iterateAllVoxels( &streamFunctor );
00057 return s;
00058 }
00059
00060 template<int _dimension_, class _TObject_, class _BoundingBoxGetter_>
00061 typename _VOXEL_SPACE_::IndexVec _VOXEL_SPACE_::indexFor(const HomogenousVecD& v ) const
00062 {
00063
00064 IndexVec iv;
00065 for(int i = 0; i < _dimension_; i++)
00066 {
00067 iv(i) = (int) nearbyint(v(i) / m_voxelSize);
00068 }
00069 return iv;
00070 }
00071 }
00072 }
00073
00074 #undef _VOXEL_SPACE_