From a6f666fae89fa06b67b8433833bdf800eb7a3131 Mon Sep 17 00:00:00 2001 From: Christophe Bourcier Date: Mon, 14 Feb 2022 16:08:23 +0100 Subject: [PATCH] Fix selection of cells with delegateToVtk --- src/VTKViewer/VTKViewer_GeometryFilter.cxx | 47 ++++++++++++++++++++-- src/VTKViewer/VTKViewer_GeometryFilter.h | 8 +++- 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/src/VTKViewer/VTKViewer_GeometryFilter.cxx b/src/VTKViewer/VTKViewer_GeometryFilter.cxx index 577206a2d..58e7e6748 100644 --- a/src/VTKViewer/VTKViewer_GeometryFilter.cxx +++ b/src/VTKViewer/VTKViewer_GeometryFilter.cxx @@ -57,6 +57,7 @@ #include #include +#include "Utils_SALOME_Exception.hxx" #include "utilities.h" #if defined __GNUC__ @@ -166,6 +167,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 SALOME_Exception("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 +237,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 +278,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.39.2