libLAS API Reference  1.8.1
color.hpp
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id$
3  *
4  * Project: libLAS - http://liblas.org - A BSD library for LAS format data.
5  * Purpose: LAS color class
6  * Author: Howard Butler, hobu.inc@gmail.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2008, Howard Butler
10  *
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following
15  * conditions are met:
16  *
17  * * Redistributions of source code must rede following disclaimer.
18  * * Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in
20  * the documentation and/or other materials provided
21  * with the distribution.
22  * * Neither the name of the Martin Isenburg or Iowa Department
23  * of Natural Resources nor the names of its contributors may be
24  * used to endorse or promote products derived from this software
25  * without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
35  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
37  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
38  * OF SUCH DAMAGE.
39  ****************************************************************************/
40 
41 #ifndef LIBLAS_LASCOLOR_HPP_INCLUDED
42 #define LIBLAS_LASCOLOR_HPP_INCLUDED
43 
44 #include <liblas/export.hpp>
45 #include <stdint.h>
46 
47 // boost
48 #include <boost/array.hpp>
49 // std
50 #include <cstdlib> // std::size_t
51 
52 namespace liblas {
53 
56 {
57 public:
58 
59  typedef uint16_t value_type;
60 
63  Color();
64 
69  Color(uint32_t red, uint32_t green, uint32_t blue);
70 
75  Color(boost::array<value_type, 3> const& color);
76 
78  Color(Color const& other);
79 
81  Color& operator=(Color const& rhs);
82 
84  value_type GetRed() const;
85 
87  void SetRed(value_type const& value);
88 
90  value_type GetBlue() const;
91 
93  void SetBlue(value_type const& value);
94 
96  value_type GetGreen() const;
97 
99  void SetGreen(value_type const& value);
100 
104  value_type& operator[](std::size_t const& index);
105 
109  value_type const& operator[](std::size_t const& index) const;
110 
111 private:
112 
113  typedef boost::array<value_type, 3> base_type;
114  base_type m_color;
115 
116  void throw_index_out_of_range() const;
117  void throw_invalid_color_component() const;
118 };
119 
121 {
122  return m_color[0];
123 }
124 
125 inline void Color::SetRed(Color::value_type const& value)
126 {
127  m_color[0] = value;
128 }
129 
131 {
132  return m_color[1];
133 }
134 
135 inline void Color::SetGreen(Color::value_type const& value)
136 {
137  m_color[1] = value;
138 }
139 
141 {
142  return m_color[2];
143 }
144 
145 inline void Color::SetBlue(Color::value_type const& value)
146 {
147  m_color[2] = value;
148 }
149 
150 inline Color::value_type& Color::operator[](std::size_t const& index)
151 {
152  return m_color[index];
153 }
154 
155 inline Color::value_type const& Color::operator[](std::size_t const& index) const
156 {
157  return m_color[index];
158 }
159 
160 inline bool operator==(Color const& lhs, Color const& rhs)
161 {
162  return lhs[0] == rhs[0] && lhs[1] == rhs[1] && lhs[2] == rhs[2];
163 }
164 
165 inline bool operator!=(Color const& lhs, Color const& rhs)
166 {
167  return !(lhs == rhs);
168 }
169 
170 } // namespace liblas
171 
172 #endif // LIBLAS_LASCOLOR_HPP_INCLUDED
bool operator!=(Classification const &lhs, Classification const &rhs)
Not-equal-to operator implemented in terms of Classification::equal.
Definition: classification.hpp:232
#define LAS_DLL
Definition: export.hpp:58
value_type GetGreen() const
Fetch value of the green image channel.
Definition: color.hpp:130
value_type & operator[](std::size_t const &index)
Index operator providing access to RGB values.
Definition: color.hpp:150
void SetRed(value_type const &value)
Set value of the red image channel.
Definition: color.hpp:125
value_type GetBlue() const
Fetch value of the blue image channel.
Definition: color.hpp:140
bool operator==(Classification const &lhs, Classification const &rhs)
Equal-to operator implemented in terms of Classification::equal.
Definition: classification.hpp:226
Namespace grouping all elements of libLAS public interface.
Definition: bounds.hpp:60
void SetGreen(value_type const &value)
Set value of the red image channel.
Definition: color.hpp:135
value_type GetRed() const
Fetch value of the red image channel.
Definition: color.hpp:120
void SetBlue(value_type const &value)
Set value of the blue image channel.
Definition: color.hpp:145
Definition: schema.hpp:80
RGB color container.
Definition: color.hpp:55
uint16_t value_type
Definition: color.hpp:59