]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
PAL16719 (Visualization of flat polyhedron in SMESH and VISU) T32x_16Aug2007_16h00m
authoreap <eap@opencascade.com>
Wed, 15 Aug 2007 09:13:09 +0000 (09:13 +0000)
committereap <eap@opencascade.com>
Wed, 15 Aug 2007 09:13:09 +0000 (09:13 +0000)
     modify VTKViewer_OrderedTriangulator to fix getting faces of vtkConvexPointSet

src/VTKViewer/VTKViewer_ConvexTool.cxx
src/VTKViewer/VTKViewer_ConvexTool.h

index 3a2a8a72f88a45d0e28aaa183b0bef26ac91bcfb..6f7831664885a1345762a5de4bf7ecf717c8e577 100644 (file)
@@ -43,6 +43,9 @@
 #include <vtkCell.h>
 #include <vtkPlane.h>
 #include <vtkMath.h>
+#include <vtkCellArray.h>
+#include <vtkTriangle.h>
+#include <vtkOrderedTriangulator.h>
 
 #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; i<numPts; i++)
+    {
+      myCell->Points->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 
index 11844fb44751f1be97cbf54ff5989a194f91a524..a9e83783851a1b05223a544570b7ab4df888fddf 100644 (file)
@@ -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*