00001 #ifndef LIBGEODECOMP_GEOMETRY_PARTITIONS_SPACEFILLINGCURVE_H 00002 #define LIBGEODECOMP_GEOMETRY_PARTITIONS_SPACEFILLINGCURVE_H 00003 00004 #include <libgeodecomp/geometry/coord.h> 00005 #include <libgeodecomp/geometry/region.h> 00006 #include <libgeodecomp/geometry/partitions/partition.h> 00007 00008 namespace LibGeoDecomp { 00009 00010 enum SpaceFillingCurveSublevelState {TRIVIAL, CACHED}; 00011 00012 template<int DIM> 00013 class SpaceFillingCurve : public Partition<DIM> 00014 { 00015 public: 00016 00017 class Iterator 00018 { 00019 public: 00020 inline Iterator(const Coord<DIM>& origin, const bool& endReached) : 00021 origin(origin), 00022 cursor(origin), 00023 endReached(endReached) 00024 {} 00025 00026 inline bool operator==(const Iterator& other) const 00027 { 00028 return (endReached == other.endReached) && (cursor == other.cursor); 00029 } 00030 00031 inline bool operator!=(const Iterator& other) const 00032 { 00033 return !(*this == other); 00034 } 00035 00036 inline const Coord<DIM>& operator*() const 00037 { 00038 return cursor; 00039 } 00040 00041 inline const Coord<DIM> *operator->() const 00042 { 00043 return &cursor; 00044 } 00045 00046 static inline bool hasTrivialDimensions(const Coord<DIM>& dimensions) 00047 { 00048 int prod = dimensions.prod(); 00049 int sum = dimensions.sum(); 00050 return ((prod == 0) || (prod == (sum - DIM + 1))); 00051 } 00052 00053 protected: 00054 Coord<DIM> origin; 00055 Coord<DIM> cursor; 00056 bool endReached; 00057 SpaceFillingCurveSublevelState sublevelState; 00058 }; 00059 00060 inline SpaceFillingCurve( 00061 const long& offset, 00062 const std::vector<std::size_t>& weights) : 00063 Partition<DIM>(offset, weights) 00064 {} 00065 }; 00066 00067 } 00068 00069 00070 #endif