OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
ossimTileCache Class Reference

#include <ossimTileCache.h>

Classes

struct  ossimTileInformation
 

Public Member Functions

 ossimTileCache (long numberOfBuckets=10)
 
virtual ~ossimTileCache ()
 
virtual ossimDataObjectget (const ossimDpt3d &origin, unsigned long resLevel=0)
 
virtual ossimDataObjectremove (const ossimDpt3d &origin, unsigned long resLevel=0)
 
virtual ossimDataObjectinsert (const ossimDpt3d &origin, ossimDataObject *data, unsigned long resLevel=0)
 
void invalidate ()
 
virtual void invalidate (const ossimDpt3d &origin, ossim_uint32 resLevel)
 
virtual long numberOfItems () const
 
virtual void display () const
 
virtual ossim_uint32 sizeInBytes ()
 

Protected Types

typedef multimap< ossim_uint32, ossimTileInformation * >::iterator Iterator
 
typedef ossimTileInformationCacheDataPtr
 
typedef ossimTileInformation CacheData
 

Protected Member Functions

void deleteAll ()
 
virtual ossim_uint32 bucketHash (const ossimDpt3d &aPt)
 
virtual ossim_uint32 tileId (const ossimDpt3d &aPt)
 

Protected Attributes

multimap< ossim_uint32, ossimTileInformation * > * theCache
 
long theNumberOfBuckets
 
ossim_uint32 theSizeInBytes
 

Detailed Description

Definition at line 25 of file ossimTileCache.h.

Member Typedef Documentation

◆ CacheData

Definition at line 94 of file ossimTileCache.h.

◆ CacheDataPtr

Definition at line 93 of file ossimTileCache.h.

◆ Iterator

typedef multimap<ossim_uint32, ossimTileInformation*>::iterator ossimTileCache::Iterator
protected

Definition at line 92 of file ossimTileCache.h.

Constructor & Destructor Documentation

◆ ossimTileCache()

ossimTileCache::ossimTileCache ( long  numberOfBuckets = 10)

Definition at line 29 of file ossimTileCache.cpp.

References theCache, and theNumberOfBuckets.

30  : theCache(NULL),
31  theNumberOfBuckets(numberOfBuckets>0?numberOfBuckets:255),
33 {
34  theCache = new multimap<ossim_uint32, ossimTileInformation*>[theNumberOfBuckets];
35 }
multimap< ossim_uint32, ossimTileInformation * > * theCache
ossim_uint32 theSizeInBytes

◆ ~ossimTileCache()

ossimTileCache::~ossimTileCache ( )
virtual

Definition at line 37 of file ossimTileCache.cpp.

References deleteAll().

38 {
39  deleteAll();
40 }

Member Function Documentation

◆ bucketHash()

ossim_uint32 ossimTileCache::bucketHash ( const ossimDpt3d aPt)
protectedvirtual

Definition at line 152 of file ossimTileCache.cpp.

References theNumberOfBuckets, and tileId().

Referenced by get(), insert(), and remove().

153 {
154  return tileId(aPt)%theNumberOfBuckets;
155 }
virtual ossim_uint32 tileId(const ossimDpt3d &aPt)

◆ deleteAll()

void ossimTileCache::deleteAll ( )
protected

Definition at line 157 of file ossimTileCache.cpp.

References theCache, and theNumberOfBuckets.

Referenced by ~ossimTileCache().

158 {
159  Iterator anIterator;
160 
161  for(long bucket = 0; bucket < theNumberOfBuckets; bucket++)
162  {
163  anIterator = theCache[bucket].begin();
164  while(anIterator != theCache[bucket].end())
165  {
166  CacheDataPtr info = (*anIterator).second;
167  delete info;
168 
169  ++anIterator;
170  }
171  theCache[bucket].clear();
172  }
173  delete [] theCache;
174 }
ossimTileInformation * CacheDataPtr
multimap< ossim_uint32, ossimTileInformation * > * theCache
multimap< ossim_uint32, ossimTileInformation * >::iterator Iterator

◆ display()

void ossimTileCache::display ( ) const
virtual

Definition at line 14 of file ossimTileCache.cpp.

References theCache, and theNumberOfBuckets.

15 {
17 
18  for(long buckets = 0; buckets < theNumberOfBuckets; buckets++)
19  {
20  tiles = theCache[buckets].begin();
21  while(tiles != theCache[buckets].end())
22  {
23  cout << ((*tiles).second) << endl;
24  ++tiles;
25  }
26  }
27 }
multimap< ossim_uint32, ossimTileInformation * > * theCache
multimap< ossim_uint32, ossimTileInformation * >::iterator Iterator

◆ get()

ossimDataObject * ossimTileCache::get ( const ossimDpt3d origin,
unsigned long  resLevel = 0 
)
virtual

This will return a tile if found. Note this tile is still owned by the cache.

Definition at line 42 of file ossimTileCache.cpp.

References bucketHash(), ossimRefPtr< T >::get(), theCache, ossimTileCache::ossimTileInformation::theCachedTile, ossimTileCache::ossimTileInformation::theOrigin, ossimTileCache::ossimTileInformation::theResLevel, and tileId().

Referenced by ossimAppTileCache::get().

44 {
45  ossimDataObject* result = NULL;
46  Iterator anIterator;
47 
48  ossim_uint32 bucket = bucketHash(origin);
49 
50  anIterator = theCache[bucket].find(tileId(origin));
51  while(anIterator != theCache[bucket].end())
52  {
53  CacheDataPtr info = (*anIterator).second;
54  if(info)
55  {
56  if(info->theOrigin == origin &&
57  info->theResLevel == resLevel)
58  {
59  return info->theCachedTile.get();
60  }
61  }
62 
63  ++anIterator;
64  }
65  return result;
66 }
ossimTileInformation * CacheDataPtr
virtual ossim_uint32 bucketHash(const ossimDpt3d &aPt)
multimap< ossim_uint32, ossimTileInformation * > * theCache
ossimRefPtr< ossimDataObject > theCachedTile
multimap< ossim_uint32, ossimTileInformation * >::iterator Iterator
unsigned int ossim_uint32
virtual ossim_uint32 tileId(const ossimDpt3d &aPt)

◆ insert()

ossimDataObject * ossimTileCache::insert ( const ossimDpt3d origin,
ossimDataObject data,
unsigned long  resLevel = 0 
)
virtual

This will not duplicate the tile. Note the tile is owned by the cache.

Definition at line 100 of file ossimTileCache.cpp.

References bucketHash(), ossimDataObject::getDataSizeInBytes(), theCache, theSizeInBytes, and tileId().

Referenced by ossimAppTileCache::insert().

103 {
104  ossim_uint32 bucket = bucketHash(origin);
105 
106  // make sure we keep up with the current size of the
107  // cache in bytes. This is only the count of the data
108  // and not any overhead required by the cache.
110  theCache[bucket].insert(make_pair(tileId(origin),
111  new CacheData(data,
112  origin,
113  resLevel)));
114 
115  return data;
116 }
virtual ossim_uint32 bucketHash(const ossimDpt3d &aPt)
ossimTileInformation CacheData
multimap< ossim_uint32, ossimTileInformation * > * theCache
ossim_uint32 theSizeInBytes
unsigned int ossim_uint32
virtual ossim_uint32 getDataSizeInBytes() const =0
virtual ossim_uint32 tileId(const ossimDpt3d &aPt)

◆ invalidate() [1/2]

void ossimTileCache::invalidate ( )

Not implemented

Definition at line 118 of file ossimTileCache.cpp.

119 {
120 
121 }

◆ invalidate() [2/2]

void ossimTileCache::invalidate ( const ossimDpt3d origin,
ossim_uint32  resLevel 
)
virtual

Not implemented

Definition at line 123 of file ossimTileCache.cpp.

125 {
126 }

◆ numberOfItems()

virtual long ossimTileCache::numberOfItems ( ) const
inlinevirtual

Definition at line 64 of file ossimTileCache.h.

64 {return theCache?(long)theCache->size():(long)0;}
multimap< ossim_uint32, ossimTileInformation * > * theCache

◆ remove()

ossimDataObject * ossimTileCache::remove ( const ossimDpt3d origin,
unsigned long  resLevel = 0 
)
virtual

Will remove the tile from the cache and will not delete. Note: the cache no longer owns the tile.

Definition at line 68 of file ossimTileCache.cpp.

References bucketHash(), ossimRefPtr< T >::get(), ossimDataObject::getDataSizeInBytes(), theCache, ossimTileCache::ossimTileInformation::theCachedTile, ossimTileCache::ossimTileInformation::theOrigin, ossimTileCache::ossimTileInformation::theResLevel, theSizeInBytes, and tileId().

Referenced by ossimAppTileCache::removeTile().

70 {
71  Iterator anIterator;
72  ossimDataObject *result;
73  ossim_uint32 bucket = bucketHash(origin);
74 
75  anIterator = theCache[bucket].find(tileId(origin));
76  while(anIterator != theCache[bucket].end())
77  {
78  CacheDataPtr info = (*anIterator).second;
79  if(info)
80  {
81  if(info->theOrigin == origin &&
82  info->theResLevel == resLevel)
83  {
84  theCache[bucket].erase(anIterator);
85  theSizeInBytes -= info->theCachedTile->getDataSizeInBytes();
86 
87  result = info->theCachedTile.get();
88 
89  delete info;
90  return result;
91  }
92  }
93 
94  ++anIterator;
95  }
96 
97  return NULL;
98 }
ossimTileInformation * CacheDataPtr
virtual ossim_uint32 bucketHash(const ossimDpt3d &aPt)
multimap< ossim_uint32, ossimTileInformation * > * theCache
ossim_uint32 theSizeInBytes
multimap< ossim_uint32, ossimTileInformation * >::iterator Iterator
unsigned int ossim_uint32
virtual ossim_uint32 tileId(const ossimDpt3d &aPt)

◆ sizeInBytes()

virtual ossim_uint32 ossimTileCache::sizeInBytes ( )
inlinevirtual

Definition at line 67 of file ossimTileCache.h.

Referenced by ossimAppTileCache::deleteCache().

67 {return theSizeInBytes;}
ossim_uint32 theSizeInBytes

◆ tileId()

ossim_uint32 ossimTileCache::tileId ( const ossimDpt3d aPt)
protectedvirtual

Definition at line 130 of file ossimTileCache.cpp.

References ossimDpt3d::x, ossimDpt3d::y, and ossimDpt3d::z.

Referenced by bucketHash(), get(), insert(), and remove().

131 {
132  const unsigned char *bufx = (unsigned char*)(&aPt.x);
133  const unsigned char *bufy = (unsigned char*)(&aPt.y);
134  const unsigned char *bufz = (unsigned char*)(&aPt.z);
135 
136  // this just multiplies each byte by some prime number
137  // and add together.
138  return (ossim_uint32)(bufx[0]*101 + bufx[1]*103 +
139  bufx[2]*107 + bufx[3]*109 +
140  bufx[4]*113 + bufx[5]*127 +
141  bufx[6]*131 + bufx[7]*137 +
142  bufy[0]*139 + bufy[1]*149 +
143  bufy[2]*151 + bufy[3]*157 +
144  bufy[4]*163 + bufy[5]*167 +
145  bufy[6]*173 + bufy[7]*179 +
146  bufz[0]*181 + bufz[1]*191 +
147  bufz[2]*193 + bufz[3]*197 +
148  bufz[4]*199 + bufz[5]*211 +
149  bufz[6]*223 + bufz[6]*227);
150 }
double z
Definition: ossimDpt3d.h:145
unsigned int ossim_uint32
double x
Definition: ossimDpt3d.h:143
double y
Definition: ossimDpt3d.h:144

Member Data Documentation

◆ theCache

multimap<ossim_uint32, ossimTileInformation*>* ossimTileCache::theCache
protected

Definition at line 100 of file ossimTileCache.h.

Referenced by deleteAll(), display(), get(), insert(), ossimTileCache(), and remove().

◆ theNumberOfBuckets

long ossimTileCache::theNumberOfBuckets
protected

Definition at line 101 of file ossimTileCache.h.

Referenced by bucketHash(), deleteAll(), display(), and ossimTileCache().

◆ theSizeInBytes

ossim_uint32 ossimTileCache::theSizeInBytes
protected

Definition at line 102 of file ossimTileCache.h.

Referenced by insert(), and remove().


The documentation for this class was generated from the following files: