diff --git a/Common/DataModel/vtkExtractStructuredGridHelper.cxx b/Common/DataModel/vtkExtractStructuredGridHelper.cxx index 75fc7a4540cc2c669ca6a64c5635f608dc1c71ff..9c03a9d6dcb4f8657dd991f7f019ceb52b6a9c79 100644 --- a/Common/DataModel/vtkExtractStructuredGridHelper.cxx +++ b/Common/DataModel/vtkExtractStructuredGridHelper.cxx @@ -478,6 +478,14 @@ void vtkExtractStructuredGridHelper::CopyCellData(int inExt[6], int outExt[6], int outCellExt[6]; vtkStructuredData::GetCellExtentFromPointExtent(outExt,outCellExt); + // clamp outCellExt using inpCellExt. This is needed for the case where outExt + // is the outer face of the dataset along any of the dimensions. + for (int dim = 0; dim < 3; ++dim) + { + EMIN(outCellExt, dim) = std::min(EMAX(inpCellExt, dim), EMIN(outCellExt, dim)); + EMAX(outCellExt, dim) = std::min(EMAX(inpCellExt, dim), EMAX(outCellExt, dim)); + } + // Lists for batching copy operations: vtkNew<vtkIdList> srcIds; vtkNew<vtkIdList> dstIds; diff --git a/Filters/Extraction/Testing/Cxx/TestExtractRectilinearGrid.cxx b/Filters/Extraction/Testing/Cxx/TestExtractRectilinearGrid.cxx index 13cb6a962535ac17f2e6a60075eb20595caf68e7..80c30d35c2446bbb8e0cdaa35a5118028329b78e 100644 --- a/Filters/Extraction/Testing/Cxx/TestExtractRectilinearGrid.cxx +++ b/Filters/Extraction/Testing/Cxx/TestExtractRectilinearGrid.cxx @@ -19,12 +19,13 @@ #include "vtkDoubleArray.h" #include "vtkExtractRectilinearGrid.h" #include "vtkMathUtilities.h" +#include "vtkNew.h" #include "vtkPointData.h" +#include "vtkPointDataToCellData.h" #include "vtkRectilinearGrid.h" #include "vtkRectilinearGridWriter.h" #include "vtkStructuredData.h" - // C/C++ includes #include <cassert> #include <cmath> @@ -142,6 +143,13 @@ void GenerateGrid( vtkRectilinearGrid* grid, int ext[6] ) xyz->SetTuple(pntIdx, grid->GetPoint(pntIdx) ); } // END for all points grid->GetPointData()->AddArray( xyz ); + + vtkNew<vtkPointDataToCellData> pd2cd; + pd2cd->PassPointDataOn(); + pd2cd->SetInputDataObject(grid); + pd2cd->Update(); + grid->ShallowCopy(pd2cd->GetOutputDataObject(0)); + xyz->Delete(); } @@ -176,6 +184,16 @@ int TestExtractRectilinearGrid( int argc, char* argv[]) rc += CheckGrid( subGrid ); + // Let's extract outer face too. + int sub_ext2[6] = { 49, 49, 0, 49, 0, 0 }; + extractFilter->SetVOI(sub_ext2); + extractFilter->SetSampleRate(1, 1, 1); + extractFilter->IncludeBoundaryOff(); + extractFilter->Update(); + + subGrid = extractFilter->GetOutput(); + rc += CheckGrid(subGrid); + extractFilter->Delete(); grid->Delete(); return( rc );