diff --git a/Common/DataModel/vtkAbstractCellLocator.cxx b/Common/DataModel/vtkAbstractCellLocator.cxx index 72b3398fd84e0ee3b0b76b93ccfc6c735379abb5..7d10a5be8ec088e2b110b96a5a888e064f2fdb77 100644 --- a/Common/DataModel/vtkAbstractCellLocator.cxx +++ b/Common/DataModel/vtkAbstractCellLocator.cxx @@ -79,6 +79,16 @@ void vtkAbstractCellLocator::FreeCellBounds() this->CellBounds = nullptr; } +//------------------------------------------------------------------------------ +void vtkAbstractCellLocator::ComputeCellBounds() +{ + if (this->CacheCellBounds) + { + this->FreeCellBounds(); + this->StoreCellBounds(); + } +} + //------------------------------------------------------------------------------ void vtkAbstractCellLocator::UpdateInternalWeights() { diff --git a/Common/DataModel/vtkAbstractCellLocator.h b/Common/DataModel/vtkAbstractCellLocator.h index c236aea552d4db4b8b8774066b0030c9bb827206..450ea958cec7e5a76901a9ffa0a2856c3cbe7e09 100644 --- a/Common/DataModel/vtkAbstractCellLocator.h +++ b/Common/DataModel/vtkAbstractCellLocator.h @@ -80,6 +80,12 @@ public: vtkBooleanMacro(CacheCellBounds, vtkTypeBool); ///@} + /** + * This function can be used either internally or externally to compute only the cached + * cell bounds if CacheCellBounds is on. + */ + void ComputeCellBounds(); + ///@{ /** * Boolean controls whether to maintain list of cells in each node. diff --git a/Common/DataModel/vtkCellLocator.cxx b/Common/DataModel/vtkCellLocator.cxx index 766d420ea08f75284f3f415eec1cc4e2698b6c19..96f3ececb401b7b8a463c3fac317f51b57c34e0b 100644 --- a/Common/DataModel/vtkCellLocator.cxx +++ b/Common/DataModel/vtkCellLocator.cxx @@ -791,11 +791,7 @@ void vtkCellLocator::BuildLocatorInternal() std::make_shared>>(numOctants, nullptr); this->Tree = TreeSharedPtr->data(); - if (this->CacheCellBounds) - { - this->FreeCellBounds(); - this->StoreCellBounds(); - } + this->ComputeCellBounds(); // Compute width of leaf octant in three directions for (i = 0; i < 3; i++) diff --git a/Common/DataModel/vtkCellLocatorStrategy.cxx b/Common/DataModel/vtkCellLocatorStrategy.cxx index b1a2d079661b73f16e1c4f8dcf9dddcf29e971e6..14252ad5595b1615788e270dfc0382ac33494a4a 100644 --- a/Common/DataModel/vtkCellLocatorStrategy.cxx +++ b/Common/DataModel/vtkCellLocatorStrategy.cxx @@ -98,8 +98,11 @@ int vtkCellLocatorStrategy::Initialize(vtkPointSet* ps) } else { - this->CellLocator = psCL; - this->OwnsLocator = false; + if (psCL != this->CellLocator) + { + this->CellLocator = psCL; + this->OwnsLocator = false; + } } this->InitializeTime.Modified(); diff --git a/Common/DataModel/vtkCellTreeLocator.cxx b/Common/DataModel/vtkCellTreeLocator.cxx index 353cbc34d0e23fee0af5b2526c8272d763ef2f0c..d3095a3ff8ec10ba5d130bb859b236dd0a31e1bf 100644 --- a/Common/DataModel/vtkCellTreeLocator.cxx +++ b/Common/DataModel/vtkCellTreeLocator.cxx @@ -70,7 +70,7 @@ struct vtkCellTree virtual void FindCellsWithinBounds(double* bbox, vtkIdList* cells) = 0; virtual int IntersectWithLine(const double a0[3], const double a1[3], double tol, double& t, double x[3], double pcoords[3], int& subId, vtkIdType& cellId, vtkGenericCell* cell) = 0; - virtual int IntersectWithLine(const double p1[3], const double p2[3], const double tol, + virtual int IntersectWithLine(const double p1[3], const double p2[3], double tol, vtkPoints* points, vtkIdList* cellIds, vtkGenericCell* cell) = 0; virtual void GenerateRepresentation(int level, vtkPolyData* pd) = 0; @@ -1346,11 +1346,7 @@ void vtkCellTreeLocator::BuildLocatorInternal() return; } this->FreeSearchStructure(); - if (this->CacheCellBounds) - { - this->FreeCellBounds(); - this->StoreCellBounds(); - } + this->ComputeCellBounds(); // Create sorted cell fragments tuples of (cellId,binId). Depending // on problem size, different types are used. if (numCells >= VTK_INT_MAX) diff --git a/Common/DataModel/vtkClosestPointStrategy.cxx b/Common/DataModel/vtkClosestPointStrategy.cxx index 6dd17588f335d8fcdc7a2dbe5172665676b6dc25..33bb41bd162fa74998563f672330441aea7a98fa 100644 --- a/Common/DataModel/vtkClosestPointStrategy.cxx +++ b/Common/DataModel/vtkClosestPointStrategy.cxx @@ -104,8 +104,11 @@ int vtkClosestPointStrategy::Initialize(vtkPointSet* ps) } else { - this->PointLocator = psPL; - this->OwnsLocator = false; + if (psPL != this->PointLocator) + { + this->PointLocator = psPL; + this->OwnsLocator = false; + } } this->VisitedCells.resize(static_cast(ps->GetNumberOfCells())); this->Weights.resize(8); diff --git a/Common/DataModel/vtkLinearTransformCellLocator.h b/Common/DataModel/vtkLinearTransformCellLocator.h index 78b3e4ba2cc6d9e92df12c444f7640ecb143722c..4f82adff6c78f9bc7f678f50bb1fb6f69564dc7e 100644 --- a/Common/DataModel/vtkLinearTransformCellLocator.h +++ b/Common/DataModel/vtkLinearTransformCellLocator.h @@ -21,15 +21,15 @@ * vtkStaticCellLocator, vtkCellLocator, calculate the transformation matrix from the cell * locator adaptor's dataset to the given dataset inside BuildLocator, and then use the cell locator * and transformation to perform cell locator operations. The transformation matrix is computed - * using the https://en.wikipedia.org/wiki/Kabsch_algorithm. UseAllPoints allows to compute the - * transformation using all the points of the dataset (use that when you are not if it's a linear - * transformation) or 100 sample points (or less if the dataset is smaller) that are chosen + * using the https://en.wikipedia.org/wiki/Kabsch_algorithm. UseAllPoints allows you to compute the + * transformation using all the points of the dataset (use that when you are not sure if it's a + * linear transformation) or 100 sample points (or less if the dataset is smaller) that are chosen * every-nth. IsLinearTransformation validates if the dataset is a linear transformation of the cell * locator's dataset based on the used points. * * @warning The cell locator adaptor MUST be built before using it. * - * vtkCellTreeLocator does NOT utilize ANY vtkLocator/vtkAbstractCellLocator parameter: + * vtkLinearTransformCellLocator does NOT utilize ANY vtkLocator/vtkAbstractCellLocator parameter: * * @sa * vtkAbstractCellLocator vtkCellLocator vtkStaticCellLocator vtkCellTreeLocator vtkModifiedBSPTree diff --git a/Common/DataModel/vtkPointSet.cxx b/Common/DataModel/vtkPointSet.cxx index 777b9eb3a4c442de697e36cf2ebd9a43dcdcbf55..eb375f2322d23f754e763c9c48b5ebab47721117 100644 --- a/Common/DataModel/vtkPointSet.cxx +++ b/Common/DataModel/vtkPointSet.cxx @@ -199,8 +199,6 @@ void vtkPointSet::BuildCellLocator() { this->CellLocator = vtkStaticCellLocator::New(); } - this->CellLocator->Register(this); - this->CellLocator->Delete(); this->CellLocator->SetDataSet(this); } else if (this->Points->GetMTime() > this->CellLocator->GetMTime()) diff --git a/Filters/Core/vtkPointDataToCellData.cxx b/Filters/Core/vtkPointDataToCellData.cxx index ca093f7b9bc50e14b926e714c48a01962d801609..1f4b1748b2ef267fe403d5d2e7d158c077402ffd 100644 --- a/Filters/Core/vtkPointDataToCellData.cxx +++ b/Filters/Core/vtkPointDataToCellData.cxx @@ -365,8 +365,7 @@ int vtkPointDataToCellData::RequestData( vtkInformation* inInfo = inputVector[0]->GetInformationObject(0); vtkDataSet* input = vtkDataSet::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT())); - vtkIdType cellId, ptId, pointId; - vtkIdType numCells, numPts; + vtkIdType numCells; vtkPointData* inputInPD = input->GetPointData(); vtkSmartPointer inPD; vtkCellData* outCD = output->GetCellData(); diff --git a/Filters/FlowPaths/Testing/Cxx/TestStreamTracer.cxx b/Filters/FlowPaths/Testing/Cxx/TestStreamTracer.cxx index f6d067c612f47f4a7c57f8562d27023403bdbea5..d96fcac1d68977df095c57f27ebcf4e0aade48e7 100644 --- a/Filters/FlowPaths/Testing/Cxx/TestStreamTracer.cxx +++ b/Filters/FlowPaths/Testing/Cxx/TestStreamTracer.cxx @@ -1,7 +1,7 @@ /*========================================================================= Program: Visualization Toolkit - Module: TestParticleTracers.cxx + Module: TestStreamTracer.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. diff --git a/Filters/FlowPaths/vtkAbstractInterpolatedVelocityField.cxx b/Filters/FlowPaths/vtkAbstractInterpolatedVelocityField.cxx index 6d9c6728c96851b55c73d3071a6b0d173298dcc5..26116a15b5dab4ec9b159eac3bf0fe5443590260 100644 --- a/Filters/FlowPaths/vtkAbstractInterpolatedVelocityField.cxx +++ b/Filters/FlowPaths/vtkAbstractInterpolatedVelocityField.cxx @@ -157,16 +157,26 @@ void vtkAbstractInterpolatedVelocityField::Initialize(vtkCompositeDataSet* compD for (auto& datasetInfo : this->DataSetsInfo) { datasetInfo.DataSet->ComputeBounds(); + if (auto polyData = vtkPolyData::SafeDownCast(datasetInfo.DataSet)) + { + // build cells is needed for both vtkClosestPointStrategy and vtkCellLocatorStrategy + polyData->BuildCells(); + } if (vtkClosestPointStrategy::SafeDownCast(datasetInfo.Strategy)) { if (auto ugrid = vtkUnstructuredGrid::SafeDownCast(datasetInfo.DataSet)) { - ugrid->BuildLinks(); + if (ugrid->GetLinks() == nullptr) + { + ugrid->BuildLinks(); + } } else if (auto polyData = vtkPolyData::SafeDownCast(datasetInfo.DataSet)) { - // Build links calls BuildCells internally - polyData->BuildLinks(); + if (polyData->GetLinks() == nullptr) + { + polyData->BuildLinks(); + } } } } diff --git a/Filters/FlowPaths/vtkModifiedBSPTree.cxx b/Filters/FlowPaths/vtkModifiedBSPTree.cxx index efe5b2b68b5dbfa0efd18668c3ae136d9e80e084..5bcbae7be24a4c66ed0e17f744da3f94365908dd 100644 --- a/Filters/FlowPaths/vtkModifiedBSPTree.cxx +++ b/Filters/FlowPaths/vtkModifiedBSPTree.cxx @@ -156,11 +156,7 @@ void vtkModifiedBSPTree::BuildLocatorInternal() this->mRoot->mAxis = rand() % 3; this->mRoot->depth = 0; - if (this->CacheCellBounds) - { - this->FreeCellBounds(); - this->StoreCellBounds(); - } + this->ComputeCellBounds(); // sort the cells into 6 lists using structure for subdividing tests Sorted_cell_extents_Lists* lists = new Sorted_cell_extents_Lists(numCells); diff --git a/Filters/FlowPaths/vtkParticleTracerBase.cxx b/Filters/FlowPaths/vtkParticleTracerBase.cxx index 54b82a7e679fd3a360e3d2968f8a536f821dd830..03fd472e0127bf352d21e004dee6ace8e2178df7 100644 --- a/Filters/FlowPaths/vtkParticleTracerBase.cxx +++ b/Filters/FlowPaths/vtkParticleTracerBase.cxx @@ -370,10 +370,25 @@ int vtkParticleTracerBase::RequestUpdateExtent(vtkInformation* vtkNotUsed(reques return 1; } +//------------------------------------------------------------------------------ +void vtkParticleTracerBase::SetMeshOverTime(int meshOverTime) +{ + if (this->MeshOverTime != + (meshOverTime < DIFFERENT ? DIFFERENT + : (meshOverTime > SAME_TOPOLOGY ? SAME_TOPOLOGY : meshOverTime))) + { + this->MeshOverTime = + (meshOverTime < DIFFERENT ? DIFFERENT + : (meshOverTime > SAME_TOPOLOGY ? SAME_TOPOLOGY : meshOverTime)); + this->Modified(); + // Needed since the value needs to be set at the same time. + this->Interpolator->SetMeshOverTime(this->MeshOverTime); + } +} + //------------------------------------------------------------------------------ void vtkParticleTracerBase::SetInterpolatorType(int interpolatorType) { - this->Interpolator->SetMeshOverTime(this->MeshOverTime); if (interpolatorType == INTERPOLATOR_WITH_CELL_LOCATOR) { // create an interpolator equipped with a cell locator (by default) @@ -431,7 +446,7 @@ int vtkParticleTracerBase::InitializeInterpolator() return VTK_ERROR; } - // create Interpolator if needed + // set strategy if needed if (this->Interpolator->GetFindCellStrategy() == nullptr) { // cell locator is the default; @@ -838,7 +853,7 @@ void vtkParticleTracerBase::ResizeArrays(vtkIdType numTuples) { // resize first so that if you already have data, you don't lose them this->OutputCoordinates->Resize(numTuples); - this->ParticleCellsOffsets->Resize(numTuples); + this->ParticleCellsOffsets->Resize(numTuples + 1); this->ParticleCellsConnectivity->Resize(numTuples); for (int i = 0; i < this->OutputPointData->GetNumberOfArrays(); ++i) { @@ -846,7 +861,7 @@ void vtkParticleTracerBase::ResizeArrays(vtkIdType numTuples) } // set number number of tuples because resize does not do that this->OutputCoordinates->SetNumberOfPoints(numTuples); - this->ParticleCellsOffsets->SetNumberOfValues(numTuples); + this->ParticleCellsOffsets->SetNumberOfValues(numTuples + 1); this->ParticleCellsConnectivity->SetNumberOfValues(numTuples); this->OutputPointData->SetNumberOfTuples(numTuples); } @@ -882,6 +897,7 @@ vtkPolyData* vtkParticleTracerBase::Execute(vtkInformationVector** inputVector) vtkDebugMacro(<< "About to allocate arrays "); this->OutputCoordinates = vtkSmartPointer::New(); this->ParticleCellsOffsets = vtkSmartPointer::New(); + this->ParticleCellsOffsets->InsertNextValue(0); this->ParticleCellsConnectivity = vtkSmartPointer::New(); this->ParticleCells = vtkSmartPointer::New(); @@ -1676,7 +1692,7 @@ void vtkParticleTracerBase::SetParticle(vtkParticleTracerBaseNamespace::Particle const double* coord = info.CurrentPosition.x; this->OutputCoordinates->SetPoint(particleId, coord); // create the cell - this->ParticleCellsOffsets->SetValue(particleId, particleId + 1); + this->ParticleCellsOffsets->SetValue(particleId + 1, particleId + 1); this->ParticleCellsConnectivity->SetValue(particleId, particleId); // set the easy scalars for this particle this->ParticleIds->SetValue(particleId, info.UniqueParticleId); diff --git a/Filters/FlowPaths/vtkParticleTracerBase.h b/Filters/FlowPaths/vtkParticleTracerBase.h index 1e9c49e8bf9de6c656fc996e739ab0d4bf63f16b..1925c875daa08e52e17ed0d3b5e73551d35450e4 100644 --- a/Filters/FlowPaths/vtkParticleTracerBase.h +++ b/Filters/FlowPaths/vtkParticleTracerBase.h @@ -229,7 +229,9 @@ public: * LINEAR_TRANSFORMATION = 2 * SAME_TOPOLOGY = 3 */ - vtkSetClampMacro(MeshOverTime, int, DIFFERENT, LINEAR_TRANSFORMATION); + virtual void SetMeshOverTime(int meshOverTime); + virtual int GetMeshOverTimeMinValue() { return DIFFERENT; } + virtual int GetMeshOverTimeMaxValue() { return SAME_TOPOLOGY; } void SetMeshOverTimeToDifferent() { this->SetMeshOverTime(DIFFERENT); } void SetMeshOverTimeToStatic() { this->SetMeshOverTime(STATIC); } void SetMeshOverTimeToLinearTransformation() { this->SetMeshOverTime(LINEAR_TRANSFORMATION); } diff --git a/Filters/FlowPaths/vtkTemporalInterpolatedVelocityField.cxx b/Filters/FlowPaths/vtkTemporalInterpolatedVelocityField.cxx index b6e43b55f5d039752617b54a21afa0a8ca402bf1..2d69edea41276ca90fb2f7081eff9a880c1b63ab 100644 --- a/Filters/FlowPaths/vtkTemporalInterpolatedVelocityField.cxx +++ b/Filters/FlowPaths/vtkTemporalInterpolatedVelocityField.cxx @@ -123,25 +123,34 @@ void vtkTemporalInterpolatedVelocityField::CreateLocators(const std::vector::New(); - cellLocator->SetDataSet(dataset); - cellLocator->CacheCellBoundsOn(); + if (!pointSet->GetCellLocator()) + { + pointSet->BuildCellLocator(); + } + auto cellLocator = pointSet->GetCellLocator(); + // if cache cell bounds were not on, enable them and compute cell bounds + if (cellLocator->GetCacheCellBounds() == 0) + { + cellLocator->CacheCellBoundsOn(); + cellLocator->ComputeCellBounds(); + } cellLocator->SetUseExistingSearchStructure( this->MeshOverTime != MeshOverTimeTypes::DIFFERENT); - cellLocator->BuildLocator(); locators.emplace_back(cellLocator); } else // vtkClosestPointStrategy { - auto pointLocator = vtkSmartPointer::New(); - pointLocator->SetDataSet(dataset); + if (!pointSet->GetPointLocator()) + { + pointSet->BuildPointLocator(); + } + auto pointLocator = pointSet->GetPointLocator(); pointLocator->SetUseExistingSearchStructure( this->MeshOverTime != MeshOverTimeTypes::DIFFERENT); - pointLocator->BuildLocator(); locators.emplace_back(pointLocator); } } @@ -164,12 +173,19 @@ void vtkTemporalInterpolatedVelocityField::CreateLinks(const std::vectorBuildLinks(); + if (ugrid->GetLinks() == nullptr) + { + ugrid->BuildLinks(); + } datasetLinks.emplace_back(ugrid->GetLinks()); } else if (auto polyData = vtkPolyData::SafeDownCast(dataset)) { - polyData->BuildLinks(); + if (polyData->GetLinks() == nullptr) + { + // Build links calls BuildCells internally + polyData->BuildLinks(); + } datasetLinks.emplace_back(polyData->GetLinks()); } } @@ -206,7 +222,7 @@ void vtkTemporalInterpolatedVelocityField::CreateLinearTransformCellLocators( void vtkTemporalInterpolatedVelocityField::InitializeWithLocators( vtkCompositeInterpolatedVelocityField* ivf, const std::vector& datasets, vtkFindCellStrategy* strategy, const std::vector>& locators, - const std::vector>& datasetLinks) + const std::vector>& links) { // Clear the datasets info, subclasses may want to put stuff into it. ivf->DataSetsInfo.clear(); @@ -269,17 +285,18 @@ void vtkTemporalInterpolatedVelocityField::InitializeWithLocators( datasetInfo.DataSet->ComputeBounds(); if (auto polyData = vtkPolyData::SafeDownCast(datasetInfo.DataSet)) { + // build cells is needed for both vtkClosestPointStrategy and vtkCellLocatorStrategy polyData->BuildCells(); } if (vtkClosestPointStrategy::SafeDownCast(datasetInfo.Strategy)) { if (auto ugrid = vtkUnstructuredGrid::SafeDownCast(datasetInfo.DataSet)) { - ugrid->SetLinks(datasetLinks[i]); + ugrid->SetLinks(links[i]); } else if (auto polyData = vtkPolyData::SafeDownCast(datasetInfo.DataSet)) { - polyData->SetLinks(vtkCellLinks::SafeDownCast(datasetLinks[i])); + polyData->SetLinks(vtkCellLinks::SafeDownCast(links[i])); } } } diff --git a/Filters/FlowPaths/vtkTemporalInterpolatedVelocityField.h b/Filters/FlowPaths/vtkTemporalInterpolatedVelocityField.h index d80f51899c9888aac7597b0ca591582d5a962f28..05502df33b8f23c2e0415405c588aaad16e8f372 100644 --- a/Filters/FlowPaths/vtkTemporalInterpolatedVelocityField.h +++ b/Filters/FlowPaths/vtkTemporalInterpolatedVelocityField.h @@ -50,9 +50,9 @@ #include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_2_0 #include "vtkFiltersFlowPathsModule.h" // For export macro #include "vtkFunctionSet.h" -#include "vtkSmartPointer.h" // because it is good +#include "vtkSmartPointer.h" // For vtkSmartPointer -#include // Because they are good +#include // For internal structures class vtkAbstractCellLinks; class vtkCompositeDataSet; @@ -108,7 +108,7 @@ public: * LINEAR_TRANSFORMATION = 2 * SAME_TOPOLOGY = 3 */ - vtkSetClampMacro(MeshOverTime, int, DIFFERENT, LINEAR_TRANSFORMATION); + vtkSetClampMacro(MeshOverTime, int, DIFFERENT, SAME_TOPOLOGY); void SetMeshOverTimeToDifferent() { this->SetMeshOverTime(DIFFERENT); } void SetMeshOverTimeToStatic() { this->SetMeshOverTime(STATIC); } void SetMeshOverTimeToLinearTransformation() { this->SetMeshOverTime(LINEAR_TRANSFORMATION); }