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 | |
b8ddfc2f |
18 | #include <gp_Dir.hxx> |
19 | #include <gp_Pnt.hxx> |
7fd59977 |
20 | |
871fa103 |
21 | inline const Handle(Graphic3d_IndexBuffer)& Graphic3d_ArrayOfPrimitives::Indices() const |
22 | { |
23 | return myIndices; |
24 | } |
25 | |
26 | inline const Handle(Graphic3d_Buffer)& Graphic3d_ArrayOfPrimitives::Attributes() const |
b8ddfc2f |
27 | { |
871fa103 |
28 | return myAttribs; |
29 | } |
30 | |
31 | inline const Handle(Graphic3d_BoundBuffer)& Graphic3d_ArrayOfPrimitives::Bounds() const |
32 | { |
33 | return myBounds; |
7fd59977 |
34 | } |
35 | |
b8ddfc2f |
36 | inline Graphic3d_TypeOfPrimitiveArray Graphic3d_ArrayOfPrimitives::Type() const |
37 | { |
871fa103 |
38 | return myType; |
7fd59977 |
39 | } |
40 | |
b8ddfc2f |
41 | inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexNormals() const |
42 | { |
871fa103 |
43 | return myVNor != 0; |
7fd59977 |
44 | } |
45 | |
b8ddfc2f |
46 | inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexColors() const |
47 | { |
871fa103 |
48 | return myVCol != 0; |
7fd59977 |
49 | } |
50 | |
b8ddfc2f |
51 | inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasVertexTexels() const |
52 | { |
871fa103 |
53 | return myVTex != 0; |
7fd59977 |
54 | } |
55 | |
b8ddfc2f |
56 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::VertexNumber() const |
57 | { |
871fa103 |
58 | return !myAttribs.IsNull() ? myAttribs->NbElements : -1; |
7fd59977 |
59 | } |
60 | |
871fa103 |
61 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex) |
b8ddfc2f |
62 | { |
871fa103 |
63 | return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z()); |
b8ddfc2f |
64 | } |
65 | |
a79f67f8 |
66 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Graphic3d_Vec3& theVertex) |
67 | { |
68 | return AddVertex (theVertex.x(), theVertex.y(), theVertex.z()); |
69 | } |
70 | |
871fa103 |
71 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, |
72 | const Standard_Real theY, |
73 | const Standard_Real theZ) |
b8ddfc2f |
74 | { |
53a70197 |
75 | return AddVertex (RealToShortReal (theX), |
76 | RealToShortReal (theY), |
77 | RealToShortReal (theZ)); |
b8ddfc2f |
78 | } |
79 | |
871fa103 |
80 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex, |
81 | const gp_Dir& theNormal) |
b8ddfc2f |
82 | { |
871fa103 |
83 | return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(), |
84 | theNormal.X(), theNormal.Y(), theNormal.Z()); |
b8ddfc2f |
85 | } |
86 | |
871fa103 |
87 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ, |
88 | const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ) |
b8ddfc2f |
89 | { |
53a70197 |
90 | return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ), |
871fa103 |
91 | Standard_ShortReal (theNX), Standard_ShortReal (theNY), Standard_ShortReal (theNZ)); |
b8ddfc2f |
92 | } |
93 | |
871fa103 |
94 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex, |
95 | const gp_Pnt2d& theTexel) |
b8ddfc2f |
96 | { |
871fa103 |
97 | return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(), |
98 | theTexel.X(), theTexel.Y()); |
b8ddfc2f |
99 | } |
100 | |
871fa103 |
101 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ, |
102 | const Standard_Real theTX, const Standard_Real theTY) |
b8ddfc2f |
103 | { |
53a70197 |
104 | return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ), |
871fa103 |
105 | Standard_ShortReal (theTX), Standard_ShortReal (theTY)); |
b8ddfc2f |
106 | } |
107 | |
871fa103 |
108 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const gp_Pnt& theVertex, |
109 | const gp_Dir& theNormal, |
110 | const gp_Pnt2d& theTexel) |
b8ddfc2f |
111 | { |
871fa103 |
112 | return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(), |
113 | theNormal.X(), theNormal.Y(), theNormal.Z(), |
114 | theTexel.X(), theTexel.Y()); |
b8ddfc2f |
115 | } |
116 | |
871fa103 |
117 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ, |
118 | const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ, |
119 | const Standard_Real theTX, const Standard_Real theTY) |
b8ddfc2f |
120 | { |
53a70197 |
121 | return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ), |
871fa103 |
122 | Standard_ShortReal (theNX), Standard_ShortReal (theNY), Standard_ShortReal (theNZ), |
123 | Standard_ShortReal (theTX), Standard_ShortReal (theTY)); |
b8ddfc2f |
124 | } |
125 | |
871fa103 |
126 | inline void Graphic3d_ArrayOfPrimitives::SetVertice (const Standard_Integer theIndex, |
127 | const Standard_ShortReal theX, |
128 | const Standard_ShortReal theY, |
129 | const Standard_ShortReal theZ) |
b8ddfc2f |
130 | { |
871fa103 |
131 | if (myAttribs.IsNull()) |
132 | { |
133 | return; |
134 | } |
7fd59977 |
135 | |
871fa103 |
136 | if (theIndex < 1 |
137 | || theIndex > myMaxVertexs) |
138 | { |
139 | Standard_OutOfRange::Raise ("BAD VERTEX index"); |
7fd59977 |
140 | } |
871fa103 |
141 | |
142 | Graphic3d_Vec3& aVec = myAttribs->ChangeValue<Graphic3d_Vec3> (theIndex - 1); |
143 | aVec.x() = theX; |
144 | aVec.y() = theY; |
145 | aVec.z() = theZ; |
146 | |
147 | myAttribs->NbElements = Max (theIndex, myAttribs->NbElements); |
7fd59977 |
148 | } |
149 | |
871fa103 |
150 | inline void Graphic3d_ArrayOfPrimitives::SetVertexColor (const Standard_Integer theIndex, |
151 | const Standard_Real theR, |
152 | const Standard_Real theG, |
153 | const Standard_Real theB) |
b8ddfc2f |
154 | { |
871fa103 |
155 | if (myAttribs.IsNull()) |
156 | { |
157 | return; |
158 | } |
159 | |
160 | if (theIndex < 1 |
161 | || theIndex > myMaxVertexs) |
162 | { |
163 | Standard_OutOfRange::Raise ("BAD VERTEX index"); |
7fd59977 |
164 | } |
165 | |
871fa103 |
166 | if (myVCol != 0) |
167 | { |
168 | Graphic3d_Vec4ub aColor (Standard_Byte(theR * 255.0), |
169 | Standard_Byte(theG * 255.0), |
170 | Standard_Byte(theB * 255.0), 0); |
171 | SetVertexColor (theIndex, *reinterpret_cast<Standard_Integer*>(&aColor)); |
6598416b |
172 | } |
871fa103 |
173 | myAttribs->NbElements = Max (theIndex, myAttribs->NbElements); |
7fd59977 |
174 | } |
175 | |
871fa103 |
176 | inline void Graphic3d_ArrayOfPrimitives::SetVertexNormal (const Standard_Integer theIndex, |
177 | const Standard_Real theNX, |
178 | const Standard_Real theNY, |
179 | const Standard_Real theNZ) |
7fd59977 |
180 | { |
871fa103 |
181 | if (myAttribs.IsNull()) |
182 | { |
183 | return; |
7fd59977 |
184 | } |
185 | |
871fa103 |
186 | if (theIndex < 1 |
187 | || theIndex > myMaxVertexs) |
188 | { |
189 | Standard_OutOfRange::Raise ("BAD VERTEX index"); |
190 | } |
7fd59977 |
191 | |
871fa103 |
192 | if (myVNor != 0) |
7fd59977 |
193 | { |
871fa103 |
194 | Graphic3d_Vec3& aVec = *reinterpret_cast<Graphic3d_Vec3* >(myAttribs->changeValue (theIndex - 1) + size_t(myVNor)); |
195 | aVec.x() = Standard_ShortReal (theNX); |
196 | aVec.y() = Standard_ShortReal (theNY); |
197 | aVec.z() = Standard_ShortReal (theNZ); |
7fd59977 |
198 | } |
871fa103 |
199 | myAttribs->NbElements = Max (theIndex, myAttribs->NbElements); |
7fd59977 |
200 | } |
201 | |
871fa103 |
202 | inline void Graphic3d_ArrayOfPrimitives::SetVertexTexel (const Standard_Integer theIndex, |
203 | const Standard_Real theTX, |
204 | const Standard_Real theTY) |
b8ddfc2f |
205 | { |
871fa103 |
206 | if (myAttribs.IsNull()) |
207 | { |
208 | return; |
7fd59977 |
209 | } |
210 | |
871fa103 |
211 | if (theIndex < 1 |
212 | || theIndex > myMaxVertexs) |
213 | { |
214 | Standard_OutOfRange::Raise ("BAD VERTEX index"); |
7fd59977 |
215 | } |
871fa103 |
216 | |
217 | if (myVTex != 0) |
218 | { |
219 | Graphic3d_Vec2& aVec = *reinterpret_cast<Graphic3d_Vec2* >(myAttribs->changeValue (theIndex - 1) + size_t(myVTex)); |
220 | aVec.x() = Standard_ShortReal (theTX); |
221 | aVec.y() = Standard_ShortReal (theTY); |
222 | } |
223 | myAttribs->NbElements = Max (theIndex, myAttribs->NbElements); |
7fd59977 |
224 | } |
225 | |
871fa103 |
226 | inline void Graphic3d_ArrayOfPrimitives::SetBoundColor (const Standard_Integer theIndex, |
227 | const Standard_Real theR, |
228 | const Standard_Real theG, |
229 | const Standard_Real theB) |
b8ddfc2f |
230 | { |
871fa103 |
231 | if (myBounds.IsNull()) |
232 | { |
233 | return; |
7fd59977 |
234 | } |
235 | |
871fa103 |
236 | if (theIndex < 1 |
237 | || theIndex > myMaxBounds) |
238 | { |
239 | Standard_OutOfRange::Raise ("BAD BOUND index"); |
240 | } |
7fd59977 |
241 | |
871fa103 |
242 | Graphic3d_Vec4& aVec = myBounds->Colors[theIndex - 1]; |
243 | aVec.r() = Standard_ShortReal (theR); |
244 | aVec.g() = Standard_ShortReal (theG); |
245 | aVec.b() = Standard_ShortReal (theB); |
246 | aVec.a() = 1.0f; |
247 | myBounds->NbBounds = Max (theIndex, myBounds->NbBounds); |
7fd59977 |
248 | } |
249 | |
871fa103 |
250 | inline void Graphic3d_ArrayOfPrimitives::Vertice (const Standard_Integer theIndex, |
251 | Standard_Real& theX, |
252 | Standard_Real& theY, |
253 | Standard_Real& theZ) const |
b8ddfc2f |
254 | { |
871fa103 |
255 | theX = theY = theZ = 0.0; |
256 | if (myAttribs.IsNull()) |
257 | { |
258 | return; |
7fd59977 |
259 | } |
260 | |
871fa103 |
261 | if (theIndex < 1 |
262 | || theIndex > myAttribs->NbElements) |
263 | { |
264 | Standard_OutOfRange::Raise ("BAD VERTEX index"); |
7fd59977 |
265 | } |
871fa103 |
266 | |
267 | const Graphic3d_Vec3& aVec = myAttribs->Value<Graphic3d_Vec3> (theIndex - 1); |
268 | theX = Standard_Real(aVec.x()); |
269 | theY = Standard_Real(aVec.y()); |
270 | theZ = Standard_Real(aVec.z()); |
7fd59977 |
271 | } |
272 | |
871fa103 |
273 | inline void Graphic3d_ArrayOfPrimitives::VertexColor (const Standard_Integer theIndex, |
274 | Standard_Real& theR, |
275 | Standard_Real& theG, |
276 | Standard_Real& theB) const |
b8ddfc2f |
277 | { |
871fa103 |
278 | theR = theG = theB = 0.0; |
279 | if (myAttribs.IsNull()) |
280 | { |
281 | return; |
6598416b |
282 | } |
871fa103 |
283 | |
284 | if (theIndex < 1 |
285 | || theIndex > myAttribs->NbElements) |
286 | { |
287 | Standard_OutOfRange::Raise ("BAD VERTEX index"); |
7fd59977 |
288 | } |
871fa103 |
289 | Standard_Integer aColorInt = 0; |
290 | VertexColor (theIndex, aColorInt); |
9bfa28a7 |
291 | const Graphic3d_Vec4ub& aColor = *reinterpret_cast<const Graphic3d_Vec4ub* >(&aColorInt); |
871fa103 |
292 | theR = Standard_Real(aColor.r()) / 255.0; |
293 | theG = Standard_Real(aColor.g()) / 255.0; |
294 | theB = Standard_Real(aColor.b()) / 255.0; |
7fd59977 |
295 | } |
296 | |
871fa103 |
297 | inline void Graphic3d_ArrayOfPrimitives::VertexColor (const Standard_Integer theIndex, |
298 | Standard_Integer& theColor) const |
7fd59977 |
299 | { |
871fa103 |
300 | if (myVCol != 0) |
301 | { |
302 | theColor = *reinterpret_cast<const Standard_Integer* >(myAttribs->value (theIndex - 1) + size_t(myVCol)); |
303 | } |
7fd59977 |
304 | } |
305 | |
871fa103 |
306 | inline void Graphic3d_ArrayOfPrimitives::VertexNormal (const Standard_Integer theIndex, |
307 | Standard_Real& theNX, |
308 | Standard_Real& theNY, |
309 | Standard_Real& theNZ) const |
b8ddfc2f |
310 | { |
871fa103 |
311 | theNX = theNY = theNZ = 0.0; |
312 | if (myAttribs.IsNull()) |
313 | { |
314 | return; |
315 | } |
316 | |
317 | if (theIndex < 1 |
318 | || theIndex > myAttribs->NbElements) |
319 | { |
320 | Standard_OutOfRange::Raise ("BAD VERTEX index"); |
7fd59977 |
321 | } |
322 | |
871fa103 |
323 | if (myVNor != 0) |
324 | { |
325 | const Graphic3d_Vec3& aVec = *reinterpret_cast<const Graphic3d_Vec3* >(myAttribs->value (theIndex - 1) + size_t(myVNor)); |
326 | theNX = Standard_Real(aVec.x()); |
327 | theNY = Standard_Real(aVec.y()); |
328 | theNZ = Standard_Real(aVec.z()); |
7fd59977 |
329 | } |
330 | } |
331 | |
871fa103 |
332 | inline void Graphic3d_ArrayOfPrimitives::VertexTexel (const Standard_Integer theIndex, |
333 | Standard_Real& theTX, |
334 | Standard_Real& theTY) const |
b8ddfc2f |
335 | { |
871fa103 |
336 | theTX = theTY = 0.0; |
337 | if (myAttribs.IsNull()) |
338 | { |
339 | return; |
7fd59977 |
340 | } |
341 | |
871fa103 |
342 | if (theIndex < 1 |
343 | || theIndex > myAttribs->NbElements) |
344 | { |
345 | Standard_OutOfRange::Raise ("BAD VERTEX index"); |
7fd59977 |
346 | } |
7fd59977 |
347 | |
871fa103 |
348 | if (myVTex != 0) |
349 | { |
350 | const Graphic3d_Vec2& aVec = *reinterpret_cast<const Graphic3d_Vec2* >(myAttribs->value (theIndex - 1) + size_t(myVTex)); |
351 | theTX = Standard_Real(aVec.x()); |
352 | theTY = Standard_Real(aVec.y()); |
353 | } |
7fd59977 |
354 | } |
355 | |
871fa103 |
356 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::EdgeNumber() const |
b8ddfc2f |
357 | { |
871fa103 |
358 | return !myIndices.IsNull() ? myIndices->NbElements : -1; |
7fd59977 |
359 | } |
360 | |
871fa103 |
361 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::Edge (const Standard_Integer theIndex) const |
b8ddfc2f |
362 | { |
871fa103 |
363 | if (myIndices.IsNull() |
364 | || theIndex <= 0 |
365 | || theIndex > myIndices->NbElements) |
366 | { |
367 | Standard_OutOfRange::Raise ("BAD EDGE index"); |
7fd59977 |
368 | } |
871fa103 |
369 | return Standard_Integer(myIndices->Index (theIndex - 1) + 1); |
7fd59977 |
370 | } |
371 | |
b8ddfc2f |
372 | inline Standard_Boolean Graphic3d_ArrayOfPrimitives::HasBoundColors() const |
373 | { |
871fa103 |
374 | return !myBounds.IsNull() && myBounds->Colors != NULL; |
7fd59977 |
375 | } |
376 | |
b8ddfc2f |
377 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::BoundNumber() const |
378 | { |
871fa103 |
379 | return !myBounds.IsNull() ? myBounds->NbBounds : -1; |
7fd59977 |
380 | } |
381 | |
871fa103 |
382 | inline Standard_Integer Graphic3d_ArrayOfPrimitives::Bound (const Standard_Integer theIndex) const |
b8ddfc2f |
383 | { |
871fa103 |
384 | if (myBounds.IsNull() |
385 | || theIndex <= 0 |
386 | || theIndex > myBounds->NbBounds) |
387 | { |
388 | Standard_OutOfRange::Raise ("BAD BOUND index"); |
7fd59977 |
389 | } |
871fa103 |
390 | return myBounds->Bounds[theIndex - 1]; |
7fd59977 |
391 | } |
392 | |
871fa103 |
393 | inline void Graphic3d_ArrayOfPrimitives::BoundColor (const Standard_Integer theIndex, |
394 | Standard_Real& theR, |
395 | Standard_Real& theG, |
396 | Standard_Real& theB) const |
b8ddfc2f |
397 | { |
871fa103 |
398 | if (myBounds.IsNull() |
399 | || myBounds->Colors == NULL |
400 | || theIndex <= 0 |
401 | || theIndex > myBounds->NbBounds) |
402 | { |
7fd59977 |
403 | Standard_OutOfRange::Raise(" BAD BOUND index"); |
404 | } |
871fa103 |
405 | |
406 | const Graphic3d_Vec4& aVec = myBounds->Colors[theIndex - 1]; |
407 | theR = Standard_Real(aVec.r()); |
408 | theG = Standard_Real(aVec.g()); |
409 | theB = Standard_Real(aVec.b()); |
7fd59977 |
410 | } |