1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License:  LGPL
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Garrett Potts
9 //
10 //*************************************************************************
11 // $Id: ossimHistogramSource.cpp 11721 2007-09-13 13:19:34Z gpotts $
12 
13 #include <ossim/base/ossimHistogramSource.h>
14 #include <ossim/base/ossimKeywordNames.h>
15 #include <ossim/base/ossimMultiResLevelHistogram.h>
16 
17 RTTI_DEF1(ossimHistogramSource, "ossimHistogramSource", ossimSource);
18 
19 
ossimHistogramSource(ossimObject * owner,ossim_uint32 numberOfInputs,ossim_uint32 numberOfOutputs,bool inputListFixedFlag,bool outputListFixedFlag)20 ossimHistogramSource::ossimHistogramSource(ossimObject* owner,
21                                            ossim_uint32 numberOfInputs,
22                                            ossim_uint32 numberOfOutputs,
23                                            bool inputListFixedFlag,
24                                            bool outputListFixedFlag)
25    : ossimSource(owner,
26                  numberOfInputs,
27                  numberOfOutputs,
28                  inputListFixedFlag,
29                  outputListFixedFlag),
30      theHistogram(0),
31      theFilename()
32 {
33 }
34 
~ossimHistogramSource()35 ossimHistogramSource::~ossimHistogramSource()
36 {
37 }
38 
getHistogram()39 ossimRefPtr<ossimMultiResLevelHistogram> ossimHistogramSource::getHistogram()
40 {
41    return theHistogram;
42 }
43 
loadState(const ossimKeywordlist & kwl,const char * prefix)44 bool ossimHistogramSource::loadState(const ossimKeywordlist& kwl,
45 				     const char* prefix)
46 {
47    theHistogram = 0;
48    const char* externalFile = kwl.find(prefix,
49                                        ossimKeywordNames::FILENAME_KW);
50 
51    theHistogram = new ossimMultiResLevelHistogram;
52    if(externalFile)
53    {
54       if(!theHistogram->importHistogram(ossimFilename(externalFile)))
55       {
56          theHistogram = 0;
57          theFilename = "";
58       }
59       theFilename = externalFile;
60    }
61    else
62    {
63       ossimString newPrefix = ossimString(prefix) + "histogram.";
64       if(!theHistogram->loadState(kwl, newPrefix))
65       {
66          theHistogram = 0;
67       }
68    }
69 
70    return ossimSource::loadState(kwl, prefix);
71 }
72 
saveState(ossimKeywordlist & kwl,const char * prefix) const73 bool ossimHistogramSource::saveState(ossimKeywordlist& kwl,
74 				     const char* prefix)const
75 {
76    if(theHistogram.valid())
77    {
78       if(!theFilename.empty())      {
79          ossimKeywordlist kwl2;
80 
81          if(theHistogram->saveState(kwl2))
82          {
83             kwl2.write(theFilename.c_str());
84             kwl.add(prefix,
85                     ossimKeywordNames::FILENAME_KW,
86                     theFilename.c_str(),
87                     true);
88          }
89       }
90       else
91       {
92          ossimString newPrefix = ossimString(prefix) + "histogram.";
93          theHistogram->saveState(kwl, newPrefix);
94       }
95    }
96 
97    return ossimSource::saveState(kwl, prefix);
98 }
99 
100 // Hidden from use.
ossimHistogramSource(const ossimHistogramSource &)101 ossimHistogramSource::ossimHistogramSource(const ossimHistogramSource&)
102    :
103    theHistogram(0),
104    theFilename()
105 {
106 }
107