Debian Codegraph @

lib/database/src/so/fields/SoMFColor.c++

raw symbols SCIP
1 /*
2 *
3 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * Further, this software is distributed without any warranty that it is
16 * free of the rightful claim of any third person regarding infringement
17 * or the like. Any license provided herein, whether implied or
18 * otherwise, applies only to this software file. Patent licenses, if
19 * any, provided herein do not apply to combinations of this program with
20 * other software, or any other product whatsoever.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
27 * Mountain View, CA 94043, or:
28 *
29 * http://www.sgi.com
30 *
31 * For further information regarding this notice, see:
32 *
33 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 *
35 */
36
37 /*
38 * Copyright (C) 1990,91 Silicon Graphics, Inc.
39 *
40 _______________________________________________________________________
41 ______________ S I L I C O N G R A P H I C S I N C . ____________
42 |
43 | $Revision: 1.1.1.1 $
44 |
45 | Classes:
46 | SoMFColor
47 |
48 | Author(s) : Paul S. Strauss
49 |
50 ______________ S I L I C O N G R A P H I C S I N C . ____________
51 _______________________________________________________________________
52 */
53
54 #include <Inventor/fields/SoMFColor.h>
55 #include <cstdlib>
56
57 //////////////////////////////////////////////////////////////////////////////
58 //
59 // SoMFColor class
60 //
61 //////////////////////////////////////////////////////////////////////////////
62
63 // Use standard definitions of all basic methods
64 SO_MFIELD_SOURCE_MALLOC(SoMFColor, SbColor, const SbColor &);
65
66 ////////////////////////////////////////////////////////////////////////
67 //
68 // Description:
69 // Sets RGB values from array of arrays of 3 floats. This can be useful
70 // in some applications that have colors stored in this manner and
71 // want to keep them that way for efficiency.
72 //
73 // Use: public
74
75 void
76 SoMFColor::setValues(int start, // Starting index
77 int num, // Number of values to set
78 const float rgb[][3]) // Array of RGB values
79 //
80 ////////////////////////////////////////////////////////////////////////
81 {
82 int newNum = start + num;
83 int i;
84
85 if (newNum > getNum())
86 makeRoom(newNum);
87
88 for (i = 0; i < num; i++)
89 values[start + i].setValue(rgb[i]);
90
91 valueChanged();
92 }
93
94 ////////////////////////////////////////////////////////////////////////
95 //
96 // Description:
97 // Sets HSV values from array of arrays of 3 floats. This can be useful
98 // in some applications that have colors stored in this manner and
99 // want to keep them that way for efficiency.
100 //
101 // Use: public
102
103 void
104 SoMFColor::setHSVValues(int start, // Starting index
105 int num, // Number of values to set
106 const float hsv[][3]) // Array of HSV values
107 //
108 ////////////////////////////////////////////////////////////////////////
109 {
110 int newNum = start + num;
111 int i;
112
113 if (newNum > getNum())
114 makeRoom(newNum);
115
116 for (i = 0; i < num; i++)
117 values[start + i].setHSVValue(hsv[i]);
118
119 valueChanged();
120 }
121
122 ////////////////////////////////////////////////////////////////////////
123 //
124 // Description:
125 // These are all convenience functions that set the field to
126 // contain one and only one value, given that value in various
127 // forms, both RGB and HSV.
128 //
129 // Use: public
130 //
131 ////////////////////////////////////////////////////////////////////////
132
133 void
134 SoMFColor::setValue(const SbVec3f &vec)
135 {
136 setValue(SbColor(vec.getValue()));
137 }
138
139 void
140 SoMFColor::setValue(float r, float g, float b)
141 {
142 setValue(SbColor(r, g, b));
143 }
144
145 void
146 SoMFColor::setValue(const float rgb[3])
147 {
148 setValue(SbColor(rgb));
149 }
150
151 void
152 SoMFColor::setHSVValue(float h, float s, float v)
153 {
154 SbColor c;
155
156 c.setHSVValue(h, s, v);
157 setValue(c);
158 }
159
160 void
161 SoMFColor::setHSVValue(const float hsv[3])
162 {
163 SbColor c;
164
165 c.setHSVValue(hsv);
166 setValue(c);
167 }
168
169 ////////////////////////////////////////////////////////////////////////
170 //
171 // Description:
172 // These are all convenience functions that set one value of the
173 // field to a given value, which is specified in various forms,
174 // both RGB and HSV.
175 //
176 // Use: public
177 //
178 ////////////////////////////////////////////////////////////////////////
179
180 void
181 SoMFColor::set1Value(int index, const SbVec3f &vec)
182 {
183 set1Value(index, SbColor(vec.getValue()));
184 }
185
186 void
187 SoMFColor::set1Value(int index, float r, float g, float b)
188 {
189 set1Value(index, SbColor(r, g, b));
190 }
191
192 void
193 SoMFColor::set1Value(int index, const float rgb[3])
194 {
195 set1Value(index, SbColor(rgb));
196 }
197
198 void
199 SoMFColor::set1HSVValue(int index, float h, float s, float v)
200 {
201 SbColor c;
202
203 c.setHSVValue(h, s, v);
204 set1Value(index, c);
205 }
206
207 void
208 SoMFColor::set1HSVValue(int index, const float hsv[3])
209 {
210 SbColor c;
211
212 c.setHSVValue(hsv);
213 set1Value(index, c);
214 }
215
216 ////////////////////////////////////////////////////////////////////////
217 //
218 // Description:
219 // Reads one (indexed) value from file. Returns FALSE on error.
220 //
221 // Use: private
222
223 SbBool
224 SoMFColor::read1Value(SoInput *in, int index)
225 //
226 ////////////////////////////////////////////////////////////////////////
227 {
228 return (in->read(values[index][0]) &&
229 in->read(values[index][1]) &&
230 in->read(values[index][2]));
231 }
232
233 ////////////////////////////////////////////////////////////////////////
234 //
235 // Description:
236 // Writes one (indexed) value to file.
237 //
238 // Use: private
239
240 void
241 SoMFColor::write1Value(SoOutput *out, int index) const
242 //
243 ////////////////////////////////////////////////////////////////////////
244 {
245 out->write(values[index][0]);
246
247 if (! out->isBinary())
248 out->write(' ');
249
250 out->write(values[index][1]);
251
252 if (! out->isBinary())
253 out->write(' ');
254
255 out->write(values[index][2]);
256 }
257
258 ////////////////////////////////////////////////////////////////////////
259 //
260 // Description:
261 // Writes array of binary values to file as one chunk.
262 //
263 // Use: private
264
265 void
266 SoMFColor::writeBinaryValues(SoOutput *out) const
267
268 //
269 ////////////////////////////////////////////////////////////////////////
270 {
271 out->writeBinaryArray((float *) values, 3 * num);
272 }
273
274
275 ////////////////////////////////////////////////////////////////////////
276 //
277 // Description:
278 // Reads array of binary values from file as one chunk.
279 //
280 // Use: private
281
282 SbBool
283 SoMFColor::readBinaryValues(SoInput *in, int numToRead)
284 //
285 ////////////////////////////////////////////////////////////////////////
286 {
287 return (in->readBinaryArray((float *) values, 3 * numToRead));
288 }