Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
colormap.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2022 Inria
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of the ALICE Project-Team nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Contact: Bruno Levy
30  *
31  * https://www.inria.fr/fr/bruno-levy
32  *
33  * Inria,
34  * Domaine de Voluceau,
35  * 78150 Le Chesnay - Rocquencourt
36  * FRANCE
37  *
38  */
39 
40 #ifndef H_GEO_IMAGE_TYPES_COLORMAP_H
41 #define H_GEO_IMAGE_TYPES_COLORMAP_H
42 
43 #include <geogram/basic/common.h>
44 #include <geogram/basic/counted.h>
46 #include <geogram/image/color.h>
47 
52 namespace GEO {
53 
54 /******************************************************************/
55 
61  class GEOGRAM_API Colormap : public Counted {
62  public:
63 
68 
73  Colormap(index_t size_in = 256) ;
74 
78  ~Colormap() override;
79 
86  const ColorCell& color_cell(index_t index) const {
87  geo_assert(index < size_) ;
88  return cells_[index] ;
89  }
90 
98  geo_assert(index < size_) ;
99  return cells_[index] ;
100  }
101 
106  index_t size() const {
107  return size_;
108  }
109 
117  void set_color(index_t index, float r, float g, float b) ;
118 
125  void set_color(index_t index, float r, float g, float b, float a) ;
126 
139  index_t component,
140  index_t index1, Numeric::uint8 val1,
141  index_t index2, Numeric::uint8 val2
142  ) ;
143 
144 
155  index_t index1, const Color& c1,
156  index_t index2, const Color& c2
157  ) ;
158 
170  index_t index1, const Color& c1,
171  index_t index2, const Color& c2
172  ) ;
173 
174  private:
175  ColorCell* cells_ ;
176  index_t size_ ;
177  } ;
178 
183 
184 /************************************************************************/
185 
186 }
187 #endif
#define geo_assert(x)
Verifies that a condition is met.
Definition: assert.h:149
A Colormap.
Definition: colormap.h:61
void color_ramp_rgb(index_t index1, const Color &c1, index_t index2, const Color &c2)
Make a color linearly interpolate two values between two given indices.
const ColorCell & color_cell(index_t index) const
Gets a ColorCell by index.
Definition: colormap.h:86
index_t size() const
Gets the size.
Definition: colormap.h:106
~Colormap() override
Colormap destructor.
ColorCell & color_cell(index_t index)
Gets a ColorCell by index.
Definition: colormap.h:97
void set_color(index_t index, float r, float g, float b, float a)
Sets a color by index and components.
void set_color(index_t index, float r, float g, float b)
Sets a color by index and components.
void color_ramp_component(index_t component, index_t index1, Numeric::uint8 val1, index_t index2, Numeric::uint8 val2)
Make a color component linearly interpolate two values between two given indices.
Colormap(index_t size_in=256)
Colormap constructor.
GenColor< Numeric::uint8 > ColorCell
Type of each cell of the Colormap.
Definition: colormap.h:67
void color_ramp_rgba(index_t index1, const Color &c1, index_t index2, const Color &c2)
Make a color linearly interpolate two values between two given indices.
Base class for reference-counted objects.
Definition: counted.h:71
A generic color type.
Definition: color.h:57
Color types.
Base class of reference-counted objects, to be used with smart pointers.
Common include file, providing basic definitions. Should be included before anything else by all head...
uint8_t uint8
Definition: numeric.h:135
Global Vorpaline namespace.
Definition: basic.h:55
SmartPointer< Colormap > Colormap_var
An automatic reference-counted pointer to a Colormap.
Definition: colormap.h:182
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Pointers with automatic reference counting.