b311480e |
1 | // Created on: 2000-06-16 |
973c2be1 |
2 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
15 | #include <Graphic3d_ArrayOfPrimitives.hxx> |
16 | #include <Standard_OutOfRange.hxx> |
17 | |
18 | #include <stdio.h> |
19 | #include <stdlib.h> |
20 | |
b8ddfc2f |
21 | #include <gp_Dir.hxx> |
22 | #include <gp_Pnt.hxx> |
7fd59977 |
23 | |
b8ddfc2f |
24 | inline Graphic3d_PrimitiveArray Graphic3d_ArrayOfPrimitives::Array() const |
25 | { |
7fd59977 |
26 | return myPrimitiveArray; |
27 | } |
28 | |
b8ddfc2f |
29 | inline Graphic3d_TypeOfPrimitiveArray Graphic3d_ArrayOfPrimitives::Type() const |
30 | { |
7fd59977 |
31 | Graphic3d_TypeOfPrimitiveArray type = Graphic3d_TOPA_UNDEFINED; |
32 | if( myPrimitiveArray ) type = (Graphic3d_TypeOfPrimitiveArray) myPrimitiveArray->type; |
33 | return type; |
34 | } |
35 | |
b8ddfc2f |
36 | inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexNormals() const |
37 | { |
7fd59977 |
38 | Standard_Boolean defined = Standard_False; |
39 | if( myPrimitiveArray && myPrimitiveArray->vnormals ) defined = Standard_True; |
40 | return defined; |
41 | } |
42 | |
b8ddfc2f |
43 | inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexColors() const |
44 | { |
7fd59977 |
45 | Standard_Boolean defined = Standard_False; |
46 | if( myPrimitiveArray && myPrimitiveArray->vcolours ) defined = Standard_True; |
47 | return defined; |
48 | } |
49 | |
b8ddfc2f |
50 | inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexTexels() const |
51 | { |
7fd59977 |
52 | Standard_Boolean defined = Standard_False; |
53 | if( myPrimitiveArray && myPrimitiveArray->vtexels ) defined = Standard_True; |
54 | return defined; |
55 | } |
56 | |
b8ddfc2f |
57 | inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasEdgeInfos() const |
58 | { |
7fd59977 |
59 | Standard_Boolean defined = Standard_False; |
60 | if( myPrimitiveArray && myPrimitiveArray->edge_vis ) defined = Standard_True; |
61 | return defined; |
62 | } |
63 | |
b8ddfc2f |
64 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::VertexNumber() const |
65 | { |
7fd59977 |
66 | Standard_Integer number = -1; |
67 | if( myPrimitiveArray ) number = myPrimitiveArray->num_vertexs; |
68 | return number; |
69 | } |
70 | |
b8ddfc2f |
71 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex(const gp_Pnt& aVertice) |
72 | { |
73 | return AddVertex(aVertice.X(),aVertice.Y(),aVertice.Z()); |
74 | } |
75 | |
76 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex( |
77 | const Standard_Real X, const Standard_Real Y, const Standard_Real Z) |
78 | { |
79 | return AddVertex(Standard_ShortReal(X),Standard_ShortReal(Y),Standard_ShortReal(Z)); |
80 | } |
81 | |
82 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex(const gp_Pnt& aVertice, const gp_Dir& aNormal) |
83 | { |
84 | return AddVertex(aVertice.X(),aVertice.Y(),aVertice.Z(),aNormal.X(),aNormal.Y(),aNormal.Z()); |
85 | } |
86 | |
87 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex( |
88 | const Standard_Real X, const Standard_Real Y, const Standard_Real Z, |
89 | const Standard_Real NX, const Standard_Real NY, const Standard_Real NZ) |
90 | { |
91 | return AddVertex(Standard_ShortReal(X),Standard_ShortReal(Y),Standard_ShortReal(Z), |
92 | Standard_ShortReal(NX),Standard_ShortReal(NY),Standard_ShortReal(NZ)); |
93 | } |
94 | |
95 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex(const gp_Pnt& aVertice, const gp_Pnt2d& aTexel) |
96 | { |
97 | return AddVertex(aVertice.X(),aVertice.Y(),aVertice.Z(),aTexel.X(),aTexel.Y()); |
98 | } |
99 | |
100 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex( |
101 | const Standard_Real X, const Standard_Real Y, const Standard_Real Z, |
102 | const Standard_Real TX, const Standard_Real TY) |
103 | { |
104 | return AddVertex(Standard_ShortReal(X),Standard_ShortReal(Y),Standard_ShortReal(Z), |
105 | Standard_ShortReal(TX),Standard_ShortReal(TY)); |
106 | } |
107 | |
108 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex(const gp_Pnt& aVertice, const gp_Dir& aNormal, const gp_Pnt2d& aTexel) |
109 | { |
110 | return AddVertex(aVertice.X(),aVertice.Y(),aVertice.Z(),aNormal.X(),aNormal.Y(),aNormal.Z(),aTexel.X(),aTexel.Y()); |
111 | } |
112 | |
113 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex( |
114 | const Standard_Real X, const Standard_Real Y, const Standard_Real Z, |
115 | const Standard_Real NX, const Standard_Real NY, const Standard_Real NZ, |
116 | const Standard_Real TX, const Standard_Real TY) |
117 | { |
118 | return AddVertex(Standard_ShortReal(X),Standard_ShortReal(Y),Standard_ShortReal(Z), |
119 | Standard_ShortReal(NX),Standard_ShortReal(NY),Standard_ShortReal(NZ), |
120 | Standard_ShortReal(TX),Standard_ShortReal(TY)); |
121 | } |
122 | |
7fd59977 |
123 | inline void Graphic3d_ArrayOfPrimitives::SetVertice( |
124 | const Standard_Integer anIndex, |
b8ddfc2f |
125 | const Standard_ShortReal X, const Standard_ShortReal Y, const Standard_ShortReal Z) |
126 | { |
7fd59977 |
127 | if( !myPrimitiveArray ) return; |
b8ddfc2f |
128 | if( anIndex < 1 || anIndex > myMaxVertexs ) |
7fd59977 |
129 | Standard_OutOfRange::Raise(" BAD VERTEX index"); |
7fd59977 |
130 | |
b8ddfc2f |
131 | if( myPrimitiveArray->vertices ) { |
132 | Tfloat *p = myPrimitiveArray->vertices[anIndex-1].xyz; |
133 | *p++ = X; |
134 | *p++ = Y; |
135 | *p = Z; |
7fd59977 |
136 | } |
137 | myPrimitiveArray->num_vertexs = Max(anIndex,myPrimitiveArray->num_vertexs); |
138 | } |
139 | |
b8ddfc2f |
140 | inline void Graphic3d_ArrayOfPrimitives::SetVertexColor(const Standard_Integer anIndex, |
6598416b |
141 | const Standard_Real R, |
142 | const Standard_Real G, |
b8ddfc2f |
143 | const Standard_Real B) |
144 | { |
7fd59977 |
145 | if( !myPrimitiveArray ) return; |
146 | if( anIndex < 1 || anIndex > myMaxVertexs ) { |
147 | Standard_OutOfRange::Raise(" BAD VERTEX index"); |
148 | } |
149 | |
150 | if( myPrimitiveArray->vcolours ) { |
8263fcd3 |
151 | unsigned int red = (unsigned int)(R * 255.); |
152 | unsigned int green = (unsigned int)(G * 255.); |
153 | unsigned int blue = (unsigned int)(B * 255.); |
154 | unsigned int alpha = 0; |
155 | Standard_Integer outColor = alpha << 24 | blue << 16 | green << 8 | red; |
7fd59977 |
156 | SetVertexColor( anIndex, outColor ); |
6598416b |
157 | } |
7fd59977 |
158 | myPrimitiveArray->num_vertexs = Max(anIndex,myPrimitiveArray->num_vertexs); |
159 | } |
160 | |
161 | inline void Graphic3d_ArrayOfPrimitives::SetVertexNormal( |
162 | const Standard_Integer anIndex, |
163 | const Standard_Real NX, const Standard_Real NY, const Standard_Real NZ) |
164 | { |
165 | if( !myPrimitiveArray ) return; |
166 | if( anIndex < 1 || anIndex > myMaxVertexs ) { |
167 | Standard_OutOfRange::Raise(" BAD VERTEX index"); |
168 | } |
169 | |
170 | Standard_Integer index = anIndex-1; |
171 | |
172 | { |
173 | if( myPrimitiveArray->vnormals ) { |
174 | Tfloat *p = myPrimitiveArray->vnormals[index].xyz; |
175 | *p++ = Standard_ShortReal(NX); |
176 | *p++ = Standard_ShortReal(NY); |
177 | *p = Standard_ShortReal(NZ); |
178 | } |
179 | } |
180 | myPrimitiveArray->num_vertexs = Max(anIndex,myPrimitiveArray->num_vertexs); |
181 | } |
182 | |
183 | inline void Graphic3d_ArrayOfPrimitives::SetVertexTexel( |
184 | const Standard_Integer anIndex, |
b8ddfc2f |
185 | const Standard_Real TX, const Standard_Real TY) |
186 | { |
7fd59977 |
187 | if( !myPrimitiveArray ) return; |
188 | if( anIndex < 1 || anIndex > myMaxVertexs ) { |
189 | Standard_OutOfRange::Raise(" BAD VERTEX index"); |
190 | } |
191 | |
192 | Standard_Integer index = anIndex-1; |
193 | if( myPrimitiveArray->vtexels ) { |
194 | Tfloat *p = myPrimitiveArray->vtexels[index].xy; |
195 | *p++ = Standard_ShortReal(TX); |
196 | *p = Standard_ShortReal(TY); |
197 | } |
198 | myPrimitiveArray->num_vertexs = Max(anIndex,myPrimitiveArray->num_vertexs); |
199 | } |
200 | |
201 | inline void Graphic3d_ArrayOfPrimitives::SetBoundColor( |
202 | const Standard_Integer anIndex, |
b8ddfc2f |
203 | const Standard_Real R, const Standard_Real G, const Standard_Real B) |
204 | { |
7fd59977 |
205 | if( !myPrimitiveArray ) return; |
206 | if( anIndex < 1 || anIndex > myMaxBounds ) { |
207 | Standard_OutOfRange::Raise(" BAD BOUND index"); |
208 | } |
209 | |
210 | Standard_Integer index = anIndex-1; |
211 | Tfloat *p = myPrimitiveArray->fcolours[index].rgb; |
212 | *p++ = Standard_ShortReal(R); |
213 | *p++ = Standard_ShortReal(G); |
214 | *p = Standard_ShortReal(B); |
215 | |
216 | myPrimitiveArray->num_bounds = Max(anIndex,myPrimitiveArray->num_bounds); |
217 | } |
218 | |
219 | inline void Graphic3d_ArrayOfPrimitives::Vertice(const Standard_Integer anIndex, |
b8ddfc2f |
220 | Standard_Real& X, Standard_Real& Y, Standard_Real& Z) const |
221 | { |
7fd59977 |
222 | X = Y = Z = 0.; |
223 | if( !myPrimitiveArray ) return; |
224 | if( anIndex < 1 || anIndex > myPrimitiveArray->num_vertexs ) { |
225 | Standard_OutOfRange::Raise(" BAD VERTEX index"); |
226 | } |
227 | |
228 | Standard_Integer index = anIndex-1; |
6598416b |
229 | if( myPrimitiveArray->vertices ) { |
7fd59977 |
230 | Tfloat *p = myPrimitiveArray->vertices[index].xyz; |
231 | X = Standard_Real(*p++); Y = Standard_Real(*p++); Z = Standard_Real(*p); |
232 | } |
233 | } |
234 | |
235 | inline void Graphic3d_ArrayOfPrimitives::VertexColor(const Standard_Integer anIndex, |
b8ddfc2f |
236 | Standard_Real& R, Standard_Real& G, Standard_Real& B) const |
237 | { |
7fd59977 |
238 | R = G = B = 0; |
239 | if( !myPrimitiveArray ) return; |
240 | if( anIndex < 1 || anIndex > myPrimitiveArray->num_vertexs ) { |
241 | Standard_OutOfRange::Raise(" BAD VERTEX index"); |
6598416b |
242 | } |
7fd59977 |
243 | Standard_Integer aColor; |
244 | VertexColor(anIndex, aColor); |
6598416b |
245 | if( myPrimitiveArray->vcolours ) { |
246 | Standard_Integer r,g,b; |
7fd59977 |
247 | Standard_Integer aColor; |
248 | VertexColor(anIndex, aColor); |
6598416b |
249 | /*Standard_Real A; |
250 | Standard_Integer a = aColor & 0xff000000; |
7fd59977 |
251 | a >>= 24; |
6598416b |
252 | A = ((Standard_Real) a) / 255.;*/ |
7fd59977 |
253 | |
254 | b = aColor & 0x00ff0000; |
255 | b >>= 16; |
256 | B =((Standard_Real) b) / 255.; |
257 | |
258 | g = aColor & 0x0000ff00; |
259 | g >>= 8; |
260 | G = ((Standard_Real) g) / 255.; |
261 | |
262 | r = aColor & 0x000000ff; |
6598416b |
263 | r >>= 0; |
7fd59977 |
264 | R = ((Standard_Real) r) / 255.; |
265 | } |
266 | } |
267 | |
268 | inline void Graphic3d_ArrayOfPrimitives::VertexColor(const Standard_Integer anIndex, |
6598416b |
269 | Standard_Integer& aColor) const |
7fd59977 |
270 | { |
271 | Standard_Integer index = anIndex-1; |
272 | |
6598416b |
273 | if( myPrimitiveArray->vcolours ) { |
7fd59977 |
274 | #if defined (sparc) || defined (__sparc__) || defined (__sparc) |
275 | aColor = 0; |
276 | const char* p_ch = (const char*)&(myPrimitiveArray->vcolours[index]); |
277 | aColor += p_ch[0]; |
278 | aColor += p_ch[1] << 8 ; |
279 | aColor += p_ch[2] << 16; |
280 | aColor += p_ch[3] << 24; |
281 | #else |
282 | aColor = myPrimitiveArray->vcolours[index]; |
283 | #endif |
284 | } |
285 | } |
286 | |
7fd59977 |
287 | inline void Graphic3d_ArrayOfPrimitives::VertexNormal(const Standard_Integer anIndex, |
b8ddfc2f |
288 | Standard_Real& NX, Standard_Real& NY, Standard_Real& NZ) const |
289 | { |
7fd59977 |
290 | NX = NY = NZ = 0.; |
291 | if( !myPrimitiveArray ) return; |
292 | if( anIndex < 1 || anIndex > myPrimitiveArray->num_vertexs ) { |
293 | Standard_OutOfRange::Raise(" BAD VERTEX index"); |
294 | } |
295 | |
296 | Standard_Integer index = anIndex-1; |
6598416b |
297 | if( myPrimitiveArray->vnormals ) { |
7fd59977 |
298 | Tfloat *p = myPrimitiveArray->vnormals[index].xyz; |
299 | NX = Standard_Real(*p++); NY = Standard_Real(*p++); NZ = Standard_Real(*p); |
300 | } |
301 | } |
302 | |
303 | inline void Graphic3d_ArrayOfPrimitives::VertexTexel(const Standard_Integer anIndex, |
b8ddfc2f |
304 | Standard_Real& TX, Standard_Real& TY) const |
305 | { |
7fd59977 |
306 | TX = TY = 0.; |
307 | if( !myPrimitiveArray ) return; |
308 | if( anIndex < 1 || anIndex > myPrimitiveArray->num_vertexs ) { |
309 | Standard_OutOfRange::Raise(" BAD VERTEX index"); |
310 | } |
311 | |
312 | Standard_Integer index = anIndex-1; |
6598416b |
313 | if( myPrimitiveArray->vtexels ) { |
7fd59977 |
314 | Tfloat *p = myPrimitiveArray->vtexels[index].xy; |
315 | TX = Standard_Real(*p++); TY = Standard_Real(*p); |
316 | } |
317 | } |
318 | |
b8ddfc2f |
319 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::EdgeNumber() const |
320 | { |
7fd59977 |
321 | Standard_Integer number = -1; |
322 | if( myPrimitiveArray ) number = myPrimitiveArray->num_edges; |
323 | return number; |
324 | } |
325 | |
b8ddfc2f |
326 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::Edge(const Standard_Integer anIndex ) const |
327 | { |
7fd59977 |
328 | Standard_Integer index=0; |
6598416b |
329 | if( myPrimitiveArray && myPrimitiveArray->edge_vis && |
7fd59977 |
330 | (anIndex > 0) && (anIndex <= myPrimitiveArray->num_edges) ) { |
331 | index = myPrimitiveArray->edges[anIndex-1]; |
332 | } else { |
333 | Standard_OutOfRange::Raise(" BAD EDGE index"); |
334 | } |
335 | return index+1; |
336 | } |
337 | |
b8ddfc2f |
338 | inline Standard_Boolean Graphic3d_ArrayOfPrimitives::EdgeIsVisible(const Standard_Integer anIndex ) const |
339 | { |
7fd59977 |
340 | Standard_Boolean isVisible = Standard_False; |
6598416b |
341 | if( myPrimitiveArray && myPrimitiveArray->edge_vis && |
7fd59977 |
342 | (anIndex > 0) && (anIndex <= myPrimitiveArray->num_edges) ) { |
6598416b |
343 | isVisible = (myPrimitiveArray->edge_vis[anIndex-1] == 0) ? |
7fd59977 |
344 | Standard_False : Standard_True; |
345 | } else { |
346 | Standard_OutOfRange::Raise(" BAD EDGE index"); |
347 | } |
348 | return isVisible; |
349 | } |
350 | |
b8ddfc2f |
351 | inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasBoundColors() const |
352 | { |
7fd59977 |
353 | Standard_Boolean defined = Standard_False; |
354 | if( myPrimitiveArray && myPrimitiveArray->fcolours ) defined = Standard_True; |
355 | return defined; |
356 | } |
357 | |
b8ddfc2f |
358 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::BoundNumber() const |
359 | { |
7fd59977 |
360 | Standard_Integer number = -1; |
361 | if( myPrimitiveArray ) number = myPrimitiveArray->num_bounds; |
362 | return number; |
363 | } |
364 | |
b8ddfc2f |
365 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::Bound(const Standard_Integer anIndex) const |
366 | { |
7fd59977 |
367 | Standard_Integer number=-1; |
6598416b |
368 | if( myPrimitiveArray && myPrimitiveArray->bounds && |
7fd59977 |
369 | (anIndex > 0) && (anIndex <= myPrimitiveArray->num_bounds) ) { |
370 | number = myPrimitiveArray->bounds[anIndex-1]; |
371 | } else { |
372 | Standard_OutOfRange::Raise(" BAD BOUND index"); |
373 | } |
374 | return number; |
375 | } |
376 | |
377 | inline void Graphic3d_ArrayOfPrimitives::BoundColor(const Standard_Integer anIndex, |
b8ddfc2f |
378 | Standard_Real& R, Standard_Real& G, Standard_Real& B) const |
379 | { |
6598416b |
380 | if( myPrimitiveArray && myPrimitiveArray->fcolours && |
7fd59977 |
381 | (anIndex > 0) && (anIndex <= myPrimitiveArray->num_bounds) ) { |
382 | Tfloat *p = myPrimitiveArray->fcolours[anIndex-1].rgb; |
383 | R = Standard_Real(*p++); G = Standard_Real(*p++); B = Standard_Real(*p); |
384 | } else { |
385 | Standard_OutOfRange::Raise(" BAD BOUND index"); |
386 | } |
387 | } |