aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp/colors/Color3_Space.h
blob: 80a6b323c3dfdae2dc6af539cc5afde61962a96f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifndef   colors_Color3_Space_H__
#define   colors_Color3_Space_H__

#include "../geo/Vectors.h"
#include "../math/Matrix.h"
#include "../math/utility.h"

#include <cstdlib>

namespace meow {

/*!
 * @brief Base class of color space with 3 channels.
 *
 * @author cat_leopard
 */
template<class T>
class Color3_Space {
protected:
  Vector3D<T> min_;
  Vector3D<T> max_;
  Vector3D<T> val_;

  /*!
   * @brief Constructor
   *
   * @param [in] min_bound  Minimum value of each channels.
   * @param [in] max_bound  Maximum value of each channels.
   * @param [in] init_value Initial value of each channels.
   */
  Color3_Space(Vector3D<T> const& min_bound,
               Vector3D<T> const& max_bound,
               Vector3D<T> const& init_value):
  min_(min_bound), max_(max_bound), val_(init_value) {
  }

  /*!
   * @brief Copy constructor
   *
   * @param [in] b Data to copy from.
   */
  Color3_Space(Color3_Space const& b):
  min_(b.min_), max_(b.max_), val_(b.val_) {
  }

  /*!
   * @brief Copy method
   *
   * We copy the value only, not include \c min_bound and \c max_bound.
   *
   * @param [in] b Value to copy from.
   * @return \c *this
   */
  Color3_Space<T>& copyFrom(Color3_Space<T> const& b) {
    val_ = b.val_;
    return *this;
  }
public:
  //! @brief Destructor
  virtual ~Color3_Space() { }

  //! @brief minimum bound of each channels.
  Vector3D<T> const& minV() const {
    return min_;
  }

  //! @brief maximum bound of each channels.
  Vector3D<T> const& maxV() const {
    return max_;
  }

  //! @brief value of each channels.
  Vector3D<T> const& valV() const {
    return val_;
  }

  /*!
   * @brief Set the value of each channels.
   *
   * @param [in] vv new value
   * @return new value
   */
  Vector3D<T> const& valV(Vector3D<T> const& vv) {
    val_ = vv;
    return val();
  }

  //! @brief Get the non-constant reference of each channels.
  Vector3D<T>& valVGet() {
    return val_;
  }

  /*!
   * @brief Return the minimum of the \c i -th channel.
   *
   * @param [in] id index of the channel.
   * @return new value
   */
  T const& min(size_t id) const { return minV()(id); }

  /*!
   * @brief Return the maximum of the \c i -th channel.
   *
   * @param [in] id index of the channel.
   * @return new value
   */
  T const& max(size_t id) const {
    return maxV()(id);
  }

  /*!
   * @brief Return the value of the \c i -th channel.
   *
   * @param [in] id index of the channel.
   * @return new value
   */
  T const& val(size_t id) const {
    return valV()(id);
  }

  /*!
   * @brief Set the value of \c i -th channel.
   *
   * @param [in] i index of the channel
   * @param [in] c new value
   */
  T const& val(size_t i, T const& c) {
    if      (i == 0) val_.x(c);
    else if (i == 1) val_.y(c);
    else if (i == 2) val_.z(c);
    return val(i);
  }

  /*!
   * @brief Get the non-constant reference of value of the \c i -th channel.
   *
   * @param [in] id index of the channel
   */
  T& valGet(size_t id) {
    if      (id == 0) return valVGet().xGet();
    else if (id == 1) return valVGet().yGet();
    else              return valVGet().zGet();
  }
};

} // meow

#endif // colors_Color3_Space_H__