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