Commit 4459ab91 authored by Kenneth Moreland's avatar Kenneth Moreland
Browse files

Merge branch 'master' into 'pointlocator-general-interface'

# Conflicts:
#   vtkm/cont/PointLocatorUniformGrid.h
parents 51fd4a11 9a1b44cc
......@@ -28,6 +28,9 @@ list(APPEND CTEST_CUSTOM_WARNING_EXCEPTION
# disable doxygen warning about not generating graph
".*warning: Included by graph for"
# Doxygen warns when creating output directory:
"Notice: Output directory.*does not exist. I have created it for you."
# disable doxygen warnings from CONTRIBUTING.md, CodingConventions.md.
# these files are really intended for Gitlab, hence we don't want to use
# doxygen tags in them.
......
......@@ -72,16 +72,19 @@ private:
vtkm::cont::DeviceAdapterTagCuda>::Portal;
PortalType Portal;
VTKM_SUPPRESS_EXEC_WARNINGS
__device__ vtkm::Int64 vtkmAtomicAdd(vtkm::Int64* address, const vtkm::Int64& value) const
{
return atomicAdd((unsigned long long*)address, (unsigned long long)value);
}
VTKM_SUPPRESS_EXEC_WARNINGS
__device__ vtkm::Int32 vtkmAtomicAdd(vtkm::Int32* address, const vtkm::Int32& value) const
{
return atomicAdd(address, value);
}
VTKM_SUPPRESS_EXEC_WARNINGS
__device__ vtkm::Int32 vtkmCompareAndSwap(vtkm::Int32* address,
const vtkm::Int32& newValue,
const vtkm::Int32& oldValue) const
......@@ -89,6 +92,7 @@ private:
return atomicCAS(address, oldValue, newValue);
}
VTKM_SUPPRESS_EXEC_WARNINGS
__device__ vtkm::Int64 vtkmCompareAndSwap(vtkm::Int64* address,
const vtkm::Int64& newValue,
const vtkm::Int64& oldValue) const
......
......@@ -19,7 +19,9 @@
//============================================================================
#ifndef vtk_m_exec_CellMeasure_h
#define vtk_m_exec_CellMeasure_h
/*!\file Functions that provide integral measures over cells. */
/*!\file
* Functions that provide integral measures over cells.
*/
#include "vtkm/CellShape.h"
#include "vtkm/CellTraits.h"
......
......@@ -25,6 +25,7 @@ set(headers
ClipWithField.h
ClipWithImplicitFunction.h
ContourTreeUniform.h
CoordinateSystemTransform.h
CrossProduct.h
DotProduct.h
Entropy.h
......@@ -71,6 +72,7 @@ set(header_template_sources
ClipWithField.hxx
ClipWithImplicitFunction.hxx
ContourTreeUniform.hxx
CoordinateSystemTransform.hxx
CrossProduct.hxx
DotProduct.hxx
Entropy.hxx
......
//============================================================================
// 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_filter_CoordianteSystemTransform_h
#define vtk_m_filter_CoordianteSystemTransform_h
#include <vtkm/filter/FilterField.h>
#include <vtkm/worklet/CoordinateSystemTransform.h>
namespace vtkm
{
namespace filter
{
/// \brief
///
/// Generate a coordinate transformation on coordiantes from a dataset.
class CylindricalCoordinateTransform
: public vtkm::filter::FilterField<CylindricalCoordinateTransform>
{
public:
VTKM_CONT
CylindricalCoordinateTransform();
VTKM_CONT void SetCartesianToCylindrical() { Worklet.SetCartesianToCylindrical(); }
VTKM_CONT void SetCylindricalToCartesian() { Worklet.SetCylindricalToCartesian(); }
template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& tag);
private:
vtkm::worklet::CylindricalCoordinateTransform Worklet;
};
template <>
class FilterTraits<CylindricalCoordinateTransform>
{
public:
//Point Elevation can only convert Float and Double Vec3 arrays
using InputFieldTypeList = vtkm::TypeListTagFieldVec3;
};
class SphericalCoordinateTransform : public vtkm::filter::FilterField<SphericalCoordinateTransform>
{
public:
VTKM_CONT
SphericalCoordinateTransform();
VTKM_CONT void SetCartesianToSpherical() { Worklet.SetCartesianToSpherical(); }
VTKM_CONT void SetSphericalToCartesian() { Worklet.SetSphericalToCartesian(); }
template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& tag) const;
private:
vtkm::worklet::SphericalCoordinateTransform Worklet;
};
template <>
class FilterTraits<SphericalCoordinateTransform>
{
public:
//Point Elevation can only convert Float and Double Vec3 arrays
using InputFieldTypeList = vtkm::TypeListTagFieldVec3;
};
}
} // namespace vtkm::filter
#include <vtkm/filter/CoordinateSystemTransform.hxx>
#endif // vtk_m_filter_CoordianteSystemTransform_h
//============================================================================
// 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.
//============================================================================
#include <vtkm/filter/internal/CreateResult.h>
#include <vtkm/worklet/DispatcherMapField.h>
namespace vtkm
{
namespace filter
{
//-----------------------------------------------------------------------------
inline VTKM_CONT CylindricalCoordinateTransform::CylindricalCoordinateTransform()
: Worklet()
{
this->SetOutputFieldName("cylindricalCoordinateSystemTransform");
}
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
inline VTKM_CONT vtkm::cont::DataSet CylindricalCoordinateTransform::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMetadata,
const vtkm::filter::PolicyBase<DerivedPolicy>&,
const DeviceAdapter& device)
{
vtkm::cont::ArrayHandle<T> outArray;
Worklet.Run(field, outArray, device);
return internal::CreateResult(inDataSet,
outArray,
this->GetOutputFieldName(),
fieldMetadata.GetAssociation(),
fieldMetadata.GetCellSetName());
}
//-----------------------------------------------------------------------------
inline VTKM_CONT SphericalCoordinateTransform::SphericalCoordinateTransform()
: Worklet()
{
this->SetOutputFieldName("sphericalCoordinateSystemTransform");
}
//-----------------------------------------------------------------------------
template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
inline VTKM_CONT vtkm::cont::DataSet SphericalCoordinateTransform::DoExecute(
const vtkm::cont::DataSet& inDataSet,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMetadata,
const vtkm::filter::PolicyBase<DerivedPolicy>&,
const DeviceAdapter& device) const
{
vtkm::cont::ArrayHandle<T> outArray;
Worklet.Run(field, outArray, device);
return internal::CreateResult(inDataSet,
outArray,
this->GetOutputFieldName(),
fieldMetadata.GetAssociation(),
fieldMetadata.GetCellSetName());
}
}
} // namespace vtkm::filter
......@@ -26,19 +26,9 @@ namespace vtkm
{
namespace filter
{
/// \brief Clean a mesh to an unstructured grid
/// \brief Calculate the entropy of input N-Dims fields
///
/// This filter takes a data set and essentially copies it into a new data set.
/// The newly constructed data set will have the same cells as the input and
/// the topology will be stored in a \c CellSetExplicit<>. The filter will also
/// optionally remove all unused points.
///
/// Note that the result of \c CleanGrid is not necessarily smaller than the
/// input. For example, "cleaning" a data set with a \c CellSetStructured
/// topology will actually result in a much larger data set.
///
/// \todo Add a feature to merge points that are coincident or within a
/// tolerance.
/// This filter calculate the entropy of input N-Dims fields.
///
class NDEntropy : public vtkm::filter::FilterDataSet<NDEntropy>
{
......
......@@ -26,19 +26,17 @@ namespace vtkm
{
namespace filter
{
/// \brief Clean a mesh to an unstructured grid
/// \brief Generate a N-Dims histogram from input fields
///
/// This filter takes a data set and essentially copies it into a new data set.
/// The newly constructed data set will have the same cells as the input and
/// the topology will be stored in a \c CellSetExplicit<>. The filter will also
/// optionally remove all unused points.
///
/// Note that the result of \c CleanGrid is not necessarily smaller than the
/// input. For example, "cleaning" a data set with a \c CellSetStructured
/// topology will actually result in a much larger data set.
///
/// \todo Add a feature to merge points that are coincident or within a
/// tolerance.
/// This filter takes a data set and with target fields and bins defined,
/// it would generate a N-Dims histogram from input fields. The result is stored
/// in a field named as "Frequency". This filed contains all the frequencies of
/// the N-Dims histogram in sparse representation. That being said, the result
/// field does not store 0 frequency bins. Meanwhile all input fileds now
/// would have the same length and store bin ids instead.
/// E.g. (FieldA[i], FieldB[i], FieldC[i], Frequency[i]) is a bin in the histogram.
/// The first three numbers are binIDs for FieldA, FieldB and FieldC. Frequency[i] stores
/// the frequency for this bin (FieldA[i], FieldB[i], FieldC[i]).
///
class NDHistogram : public vtkm::filter::FilterDataSet<NDHistogram>
{
......
......@@ -25,6 +25,7 @@ set(unit_tests
UnitTestClipWithFieldFilter.cxx
UnitTestClipWithImplicitFunctionFilter.cxx
UnitTestContourTreeUniformFilter.cxx
UnitTestCoordinateSystemTransform.cxx
UnitTestCrossProductFilter.cxx
UnitTestDotProductFilter.cxx
UnitTestEntropyFilter.cxx
......
//============================================================================
// 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.
//============================================================================
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/CoordinateSystemTransform.h>
#include <string>
#include <vector>
namespace
{
enum CoordinateType
{
CART = 0,
CYL,
SPH
};
vtkm::cont::DataSet MakeTestDataSet(const CoordinateType& cType)
{
vtkm::cont::DataSet dataSet;
std::vector<vtkm::Vec<vtkm::FloatDefault, 3>> coordinates;
const vtkm::Id dim = 5;
if (cType == CART)
{
for (vtkm::Id j = 0; j < dim; ++j)
{
vtkm::FloatDefault z =
static_cast<vtkm::FloatDefault>(j) / static_cast<vtkm::FloatDefault>(dim - 1);
for (vtkm::Id i = 0; i < dim; ++i)
{
vtkm::FloatDefault x =
static_cast<vtkm::FloatDefault>(i) / static_cast<vtkm::FloatDefault>(dim - 1);
vtkm::FloatDefault y = (x * x + z * z) / 2.0f;
coordinates.push_back(vtkm::make_Vec(x + 0, y + 0, z + 0));
}
}
}
else if (cType == CYL)
{
vtkm::FloatDefault R = 1.0f;
for (vtkm::Id j = 0; j < dim; j++)
{
vtkm::FloatDefault Z =
static_cast<vtkm::FloatDefault>(j) / static_cast<vtkm::FloatDefault>(dim - 1);
for (vtkm::Id i = 0; i < dim; i++)
{
vtkm::FloatDefault Theta = vtkm::TwoPif() *
(static_cast<vtkm::FloatDefault>(i) / static_cast<vtkm::FloatDefault>(dim - 1));
coordinates.push_back(vtkm::make_Vec(R, Theta, Z));
}
}
}
else if (cType == SPH)
{
//Spherical coordinates have some degenerate cases, so provide some good cases.
vtkm::FloatDefault R = 1.0f;
vtkm::FloatDefault eps = vtkm::Epsilon<float>();
std::vector<vtkm::FloatDefault> Thetas = {
eps, vtkm::Pif() / 4, vtkm::Pif() / 3, vtkm::Pif() / 2, vtkm::Pif() - eps
};
std::vector<vtkm::FloatDefault> Phis = {
eps, vtkm::TwoPif() / 4, vtkm::TwoPif() / 3, vtkm::TwoPif() / 2, vtkm::TwoPif() - eps
};
for (std::size_t i = 0; i < Thetas.size(); i++)
for (std::size_t j = 0; j < Phis.size(); j++)
coordinates.push_back(vtkm::make_Vec(R, Thetas[i], Phis[j]));
}
vtkm::Id numCells = (dim - 1) * (dim - 1);
dataSet.AddCoordinateSystem(
vtkm::cont::make_CoordinateSystem("coordinates", coordinates, vtkm::CopyFlag::On));
vtkm::cont::CellSetExplicit<> cellSet("cells");
cellSet.PrepareToAddCells(numCells, numCells * 4);
for (vtkm::Id j = 0; j < dim - 1; ++j)
{
for (vtkm::Id i = 0; i < dim - 1; ++i)
{
cellSet.AddCell(vtkm::CELL_SHAPE_QUAD,
4,
vtkm::make_Vec<vtkm::Id>(
j * dim + i, j * dim + i + 1, (j + 1) * dim + i + 1, (j + 1) * dim + i));
}
}
cellSet.CompleteAddingCells(vtkm::Id(coordinates.size()));
dataSet.AddCellSet(cellSet);
return dataSet;
}
void ValidateCoordTransform(const vtkm::cont::DataSet& ds,
const vtkm::cont::DataSet& dsTrn,
const std::vector<bool>& isAngle)
{
auto points = ds.GetCoordinateSystem().GetData();
auto pointsTrn = dsTrn.GetCoordinateSystem().GetData();
VTKM_TEST_ASSERT(points.GetNumberOfValues() == pointsTrn.GetNumberOfValues(),
"Incorrect number of points in point transform");
auto pointsPortal = points.GetPortalConstControl();
auto pointsTrnPortal = pointsTrn.GetPortalConstControl();
for (vtkm::Id i = 0; i < points.GetNumberOfValues(); i++)
{
vtkm::Vec<vtkm::FloatDefault, 3> p = pointsPortal.Get(i);
vtkm::Vec<vtkm::FloatDefault, 3> r = pointsTrnPortal.Get(i);
bool isEqual = true;
for (vtkm::IdComponent j = 0; j < 3; j++)
{
if (isAngle[static_cast<std::size_t>(j)])
isEqual &= (test_equal(p[j], r[j]) || test_equal(p[j] + vtkm::TwoPif(), r[j]) ||
test_equal(p[j], r[j] + vtkm::TwoPif()));
else
isEqual &= test_equal(p[j], r[j]);
}
VTKM_TEST_ASSERT(isEqual, "Wrong result for PointTransform worklet");
}
}
}
void TestCoordinateSystemTransform()
{
std::cout << "Testing CylindricalCoordinateTransform Filter" << std::endl;
//Test cartesian to cyl
vtkm::cont::DataSet dsCart = MakeTestDataSet(CART);
vtkm::filter::CylindricalCoordinateTransform cylTrn;
cylTrn.SetOutputFieldName("cylindricalCoords");
cylTrn.SetUseCoordinateSystemAsField(true);
cylTrn.SetCartesianToCylindrical();
vtkm::cont::DataSet carToCylDataSet = cylTrn.Execute(dsCart);
cylTrn.SetCylindricalToCartesian();
cylTrn.SetUseCoordinateSystemAsField(true);
cylTrn.SetOutputFieldName("cartesianCoords");
vtkm::cont::DataSet cylToCarDataSet = cylTrn.Execute(carToCylDataSet);
ValidateCoordTransform(dsCart, cylToCarDataSet, { false, false, false });
//Test cyl to cart.
vtkm::cont::DataSet dsCyl = MakeTestDataSet(CYL);
cylTrn.SetCylindricalToCartesian();
cylTrn.SetUseCoordinateSystemAsField(true);
cylTrn.SetOutputFieldName("cartesianCoords");
cylToCarDataSet = cylTrn.Execute(dsCyl);
cylTrn.SetCartesianToCylindrical();
cylTrn.SetUseCoordinateSystemAsField(true);
cylTrn.SetOutputFieldName("cylindricalCoords");
carToCylDataSet = cylTrn.Execute(cylToCarDataSet);
ValidateCoordTransform(dsCyl, carToCylDataSet, { false, true, false });
std::cout << "Testing SphericalCoordinateTransform Filter" << std::endl;
vtkm::filter::SphericalCoordinateTransform sphTrn;
sphTrn.SetOutputFieldName("sphericalCoords");
sphTrn.SetUseCoordinateSystemAsField(true);
sphTrn.SetCartesianToSpherical();
vtkm::cont::DataSet carToSphDataSet = sphTrn.Execute(dsCart);
sphTrn.SetOutputFieldName("cartesianCoords");
sphTrn.SetUseCoordinateSystemAsField(true);
sphTrn.SetSphericalToCartesian();
vtkm::cont::DataSet sphToCarDataSet = sphTrn.Execute(carToSphDataSet);
ValidateCoordTransform(dsCart, sphToCarDataSet, { false, true, true });
vtkm::cont::DataSet dsSph = MakeTestDataSet(SPH);
sphTrn.SetSphericalToCartesian();
sphTrn.SetUseCoordinateSystemAsField(true);
sphTrn.SetOutputFieldName("sphericalCoords");
sphToCarDataSet = sphTrn.Execute(dsSph);
sphTrn.SetCartesianToSpherical();
sphTrn.SetUseCoordinateSystemAsField(true);
sphTrn.SetOutputFieldName("sphericalCoords");
carToSphDataSet = cylTrn.Execute(sphToCarDataSet);
ValidateCoordTransform(dsSph, carToSphDataSet, { false, true, true });
}
int UnitTestCoordinateSystemTransform(int, char* [])
{
return vtkm::cont::testing::Testing::Run(TestCoordinateSystemTransform);
}
......@@ -80,7 +80,7 @@ void RunTest()
//The first "fieldNames.size()"" fields are the binId arrays for inputs field
//And their order and field names are the same as the order and name in fieldNames
//The name of last fields in the dataset is "Frequency"
//This field contains the all freqncys of the N-Dims histogram
//This field contains all the frequencies of the N-Dims histogram
//The result histogram is stored in sparse representation
//(Do not store and return zero frequency bins)
//All fields in return dataset must have the same length
......
......@@ -61,7 +61,9 @@
// by the visibility of both T and S.
//
// Solution:
// The solution is fairly simple, but annoying. You need to mark
// The solution is fairly simple, but annoying. You need to mark every single
// header only class that is tempgit lated on non value types to be marked as
// always exported ( or never pass fvisibility=hidden ).
//
// TL;DR:
// This markup is used when we want to make sure:
......
......@@ -123,7 +123,6 @@ struct CarToSphere : public vtkm::worklet::WorkletMapField
};
};
template <typename T>
class CylindricalCoordinateTransform
{
public:
......@@ -136,9 +135,9 @@ public:
VTKM_CONT void SetCartesianToCylindrical() { cartesianToCylindrical = true; }
VTKM_CONT void SetCylindricalToCartesian() { cartesianToCylindrical = false; }
template <typename CoordsStorageType, typename DeviceAdapterTag>
void Run(const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, CoordsStorageType>& inPoints,
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, CoordsStorageType>& outPoints,
template <typename T, typename InStorageType, typename OutStorageType, typename DeviceAdapterTag>
void Run(const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, InStorageType>& inPoints,
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, OutStorageType>& outPoints,
DeviceAdapterTag) const
{
if (cartesianToCylindrical)
......@@ -153,7 +152,7 @@ public:
}
}
template <typename CoordsStorageType, typename DeviceAdapterTag>
template <typename T, typename CoordsStorageType, typename DeviceAdapterTag>
void Run(const vtkm::cont::CoordinateSystem& inPoints,
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, CoordsStorageType>& outPoints,
DeviceAdapterTag) const
......@@ -174,7 +173,6 @@ private:
bool cartesianToCylindrical;
};
template <typename T>
class SphericalCoordinateTransform
{
public:
......@@ -187,9 +185,9 @@ public:
VTKM_CONT void SetCartesianToSpherical() { CartesianToSpherical = true; }
VTKM_CONT void SetSphericalToCartesian() { CartesianToSpherical = false; }
template <typename CoordsStorageType, typename DeviceAdapterTag>
void Run(const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, CoordsStorageType>& inPoints,
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, CoordsStorageType>& outPoints,
template <typename T, typename InStorageType, typename OutStorageType, typename DeviceAdapterTag>
void Run(const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, InStorageType>& inPoints,
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, OutStorageType>& outPoints,
DeviceAdapterTag) const
{
if (CartesianToSpherical)
......@@ -204,7 +202,7 @@ public:
}
}
template <typename CoordsStorageType, typename DeviceAdapterTag>
template <typename T, typename CoordsStorageType, typename DeviceAdapterTag>
void Run(const vtkm::cont::CoordinateSystem& inPoints,
vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, CoordsStorageType>& outPoints,
DeviceAdapterTag) const
......
......@@ -153,7 +153,7 @@ void TestCoordinateSystemTransform()
//Test cartesian to cyl