1616// along with pythonOCC. If not, see <http://www.gnu.org/licenses/>.
1717
1818// ---------------------------------------------------------------------------
19- #include " Tesselator .h"
19+ #include " ShapeTesselator .h"
2020#include < sstream>
2121#include < algorithm>
2222#include < cmath>
4040#include < TopoDS_Face.hxx>
4141
4242// ---------------------------------------------------------------------------
43- Tesselator::Tesselator (TopoDS_Shape aShape):
43+ ShapeTesselator::ShapeTesselator (TopoDS_Shape aShape):
4444 myShape(aShape),
4545 locVertexcoord(NULL ),
4646 locNormalcoord(NULL ),
@@ -50,13 +50,13 @@ Tesselator::Tesselator(TopoDS_Shape aShape):
5050 ComputeDefaultDeviation ();
5151}
5252
53- void Tesselator ::Compute (bool compute_edges, float mesh_quality, bool parallel)
53+ void ShapeTesselator ::Compute (bool compute_edges, float mesh_quality, bool parallel)
5454{
5555 Tesselate (compute_edges, mesh_quality, parallel);
5656 computed=true ;
5757}
5858
59- Tesselator ::~Tesselator ()
59+ ShapeTesselator ::~ShapeTesselator ()
6060{
6161 if (locVertexcoord)
6262 delete [] locVertexcoord;
@@ -81,14 +81,14 @@ Tesselator::~Tesselator()
8181}
8282
8383// ---------------------------------------------------------------------------
84- void Tesselator ::SetDeviation (Standard_Real aDeviation)
84+ void ShapeTesselator ::SetDeviation (Standard_Real aDeviation)
8585{
8686 myDeviation = aDeviation;
8787}
8888
8989
9090// ---------------------------------------------------------------------------
91- void Tesselator ::Tesselate (bool compute_edges, float mesh_quality, bool parallel)
91+ void ShapeTesselator ::Tesselate (bool compute_edges, float mesh_quality, bool parallel)
9292{
9393 TopExp_Explorer ExpFace;
9494 // clean shape to remove any previous tringulation
@@ -184,7 +184,7 @@ void Tesselator::Tesselate(bool compute_edges, float mesh_quality, bool parallel
184184
185185
186186// ---------------------------INTERFACE---------------------------------------
187- void Tesselator ::ComputeDefaultDeviation ()
187+ void ShapeTesselator ::ComputeDefaultDeviation ()
188188{
189189 // This method automatically computes precision from the bounding box of the shape
190190 Bnd_Box aBox;
@@ -198,7 +198,7 @@ void Tesselator::ComputeDefaultDeviation()
198198 myDeviation = adeviation;
199199}
200200
201- void Tesselator ::ComputeEdges ()
201+ void ShapeTesselator ::ComputeEdges ()
202202{
203203 TopLoc_Location aTrsf;
204204
@@ -293,7 +293,7 @@ void Tesselator::ComputeEdges()
293293 }
294294}
295295
296- void Tesselator ::EnsureMeshIsComputed ()
296+ void ShapeTesselator ::EnsureMeshIsComputed ()
297297{
298298 // this method ensures that the mesh is computed before returning any
299299 // related data
@@ -318,36 +318,33 @@ std::string formatFloatNumber(float f)
318318 return formatted_float.str ();
319319}
320320
321- std::vector<float > Tesselator ::GetVerticesPositionAsTuple ()
321+ std::vector<float > ShapeTesselator ::GetVerticesPositionAsTuple ()
322322{
323323 EnsureMeshIsComputed ();
324324 // create the vector and allocate memory
325325 std::vector<float > vertices_position;
326326 vertices_position.reserve (tot_triangle_count);
327327 // loop over tertices
328- int pID = 0 ;
329- int qID = 0 ;
330- int rID = 0 ;
331328 for (int i=0 ;i<tot_triangle_count;i++) {
332- pID = locTriIndices[(i * 3 ) + 0 ] * 3 ;
329+ int pID = locTriIndices[(i * 3 ) + 0 ] * 3 ;
333330 vertices_position.push_back (locVertexcoord[pID]);
334331 vertices_position.push_back (locVertexcoord[pID+1 ]);
335332 vertices_position.push_back (locVertexcoord[pID+2 ]);
336333 // Second vertex
337- qID = locTriIndices[(i * 3 ) + 1 ] * 3 ;
334+ int qID = locTriIndices[(i * 3 ) + 1 ] * 3 ;
338335 vertices_position.push_back (locVertexcoord[qID]);
339336 vertices_position.push_back (locVertexcoord[qID+1 ]);
340337 vertices_position.push_back (locVertexcoord[qID+2 ]);
341338 // Third vertex
342- rID = locTriIndices[(i * 3 ) + 2 ] * 3 ;
339+ int rID = locTriIndices[(i * 3 ) + 2 ] * 3 ;
343340 vertices_position.push_back (locVertexcoord[rID]);
344341 vertices_position.push_back (locVertexcoord[rID+1 ]);
345342 vertices_position.push_back (locVertexcoord[rID+2 ]);
346343 }
347344 return vertices_position;
348345}
349346
350- std::vector<float > Tesselator ::GetNormalsAsTuple ()
347+ std::vector<float > ShapeTesselator ::GetNormalsAsTuple ()
351348{
352349 EnsureMeshIsComputed ();
353350 // create the vector and allocate memory
@@ -373,7 +370,7 @@ std::vector<float> Tesselator::GetNormalsAsTuple()
373370 return normals;
374371}
375372
376- std::string Tesselator ::ExportShapeToX3DIndexedFaceSet ()
373+ std::string ShapeTesselator ::ExportShapeToX3DIndexedFaceSet ()
377374{
378375 EnsureMeshIsComputed ();
379376 std::stringstream str_ifs, str_vertices, str_normals;
@@ -427,7 +424,7 @@ std::string Tesselator::ExportShapeToX3DIndexedFaceSet()
427424 return str_ifs.str ();
428425}
429426
430- void Tesselator ::ExportShapeToX3D (char * filename, int diffR, int diffG, int diffB)
427+ void ShapeTesselator ::ExportShapeToX3D (char * filename, int diffR, int diffG, int diffB)
431428{
432429 EnsureMeshIsComputed ();
433430 std::ofstream X3Dfile;
@@ -448,7 +445,7 @@ void Tesselator::ExportShapeToX3D(char * filename, int diffR, int diffG, int dif
448445
449446}
450447
451- std::string Tesselator ::ExportShapeToThreejsJSONString (char *shape_function_name)
448+ std::string ShapeTesselator ::ExportShapeToThreejsJSONString (char *shape_function_name)
452449{
453450 EnsureMeshIsComputed ();
454451 // a method that export a shape to a JSON BufferGeometry object
@@ -531,55 +528,55 @@ std::string Tesselator::ExportShapeToThreejsJSONString(char *shape_function_name
531528}
532529
533530// ---------------------------------------------------------------------------
534- Standard_Real* Tesselator ::VerticesList ()
531+ Standard_Real* ShapeTesselator ::VerticesList ()
535532{
536533 EnsureMeshIsComputed ();
537534 return locVertexcoord;
538535}
539536// ---------------------------------------------------------------------------
540- Standard_Real* Tesselator ::NormalsList ()
537+ Standard_Real* ShapeTesselator ::NormalsList ()
541538{
542539 EnsureMeshIsComputed ();
543540 return locNormalcoord;
544541}
545542// ---------------------------------------------------------------------------
546- Standard_Integer Tesselator ::ObjGetInvalidTriangleCount ()
543+ Standard_Integer ShapeTesselator ::ObjGetInvalidTriangleCount ()
547544{
548545 EnsureMeshIsComputed ();
549546 return tot_invalid_triangle_count;
550547}
551548// ---------------------------------------------------------------------------
552- Standard_Integer Tesselator ::ObjGetTriangleCount ()
549+ Standard_Integer ShapeTesselator ::ObjGetTriangleCount ()
553550{
554551 EnsureMeshIsComputed ();
555552 return tot_triangle_count;
556553}
557554// ---------------------------------------------------------------------------
558- Standard_Integer Tesselator ::ObjGetVertexCount ()
555+ Standard_Integer ShapeTesselator ::ObjGetVertexCount ()
559556{
560557 EnsureMeshIsComputed ();
561558 return tot_vertex_count;
562559}
563560// ---------------------------------------------------------------------------
564- Standard_Integer Tesselator ::ObjGetNormalCount ()
561+ Standard_Integer ShapeTesselator ::ObjGetNormalCount ()
565562{
566563 EnsureMeshIsComputed ();
567564 return tot_normal_count;
568565}
569566// ---------------------------------------------------------------------------
570- Standard_Integer Tesselator ::ObjGetInvalidNormalCount ()
567+ Standard_Integer ShapeTesselator ::ObjGetInvalidNormalCount ()
571568{
572569 EnsureMeshIsComputed ();
573570 return tot_invalid_normal_count;
574571}
575572// ---------------------------------------------------------------------------
576- Standard_Integer Tesselator ::ObjGetEdgeCount ()
573+ Standard_Integer ShapeTesselator ::ObjGetEdgeCount ()
577574{
578575 EnsureMeshIsComputed ();
579576 return edgelist.size ();
580577}
581578// ---------------------------------------------------------------------------
582- Standard_Integer Tesselator ::ObjEdgeGetVertexCount (int iEdge)
579+ Standard_Integer ShapeTesselator ::ObjEdgeGetVertexCount (int iEdge)
583580{
584581 EnsureMeshIsComputed ();
585582 aedge* edge = edgelist.at (iEdge);
@@ -589,31 +586,31 @@ Standard_Integer Tesselator::ObjEdgeGetVertexCount(int iEdge)
589586 return edge->number_of_coords ;
590587}
591588// ---------------------------------------------------------------------------
592- void Tesselator ::GetVertex (int ivert, float & x, float & y, float & z)
589+ void ShapeTesselator ::GetVertex (int ivert, float & x, float & y, float & z)
593590{
594591 EnsureMeshIsComputed ();
595592 x = locVertexcoord[ivert*3 + 0 ];
596593 y = locVertexcoord[ivert*3 + 1 ];
597594 z = locVertexcoord[ivert*3 + 2 ];
598595}
599596// ---------------------------------------------------------------------------
600- void Tesselator ::GetNormal (int ivert, float & x, float & y, float & z)
597+ void ShapeTesselator ::GetNormal (int ivert, float & x, float & y, float & z)
601598{
602599 EnsureMeshIsComputed ();
603600 x = locNormalcoord[ivert*3 + 0 ];
604601 y = locNormalcoord[ivert*3 + 1 ];
605602 z = locNormalcoord[ivert*3 + 2 ];
606603}
607604// ---------------------------------------------------------------------------
608- void Tesselator ::GetTriangleIndex (int triangleIdx, int &v1, int &v2, int &v3)
605+ void ShapeTesselator ::GetTriangleIndex (int triangleIdx, int &v1, int &v2, int &v3)
609606{
610607 EnsureMeshIsComputed ();
611608 v1 = locTriIndices[3 *triangleIdx + 0 ];
612609 v2 = locTriIndices[3 *triangleIdx + 1 ];
613610 v3 = locTriIndices[3 *triangleIdx + 2 ];
614611}
615612// ---------------------------------------------------------------------------
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)
617614{
618615 EnsureMeshIsComputed ();
619616 aedge* e = edgelist.at (iEdge);
@@ -626,7 +623,7 @@ void Tesselator::GetEdgeVertex(int iEdge, int ivert, float &x, float &y, float &
626623 z = e->vertex_coord [3 *ivert + 2 ];
627624}
628625// ---------------------------------------------------------------------------
629- void Tesselator ::ObjGetTriangle (int trianglenum, int *vertices, int *normals)
626+ void ShapeTesselator ::ObjGetTriangle (int trianglenum, int *vertices, int *normals)
630627{
631628 EnsureMeshIsComputed ();
632629 int pID = locTriIndices[(trianglenum * 3 ) + 0 ] * 3 ;
@@ -644,7 +641,7 @@ void Tesselator::ObjGetTriangle(int trianglenum, int *vertices, int *normals)
644641// ---------------------------------------------------------------------------
645642// ---------------------------------HELPERS-----------------------------------
646643// ---------------------------------------------------------------------------
647- void Tesselator ::JoinPrimitives ()
644+ void ShapeTesselator ::JoinPrimitives ()
648645{
649646 int obP = 0 ;
650647 int obN = 0 ;
@@ -670,7 +667,7 @@ void Tesselator::JoinPrimitives()
670667 tot_normal_count = tot_normal_count + myface->number_of_normals ;
671668 tot_invalid_normal_count = tot_invalid_normal_count + myface->number_of_invalid_normals ;
672669
673- anIterator++ ;
670+ ++anIterator ;
674671 }
675672
676673 locTriIndices= new Standard_Integer[tot_triangle_count * 3 ];
0 commit comments