Debian Codegraph @

lib/database/src/so/elements/SoProfileCoordinateElement.c++

raw
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 $
44 |
45 | Classes:
46 | SoProfileCoordinateElement
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/elements/SoProfileCoordinateElement.h>
55 #include <Inventor/errors/SoDebugError.h>
56
57 SO_ELEMENT_SOURCE(SoProfileCoordinateElement);
58
59 SbVec2f *SoProfileCoordinateElement::defaultCoord2 = NULL;
60
61 ////////////////////////////////////////////////////////////////////////
62 //
63 // Description:
64 // Destructor.
65 //
66 // Use: private
67
68 SoProfileCoordinateElement::~SoProfileCoordinateElement()
69 //
70 ////////////////////////////////////////////////////////////////////////
71 {
72 }
73
74 ////////////////////////////////////////////////////////////////////////
75 //
76 // Description:
77 // Initializes element.
78 //
79 // Use: public
80
81 void
82 SoProfileCoordinateElement::init(SoState *state)
83 //
84 ////////////////////////////////////////////////////////////////////////
85 {
86 SoReplacedElement::init(state);
87
88 // Initialize default coordinate storage if not already done
89 if (defaultCoord2 == NULL) {
90 defaultCoord2 = new SbVec2f;
91 *defaultCoord2 = getDefault2();
92 }
93
94 // Assume 2D until told otherwise
95 coordsAre2D = TRUE;
96 coords2 = defaultCoord2;
97 numCoords = 1;
98 }
99
100 ////////////////////////////////////////////////////////////////////////
101 //
102 // Description:
103 // Sets the 2-D coordinates in element accessed from state.
104 //
105 // Use: public
106
107 void
108 SoProfileCoordinateElement::set2(SoState *state, SoNode *node,
109 int32_t numCoords, const SbVec2f *coords)
110 //
111 ////////////////////////////////////////////////////////////////////////
112 {
113 SoProfileCoordinateElement *elt;
114
115 // Get an instance we can change (pushing if necessary)
116 elt = (SoProfileCoordinateElement *)
117 getElement(state, classStackIndex, node);
118
119 if (elt != NULL) {
120 elt->numCoords = numCoords;
121 elt->coords2 = coords;
122 elt->coordsAre2D = TRUE;
123 }
124 }
125
126 ////////////////////////////////////////////////////////////////////////
127 //
128 // Description:
129 // Sets the 3-D coordinates in element accessed from state.
130 //
131 // Use: public
132
133 void
134 SoProfileCoordinateElement::set3(SoState *state, SoNode *node,
135 int32_t numCoords, const SbVec3f *coords)
136 //
137 ////////////////////////////////////////////////////////////////////////
138 {
139 SoProfileCoordinateElement *elt;
140
141 // Get an instance we can change (pushing if necessary)
142 elt = (SoProfileCoordinateElement *)
143 getElement(state, classStackIndex, node);
144
145 if (elt != NULL) {
146 elt->numCoords = numCoords;
147 elt->coords3 = coords;
148 elt->coordsAre2D = FALSE;
149 }
150 }
151
152 ////////////////////////////////////////////////////////////////////////
153 //
154 // Description:
155 // Returns the top (current) instance of the element in the state.
156 //
157 // Use: public
158
159 const SoProfileCoordinateElement *
160 SoProfileCoordinateElement::getInstance(SoState *state)
161 //
162 ////////////////////////////////////////////////////////////////////////
163 {
164 return (const SoProfileCoordinateElement *)
165 getConstElement(state, classStackIndex);
166 }
167
168 ////////////////////////////////////////////////////////////////////////
169 //
170 // Description:
171 // Returns the indexed coordinate from an element as an SbVec2f.
172 //
173 // Use: public
174
175 const SbVec2f &
176 SoProfileCoordinateElement::get2(int index) const
177 //
178 ////////////////////////////////////////////////////////////////////////
179 {
180 #ifdef DEBUG
181 if (index < 0 || index >= numCoords)
182 SoDebugError::post("SoProfileCoordinateElement::get2",
183 "Index (%d) is out of range 0 - %d",
184 index, numCoords - 1);
185 #endif /* DEBUG */
186
187 if (coordsAre2D)
188 return coords2[index];
189
190 // Convert from 3-D if necessary
191 else {
192 // Cast the const away...
193 SoProfileCoordinateElement *elt = (SoProfileCoordinateElement *) this;
194 const SbVec3f &c3 = coords3[index];
195
196 elt->convert2[0] = c3[0] / c3[2];
197 elt->convert2[1] = c3[1] / c3[2];
198
199 return convert2;
200 }
201 }
202
203 ////////////////////////////////////////////////////////////////////////
204 //
205 // Description:
206 // Returns the indexed coordinate from an element as an SbVec3f.
207 //
208 // Use: public
209
210 const SbVec3f &
211 SoProfileCoordinateElement::get3(int index) const
212 //
213 ////////////////////////////////////////////////////////////////////////
214 {
215 #ifdef DEBUG
216 if (index < 0 || index >= numCoords)
217 SoDebugError::post("SoProfileCoordinateElement::get3",
218 "Index (%d) is out of range 0 - %d",
219 index, numCoords - 1);
220 #endif /* DEBUG */
221
222 // Convert from 2-D if necessary
223 if (coordsAre2D) {
224 // Cast the const away...
225 SoProfileCoordinateElement *elt = (SoProfileCoordinateElement *) this;
226 const SbVec2f &c2 = coords2[index];
227
228 elt->convert3[0] = c2[0];
229 elt->convert3[1] = c2[1];
230 elt->convert3[2] = 0.0;
231
232 return convert3;
233 }
234
235 else
236 return coords3[index];
237 }
238
239 ////////////////////////////////////////////////////////////////////////
240 //
241 // Description:
242 // Prints element for debugging.
243 //
244 // Use: public
245 //
246 ////////////////////////////////////////////////////////////////////////
247
248 #ifdef DEBUG
249 void
250 SoProfileCoordinateElement::print(FILE *fp) const
251 {
252 SoReplacedElement::print(fp);
253 }
254 #else /* DEBUG */
255 void
256 SoProfileCoordinateElement::print(FILE *) const
257 {
258 }
259 #endif /* DEBUG */