From d20fb24d26a5529b203cef4f849497c07206a27a Mon Sep 17 00:00:00 2001 From: Christophe Bourcier Date: Mon, 14 Feb 2022 16:08:23 +0100 Subject: [PATCH 1/1] Fix selection of cells with delegateToVtk --- src/VTKViewer/VTKViewer_GeometryFilter.cxx | 50 +++++++++++++++++++--- src/VTKViewer/VTKViewer_GeometryFilter.h | 8 +++- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/VTKViewer/VTKViewer_GeometryFilter.cxx b/src/VTKViewer/VTKViewer_GeometryFilter.cxx index 577206a2d..e05ec36f2 100644 --- a/src/VTKViewer/VTKViewer_GeometryFilter.cxx +++ b/src/VTKViewer/VTKViewer_GeometryFilter.cxx @@ -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( @@ -217,9 +236,16 @@ VTKViewer_GeometryFilter return this->vtkGeometryFilter::PolyDataExecute(input, output, &exc); case VTK_UNSTRUCTURED_GRID: { - vtkUnstructuredGrid* inputUnstrctured = static_cast(input); + vtkUnstructuredGrid* inputUnstructured = static_cast(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 ElementsNotFitToDelegate; @@ -251,7 +277,21 @@ VTKViewer_GeometryFilter 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, &exc); + FillVTK2ObjIds(output); + } + else { + // no need to get original cell ids + this->PassThroughCellIds = false; + ret = this->vtkGeometryFilter::UnstructuredGridExecute(input, output, info, &exc); + } + return ret; + } } } diff --git a/src/VTKViewer/VTKViewer_GeometryFilter.h b/src/VTKViewer/VTKViewer_GeometryFilter.h index af65b0267..119427545 100644 --- a/src/VTKViewer/VTKViewer_GeometryFilter.h +++ b/src/VTKViewer/VTKViewer_GeometryFilter.h @@ -130,7 +130,7 @@ protected: //special cases for performance /*! \fn void UnstructuredGridExecute(); - * \brief Filter culculation method for data object type is VTK_UNSTRUCTURED_GRID. + * \brief Filter calculation method for data object type is VTK_UNSTRUCTURED_GRID. */ int UnstructuredGridExecute (vtkDataSet *, vtkPolyData *, vtkInformation *); @@ -141,6 +141,12 @@ protected: TMapOfVectorId& theDimension2VTK2ObjIds, bool triangulate = false); + /*! \fn void FillVTK2ObjIds(vtkPolyData *output); + * \brief fill myVTK2ObjIds to get the correspondence between vtk ids (displayed edges and faces + * computed in vtkGeometryFilter::UnstructuredGridExecute) and original cell ids (mesh cells) + */ + void FillVTK2ObjIds(vtkPolyData *output); + // Delegate VTKViewer_GeometryFilter::UnstructuredGridExecute to vtkGeometryFilter::UnstructuredGridExecute bool delegateToVtk = false; -- 2.30.2