Open3D (C++ API)
ColorMap.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 #include <memory>
29 #include <Eigen/Core>
30 
31 namespace open3d {
32 namespace visualization {
33 
34 class ColorMap {
35 public:
36  enum class ColorMapOption {
37  Gray = 0,
38  Jet = 1,
39  Summer = 2,
40  Winter = 3,
41  Hot = 4,
42  };
43 
44 public:
45  ColorMap(){};
46  virtual ~ColorMap(){};
47 
48 public:
50  virtual Eigen::Vector3d GetColor(double value) const = 0;
51 
52 protected:
53  double Interpolate(
54  double value, double y0, double x0, double y1, double x1) const {
55  if (value < x0) return y0;
56  if (value > x1) return y1;
57  return (value - x0) * (y1 - y0) / (x1 - x0) + y0;
58  }
59  Eigen::Vector3d Interpolate(double value,
60  const Eigen::Vector3d &y0,
61  double x0,
62  const Eigen::Vector3d &y1,
63  double x1) const {
64  if (value < x0) return y0;
65  if (value > x1) return y1;
66  return (value - x0) * (y1 - y0) / (x1 - x0) + y0;
67  }
68 };
69 
70 class ColorMapGray final : public ColorMap {
71 public:
72  Eigen::Vector3d GetColor(double value) const final;
73 };
74 
76 class ColorMapJet final : public ColorMap {
77 public:
78  Eigen::Vector3d GetColor(double value) const final;
79 
80 protected:
81  double JetBase(double value) const {
82  if (value <= -0.75) {
83  return 0.0;
84  } else if (value <= -0.25) {
85  return Interpolate(value, 0.0, -0.75, 1.0, -0.25);
86  } else if (value <= 0.25) {
87  return 1.0;
88  } else if (value <= 0.75) {
89  return Interpolate(value, 1.0, 0.25, 0.0, 0.75);
90  } else {
91  return 0.0;
92  }
93  }
94 };
95 
97 class ColorMapSummer final : public ColorMap {
98 public:
99  Eigen::Vector3d GetColor(double value) const final;
100 };
101 
103 class ColorMapWinter final : public ColorMap {
104 public:
105  Eigen::Vector3d GetColor(double value) const final;
106 };
107 
108 class ColorMapHot final : public ColorMap {
109 public:
110  Eigen::Vector3d GetColor(double value) const final;
111 };
112 
114 const std::shared_ptr<const ColorMap> GetGlobalColorMap();
116 
117 } // namespace visualization
118 } // namespace open3d
void SetGlobalColorMap(ColorMap::ColorMapOption option)
Definition: ColorMap.cpp:107
ColorMapOption
Definition: ColorMap.h:36
Definition: ColorMap.h:108
double Interpolate(double value, double y0, double x0, double y1, double x1) const
Definition: ColorMap.h:53
virtual ~ColorMap()
Definition: ColorMap.h:46
See Matlab&#39;s Winter colormap.
Definition: ColorMap.h:103
See Matlab&#39;s Summer colormap.
Definition: ColorMap.h:97
See Matlab&#39;s Jet colormap.
Definition: ColorMap.h:76
Definition: PinholeCameraIntrinsic.cpp:33
virtual Eigen::Vector3d GetColor(double value) const =0
Function to get a color from a value in [0..1].
const std::shared_ptr< const ColorMap > GetGlobalColorMap()
Interface functions.
Definition: ColorMap.cpp:103
ColorMap()
Definition: ColorMap.h:45
Definition: ColorMap.h:70
Eigen::Vector3d Interpolate(double value, const Eigen::Vector3d &y0, double x0, const Eigen::Vector3d &y1, double x1) const
Definition: ColorMap.h:59
double JetBase(double value) const
Definition: ColorMap.h:81
Definition: ColorMap.h:34