From f7e26a4b858c58a95f83feaf3787c08022b0672f Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Thu, 12 Mar 2020 15:02:36 +0100 Subject: [PATCH] PV58 : Modification of internal access of vtkUnstructuredGrid + int64 compability --- .../DevelopedSurfaceModule/VTKToMEDMem.cxx | 46 +++++++++++-------- .../plugin/MEDWriterIO/VTKToMEDMem.cxx | 46 +++++++++++-------- .../plugin/VoroGaussModule/vtkVoroGauss.cxx | 43 +++++++++-------- 3 files changed, 77 insertions(+), 58 deletions(-) diff --git a/src/Plugins/DevelopedSurface/plugin/DevelopedSurfaceModule/VTKToMEDMem.cxx b/src/Plugins/DevelopedSurface/plugin/DevelopedSurfaceModule/VTKToMEDMem.cxx index 3a0cb639..a443f4fa 100644 --- a/src/Plugins/DevelopedSurface/plugin/DevelopedSurfaceModule/VTKToMEDMem.cxx +++ b/src/Plugins/DevelopedSurface/plugin/DevelopedSurfaceModule/VTKToMEDMem.cxx @@ -161,6 +161,13 @@ DataArrayIdType *ConvertVTKArrayToMCArrayInt(vtkDataArray *data) std::copy(pt,pt+nbElts,ptOut); return ret.retn(); } + vtkIdTypeArray *d3(vtkIdTypeArray::SafeDownCast(data)); + if(d3) + { + const vtkIdType *pt(d3->GetPointer(0)); + std::copy(pt,pt+nbElts,ptOut); + return ret.retn(); + } vtkUnsignedCharArray *d2(vtkUnsignedCharArray::SafeDownCast(data)); if(d2) { @@ -241,7 +248,8 @@ DataArray *ConvertVTKArrayToMCArray(vtkDataArray *data) vtkIntArray *d2(vtkIntArray::SafeDownCast(data)); vtkLongArray *d3(vtkLongArray::SafeDownCast(data)); vtkUnsignedCharArray *d4(vtkUnsignedCharArray::SafeDownCast(data)); - if(d2 || d3 || d4) + vtkIdTypeArray *d5(vtkIdTypeArray::SafeDownCast(data)); + if(d2 || d3 || d4 || d5) return ConvertVTKArrayToMCArrayInt(data); std::ostringstream oss; oss << "ConvertVTKArrayToMCArray : unrecognized array \"" << typeid(*data).name() << "\" type !"; @@ -781,41 +789,43 @@ void ConvertFromUnstructuredGrid(MEDFileData *ret, vtkUnstructuredGrid *ds, cons MCAuto cellIdsCurLev(lev->findIdsEqual(*curLev)); for(const mcIdType *cellId=cellIdsCurLev->begin();cellId!=cellIdsCurLev->end();cellId++) { - int vtkType(ctPtr[*cellId]); + int vtkType(ds->GetCellType(*cellId)); std::map::iterator it(m.find(vtkType)); - vtkIdType offset(claPtr[*cellId]); - vtkIdType sz(caPtr[offset]); INTERP_KERNEL::NormalizedCellType ct=it!=m.end()?(INTERP_KERNEL::NormalizedCellType)((*it).second):INTERP_KERNEL::NORM_POINT1; if(ct!=INTERP_KERNEL::NORM_POLYHED && vtkType!=VTK_POLY_VERTEX) { - std::vector conn2(sz); - for(int kk=0;kkinsertNextCell(ct,sz,&conn2[0]); + vtkIdType sz(0); + const vtkIdType *pts(nullptr); + ds->GetCellPoints(*cellId, sz, pts); + std::vector conn2(pts,pts+sz); + m0->insertNextCell(ct,sz,conn2.data()); } else if(ct==INTERP_KERNEL::NORM_POLYHED) { - if(!faces || !faceLoc) - throw MZCException("ConvertFromUnstructuredGrid : faces are expected when there are polyhedra !"); - const vtkIdType *facPtr(faces->GetPointer(0)),*facLocPtr(faceLoc->GetPointer(0)); + // # de faces du polyèdre + vtkIdType nbOfFaces(0); + // connectivé des faces (numFace0Pts, id1, id2, id3, numFace1Pts,id1, id2, id3, ...) + const vtkIdType *facPtr(nullptr); + ds->GetFaceStream(*cellId, nbOfFaces, facPtr); std::vector conn; - int off0(facLocPtr[*cellId]); - int nbOfFaces(facPtr[off0++]); - for(int k=0;kinsertNextCell(ct,ToIdType(conn.size()),&conn[0]); } else { + vtkIdType sz(0); + const vtkIdType *pts(nullptr); + ds->GetCellPoints(*cellId, sz, pts); if(sz!=1) throw MZCException("ConvertFromUnstructuredGrid : non single poly vertex not managed by MED !"); - m0->insertNextCell(ct,1,(const mcIdType*)(caPtr+offset+1)); + m0->insertNextCell(ct,1,(const mcIdType*)pts); } } std::vector > cellFs(AddPartFields(cellIdsCurLev,ds->GetCellData())); diff --git a/src/Plugins/MEDWriter/plugin/MEDWriterIO/VTKToMEDMem.cxx b/src/Plugins/MEDWriter/plugin/MEDWriterIO/VTKToMEDMem.cxx index 3a0cb639..a443f4fa 100644 --- a/src/Plugins/MEDWriter/plugin/MEDWriterIO/VTKToMEDMem.cxx +++ b/src/Plugins/MEDWriter/plugin/MEDWriterIO/VTKToMEDMem.cxx @@ -161,6 +161,13 @@ DataArrayIdType *ConvertVTKArrayToMCArrayInt(vtkDataArray *data) std::copy(pt,pt+nbElts,ptOut); return ret.retn(); } + vtkIdTypeArray *d3(vtkIdTypeArray::SafeDownCast(data)); + if(d3) + { + const vtkIdType *pt(d3->GetPointer(0)); + std::copy(pt,pt+nbElts,ptOut); + return ret.retn(); + } vtkUnsignedCharArray *d2(vtkUnsignedCharArray::SafeDownCast(data)); if(d2) { @@ -241,7 +248,8 @@ DataArray *ConvertVTKArrayToMCArray(vtkDataArray *data) vtkIntArray *d2(vtkIntArray::SafeDownCast(data)); vtkLongArray *d3(vtkLongArray::SafeDownCast(data)); vtkUnsignedCharArray *d4(vtkUnsignedCharArray::SafeDownCast(data)); - if(d2 || d3 || d4) + vtkIdTypeArray *d5(vtkIdTypeArray::SafeDownCast(data)); + if(d2 || d3 || d4 || d5) return ConvertVTKArrayToMCArrayInt(data); std::ostringstream oss; oss << "ConvertVTKArrayToMCArray : unrecognized array \"" << typeid(*data).name() << "\" type !"; @@ -781,41 +789,43 @@ void ConvertFromUnstructuredGrid(MEDFileData *ret, vtkUnstructuredGrid *ds, cons MCAuto cellIdsCurLev(lev->findIdsEqual(*curLev)); for(const mcIdType *cellId=cellIdsCurLev->begin();cellId!=cellIdsCurLev->end();cellId++) { - int vtkType(ctPtr[*cellId]); + int vtkType(ds->GetCellType(*cellId)); std::map::iterator it(m.find(vtkType)); - vtkIdType offset(claPtr[*cellId]); - vtkIdType sz(caPtr[offset]); INTERP_KERNEL::NormalizedCellType ct=it!=m.end()?(INTERP_KERNEL::NormalizedCellType)((*it).second):INTERP_KERNEL::NORM_POINT1; if(ct!=INTERP_KERNEL::NORM_POLYHED && vtkType!=VTK_POLY_VERTEX) { - std::vector conn2(sz); - for(int kk=0;kkinsertNextCell(ct,sz,&conn2[0]); + vtkIdType sz(0); + const vtkIdType *pts(nullptr); + ds->GetCellPoints(*cellId, sz, pts); + std::vector conn2(pts,pts+sz); + m0->insertNextCell(ct,sz,conn2.data()); } else if(ct==INTERP_KERNEL::NORM_POLYHED) { - if(!faces || !faceLoc) - throw MZCException("ConvertFromUnstructuredGrid : faces are expected when there are polyhedra !"); - const vtkIdType *facPtr(faces->GetPointer(0)),*facLocPtr(faceLoc->GetPointer(0)); + // # de faces du polyèdre + vtkIdType nbOfFaces(0); + // connectivé des faces (numFace0Pts, id1, id2, id3, numFace1Pts,id1, id2, id3, ...) + const vtkIdType *facPtr(nullptr); + ds->GetFaceStream(*cellId, nbOfFaces, facPtr); std::vector conn; - int off0(facLocPtr[*cellId]); - int nbOfFaces(facPtr[off0++]); - for(int k=0;kinsertNextCell(ct,ToIdType(conn.size()),&conn[0]); } else { + vtkIdType sz(0); + const vtkIdType *pts(nullptr); + ds->GetCellPoints(*cellId, sz, pts); if(sz!=1) throw MZCException("ConvertFromUnstructuredGrid : non single poly vertex not managed by MED !"); - m0->insertNextCell(ct,1,(const mcIdType*)(caPtr+offset+1)); + m0->insertNextCell(ct,1,(const mcIdType*)pts); } } std::vector > cellFs(AddPartFields(cellIdsCurLev,ds->GetCellData())); diff --git a/src/Plugins/VoroGauss/plugin/VoroGaussModule/vtkVoroGauss.cxx b/src/Plugins/VoroGauss/plugin/VoroGaussModule/vtkVoroGauss.cxx index afc59954..57856383 100644 --- a/src/Plugins/VoroGauss/plugin/VoroGaussModule/vtkVoroGauss.cxx +++ b/src/Plugins/VoroGauss/plugin/VoroGaussModule/vtkVoroGauss.cxx @@ -205,7 +205,7 @@ DataArrayIdType *ConvertVTKArrayToMCArrayInt(vtkDataArray *data) vtkIdTypeArray *d2(vtkIdTypeArray::SafeDownCast(data)); if(d2) { - const int *pt(d2->GetPointer(0)); + const vtkIdType *pt(d2->GetPointer(0)); std::copy(pt,pt+nbElts,ptOut); return ret.retn(); } @@ -323,32 +323,31 @@ void ConvertFromUnstructuredGrid(vtkUnstructuredGrid *ds, std::vector< MCAuto cellIdsCurLev(lev->findIdsEqual(*curLev)); for(const mcIdType *cellId=cellIdsCurLev->begin();cellId!=cellIdsCurLev->end();cellId++) { - std::map::iterator it(m.find(ctPtr[*cellId])); - vtkIdType offset(claPtr[*cellId]); - vtkIdType sz(caPtr[offset]); + std::map::iterator it(m.find(ds->GetCellType(*cellId))); INTERP_KERNEL::NormalizedCellType ct((INTERP_KERNEL::NormalizedCellType)(*it).second); if(ct!=INTERP_KERNEL::NORM_POLYHED) { - std::vector conn2(sz); - for(int kk=0;kkinsertNextCell(ct,sz,&conn2[0]); + vtkIdType szzz(0); + const vtkIdType *ptszz(nullptr); + ds->GetCellPoints(*cellId, szzz, ptszz); + std::vector conn(ptszz,ptszz+szzz); + m0->insertNextCell(ct,szzz,conn.data()); } else { - if(!faces || !faceLoc) - throw INTERP_KERNEL::Exception("ConvertFromUnstructuredGrid : faces are expected when there are polyhedra !"); - const vtkIdType *facPtr(faces->GetPointer(0)),*facLocPtr(faceLoc->GetPointer(0)); + // # de faces du polyèdre + vtkIdType nbOfFaces(0); + // connectivé des faces (numFace0Pts, id1, id2, id3, numFace1Pts,id1, id2, id3, ...) + const vtkIdType *facPtr(nullptr); + ds->GetFaceStream(*cellId, nbOfFaces, facPtr); std::vector conn; - int off0(facLocPtr[*cellId]); - int nbOfFaces(facPtr[off0++]); - for(int k=0;kinsertNextCell(ct,ToIdType(conn.size()),&conn[0]); } @@ -378,7 +377,7 @@ vtkSmartPointer ConvertUMeshFromMCToVTK(const MEDCouplingUM { case 3: { - int *cPtr(nullptr),*dPtr(nullptr); + vtkIdType *cPtr(nullptr),*dPtr(nullptr); unsigned char *aPtr(nullptr); vtkSmartPointer cellTypes(vtkSmartPointer::New()); { @@ -460,7 +459,7 @@ vtkSmartPointer ConvertUMeshFromMCToVTK(const MEDCouplingUM unsigned char *ptr(cellTypes->GetPointer(0)); std::fill(ptr,ptr+nbCells,zeMapRev[(int)INTERP_KERNEL::NORM_POLYGON]); } - int *cPtr(0),*dPtr(0); + vtkIdType *cPtr(nullptr),*dPtr(nullptr); vtkSmartPointer cellLocations(vtkSmartPointer::New()); { cellLocations->SetNumberOfComponents(1); @@ -495,7 +494,7 @@ vtkSmartPointer ConvertUMeshFromMCToVTK(const MEDCouplingUM unsigned char *ptr(cellTypes->GetPointer(0)); std::fill(ptr,ptr+nbCells,zeMapRev[(int)INTERP_KERNEL::NORM_SEG2]); } - int *cPtr(0),*dPtr(0); + vtkIdType *cPtr(nullptr),*dPtr(nullptr); vtkSmartPointer cellLocations(vtkSmartPointer::New()); { cellLocations->SetNumberOfComponents(1); @@ -698,7 +697,7 @@ vtkSmartPointer Voronize(const MEDCouplingUMesh *m, const D } if(elt4) { - vtkSmartPointer arr(ExtractFieldFieldArr(elt4,zeSizeOfOutCellArr,nbOfCellsOfInput,myOffsetsPtr,nbPtsPerCellArrPtr)); + vtkSmartPointer arr(ExtractFieldFieldArr(elt4,zeSizeOfOutCellArr,nbOfCellsOfInput,myOffsetsPtr,nbPtsPerCellArrPtr)); ret->GetCellData()->AddArray(arr); continue; } @@ -723,7 +722,7 @@ vtkSmartPointer Voronize(const MEDCouplingUMesh *m, const D } if(elt4) { - vtkSmartPointer arr(ExtractCellFieldArr(elt4,zeSizeOfOutCellArr,nbOfCellsOfInput,ids->begin(),nbPtsPerCellArrPtr)); + vtkSmartPointer arr(ExtractCellFieldArr(elt4,zeSizeOfOutCellArr,nbOfCellsOfInput,ids->begin(),nbPtsPerCellArrPtr)); ret->GetCellData()->AddArray(arr); continue; } -- 2.39.2