Commit 9f150a78 authored by Spiros Tsalikis's avatar Spiros Tsalikis
Browse files

vtkTemporalInterpolatedVelocityField: Use cached Locator if possible

parent b78324f5
......@@ -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();
......
......@@ -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<size_t>(ps->GetNumberOfCells()));
this->Weights.resize(8);
......
......@@ -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())
......
......@@ -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();
}
}
}
}
......
......@@ -123,25 +123,34 @@ void vtkTemporalInterpolatedVelocityField::CreateLocators(const std::vector<vtkD
locators.reserve(datasets.size());
for (const auto& dataset : datasets)
{
if (vtkPointSet::SafeDownCast(dataset))
if (auto pointSet = vtkPointSet::SafeDownCast(dataset))
{
if (vtkCellLocatorStrategy::SafeDownCast(strategy))
{
auto cellLocator = vtkSmartPointer<vtkStaticCellLocator>::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<vtkStaticPointLocator>::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::vector<vtkData
{
if (auto ugrid = vtkUnstructuredGrid::SafeDownCast(dataset))
{
ugrid->BuildLinks();
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<vtkDataSet*>& datasets,
vtkFindCellStrategy* strategy, const std::vector<vtkSmartPointer<vtkLocator>>& locators,
const std::vector<vtkSmartPointer<vtkAbstractCellLinks>>& datasetLinks)
const std::vector<vtkSmartPointer<vtkAbstractCellLinks>>& 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]));
}
}
}
......
......@@ -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 <vector> // Because they are good
#include <vector> // For internal structures
class vtkAbstractCellLinks;
class vtkCompositeDataSet;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment