Move ColorTable mapping to its own header

We would really like to be able to include `vtkm::cont::ColorTable` in
such a way that you don't have to compile device code (unless you are
actually compiling functions for the device). Thus, the `Map` functions
of `ColorTable` were in a special `ColorTable.hxx` that contains the
"implementation" for `ColorTable`.

That is confusing to many users. It is more clear to simply have `.h`
headers that do a specific thing. To achieve these two goals, the `Map`
functionality of `ColorTable` is separated out into its own header file.
So you don't need to be using a device compiler just to use `ColorTable`
(including `ColorTable.h`), but you do need to use a device compiler if
mapping values to colors (including `ColorTableMap.h`).
This commit is contained in:
Kenneth Moreland 2020-09-14 16:39:51 -06:00
parent 38bdfec40a
commit 2e918c58dc
8 changed files with 266 additions and 358 deletions

@ -26,8 +26,6 @@
#include <vtkm/exec/FunctorBase.h>
#include <vtkm/cont/ColorTable.hxx>
#include <sstream>
#include <string>
#include <vector>

@ -66,6 +66,7 @@ set(headers
CellSetSingleType.h
CellSetStructured.h
ColorTable.h
ColorTableMap.h
ColorTableSamples.h
CoordinateSystem.h
DataSet.h
@ -125,7 +126,6 @@ set(template_sources
CellSetExplicit.hxx
CellSetExtrude.hxx
CellSetStructured.hxx
ColorTable.hxx
FieldRangeCompute.hxx
FieldRangeGlobalCompute.hxx
ParticleArrayCopy.hxx

@ -12,7 +12,7 @@
#include <memory>
#include <vtkm/cont/ColorTable.h>
#include <vtkm/cont/ColorTable.hxx>
#include <vtkm/cont/ColorTableMap.h>
#include <vtkm/cont/ErrorBadType.h>
#include <vtkm/cont/TryExecute.h>
@ -316,13 +316,13 @@ inline bool sampleColorTable(const vtkm::cont::ColorTable* self,
{
auto handle =
buildSampleHandle((numSamples - 1), f_start, f_end, f_delta, appendNanAndRangeColors);
return self->Map(handle, colors);
return vtkm::cont::ColorTableMap(handle, *self, colors);
}
}
//otherwise we need to use Float64 space
auto handle = buildSampleHandle((numSamples - 1), r.Min, r.Max, d_delta, appendNanAndRangeColors);
return self->Map(handle, colors);
return vtkm::cont::ColorTableMap(handle, *self, colors);
}
} // anonymous namespace

@ -532,126 +532,6 @@ public:
bool FillOpacityTableFromDataPointer(vtkm::Int32 n, const vtkm::Float32* ptr);
/// \brief Sample each value through an intermediate lookup/sample table to generate RGBA colors
///
/// Each value in \c values is binned based on its value in relationship to the range
/// of the color table and will use the color value at that bin from the \c samples.
/// To generate the lookup table use \c Sample .
///
/// Here is a simple example.
/// \code{.cpp}
///
/// vtkm::cont::ColorTableSamplesRGBA samples;
/// vtkm::cont::ColorTable table("black-body radiation");
/// table.Sample(256, samples);
/// vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors;
/// table.Map(input, samples, colors);
///
/// \endcode
template <typename T, typename S>
inline bool Map(const vtkm::cont::ArrayHandle<T, S>& values,
const vtkm::cont::ColorTableSamplesRGBA& samples,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const;
/// \brief Sample each value through an intermediate lookup/sample table to generate RGB colors
///
/// Each value in \c values is binned based on its value in relationship to the range
/// of the color table and will use the color value at that bin from the \c samples.
/// To generate the lookup table use \c Sample .
///
/// Here is a simple example.
/// \code{.cpp}
///
/// vtkm::cont::ColorTableSamplesRGB samples;
/// vtkm::cont::ColorTable table("black-body radiation");
/// table.Sample(256, samples);
/// vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
/// table.Map(input, samples, colors);
///
/// \endcode
template <typename T, typename S>
inline bool Map(const vtkm::cont::ArrayHandle<T, S>& values,
const vtkm::cont::ColorTableSamplesRGB& samples,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbaOut) const;
/// \brief Use magnitude of a vector with a sample table to generate RGBA colors
///
template <typename T, int N, typename S>
inline bool MapMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
const vtkm::cont::ColorTableSamplesRGBA& samples,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const;
/// \brief Use magnitude of a vector with a sample table to generate RGB colors
///
template <typename T, int N, typename S>
inline bool MapMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
const vtkm::cont::ColorTableSamplesRGB& samples,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbaOut) const;
/// \brief Use a single component of a vector with a sample table to generate RGBA colors
///
template <typename T, int N, typename S>
inline bool MapComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::IdComponent comp,
const vtkm::cont::ColorTableSamplesRGBA& samples,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const;
/// \brief Use a single component of a vector with a sample table to generate RGB colors
///
template <typename T, int N, typename S>
inline bool MapComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::IdComponent comp,
const vtkm::cont::ColorTableSamplesRGB& samples,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const;
/// \brief Interpolate each value through the color table to generate RGBA colors
///
/// Each value in \c values will be sampled through the entire color table
/// to determine a color.
///
/// Note: This is more costly than using Sample/Map with the generated intermediate lookup table
template <typename T, typename S>
inline bool Map(const vtkm::cont::ArrayHandle<T, S>& values,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const;
/// \brief Interpolate each value through the color table to generate RGB colors
///
/// Each value in \c values will be sampled through the entire color table
/// to determine a color.
///
/// Note: This is more costly than using Sample/Map with the generated intermediate lookup table
template <typename T, typename S>
inline bool Map(const vtkm::cont::ArrayHandle<T, S>& values,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const;
/// \brief Use magnitude of a vector to generate RGBA colors
///
template <typename T, int N, typename S>
inline bool MapMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const;
/// \brief Use magnitude of a vector to generate RGB colors
///
template <typename T, int N, typename S>
inline bool MapMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const;
/// \brief Use a single component of a vector to generate RGBA colors
///
template <typename T, int N, typename S>
inline bool MapComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::IdComponent comp,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const;
/// \brief Use a single component of a vector to generate RGB colors
///
template <typename T, int N, typename S>
inline bool MapComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::IdComponent comp,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const;
/// \brief generate RGB colors using regular spaced samples along the range.
///
/// Will use the current range of the color table to generate evenly spaced

@ -1,158 +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.
//============================================================================
#ifndef vtk_m_cont_ColorTable_hxx
#define vtk_m_cont_ColorTable_hxx
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayHandleTransform.h>
#include <vtkm/cont/TryExecute.h>
#include <vtkm/cont/VirtualObjectHandle.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/worklet/colorconversion/LookupTable.h>
#include <vtkm/worklet/colorconversion/Portals.h>
#include <vtkm/worklet/colorconversion/TransferFunction.h>
#include <vtkm/exec/ColorTable.h>
namespace vtkm
{
namespace cont
{
//---------------------------------------------------------------------------
template <typename T, typename S>
bool ColorTable::Map(const vtkm::cont::ArrayHandle<T, S>& values,
const vtkm::cont::ColorTableSamplesRGBA& samples,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const
{
if (samples.NumberOfSamples <= 0)
{
return false;
}
vtkm::worklet::colorconversion::LookupTable lookupTable(samples);
vtkm::cont::Invoker invoke(vtkm::cont::DeviceAdapterTagAny{});
invoke(lookupTable, values, samples.Samples, rgbaOut);
return true;
}
//---------------------------------------------------------------------------
template <typename T, typename S>
bool ColorTable::Map(const vtkm::cont::ArrayHandle<T, S>& values,
const vtkm::cont::ColorTableSamplesRGB& samples,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const
{
if (samples.NumberOfSamples <= 0)
{
return false;
}
vtkm::worklet::colorconversion::LookupTable lookupTable(samples);
vtkm::cont::Invoker invoke(vtkm::cont::DeviceAdapterTagAny{});
invoke(lookupTable, values, samples.Samples, rgbOut);
return true;
}
//---------------------------------------------------------------------------
template <typename T, int N, typename S>
bool ColorTable::MapMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
const vtkm::cont::ColorTableSamplesRGBA& samples,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const
{
using namespace vtkm::worklet::colorconversion;
return this->Map(
vtkm::cont::make_ArrayHandleTransform(values, MagnitudePortal()), samples, rgbaOut);
}
//---------------------------------------------------------------------------
template <typename T, int N, typename S>
bool ColorTable::MapMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
const vtkm::cont::ColorTableSamplesRGB& samples,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const
{
using namespace vtkm::worklet::colorconversion;
return this->Map(
vtkm::cont::make_ArrayHandleTransform(values, MagnitudePortal()), samples, rgbOut);
}
//---------------------------------------------------------------------------
template <typename T, int N, typename S>
bool ColorTable::MapComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::IdComponent comp,
const vtkm::cont::ColorTableSamplesRGBA& samples,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const
{
using namespace vtkm::worklet::colorconversion;
return this->Map(
vtkm::cont::make_ArrayHandleTransform(values, ComponentPortal(comp)), samples, rgbaOut);
}
//---------------------------------------------------------------------------
template <typename T, int N, typename S>
bool ColorTable::MapComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::IdComponent comp,
const vtkm::cont::ColorTableSamplesRGB& samples,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const
{
using namespace vtkm::worklet::colorconversion;
return this->Map(
vtkm::cont::make_ArrayHandleTransform(values, ComponentPortal(comp)), samples, rgbOut);
}
//---------------------------------------------------------------------------
template <typename T, typename S>
bool ColorTable::Map(const vtkm::cont::ArrayHandle<T, S>& values,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const
{
vtkm::cont::Invoker invoke;
invoke(vtkm::worklet::colorconversion::TransferFunction{}, values, *this, rgbaOut);
return true;
}
//---------------------------------------------------------------------------
template <typename T, typename S>
bool ColorTable::Map(const vtkm::cont::ArrayHandle<T, S>& values,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const
{
vtkm::cont::Invoker invoke;
invoke(vtkm::worklet::colorconversion::TransferFunction{}, values, *this, rgbOut);
return true;
}
//---------------------------------------------------------------------------
template <typename T, int N, typename S>
bool ColorTable::MapMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const
{
using namespace vtkm::worklet::colorconversion;
return this->Map(vtkm::cont::make_ArrayHandleTransform(values, MagnitudePortal()), rgbaOut);
}
//---------------------------------------------------------------------------
template <typename T, int N, typename S>
bool ColorTable::MapMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const
{
using namespace vtkm::worklet::colorconversion;
return this->Map(vtkm::cont::make_ArrayHandleTransform(values, MagnitudePortal()), rgbOut);
}
//---------------------------------------------------------------------------
template <typename T, int N, typename S>
bool ColorTable::MapComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::IdComponent comp,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut) const
{
using namespace vtkm::worklet::colorconversion;
return this->Map(vtkm::cont::make_ArrayHandleTransform(values, ComponentPortal(comp)), rgbaOut);
}
//---------------------------------------------------------------------------
template <typename T, int N, typename S>
bool ColorTable::MapComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::IdComponent comp,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut) const
{
using namespace vtkm::worklet::colorconversion;
return this->Map(vtkm::cont::make_ArrayHandleTransform(values, ComponentPortal(comp)), rgbOut);
}
}
}
#endif

226
vtkm/cont/ColorTableMap.h Normal file

@ -0,0 +1,226 @@
//============================================================================
// 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.
//============================================================================
#ifndef vtk_m_cont_ColorTableMap_h
#define vtk_m_cont_ColorTableMap_h
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayHandleTransform.h>
#include <vtkm/cont/ColorTable.h>
#include <vtkm/cont/ColorTableSamples.h>
#include <vtkm/cont/TryExecute.h>
#include <vtkm/cont/Invoker.h>
#include <vtkm/worklet/colorconversion/LookupTable.h>
#include <vtkm/worklet/colorconversion/Portals.h>
#include <vtkm/worklet/colorconversion/TransferFunction.h>
#include <vtkm/exec/ColorTable.h>
namespace vtkm
{
namespace cont
{
/// \brief Sample each value through an intermediate lookup/sample table to generate RGBA colors
///
/// Each value in \c values is binned based on its value in relationship to the range
/// of the color table and will use the color value at that bin from the \c samples.
/// To generate the lookup table use \c Sample .
///
/// Here is a simple example.
/// \code{.cpp}
///
/// vtkm::cont::ColorTableSamplesRGBA samples;
/// vtkm::cont::ColorTable table("black-body radiation");
/// table.Sample(256, samples);
/// vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors;
/// vtkm::cont::ColorTableMap(input, samples, colors);
///
/// \endcode
template <typename T, typename S>
bool ColorTableMap(const vtkm::cont::ArrayHandle<T, S>& values,
const vtkm::cont::ColorTableSamplesRGBA& samples,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut)
{
if (samples.NumberOfSamples <= 0)
{
return false;
}
vtkm::worklet::colorconversion::LookupTable lookupTable(samples);
vtkm::cont::Invoker invoke(vtkm::cont::DeviceAdapterTagAny{});
invoke(lookupTable, values, samples.Samples, rgbaOut);
return true;
}
/// \brief Sample each value through an intermediate lookup/sample table to generate RGB colors
///
/// Each value in \c values is binned based on its value in relationship to the range
/// of the color table and will use the color value at that bin from the \c samples.
/// To generate the lookup table use \c Sample .
///
/// Here is a simple example.
/// \code{.cpp}
///
/// vtkm::cont::ColorTableSamplesRGB samples;
/// vtkm::cont::ColorTable table("black-body radiation");
/// table.Sample(256, samples);
/// vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
/// vtkm::cont::ColorTableMap(input, samples, colors);
///
/// \endcode
template <typename T, typename S>
bool ColorTableMap(const vtkm::cont::ArrayHandle<T, S>& values,
const vtkm::cont::ColorTableSamplesRGB& samples,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut)
{
if (samples.NumberOfSamples <= 0)
{
return false;
}
vtkm::worklet::colorconversion::LookupTable lookupTable(samples);
vtkm::cont::Invoker invoke(vtkm::cont::DeviceAdapterTagAny{});
invoke(lookupTable, values, samples.Samples, rgbOut);
return true;
}
/// \brief Use magnitude of a vector with a sample table to generate RGBA colors
///
template <typename T, int N, typename S>
bool ColorTableMapMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
const vtkm::cont::ColorTableSamplesRGBA& samples,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut)
{
using namespace vtkm::worklet::colorconversion;
return vtkm::cont::ColorTableMap(
vtkm::cont::make_ArrayHandleTransform(values, MagnitudePortal()), samples, rgbaOut);
}
/// \brief Use magnitude of a vector with a sample table to generate RGB colors
///
template <typename T, int N, typename S>
bool ColorTableMapMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
const vtkm::cont::ColorTableSamplesRGB& samples,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut)
{
using namespace vtkm::worklet::colorconversion;
return vtkm::cont::ColorTableMap(
vtkm::cont::make_ArrayHandleTransform(values, MagnitudePortal()), samples, rgbOut);
}
/// \brief Use a single component of a vector with a sample table to generate RGBA colors
///
template <typename T, int N, typename S>
bool ColorTableMapComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::IdComponent comp,
const vtkm::cont::ColorTableSamplesRGBA& samples,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut)
{
using namespace vtkm::worklet::colorconversion;
return vtkm::cont::ColorTableMap(
vtkm::cont::make_ArrayHandleTransform(values, ComponentPortal(comp)), samples, rgbaOut);
}
/// \brief Use a single component of a vector with a sample table to generate RGB colors
///
template <typename T, int N, typename S>
bool ColorTableMapComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::IdComponent comp,
const vtkm::cont::ColorTableSamplesRGB& samples,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut)
{
using namespace vtkm::worklet::colorconversion;
return vtkm::cont::ColorTableMap(
vtkm::cont::make_ArrayHandleTransform(values, ComponentPortal(comp)), samples, rgbOut);
}
/// \brief Interpolate each value through the color table to generate RGBA colors
///
/// Each value in \c values will be sampled through the entire color table
/// to determine a color.
///
/// Note: This is more costly than using Sample/Map with the generated intermediate lookup table
template <typename T, typename S>
bool ColorTableMap(const vtkm::cont::ArrayHandle<T, S>& values,
const vtkm::cont::ColorTable& table,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut)
{
vtkm::cont::Invoker invoke;
invoke(vtkm::worklet::colorconversion::TransferFunction{}, values, table, rgbaOut);
return true;
}
/// \brief Interpolate each value through the color table to generate RGB colors
///
/// Each value in \c values will be sampled through the entire color table
/// to determine a color.
///
/// Note: This is more costly than using Sample/Map with the generated intermediate lookup table
template <typename T, typename S>
bool ColorTableMap(const vtkm::cont::ArrayHandle<T, S>& values,
const vtkm::cont::ColorTable& table,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut)
{
vtkm::cont::Invoker invoke;
invoke(vtkm::worklet::colorconversion::TransferFunction{}, values, table, rgbOut);
return true;
}
/// \brief Use magnitude of a vector to generate RGBA colors
///
template <typename T, int N, typename S>
bool ColorTableMapMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
const vtkm::cont::ColorTable& table,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut)
{
using namespace vtkm::worklet::colorconversion;
return vtkm::cont::ColorTableMap(
vtkm::cont::make_ArrayHandleTransform(values, MagnitudePortal()), table, rgbaOut);
}
/// \brief Use magnitude of a vector to generate RGB colors
///
template <typename T, int N, typename S>
bool ColorTableMapMagnitude(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
const vtkm::cont::ColorTable& table,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut)
{
using namespace vtkm::worklet::colorconversion;
return vtkm::cont::ColorTableMap(
vtkm::cont::make_ArrayHandleTransform(values, MagnitudePortal()), table, rgbOut);
}
/// \brief Use a single component of a vector to generate RGBA colors
///
template <typename T, int N, typename S>
bool ColorTableMapComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::IdComponent comp,
const vtkm::cont::ColorTable& table,
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8>& rgbaOut)
{
using namespace vtkm::worklet::colorconversion;
return vtkm::cont::ColorTableMap(
vtkm::cont::make_ArrayHandleTransform(values, ComponentPortal(comp)), table, rgbaOut);
}
/// \brief Use a single component of a vector to generate RGB colors
///
template <typename T, int N, typename S>
bool ColorTableMapComponent(const vtkm::cont::ArrayHandle<vtkm::Vec<T, N>, S>& values,
vtkm::IdComponent comp,
const vtkm::cont::ColorTable& table,
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8>& rgbOut)
{
using namespace vtkm::worklet::colorconversion;
return vtkm::cont::ColorTableMap(
vtkm::cont::make_ArrayHandleTransform(values, ComponentPortal(comp)), table, rgbOut);
}
}
}
#endif // vtk_m_cont_ColorTableMap_h

@ -12,15 +12,13 @@
#include <vtkm/Types.h>
#include <vtkm/cont/ColorTable.h>
#include <vtkm/cont/ColorTableMap.h>
#include <vtkm/cont/ColorTableSamples.h>
#include <vtkm/cont/testing/Testing.h>
// Required for implementation of ArrayRangeCompute for "odd" arrays
#include <vtkm/cont/ArrayRangeCompute.hxx>
// Required for implementation of ColorTable
#include <vtkm/cont/ColorTable.hxx>
#include <algorithm>
#include <iostream>
@ -180,7 +178,7 @@ public:
auto field = vtkm::cont::make_ArrayHandle({ -1, 0, 1, 2 });
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
const bool ran = table.Map(field, colors);
const bool ran = vtkm::cont::ColorTableMap(field, table, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute");
//verify that we clamp the values to the expected range
@ -203,7 +201,7 @@ public:
auto field = vtkm::cont::make_ArrayHandle({ -2, -1, 2, 3 });
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
const bool ran = table.Map(field, colors);
const bool ran = vtkm::cont::ColorTableMap(field, table, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute");
//verify that both the above and below range colors are used,
@ -215,7 +213,7 @@ public:
//verify that we can specify custom above and below range colors
table.SetAboveRangeColor(vtkm::Vec<float, 3>{ 1.0f, 0.0f, 0.0f }); //red
table.SetBelowRangeColor(vtkm::Vec<float, 3>{ 0.0f, 0.0f, 1.0f }); //green
const bool ran2 = table.Map(field, colors);
const bool ran2 = vtkm::cont::ColorTableMap(field, table, colors);
VTKM_TEST_ASSERT(ran2, "color table failed to execute");
CheckColors(colors, { { 0, 0, 255 }, { 0, 255, 0 }, { 255, 0, 255 }, { 255, 0, 0 } });
}
@ -248,7 +246,7 @@ public:
auto field = vtkm::cont::make_ArrayHandle({ 0, 10, 20, 30, 40, 50 });
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
const bool ran = newTable.Map(field, colors);
const bool ran = vtkm::cont::ColorTableMap(field, newTable, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute");
//values confirmed with ParaView 5.4
@ -280,7 +278,7 @@ public:
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
auto field = vtkm::cont::make_ArrayHandle({ 10.0f, -5.0f, -15.0f });
const bool ran = table.Map(field, colors);
const bool ran = vtkm::cont::ColorTableMap(field, table, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute");
CheckColors(colors, { { 0, 0, 128 }, { 0, 128, 255 }, { 128, 255, 255 } });
@ -315,7 +313,7 @@ public:
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors;
auto field = vtkm::cont::make_ArrayHandle({ 0, 10, 20, 30, 40, 50 });
const bool ran = table.Map(field, colors);
const bool ran = vtkm::cont::ColorTableMap(field, table, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute");
//values confirmed with ParaView 5.4
@ -356,7 +354,7 @@ public:
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
auto field = vtkm::cont::make_ArrayHandle({ 0.0f, 10.0f, 20.0f, 30.0f, 40.0f, 50.0f });
const bool ran = table.Map(field, colors);
const bool ran = vtkm::cont::ColorTableMap(field, table, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute");
//values confirmed with ParaView 5.4
@ -371,7 +369,7 @@ public:
std::cout << " Change Color Space" << std::endl;
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors_rgb;
table.SetColorSpace(vtkm::ColorSpace::RGB);
table.Map(field, colors_rgb);
vtkm::cont::ColorTableMap(field, table, colors_rgb);
CheckColors(colors_rgb,
{ { 0, 0, 255 },
@ -411,7 +409,7 @@ public:
vtkm::cont::ArrayHandle<vtkm::Vec4ui_8> colors;
auto field = vtkm::cont::make_ArrayHandle({ 0.0f, 10.0f, 20.0f, 30.0f, 40.0f, 50.0f });
const bool ran = table.Map(field, colors);
const bool ran = vtkm::cont::ColorTableMap(field, table, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute");
//values confirmed with ParaView 5.4
@ -480,7 +478,7 @@ public:
vtkm::cont::ArrayHandle<vtkm::Vec3ui_8> colors;
auto field = vtkm::cont::make_ArrayHandle({ -1, 0, 10, 20, 30, 40, 50, 60 });
const bool ran = table.Map(field, samples, colors);
const bool ran = vtkm::cont::ColorTableMap(field, samples, colors);
VTKM_TEST_ASSERT(ran, "color table failed to execute");
//values confirmed with ParaView 5.4

@ -12,7 +12,7 @@
#define vtk_m_filter_FieldToColors_hxx
#include <vtkm/VecTraits.h>
#include <vtkm/cont/ColorTable.hxx>
#include <vtkm/cont/ColorTableMap.h>
#include <vtkm/cont/ErrorFilterExecution.h>
namespace vtkm
@ -34,74 +34,68 @@ struct ComponentInputMode
}
template <typename T, typename S, typename U>
inline bool execute(const vtkm::cont::ColorTable& table,
ScalarInputMode,
inline bool execute(ScalarInputMode,
int,
const T& input,
const S& samples,
U& output,
vtkm::VecTraitsTagSingleComponent)
{
return table.Map(input, samples, output);
return vtkm::cont::ColorTableMap(input, samples, output);
}
template <typename T, typename S, typename U>
inline bool execute(const vtkm::cont::ColorTable& table,
MagnitudeInputMode,
inline bool execute(MagnitudeInputMode,
int,
const T& input,
const S& samples,
U& output,
vtkm::VecTraitsTagMultipleComponents)
{
return table.MapMagnitude(input, samples, output);
return vtkm::cont::ColorTableMapMagnitude(input, samples, output);
}
template <typename T, typename S, typename U>
inline bool execute(const vtkm::cont::ColorTable& table,
ComponentInputMode,
inline bool execute(ComponentInputMode,
int comp,
const T& input,
const S& samples,
U& output,
vtkm::VecTraitsTagMultipleComponents)
{
return table.MapComponent(input, comp, samples, output);
return vtkm::cont::ColorTableMapComponent(input, comp, samples, output);
}
//error cases
template <typename T, typename S, typename U>
inline bool execute(const vtkm::cont::ColorTable& table,
ScalarInputMode,
inline bool execute(ScalarInputMode,
int,
const T& input,
const S& samples,
U& output,
vtkm::VecTraitsTagMultipleComponents)
{ //vector input in scalar mode so do magnitude
return table.MapMagnitude(input, samples, output);
return vtkm::cont::ColorTableMapMagnitude(input, samples, output);
}
template <typename T, typename S, typename U>
inline bool execute(const vtkm::cont::ColorTable& table,
MagnitudeInputMode,
inline bool execute(MagnitudeInputMode,
int,
const T& input,
const S& samples,
U& output,
vtkm::VecTraitsTagSingleComponent)
{ //is a scalar array so ignore Magnitude mode
return table.Map(input, samples, output);
return vtkm::cont::ColorTableMap(input, samples, output);
}
template <typename T, typename S, typename U>
inline bool execute(const vtkm::cont::ColorTable& table,
ComponentInputMode,
inline bool execute(ComponentInputMode,
int,
const T& input,
const S& samples,
U& output,
vtkm::VecTraitsTagSingleComponent)
{ //is a scalar array so ignore COMPONENT mode
return table.Map(input, samples, output);
return vtkm::cont::ColorTableMap(input, samples, output);
}
@ -167,35 +161,20 @@ inline VTKM_CONT vtkm::cont::DataSet FieldToColors::DoExecute(
{
case SCALAR:
{
ran = execute(this->Table,
ScalarInputMode{},
this->Component,
inField,
this->SamplesRGBA,
output,
IsVec{});
ran =
execute(ScalarInputMode{}, this->Component, inField, this->SamplesRGBA, output, IsVec{});
break;
}
case MAGNITUDE:
{
ran = execute(this->Table,
MagnitudeInputMode{},
this->Component,
inField,
this->SamplesRGBA,
output,
IsVec{});
ran = execute(
MagnitudeInputMode{}, this->Component, inField, this->SamplesRGBA, output, IsVec{});
break;
}
case COMPONENT:
{
ran = execute(this->Table,
ComponentInputMode{},
this->Component,
inField,
this->SamplesRGBA,
output,
IsVec{});
ran = execute(
ComponentInputMode{}, this->Component, inField, this->SamplesRGBA, output, IsVec{});
break;
}
}
@ -215,35 +194,20 @@ inline VTKM_CONT vtkm::cont::DataSet FieldToColors::DoExecute(
{
case SCALAR:
{
ran = execute(this->Table,
ScalarInputMode{},
this->Component,
inField,
this->SamplesRGB,
output,
IsVec{});
ran =
execute(ScalarInputMode{}, this->Component, inField, this->SamplesRGB, output, IsVec{});
break;
}
case MAGNITUDE:
{
ran = execute(this->Table,
MagnitudeInputMode{},
this->Component,
inField,
this->SamplesRGB,
output,
IsVec{});
ran = execute(
MagnitudeInputMode{}, this->Component, inField, this->SamplesRGB, output, IsVec{});
break;
}
case COMPONENT:
{
ran = execute(this->Table,
ComponentInputMode{},
this->Component,
inField,
this->SamplesRGB,
output,
IsVec{});
ran = execute(
ComponentInputMode{}, this->Component, inField, this->SamplesRGB, output, IsVec{});
break;
}
}