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

#include <ossimRgbLutDataObject.h>

Inheritance diagram for ossimRgbLutDataObject:
ossimObject ossimReferenced

Public Member Functions

 ossimRgbLutDataObject (unsigned long numberOfEntries=0)
 
 ossimRgbLutDataObject (const ossimRgbLutDataObject &lut)
 
virtual ossimObjectdup () const
 
const ossimRgbVectoroperator[] (unsigned int index) const
 
ossimRgbVectoroperator[] (unsigned int index)
 
const ossimRgbVectoroperator[] (int index) const
 
ossimRgbVectoroperator[] (int index)
 
const ossimRgbVectoroperator[] (double normalizedIndex) const
 
ossimRgbVectoroperator[] (double normalizedIndex)
 
long getNumberOfEntries () const
 
int findIndex (const ossimRgbVector &rgb)
 
int findIndex (ossim_uint8 r, ossim_uint8 g, ossim_uint8 b)
 
ossimRgbLutDataObjectrotate (long numberOfElements=1)
 
ossimRgbLutDataObject rotate (long numberOfElements=1) const
 
const ossimRgbLutDataObjectoperator= (const ossimRgbLutDataObject &lut)
 
bool operator== (const ossimRgbLutDataObject &lut) const
 
virtual bool saveState (ossimKeywordlist &kwl, const char *prefix=0) const
 
virtual bool loadState (const ossimKeywordlist &kwl, const char *prefix=0)
 
- Public Member Functions inherited from ossimObject
 ossimObject ()
 
virtual ~ossimObject ()
 
virtual ossimString getShortName () const
 
virtual ossimString getLongName () const
 
virtual ossimString getDescription () const
 
virtual ossimString getClassName () const
 
virtual RTTItypeid getType () const
 
virtual bool canCastTo (ossimObject *obj) const
 
virtual bool canCastTo (const RTTItypeid &id) const
 
virtual bool canCastTo (const ossimString &parentClassName) const
 
virtual std::ostream & print (std::ostream &out) const
 Generic print method. More...
 
virtual bool isEqualTo (const ossimObject &obj, ossimCompareType compareType=OSSIM_COMPARE_FULL) const
 
virtual void accept (ossimVisitor &visitor)
 
- Public Member Functions inherited from ossimReferenced
 ossimReferenced ()
 
 ossimReferenced (const ossimReferenced &)
 
ossimReferencedoperator= (const ossimReferenced &)
 
void ref () const
 increment the reference count by one, indicating that this object has another pointer which is referencing it. More...
 
void unref () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
void unref_nodelete () const
 decrement the reference count by one, indicating that a pointer to this object is referencing it. More...
 
int referenceCount () const
 

Protected Member Functions

virtual ~ossimRgbLutDataObject ()
 
- Protected Member Functions inherited from ossimReferenced
virtual ~ossimReferenced ()
 

Protected Attributes

ossimRgbVectortheLut
 
ossim_uint32 theNumberOfEntries
 

Friends

std::ostream & operator<< (std::ostream &out, const ossimRgbLutDataObject &lut)
 

Detailed Description

Definition at line 18 of file ossimRgbLutDataObject.h.

Constructor & Destructor Documentation

◆ ossimRgbLutDataObject() [1/2]

ossimRgbLutDataObject::ossimRgbLutDataObject ( unsigned long  numberOfEntries = 0)

Will allocate 256 values for the color table

Definition at line 34 of file ossimRgbLutDataObject.cpp.

References theLut, and theNumberOfEntries.

35  :
36  theLut(NULL),
37  theNumberOfEntries(numberOfEntries)
38 {
39  if(theNumberOfEntries > 0)
40  {
41  // allocate 256 entries for the data object;
43  }
44 
45 }

◆ ossimRgbLutDataObject() [2/2]

ossimRgbLutDataObject::ossimRgbLutDataObject ( const ossimRgbLutDataObject lut)

Definition at line 47 of file ossimRgbLutDataObject.cpp.

References theLut, and theNumberOfEntries.

48  :
49  theLut(NULL),
51 {
53  if(theNumberOfEntries > 0)
54  {
56  for(ossim_uint32 index = 0; index < theNumberOfEntries; ++index)
57  {
58  theLut[index] = lut.theLut[index];
59  }
60  }
61 }
unsigned int ossim_uint32

◆ ~ossimRgbLutDataObject()

ossimRgbLutDataObject::~ossimRgbLutDataObject ( )
protectedvirtual

Definition at line 63 of file ossimRgbLutDataObject.cpp.

References theLut, and theNumberOfEntries.

64 {
65  if(theLut)
66  {
67  delete [] theLut;
68  theLut = NULL;
69  }
71 }

Member Function Documentation

◆ dup()

virtual ossimObject* ossimRgbLutDataObject::dup ( ) const
inlinevirtual

Reimplemented from ossimObject.

Definition at line 28 of file ossimRgbLutDataObject.h.

Referenced by ossimRgbToIndexFilter::setLut().

29  {
30  return new ossimRgbLutDataObject(*this);
31  }
ossimRgbLutDataObject(unsigned long numberOfEntries=0)

◆ findIndex() [1/2]

int ossimRgbLutDataObject::findIndex ( const ossimRgbVector rgb)
inline

Definition at line 67 of file ossimRgbLutDataObject.h.

References ossimRgbVector::getB(), ossimRgbVector::getG(), and ossimRgbVector::getR().

Referenced by ossimRgbToIndexFilter::convertInputTile().

68  {
69  return findIndex(rgb.getR(),
70  rgb.getG(),
71  rgb.getB());
72  }
unsigned char getR() const
unsigned char getB() const
unsigned char getG() const
int findIndex(const ossimRgbVector &rgb)

◆ findIndex() [2/2]

int ossimRgbLutDataObject::findIndex ( ossim_uint8  r,
ossim_uint8  g,
ossim_uint8  b 
)

Definition at line 73 of file ossimRgbLutDataObject.cpp.

References distance(), ossimRgbVector::getB(), ossimRgbVector::getG(), ossimRgbVector::getR(), theLut, and theNumberOfEntries.

74 {
75  ossim_uint32 distance = 0x7FFFFFFF; // max 4 byte signed
76  ossim_int32 result = 0;
77 
78  if(theNumberOfEntries > 0)
79  {
80  for(ossim_uint32 i = 0; i < theNumberOfEntries; ++i)
81  {
82  ossim_uint32 rDelta = r - theLut[i].getR();
83  ossim_uint32 gDelta = g - theLut[i].getG();
84  ossim_uint32 bDelta = b - theLut[i].getB();
85 
86  ossim_uint32 deltaSumSquare = (rDelta*rDelta +
87  gDelta*gDelta +
88  bDelta*bDelta);
89  if(deltaSumSquare == 0)
90  {
91  return static_cast<int>(i);
92  }
93  else if( deltaSumSquare < distance)
94  {
95  result = static_cast<int>(i);
96  distance = deltaSumSquare;
97  }
98  }
99  }
100 
101  return result;
102 }
unsigned char getR() const
unsigned int ossim_uint32
unsigned char getB() const
unsigned char getG() const
float distance(double lat1, double lon1, double lat2, double lon2, int units)
int ossim_int32

◆ getNumberOfEntries()

long ossimRgbLutDataObject::getNumberOfEntries ( ) const
inline

Definition at line 66 of file ossimRgbLutDataObject.h.

66 {return theNumberOfEntries;}

◆ loadState()

bool ossimRgbLutDataObject::loadState ( const ossimKeywordlist kwl,
const char *  prefix = 0 
)
virtual

Method to the load (recreate) the state of the object from a keyword list. Return true if ok or false on error.

Reimplemented from ossimObject.

Definition at line 199 of file ossimRgbLutDataObject.cpp.

References ossimKeywordlist::addFile(), ossimString::c_str(), ossimFilename::exists(), ossimKeywordlist::find(), ossimRgbVector::setB(), ossimRgbVector::setG(), ossimRgbVector::setR(), theLut, theNumberOfEntries, ossimString::toInt32(), ossimString::toString(), and ossimString::toULong().

Referenced by ossimRgbToIndexFilter::loadState().

200 {
201  const char* lutFile = kwl.find(prefix, "lut_file");
202  ossimKeywordlist fileLut;
203  ossimKeywordlist* tempKwl = (const_cast<ossimKeywordlist*>(&kwl));
204  ossimString tempPrefix = prefix;
205 
206  // this should have been used instead of lut_file. We will still look
207  // for lut_file for backward compatibility.
208  //
209  if(!lutFile)
210  {
211  lutFile = kwl.find(prefix, "filename");
212  }
213  // check to see if we should open an external file
214  // if so point the fileLut to the one that we use
215  if(lutFile)
216  {
217  ossimFilename filename(lutFile);
218  if(filename.exists())
219  {
220  fileLut.addFile(filename.c_str());
221  tempKwl = &fileLut;
222  tempPrefix = "";
223  }
224  }
225 
226  const char* numberOfEntries = tempKwl->find(tempPrefix, "number_of_entries");
227  if(!numberOfEntries)
228  {
229  numberOfEntries = tempKwl->find(tempPrefix, "number_entries");
230  }
231  if(!numberOfEntries) return false;
232  theNumberOfEntries = ossimString(numberOfEntries).toULong();
233 
234  delete [] theLut;
236 
237  if(tempKwl->find(tempPrefix, "entry0"))
238  {
239  for(ossim_uint32 index = 0; index < theNumberOfEntries; ++index)
240  {
241  ossimString newPrefix = "entry";
242  newPrefix += ossimString::toString(index);
243  ossimString v = tempKwl->find(tempPrefix, newPrefix.c_str());
244  istringstream istr(v);
245 
246  ossimString r, g, b;
247  istr >> r >> g >> b;
248  theLut[index].setR((unsigned char)r.toInt32());
249  theLut[index].setG((unsigned char)g.toInt32());
250  theLut[index].setB((unsigned char)b.toInt32());
251  }
252  }
253  else
254  {
255  for(ossim_uint32 index = 0; index < theNumberOfEntries; ++index)
256  {
257  ossimString newPrefix = "entry";
258  newPrefix += ossimString::toString(index);
259 
260  const char* r = tempKwl->find(tempPrefix, (newPrefix+".r").c_str());
261  const char* g = tempKwl->find(tempPrefix, (newPrefix+".g").c_str());
262  const char* b = tempKwl->find(tempPrefix, (newPrefix+".b").c_str());
263 
264  if(r)
265  {
266  theLut[index].setR((unsigned char)ossimString(r).toLong());
267  }
268  if(g)
269  {
270  theLut[index].setG((unsigned char)ossimString(g).toLong());
271  }
272  if(b)
273  {
274  theLut[index].setB((unsigned char)ossimString(b).toLong());
275  }
276  }
277  }
278  return true;
279 }
Represents serializable keyword/value map.
bool addFile(const char *file)
const char * find(const char *key) const
void setR(unsigned char R)
static ossimString toString(bool aValue)
Numeric to string methods.
void setB(unsigned char B)
ossim_int32 toInt32() const
unsigned int ossim_uint32
unsigned long toULong() const
void setG(unsigned char G)
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::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32

◆ operator=()

const ossimRgbLutDataObject & ossimRgbLutDataObject::operator= ( const ossimRgbLutDataObject lut)

Definition at line 135 of file ossimRgbLutDataObject.cpp.

References theLut, and theNumberOfEntries.

136 {
138  {
139  delete [] theLut;
140  theLut = NULL;
141  }
142 
144  if(!theLut&&(theNumberOfEntries > 0))
145  {
147  }
148  for(unsigned long index = 0; index < theNumberOfEntries; ++index)
149  {
150  theLut[index] = lut.theLut[index];
151  }
152 
153  return *this;
154 }

◆ operator==()

bool ossimRgbLutDataObject::operator== ( const ossimRgbLutDataObject lut) const

Definition at line 156 of file ossimRgbLutDataObject.cpp.

References theLut, and theNumberOfEntries.

157 {
159  {
160  return false;
161  }
162  for(unsigned long index = 0; index < theNumberOfEntries; ++index)
163  {
164  if(theLut[index] != lut.theLut[index])
165  {
166  return false;
167  }
168  }
169  return true;
170 }

◆ operator[]() [1/6]

const ossimRgbVector& ossimRgbLutDataObject::operator[] ( unsigned int  index) const
inline

Definition at line 32 of file ossimRgbLutDataObject.h.

33  {
34  return index<theNumberOfEntries?theLut[index]:theLut[theNumberOfEntries-1];
35  }

◆ operator[]() [2/6]

ossimRgbVector& ossimRgbLutDataObject::operator[] ( unsigned int  index)
inline

Definition at line 36 of file ossimRgbLutDataObject.h.

37  {
38  return index<theNumberOfEntries?theLut[index]:theLut[theNumberOfEntries-1];
39  }

◆ operator[]() [3/6]

const ossimRgbVector& ossimRgbLutDataObject::operator[] ( int  index) const
inline

Definition at line 40 of file ossimRgbLutDataObject.h.

41  {
42  return index<(long)theNumberOfEntries?theLut[index]:theLut[theNumberOfEntries-1];
43  }

◆ operator[]() [4/6]

ossimRgbVector& ossimRgbLutDataObject::operator[] ( int  index)
inline

Definition at line 44 of file ossimRgbLutDataObject.h.

45  {
46  return index<(long)theNumberOfEntries?theLut[index]:theLut[theNumberOfEntries-1];
47  }

◆ operator[]() [5/6]

const ossimRgbVector& ossimRgbLutDataObject::operator[] ( double  normalizedIndex) const
inline

Definition at line 48 of file ossimRgbLutDataObject.h.

49  {
50  int index = int(normalizedIndex*theNumberOfEntries+.5);
51  if (index < 0)
52  {
53  index = 0;
54  }
55  return (*this)[index];
56  }

◆ operator[]() [6/6]

ossimRgbVector& ossimRgbLutDataObject::operator[] ( double  normalizedIndex)
inline

Definition at line 57 of file ossimRgbLutDataObject.h.

58  {
59  int index = int(normalizedIndex*theNumberOfEntries+.5);
60  if (index < 0)
61  {
62  index = 0;
63  }
64  return (*this)[index];
65  }

◆ rotate() [1/2]

ossimRgbLutDataObject & ossimRgbLutDataObject::rotate ( long  numberOfElements = 1)

Definition at line 121 of file ossimRgbLutDataObject.cpp.

References ossimNotify(), ossimNotifyLevel_FATAL, and rotate().

Referenced by rotate().

122 {
123  if(numberOfElements < 0)
124  {
125  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL: Negative rotation is not supported yet in ossimRgbLutDataObject::rotate" << endl;
126  return *this;
127  }
128  const ossimRgbLutDataObject* temp = this;
129 
130  *this = temp->rotate(numberOfElements);
131 
132  return *this;
133 }
ossimRgbLutDataObject & rotate(long numberOfElements=1)
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ rotate() [2/2]

ossimRgbLutDataObject ossimRgbLutDataObject::rotate ( long  numberOfElements = 1) const

Definition at line 104 of file ossimRgbLutDataObject.cpp.

References ossimNotify(), ossimNotifyLevel_FATAL, theLut, and theNumberOfEntries.

105 {
106  if(numberOfElements < 0)
107  {
108  ossimNotify(ossimNotifyLevel_FATAL) << "FATAL: Negative rotation is not supported yet in ossimRgbLutDataObject::rotate" << endl;
109  return *this;
110  }
112  for(ossim_uint32 index = 0; index < theNumberOfEntries; ++index)
113  {
114  int adjustedDestinationIndex = (index+numberOfElements)%theNumberOfEntries;
115  lut[adjustedDestinationIndex] = theLut[index] ;
116  }
117 
118  return lut;
119 }
unsigned int ossim_uint32
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)

◆ saveState()

bool ossimRgbLutDataObject::saveState ( ossimKeywordlist kwl,
const char *  prefix = 0 
) const
virtual

Method to save the state of the object to a keyword list. Return true if ok or false on error.

Reimplemented from ossimObject.

Definition at line 172 of file ossimRgbLutDataObject.cpp.

References ossimKeywordlist::add(), ossimString::c_str(), ossimRgbVector::getB(), ossimObject::getClassName(), ossimRgbVector::getG(), theLut, theNumberOfEntries, and ossimString::toString().

Referenced by ossimRgbToIndexFilter::saveState().

173 {
174  kwl.add(prefix,
175  "type",
176  getClassName(),
177  true);
178  kwl.add(prefix,
179  "number_of_entries",
181  true);
182  for(ossim_uint32 index = 0; index < theNumberOfEntries; ++index)
183  {
184  ossimString newPrefix = "entry";
185  newPrefix += ossimString::toString(index);
186  ostringstream ostr;
187  ostr << (int)(theLut[index].getR())
188  << " " << (int)(theLut[index].getG())
189  << " " << (int)(theLut[index].getB());
190  kwl.add(prefix,
191  newPrefix,
192  ostr.str().c_str(),
193  true);
194  }
195 
196  return true;
197 }
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
static ossimString toString(bool aValue)
Numeric to string methods.
virtual ossimString getClassName() const
Definition: ossimObject.cpp:64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
unsigned int ossim_uint32
unsigned char getB() const
unsigned char getG() const

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  out,
const ossimRgbLutDataObject lut 
)
friend

Member Data Documentation

◆ theLut

ossimRgbVector* ossimRgbLutDataObject::theLut
protected

◆ theNumberOfEntries

ossim_uint32 ossimRgbLutDataObject::theNumberOfEntries
protected

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