-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcolortable.cpp
More file actions
177 lines (152 loc) · 5.16 KB
/
colortable.cpp
File metadata and controls
177 lines (152 loc) · 5.16 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* ============================================================================
'colortable.cpp' defines a pair of classes used to maintain the color tables
required by the application.
Written by Nicholas Phillips.
QT4 adaption and Black/White color table by Michael R. Greason, ADNET,
27 August 2007.
============================================================================ */
/*
Fetch header files.
*/
#include "colortable.h"
#include "define_colortable.h"
using namespace std;
/* ============================================================================
'ColorTable' maintains a single color table. Each element represents one
usable color; it may be accessed either by indexing it directly or by supplying
a value from 0--1.
The color tables currently supported are staticly defined in
'define_colortable.h'.
TBD:
- Allow the setting of color tables from image files.
- Return a pixmap of the color table.
============================================================================ */
/* ----------------------------------------------------------------------------
'ColorTable' is the default class constructor; it defines the default color
table in the new instance.
Arguments:
None.
Written by Michael R. Greason, ADNET, 27 August 2007.
---------------------------------------------------------------------------- */
ColorTable::ColorTable()
{
name = default_ct_name;
define_table(default_colortable);
return;
}
/* ----------------------------------------------------------------------------
'ColorTable' is a class constructor; it defines the 'indexed' color table from
'define_colortable.h'
Arguments:
id - The color table in the file to define:
0 - default
1 - black-white
Written by Michael R. Greason, ADNET, 27 August 2007.
---------------------------------------------------------------------------- */
ColorTable::ColorTable(int id)
{
switch (id)
{
case 1:
name = blkwht_ct_name;
define_table(blkwht_colortable);
break;
default:
name = default_ct_name;
define_table(default_colortable);
break;
}
return;
}
/* ----------------------------------------------------------------------------
'define_table' performs the work in defining a color table from
'define_colortable.h'. This routine does NOT define the name of the table.
Arguments:
intab - The desired color table as a float array.
Returned:
Nothing.
Written by Michael R. Greason, ADNET, 27 August 2007.
---------------------------------------------------------------------------- */
void ColorTable::define_table (float intab[][3])
{
for(ncols = 0; intab[ncols][0] != -1; ncols++);
table.resize(ncols);
for(uint i = 0; i < ncols; i++)
table[i].setRgbF(intab[i][0], intab[i][1], intab[i][2]);
}
/* ----------------------------------------------------------------------------
'operator[]' returns the indexed element in the table.
Arguments:
v - The 'index'; this is a value between 0 and 1 identifying the
desired color as a fractional position in the table.
Returned:
col - The desired color.
Written by Michael R. Greason, ADNET, 27 August 2007.
---------------------------------------------------------------------------- */
QColor ColorTable::operator[](float v) const
{
v = v < 0 ? 0 : v;
v = v > 1 ? 1 : v;
uint idx = (uint)(v*(ncols-1));
return table[idx];
}
/* ----------------------------------------------------------------------------
'getPixmap' returns a pixmap of the color table.
NOT CURRENTLY DEFINED
Arguments:
None.
Returned:
pm - The pixmap.
Written by Michael R. Greason, ADNET, 27 August 2007.
---------------------------------------------------------------------------- */
QPixmap ColorTable::getPixmap()
{
return QPixmap();
}
/* ============================================================================
'ColorTableList' maintains a vector of color tables.
============================================================================ */
/* ----------------------------------------------------------------------------
'ColorTableList' is the default class constructor, defining all the color
tables defined in 'define_colortable.h'.
Arguments:
None.
Written by Michael R. Greason, ADNET, 27 August 2007.
---------------------------------------------------------------------------- */
ColorTableList::ColorTableList(void)
{
set();
}
/* ----------------------------------------------------------------------------
'~ColorTableList' is class destructor, destroying the color tables before
this instance is destroyed.
Arguments:
None.
Written by Michael R. Greason, ADNET, 27 August 2007.
---------------------------------------------------------------------------- */
ColorTableList::~ColorTableList()
{
for( iterator cti = begin(); cti != end(); ++cti){
delete *cti;
}
return;
}
/* ----------------------------------------------------------------------------
'set' defines all the color tables defined in 'define_colortable.h'.
Arguments:
None.
Returned:
flg - true if successful.
Written by Michael R. Greason, ADNET, 27 August 2007.
---------------------------------------------------------------------------- */
bool ColorTableList::set()
{
ColorTable *ct;
clear();
for (int i = 0; i < colortable_count; i++)
{
ct = new ColorTable(i);
push_back(ct);
}
return true;
}