diff --git a/Common/ExecutionModel/vtkSphereTree.cxx b/Common/ExecutionModel/vtkSphereTree.cxx index cbea6b29ae3ad15918031ab96a3df154b9613fa9..6049836eed8ab2132203e81ae1906c7f250b5429 100644 --- a/Common/ExecutionModel/vtkSphereTree.cxx +++ b/Common/ExecutionModel/vtkSphereTree.cxx @@ -14,24 +14,24 @@ =========================================================================*/ #include "vtkSphereTree.h" -#include "vtkStructuredGrid.h" -#include "vtkUnstructuredGrid.h" -#include "vtkDataSet.h" #include "vtkCellData.h" -#include "vtkPointData.h" #include "vtkDataArray.h" -#include "vtkDoubleArray.h" -#include "vtkMath.h" -#include "vtkLine.h" -#include "vtkPlane.h" -#include "vtkSphere.h" +#include "vtkDataSet.h" #include "vtkDebugLeaks.h" +#include "vtkDoubleArray.h" #include "vtkInformation.h" #include "vtkInformationVector.h" +#include "vtkLine.h" +#include "vtkMath.h" +#include "vtkNew.h" #include "vtkObjectFactory.h" -#include "vtkSMPTools.h" +#include "vtkPlane.h" +#include "vtkPointData.h" #include "vtkSMPThreadLocal.h" - +#include "vtkSMPTools.h" +#include "vtkSphere.h" +#include "vtkStructuredGrid.h" +#include "vtkUnstructuredGrid.h" vtkStandardNewMacro(vtkSphereTree); vtkCxxSetObjectMacro(vtkSphereTree,DataSet,vtkDataSet); @@ -316,10 +316,17 @@ namespace { static void Execute(vtkIdType numCells, vtkDataSet *ds, double *s, double& aveRadius, double sphereBounds[6]) { - DataSetSpheres spheres(ds, s); - vtkSMPTools::For(0, numCells, spheres); - aveRadius = spheres.AverageRadius; - spheres.GetBounds(sphereBounds); + if (ds->GetNumberOfCells() > 0 && numCells <= ds->GetNumberOfCells()) + { + // Dummy call to GetCellBounds to enable its uses in the threaded code + double dummy[6]; + ds->GetCellBounds(0, dummy); + + DataSetSpheres spheres(ds, s); + vtkSMPTools::For(0, numCells, spheres); + aveRadius = spheres.AverageRadius; + spheres.GetBounds(sphereBounds); + } } }; @@ -387,10 +394,17 @@ namespace { static void Execute(vtkIdType numCells, vtkUnstructuredGrid *grid, double *s, double& aveRadius, double sphereBounds[6]) { - UnstructuredSpheres spheres(grid, s); - vtkSMPTools::For(0, numCells, spheres); - aveRadius = spheres.AverageRadius; - spheres.GetBounds(sphereBounds); + if (grid->GetNumberOfCells() > 0 && numCells <= grid->GetNumberOfCells()) + { + // Dummy call to GetCellPoints to enable its uses in the threaded code + vtkNew<vtkIdList> dummy; + grid->GetCellPoints(0, dummy.Get()); + + UnstructuredSpheres spheres(grid, s); + vtkSMPTools::For(0, numCells, spheres); + aveRadius = spheres.AverageRadius; + spheres.GetBounds(sphereBounds); + } } }; diff --git a/Filters/Core/vtkPlaneCutter.cxx b/Filters/Core/vtkPlaneCutter.cxx index e76abb14943dc8d9bc7ee65f7300d54783ab8585..c45cb76cc9df79ced477f4808d9939eb742ebaf4 100644 --- a/Filters/Core/vtkPlaneCutter.cxx +++ b/Filters/Core/vtkPlaneCutter.cxx @@ -1401,9 +1401,8 @@ int vtkPlaneCutter::ExecuteDataSet(vtkDataSet* input, vtkMultiPieceDataSet* outp (numPts = input->GetNumberOfPoints()) < 1) { vtkDebugMacro("No input"); - vtkDataSet* filler = input->NewInstance(); - output->SetPiece(0, filler); - filler->Delete(); + // Empty/no input, we need to initialize output anyway + this->InitializeOutput(output); return 1; } @@ -1468,6 +1467,8 @@ int vtkPlaneCutter::ExecuteDataSet(vtkDataSet* input, vtkMultiPieceDataSet* outp return 1; } + this->InitializeOutput(output); + // Okay we'll be using a sphere tree. The tree's mtime will handle // changes to the input. Delegation occurs to the appropriate // algorithm. @@ -1525,6 +1526,7 @@ int vtkPlaneCutter::ExecuteDataSet(vtkDataSet* input, vtkMultiPieceDataSet* outp return 1; } +//---------------------------------------------------------------------------- void vtkPlaneCutter::AddNormalArray(double* planeNormal, vtkDataSet* ds) { vtkNew<vtkFloatArray> newNormals; @@ -1538,6 +1540,20 @@ void vtkPlaneCutter::AddNormalArray(double* planeNormal, vtkDataSet* ds) ds->GetPointData()->AddArray(newNormals.Get()); } +//---------------------------------------------------------------------------- +void vtkPlaneCutter::InitializeOutput(vtkMultiPieceDataSet* output) +{ + // Initialize the multipiece output with as many filler as needed, + // to have a coherent multipiece output, even in parallel. + int nThreads = vtkSMPTools::GetEstimatedNumberOfThreads(); + output->SetNumberOfPieces(nThreads); + for(int i = 0; i < nThreads; i++) + { + vtkNew<vtkPolyData> filler; + output->SetPiece(i, filler.Get()); + } +} + //---------------------------------------------------------------------------- void vtkPlaneCutter::PrintSelf(ostream& os, vtkIndent indent) { diff --git a/Filters/Core/vtkPlaneCutter.h b/Filters/Core/vtkPlaneCutter.h index d2c52b4c0749777290928665cbceaee492496169..ec69f159228ff93adf8f047a11356213eee8386f 100644 --- a/Filters/Core/vtkPlaneCutter.h +++ b/Filters/Core/vtkPlaneCutter.h @@ -170,6 +170,7 @@ protected: virtual int ExecuteDataSet(vtkDataSet* input, vtkMultiPieceDataSet* output); static void AddNormalArray(double* planeNormal, vtkDataSet* ds); + static void InitializeOutput(vtkMultiPieceDataSet* output); private: vtkPlaneCutter(const vtkPlaneCutter&) VTK_DELETE_FUNCTION;