From 8127093a2fd343ad6beed57b9aa7896d968f20e2 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Thu, 12 Jul 2018 15:34:29 -0600 Subject: [PATCH] Add CellLocator to name of BoundingIntervalHierarchy This will help identify the nature of this object as well as find cell locator implementations. --- vtkm/cont/BoundingIntervalHierarchyNode.h | 62 ------------- vtkm/cont/CMakeLists.txt | 5 +- ...=> CellLocatorBoundingIntervalHierarchy.h} | 15 ++-- ... CellLocatorBoundingIntervalHierarchy.hxx} | 54 ++++++------ vtkm/exec/CMakeLists.txt | 6 +- ...ellLocatorBoundingIntervalHierarchyExec.h} | 86 ++++++++++++------- .../BoundingIntervalHierarchy.h | 4 +- .../UnitTestBoundingIntervalHierarchy.cxx | 5 +- 8 files changed, 104 insertions(+), 133 deletions(-) delete mode 100644 vtkm/cont/BoundingIntervalHierarchyNode.h rename vtkm/cont/{BoundingIntervalHierarchy.h => CellLocatorBoundingIntervalHierarchy.h} (89%) rename vtkm/cont/{BoundingIntervalHierarchy.hxx => CellLocatorBoundingIntervalHierarchy.hxx} (91%) rename vtkm/exec/{BoundingIntervalHierarchyExec.h => CellLocatorBoundingIntervalHierarchyExec.h} (73%) diff --git a/vtkm/cont/BoundingIntervalHierarchyNode.h b/vtkm/cont/BoundingIntervalHierarchyNode.h deleted file mode 100644 index 170e15651..000000000 --- a/vtkm/cont/BoundingIntervalHierarchyNode.h +++ /dev/null @@ -1,62 +0,0 @@ -//============================================================================ -// Copyright (c) Kitware, Inc. -// All rights reserved. -// See LICENSE.txt for details. -// This software is distributed WITHOUT ANY WARRANTY; without even -// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR -// PURPOSE. See the above copyright notice for more information. -// -// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). -// Copyright 2014 UT-Battelle, LLC. -// Copyright 2014 Los Alamos National Security. -// -// Under the terms of Contract DE-NA0003525 with NTESS, -// the U.S. Government retains certain rights in this software. -// -// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National -// Laboratory (LANL), the U.S. Government retains certain rights in -// this software. -//============================================================================ - -#ifndef vtk_m_cont_BoundingIntervalHierarchyNode_h -#define vtk_m_cont_BoundingIntervalHierarchyNode_h - -#include - -namespace vtkm -{ -namespace cont -{ - -struct BoundingIntervalHierarchyNode -{ - vtkm::IdComponent Dimension; - vtkm::Id ParentIndex; - vtkm::Id ChildIndex; - union { - struct - { - vtkm::FloatDefault LMax; - vtkm::FloatDefault RMin; - } Node; - struct - { - vtkm::Id Start; - vtkm::Id Size; - } Leaf; - }; - - VTKM_EXEC_CONT - BoundingIntervalHierarchyNode() - : Dimension() - , ParentIndex() - , ChildIndex() - , Node{ 0, 0 } - { - } -}; // struct BoundingIntervalHierarchyNode - -} // namespace cont -} // namespace vtkm - -#endif // vtk_m_cont_BoundingIntervalHierarchyNode_h diff --git a/vtkm/cont/CMakeLists.txt b/vtkm/cont/CMakeLists.txt index 5a58ad8d2..5a29d7fb3 100644 --- a/vtkm/cont/CMakeLists.txt +++ b/vtkm/cont/CMakeLists.txt @@ -49,11 +49,10 @@ set(headers ArrayRangeCompute.h AssignerMultiBlock.h AtomicArray.h - BoundingIntervalHierarchy.h - BoundingIntervalHierarchyNode.h BoundsCompute.h BoundsGlobalCompute.h CellLocator.h + CellLocatorBoundingIntervalHierarchy.h CellLocatorHelper.h CellLocatorRectilinearGrid.h CellLocatorTwoLevelUniformGrid.h @@ -115,7 +114,7 @@ set(template_sources ArrayHandle.hxx ArrayHandleVirtual.hxx ArrayRangeCompute.hxx - BoundingIntervalHierarchy.hxx + CellLocatorBoundingIntervalHierarchy.hxx CellSetExplicit.hxx CellSetStructured.hxx ColorTable.hxx diff --git a/vtkm/cont/BoundingIntervalHierarchy.h b/vtkm/cont/CellLocatorBoundingIntervalHierarchy.h similarity index 89% rename from vtkm/cont/BoundingIntervalHierarchy.h rename to vtkm/cont/CellLocatorBoundingIntervalHierarchy.h index 5da26e348..c7e4b833a 100644 --- a/vtkm/cont/BoundingIntervalHierarchy.h +++ b/vtkm/cont/CellLocatorBoundingIntervalHierarchy.h @@ -18,14 +18,12 @@ // this software. //============================================================================ -#ifndef vtk_m_cont_BoundingIntervalHierarchy_h -#define vtk_m_cont_BoundingIntervalHierarchy_h +#ifndef vtk_m_cont_CellLocatorBoundingIntervalHierarchy_h +#define vtk_m_cont_CellLocatorBoundingIntervalHierarchy_h #include #include #include - -#include #include #include @@ -35,7 +33,7 @@ namespace vtkm namespace cont { -class BoundingIntervalHierarchy : public vtkm::cont::CellLocator +class CellLocatorBoundingIntervalHierarchy : public vtkm::cont::CellLocator { private: using IdArrayHandle = vtkm::cont::ArrayHandle; @@ -83,7 +81,8 @@ private: public: VTKM_CONT - BoundingIntervalHierarchy(vtkm::IdComponent numPlanes = 4, vtkm::IdComponent maxLeafSize = 5) + CellLocatorBoundingIntervalHierarchy(vtkm::IdComponent numPlanes = 4, + vtkm::IdComponent maxLeafSize = 5) : NumPlanes(numPlanes) , MaxLeafSize(maxLeafSize) , Nodes() @@ -122,7 +121,7 @@ protected: private: vtkm::IdComponent NumPlanes; vtkm::IdComponent MaxLeafSize; - vtkm::cont::ArrayHandle Nodes; + vtkm::cont::ArrayHandle Nodes; IdArrayHandle ProcessedCellIds; mutable HandleType ExecHandle; }; @@ -130,4 +129,4 @@ private: } // namespace cont } // namespace vtkm -#endif // vtk_m_cont_BoundingIntervalHierarchy_h +#endif // vtk_m_cont_CellLocatorBoundingIntervalHierarchy_h diff --git a/vtkm/cont/BoundingIntervalHierarchy.hxx b/vtkm/cont/CellLocatorBoundingIntervalHierarchy.hxx similarity index 91% rename from vtkm/cont/BoundingIntervalHierarchy.hxx rename to vtkm/cont/CellLocatorBoundingIntervalHierarchy.hxx index 967586ac1..a8fad8d01 100644 --- a/vtkm/cont/BoundingIntervalHierarchy.hxx +++ b/vtkm/cont/CellLocatorBoundingIntervalHierarchy.hxx @@ -26,12 +26,12 @@ #include #include #include -#include -#include +#include #include #include -#include -#include +#include +#include +#include #include #include #include @@ -62,7 +62,8 @@ using HandleType = vtkm::cont::VirtualObjectHandle; template VTKM_CONT IdArrayHandle -BoundingIntervalHierarchy::CalculateSegmentSizes(const IdArrayHandle& segmentIds, vtkm::Id numCells) +CellLocatorBoundingIntervalHierarchy::CalculateSegmentSizes(const IdArrayHandle& segmentIds, + vtkm::Id numCells) { using Algorithms = typename vtkm::cont::DeviceAdapterAlgorithm; IdArrayHandle discardKeys; @@ -77,7 +78,8 @@ BoundingIntervalHierarchy::CalculateSegmentSizes(const IdArrayHandle& segmentIds template VTKM_CONT IdArrayHandle -BoundingIntervalHierarchy::GenerateSegmentIds(const IdArrayHandle& segmentSizes, vtkm::Id numCells) +CellLocatorBoundingIntervalHierarchy::GenerateSegmentIds(const IdArrayHandle& segmentSizes, + vtkm::Id numCells) { // Compact segment ids, removing non-contiguous values. using Algorithms = typename vtkm::cont::DeviceAdapterAlgorithm; @@ -92,7 +94,7 @@ BoundingIntervalHierarchy::GenerateSegmentIds(const IdArrayHandle& segmentSizes, } template -VTKM_CONT void BoundingIntervalHierarchy::CalculateSplitCosts( +VTKM_CONT void CellLocatorBoundingIntervalHierarchy::CalculateSplitCosts( RangePermutationArrayHandle& segmentRanges, RangeArrayHandle& ranges, CoordsArrayHandle& coords, @@ -118,7 +120,7 @@ VTKM_CONT void BoundingIntervalHierarchy::CalculateSplitCosts( } template -VTKM_CONT void BoundingIntervalHierarchy::CalculatePlaneSplitCost( +VTKM_CONT void CellLocatorBoundingIntervalHierarchy::CalculatePlaneSplitCost( vtkm::IdComponent planeIndex, vtkm::IdComponent numPlanes, RangePermutationArrayHandle& segmentRanges, @@ -197,10 +199,10 @@ VTKM_CONT void BoundingIntervalHierarchy::CalculatePlaneSplitCost( template VTKM_CONT IdArrayHandle -BoundingIntervalHierarchy::CalculateSplitScatterIndices(const IdArrayHandle& cellIds, - const IdArrayHandle& leqFlags, - const IdArrayHandle& segmentIds, - DeviceAdapter) +CellLocatorBoundingIntervalHierarchy::CalculateSplitScatterIndices(const IdArrayHandle& cellIds, + const IdArrayHandle& leqFlags, + const IdArrayHandle& segmentIds, + DeviceAdapter) { using Algorithms = typename vtkm::cont::DeviceAdapterAlgorithm; vtkm::worklet::Invoker invoker(DeviceAdapter{}); @@ -242,14 +244,14 @@ BoundingIntervalHierarchy::CalculateSplitScatterIndices(const IdArrayHandle& cel return scatterIndices; } -class BoundingIntervalHierarchy::BuildFunctor +class CellLocatorBoundingIntervalHierarchy::BuildFunctor { protected: - BoundingIntervalHierarchy* Self; + CellLocatorBoundingIntervalHierarchy* Self; public: VTKM_CONT - BuildFunctor(BoundingIntervalHierarchy* self) + BuildFunctor(CellLocatorBoundingIntervalHierarchy* self) : Self(self) { } @@ -437,7 +439,7 @@ public: //START_TIMER(s43); // Make a new nodes with enough nodes for the current level, copying over the old one vtkm::Id nodesSize = Self->Nodes.GetNumberOfValues() + numSegments; - vtkm::cont::ArrayHandle newTree; + vtkm::cont::ArrayHandle newTree; newTree.Allocate(nodesSize); Algorithms::CopySubRange(Self->Nodes, 0, Self->Nodes.GetNumberOfValues(), newTree); @@ -480,19 +482,20 @@ public: } }; -class BoundingIntervalHierarchy::PrepareForExecutionFunctor +class CellLocatorBoundingIntervalHierarchy::PrepareForExecutionFunctor { public: template VTKM_CONT bool operator()(DeviceAdapter, - const vtkm::cont::BoundingIntervalHierarchy& bih, + const vtkm::cont::CellLocatorBoundingIntervalHierarchy& bih, HandleType& bihExec) const { vtkm::cont::DynamicCellSet cellSet = bih.GetCellSet(); if (cellSet.IsType>()) { using CellSetType = vtkm::cont::CellSetExplicit<>; - using ExecutionType = vtkm::exec::BoundingIntervalHierarchyExec; + using ExecutionType = + vtkm::exec::CellLocatorBoundingIntervalHierarchyExec; ExecutionType* execObject = new ExecutionType(bih.Nodes, bih.ProcessedCellIds, bih.GetCellSet().Cast(), @@ -503,7 +506,8 @@ public: else if (cellSet.IsType>()) { using CellSetType = vtkm::cont::CellSetStructured<2>; - using ExecutionType = vtkm::exec::BoundingIntervalHierarchyExec; + using ExecutionType = + vtkm::exec::CellLocatorBoundingIntervalHierarchyExec; ExecutionType* execObject = new ExecutionType(bih.Nodes, bih.ProcessedCellIds, bih.GetCellSet().Cast(), @@ -514,7 +518,8 @@ public: else if (cellSet.IsType>()) { using CellSetType = vtkm::cont::CellSetStructured<3>; - using ExecutionType = vtkm::exec::BoundingIntervalHierarchyExec; + using ExecutionType = + vtkm::exec::CellLocatorBoundingIntervalHierarchyExec; ExecutionType* execObject = new ExecutionType(bih.Nodes, bih.ProcessedCellIds, bih.GetCellSet().Cast(), @@ -525,7 +530,8 @@ public: else if (cellSet.IsType>()) { using CellSetType = vtkm::cont::CellSetSingleType<>; - using ExecutionType = vtkm::exec::BoundingIntervalHierarchyExec; + using ExecutionType = + vtkm::exec::CellLocatorBoundingIntervalHierarchyExec; ExecutionType* execObject = new ExecutionType(bih.Nodes, bih.ProcessedCellIds, bih.GetCellSet().Cast(), @@ -542,14 +548,14 @@ public: }; VTKM_CONT -void BoundingIntervalHierarchy::Build() +void CellLocatorBoundingIntervalHierarchy::Build() { BuildFunctor functor(this); vtkm::cont::TryExecute(functor); } VTKM_CONT -const HandleType BoundingIntervalHierarchy::PrepareForExecutionImpl( +const HandleType CellLocatorBoundingIntervalHierarchy::PrepareForExecutionImpl( const vtkm::cont::DeviceAdapterId deviceId) const { const bool success = diff --git a/vtkm/exec/CMakeLists.txt b/vtkm/exec/CMakeLists.txt index 534b31b5b..7d3c79cb0 100644 --- a/vtkm/exec/CMakeLists.txt +++ b/vtkm/exec/CMakeLists.txt @@ -19,17 +19,17 @@ ##============================================================================ set(headers - BoundingIntervalHierarchyExec.h - BoundaryState.h AtomicArrayExecutionObject.h + BoundaryState.h CellDerivative.h CellEdge.h CellFace.h CellInside.h CellInterpolate.h CellLocator.h - CellLocatorUniformGrid.h + CellLocatorBoundingIntervalHierarchyExec.h CellLocatorRectilinearGrid.h + CellLocatorUniformGrid.h CellMeasure.h ColorTable.h ConnectivityExplicit.h diff --git a/vtkm/exec/BoundingIntervalHierarchyExec.h b/vtkm/exec/CellLocatorBoundingIntervalHierarchyExec.h similarity index 73% rename from vtkm/exec/BoundingIntervalHierarchyExec.h rename to vtkm/exec/CellLocatorBoundingIntervalHierarchyExec.h index 75abfb3c9..5976f1494 100644 --- a/vtkm/exec/BoundingIntervalHierarchyExec.h +++ b/vtkm/exec/CellLocatorBoundingIntervalHierarchyExec.h @@ -17,14 +17,13 @@ // Laboratory (LANL), the U.S. Government retains certain rights in // this software. //============================================================================ -#ifndef vtk_m_cont_BoundingIntervalHierarchyExec_h -#define vtk_m_cont_BoundingIntervalHierarchyExec_h +#ifndef vtk_m_cont_CellLocatorBoundingIntervalHierarchyExec_h +#define vtk_m_cont_CellLocatorBoundingIntervalHierarchyExec_h #include #include #include #include -#include #include #include #include @@ -33,31 +32,57 @@ namespace vtkm { namespace exec { -namespace -{ -using NodeArrayHandle = vtkm::cont::ArrayHandle; -using CellIdArrayHandle = vtkm::cont::ArrayHandle; -} // namespace +struct CellLocatorBoundingIntervalHierarchyNode +{ + vtkm::IdComponent Dimension; + vtkm::Id ParentIndex; + vtkm::Id ChildIndex; + union { + struct + { + vtkm::FloatDefault LMax; + vtkm::FloatDefault RMin; + } Node; + struct + { + vtkm::Id Start; + vtkm::Id Size; + } Leaf; + }; + + VTKM_EXEC_CONT + CellLocatorBoundingIntervalHierarchyNode() + : Dimension() + , ParentIndex() + , ChildIndex() + , Node{ 0, 0 } + { + } +}; // struct CellLocatorBoundingIntervalHierarchyNode template -class BoundingIntervalHierarchyExec : public vtkm::exec::CellLocator +class CellLocatorBoundingIntervalHierarchyExec : public vtkm::exec::CellLocator { + using NodeArrayHandle = + vtkm::cont::ArrayHandle; + using CellIdArrayHandle = vtkm::cont::ArrayHandle; + public: VTKM_CONT - BoundingIntervalHierarchyExec() {} + CellLocatorBoundingIntervalHierarchyExec() {} VTKM_CONT - BoundingIntervalHierarchyExec(const NodeArrayHandle& nodes, - const CellIdArrayHandle& cellIds, - const CellSetType& cellSet, - const vtkm::cont::ArrayHandleVirtualCoordinates& coords, - DeviceAdapter) + CellLocatorBoundingIntervalHierarchyExec(const NodeArrayHandle& nodes, + const CellIdArrayHandle& cellIds, + const CellSetType& cellSet, + const vtkm::cont::ArrayHandleVirtualCoordinates& coords, + DeviceAdapter) : Nodes(nodes.PrepareForInput(DeviceAdapter())) , CellIds(cellIds.PrepareForInput(DeviceAdapter())) + , CellSet(cellSet.PrepareForInput(DeviceAdapter(), FromType(), ToType())) + , Coords(coords.PrepareForInput(DeviceAdapter())) { - CellSet = cellSet.PrepareForInput(DeviceAdapter(), FromType(), ToType()); - Coords = coords.PrepareForInput(DeviceAdapter()); } VTKM_EXEC @@ -109,7 +134,7 @@ private: { VTKM_ASSERT(state == FindCellState::EnterNode); - const vtkm::cont::BoundingIntervalHierarchyNode& node = this->Nodes.Get(nodeIndex); + const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node = this->Nodes.Get(nodeIndex); if (node.ChildIndex < 0) { @@ -129,9 +154,11 @@ private: VTKM_ASSERT(state == FindCellState::AscendFromNode); vtkm::Id childNodeIndex = nodeIndex; - const vtkm::cont::BoundingIntervalHierarchyNode& childNode = this->Nodes.Get(childNodeIndex); + const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& childNode = + this->Nodes.Get(childNodeIndex); nodeIndex = childNode.ParentIndex; - const vtkm::cont::BoundingIntervalHierarchyNode& parentNode = this->Nodes.Get(nodeIndex); + const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& parentNode = + this->Nodes.Get(nodeIndex); if (parentNode.ChildIndex == childNodeIndex) { @@ -152,7 +179,7 @@ private: { VTKM_ASSERT(state == FindCellState::DescendLeftChild); - const vtkm::cont::BoundingIntervalHierarchyNode& node = this->Nodes.Get(nodeIndex); + const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node = this->Nodes.Get(nodeIndex); const vtkm::FloatDefault& coordinate = point[node.Dimension]; if (coordinate <= node.Node.LMax) { @@ -174,7 +201,7 @@ private: { VTKM_ASSERT(state == FindCellState::DescendRightChild); - const vtkm::cont::BoundingIntervalHierarchyNode& node = this->Nodes.Get(nodeIndex); + const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node = this->Nodes.Get(nodeIndex); const vtkm::FloatDefault& coordinate = point[node.Dimension]; if (coordinate >= node.Node.RMin) { @@ -191,16 +218,17 @@ private: VTKM_EXEC vtkm::Id FindInLeaf(const vtkm::Vec& point, vtkm::Vec& parametric, - const vtkm::cont::BoundingIntervalHierarchyNode& node, + const vtkm::exec::CellLocatorBoundingIntervalHierarchyNode& node, const vtkm::exec::FunctorBase& worklet) const { using IndicesType = typename CellSetPortal::IndicesType; for (vtkm::Id i = node.Leaf.Start; i < node.Leaf.Start + node.Leaf.Size; ++i) { - vtkm::Id cellId = CellIds.Get(i); - IndicesType cellPointIndices = CellSet.GetIndices(cellId); - vtkm::VecFromPortalPermute cellPoints(&cellPointIndices, Coords); - if (IsPointInCell(point, parametric, CellSet.GetCellShape(cellId), cellPoints, worklet)) + vtkm::Id cellId = this->CellIds.Get(i); + IndicesType cellPointIndices = this->CellSet.GetIndices(cellId); + vtkm::VecFromPortalPermute cellPoints(&cellPointIndices, + this->Coords); + if (IsPointInCell(point, parametric, this->CellSet.GetCellShape(cellId), cellPoints, worklet)) { return cellId; } @@ -235,10 +263,10 @@ private: CellIdPortal CellIds; CellSetPortal CellSet; CoordsPortal Coords; -}; // class BoundingIntervalHierarchyExec +}; // class CellLocatorBoundingIntervalHierarchyExec } // namespace exec } // namespace vtkm -#endif //vtk_m_cont_BoundingIntervalHierarchyExec_h +#endif //vtk_m_cont_CellLocatorBoundingIntervalHierarchyExec_h diff --git a/vtkm/worklet/spatialstructure/BoundingIntervalHierarchy.h b/vtkm/worklet/spatialstructure/BoundingIntervalHierarchy.h index bae1e2b97..e08b8079c 100644 --- a/vtkm/worklet/spatialstructure/BoundingIntervalHierarchy.h +++ b/vtkm/worklet/spatialstructure/BoundingIntervalHierarchy.h @@ -31,9 +31,9 @@ #include #include #include -#include #include #include +#include #include #include #include @@ -533,7 +533,7 @@ struct TreeLevelAdder : public vtkm::worklet::WorkletMapField BoundingIntervalHierarchyPortal& treePortal, NextParentPortal& nextParentPortal) const { - vtkm::cont::BoundingIntervalHierarchyNode node; + vtkm::exec::CellLocatorBoundingIntervalHierarchyNode node; node.ParentIndex = parentIndex; if (count > this->MaxLeafSize) { diff --git a/vtkm/worklet/testing/UnitTestBoundingIntervalHierarchy.cxx b/vtkm/worklet/testing/UnitTestBoundingIntervalHierarchy.cxx index b9371b1d7..00a9994b6 100644 --- a/vtkm/worklet/testing/UnitTestBoundingIntervalHierarchy.cxx +++ b/vtkm/worklet/testing/UnitTestBoundingIntervalHierarchy.cxx @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include #include @@ -79,7 +79,8 @@ void TestBoundingIntervalHierarchy(vtkm::cont::DataSet dataSet, std::cout << "Using numPlanes: " << numPlanes << "\n"; std::cout << "Building Bounding Interval Hierarchy Tree" << std::endl; - vtkm::cont::BoundingIntervalHierarchy bih = vtkm::cont::BoundingIntervalHierarchy(numPlanes, 5); + vtkm::cont::CellLocatorBoundingIntervalHierarchy bih = + vtkm::cont::CellLocatorBoundingIntervalHierarchy(numPlanes, 5); bih.SetCellSet(cellSet); bih.SetCoordinates(dataSet.GetCoordinateSystem()); bih.Update();