OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimIndexToRgbLutFilter.h
Go to the documentation of this file.
1 //*******************************************************************
2 // Copyright (C) 2000 ImageLinks Inc.
3 //
4 // License: MIT
5 //
6 // See LICENSE.txt file in the top level directory for more details.
7 //
8 // Author: Oscar Kramer
9 //
10 //*************************************************************************
11 // $Id: ossimIndexToRgbLutFilter.h 23616 2015-11-11 19:50:29Z dburken $
12 #ifndef ossimIndexToRgbLutFilter_HEADER
13 #define ossimIndexToRgbLutFilter_HEADER
14 
18 #include <vector>
19 
20 class ossimImageData;
21 
22 /***************************************************************************************************
23  *
24  * This class provides a look-up-table remap from a single band input (the index), to a 3-band RGB
25  * output. The LUT is provided as a KWL with several remapping modes supported:
26  *
27  * Literal: Only those indices represented in the KWL are remapped to the values indicated. All
28  * other pixel values are mapped to the NULL pixel (0,0,0). Note that this is only meaningful for
29  * integer input scalar types since a normalized input will likely not find an exact match.
30  *
31  * Arbitrary piecewise linear ("vertices"): The LUT KWL provides vertices to contiguous line
32  * segments. Pixel values falling between specified indices are linearly interpolated between
33  * adjacent vertices. Any index pixel values falling outside the range between min and max vertex
34  * indices will be mapped to the NULL pixel.
35  *
36  * Regular piecewise linear ("regular"): The entries in the KWL do not correspond to any specific
37  * index (except the first and the last entries that correspond to the min and max pixel values).
38  * Remaining intermediate entries are equally spaced in index space so that the line segments are of
39  * equal length. The min and max values are queried from the input source, but can be overriden with
40  * the "min_value" and "max_value" keywords in the LUT KWL.
41  *
42  * Here are example KWLs for the three modes, first for the literal remap:
43  *
44  * type: ossimIndexToRgbLutFilter
45  * mode: literal
46  * entry0.index: 0
47  * entry0.color: 1 1 1
48  * entry1.index: 128
49  * entry1.color: 255 0 0
50  * entry2.index: 255
51  * entry2.color: 0 255 0
52  *
53  * The above KWL will map only pixels with input values of 0, 128, and 255. All other indices will
54  * map to the null value.
55  *
56  * Example for arbitrary piecewise linear:
57  *
58  * type: ossimIndexToRgbLutFilter
59  * mode: vertices
60  * entry0.index: 1
61  * entry0.color: 0 0 255
62  * entry1.index: 128
63  * entry1.color: 0 255 0
64  * entry2.index: 250
65  * entry2.color: 255 0 0
66  *
67  * The above KWL is a sort of heat map where indices between 1 and 128 will linearly map from blue
68  * to green, and then 128 to 250 will map from green (through yellow) to red. Note that any value
69  * above 250 as well as 0 are outside of the remap range and will map to the null pixel (0,0,0).
70  *
71  * Example of regular piecewise linear. This is the default mode. For backward compatibility, the
72  * mode keyword here is optional and if omitted will imply this mode. Also, unlike previous form,
73  * the number_of_entries keyword is not required and is ignored if present.
74  *
75  * type: ossimIndexToRgbLutFilter
76  * mode: regular
77  * entry0: 0 0 255
78  * entry1: 0 255 0
79  * entry2: 255 0 0
80  * max_value: 250
81  * min_value: 1
82  *
83  * The above KWL is almost equivalent to the "vertices" example above, i.e., a heat map. However,
84  * the individual vertices are not specified. Instead, three entries will define two line segments.
85  * The first line segment will commence with index 1 (min_value) and finish at:
86  *
87  * [(max_value-min_value)/(number_of_entries-1)] + min_value
88  *
89  * In this case it will be 125.5. The quantity in square-brackets (124.5) is the interval, or
90  * length of each line segment, so the second line segment will go from 125.5 to 250. Input pixel
91  * values below the min_value will clamp to the min value (except the null pixel) and those above
92  * the max value will clamp to the max value.
93  *
94  * The table can be contained in a separate file from the main KWL state file. In this case, the
95  * loadState can accept a file name in place of a complete table:
96  *
97  * type: ossimIndexToRgbLutFilter
98  * lut_file: <path to LUT KWL file>
99  *
100  * The format of the LUT KWL file is just as specified above for the inline case.
101  *
102  **************************************************************************************************/
104 {
105 public:
106  enum Mode { LITERAL = 0, VERTICES = 1, REGULAR = 2 };
107 
109 
110  virtual ~ossimIndexToRgbLutFilter();
111 
112  virtual ossimRefPtr<ossimImageData> getTile(const ossimIrect& origin,
113  ossim_uint32 resLevel=0);
114 
116 
117  virtual ossimScalarType getOutputScalarType() const;
118 
119  void setMode(Mode mode) { theMode = mode; }
120  Mode getMode() const { return theMode; }
121 
133  void setLut(const ossimFilename& file);
134 
135  double getMinValue()const;
136  double getMaxValue()const;
137 
138  void setMinValue(double value);
139  void setMaxValue(double value);
140 
141  virtual double getNullPixelValue(ossim_uint32 band=0)const;
142  virtual double getMinPixelValue(ossim_uint32 band=0)const;
143  virtual double getMaxPixelValue(ossim_uint32 band=0)const;
144 
145  virtual void initialize();
146 
147  virtual bool saveState(ossimKeywordlist& kwl, const char* prefix=NULL)const;
148 
149  virtual bool loadState(const ossimKeywordlist& kwl, const char* prefix=NULL);
150 
151 protected:
155  void allocate();
156  bool initializeLut(const ossimKeywordlist* kwl, const char* prefix=0);
157 
158  std::map<double, ossimRgbVector> theLut;
159 
160  double theMinValue;
161  double theMaxValue;
167 
168 TYPE_DATA
169 };
170 
171 #endif /* #ifndef ossimIndexToRgbLutFilter_HEADER */
Represents serializable keyword/value map.
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
virtual double getMinPixelValue(ossim_uint32 band=0) const
Returns the min pixel of the band.
#define TYPE_DATA
Definition: ossimRtti.h:339
unsigned int ossim_uint32
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
ossimScalarType
virtual ossimScalarType getOutputScalarType() const
This will be used to query the output pixel type of the tile source.
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
Method to save the state of an object to a keyword list.
virtual double getMaxPixelValue(ossim_uint32 band=0) const
Returns the max pixel of the band.
#define OSSIM_DLL
std::map< double, ossimRgbVector > theLut
ossimRefPtr< ossimImageData > theTile
virtual double getNullPixelValue(ossim_uint32 band=0) const
Each band has a null pixel associated with it.
virtual ossimRefPtr< ossimImageData > getTile(const ossimIpt &origin, ossim_uint32 resLevel=0)