16
16
// along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
17
17
18
18
// ---------------------------------------------------------------------------
19
- #include " Tesselator .h"
19
+ #include " ShapeTesselator .h"
20
20
#include < sstream>
21
21
#include < algorithm>
22
22
#include < cmath>
40
40
#include < TopoDS_Face.hxx>
41
41
42
42
// ---------------------------------------------------------------------------
43
- Tesselator::Tesselator (TopoDS_Shape aShape):
43
+ ShapeTesselator::ShapeTesselator (TopoDS_Shape aShape):
44
44
myShape(aShape),
45
45
locVertexcoord(NULL ),
46
46
locNormalcoord(NULL ),
@@ -50,13 +50,13 @@ Tesselator::Tesselator(TopoDS_Shape aShape):
50
50
ComputeDefaultDeviation ();
51
51
}
52
52
53
- void Tesselator ::Compute (bool compute_edges, float mesh_quality, bool parallel)
53
+ void ShapeTesselator ::Compute (bool compute_edges, float mesh_quality, bool parallel)
54
54
{
55
55
Tesselate (compute_edges, mesh_quality, parallel);
56
56
computed=true ;
57
57
}
58
58
59
- Tesselator ::~Tesselator ()
59
+ ShapeTesselator ::~ShapeTesselator ()
60
60
{
61
61
if (locVertexcoord)
62
62
delete [] locVertexcoord;
@@ -81,14 +81,14 @@ Tesselator::~Tesselator()
81
81
}
82
82
83
83
// ---------------------------------------------------------------------------
84
- void Tesselator ::SetDeviation (Standard_Real aDeviation)
84
+ void ShapeTesselator ::SetDeviation (Standard_Real aDeviation)
85
85
{
86
86
myDeviation = aDeviation;
87
87
}
88
88
89
89
90
90
// ---------------------------------------------------------------------------
91
- void Tesselator ::Tesselate (bool compute_edges, float mesh_quality, bool parallel)
91
+ void ShapeTesselator ::Tesselate (bool compute_edges, float mesh_quality, bool parallel)
92
92
{
93
93
TopExp_Explorer ExpFace;
94
94
// clean shape to remove any previous tringulation
@@ -184,7 +184,7 @@ void Tesselator::Tesselate(bool compute_edges, float mesh_quality, bool parallel
184
184
185
185
186
186
// ---------------------------INTERFACE---------------------------------------
187
- void Tesselator ::ComputeDefaultDeviation ()
187
+ void ShapeTesselator ::ComputeDefaultDeviation ()
188
188
{
189
189
// This method automatically computes precision from the bounding box of the shape
190
190
Bnd_Box aBox;
@@ -198,7 +198,7 @@ void Tesselator::ComputeDefaultDeviation()
198
198
myDeviation = adeviation;
199
199
}
200
200
201
- void Tesselator ::ComputeEdges ()
201
+ void ShapeTesselator ::ComputeEdges ()
202
202
{
203
203
TopLoc_Location aTrsf;
204
204
@@ -293,7 +293,7 @@ void Tesselator::ComputeEdges()
293
293
}
294
294
}
295
295
296
- void Tesselator ::EnsureMeshIsComputed ()
296
+ void ShapeTesselator ::EnsureMeshIsComputed ()
297
297
{
298
298
// this method ensures that the mesh is computed before returning any
299
299
// related data
@@ -318,36 +318,33 @@ std::string formatFloatNumber(float f)
318
318
return formatted_float.str ();
319
319
}
320
320
321
- std::vector<float > Tesselator ::GetVerticesPositionAsTuple ()
321
+ std::vector<float > ShapeTesselator ::GetVerticesPositionAsTuple ()
322
322
{
323
323
EnsureMeshIsComputed ();
324
324
// create the vector and allocate memory
325
325
std::vector<float > vertices_position;
326
326
vertices_position.reserve (tot_triangle_count);
327
327
// loop over tertices
328
- int pID = 0 ;
329
- int qID = 0 ;
330
- int rID = 0 ;
331
328
for (int i=0 ;i<tot_triangle_count;i++) {
332
- pID = locTriIndices[(i * 3 ) + 0 ] * 3 ;
329
+ int pID = locTriIndices[(i * 3 ) + 0 ] * 3 ;
333
330
vertices_position.push_back (locVertexcoord[pID]);
334
331
vertices_position.push_back (locVertexcoord[pID+1 ]);
335
332
vertices_position.push_back (locVertexcoord[pID+2 ]);
336
333
// Second vertex
337
- qID = locTriIndices[(i * 3 ) + 1 ] * 3 ;
334
+ int qID = locTriIndices[(i * 3 ) + 1 ] * 3 ;
338
335
vertices_position.push_back (locVertexcoord[qID]);
339
336
vertices_position.push_back (locVertexcoord[qID+1 ]);
340
337
vertices_position.push_back (locVertexcoord[qID+2 ]);
341
338
// Third vertex
342
- rID = locTriIndices[(i * 3 ) + 2 ] * 3 ;
339
+ int rID = locTriIndices[(i * 3 ) + 2 ] * 3 ;
343
340
vertices_position.push_back (locVertexcoord[rID]);
344
341
vertices_position.push_back (locVertexcoord[rID+1 ]);
345
342
vertices_position.push_back (locVertexcoord[rID+2 ]);
346
343
}
347
344
return vertices_position;
348
345
}
349
346
350
- std::vector<float > Tesselator ::GetNormalsAsTuple ()
347
+ std::vector<float > ShapeTesselator ::GetNormalsAsTuple ()
351
348
{
352
349
EnsureMeshIsComputed ();
353
350
// create the vector and allocate memory
@@ -373,7 +370,7 @@ std::vector<float> Tesselator::GetNormalsAsTuple()
373
370
return normals;
374
371
}
375
372
376
- std::string Tesselator ::ExportShapeToX3DIndexedFaceSet ()
373
+ std::string ShapeTesselator ::ExportShapeToX3DIndexedFaceSet ()
377
374
{
378
375
EnsureMeshIsComputed ();
379
376
std::stringstream str_ifs, str_vertices, str_normals;
@@ -427,7 +424,7 @@ std::string Tesselator::ExportShapeToX3DIndexedFaceSet()
427
424
return str_ifs.str ();
428
425
}
429
426
430
- void Tesselator ::ExportShapeToX3D (char * filename, int diffR, int diffG, int diffB)
427
+ void ShapeTesselator ::ExportShapeToX3D (char * filename, int diffR, int diffG, int diffB)
431
428
{
432
429
EnsureMeshIsComputed ();
433
430
std::ofstream X3Dfile;
@@ -448,7 +445,7 @@ void Tesselator::ExportShapeToX3D(char * filename, int diffR, int diffG, int dif
448
445
449
446
}
450
447
451
- std::string Tesselator ::ExportShapeToThreejsJSONString (char *shape_function_name)
448
+ std::string ShapeTesselator ::ExportShapeToThreejsJSONString (char *shape_function_name)
452
449
{
453
450
EnsureMeshIsComputed ();
454
451
// a method that export a shape to a JSON BufferGeometry object
@@ -531,55 +528,55 @@ std::string Tesselator::ExportShapeToThreejsJSONString(char *shape_function_name
531
528
}
532
529
533
530
// ---------------------------------------------------------------------------
534
- Standard_Real* Tesselator ::VerticesList ()
531
+ Standard_Real* ShapeTesselator ::VerticesList ()
535
532
{
536
533
EnsureMeshIsComputed ();
537
534
return locVertexcoord;
538
535
}
539
536
// ---------------------------------------------------------------------------
540
- Standard_Real* Tesselator ::NormalsList ()
537
+ Standard_Real* ShapeTesselator ::NormalsList ()
541
538
{
542
539
EnsureMeshIsComputed ();
543
540
return locNormalcoord;
544
541
}
545
542
// ---------------------------------------------------------------------------
546
- Standard_Integer Tesselator ::ObjGetInvalidTriangleCount ()
543
+ Standard_Integer ShapeTesselator ::ObjGetInvalidTriangleCount ()
547
544
{
548
545
EnsureMeshIsComputed ();
549
546
return tot_invalid_triangle_count;
550
547
}
551
548
// ---------------------------------------------------------------------------
552
- Standard_Integer Tesselator ::ObjGetTriangleCount ()
549
+ Standard_Integer ShapeTesselator ::ObjGetTriangleCount ()
553
550
{
554
551
EnsureMeshIsComputed ();
555
552
return tot_triangle_count;
556
553
}
557
554
// ---------------------------------------------------------------------------
558
- Standard_Integer Tesselator ::ObjGetVertexCount ()
555
+ Standard_Integer ShapeTesselator ::ObjGetVertexCount ()
559
556
{
560
557
EnsureMeshIsComputed ();
561
558
return tot_vertex_count;
562
559
}
563
560
// ---------------------------------------------------------------------------
564
- Standard_Integer Tesselator ::ObjGetNormalCount ()
561
+ Standard_Integer ShapeTesselator ::ObjGetNormalCount ()
565
562
{
566
563
EnsureMeshIsComputed ();
567
564
return tot_normal_count;
568
565
}
569
566
// ---------------------------------------------------------------------------
570
- Standard_Integer Tesselator ::ObjGetInvalidNormalCount ()
567
+ Standard_Integer ShapeTesselator ::ObjGetInvalidNormalCount ()
571
568
{
572
569
EnsureMeshIsComputed ();
573
570
return tot_invalid_normal_count;
574
571
}
575
572
// ---------------------------------------------------------------------------
576
- Standard_Integer Tesselator ::ObjGetEdgeCount ()
573
+ Standard_Integer ShapeTesselator ::ObjGetEdgeCount ()
577
574
{
578
575
EnsureMeshIsComputed ();
579
576
return edgelist.size ();
580
577
}
581
578
// ---------------------------------------------------------------------------
582
- Standard_Integer Tesselator ::ObjEdgeGetVertexCount (int iEdge)
579
+ Standard_Integer ShapeTesselator ::ObjEdgeGetVertexCount (int iEdge)
583
580
{
584
581
EnsureMeshIsComputed ();
585
582
aedge* edge = edgelist.at (iEdge);
@@ -589,31 +586,31 @@ Standard_Integer Tesselator::ObjEdgeGetVertexCount(int iEdge)
589
586
return edge->number_of_coords ;
590
587
}
591
588
// ---------------------------------------------------------------------------
592
- void Tesselator ::GetVertex (int ivert, float & x, float & y, float & z)
589
+ void ShapeTesselator ::GetVertex (int ivert, float & x, float & y, float & z)
593
590
{
594
591
EnsureMeshIsComputed ();
595
592
x = locVertexcoord[ivert*3 + 0 ];
596
593
y = locVertexcoord[ivert*3 + 1 ];
597
594
z = locVertexcoord[ivert*3 + 2 ];
598
595
}
599
596
// ---------------------------------------------------------------------------
600
- void Tesselator ::GetNormal (int ivert, float & x, float & y, float & z)
597
+ void ShapeTesselator ::GetNormal (int ivert, float & x, float & y, float & z)
601
598
{
602
599
EnsureMeshIsComputed ();
603
600
x = locNormalcoord[ivert*3 + 0 ];
604
601
y = locNormalcoord[ivert*3 + 1 ];
605
602
z = locNormalcoord[ivert*3 + 2 ];
606
603
}
607
604
// ---------------------------------------------------------------------------
608
- void Tesselator ::GetTriangleIndex (int triangleIdx, int &v1, int &v2, int &v3)
605
+ void ShapeTesselator ::GetTriangleIndex (int triangleIdx, int &v1, int &v2, int &v3)
609
606
{
610
607
EnsureMeshIsComputed ();
611
608
v1 = locTriIndices[3 *triangleIdx + 0 ];
612
609
v2 = locTriIndices[3 *triangleIdx + 1 ];
613
610
v3 = locTriIndices[3 *triangleIdx + 2 ];
614
611
}
615
612
// ---------------------------------------------------------------------------
616
- void Tesselator ::GetEdgeVertex (int iEdge, int ivert, float &x, float &y, float &z)
613
+ void ShapeTesselator ::GetEdgeVertex (int iEdge, int ivert, float &x, float &y, float &z)
617
614
{
618
615
EnsureMeshIsComputed ();
619
616
aedge* e = edgelist.at (iEdge);
@@ -626,7 +623,7 @@ void Tesselator::GetEdgeVertex(int iEdge, int ivert, float &x, float &y, float &
626
623
z = e->vertex_coord [3 *ivert + 2 ];
627
624
}
628
625
// ---------------------------------------------------------------------------
629
- void Tesselator ::ObjGetTriangle (int trianglenum, int *vertices, int *normals)
626
+ void ShapeTesselator ::ObjGetTriangle (int trianglenum, int *vertices, int *normals)
630
627
{
631
628
EnsureMeshIsComputed ();
632
629
int pID = locTriIndices[(trianglenum * 3 ) + 0 ] * 3 ;
@@ -644,7 +641,7 @@ void Tesselator::ObjGetTriangle(int trianglenum, int *vertices, int *normals)
644
641
// ---------------------------------------------------------------------------
645
642
// ---------------------------------HELPERS-----------------------------------
646
643
// ---------------------------------------------------------------------------
647
- void Tesselator ::JoinPrimitives ()
644
+ void ShapeTesselator ::JoinPrimitives ()
648
645
{
649
646
int obP = 0 ;
650
647
int obN = 0 ;
@@ -670,7 +667,7 @@ void Tesselator::JoinPrimitives()
670
667
tot_normal_count = tot_normal_count + myface->number_of_normals ;
671
668
tot_invalid_normal_count = tot_invalid_normal_count + myface->number_of_invalid_normals ;
672
669
673
- anIterator++ ;
670
+ ++anIterator ;
674
671
}
675
672
676
673
locTriIndices= new Standard_Integer[tot_triangle_count * 3 ];
0 commit comments