Salome HOME
Update copyrights 2014.
[modules/gui.git] / src / VTKViewer / VTKViewer_GeometryFilter.cxx
index e6464522423a4b136fea63eea0d94be936cbd145..e3fe7b6583253363e40072487e19851ba3cf7110 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -48,6 +48,7 @@
 #include <vtkUnstructuredGrid.h>
 #include <vtkVoxel.h>
 #include <vtkWedge.h>
+#include <vtkVersion.h>
 
 #include <algorithm>
 #include <iterator>
@@ -381,10 +382,10 @@ VTKViewer_GeometryFilter
         }
         case VTK_TETRA: {
 #ifdef SHOW_COINCIDING_3D_PAL21924
-         faceIdsTmp->Reset();
-         for (int ai=0; ai<npts; ai++)
-           faceIdsTmp->InsertNextId(pts[ai]);
-         input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
+          faceIdsTmp->Reset();
+          for (int ai=0; ai<npts; ai++)
+            faceIdsTmp->InsertNextId(pts[ai]);
+          input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
 #endif
           for (faceId = 0; faceId < 4; faceId++)
             {
@@ -397,10 +398,10 @@ VTKViewer_GeometryFilter
             numFacePts = 3;
             input->GetCellNeighbors(cellId, faceIds, cellIds);
 #ifdef SHOW_COINCIDING_3D_PAL21924
-           int nbNeighbors = 0;
-           for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
-             if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
-           }
+            int nbNeighbors = 0;
+            for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
+              if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
+            }
             bool process = nbNeighbors <= 0;
 #else
             bool process = cellIds->GetNumberOfIds() <= 0 || GetAppendCoincident3D();
@@ -420,10 +421,10 @@ VTKViewer_GeometryFilter
         }
         case VTK_VOXEL: {
 #ifdef SHOW_COINCIDING_3D_PAL21924
-         faceIdsTmp->Reset();
-         for (int ai=0; ai<npts; ai++)
-           faceIdsTmp->InsertNextId(pts[ai]);
-         input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
+          faceIdsTmp->Reset();
+          for (int ai=0; ai<npts; ai++)
+            faceIdsTmp->InsertNextId(pts[ai]);
+          input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
 #endif
           for (faceId = 0; faceId < 6; faceId++)
             {
@@ -437,10 +438,10 @@ VTKViewer_GeometryFilter
             numFacePts = 4;
             input->GetCellNeighbors(cellId, faceIds, cellIds);
 #ifdef SHOW_COINCIDING_3D_PAL21924
-           int nbNeighbors = 0;
-           for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
-             if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
-           }
+            int nbNeighbors = 0;
+            for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
+              if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
+            }
             bool process = nbNeighbors <= 0;
 #else
             bool process = cellIds->GetNumberOfIds() <= 0 || GetAppendCoincident3D();
@@ -460,10 +461,10 @@ VTKViewer_GeometryFilter
         }
         case VTK_HEXAHEDRON: {
 #ifdef SHOW_COINCIDING_3D_PAL21924
-         faceIdsTmp->Reset();
-         for (int ai=0; ai<npts; ai++)
-           faceIdsTmp->InsertNextId(pts[ai]);
-         input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
+          faceIdsTmp->Reset();
+          for (int ai=0; ai<npts; ai++)
+            faceIdsTmp->InsertNextId(pts[ai]);
+          input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
 #endif
           for (faceId = 0; faceId < 6; faceId++)
             {
@@ -477,10 +478,10 @@ VTKViewer_GeometryFilter
             numFacePts = 4;
             input->GetCellNeighbors(cellId, faceIds, cellIds);
 #ifdef SHOW_COINCIDING_3D_PAL21924
-           int nbNeighbors = 0;
-           for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
-             if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
-           }
+            int nbNeighbors = 0;
+            for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
+              if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
+            }
             bool process = nbNeighbors <= 0;
 #else
             bool process = cellIds->GetNumberOfIds() <= 0 || GetAppendCoincident3D();
@@ -500,10 +501,10 @@ VTKViewer_GeometryFilter
         }
         case VTK_WEDGE: {
 #ifdef SHOW_COINCIDING_3D_PAL21924
-         faceIdsTmp->Reset();
-         for (int ai=0; ai<npts; ai++)
-           faceIdsTmp->InsertNextId(pts[ai]);
-         input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
+          faceIdsTmp->Reset();
+          for (int ai=0; ai<npts; ai++)
+            faceIdsTmp->InsertNextId(pts[ai]);
+          input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
 #endif
           for (faceId = 0; faceId < 5; faceId++)
             {
@@ -523,10 +524,10 @@ VTKViewer_GeometryFilter
 
             input->GetCellNeighbors(cellId, faceIds, cellIds);
 #ifdef SHOW_COINCIDING_3D_PAL21924
-           int nbNeighbors = 0;
-           for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
-             if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
-           }
+            int nbNeighbors = 0;
+            for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
+              if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
+            }
             bool process = nbNeighbors <= 0;
 #else
             bool process = cellIds->GetNumberOfIds() <= 0 || GetAppendCoincident3D();
@@ -546,10 +547,10 @@ VTKViewer_GeometryFilter
         }
         case VTK_HEXAGONAL_PRISM: {
 #ifdef SHOW_COINCIDING_3D_PAL21924
-         faceIdsTmp->Reset();
-         for (int ai=0; ai<npts; ai++)
-           faceIdsTmp->InsertNextId(pts[ai]);
-         input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
+          faceIdsTmp->Reset();
+          for (int ai=0; ai<npts; ai++)
+            faceIdsTmp->InsertNextId(pts[ai]);
+          input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
 #endif
           for (faceId = 0; faceId < 8; faceId++)
           {
@@ -570,10 +571,10 @@ VTKViewer_GeometryFilter
             }
             input->GetCellNeighbors(cellId, faceIds, cellIds);
 #ifdef SHOW_COINCIDING_3D_PAL21924
-           int nbNeighbors = 0;
-           for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
-             if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
-           }
+            int nbNeighbors = 0;
+            for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
+              if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
+            }
             bool process = nbNeighbors <= 0;
 #else
             bool process = cellIds->GetNumberOfIds() <= 0 || GetAppendCoincident3D();
@@ -593,10 +594,10 @@ VTKViewer_GeometryFilter
         }
         case VTK_PYRAMID: {
 #ifdef SHOW_COINCIDING_3D_PAL21924
-         faceIdsTmp->Reset();
-         for (int ai=0; ai<npts; ai++)
-           faceIdsTmp->InsertNextId(pts[ai]);
-         input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
+          faceIdsTmp->Reset();
+          for (int ai=0; ai<npts; ai++)
+            faceIdsTmp->InsertNextId(pts[ai]);
+          input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
 #endif
           for (faceId = 0; faceId < 5; faceId++)
             {
@@ -615,10 +616,10 @@ VTKViewer_GeometryFilter
               }
             input->GetCellNeighbors(cellId, faceIds, cellIds);
 #ifdef SHOW_COINCIDING_3D_PAL21924
-           int nbNeighbors = 0;
-           for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
-             if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
-           }
+            int nbNeighbors = 0;
+            for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
+              if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
+            }
             bool process = nbNeighbors <= 0;
 #else
             bool process = cellIds->GetNumberOfIds() <= 0 || GetAppendCoincident3D();
@@ -646,10 +647,10 @@ VTKViewer_GeometryFilter
             int idp = 0;
             input->GetFaceStream(cellId, nFaces, ptIds);
 #ifdef SHOW_COINCIDING_3D_PAL21924
-           faceIdsTmp->Reset();
-           for (int ai=0; ai<npts; ai++)
-             faceIdsTmp->InsertNextId(pts[ai]);
-           input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
+            faceIdsTmp->Reset();
+            for (int ai=0; ai<npts; ai++)
+              faceIdsTmp->InsertNextId(pts[ai]);
+            input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
 #endif
             for (faceId = 0; faceId < nFaces; faceId++)
               {
@@ -678,13 +679,13 @@ VTKViewer_GeometryFilter
                 // TODO understand and fix display of several polyhedrons                
                 input->GetCellNeighbors(cellId, faceIds, cellIds);
 #ifdef SHOW_COINCIDING_3D_PAL21924
-               int nbNeighbors = 0;
-               for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
-                 if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
-               }
-               bool process = nbNeighbors <= 0;
+                int nbNeighbors = 0;
+                for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
+                  if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
+                }
+                bool process = nbNeighbors <= 0;
 #else
-               bool process = cellIds->GetNumberOfIds() <= 0 || GetAppendCoincident3D();
+                bool process = cellIds->GetNumberOfIds() <= 0 || GetAppendCoincident3D();
 #endif
                 if (process || myShowInside
                     || (!allVisible && !cellVis[cellIds->GetId(0)]))
@@ -703,6 +704,7 @@ VTKViewer_GeometryFilter
         //Quadratic cells
         case VTK_QUADRATIC_EDGE:
         case VTK_QUADRATIC_TRIANGLE:
+        case VTK_BIQUADRATIC_TRIANGLE:
         case VTK_QUADRATIC_QUAD:
         case VTK_BIQUADRATIC_QUAD:
         case VTK_QUADRATIC_TETRA:
@@ -765,20 +767,20 @@ VTKViewer_GeometryFilter
             else //3D nonlinear cell
             {
 #ifdef SHOW_COINCIDING_3D_PAL21924
-             faceIdsTmp->Reset();
-             int npts1 = 0;
-             switch (aCellType ){
-             case VTK_QUADRATIC_TETRA:         npts1 = 4; break;
-             case VTK_QUADRATIC_HEXAHEDRON:    npts1 = 8; break;
-             case VTK_TRIQUADRATIC_HEXAHEDRON: npts1 = 8; break;
-             case VTK_QUADRATIC_WEDGE:         npts1 = 6; break;
-             case VTK_QUADRATIC_PYRAMID:       npts1 = 5; break;
-             }
-             if ( npts1 > 0 ) {
-               for (int ai=0; ai<npts; ai++)
-                 faceIdsTmp->InsertNextId(pts[ai]);
-               input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
-             }
+              faceIdsTmp->Reset();
+              int npts1 = 0;
+              switch (aCellType ){
+              case VTK_QUADRATIC_TETRA:         npts1 = 4; break;
+              case VTK_QUADRATIC_HEXAHEDRON:    npts1 = 8; break;
+              case VTK_TRIQUADRATIC_HEXAHEDRON: npts1 = 8; break;
+              case VTK_QUADRATIC_WEDGE:         npts1 = 6; break;
+              case VTK_QUADRATIC_PYRAMID:       npts1 = 5; break;
+              }
+              if ( npts1 > 0 ) {
+                for (int ai=0; ai<npts; ai++)
+                  faceIdsTmp->InsertNextId(pts[ai]);
+                input->GetCellNeighbors(cellId, faceIdsTmp, cellIdsTmp);
+              }
 #endif
               aCellType = VTK_TRIANGLE;
               numFacePts = 3;
@@ -786,13 +788,13 @@ VTKViewer_GeometryFilter
                 vtkCell *face = cell->GetFace(j);
                 input->GetCellNeighbors(cellId, face->PointIds, cellIds);
 #ifdef SHOW_COINCIDING_3D_PAL21924
-               int nbNeighbors = 0;
-               for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
-                 if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
-               }
-               bool process = nbNeighbors <= 0;
+                int nbNeighbors = 0;
+                for(int ai=0;ai<cellIds->GetNumberOfIds();ai++) {
+                  if (cellIdsTmp->IsId(cellIds->GetId(ai)) == -1) nbNeighbors++;
+                }
+                bool process = nbNeighbors <= 0;
 #else
-               bool process = cellIds->GetNumberOfIds() <= 0 || GetAppendCoincident3D();
+                bool process = cellIds->GetNumberOfIds() <= 0 || GetAppendCoincident3D();
 #endif
                 if ( process || myShowInside ) {
                   face->Triangulate(0,lpts,coords);
@@ -837,7 +839,8 @@ VTKViewer_GeometryFilter
               outputCD->CopyData(cd,cellId,newCellId);
               break;
             }
-            case VTK_QUADRATIC_TRIANGLE: {
+            case VTK_QUADRATIC_TRIANGLE:
+            case VTK_BIQUADRATIC_TRIANGLE: {
               if(!myIsBuildArc) {
                 aCellType = VTK_POLYGON;
                 numFacePts = 6;
@@ -859,8 +862,8 @@ VTKViewer_GeometryFilter
                 BuildArcedPolygon(cellId,input,output,aDimension2VTK2ObjIds);
               break;
             }
-            case VTK_BIQUADRATIC_QUAD:
-            case VTK_QUADRATIC_QUAD: {
+            case VTK_QUADRATIC_QUAD:
+            case VTK_BIQUADRATIC_QUAD: {
               if(!myIsBuildArc) {
                 aCellType = VTK_POLYGON;
                 numFacePts = 8;
@@ -1353,7 +1356,8 @@ void VTKViewer_GeometryFilter::BuildArcedPolygon(vtkIdType cellId,
                                                  vtkUnstructuredGrid* input,
                                                  vtkPolyData *output,
                                                  TMapOfVectorId& theDimension2VTK2ObjIds,
-                                                 bool triangulate){
+                                                 bool triangulate)
+{
   vtkIdType aCellType = VTK_POLYGON;
   vtkIdType *aNewPoints = NULL;
   vtkIdType aNbPoints = 0;
@@ -1367,12 +1371,13 @@ void VTKViewer_GeometryFilter::BuildArcedPolygon(vtkIdType cellId,
   vtkDataArray* inputScalars = input->GetPointData()->GetScalars();
   vtkDataArray* outputScalars = output->GetPointData()->GetScalars();
 
-  std::vector<vtkPoints*> aCollection;
+  std::vector< vtkSmartPointer<vtkPoints> > aCollection;
   std::vector< std::vector<double> > aScalarCollection;
 
   vtkCell* aCell = input->GetCell(cellId);
   switch(aCell->GetCellType()) {
     case VTK_QUADRATIC_TRIANGLE:
+    case VTK_BIQUADRATIC_TRIANGLE:
     {
       //Get All points from input cell
       Pnt P0 = CreatePnt( aCell, inputScalars, 0 );
@@ -1406,8 +1411,8 @@ void VTKViewer_GeometryFilter::BuildArcedPolygon(vtkIdType cellId,
       aScalarCollection.push_back(aBuilder3.GetScalarValues());
       break;
     }
-    case VTK_BIQUADRATIC_QUAD:
     case VTK_QUADRATIC_QUAD:
+    case VTK_BIQUADRATIC_QUAD:
     {
       //Get All points from input cell
       Pnt P0 = CreatePnt( aCell, inputScalars, 0 );