mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-10-05 01:49:02 +00:00
Merge topic 'uniformbin_locator_bincheck'
b6c69774f Add comment addressing the missing else 7fb1821b7 Fix issue (findBinIdx won't fail if point outside dataset). 699646675 Merge branch 'master' of https://gitlab.kitware.com/vtk/vtk-m into uniformbin_locator_bincheck c06173274 Add helper methods. Check the binIdx FIRST. 9fb58dcf1 Optimize cellID bin check. Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !3130
This commit is contained in:
commit
6e8308f2bb
@ -89,26 +89,38 @@ public:
|
||||
vtkm::Vec3f& parametric,
|
||||
LastCell& lastCell) const
|
||||
{
|
||||
//See if point is inside the last cell.
|
||||
vtkm::Vec3f pc;
|
||||
if ((lastCell.CellId >= 0) && (lastCell.CellId < this->CellSet.GetNumberOfElements()) &&
|
||||
this->PointInCell(point, lastCell.CellId, pc) == vtkm::ErrorCode::Success)
|
||||
{
|
||||
parametric = pc;
|
||||
cellId = lastCell.CellId;
|
||||
return vtkm::ErrorCode::Success;
|
||||
}
|
||||
vtkm::Id binIdx = this->FindBinIdx(point);
|
||||
|
||||
//See if it's in the last bin.
|
||||
if ((lastCell.BinIdx >= 0) && (lastCell.BinIdx < this->CellIds.GetNumberOfValues()) &&
|
||||
this->PointInBin(point, lastCell.BinIdx, cellId, pc) == vtkm::ErrorCode::Success)
|
||||
if (binIdx == -1)
|
||||
{
|
||||
parametric = pc;
|
||||
lastCell.CellId = cellId;
|
||||
return vtkm::ErrorCode::Success;
|
||||
lastCell.CellId = -1;
|
||||
lastCell.BinIdx = -1;
|
||||
cellId = -1;
|
||||
return vtkm::ErrorCode::CellNotFound;
|
||||
}
|
||||
//See if the point is still in the same bin.
|
||||
else if (binIdx == lastCell.BinIdx && this->LastCellValid(lastCell))
|
||||
{
|
||||
vtkm::Vec3f pc;
|
||||
//Check the last cell first.
|
||||
if (this->PointInCell(point, lastCell.CellId, pc))
|
||||
{
|
||||
parametric = pc;
|
||||
cellId = lastCell.CellId;
|
||||
return vtkm::ErrorCode::Success;
|
||||
}
|
||||
//Otherwise, check cells in the bin, but skip lastCell.CellId
|
||||
else if (this->PointInBin(point, lastCell.BinIdx, cellId, pc, lastCell.CellId))
|
||||
{
|
||||
parametric = pc;
|
||||
return vtkm::ErrorCode::Success;
|
||||
}
|
||||
}
|
||||
//if cell still not found, drop to the general find cell below.
|
||||
|
||||
return this->FindCellImpl(point, cellId, parametric, lastCell);
|
||||
//LastCell not initialized, or not in the same bin: do a full test.
|
||||
//Since already computed the binIdx, re-use it.
|
||||
return this->FindCellImpl(point, cellId, parametric, lastCell, binIdx);
|
||||
}
|
||||
|
||||
VTKM_DEPRECATED(1.6, "Locators are no longer pointers. Use . operator.")
|
||||
@ -117,6 +129,30 @@ public:
|
||||
VTKM_EXEC const CellLocatorUniformBins* operator->() const { return this; }
|
||||
|
||||
private:
|
||||
VTKM_EXEC vtkm::Id FindBinIdx(const vtkm::Vec3f& point) const
|
||||
{
|
||||
if (!this->IsInside(point))
|
||||
return -1;
|
||||
|
||||
vtkm::Vec3f temp;
|
||||
temp = point - this->Origin;
|
||||
temp = temp * this->InvSpacing;
|
||||
|
||||
//make sure that if we border the upper edge, we sample the correct cell
|
||||
vtkm::Id3 logicalCell = vtkm::Min(vtkm::Id3(temp), this->MaxCellIds);
|
||||
|
||||
vtkm::Id binIdx =
|
||||
(logicalCell[2] * this->CellDims[1] + logicalCell[1]) * this->CellDims[0] + logicalCell[0];
|
||||
|
||||
return binIdx;
|
||||
}
|
||||
|
||||
VTKM_EXEC bool LastCellValid(const LastCell& lastCell) const
|
||||
{
|
||||
return lastCell.BinIdx >= 0 && lastCell.BinIdx < this->CellIds.GetNumberOfValues() &&
|
||||
lastCell.CellId >= 0 && lastCell.CellId < this->CellSet.GetNumberOfElements();
|
||||
}
|
||||
|
||||
VTKM_EXEC bool IsInside(const vtkm::Vec3f& point) const
|
||||
{
|
||||
if (point[0] < this->Origin[0] || point[0] > this->MaxPoint[0])
|
||||
@ -133,32 +169,29 @@ private:
|
||||
vtkm::ErrorCode FindCellImpl(const vtkm::Vec3f& point,
|
||||
vtkm::Id& cellId,
|
||||
vtkm::Vec3f& parametric,
|
||||
LastCell& lastCell) const
|
||||
LastCell& lastCell,
|
||||
vtkm::Id ptBinIdx = -1) const
|
||||
{
|
||||
lastCell.CellId = -1;
|
||||
lastCell.BinIdx = -1;
|
||||
|
||||
if (!this->IsInside(point))
|
||||
//if ptBinIdx is set, use it. Otherwise, compute the bin idx.
|
||||
vtkm::Id binIdx = -1;
|
||||
if (ptBinIdx == -1)
|
||||
binIdx = this->FindBinIdx(point);
|
||||
else
|
||||
binIdx = ptBinIdx;
|
||||
|
||||
//point not in a bin. return not found.
|
||||
if (binIdx == -1)
|
||||
{
|
||||
cellId = -1;
|
||||
return vtkm::ErrorCode::CellNotFound;
|
||||
}
|
||||
|
||||
//Find the bin containing the point.
|
||||
vtkm::Id3 logicalCell(0, 0, 0);
|
||||
|
||||
vtkm::Vec3f temp;
|
||||
temp = point - this->Origin;
|
||||
temp = temp * this->InvSpacing;
|
||||
|
||||
//make sure that if we border the upper edge, we sample the correct cell
|
||||
logicalCell = vtkm::Min(vtkm::Id3(temp), this->MaxCellIds);
|
||||
|
||||
vtkm::Id binIdx =
|
||||
(logicalCell[2] * this->CellDims[1] + logicalCell[1]) * this->CellDims[0] + logicalCell[0];
|
||||
|
||||
//search cells in the bin.
|
||||
vtkm::Vec3f pc;
|
||||
if (this->PointInBin(point, binIdx, cellId, pc) == vtkm::ErrorCode::Success)
|
||||
if (this->PointInBin(point, binIdx, cellId, pc))
|
||||
{
|
||||
parametric = pc;
|
||||
lastCell.CellId = cellId;
|
||||
@ -207,32 +240,31 @@ private:
|
||||
}
|
||||
|
||||
VTKM_EXEC
|
||||
vtkm::ErrorCode PointInBin(const vtkm::Vec3f& point,
|
||||
const vtkm::Id& binIdx,
|
||||
vtkm::Id& cellId,
|
||||
vtkm::Vec3f& parametric) const
|
||||
bool PointInBin(const vtkm::Vec3f& point,
|
||||
const vtkm::Id& binIdx,
|
||||
vtkm::Id& cellId,
|
||||
vtkm::Vec3f& parametric,
|
||||
const vtkm::Id& skipCellId = -1) const
|
||||
{
|
||||
auto binIds = this->CellIds.Get(binIdx);
|
||||
|
||||
vtkm::Vec3f pc;
|
||||
for (vtkm::IdComponent i = 0; i < binIds.GetNumberOfComponents(); i++)
|
||||
{
|
||||
vtkm::Id cid = binIds[i];
|
||||
vtkm::Vec3f pc;
|
||||
if (this->PointInCell(point, cid, pc) == vtkm::ErrorCode::Success)
|
||||
if (cid != skipCellId && this->PointInCell(point, cid, pc))
|
||||
{
|
||||
cellId = cid;
|
||||
parametric = pc;
|
||||
return vtkm::ErrorCode::Success;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return vtkm::ErrorCode::CellNotFound;
|
||||
return false;
|
||||
}
|
||||
|
||||
VTKM_EXEC
|
||||
vtkm::ErrorCode PointInCell(const vtkm::Vec3f& point,
|
||||
const vtkm::Id& cid,
|
||||
vtkm::Vec3f& parametric) const
|
||||
bool PointInCell(const vtkm::Vec3f& point, const vtkm::Id& cid, vtkm::Vec3f& parametric) const
|
||||
{
|
||||
auto indices = this->CellSet.GetIndices(cid);
|
||||
auto pts = vtkm::make_VecFromPortalPermute(&indices, this->Coords);
|
||||
@ -242,10 +274,10 @@ private:
|
||||
if (status == vtkm::ErrorCode::Success && inside)
|
||||
{
|
||||
parametric = pc;
|
||||
return vtkm::ErrorCode::Success;
|
||||
return true;
|
||||
}
|
||||
|
||||
return vtkm::ErrorCode::CellNotFound;
|
||||
return false;
|
||||
}
|
||||
|
||||
vtkm::Id3 CellDims;
|
||||
|
Loading…
Reference in New Issue
Block a user