Add BoundsCompute
and BoundsGlobalCompute
Adding compute function to compute local and global bounds for datasets and multiblocks alike.
This commit is contained in:
parent
f966a36214
commit
c4970604fa
88
vtkm/cont/BoundsCompute.cxx
Normal file
88
vtkm/cont/BoundsCompute.cxx
Normal file
@ -0,0 +1,88 @@
|
||||
//============================================================================
|
||||
// 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 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2015 UT-Battelle, LLC.
|
||||
// Copyright 2015 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.
|
||||
//============================================================================
|
||||
#include <vtkm/cont/BoundsCompute.h>
|
||||
|
||||
#include <vtkm/cont/CoordinateSystem.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/MultiBlock.h>
|
||||
|
||||
#include <numeric> // for std::accumulate
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsCompute(const vtkm::cont::DataSet& dataset, vtkm::Id coordinate_system_index)
|
||||
{
|
||||
try
|
||||
{
|
||||
return dataset.GetCoordinateSystem(coordinate_system_index).GetBounds();
|
||||
}
|
||||
catch (vtkm::cont::ErrorBadValue&)
|
||||
{
|
||||
// missing coordinate_system_index, return empty bounds.
|
||||
return vtkm::Bounds();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsCompute(const vtkm::cont::MultiBlock& multiblock,
|
||||
vtkm::Id coordinate_system_index)
|
||||
{
|
||||
return std::accumulate(multiblock.begin(),
|
||||
multiblock.end(),
|
||||
vtkm::Bounds(),
|
||||
[=](const vtkm::Bounds& val, const vtkm::cont::DataSet& block) {
|
||||
return val + vtkm::cont::BoundsCompute(block, coordinate_system_index);
|
||||
});
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsCompute(const vtkm::cont::DataSet& dataset, const std::string& name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return dataset.GetCoordinateSystem(name).GetBounds();
|
||||
}
|
||||
catch (vtkm::cont::ErrorBadValue&)
|
||||
{
|
||||
// missing coordinate_system_index, return empty bounds.
|
||||
return vtkm::Bounds();
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsCompute(const vtkm::cont::MultiBlock& multiblock, const std::string& name)
|
||||
{
|
||||
return std::accumulate(multiblock.begin(),
|
||||
multiblock.end(),
|
||||
vtkm::Bounds(),
|
||||
[=](const vtkm::Bounds& val, const vtkm::cont::DataSet& block) {
|
||||
return val + vtkm::cont::BoundsCompute(block, name);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
68
vtkm/cont/BoundsCompute.h
Normal file
68
vtkm/cont/BoundsCompute.h
Normal file
@ -0,0 +1,68 @@
|
||||
//============================================================================
|
||||
// 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 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2015 UT-Battelle, LLC.
|
||||
// Copyright 2015 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_BoundsCompute_h
|
||||
#define vtk_m_cont_BoundsCompute_h
|
||||
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/vtkm_cont_export.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
|
||||
class DataSet;
|
||||
class MultiBlock;
|
||||
|
||||
//@{
|
||||
/// \brief Functions to compute bounds for a dataset or multiblock
|
||||
///
|
||||
/// These are utility functions that compute bounds for the dataset or
|
||||
/// multiblock. When VTK-m is operating in an distributed environment, these
|
||||
/// are bounds on the local process. To get global bounds across all ranks,
|
||||
/// use `vtkm::cont::BoundsGlobalCompute` instead.
|
||||
///
|
||||
/// Note that if the provided CoordinateSystem does not exists, empty bounds
|
||||
/// are returned. Likewise, for MultiBlock, blocks without the chosen CoordinateSystem
|
||||
/// are skipped.
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsCompute(const vtkm::cont::DataSet& dataset,
|
||||
vtkm::Id coordinate_system_index = 0);
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsCompute(const vtkm::cont::MultiBlock& multiblock,
|
||||
vtkm::Id coordinate_system_index = 0);
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsCompute(const vtkm::cont::DataSet& dataset,
|
||||
const std::string& coordinate_system_name);
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsCompute(const vtkm::cont::MultiBlock& multiblock,
|
||||
const std::string& coordinate_system_name);
|
||||
//@}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
83
vtkm/cont/BoundsGlobalCompute.cxx
Normal file
83
vtkm/cont/BoundsGlobalCompute.cxx
Normal file
@ -0,0 +1,83 @@
|
||||
//============================================================================
|
||||
// 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 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2015 UT-Battelle, LLC.
|
||||
// Copyright 2015 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.
|
||||
//============================================================================
|
||||
#include <vtkm/cont/BoundsGlobalCompute.h>
|
||||
|
||||
#include <vtkm/cont/BoundsCompute.h>
|
||||
#include <vtkm/cont/CoordinateSystem.h>
|
||||
#include <vtkm/cont/DataSet.h>
|
||||
#include <vtkm/cont/FieldRangeGlobalCompute.h>
|
||||
#include <vtkm/cont/MultiBlock.h>
|
||||
|
||||
#include <numeric> // for std::accumulate
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
VTKM_CONT
|
||||
vtkm::Bounds MergeBoundsGlobal(const vtkm::Bounds& local)
|
||||
{
|
||||
vtkm::cont::ArrayHandle<vtkm::Range> ranges;
|
||||
ranges.Allocate(3);
|
||||
ranges.GetPortalControl().Set(0, local.X);
|
||||
ranges.GetPortalControl().Set(1, local.Y);
|
||||
ranges.GetPortalControl().Set(2, local.Z);
|
||||
|
||||
ranges = vtkm::cont::detail::MergeRangesGlobal(ranges);
|
||||
auto portal = ranges.GetPortalConstControl();
|
||||
return vtkm::Bounds(portal.Get(0), portal.Get(1), portal.Get(2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsGlobalCompute(const vtkm::cont::DataSet& dataset,
|
||||
vtkm::Id coordinate_system_index)
|
||||
{
|
||||
return detail::MergeBoundsGlobal(vtkm::cont::BoundsCompute(dataset, coordinate_system_index));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsGlobalCompute(const vtkm::cont::MultiBlock& multiblock,
|
||||
vtkm::Id coordinate_system_index)
|
||||
{
|
||||
return detail::MergeBoundsGlobal(vtkm::cont::BoundsCompute(multiblock, coordinate_system_index));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsGlobalCompute(const vtkm::cont::DataSet& dataset, const std::string& name)
|
||||
{
|
||||
return detail::MergeBoundsGlobal(vtkm::cont::BoundsCompute(dataset, name));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsGlobalCompute(const vtkm::cont::MultiBlock& multiblock, const std::string& name)
|
||||
{
|
||||
return detail::MergeBoundsGlobal(vtkm::cont::BoundsCompute(multiblock, name));
|
||||
}
|
||||
}
|
||||
}
|
67
vtkm/cont/BoundsGlobalCompute.h
Normal file
67
vtkm/cont/BoundsGlobalCompute.h
Normal file
@ -0,0 +1,67 @@
|
||||
//============================================================================
|
||||
// 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 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2015 UT-Battelle, LLC.
|
||||
// Copyright 2015 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_BoundsGlobalCompute_h
|
||||
#define vtk_m_cont_BoundsGlobalCompute_h
|
||||
|
||||
#include <vtkm/Bounds.h>
|
||||
#include <vtkm/cont/vtkm_cont_export.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
|
||||
class DataSet;
|
||||
class MultiBlock;
|
||||
|
||||
//@{
|
||||
/// \brief Functions to compute bounds for a dataset or multiblock globally
|
||||
///
|
||||
/// These are utility functions that compute bounds for the dataset or
|
||||
/// multiblock globally i.e. across all ranks when operating in a distributed
|
||||
/// environment. When VTK-m not operating in an distributed environment, these
|
||||
/// behave same as `vtkm::cont::BoundsCompute`.
|
||||
///
|
||||
/// Note that if the provided CoordinateSystem does not exists, empty bounds
|
||||
/// are returned. Likewise, for MultiBlock, blocks without the chosen CoordinateSystem
|
||||
/// are skipped.
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsGlobalCompute(const vtkm::cont::DataSet& dataset,
|
||||
vtkm::Id coordinate_system_index = 0);
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsGlobalCompute(const vtkm::cont::MultiBlock& multiblock,
|
||||
vtkm::Id coordinate_system_index = 0);
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsGlobalCompute(const vtkm::cont::DataSet& dataset,
|
||||
const std::string& coordinate_system_name);
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_CONT
|
||||
vtkm::Bounds BoundsGlobalCompute(const vtkm::cont::MultiBlock& multiblock,
|
||||
const std::string& coordinate_system_name);
|
||||
//@}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -46,6 +46,8 @@ set(headers
|
||||
ArrayHandleConcatenate.h
|
||||
ArrayRangeCompute.h
|
||||
AssignerMultiBlock.h
|
||||
BoundsCompute.h
|
||||
BoundsGlobalCompute.h
|
||||
CellLocator.h
|
||||
CellLocatorTwoLevelUniformGrid.h
|
||||
CellSet.h
|
||||
@ -107,6 +109,8 @@ set(template_sources
|
||||
set(sources
|
||||
ArrayHandle.cxx
|
||||
AssignerMultiBlock.cxx
|
||||
BoundsCompute.cxx
|
||||
BoundsGlobalCompute.cxx
|
||||
CellSet.cxx
|
||||
CellSetStructured.cxx
|
||||
DynamicArrayHandle.cxx
|
||||
|
Loading…
Reference in New Issue
Block a user