Salome HOME
updated copyright message
[modules/gui.git] / src / VTKViewer / VTKViewer_GeometryFilter.cxx
index 577206a2d0f93ed717ac2f26305c1b701fb93a09..2a17bf47caae380ba4675d6a5ce2c2592e9a8257 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -108,8 +108,8 @@ VTKViewer_GeometryFilter
   static int forceDelegateToVtk = -1;
   if ( forceDelegateToVtk < 0 )
   {
-    QString env = Qtx::getenv( "SALOME_ACTOR_DELEGATE_TO_VTK" );
-    forceDelegateToVtk = (int)(env == "1");
+    QString env = Qtx::getenv( "SALOME_ACTOR_DO_NOT_DELEGATE_TO_VTK" );
+    forceDelegateToVtk = (int)(env != "1");
   }
   delegateToVtk = forceDelegateToVtk > 0;
 }
@@ -166,6 +166,25 @@ struct vtkExcludedFaces
   ~vtkExcludedFaces() { delete this->Links; }
 };
 
+// fill myVTK2ObjIds to get the correspondence between vtk ids (displayed edges and faces
+// computed in vtkGeometryFilter::UnstructuredGridExecute) and original cell ids (mesh cells)
+void VTKViewer_GeometryFilter
+::FillVTK2ObjIds(vtkPolyData *output) {
+
+  vtkDataArray* vtkOriginalCellIds = output->GetCellData()->GetArray("vtkOriginalCellIds");
+
+  if (vtkOriginalCellIds == nullptr)
+    throw std::runtime_error("vtkOriginalCellIds is null. Something is wrong.");
+
+  const vtkIdType numTuples = vtkOriginalCellIds->GetNumberOfTuples();
+  myVTK2ObjIds.resize(numTuples);
+
+  // copy ids of vtkOriginalCellIds into myVTK2ObjIds
+  vtkIdTypeArray *vtkOriginalCellIdsInt(vtkIdTypeArray::SafeDownCast(vtkOriginalCellIds));
+  vtkIdType* origIds(vtkOriginalCellIdsInt->GetPointer(0));
+  myVTK2ObjIds.assign(origIds, origIds+numTuples);
+}
+
 int
 VTKViewer_GeometryFilter
 ::RequestData(
@@ -200,9 +219,10 @@ VTKViewer_GeometryFilter
      vtkInformation* excInfo = inputVector[1]->GetInformationObject(0);
 
      vtkExcludedFaces exc; // Will delete exc->Links when goes out of scope
+     vtkPolyData* excFaces = nullptr;
      if (excInfo)
        {
-        vtkPolyData* excFaces = vtkPolyData::SafeDownCast(excInfo->Get(vtkDataObject::DATA_OBJECT()));
+        excFaces = vtkPolyData::SafeDownCast(excInfo->Get(vtkDataObject::DATA_OBJECT()));
         vtkCellArray* excPolys = excFaces->GetPolys();
         if (excPolys->GetNumberOfCells() > 0)
           {
@@ -214,12 +234,19 @@ VTKViewer_GeometryFilter
      switch (input->GetDataObjectType())
      {
        case VTK_POLY_DATA:
-          return this->vtkGeometryFilter::PolyDataExecute(input, output, &exc);
+          return this->vtkGeometryFilter::PolyDataExecute(input, output, excFaces);
        case VTK_UNSTRUCTURED_GRID:
          {
-          vtkUnstructuredGrid* inputUnstrctured = static_cast<vtkUnstructuredGrid*>(input);
+          vtkUnstructuredGrid* inputUnstructured = static_cast<vtkUnstructuredGrid*>(input);
+
+          // The "info", is passed to provide information about the unstructured grid. This
+          // is done to avoid repeated evaluations of "info" in the vtkGeometryFilter and
+          // the vtkDataSetSurfaceFilter (which vtkGeometryFilter  might delagate to in case
+          // of nonlinear data).
+          vtkGeometryFilterHelper* info = vtkGeometryFilterHelper::CharacterizeUnstructuredGrid(inputUnstructured);
+
           bool NotFitForDelegation = false;
-          if ( vtkUnsignedCharArray* types = inputUnstrctured->GetCellTypesArray() )
+          if ( vtkUnsignedCharArray* types = inputUnstructured->GetCellTypesArray() )
             {
              std::set<vtkIdType> ElementsNotFitToDelegate;
 
@@ -240,22 +267,31 @@ VTKViewer_GeometryFilter
              ElementsNotFitToDelegate.insert( VTK_BIQUADRATIC_QUADRATIC_WEDGE );
              ElementsNotFitToDelegate.insert( VTK_QUADRATIC_PYRAMID );
 
-             // Some openMP tests reveal that  meshes with  polyhedrons  can  sometimes cause
-             // problems as such we avoide delegation = ElementsNotFitToDelegate. It would be
-             // nice to investigate and resolve the problem with multi-therding in future.   
-             ElementsNotFitToDelegate.insert( VTK_POLYHEDRON );
-
              for ( int i = 0; i < types->GetNumberOfTuples() && !NotFitForDelegation; ++i )
                 NotFitForDelegation = ElementsNotFitToDelegate.count( types->GetValue(i) );
             }
          if ( NotFitForDelegation )
             return this->UnstructuredGridExecute(input, output, outInfo);
          else
-            return this->vtkGeometryFilter::UnstructuredGridExecute(input, output, nullptr, &exc);
+           {
+           int ret;
+            if ( myStoreMapping ) {
+              // pass through cell ids to get original cell ids
+              this->PassThroughCellIds = true;
+              ret = this->vtkGeometryFilter::UnstructuredGridExecute(input, output, info, excFaces);
+              FillVTK2ObjIds(output);
+            }
+            else {
+              // no need to get original cell ids
+              this->PassThroughCellIds = false;
+              ret = this->vtkGeometryFilter::UnstructuredGridExecute(input, output, info, excFaces);
+            }
+            return ret;
+           }
          }
      }
 
-     return this->vtkGeometryFilter::DataSetExecute(input, output, &exc);
+     return this->vtkGeometryFilter::DataSetExecute(input, output, excFaces);
     }  
     else // !delegateToVtk
 #endif