libcootapi
 
Loading...
Searching...
No Matches
/opt/conda/conda-bld/coot-headless_1766554182969/work/api/coot-colour.hh
1/*
2 * api/coot-colour.hh
3 *
4 * Copyright 2020 by Medical Research Council
5 * Author: Paul Emsley
6 *
7 * This file is part of Coot
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation; either version 3 of the License, or (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA
23 */
24
25
26#ifndef COOT_COLOUR_HH
27#define COOT_COLOUR_HH
28
29#include <vector>
30#include <glm/glm.hpp>
31
32#include "utils/colour-holder.hh" // funny old thing. Consolidate the colour class one day.
33
34namespace coot {
35 class colour_t {
36 void init(float r, float g, float b) {
37 col.resize(3);
38 col[0] = r;
39 col[1] = g;
40 col[2] = b;
41 }
42 std::vector<float> convert_to_hsv() const;
43 void convert_from_hsv(const std::vector<float> &hsv);
44 public:
45 std::vector<float> col;
46 colour_t() { init(0.5, 0.5, 0.5); }
47 colour_t(float r, float g, float b) { init(r,g,b); }
48 void set(float r, float g, float b) { init(r,g,b); }
49 float &operator[](const unsigned int &idx) { return col[idx]; }
50 const float &operator[](const unsigned int &idx) const { return col[idx]; }
51 void rotate(float f);
52 void average(const colour_t &other) {
53 for (unsigned int idx=0; idx<3; idx++)
54 col[idx] = 0.5 * (col[idx] + other[idx]);
55 }
56 void brighter(float f) {
57 for (unsigned int idx=0; idx<3; idx++)
58 col[idx] *= f;
59 for (unsigned int idx=0; idx<3; idx++)
60 if (col[idx] > 1.0)
61 col[idx] = 1.0;
62 }
63 glm::vec4 to_glm() const {
64 return glm::vec4(col[0], col[1], col[2], 1.0f);
65 }
66 colour_holder to_colour_holder() const {
67 return colour_holder(col[0], col[1], col[2]);
68 }
69 };
70 std::ostream& operator<<(std::ostream &s, colour_t col);
71}
72#endif
Definition coot-colour.hh:35