snark
Coloured.h
1 // This file is part of snark, a generic and flexible library
2 // for robotics research.
3 //
4 // Copyright (C) 2011 The University of Sydney
5 //
6 // snark is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 3 of the License, or (at your option) any later version.
10 //
11 // snark is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
14 // for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with snark. If not, see <http://www.gnu.org/licenses/>.
18 
20 
21 #ifndef SNARK_GRAPHICS_APPLICATIONS_VIEWPOINTS_COLOURED_H_
22 #define SNARK_GRAPHICS_APPLICATIONS_VIEWPOINTS_COLOURED_H_
23 
24 #include <string>
25 #include <Qt3D/qcolor4ub.h>
26 #include "./PointWithId.h"
27 
28 namespace snark { namespace graphics { namespace View {
29 
30 struct coloured
31 {
32  virtual ~coloured() {}
33  virtual QColor4ub color( const Eigen::Vector3d& point
34  , comma::uint32 id
35  , double scalar
36  , const QColor4ub& c ) const = 0;
37 
38 };
39 
40 class Fixed : public coloured
41 {
42  public:
43  Fixed( const std::string& name );
44  QColor4ub color( const Eigen::Vector3d& point
45  , comma::uint32 id
46  , double scalar
47  , const QColor4ub& c ) const;
48 
49  private:
50  QColor4ub m_color;
51 };
52 
53 struct ByHeight : public coloured // todo: refactor and merge with byscalar
54 {
55  ByHeight( double from
56  , double to
57  , const QColor4ub& from_color = QColor4ub( 255, 0, 0 )
58  , const QColor4ub& to_color = QColor4ub( 0, 0, 255 )
59  , bool cyclic = false
60  , bool linear = true
61  , bool sharp = false );
62 
63  double from, to, sum, diff, middle;
64  QColor4ub from_color, to_color, average_color;
65  bool cyclic, linear, sharp;
66 
67  QColor4ub color( const Eigen::Vector3d& point
68  , comma::uint32 id
69  , double scalar
70  , const QColor4ub& c ) const;
71 };
72 
73 struct ByScalar : public coloured
74 {
75  ByScalar( double from = 0
76  , double to = 1
77  , const QColor4ub& from_color = QColor4ub( 255, 0, 0 )
78  , const QColor4ub& to_color = QColor4ub( 0, 0, 255 ) );
79  double from, to, diff;
80  QColor4ub from_color;
81  QColor4ub to_color;
82  QColor4ub color( const Eigen::Vector3d& point
83  , comma::uint32 id
84  , double scalar
85  , const QColor4ub& c ) const;
86 };
87 
88 class ById : public coloured
89 {
90  public:
91  ById( const QColor4ub& backgroundcolour );
92 
93  ById( const QColor4ub& backgroundcolour
94  , double from
95  , double to );
96  QColor4ub color( const Eigen::Vector3d& point
97  , comma::uint32 id
98  , double scalar
99  , const QColor4ub& c ) const;
100  private:
101  const QColor4ub m_background;
102  bool m_hasScalar;
103  double m_from;
104  double m_diff;
105 };
106 
107 struct ByRGB : public coloured
108 {
109  QColor4ub color( const Eigen::Vector3d& point
110  , comma::uint32 id
111  , double scalar
112  , const QColor4ub& c ) const;
113 };
114 
115 coloured* colourFromString( const std::string& s, const std::string& fields, const QColor4ub& backgroundcolour );
116 
117 } } } // namespace snark { namespace graphics { namespace View {
118 
119 #endif /*SNARK_GRAPHICS_APPLICATIONS_VIEWPOINTS_COLOURED_H_*/