OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimMultiResLevelHistogram.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts
6 //
7 // Description:
8 //
9 //*******************************************************************
10 // $Id: ossimMultiResLevelHistogram.cpp 20610 2012-02-27 12:19:25Z gpotts $
17 #include <fstream>
18 using namespace std;
19 
20 static const ossimKeyword NUMBER_OF_RES_LEVELS("number_of_res_levels",
21  "");
22 
24  :
25  theHistogramList(),
26  theHistogramFile()
27 {
28 }
29 
31  :
32  theHistogramList(),
33  theHistogramFile()
34 {
35  create(numberOfResLevels);
36 }
37 
39  :
40  theHistogramList(),
41  theHistogramFile()
42 {
43 
45  for(ossim_uint32 i = 0; i < theHistogramList.size(); ++i)
46  {
47  theHistogramList[i] = rhs.theHistogramList[i].valid()?
50  }
51 }
52 
54 {
56 }
57 
59 {
61 
62  for(ossim_uint32 idx = 0; idx < numberOfResLevels; ++idx)
63  {
65  }
66 }
67 
69 {
71 
72  if(theHistogramList.size() > 0)
73  {
75 
76  for(ossim_uint32 idx=0; idx < (ossim_uint32) theHistogramList.size(); ++ idx)
77  {
78  if(theHistogramList[idx].valid())
79  {
80  ossimRefPtr<ossimMultiBandHistogram> multiBandAccumulator = theHistogramList[idx]->createAccumulationLessThanEqual();
81  result->theHistogramList[idx] = multiBandAccumulator;
82  }
83  else
84  {
85  // we will push on a null since someone could
86  // turn off a band. A null accumulation will
87  // indicate no histogram data.
88  //
89  result->theHistogramList[idx] = 0;
90  }
91  }
92  }
93 
94  return result;
95 }
96 
97 void ossimMultiResLevelHistogram::setBinCount(double binNumber, double count)
98 {
99  if(theHistogramList.size() > 0)
100  {
101  for(ossim_uint32 idx=0; idx < (ossim_uint32) theHistogramList.size(); ++ idx)
102  {
103  if(theHistogramList[idx].valid())
104  {
105  theHistogramList[idx]->setBinCount(binNumber, count);
106  }
107  }
108  }
109 }
110 
112 {
114 
115  if(theHistogramList.size() > 0)
116  {
118 
119  for(ossim_uint32 idx=0; idx < (ossim_uint32) theHistogramList.size(); ++ idx)
120  {
121  if(theHistogramList[idx].valid())
122  {
123  ossimRefPtr<ossimMultiBandHistogram> multiBandAccumulator = theHistogramList[idx]->createAccumulationGreaterThanEqual();
124  result->theHistogramList[idx]=multiBandAccumulator;
125  }
126  else
127  {
128  // we will push on a null since someone could
129  // turn off a band. A null accumulation will
130  // indicate no histogram data.
131  //
132  result->theHistogramList[idx] = 0;
133  }
134  }
135  result = 0;
136  }
137 
138  return result;
139 }
140 
142 {
143  theHistogramList.push_back(histo);
144 }
145 
147 {
149  theHistogramList.push_back(result);
150  return result;
151 }
152 
154  ossim_uint32 resLevel)
155 {
156  if(resLevel < getNumberOfResLevels())
157  {
158  theHistogramList[resLevel] = histo;
159  return true;
160  }
161  return false;
162 }
163 
165 {
166  for(ossim_uint32 idx = 0; idx < (ossim_uint32)theHistogramList.size(); ++idx)
167  {
168  if(theHistogramList[idx].valid())
169  {
170  theHistogramList[idx] = NULL;
171  }
172  }
173 
174  theHistogramList.clear();
175 }
176 
178  ossim_uint32 resLevel)
179 {
181 
182  if(temp.valid())
183  {
184  return temp->getHistogram(band);
185  }
186 
187  return (ossimHistogram*)0;
188 }
190  ossim_uint32 resLevel)const
191 {
193 
194  if(temp.valid())
195  {
196  return temp->getHistogram(band);
197  }
198 
199  return (ossimHistogram*)0;
200 }
201 
203 {
204  return (ossim_uint32)theHistogramList.size();
205 }
206 
208 {
210  if (h.valid())
211  {
212  return h->getNumberOfBands();
213  }
214 
215  return 0;
216 }
217 
219 {
220  if(resLevel < (ossim_uint32)theHistogramList.size())
221  {
222  return theHistogramList[resLevel];
223  }
224 
225  return NULL;
226 }
227 
229 {
230  if (!in) // Check stream state.
231  {
232  return false;
233  }
234 
235  ossimString buffer;
236  getline(in, buffer);
237 
238  if ( in.eof() ) // Zero byte files will hit here.
239  {
240  return false;
241  }
242 
243  // check to see if it is a proprietary histogram file
244  //
245  if((buffer =="") || (buffer.c_str()[0] != 'F' ||
246  buffer.c_str()[1] != 'i'))
247  {
248  in.seekg(0, ios::beg);
249  ossimKeywordlist kwl;
250  if (kwl.parseStream(in) == true)
251  {
252  return loadState(kwl);
253  }
254  else
255  {
256  return false;
257  }
258  }
259 
261  in.seekg(0, ios::beg);
263  if(header.parseStream(in))
264  {
265  ossim_uint32 numberOfResLevels = header.getNumberOfResLevels();
266 
267  if(numberOfResLevels)
268  {
269  theHistogramList.resize(numberOfResLevels);
270 
271  for(ossim_uint32 counter = 0; counter < (ossim_uint32)theHistogramList.size(); ++counter)
272  {
273  theHistogramList[counter] = NULL;
274  }
275  ossimString reslevelBuffer;
276  ossimString buffer;
277 
278  for(ossim_uint32 idx = 0; idx < numberOfResLevels; ++idx)
279  {
280  getline(in, buffer);
281  if(buffer.find("RR Level") != string::npos)
282  {
283  std::string::size_type offset = buffer.find(":");
284  if(offset != string::npos)
285  {
286  reslevelBuffer = buffer.substr(offset+1);
287  }
288  else
289  {
291  return false;
292  }
293  }
294  else
295  {
297  return false;
298  }
299  ossim_uint32 resLevelIdx = reslevelBuffer.toUInt32();
300 
301  if(resLevelIdx < (ossim_uint32)theHistogramList.size())
302  {
303  if(!theHistogramList[resLevelIdx])
304  {
306  if(histogram->importHistogram(in))
307  {
308  theHistogramList[resLevelIdx] = histogram;
309  }
310  else
311  {
313  return false;
314  }
315  }
316  }
317  else
318  {
320  return false;
321  }
322  ossimString skipDot;
323  getline(in, skipDot);
324  }
325  }
326  else
327  {
328  return false;
329  }
330  }
331 
332  return true;
333 }
334 
336 {
337  //---
338  // File size check removed for s3
339  // if( file.fileSize() > 0 )
340  // {
341  // theHistogramFile = file;
342 
343  bool result = false;
344  std::shared_ptr<ossim::istream> in = ossim::StreamFactoryRegistry::instance()->
345  createIstream( file, std::ios_base::in );
346  if ( in )
347  {
348  result = importHistogram( *in );
349  if ( result )
350  {
351  theHistogramFile = file;
352  }
353  }
354  return result;
355 }
356 
358 {
359  ossimString inputLine;
360 
361  getline(in, inputLine);
362  if(inputLine.find("File Type") != string::npos)
363  {
364  std::string::size_type idx = inputLine.find(":");
365  if(idx != string::npos)
366  {
367  theFileType = inputLine.substr(idx+1);
369  }
370  else
371  {
372  return false;
373  }
374 
375  }
376  else
377  {
378  return false;
379  }
380 
381  getline(in, inputLine);
382  if(inputLine.find("Version") != string::npos)
383  {
384  std::string::size_type idx = inputLine.find(":");
385  if(idx != string::npos)
386  {
387  theVersion = inputLine.substr(idx+1);
389  }
390  else
391  {
392  return false;
393  }
394  }
395  else
396  {
397  return false;
398  }
399 
400  getline(in, inputLine);
401  if(inputLine.find("Creator ID") != string::npos)
402  {
403  std::string::size_type idx = inputLine.find(":");
404  if(idx != string::npos)
405  {
406  theCreatorId = inputLine.substr(idx+1);
408  }
409  else
410  {
411  return false;
412  }
413  }
414  else
415  {
416  return false;
417  }
418 
419  getline(in, inputLine);
420  if(inputLine.find("RR Levels") != string::npos)
421  {
422  std::string::size_type idx = inputLine.find(":");
423  if(idx != string::npos)
424  {
425  theNumberOfResLevels = inputLine.substr(idx+1);
427  }
428  else
429  {
430  return false;
431  }
432  }
433  else
434  {
435  return false;
436  }
437 
438  return true;
439 }
440 
442  const char* prefix)const
443 {
444  bool result = true;
445  if(theHistogramList.size() > 0)
446  {
447  ossimString s1 = prefix;
448  kwl.add(prefix,
450  "ossimMultiResLevelHistogram",
451  true);
452  kwl.add(prefix,
453  NUMBER_OF_RES_LEVELS.key(),
454  static_cast<ossim_uint32>(theHistogramList.size()),
455  true);
456 
457  for(ossim_uint32 idx = 0; idx < theHistogramList.size(); ++idx)
458  {
459  ossimString rr_level = ossimString(prefix) + "rr_level";
460  rr_level += ossimString::toString(idx) + ".";
461  if(theHistogramList[idx].valid())
462  {
463  result = theHistogramList[idx]->saveState(kwl, rr_level.c_str());
464 
465  if(!result)
466  {
467  return result;
468  }
469  }
470  }
471  }
472 
473  return result;
474 }
475 
477  const char* prefix)
478 {
480  const char* number_of_res_levels = kwl.find(prefix, NUMBER_OF_RES_LEVELS.key());
481 
482  if(number_of_res_levels)
483  {
484  ossim_uint32 numberOfResLevels = ossimString(number_of_res_levels).toUInt32();
485 
486  if(numberOfResLevels)
487  {
488  ossimString newPrefix;
489  for(ossim_uint32 idx = 0; idx < numberOfResLevels; ++idx)
490  {
492 
493  if (prefix) newPrefix = prefix;
494 
495  newPrefix += "rr_level";
496  newPrefix += ossimString::toString(idx);
497  newPrefix += ".";
498 
499  histo->loadState(kwl, newPrefix.c_str());
500 
501  theHistogramList.push_back(histo);
502  }
503  }
504  }
505  return true;
506 }
507 
509 {
510  return theHistogramFile;
511 }
virtual bool setHistogram(ossimRefPtr< ossimMultiBandHistogram > histo, ossim_uint32 resLevel)
virtual bool importHistogram(const ossimFilename &inputFile)
ossimRefPtr< ossimMultiResLevelHistogram > createAccumulationGreaterThanEqual() const
ossimRefPtr< ossimHistogram > getHistogram(ossim_uint32 band, ossim_uint32 resLevel=0)
void setBinCount(double binNumber, double count)
Represents serializable keyword/value map.
bool valid() const
Definition: ossimRefPtr.h:75
const char * find(const char *key) const
std::vector< ossimRefPtr< ossimMultiBandHistogram > > theHistogramList
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
static ossimString toString(bool aValue)
Numeric to string methods.
void create(ossim_uint32 numberOfResLevels)
ossim_uint32 toUInt32() const
static StreamFactoryRegistry * instance()
std::istream & getline(std::istream &is, ossimString &str, char delim)
Definition: ossimString.h:916
static const char * TYPE_KW
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
ossim_uint32 getNumberOfBands() const
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
ossimRefPtr< ossimHistogram > getHistogram(ossim_int32 band)
ossim_uint32 getNumberOfBands(ossim_uint32 resLevel=0) const
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
virtual bool parseStream(ossim::istream &is, bool ignoreBinaryChars)
deprecated method
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396
std::string substr(std::string::size_type pos=0, std::string::size_type n=std::string::npos) const
Equivalent to basic_string(*this, pos, n).
Definition: ossimString.h:910
virtual ossimRefPtr< ossimMultiBandHistogram > addHistogram()
ossimRefPtr< ossimMultiBandHistogram > getMultiBandHistogram(ossim_uint32 resLevel) const
std::string::size_type find(const std::string &s, std::string::size_type pos=0) const
Searches for s as a substring of *this, beginning at character pos of *this.
Definition: ossimString.h:753
virtual ossimFilename getHistogramFile() const
ossimRefPtr< ossimMultiResLevelHistogram > createAccumulationLessThanEqual() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
const char * key() const
virtual bool importHistogram(const ossimFilename &inputFile)