OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimTileCache.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts (gpotts@imagelinks.com)
6 // Description: This file contains the cache algorithm
7 //
8 //***********************************
9 // $Id: ossimTileCache.cpp 17206 2010-04-25 23:20:40Z dburken $
10 
13 
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 }
28 
29 ossimTileCache::ossimTileCache(long numberOfBuckets)
30  : theCache(NULL),
31  theNumberOfBuckets(numberOfBuckets>0?numberOfBuckets:255),
32  theSizeInBytes(0)
33 {
34  theCache = new multimap<ossim_uint32, ossimTileInformation*>[theNumberOfBuckets];
35 }
36 
38 {
39  deleteAll();
40 }
41 
43  unsigned long resLevel)
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 }
67 
69  unsigned long resLevel)
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);
86 
87  result = info->theCachedTile.get();
88 
89  delete info;
90  return result;
91  }
92  }
93 
94  ++anIterator;
95  }
96 
97  return NULL;
98 }
99 
101  ossimDataObject* data,
102  unsigned long resLevel)
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 }
117 
119 {
120 
121 }
122 
123 void ossimTileCache::invalidate(const ossimDpt3d& /* origin */,
124  ossim_uint32 /* resLevel */)
125 {
126 }
127 
128 
129 
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 }
151 
153 {
154  return tileId(aPt)%theNumberOfBuckets;
155 }
156 
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 }
virtual ossimDataObject * remove(const ossimDpt3d &origin, unsigned long resLevel=0)
virtual ossim_uint32 bucketHash(const ossimDpt3d &aPt)
ossimTileInformation CacheData
multimap< ossim_uint32, ossimTileInformation * > * theCache
virtual ossimDataObject * get(const ossimDpt3d &origin, unsigned long resLevel=0)
ossim_uint32 theSizeInBytes
ossimTileCache(long numberOfBuckets=10)
ossimRefPtr< ossimDataObject > theCachedTile
multimap< ossim_uint32, ossimTileInformation * >::iterator Iterator
double z
Definition: ossimDpt3d.h:145
virtual ~ossimTileCache()
unsigned int ossim_uint32
virtual ossimDataObject * insert(const ossimDpt3d &origin, ossimDataObject *data, unsigned long resLevel=0)
double x
Definition: ossimDpt3d.h:143
virtual void display() const
double y
Definition: ossimDpt3d.h:144
virtual ossim_uint32 getDataSizeInBytes() const =0
virtual ossim_uint32 tileId(const ossimDpt3d &aPt)