From: eap Date: Wed, 15 Aug 2007 09:13:09 +0000 (+0000) Subject: PAL16719 (Visualization of flat polyhedron in SMESH and VISU) X-Git-Tag: T32x_16Aug2007_16h00m X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=721db1c392f1fc7c096de54bbe4c76d0ffee3fe5;p=modules%2Fgui.git PAL16719 (Visualization of flat polyhedron in SMESH and VISU) modify VTKViewer_OrderedTriangulator to fix getting faces of vtkConvexPointSet --- diff --git a/src/VTKViewer/VTKViewer_ConvexTool.cxx b/src/VTKViewer/VTKViewer_ConvexTool.cxx index 3a2a8a72f..6f7831664 100644 --- a/src/VTKViewer/VTKViewer_ConvexTool.cxx +++ b/src/VTKViewer/VTKViewer_ConvexTool.cxx @@ -43,6 +43,9 @@ #include #include #include +#include +#include +#include #ifdef _DEBUG_ static int DEBUG_TRIA_EXECUTE = 0; @@ -513,8 +516,15 @@ VTKViewer_Triangulator */ VTKViewer_OrderedTriangulator ::VTKViewer_OrderedTriangulator(): - myCell(vtkGenericCell::New()) -{} + myCell(vtkGenericCell::New()), + myBoundaryTris(vtkCellArray::New()), + myTriangle(vtkTriangle::New()), + myTriangulator(vtkOrderedTriangulator::New()) +{ + myBoundaryTris->Allocate(100); + myTriangulator->PreSortedOff(); + //myTriangulator->UseTemplatesOn(); +} /*! Destructor @@ -523,6 +533,9 @@ VTKViewer_OrderedTriangulator ::~VTKViewer_OrderedTriangulator() { myCell->Delete(); + myBoundaryTris->Delete(); + myTriangle->Delete(); + myTriangulator->Delete(); } vtkPoints* @@ -530,6 +543,39 @@ VTKViewer_OrderedTriangulator ::InitPoints() { myInput->GetCell(myCellId,myCell); + + int numPts = myCell->GetNumberOfPoints(); + if ( numPts > 0 ) + { + myTriangulator->InitTriangulation(0.0,1.0, 0.0,1.0, 0.0,1.0, numPts); + + vtkFloatingPointType x[3], p[3]; + vtkIdType ptId; + vtkFloatingPointType *bounds = myCell->GetBounds(); + + // Inject cell points into triangulation + for (int i=0; iPoints->GetPoint(i, x); + for (int j=0; j<3; j++) + p[j] = (x[j] - bounds[2*j]) / (bounds[2*j+1] - bounds[2*j]); + ptId = myCell->PointIds->GetId(i); + // myTriangulator->InsertPoint(ptId, x, x, 0); + myTriangulator->InsertPoint(ptId, x, p, 0); + }//for all points + + +// if ( myCell->IsPrimaryCell() ) //use templates if topology is fixed +// { +// int numEdges=myCell->GetNumberOfEdges(); +// myTriangulator->TemplateTriangulate(myCell->GetCellType(), +// numPts,numEdges); +// } +// else //use ordered triangulator + { + myTriangulator->Triangulate(); + } + } return myInput->GetPoints(); } @@ -558,14 +604,31 @@ vtkIdType VTKViewer_OrderedTriangulator ::GetNumFaces() { - return myCell->GetNumberOfFaces(); + myBoundaryTris->Reset(); + myTriangulator->AddTriangles(myBoundaryTris); + return myBoundaryTris->GetNumberOfCells(); + //return myCell->GetNumberOfFaces(); } vtkCell* VTKViewer_OrderedTriangulator ::GetFace(vtkIdType theFaceId) { - return myCell->GetFace(theFaceId); + int numCells = myBoundaryTris->GetNumberOfCells(); + if ( theFaceId < 0 || theFaceId >=numCells ) {return NULL;} + + vtkIdType *cells = myBoundaryTris->GetPointer(); + + // Each triangle has three points plus number of points + vtkIdType *cptr = cells + 4*theFaceId; + for (int i=0; i<3; i++) + { + myTriangle->PointIds->SetId(i,cptr[i+1]); + myTriangle->Points->SetPoint(i,myCell->Points->GetPoint(cptr[i+1])); + } + + return myTriangle; + //return myCell->GetFace(theFaceId); } void diff --git a/src/VTKViewer/VTKViewer_ConvexTool.h b/src/VTKViewer/VTKViewer_ConvexTool.h index 11844fb44..a9e837838 100644 --- a/src/VTKViewer/VTKViewer_ConvexTool.h +++ b/src/VTKViewer/VTKViewer_ConvexTool.h @@ -36,6 +36,9 @@ class vtkCellData; class vtkPoints; class vtkIdList; class vtkCell; +class vtkCellArray; +class vtkTriangle; +class vtkOrderedTriangulator; class VTKVIEWER_EXPORT VTKViewer_Triangulator { @@ -111,7 +114,10 @@ class VTKVIEWER_EXPORT VTKViewer_OrderedTriangulator : public VTKViewer_Triangul ~VTKViewer_OrderedTriangulator(); protected: - vtkGenericCell *myCell; + vtkGenericCell *myCell; + vtkCellArray *myBoundaryTris; + vtkTriangle *myTriangle; + vtkOrderedTriangulator *myTriangulator; virtual vtkPoints*