iRoCS Toolbox  1.1.0
ColorMap.hh
Go to the documentation of this file.
1 /**************************************************************************
2  *
3  * This file belongs to the iRoCS Toolbox.
4  *
5  * Copyright (C) 2015 Thorsten Falk
6  *
7  * Image Analysis Lab, University of Freiburg, Germany
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  *
23  **************************************************************************/
24 
25 #ifndef COLORMAP_HH
26 #define COLORMAP_HH
27 
28 #ifdef HAVE_CONFIG_H
29 #include <config.hh>
30 #endif
31 
32 #include <blitz/array.h>
33 #include <map>
34 #include <vector>
35 
37 
38 class IColorMapEditor;
39 
40 class ColorMap
41 {
42 
43 public:
44 
46 
47  ColorMap(long long start = 0, long long end = 65535);
48  ColorMap(ColorMap const &colorMap);
49  ~ColorMap();
50 
51  ColorMap &operator=(ColorMap const &colorMap);
52 
53  // Index ranges for default types
54  bool isUnsigned8BitRange() const;
55  void setUnsigned8BitRange();
56  bool isSigned8BitRange() const;
57  void setSigned8BitRange();
58  bool isUnsigned12BitRange() const;
59  void setUnsigned12BitRange();
60  bool isUnsigned16BitRange() const;
61  void setUnsigned16BitRange();
62  bool isSigned16BitRange() const;
63  void setSigned16BitRange();
64  bool isUnsigned32BitRange() const;
65  void setUnsigned32BitRange();
66  bool isSigned32BitRange() const;
67  void setSigned32BitRange();
68  bool isSigned64BitRange() const;
69  void setSigned64BitRange();
70 
71  // Custom index ranges
72  void setStartIndex(long long index);
73  void setEndIndex(long long index);
74  long long startIndex() const;
75  long long endIndex() const;
76 
77  // Custom colors at the ends of the color transition
78  void setStartColor(blitz::TinyVector<float,3> const &color);
79  void setEndColor(blitz::TinyVector<float,3> const &color);
80  blitz::TinyVector<float,3> startColor() const;
81  blitz::TinyVector<float,3> endColor() const;
82 
83  // Intermediate colors for smooth interpolation
85  double percentage, blitz::TinyVector<float,3> const &color);
86  void removeIntermediateColor(double percentage);
88  std::map< double,blitz::TinyVector<float,3> > const
89  &intermediateColors() const;
90 
91  // Intermediate colors replacing the interpolated ones
92  void addOverrideColor(
93  long long index, blitz::TinyVector<float,3> const &color);
94  void removeOverrideColor(long long index);
95  void clearOverrideColors();
96  std::map< long long,blitz::TinyVector<float,3> > const
97  &overrideColors() const;
98 
99  // Default colormaps (Overrides will be preserved)
100  bool isGray() const;
101  void setGray();
102  bool isHot() const;
103  void setHot();
104  bool isJet() const;
105  void setJet();
106  bool isHSV() const;
107  void setHSV();
108  bool isRandom() const;
109  void setRandom();
110 
111  // Monochrome color
112  void setMonochromeColor(blitz::TinyVector<float,3> const &color);
113  blitz::TinyVector<float,3> monochromeColor() const;
114 
115  // Toggle range indicator
116  void setRangeIndicatorEnabled(bool enable);
117  bool rangeIndicatorEnabled() const;
118 
119  // gamma correction
120  void setGamma(double gamma);
121  double gamma() const;
122 
123  // Type is either Monochrome or RGB
124  ColorMapType type() const;
125 
126  // Get the color at index
127  blitz::TinyVector<float,3> color(long long index) const;
128 
129  // Load and save from/to HDF5
130  void load(BlitzH5File const &infile, std::string const &group);
131  void load(std::string const &fileName, std::string const &group);
132  void save(BlitzH5File &outfile, std::string const &group) const;
133  void save(std::string const &fileName, std::string const &group) const;
134 
135  // Attach and get the attached color map editor
138 
139  static blitz::TinyVector<float,3> generateRandomColor();
140 
141 private:
142 
143  void _updateGammaLUT();
144  void _updateColorMapType();
145 
146  long long _start, _end;
147  double _gamma;
148  blitz::TinyVector<float,3> _startColor, _endColor;
149  blitz::TinyVector<float,3> _monochromeColor;
150  bool _isRandom;
151  std::map< double,blitz::TinyVector<float,3> > _intermediateColors;
152  std::map< long long,blitz::TinyVector<float,3> > _overrideColors;
153  std::vector< blitz::TinyVector<float,3> > _fixedRandomColors;
154  mutable std::map< long long,blitz::TinyVector<float,3> >
155  _additionalRandomColors;
156  ColorMapType _colorMapType;
157  bool _rangeIndicator;
158 
159  std::vector<double> _gammaLUT;
160 
161  IColorMapEditor *p_colorMapEditor;
162 
163 };
164 
165 #endif
166 
167 
bool isSigned64BitRange() const
void setUnsigned32BitRange()
IColorMapEditor * colorMapEditor() const
void setGamma(double gamma)
void removeIntermediateColor(double percentage)
bool isSigned32BitRange() const
void setEndIndex(long long index)
bool isRandom() const
ColorMapType type() const
void setRangeIndicatorEnabled(bool enable)
bool rangeIndicatorEnabled() const
void setJet()
void removeOverrideColor(long long index)
void addIntermediateColor(double percentage, blitz::TinyVector< float, 3 > const &color)
ColorMap(long long start=0, long long end=65535)
bool isHSV() const
ColorMap & operator=(ColorMap const &colorMap)
bool isUnsigned32BitRange() const
void save(BlitzH5File &outfile, std::string const &group) const
Lightweight alternative to libBlitzHDF5 providing its basic functionality.
void setUnsigned8BitRange()
void setStartIndex(long long index)
void setSigned32BitRange()
void setUnsigned12BitRange()
bool isUnsigned16BitRange() const
void setColorMapEditor(IColorMapEditor *colorMapEditor)
void setSigned16BitRange()
std::map< double, blitz::TinyVector< float, 3 > > const & intermediateColors() const
void setStartColor(blitz::TinyVector< float, 3 > const &color)
blitz::TinyVector< float, 3 > endColor() const
bool isSigned8BitRange() const
blitz::TinyVector< float, 3 > startColor() const
bool isJet() const
void clearIntermediateColors()
blitz::TinyVector< float, 3 > color(long long index) const
void setRandom()
blitz::TinyVector< float, 3 > monochromeColor() const
static blitz::TinyVector< float, 3 > generateRandomColor()
bool isSigned16BitRange() const
void load(BlitzH5File const &infile, std::string const &group)
ColorMapType
Definition: ColorMap.hh:45
bool isUnsigned8BitRange() const
void setGray()
long long endIndex() const
std::map< long long, blitz::TinyVector< float, 3 > > const & overrideColors() const
bool isHot() const
void setMonochromeColor(blitz::TinyVector< float, 3 > const &color)
bool isGray() const
void addOverrideColor(long long index, blitz::TinyVector< float, 3 > const &color)
double gamma() const
void setUnsigned16BitRange()
long long startIndex() const
void clearOverrideColors()
void setSigned64BitRange()
void setHSV()
void setHot()
void setEndColor(blitz::TinyVector< float, 3 > const &color)
void setSigned8BitRange()
bool isUnsigned12BitRange() const