0023433: Compiler warnings in Graphic3d_ArrayOfPrimitives.lxx
[occt.git] / src / Graphic3d / Graphic3d_ArrayOfPrimitives.lxx
CommitLineData
b311480e 1// Created on: 2000-06-16
2// Copyright (c) 2000-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19
20#include <Graphic3d_ArrayOfPrimitives.hxx>
21#include <Standard_OutOfRange.hxx>
22
23#include <stdio.h>
24#include <stdlib.h>
25
26inline Graphic3d_PrimitiveArray Graphic3d_ArrayOfPrimitives::Array() const {
27
28 return myPrimitiveArray;
29}
30
31inline Graphic3d_TypeOfPrimitiveArray Graphic3d_ArrayOfPrimitives::Type() const {
32
33 Graphic3d_TypeOfPrimitiveArray type = Graphic3d_TOPA_UNDEFINED;
34 if( myPrimitiveArray ) type = (Graphic3d_TypeOfPrimitiveArray) myPrimitiveArray->type;
35 return type;
36}
37
38inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexNormals() const {
39 Standard_Boolean defined = Standard_False;
40 if( myPrimitiveArray && myPrimitiveArray->vnormals ) defined = Standard_True;
41 return defined;
42}
43
44inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexColors() const {
45 Standard_Boolean defined = Standard_False;
46 if( myPrimitiveArray && myPrimitiveArray->vcolours ) defined = Standard_True;
47 return defined;
48}
49
50inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexTexels() const {
51 Standard_Boolean defined = Standard_False;
52 if( myPrimitiveArray && myPrimitiveArray->vtexels ) defined = Standard_True;
53 return defined;
54}
55
56inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasEdgeInfos() const {
57 Standard_Boolean defined = Standard_False;
58 if( myPrimitiveArray && myPrimitiveArray->edge_vis ) defined = Standard_True;
59 return defined;
60}
61
62inline Standard_Integer Graphic3d_ArrayOfPrimitives::VertexNumber() const {
63 Standard_Integer number = -1;
64 if( myPrimitiveArray ) number = myPrimitiveArray->num_vertexs;
65 return number;
66}
67
68inline void Graphic3d_ArrayOfPrimitives::SetVertice(
69 const Standard_Integer anIndex,
70 const Standard_Real X, const Standard_Real Y, const Standard_Real Z) {
71
72 if( !myPrimitiveArray ) return;
73 if( anIndex < 1 || anIndex > myMaxVertexs ) {
74 Standard_OutOfRange::Raise(" BAD VERTEX index");
75 }
76
77 Standard_Integer index = anIndex-1;
78 {
79 if( myPrimitiveArray->vertices ) {
80 Tfloat *p = myPrimitiveArray->vertices[index].xyz;
81 *p++ = Standard_ShortReal(X);
82 *p++ = Standard_ShortReal(Y);
83 *p = Standard_ShortReal(Z);
84 }
85 }
86 myPrimitiveArray->num_vertexs = Max(anIndex,myPrimitiveArray->num_vertexs);
87}
88
89
90inline void Graphic3d_ArrayOfPrimitives::SetVertexColor(
91 const Standard_Integer anIndex,
92 const Standard_Real R,
93 const Standard_Real G,
94 const Standard_Real B) {
95 if( !myPrimitiveArray ) return;
96 if( anIndex < 1 || anIndex > myMaxVertexs ) {
97 Standard_OutOfRange::Raise(" BAD VERTEX index");
98 }
99
100 if( myPrimitiveArray->vcolours ) {
a180e384 101 unsigned char red = (unsigned char)(R <= 0. ? 0. : R >= 1. ? 255. : R * 255.);
102 unsigned char green = (unsigned char)(G <= 0. ? 0. : G >= 1. ? 255. : G * 255.);
103 unsigned char blue = (unsigned char)(B <= 0. ? 0. : B >= 1. ? 255. : B * 255.);
7fd59977 104 unsigned char alpha = 0;
105 Standard_Integer outColor ;
106 outColor = red;
107 outColor += green << 8;
108 outColor += blue << 16;
109 outColor += alpha << 24;
110 SetVertexColor( anIndex, outColor );
111 }
112 myPrimitiveArray->num_vertexs = Max(anIndex,myPrimitiveArray->num_vertexs);
113}
114
115inline void Graphic3d_ArrayOfPrimitives::SetVertexNormal(
116 const Standard_Integer anIndex,
117 const Standard_Real NX, const Standard_Real NY, const Standard_Real NZ)
118{
119 if( !myPrimitiveArray ) return;
120 if( anIndex < 1 || anIndex > myMaxVertexs ) {
121 Standard_OutOfRange::Raise(" BAD VERTEX index");
122 }
123
124 Standard_Integer index = anIndex-1;
125
126 {
127 if( myPrimitiveArray->vnormals ) {
128 Tfloat *p = myPrimitiveArray->vnormals[index].xyz;
129 *p++ = Standard_ShortReal(NX);
130 *p++ = Standard_ShortReal(NY);
131 *p = Standard_ShortReal(NZ);
132 }
133 }
134 myPrimitiveArray->num_vertexs = Max(anIndex,myPrimitiveArray->num_vertexs);
135}
136
137inline void Graphic3d_ArrayOfPrimitives::SetVertexTexel(
138 const Standard_Integer anIndex,
139 const Standard_Real TX, const Standard_Real TY) {
140 if( !myPrimitiveArray ) return;
141 if( anIndex < 1 || anIndex > myMaxVertexs ) {
142 Standard_OutOfRange::Raise(" BAD VERTEX index");
143 }
144
145 Standard_Integer index = anIndex-1;
146 if( myPrimitiveArray->vtexels ) {
147 Tfloat *p = myPrimitiveArray->vtexels[index].xy;
148 *p++ = Standard_ShortReal(TX);
149 *p = Standard_ShortReal(TY);
150 }
151 myPrimitiveArray->num_vertexs = Max(anIndex,myPrimitiveArray->num_vertexs);
152}
153
154inline void Graphic3d_ArrayOfPrimitives::SetBoundColor(
155 const Standard_Integer anIndex,
156 const Standard_Real R, const Standard_Real G, const Standard_Real B) {
157 if( !myPrimitiveArray ) return;
158 if( anIndex < 1 || anIndex > myMaxBounds ) {
159 Standard_OutOfRange::Raise(" BAD BOUND index");
160 }
161
162 Standard_Integer index = anIndex-1;
163 Tfloat *p = myPrimitiveArray->fcolours[index].rgb;
164 *p++ = Standard_ShortReal(R);
165 *p++ = Standard_ShortReal(G);
166 *p = Standard_ShortReal(B);
167
168 myPrimitiveArray->num_bounds = Max(anIndex,myPrimitiveArray->num_bounds);
169}
170
171inline void Graphic3d_ArrayOfPrimitives::Vertice(const Standard_Integer anIndex,
172 Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const {
173 X = Y = Z = 0.;
174 if( !myPrimitiveArray ) return;
175 if( anIndex < 1 || anIndex > myPrimitiveArray->num_vertexs ) {
176 Standard_OutOfRange::Raise(" BAD VERTEX index");
177 }
178
179 Standard_Integer index = anIndex-1;
180 if( myPrimitiveArray->vertices ) {
181 Tfloat *p = myPrimitiveArray->vertices[index].xyz;
182 X = Standard_Real(*p++); Y = Standard_Real(*p++); Z = Standard_Real(*p);
183 }
184}
185
186inline void Graphic3d_ArrayOfPrimitives::VertexColor(const Standard_Integer anIndex,
187 Standard_Real& R, Standard_Real& G, Standard_Real& B) const {
188 R = G = B = 0;
189 if( !myPrimitiveArray ) return;
190 if( anIndex < 1 || anIndex > myPrimitiveArray->num_vertexs ) {
191 Standard_OutOfRange::Raise(" BAD VERTEX index");
192 }
193 Standard_Integer aColor;
194 VertexColor(anIndex, aColor);
195 if( myPrimitiveArray->vcolours ) {
196 Standard_Integer r,g,b,a;
197 Standard_Integer aColor;
198 VertexColor(anIndex, aColor);
199 Standard_Real A;
200 a = aColor & 0xff000000;
201 a >>= 24;
202 A = ((Standard_Real) a) / 255.;
203
204 b = aColor & 0x00ff0000;
205 b >>= 16;
206 B =((Standard_Real) b) / 255.;
207
208 g = aColor & 0x0000ff00;
209 g >>= 8;
210 G = ((Standard_Real) g) / 255.;
211
212 r = aColor & 0x000000ff;
213 r >>= 0;
214 R = ((Standard_Real) r) / 255.;
215 }
216}
217
218inline void Graphic3d_ArrayOfPrimitives::VertexColor(const Standard_Integer anIndex,
219 Standard_Integer& aColor) const
220{
221 Standard_Integer index = anIndex-1;
222
223 if( myPrimitiveArray->vcolours ) {
224#if defined (sparc) || defined (__sparc__) || defined (__sparc)
225 aColor = 0;
226 const char* p_ch = (const char*)&(myPrimitiveArray->vcolours[index]);
227 aColor += p_ch[0];
228 aColor += p_ch[1] << 8 ;
229 aColor += p_ch[2] << 16;
230 aColor += p_ch[3] << 24;
231#else
232 aColor = myPrimitiveArray->vcolours[index];
233#endif
234 }
235}
236
237
238inline void Graphic3d_ArrayOfPrimitives::VertexNormal(const Standard_Integer anIndex,
239 Standard_Real& NX, Standard_Real& NY, Standard_Real& NZ) const {
240 NX = NY = NZ = 0.;
241 if( !myPrimitiveArray ) return;
242 if( anIndex < 1 || anIndex > myPrimitiveArray->num_vertexs ) {
243 Standard_OutOfRange::Raise(" BAD VERTEX index");
244 }
245
246 Standard_Integer index = anIndex-1;
247 if( myPrimitiveArray->vnormals ) {
248 Tfloat *p = myPrimitiveArray->vnormals[index].xyz;
249 NX = Standard_Real(*p++); NY = Standard_Real(*p++); NZ = Standard_Real(*p);
250 }
251}
252
253inline void Graphic3d_ArrayOfPrimitives::VertexTexel(const Standard_Integer anIndex,
254 Standard_Real& TX, Standard_Real& TY) const {
255 TX = TY = 0.;
256 if( !myPrimitiveArray ) return;
257 if( anIndex < 1 || anIndex > myPrimitiveArray->num_vertexs ) {
258 Standard_OutOfRange::Raise(" BAD VERTEX index");
259 }
260
261 Standard_Integer index = anIndex-1;
262 if( myPrimitiveArray->vtexels ) {
263 Tfloat *p = myPrimitiveArray->vtexels[index].xy;
264 TX = Standard_Real(*p++); TY = Standard_Real(*p);
265 }
266}
267
268inline Standard_Integer Graphic3d_ArrayOfPrimitives::EdgeNumber() const {
269 Standard_Integer number = -1;
270 if( myPrimitiveArray ) number = myPrimitiveArray->num_edges;
271 return number;
272}
273
274inline Standard_Integer Graphic3d_ArrayOfPrimitives::Edge(
275 const Standard_Integer anIndex ) const {
276 Standard_Integer index=0;
277 if( myPrimitiveArray && myPrimitiveArray->edge_vis &&
278 (anIndex > 0) && (anIndex <= myPrimitiveArray->num_edges) ) {
279 index = myPrimitiveArray->edges[anIndex-1];
280 } else {
281 Standard_OutOfRange::Raise(" BAD EDGE index");
282 }
283 return index+1;
284}
285
286inline Standard_Boolean Graphic3d_ArrayOfPrimitives::EdgeIsVisible(
287 const Standard_Integer anIndex ) const {
288 Standard_Boolean isVisible = Standard_False;
289 if( myPrimitiveArray && myPrimitiveArray->edge_vis &&
290 (anIndex > 0) && (anIndex <= myPrimitiveArray->num_edges) ) {
291 isVisible = (myPrimitiveArray->edge_vis[anIndex-1] == 0) ?
292 Standard_False : Standard_True;
293 } else {
294 Standard_OutOfRange::Raise(" BAD EDGE index");
295 }
296 return isVisible;
297}
298
299inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasBoundColors() const {
300 Standard_Boolean defined = Standard_False;
301 if( myPrimitiveArray && myPrimitiveArray->fcolours ) defined = Standard_True;
302 return defined;
303}
304
305inline Standard_Integer Graphic3d_ArrayOfPrimitives::BoundNumber() const {
306 Standard_Integer number = -1;
307 if( myPrimitiveArray ) number = myPrimitiveArray->num_bounds;
308 return number;
309}
310
311inline Standard_Integer Graphic3d_ArrayOfPrimitives::Bound(const Standard_Integer anIndex) const {
312 Standard_Integer number=-1;
313 if( myPrimitiveArray && myPrimitiveArray->bounds &&
314 (anIndex > 0) && (anIndex <= myPrimitiveArray->num_bounds) ) {
315 number = myPrimitiveArray->bounds[anIndex-1];
316 } else {
317 Standard_OutOfRange::Raise(" BAD BOUND index");
318 }
319 return number;
320}
321
322inline void Graphic3d_ArrayOfPrimitives::BoundColor(const Standard_Integer anIndex,
323 Standard_Real& R, Standard_Real& G, Standard_Real& B) const {
324 if( myPrimitiveArray && myPrimitiveArray->fcolours &&
325 (anIndex > 0) && (anIndex <= myPrimitiveArray->num_bounds) ) {
326 Tfloat *p = myPrimitiveArray->fcolours[anIndex-1].rgb;
327 R = Standard_Real(*p++); G = Standard_Real(*p++); B = Standard_Real(*p);
328 } else {
329 Standard_OutOfRange::Raise(" BAD BOUND index");
330 }
331}