Open3D (C++ API)  0.18.0
ColorMap.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <Eigen/Core>
11 #include <memory>
12 
13 namespace open3d {
14 namespace visualization {
15 
16 class ColorMap {
17 public:
18  enum class ColorMapOption {
19  Gray = 0,
20  Jet = 1,
21  Summer = 2,
22  Winter = 3,
23  Hot = 4,
24  };
25 
26 public:
27  ColorMap() {}
28  virtual ~ColorMap() {}
29 
30 public:
32  virtual Eigen::Vector3d GetColor(double value) const = 0;
33 
34 protected:
35  double Interpolate(
36  double value, double y0, double x0, double y1, double x1) const {
37  if (value < x0) return y0;
38  if (value > x1) return y1;
39  return (value - x0) * (y1 - y0) / (x1 - x0) + y0;
40  }
41  Eigen::Vector3d Interpolate(double value,
42  const Eigen::Vector3d &y0,
43  double x0,
44  const Eigen::Vector3d &y1,
45  double x1) const {
46  if (value < x0) return y0;
47  if (value > x1) return y1;
48  return (value - x0) * (y1 - y0) / (x1 - x0) + y0;
49  }
50 };
51 
52 class ColorMapGray final : public ColorMap {
53 public:
54  Eigen::Vector3d GetColor(double value) const final;
55 };
56 
58 class ColorMapJet final : public ColorMap {
59 public:
60  Eigen::Vector3d GetColor(double value) const final;
61 
62 protected:
63  double JetBase(double value) const {
64  if (value <= -0.75) {
65  return 0.0;
66  } else if (value <= -0.25) {
67  return Interpolate(value, 0.0, -0.75, 1.0, -0.25);
68  } else if (value <= 0.25) {
69  return 1.0;
70  } else if (value <= 0.75) {
71  return Interpolate(value, 1.0, 0.25, 0.0, 0.75);
72  } else {
73  return 0.0;
74  }
75  }
76 };
77 
79 class ColorMapSummer final : public ColorMap {
80 public:
81  Eigen::Vector3d GetColor(double value) const final;
82 };
83 
85 class ColorMapWinter final : public ColorMap {
86 public:
87  Eigen::Vector3d GetColor(double value) const final;
88 };
89 
90 class ColorMapHot final : public ColorMap {
91 public:
92  Eigen::Vector3d GetColor(double value) const final;
93 };
94 
96 const std::shared_ptr<const ColorMap> GetGlobalColorMap();
98 
99 } // namespace visualization
100 } // namespace open3d
Definition: ColorMap.h:52
Eigen::Vector3d GetColor(double value) const final
Function to get a color from a value in [0..1].
Definition: ColorMap.cpp:44
Definition: ColorMap.h:90
Eigen::Vector3d GetColor(double value) const final
Function to get a color from a value in [0..1].
Definition: ColorMap.cpp:64
Definition: ColorMap.h:16
ColorMapOption
Definition: ColorMap.h:18
virtual ~ColorMap()
Definition: ColorMap.h:28
virtual Eigen::Vector3d GetColor(double value) const =0
Function to get a color from a value in [0..1].
Eigen::Vector3d Interpolate(double value, const Eigen::Vector3d &y0, double x0, const Eigen::Vector3d &y1, double x1) const
Definition: ColorMap.h:41
double Interpolate(double value, double y0, double x0, double y1, double x1) const
Definition: ColorMap.h:35
ColorMap()
Definition: ColorMap.h:27
See Matlab's Jet colormap.
Definition: ColorMap.h:58
double JetBase(double value) const
Definition: ColorMap.h:63
Eigen::Vector3d GetColor(double value) const final
Function to get a color from a value in [0..1].
Definition: ColorMap.cpp:48
See Matlab's Summer colormap.
Definition: ColorMap.h:79
Eigen::Vector3d GetColor(double value) const final
Function to get a color from a value in [0..1].
Definition: ColorMap.cpp:54
See Matlab's Winter colormap.
Definition: ColorMap.h:85
Eigen::Vector3d GetColor(double value) const final
Function to get a color from a value in [0..1].
Definition: ColorMap.cpp:59
const std::shared_ptr< const ColorMap > GetGlobalColorMap()
Interface functions.
Definition: ColorMap.cpp:84
void SetGlobalColorMap(ColorMap::ColorMapOption option)
Definition: ColorMap.cpp:88
Definition: PinholeCameraIntrinsic.cpp:16