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

#include <ossimWavelength.h>

Public Types

typedef std::map< ossim_float64, ossim_uint32WavelengthMap
 

Public Member Functions

 ossimWavelength ()
 default constructor More...
 
 ossimWavelength (const ossimWavelength &obj)
 copy constructor More...
 
const ossimWavelengthoperator= (const ossimWavelength &rhs)
 assignment operator= More...
 
 ~ossimWavelength ()
 virtual destructor More...
 
const ossimWavelength::WavelengthMapgetMap () const
 
ossimWavelength::WavelengthMapgetMap ()
 
bool initialize (const ossimEnviHeader &hdr)
 Initializes map from ENVI header class. More...
 
WavelengthMap::const_iterator findClosestIterator (const ossim_float64 &requestedWavelength, const ossim_float64 &thresholdFromCenter) const
 Finds iterator closest to wavelength. More...
 
ossim_int32 findClosestIndex (const ossim_float64 &requestedWavelength, const ossim_float64 &thresholdFromCenter) const
 Finds index closest to wavelength. More...
 
bool getRgbBands (std::vector< ossim_uint32 > &bands) const
 Gets rgb bands if "wavelength" keyword is present. More...
 
WavelengthMap::const_iterator end () const
 
WavelengthMap::iterator end ()
 

Private Attributes

WavelengthMap m_map
 

Detailed Description

Definition at line 34 of file ossimWavelength.h.

Member Typedef Documentation

◆ WavelengthMap

Definition at line 38 of file ossimWavelength.h.

Constructor & Destructor Documentation

◆ ossimWavelength() [1/2]

ossimWavelength::ossimWavelength ( )

default constructor

Definition at line 18 of file ossimWavelength.cpp.

19  : m_map()
20 {}
WavelengthMap m_map

◆ ossimWavelength() [2/2]

ossimWavelength::ossimWavelength ( const ossimWavelength obj)

copy constructor

Definition at line 22 of file ossimWavelength.cpp.

23  : m_map( obj.m_map )
24 {}
WavelengthMap m_map

◆ ~ossimWavelength()

ossimWavelength::~ossimWavelength ( )

virtual destructor

Definition at line 35 of file ossimWavelength.cpp.

36 {
37 }

Member Function Documentation

◆ end() [1/2]

ossimWavelength::WavelengthMap::const_iterator ossimWavelength::end ( ) const
Returns
WavelengthMap::const_iterator of underlying map.

Definition at line 195 of file ossimWavelength.cpp.

196 {
197  return m_map.end();
198 }
WavelengthMap m_map

◆ end() [2/2]

ossimWavelength::WavelengthMap::iterator ossimWavelength::end ( )
Returns
WavelengthMap::iterator of underlying map.

Definition at line 200 of file ossimWavelength.cpp.

201 {
202  return m_map.end();
203 }
WavelengthMap m_map

◆ findClosestIndex()

ossim_int32 ossimWavelength::findClosestIndex ( const ossim_float64 requestedWavelength,
const ossim_float64 thresholdFromCenter 
) const

Finds index closest to wavelength.

Parameters
requestedWavelengthRequested wavelength in nanometers.
thresholdFromCenterin nanometers.
Returns
Closest zero based index to wavelength or -1 if not found.

Definition at line 139 of file ossimWavelength.cpp.

141 {
142  ossim_int32 result = -1;
143  WavelengthMap::const_iterator i =
144  findClosestIterator( requestedWavelength, thresholdFromCenter );
145  if ( i != m_map.end() )
146  {
147  result = (*i).second;
148  }
149  return result;
150 
151 } // End: ossim_int32 ossimWavelength::findClosestIndex(...
WavelengthMap::const_iterator findClosestIterator(const ossim_float64 &requestedWavelength, const ossim_float64 &thresholdFromCenter) const
Finds iterator closest to wavelength.
WavelengthMap m_map
int ossim_int32

◆ findClosestIterator()

ossimWavelength::WavelengthMap::const_iterator ossimWavelength::findClosestIterator ( const ossim_float64 requestedWavelength,
const ossim_float64 thresholdFromCenter 
) const

Finds iterator closest to wavelength.

Parameters
requestedWavelengthRequested wavelength in nanometers.
thresholdFromCenterin nanometers.
Returns
WavelengthMap::const_iterator if not found will return.

Definition at line 100 of file ossimWavelength.cpp.

103 {
104  WavelengthMap::const_iterator result = m_map.lower_bound( requestedWavelength );
105  if ( result != m_map.end() )
106  {
107  if ( result != m_map.begin() ) // && (result->first > requestedWavelength) )
108  {
109  // Somewhere in the middle.
110  WavelengthMap::const_iterator lower = result;
111  --lower;
112 
113  ossim_float64 t = (requestedWavelength - lower->first) / (result->first -lower->first);
114  if ( t < 0.5 )
115  {
116  result = lower;
117  }
118  }
119  }
120  else
121  {
122  --result;
123  }
124 
125  if ( result != m_map.end() )
126  {
127  // Within threshold check.
128  if ( std::fabs( result->first - requestedWavelength) > thresholdFromCenter )
129  {
130  result = m_map.end();
131  }
132 
133  } // if ( result != m_map.end() )
134 
135  return result;
136 
137 } // End: WavelengthMap::const_iterator ossimWavelength::findClosestIterator
double ossim_float64
WavelengthMap m_map

◆ getMap() [1/2]

const ossimWavelength::WavelengthMap & ossimWavelength::getMap ( ) const

Definition at line 39 of file ossimWavelength.cpp.

References m_map.

40 {
41  return m_map;
42 }
WavelengthMap m_map

◆ getMap() [2/2]

ossimWavelength::WavelengthMap & ossimWavelength::getMap ( )

Definition at line 44 of file ossimWavelength.cpp.

References m_map.

45 {
46  return m_map;
47 }
WavelengthMap m_map

◆ getRgbBands()

bool ossimWavelength::getRgbBands ( std::vector< ossim_uint32 > &  bands) const

Gets rgb bands if "wavelength" keyword is present.

Parameters
bandsInitialized by this with zero base rbg band indexes.
Returns
true on success, false if bands not found.

Definition at line 153 of file ossimWavelength.cpp.

154 {
155  bool result = false;
156 
157  if ( m_map.size() )
158  {
159  //---
160  // Attempt to find bands with closest rgb wavelengths.
161  // red: 620 - 750 nm
162  // green: 495 - 570 nm
163  // blue: 450 - 495 nm
164  //---
165  //const ossim_float32 RED_WAVELENGTH = 439.978577; // 442.0;
166  //const ossim_float32 GREEN_WAVELENGTH = 546.666504; // 546.0;
167  //const ossim_float32 BLUE_WAVELENGTH = 636.941406; // 637.0;
168  const ossim_float32 RED_WAVELENGTH = 685.0;
169  const ossim_float32 GREEN_WAVELENGTH = 532.5;
170  const ossim_float32 BLUE_WAVELENGTH = 472.5;
171  const ossim_float32 RED_THRESHOLD_FROM_CENTER = 65.0;
172  const ossim_float32 GREEN_THRESHOLD_FROM_CENTER = 37.5;
173  const ossim_float32 BLUE_THRESHOLD_FROM_CENTER = 22.5;
174 
175  WavelengthMap::const_iterator r =
176  findClosestIterator( RED_WAVELENGTH, RED_THRESHOLD_FROM_CENTER );
177  WavelengthMap::const_iterator g =
178  findClosestIterator( GREEN_WAVELENGTH, GREEN_THRESHOLD_FROM_CENTER );
179  WavelengthMap::const_iterator b =
180  findClosestIterator( BLUE_WAVELENGTH, BLUE_THRESHOLD_FROM_CENTER );
181 
182  if ( (r != m_map.end()) && (g != m_map.end()) && (b != m_map.end()) )
183  {
184  bands.resize(3);
185  bands[0] = (*r).second;
186  bands[1] = (*g).second;
187  bands[2] = (*b).second;
188  result = true;
189  }
190  }
191  return result;
192 
193 } // bool ossimWavelength::getRgbBands( std::vector<ossim_uint32>& ) const
WavelengthMap::const_iterator findClosestIterator(const ossim_float64 &requestedWavelength, const ossim_float64 &thresholdFromCenter) const
Finds iterator closest to wavelength.
float ossim_float32
WavelengthMap m_map

◆ initialize()

bool ossimWavelength::initialize ( const ossimEnviHeader hdr)

Initializes map from ENVI header class.

This will clear any existing map, look for the keywords "wavelength units" and "wavelength".

Parameters
headerto initialize from.
Returns
true on success, false on error.

Definition at line 49 of file ossimWavelength.cpp.

References ossimString::downcase(), ossimEnviHeader::getValue(), m_map, ossimString::size(), ossimString::split(), ossimString::trim(), and true.

50 {
51  //---
52  // Example envi wavelength format:
53  // wavelength = { 374.323608, 382.530487, 390.737427 }
54  //---
55  ossimString value;
56 
57  // Check the units...
58  ossimString key = "wavelength units";
59  if ( hdr.getValue( key, value ) )
60  {
61  if ( value.downcase() == "nanometers" )
62  {
63  // Check for wavelength key:
64  key = "wavelength";
65  if ( hdr.getValue( key, value ) )
66  {
67  if ( value.size() )
68  {
69  // Split into array.
70  value.trim( ossimString("{}") );
71  std::vector<ossimString> list;
72  value.split( list, ossimString(","), true );
73 
74  if ( list.size() )
75  {
76  // Initialize the map:
77 
78  std::vector<ossimString>::const_iterator i = list.begin();
79  ossim_uint32 band = 0;
80  ossim_float32 wavelength = 0.0;
81 
82  while ( i != list.end() )
83  {
84  wavelength = (*i).toFloat64();
85  m_map.insert( std::make_pair( wavelength, band ) );
86  ++band;
87  ++i;
88  }
89  }
90  }
91  }
92  }
93  }
94 
95  return ( m_map.size() ? true : false);
96 
97 } // End: bool ossimWavelength::initialize(const ossimEnviHeader&)
float ossim_float32
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
std::string::size_type size() const
Definition: ossimString.h:405
unsigned int ossim_uint32
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
bool getValue(const ossimString &key, ossimString &value) const
Gets value for key.
WavelengthMap m_map

◆ operator=()

const ossimWavelength & ossimWavelength::operator= ( const ossimWavelength rhs)

assignment operator=

Definition at line 26 of file ossimWavelength.cpp.

References m_map.

27 {
28  if ( this != &rhs )
29  {
30  m_map = rhs.m_map;
31  }
32  return *this;
33 }
WavelengthMap m_map

Member Data Documentation

◆ m_map

WavelengthMap ossimWavelength::m_map
private

Definition at line 103 of file ossimWavelength.h.

Referenced by getMap(), initialize(), and operator=().


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