Open3D (C++ API)  0.11.0
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 
29 #include <Eigen/Core>
30 #include <memory>
31 
32 namespace open3d {
33 namespace visualization {
34 
35 class ColorMap {
36 public:
37  enum class ColorMapOption {
38  Gray = 0,
39  Jet = 1,
40  Summer = 2,
41  Winter = 3,
42  Hot = 4,
43  };
44 
45 public:
46  ColorMap() {}
47  virtual ~ColorMap() {}
48 
49 public:
51  virtual Eigen::Vector3d GetColor(double value) const = 0;
52 
53 protected:
54  double Interpolate(
55  double value, double y0, double x0, double y1, double x1) const {
56  if (value < x0) return y0;
57  if (value > x1) return y1;
58  return (value - x0) * (y1 - y0) / (x1 - x0) + y0;
59  }
60  Eigen::Vector3d Interpolate(double value,
61  const Eigen::Vector3d &y0,
62  double x0,
63  const Eigen::Vector3d &y1,
64  double x1) const {
65  if (value < x0) return y0;
66  if (value > x1) return y1;
67  return (value - x0) * (y1 - y0) / (x1 - x0) + y0;
68  }
69 };
70 
71 class ColorMapGray final : public ColorMap {
72 public:
73  Eigen::Vector3d GetColor(double value) const final;
74 };
75 
77 class ColorMapJet final : public ColorMap {
78 public:
79  Eigen::Vector3d GetColor(double value) const final;
80 
81 protected:
82  double JetBase(double value) const {
83  if (value <= -0.75) {
84  return 0.0;
85  } else if (value <= -0.25) {
86  return Interpolate(value, 0.0, -0.75, 1.0, -0.25);
87  } else if (value <= 0.25) {
88  return 1.0;
89  } else if (value <= 0.75) {
90  return Interpolate(value, 1.0, 0.25, 0.0, 0.75);
91  } else {
92  return 0.0;
93  }
94  }
95 };
96 
98 class ColorMapSummer final : public ColorMap {
99 public:
100  Eigen::Vector3d GetColor(double value) const final;
101 };
102 
104 class ColorMapWinter final : public ColorMap {
105 public:
106  Eigen::Vector3d GetColor(double value) const final;
107 };
108 
109 class ColorMapHot final : public ColorMap {
110 public:
111  Eigen::Vector3d GetColor(double value) const final;
112 };
113 
115 const std::shared_ptr<const ColorMap> GetGlobalColorMap();
117 
118 } // namespace visualization
119 } // namespace open3d
void SetGlobalColorMap(ColorMap::ColorMapOption option)
Definition: ColorMap.cpp:107
ColorMapOption
Definition: ColorMap.h:37
Definition: ColorMap.h:109
double Interpolate(double value, double y0, double x0, double y1, double x1) const
Definition: ColorMap.h:54
virtual ~ColorMap()
Definition: ColorMap.h:47
See Matlab&#39;s Winter colormap.
Definition: ColorMap.h:104
See Matlab&#39;s Summer colormap.
Definition: ColorMap.h:98
See Matlab&#39;s Jet colormap.
Definition: ColorMap.h:77
Definition: PinholeCameraIntrinsic.cpp:35
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:46
Definition: ColorMap.h:71
Eigen::Vector3d Interpolate(double value, const Eigen::Vector3d &y0, double x0, const Eigen::Vector3d &y1, double x1) const
Definition: ColorMap.h:60
double JetBase(double value) const
Definition: ColorMap.h:82
Definition: ColorMap.h:35