File indexing completed on 2025-01-18 10:03:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _Graphic3d_ArrayOfPrimitives_HeaderFile
0016 #define _Graphic3d_ArrayOfPrimitives_HeaderFile
0017
0018 #include <Graphic3d_BoundBuffer.hxx>
0019 #include <Graphic3d_ArrayFlags.hxx>
0020 #include <Graphic3d_Buffer.hxx>
0021 #include <Graphic3d_IndexBuffer.hxx>
0022 #include <Graphic3d_TypeOfPrimitiveArray.hxx>
0023 #include <gp_Dir.hxx>
0024 #include <gp_Pnt.hxx>
0025 #include <Standard_OutOfRange.hxx>
0026 #include <Standard_TypeMismatch.hxx>
0027 #include <Quantity_Color.hxx>
0028
0029 class Graphic3d_ArrayOfPrimitives;
0030 DEFINE_STANDARD_HANDLE(Graphic3d_ArrayOfPrimitives, Standard_Transient)
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 class Graphic3d_ArrayOfPrimitives : public Standard_Transient
0064 {
0065 DEFINE_STANDARD_RTTIEXT(Graphic3d_ArrayOfPrimitives, Standard_Transient)
0066 public:
0067
0068
0069 static Handle(Graphic3d_ArrayOfPrimitives) CreateArray (Graphic3d_TypeOfPrimitiveArray theType,
0070 Standard_Integer theMaxVertexs,
0071 Standard_Integer theMaxEdges,
0072 Graphic3d_ArrayFlags theArrayFlags)
0073 {
0074 return CreateArray (theType, theMaxVertexs, 0, theMaxEdges, theArrayFlags);
0075 }
0076
0077
0078 static Standard_EXPORT Handle(Graphic3d_ArrayOfPrimitives) CreateArray (Graphic3d_TypeOfPrimitiveArray theType,
0079 Standard_Integer theMaxVertexs,
0080 Standard_Integer theMaxBounds,
0081 Standard_Integer theMaxEdges,
0082 Graphic3d_ArrayFlags theArrayFlags);
0083 public:
0084
0085
0086 Standard_EXPORT virtual ~Graphic3d_ArrayOfPrimitives();
0087
0088
0089 const Handle(Graphic3d_Buffer)& Attributes() const { return myAttribs; }
0090
0091
0092 Graphic3d_TypeOfPrimitiveArray Type() const { return myType; }
0093
0094
0095 Standard_EXPORT Standard_CString StringType() const;
0096
0097
0098 Standard_Boolean HasVertexNormals() const { return myNormData != NULL; }
0099
0100
0101 Standard_Boolean HasVertexColors() const { return myColData != NULL; }
0102
0103
0104 Standard_Boolean HasVertexTexels() const { return myTexData != NULL; }
0105
0106
0107 Standard_Integer VertexNumber() const { return myAttribs->NbElements; }
0108
0109
0110 Standard_Integer VertexNumberAllocated() const { return myAttribs->NbMaxElements(); }
0111
0112
0113 Standard_EXPORT Standard_Integer ItemNumber() const;
0114
0115
0116 Standard_EXPORT Standard_Boolean IsValid();
0117
0118
0119
0120 Standard_Integer AddVertex (const gp_Pnt& theVertex) { return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z()); }
0121
0122
0123
0124 Standard_Integer AddVertex (const Graphic3d_Vec3& theVertex) { return AddVertex (theVertex.x(), theVertex.y(), theVertex.z()); }
0125
0126
0127
0128 Standard_Integer AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ)
0129 {
0130 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ));
0131 }
0132
0133
0134
0135 Standard_Integer AddVertex (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ)
0136 {
0137 const Standard_Integer anIndex = myAttribs->NbElements + 1;
0138 SetVertice (anIndex, theX, theY, theZ);
0139 return anIndex;
0140 }
0141
0142
0143
0144
0145 Standard_Integer AddVertex (const gp_Pnt& theVertex, const Quantity_Color& theColor)
0146 {
0147 const Standard_Integer anIndex = AddVertex (theVertex);
0148 SetVertexColor (anIndex, theColor.Red(), theColor.Green(), theColor.Blue());
0149 return anIndex;
0150 }
0151
0152
0153
0154
0155
0156
0157
0158 Standard_Integer AddVertex (const gp_Pnt& theVertex, const Standard_Integer theColor32)
0159 {
0160 const Standard_Integer anIndex = AddVertex (theVertex);
0161 SetVertexColor (anIndex, theColor32);
0162 return anIndex;
0163 }
0164
0165
0166
0167
0168 Standard_Integer AddVertex (const gp_Pnt& theVertex,
0169 const Graphic3d_Vec4ub& theColor)
0170 {
0171 const Standard_Integer anIndex = AddVertex (theVertex);
0172 SetVertexColor (anIndex, theColor);
0173 return anIndex;
0174 }
0175
0176
0177
0178
0179 Standard_Integer AddVertex (const gp_Pnt& theVertex, const gp_Dir& theNormal)
0180 {
0181 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
0182 theNormal.X(), theNormal.Y(), theNormal.Z());
0183 }
0184
0185
0186
0187
0188 Standard_Integer AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
0189 const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ)
0190 {
0191 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
0192 Standard_ShortReal (theNX), Standard_ShortReal (theNY), Standard_ShortReal (theNZ));
0193 }
0194
0195
0196
0197
0198 Standard_Integer AddVertex (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ,
0199 const Standard_ShortReal theNX, const Standard_ShortReal theNY, const Standard_ShortReal theNZ)
0200 {
0201 const Standard_Integer anIndex = myAttribs->NbElements + 1;
0202 SetVertice (anIndex, theX, theY, theZ);
0203 SetVertexNormal (anIndex, theNX, theNY, theNZ);
0204 return anIndex;
0205 }
0206
0207
0208
0209
0210
0211 Standard_Integer AddVertex (const gp_Pnt& theVertex, const gp_Dir& theNormal, const Quantity_Color& theColor)
0212 {
0213 const Standard_Integer anIndex = AddVertex (theVertex, theNormal);
0214 SetVertexColor (anIndex, theColor.Red(), theColor.Green(), theColor.Blue());
0215 return anIndex;
0216 }
0217
0218
0219
0220
0221
0222
0223
0224
0225 Standard_Integer AddVertex (const gp_Pnt& theVertex, const gp_Dir& theNormal, const Standard_Integer theColor32)
0226 {
0227 const Standard_Integer anIndex = AddVertex (theVertex, theNormal);
0228 SetVertexColor (anIndex, theColor32);
0229 return anIndex;
0230 }
0231
0232
0233
0234
0235 Standard_Integer AddVertex (const gp_Pnt& theVertex, const gp_Pnt2d& theTexel)
0236 {
0237 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
0238 theTexel.X(), theTexel.Y());
0239 }
0240
0241
0242
0243
0244 Standard_Integer AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
0245 const Standard_Real theTX, const Standard_Real theTY)
0246 {
0247 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
0248 Standard_ShortReal (theTX), Standard_ShortReal (theTY));
0249 }
0250
0251
0252
0253
0254 Standard_Integer AddVertex (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ,
0255 const Standard_ShortReal theTX, const Standard_ShortReal theTY)
0256 {
0257 const Standard_Integer anIndex = myAttribs->NbElements + 1;
0258 SetVertice (anIndex, theX, theY, theZ);
0259 SetVertexTexel (anIndex, theTX, theTY);
0260 return anIndex;
0261 }
0262
0263
0264
0265
0266
0267 Standard_Integer AddVertex (const gp_Pnt& theVertex, const gp_Dir& theNormal, const gp_Pnt2d& theTexel)
0268 {
0269 return AddVertex (theVertex.X(), theVertex.Y(), theVertex.Z(),
0270 theNormal.X(), theNormal.Y(), theNormal.Z(),
0271 theTexel.X(), theTexel.Y());
0272 }
0273
0274
0275
0276
0277
0278 Standard_Integer AddVertex (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ,
0279 const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ,
0280 const Standard_Real theTX, const Standard_Real theTY)
0281 {
0282 return AddVertex (RealToShortReal (theX), RealToShortReal (theY), RealToShortReal (theZ),
0283 Standard_ShortReal (theNX), Standard_ShortReal (theNY), Standard_ShortReal (theNZ),
0284 Standard_ShortReal (theTX), Standard_ShortReal (theTY));
0285 }
0286
0287
0288
0289
0290
0291 Standard_Integer AddVertex (const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ,
0292 const Standard_ShortReal theNX, const Standard_ShortReal theNY, const Standard_ShortReal theNZ,
0293 const Standard_ShortReal theTX, const Standard_ShortReal theTY)
0294 {
0295 const Standard_Integer anIndex = myAttribs->NbElements + 1;
0296 SetVertice (anIndex, theX, theY, theZ);
0297 SetVertexNormal(anIndex, theNX, theNY, theNZ);
0298 SetVertexTexel (anIndex, theTX, theTY);
0299 return anIndex;
0300 }
0301
0302
0303
0304
0305 void SetVertice (const Standard_Integer theIndex, const gp_Pnt& theVertex)
0306 {
0307 SetVertice (theIndex, Standard_ShortReal (theVertex.X()), Standard_ShortReal (theVertex.Y()), Standard_ShortReal (theVertex.Z()));
0308 }
0309
0310
0311
0312
0313
0314
0315 void SetVertice (const Standard_Integer theIndex, const Standard_ShortReal theX, const Standard_ShortReal theY, const Standard_ShortReal theZ)
0316 {
0317 Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
0318 Graphic3d_Vec3& aVec = *reinterpret_cast<Graphic3d_Vec3*> (myAttribs->ChangeData() + myPosStride * ((Standard_Size)theIndex - 1));
0319 aVec.x() = theX;
0320 aVec.y() = theY;
0321 aVec.z() = theZ;
0322 if (myAttribs->NbElements < theIndex)
0323 {
0324 myAttribs->NbElements = theIndex;
0325 }
0326 }
0327
0328
0329
0330
0331 void SetVertexColor (const Standard_Integer theIndex, const Quantity_Color& theColor)
0332 {
0333 SetVertexColor (theIndex, theColor.Red(), theColor.Green(), theColor.Blue());
0334 }
0335
0336
0337
0338
0339
0340
0341 void SetVertexColor (const Standard_Integer theIndex, const Standard_Real theR, const Standard_Real theG, const Standard_Real theB)
0342 {
0343 Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
0344 if (myColData != NULL)
0345 {
0346 Graphic3d_Vec4ub* aColorPtr = reinterpret_cast<Graphic3d_Vec4ub* >(myColData + myColStride * ((Standard_Size)theIndex - 1));
0347 aColorPtr->SetValues (Standard_Byte(theR * 255.0),
0348 Standard_Byte(theG * 255.0),
0349 Standard_Byte(theB * 255.0), 255);
0350 }
0351 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
0352 }
0353
0354
0355
0356
0357 void SetVertexColor (const Standard_Integer theIndex,
0358 const Graphic3d_Vec4ub& theColor)
0359 {
0360 Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
0361 if (myColData != NULL)
0362 {
0363 Graphic3d_Vec4ub* aColorPtr = reinterpret_cast<Graphic3d_Vec4ub* >(myColData + myColStride * ((Standard_Size)theIndex - 1));
0364 (*aColorPtr) = theColor;
0365 }
0366 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
0367 }
0368
0369
0370
0371
0372
0373
0374
0375 void SetVertexColor (const Standard_Integer theIndex, const Standard_Integer theColor32)
0376 {
0377 Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
0378 if (myColData != NULL)
0379 {
0380 *reinterpret_cast<Standard_Integer* >(myColData + myColStride * ((Standard_Size)theIndex - 1)) = theColor32;
0381 }
0382 }
0383
0384
0385
0386
0387 void SetVertexNormal (const Standard_Integer theIndex, const gp_Dir& theNormal)
0388 {
0389 SetVertexNormal (theIndex, theNormal.X(), theNormal.Y(), theNormal.Z());
0390 }
0391
0392
0393
0394
0395
0396
0397 void SetVertexNormal (const Standard_Integer theIndex, const Standard_Real theNX, const Standard_Real theNY, const Standard_Real theNZ)
0398 {
0399 Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
0400 if (myNormData != NULL)
0401 {
0402 Graphic3d_Vec3& aVec = *reinterpret_cast<Graphic3d_Vec3* >(myNormData + myNormStride * ((Standard_Size)theIndex - 1));
0403 aVec.x() = Standard_ShortReal (theNX);
0404 aVec.y() = Standard_ShortReal (theNY);
0405 aVec.z() = Standard_ShortReal (theNZ);
0406 }
0407 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
0408 }
0409
0410
0411
0412
0413 void SetVertexTexel (const Standard_Integer theIndex, const gp_Pnt2d& theTexel)
0414 {
0415 SetVertexTexel (theIndex, theTexel.X(), theTexel.Y());
0416 }
0417
0418
0419
0420
0421
0422 void SetVertexTexel (const Standard_Integer theIndex, const Standard_Real theTX, const Standard_Real theTY)
0423 {
0424 Standard_OutOfRange_Raise_if (theIndex < 1 || theIndex > myAttribs->NbMaxElements(), "BAD VERTEX index");
0425 if (myTexData != NULL)
0426 {
0427 Graphic3d_Vec2& aVec = *reinterpret_cast<Graphic3d_Vec2* >(myTexData + myTexStride * ((Standard_Size)theIndex - 1));
0428 aVec.x() = Standard_ShortReal (theTX);
0429 aVec.y() = Standard_ShortReal (theTY);
0430 }
0431 myAttribs->NbElements = Max (theIndex, myAttribs->NbElements);
0432 }
0433
0434
0435
0436
0437 gp_Pnt Vertice (const Standard_Integer theRank) const
0438 {
0439 Standard_Real anXYZ[3];
0440 Vertice (theRank, anXYZ[0], anXYZ[1], anXYZ[2]);
0441 return gp_Pnt (anXYZ[0], anXYZ[1], anXYZ[2]);
0442 }
0443
0444
0445
0446
0447
0448
0449 void Vertice (const Standard_Integer theRank, Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const
0450 {
0451 theX = theY = theZ = 0.0;
0452 Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index");
0453 const Graphic3d_Vec3& aVec = *reinterpret_cast<const Graphic3d_Vec3*> (myAttribs->Data() + myPosStride * ((Standard_Size)theRank - 1));
0454 theX = Standard_Real(aVec.x());
0455 theY = Standard_Real(aVec.y());
0456 theZ = Standard_Real(aVec.z());
0457 }
0458
0459
0460
0461
0462 Quantity_Color VertexColor (const Standard_Integer theRank) const
0463 {
0464 Standard_Real anRGB[3];
0465 VertexColor (theRank, anRGB[0], anRGB[1], anRGB[2]);
0466 return Quantity_Color (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
0467 }
0468
0469
0470
0471
0472 void VertexColor (const Standard_Integer theIndex,
0473 Graphic3d_Vec4ub& theColor) const
0474 {
0475 Standard_OutOfRange_Raise_if (myColData == NULL || theIndex < 1 || theIndex > myAttribs->NbElements, "BAD VERTEX index");
0476 theColor = *reinterpret_cast<const Graphic3d_Vec4ub* >(myColData + myColStride * ((Standard_Size)theIndex - 1));
0477 }
0478
0479
0480
0481
0482
0483
0484 void VertexColor (const Standard_Integer theRank, Standard_Real& theR, Standard_Real& theG, Standard_Real& theB) const
0485 {
0486 theR = theG = theB = 0.0;
0487 Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index");
0488 if (myColData == NULL)
0489 {
0490 return;
0491 }
0492 const Graphic3d_Vec4ub& aColor = *reinterpret_cast<const Graphic3d_Vec4ub* >(myColData + myColStride * ((Standard_Size)theRank - 1));
0493 theR = Standard_Real(aColor.r()) / 255.0;
0494 theG = Standard_Real(aColor.g()) / 255.0;
0495 theB = Standard_Real(aColor.b()) / 255.0;
0496 }
0497
0498
0499
0500
0501 void VertexColor (const Standard_Integer theRank, Standard_Integer& theColor) const
0502 {
0503 Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index");
0504 if (myColData != NULL)
0505 {
0506 theColor = *reinterpret_cast<const Standard_Integer* >(myColData + myColStride * ((Standard_Size)theRank - 1));
0507 }
0508 }
0509
0510
0511
0512
0513 gp_Dir VertexNormal (const Standard_Integer theRank) const
0514 {
0515 Standard_Real anXYZ[3];
0516 VertexNormal (theRank, anXYZ[0], anXYZ[1], anXYZ[2]);
0517 return gp_Dir (anXYZ[0], anXYZ[1], anXYZ[2]);
0518 }
0519
0520
0521
0522
0523
0524
0525 void VertexNormal (const Standard_Integer theRank, Standard_Real& theNX, Standard_Real& theNY, Standard_Real& theNZ) const
0526 {
0527 theNX = theNY = theNZ = 0.0;
0528 Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index");
0529 if (myNormData != NULL)
0530 {
0531 const Graphic3d_Vec3& aVec = *reinterpret_cast<const Graphic3d_Vec3* >(myNormData + myNormStride * ((Standard_Size)theRank - 1));
0532 theNX = Standard_Real(aVec.x());
0533 theNY = Standard_Real(aVec.y());
0534 theNZ = Standard_Real(aVec.z());
0535 }
0536 }
0537
0538
0539
0540
0541 gp_Pnt2d VertexTexel (const Standard_Integer theRank) const
0542 {
0543 Standard_Real anXY[2];
0544 VertexTexel (theRank, anXY[0], anXY[1]);
0545 return gp_Pnt2d (anXY[0], anXY[1]);
0546 }
0547
0548
0549
0550
0551
0552 void VertexTexel (const Standard_Integer theRank, Standard_Real& theTX, Standard_Real& theTY) const
0553 {
0554 theTX = theTY = 0.0;
0555 Standard_OutOfRange_Raise_if (theRank < 1 || theRank > myAttribs->NbElements, "BAD VERTEX index");
0556 if (myTexData != NULL)
0557 {
0558 const Graphic3d_Vec2& aVec = *reinterpret_cast<const Graphic3d_Vec2* >(myTexData + myTexStride * ((Standard_Size)theRank - 1));
0559 theTX = Standard_Real(aVec.x());
0560 theTY = Standard_Real(aVec.y());
0561 }
0562 }
0563
0564 public:
0565
0566
0567 const Handle(Graphic3d_IndexBuffer)& Indices() const { return myIndices; }
0568
0569
0570 Standard_Integer EdgeNumber() const { return !myIndices.IsNull() ? myIndices->NbElements : -1; }
0571
0572
0573 Standard_Integer EdgeNumberAllocated() const { return !myIndices.IsNull() ? myIndices->NbMaxElements() : 0; }
0574
0575
0576 Standard_Integer Edge (const Standard_Integer theRank) const
0577 {
0578 Standard_OutOfRange_Raise_if (myIndices.IsNull() || theRank < 1 || theRank > myIndices->NbElements, "BAD EDGE index");
0579 return Standard_Integer(myIndices->Index (theRank - 1) + 1);
0580 }
0581
0582
0583
0584 Standard_EXPORT Standard_Integer AddEdge (const Standard_Integer theVertexIndex);
0585
0586
0587
0588 Standard_Integer AddEdges (Standard_Integer theVertexIndex1,
0589 Standard_Integer theVertexIndex2)
0590 {
0591 AddEdge (theVertexIndex1);
0592 return AddEdge (theVertexIndex2);
0593 }
0594
0595
0596
0597
0598 Standard_Integer AddSegmentEdges (Standard_Integer theVertexIndex1,
0599 Standard_Integer theVertexIndex2)
0600 {
0601 Standard_TypeMismatch_Raise_if (myType != Graphic3d_TOPA_SEGMENTS, "Not array of segments");
0602 return AddEdges (theVertexIndex1, theVertexIndex2);
0603 }
0604
0605
0606
0607 Standard_Integer AddEdges (Standard_Integer theVertexIndex1,
0608 Standard_Integer theVertexIndex2,
0609 Standard_Integer theVertexIndex3)
0610 {
0611 AddEdge (theVertexIndex1);
0612 AddEdge (theVertexIndex2);
0613 return AddEdge (theVertexIndex3);
0614 }
0615
0616
0617
0618
0619 Standard_Integer AddTriangleEdges (Standard_Integer theVertexIndex1,
0620 Standard_Integer theVertexIndex2,
0621 Standard_Integer theVertexIndex3)
0622 {
0623 Standard_TypeMismatch_Raise_if (myType != Graphic3d_TOPA_TRIANGLES, "Not array of triangles");
0624 return AddEdges (theVertexIndex1, theVertexIndex2, theVertexIndex3);
0625 }
0626
0627
0628
0629
0630 Standard_Integer AddTriangleEdges (const Graphic3d_Vec3i& theIndexes)
0631 {
0632 Standard_TypeMismatch_Raise_if (myType != Graphic3d_TOPA_TRIANGLES, "Not array of triangles");
0633 return AddEdges (theIndexes[0], theIndexes[1], theIndexes[2]);
0634 }
0635
0636
0637
0638
0639 Standard_Integer AddTriangleEdges (const Graphic3d_Vec4i& theIndexes)
0640 {
0641 Standard_TypeMismatch_Raise_if (myType != Graphic3d_TOPA_TRIANGLES, "Not array of triangles");
0642 return AddEdges (theIndexes[0], theIndexes[1], theIndexes[2]);
0643 }
0644
0645
0646
0647 Standard_Integer AddEdges (Standard_Integer theVertexIndex1,
0648 Standard_Integer theVertexIndex2,
0649 Standard_Integer theVertexIndex3,
0650 Standard_Integer theVertexIndex4)
0651 {
0652 AddEdge (theVertexIndex1);
0653 AddEdge (theVertexIndex2);
0654 AddEdge (theVertexIndex3);
0655 return AddEdge (theVertexIndex4);
0656 }
0657
0658
0659
0660
0661 Standard_Integer AddQuadEdges (Standard_Integer theVertexIndex1,
0662 Standard_Integer theVertexIndex2,
0663 Standard_Integer theVertexIndex3,
0664 Standard_Integer theVertexIndex4)
0665 {
0666 Standard_TypeMismatch_Raise_if (myType != Graphic3d_TOPA_QUADRANGLES, "Not array of quads");
0667 return AddEdges (theVertexIndex1, theVertexIndex2, theVertexIndex3, theVertexIndex4);
0668 }
0669
0670
0671
0672
0673 Standard_Integer AddQuadTriangleEdges (Standard_Integer theVertexIndex1,
0674 Standard_Integer theVertexIndex2,
0675 Standard_Integer theVertexIndex3,
0676 Standard_Integer theVertexIndex4)
0677 {
0678 AddTriangleEdges (theVertexIndex3, theVertexIndex1, theVertexIndex2);
0679 return AddTriangleEdges (theVertexIndex1, theVertexIndex3, theVertexIndex4);
0680 }
0681
0682
0683
0684
0685 Standard_Integer AddQuadTriangleEdges (const Graphic3d_Vec4i& theIndexes)
0686 {
0687 return AddQuadTriangleEdges (theIndexes[0], theIndexes[1], theIndexes[2], theIndexes[3]);
0688 }
0689
0690
0691
0692
0693
0694
0695 Standard_EXPORT void AddTriangleStripEdges (Standard_Integer theVertexLower,
0696 Standard_Integer theVertexUpper);
0697
0698
0699
0700
0701
0702
0703
0704 Standard_EXPORT void AddTriangleFanEdges (Standard_Integer theVertexLower,
0705 Standard_Integer theVertexUpper,
0706 Standard_Boolean theToClose);
0707
0708
0709
0710
0711
0712
0713
0714 Standard_EXPORT void AddPolylineEdges (Standard_Integer theVertexLower,
0715 Standard_Integer theVertexUpper,
0716 Standard_Boolean theToClose);
0717
0718 public:
0719
0720
0721 const Handle(Graphic3d_BoundBuffer)& Bounds() const { return myBounds; }
0722
0723
0724 Standard_Boolean HasBoundColors() const { return !myBounds.IsNull() && myBounds->Colors != NULL; }
0725
0726
0727 Standard_Integer BoundNumber() const { return !myBounds.IsNull() ? myBounds->NbBounds : -1; }
0728
0729
0730 Standard_Integer BoundNumberAllocated() const { return !myBounds.IsNull() ? myBounds->NbMaxBounds : 0; }
0731
0732
0733 Standard_Integer Bound (const Standard_Integer theRank) const
0734 {
0735 Standard_OutOfRange_Raise_if (myBounds.IsNull() || theRank < 1 || theRank > myBounds->NbBounds, "BAD BOUND index");
0736 return myBounds->Bounds[theRank - 1];
0737 }
0738
0739
0740 Quantity_Color BoundColor (const Standard_Integer theRank) const
0741 {
0742 Standard_Real anRGB[3] = {0.0, 0.0, 0.0};
0743 BoundColor (theRank, anRGB[0], anRGB[1], anRGB[2]);
0744 return Quantity_Color (anRGB[0], anRGB[1], anRGB[2], Quantity_TOC_RGB);
0745 }
0746
0747
0748 void BoundColor (const Standard_Integer theRank, Standard_Real& theR, Standard_Real& theG, Standard_Real& theB) const
0749 {
0750 Standard_OutOfRange_Raise_if (myBounds.IsNull() || myBounds->Colors == NULL || theRank < 1 || theRank > myBounds->NbBounds, "BAD BOUND index");
0751 const Graphic3d_Vec4& aVec = myBounds->Colors[theRank - 1];
0752 theR = Standard_Real(aVec.r());
0753 theG = Standard_Real(aVec.g());
0754 theB = Standard_Real(aVec.b());
0755 }
0756
0757
0758
0759 Standard_EXPORT Standard_Integer AddBound (const Standard_Integer theEdgeNumber);
0760
0761
0762
0763
0764 Standard_Integer AddBound (const Standard_Integer theEdgeNumber, const Quantity_Color& theBColor)
0765 {
0766 return AddBound (theEdgeNumber, theBColor.Red(), theBColor.Green(), theBColor.Blue());
0767 }
0768
0769
0770
0771
0772 Standard_EXPORT Standard_Integer AddBound (const Standard_Integer theEdgeNumber, const Standard_Real theR, const Standard_Real theG, const Standard_Real theB);
0773
0774
0775 void SetBoundColor (const Standard_Integer theIndex, const Quantity_Color& theColor)
0776 {
0777 SetBoundColor (theIndex, theColor.Red(), theColor.Green(), theColor.Blue());
0778 }
0779
0780
0781 void SetBoundColor (const Standard_Integer theIndex, const Standard_Real theR, const Standard_Real theG, const Standard_Real theB)
0782 {
0783 if (myBounds.IsNull())
0784 {
0785 return;
0786 }
0787 Standard_OutOfRange_Raise_if (myBounds.IsNull() || myBounds->Colors == NULL || theIndex < 1 || theIndex > myBounds->NbMaxBounds, "BAD BOUND index");
0788 Graphic3d_Vec4& aVec = myBounds->Colors[theIndex - 1];
0789 aVec.r() = Standard_ShortReal (theR);
0790 aVec.g() = Standard_ShortReal (theG);
0791 aVec.b() = Standard_ShortReal (theB);
0792 aVec.a() = 1.0f;
0793 myBounds->NbBounds = Max (theIndex, myBounds->NbBounds);
0794 }
0795
0796 protected:
0797
0798
0799
0800
0801
0802
0803
0804 Graphic3d_ArrayOfPrimitives (Graphic3d_TypeOfPrimitiveArray theType,
0805 Standard_Integer theMaxVertexs,
0806 Standard_Integer theMaxBounds,
0807 Standard_Integer theMaxEdges,
0808 Graphic3d_ArrayFlags theArrayFlags)
0809 : myNormData (NULL), myTexData (NULL), myColData (NULL), myPosStride (0), myNormStride (0), myTexStride (0), myColStride (0),
0810 myType (Graphic3d_TOPA_UNDEFINED)
0811 {
0812 init (theType, theMaxVertexs, theMaxBounds, theMaxEdges, theArrayFlags);
0813 }
0814
0815
0816 Standard_EXPORT void init (Graphic3d_TypeOfPrimitiveArray theType,
0817 Standard_Integer theMaxVertexs,
0818 Standard_Integer theMaxBounds,
0819 Standard_Integer theMaxEdges,
0820 Graphic3d_ArrayFlags theArrayFlags);
0821
0822 private:
0823
0824 Handle(Graphic3d_IndexBuffer) myIndices;
0825 Handle(Graphic3d_Buffer) myAttribs;
0826 Handle(Graphic3d_BoundBuffer) myBounds;
0827 Standard_Byte* myNormData;
0828 Standard_Byte* myTexData;
0829 Standard_Byte* myColData;
0830 Standard_Size myPosStride;
0831 Standard_Size myNormStride;
0832 Standard_Size myTexStride;
0833 Standard_Size myColStride;
0834 Graphic3d_TypeOfPrimitiveArray myType;
0835
0836 };
0837
0838 #endif