Merge topic 'clipping-example-use-vtkm-io'

c6a562ae Fix for MSVC conversion warning
70b2eff8 Update clipping example to use the new io framework
503f9197 Fix VTK DataSet IO to work correctly with DynamicArrayHandle
2b771418 Update Clip worklets to work with more types

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !268
This commit is contained in:
Sujin Philip 2015-11-12 15:32:16 -05:00 committed by Kitware Robot
commit 501371ee5e
5 changed files with 265 additions and 274 deletions

@ -21,6 +21,8 @@
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/Timer.h>
#include <vtkm/io/reader/VTKDataSetReader.h>
#include <vtkm/io/writer/VTKDataSetWriter.h>
#include <vtkm/worklet/Clip.h>
@ -36,223 +38,14 @@ VTKM_THIRDPARTY_POST_INCLUDE
typedef vtkm::Vec<vtkm::Float32, 3> FloatVec3;
template<typename T>
inline void flipEndianness(T* buffer, vtkm::Id size)
{
for (vtkm::Id i = 0; i < size; ++i)
{
T val = buffer[i];
vtkm::UInt8 *bytes = reinterpret_cast<vtkm::UInt8*>(&val);
std::reverse(bytes, bytes + sizeof(T));
buffer[i] = val;
}
}
template<typename T, typename DeviceAdapter>
inline vtkm::cont::ArrayHandle<vtkm::Float32> LoadBinaryPointDataImpl(
std::ifstream &fstream, vtkm::Id numPoints, T, DeviceAdapter)
{
vtkm::cont::ArrayHandle<vtkm::Float32> result;
std::vector<T> buffer(static_cast<size_t>(numPoints));
fstream.read(reinterpret_cast<char*>(&buffer[0]),
numPoints * static_cast<vtkm::Id>(sizeof(T)));
flipEndianness(&buffer[0], numPoints);
vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>::Copy(
vtkm::cont::make_ArrayHandleCast(vtkm::cont::make_ArrayHandle(buffer), vtkm::Float32()),
result);
return result;
}
template<typename DeviceAdapter>
inline vtkm::cont::ArrayHandle<vtkm::Float32> LoadBinaryPointData(
std::ifstream &fstream, vtkm::Id numPoints, std::string type, DeviceAdapter)
{
if (type == "short")
{
return LoadBinaryPointDataImpl(fstream, numPoints, short(), DeviceAdapter());
}
else if (type == "float")
{
return LoadBinaryPointDataImpl(fstream, numPoints, vtkm::Float32(), DeviceAdapter());
}
else
{
throw std::runtime_error("only short and float types supported");
}
return vtkm::cont::ArrayHandle<vtkm::Float32>();
}
template <typename DeviceAdapter>
vtkm::cont::DataSet LoadVtkLegacyStructuredPoints(const char *fname, DeviceAdapter)
{
vtkm::Id3 dim;
FloatVec3 spacing, origin;
vtkm::cont::ArrayHandle<vtkm::Float32> scalars;
std::ifstream vtkfile;
vtkfile.open(fname);
std::string tag;
std::getline(vtkfile, tag); // version comment
std::getline(vtkfile, tag); // datset name
vtkfile >> tag;
if (tag != "BINARY")
{
throw std::runtime_error("only binary format supported");
}
for (;;)
{
vtkfile >> tag;
if (tag == "DATASET")
{
std::string dataset;
vtkfile >> dataset;
if (dataset != "STRUCTURED_POINTS")
{
throw std::runtime_error("expecting structured dataset");
}
}
else if (tag == "DIMENSIONS")
{
vtkfile >> dim[0] >> dim[1] >> dim[2];
}
else if (tag == "SPACING")
{
vtkfile >> spacing[0] >> spacing[1] >> spacing[2];
}
else if (tag == "ORIGIN")
{
vtkfile >> origin[0] >> origin[1] >> origin[2];
}
else if (tag == "POINT_DATA")
{
vtkm::Id numPoints;
std::string type;
vtkfile >> numPoints;
vtkfile >> tag;
if (tag != "SCALARS")
{
throw std::runtime_error("only scalars supported for point data");
}
vtkfile >> tag >> type >> std::ws;
std::getline(vtkfile, tag); // LOOKUP_TABLE default
scalars = LoadBinaryPointData(vtkfile, numPoints, type, DeviceAdapter());
break;
}
}
vtkfile.close();
vtkm::cont::CellSetStructured<3> cs("cells");
cs.SetPointDimensions(vtkm::make_Vec(dim[0], dim[1], dim[2]));
vtkm::cont::DataSet ds;
ds.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", 1, dim, origin,
spacing));
ds.AddField(vtkm::cont::Field("scalars", 1, vtkm::cont::Field::ASSOC_POINTS,
scalars));
ds.AddCellSet(cs);
return ds;
}
void WriteVtkLegacyUnstructuredGrid(const char *fname, const vtkm::cont::DataSet &ds)
{
std::ofstream vtkfile;
vtkfile.open(fname);
vtkfile << "# vtk DataFile Version 3.0" << std::endl;
vtkfile << "vtkm_clip_output" << std::endl;
vtkfile << "BINARY" << std::endl << "DATASET UNSTRUCTURED_GRID" << std::endl;
vtkm::cont::CoordinateSystem coords = ds.GetCoordinateSystem();
vtkm::Id numPoints = coords.GetData().GetNumberOfValues();
vtkfile << "POINTS " << numPoints << " float" << std::endl;
{
vtkm::cont::ArrayHandle<FloatVec3> coordinates =
coords.GetData().CastToArrayHandle(FloatVec3(), VTKM_DEFAULT_STORAGE_TAG());
std::vector<FloatVec3> buffer(static_cast<size_t>(numPoints));
std::copy(vtkm::cont::ArrayPortalToIteratorBegin(coordinates.GetPortalConstControl()),
vtkm::cont::ArrayPortalToIteratorEnd(coordinates.GetPortalConstControl()),
buffer.begin());
flipEndianness(reinterpret_cast<vtkm::Float32*>(&buffer[0]), numPoints * 3);
vtkfile.write(reinterpret_cast<const char*>(&buffer[0]),
numPoints * static_cast<vtkm::Id>(sizeof(FloatVec3)));
}
vtkfile << std::endl;
vtkm::cont::CellSetExplicit<> cse =
ds.GetCellSet().CastTo<vtkm::cont::CellSetExplicit<> >();
vtkm::Id numCells = cse.GetNumberOfCells();
{
std::vector<int> idxBuffer, shapeBuffer;
idxBuffer.reserve(static_cast<size_t>(numCells * 4));
shapeBuffer.reserve(static_cast<size_t>(numCells));
vtkm::Vec<vtkm::Id, 8> pointIndices;
for (vtkm::Id i = 0; i < numCells; ++i)
{
vtkm::IdComponent numCellPoints = cse.GetNumberOfPointsInCell(i);
idxBuffer.push_back(static_cast<int>(numCellPoints));
cse.GetIndices(i, pointIndices);
for (vtkm::IdComponent j = 0; j < numCellPoints; ++j)
{
idxBuffer.push_back(static_cast<int>(pointIndices[j]));
}
shapeBuffer.push_back(static_cast<int>(cse.GetCellShape(i)));
}
vtkm::Id numIndices = static_cast<vtkm::Id>(idxBuffer.size());
vtkfile << "CELLS " << numCells << " " << numIndices << std::endl;
flipEndianness(&idxBuffer[0], numIndices);
vtkfile.write(reinterpret_cast<const char*>(&idxBuffer[0]),
numIndices * static_cast<vtkm::Id>(sizeof(idxBuffer[0])));
vtkfile << std::endl;
vtkfile << "CELL_TYPES " << numCells << std::endl;
flipEndianness(&shapeBuffer[0], numCells);
vtkfile.write(reinterpret_cast<const char*>(&shapeBuffer[0]),
numCells * static_cast<vtkm::Id>(sizeof(shapeBuffer[0])));
}
vtkfile << std::endl;
vtkm::cont::Field field = ds.GetField(0);
vtkfile << "POINT_DATA " << numPoints << std::endl
<< "SCALARS " << field.GetName() << " float" << std::endl
<< "LOOKUP_TABLE default" << std::endl;
{
vtkm::cont::ArrayHandle<vtkm::Float32> scalars =
field.GetData().CastToArrayHandle(vtkm::Float32(), VTKM_DEFAULT_STORAGE_TAG());
std::vector<vtkm::Float32> buffer(static_cast<size_t>(numPoints));
std::copy(vtkm::cont::ArrayPortalToIteratorBegin(scalars.GetPortalConstControl()),
vtkm::cont::ArrayPortalToIteratorEnd(scalars.GetPortalConstControl()),
buffer.begin());
flipEndianness(&buffer[0], numPoints);
vtkfile.write(reinterpret_cast<const char*>(&buffer[0]),
numPoints * static_cast<vtkm::Id>(sizeof(vtkm::Float32)));
}
vtkfile << std::endl;
vtkfile.close();
}
int main(int argc, char *argv[])
{
if (argc != 4)
if (argc < 4)
{
std::cout << "Usage: " << std::endl
<< "$ " << argv[0]
<< " <vtk_structure_points> <isoval> <vtk_unstructured_grid>"
<< " <input_vtk_file> [fieldName] <isoval> <output_vtk_file>"
<< std::endl;
return 1;
}
@ -262,24 +55,46 @@ int main(int argc, char *argv[])
<< vtkm::cont::internal::DeviceAdapterTraits<DeviceAdapter>::GetId()
<< std::endl;
vtkm::cont::DataSet input = LoadVtkLegacyStructuredPoints(argv[1], DeviceAdapter());
vtkm::io::reader::VTKDataSetReader reader(argv[1]);
vtkm::cont::DataSet input = reader.ReadDataSet();
vtkm::Float32 clipValue = boost::lexical_cast<vtkm::Float32>(argv[2]);
vtkm::cont::Field scalarField = (argc == 5) ?
input.GetField(argv[2]) :
input.GetField(0);
vtkm::Float32 clipValue = boost::lexical_cast<vtkm::Float32>(argv[argc - 2]);
vtkm::worklet::Clip<DeviceAdapter> clip;
vtkm::cont::Timer<DeviceAdapter> total;
vtkm::cont::Timer<DeviceAdapter> timer;
vtkm::cont::CellSetExplicit<> outputCellSet =
clip.Run(input.GetCellSet(0), input.GetField(0).GetData(), clipValue);
clip.Run(input.GetCellSet(0),
scalarField.GetData().ResetTypeList(vtkm::TypeListTagScalarAll()),
clipValue);
vtkm::Float64 clipTime = timer.GetElapsedTime();
vtkm::cont::DataSet output;
output.AddCellSet(outputCellSet);
timer.Reset();
vtkm::cont::DynamicArrayHandle coords =
clip.ProcessField(input.GetCoordinateSystem(0).GetData());
vtkm::Float64 processCoordinatesTime = timer.GetElapsedTime();
output.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", 1, coords));
timer.Reset();
vtkm::cont::DynamicArrayHandle scalars =
clip.ProcessField(input.GetField(0).GetData());
for (vtkm::Id i = 0; i < input.GetNumberOfFields(); ++i)
{
vtkm::cont::Field inField = input.GetField(i);
if (inField.GetAssociation() != vtkm::cont::Field::ASSOC_POINTS)
{
continue; // clip only supports point fields for now.
}
vtkm::cont::DynamicArrayHandle data =
clip.ProcessField(inField.GetData().ResetTypeList(vtkm::TypeListTagAll()));
output.AddField(vtkm::cont::Field(inField.GetName(), 1,
vtkm::cont::Field::ASSOC_POINTS, data));
}
vtkm::Float64 processScalarsTime = timer.GetElapsedTime();
vtkm::Float64 totalTime = total.GetElapsedTime();
@ -290,13 +105,9 @@ int main(int argc, char *argv[])
<< "process scalars: " << processScalarsTime << std::endl
<< "Total: " << totalTime << std::endl;
vtkm::cont::DataSet output;
output.AddField(vtkm::cont::Field("scalars", 1, vtkm::cont::Field::ASSOC_POINTS,
scalars));
output.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", 1, coords));
output.AddCellSet(outputCellSet);
WriteVtkLegacyUnstructuredGrid(argv[3], output);
std::ofstream outFile(argv[argc - 1]);
vtkm::io::writer::VTKDataSetWriter::Write(outFile, output);
outFile.close();
return 0;
}

@ -33,11 +33,13 @@
VTKM_THIRDPARTY_PRE_INCLUDE
#include <boost/smart_ptr/scoped_ptr.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/type_traits/is_same.hpp>
VTKM_THIRDPARTY_POST_INCLUDE
#include <algorithm>
#include <fstream>
#include <string>
#include <typeinfo>
#include <vector>
@ -92,34 +94,92 @@ inline void parseAssert(bool condition)
}
}
struct DummyFixed8Type
{
vtkm::UInt8 data;
};
template <typename T> struct StreamIOType { typedef T Type; };
template <> struct StreamIOType<vtkm::Int8> { typedef vtkm::Int16 Type; };
template <> struct StreamIOType<vtkm::UInt8> { typedef vtkm::UInt16 Type; };
// Since Fields and DataSets store data in the default DynamicArrayHandle, convert
// the data to the closest type supported by default. The following will
// need to be updated if DynamicArrayHandle or TypeListTagCommon changes.
template <typename T> struct ClosestCommonType { typedef T Type; };
template <> struct ClosestCommonType<vtkm::Int8> { typedef vtkm::Int32 Type; };
template <> struct ClosestCommonType<vtkm::UInt8> { typedef vtkm::Int32 Type; };
template <> struct ClosestCommonType<vtkm::Int16> { typedef vtkm::Int32 Type; };
template <> struct ClosestCommonType<vtkm::UInt16> { typedef vtkm::Int32 Type; };
template <> struct ClosestCommonType<vtkm::UInt32> { typedef vtkm::Int64 Type; };
template <> struct ClosestCommonType<vtkm::UInt64> { typedef vtkm::Int64 Type; };
template <typename T> struct ClosestFloat { typedef T Type; };
template <> struct ClosestFloat<vtkm::Int8> { typedef vtkm::Float32 Type; };
template <> struct ClosestFloat<vtkm::UInt8> { typedef vtkm::Float32 Type; };
template <> struct ClosestFloat<vtkm::Int16> { typedef vtkm::Float32 Type; };
template <> struct ClosestFloat<vtkm::UInt16> { typedef vtkm::Float32 Type; };
template <> struct ClosestFloat<vtkm::Int32> { typedef vtkm::Float64 Type; };
template <> struct ClosestFloat<vtkm::UInt32> { typedef vtkm::Float64 Type; };
template <> struct ClosestFloat<vtkm::Int64> { typedef vtkm::Float64 Type; };
template <> struct ClosestFloat<vtkm::UInt64> { typedef vtkm::Float64 Type; };
template <typename T>
struct TypeTraits
vtkm::cont::DynamicArrayHandle CreateDynamicArrayHandle(const std::vector<T> &vec)
{
typedef T AsciiReadType;
};
switch (vtkm::VecTraits<T>::NUM_COMPONENTS)
{
case 1:
{
typedef typename ClosestCommonType<T>::Type CommonType;
if (!boost::is_same<T, CommonType>::value)
{
std::cerr << "Type " << typeid(T).name() << " is currently unsupported. "
<< "Converting to " << typeid(CommonType).name() << "." << std::endl;
}
template <>
struct TypeTraits<vtkm::Int8>
{
typedef vtkm::Int16 AsciiReadType;
};
vtkm::cont::ArrayHandle<CommonType> output;
output.Allocate(static_cast<vtkm::Id>(vec.size()));
for (vtkm::Id i = 0; i < output.GetNumberOfValues(); ++i)
{
output.GetPortalControl().Set(i,
static_cast<CommonType>(vec[static_cast<std::size_t>(i)]));
}
template <>
struct TypeTraits<vtkm::UInt8>
{
typedef vtkm::UInt16 AsciiReadType;
};
return vtkm::cont::DynamicArrayHandle(output);
}
case 2:
case 3:
{
typedef typename vtkm::VecTraits<T>::ComponentType InComponentType;
typedef typename ClosestFloat<InComponentType>::Type OutComponentType;
typedef vtkm::Vec<OutComponentType, 3> CommonType;
if (!boost::is_same<T, CommonType>::value)
{
std::cerr << "Type " << typeid(InComponentType).name()
<< "[" << vtkm::VecTraits<T>::NUM_COMPONENTS << "] "
<< "is currently unsupported. Converting to "
<< typeid(OutComponentType).name() << "[3]." << std::endl;
}
template <>
struct TypeTraits<DummyFixed8Type>
{
typedef vtkm::Float32 AsciiReadType;
};
vtkm::cont::ArrayHandle<CommonType> output;
output.Allocate(static_cast<vtkm::Id>(vec.size()));
for (vtkm::Id i = 0; i < output.GetNumberOfValues(); ++i)
{
CommonType outval = CommonType();
for (vtkm::IdComponent j = 0; j < vtkm::VecTraits<T>::NUM_COMPONENTS; ++j)
{
outval[j] = static_cast<OutComponentType>(
vtkm::VecTraits<T>::GetComponent(vec[static_cast<std::size_t>(i)], j));
}
output.GetPortalControl().Set(i, outval);
}
return vtkm::cont::DynamicArrayHandle(output);
}
default:
{
std::cerr << "Only 1, 2, or 3 components supported. Skipping." << std::endl;
return vtkm::cont::DynamicArrayHandle(vtkm::cont::ArrayHandle<vtkm::Float32>());
}
}
}
} // namespace internal
@ -443,7 +503,7 @@ private:
std::size_t numValues;
this->DataFile->Stream >> dataName >> numValues >> std::ws;
this->SkipArray(numElements * numValues, internal::DummyFixed8Type());
this->SkipArray(numElements * numValues, internal::ColorChannel8());
}
void ReadLookupTable(std::string &dataName)
@ -453,7 +513,7 @@ private:
std::size_t numEntries;
this->DataFile->Stream >> dataName >> numEntries >> std::ws;
this->SkipArray(numEntries, vtkm::Vec<internal::DummyFixed8Type, 4>());
this->SkipArray(numEntries, vtkm::Vec<internal::ColorChannel8, 4>());
}
void ReadTextureCoordinates(std::size_t numElements, std::string &dataName,
@ -544,11 +604,7 @@ private:
std::vector<T> buffer(this->NumElements);
this->Reader->ReadArray(buffer);
vtkm::cont::ArrayHandle<T> data;
data.Allocate(static_cast<vtkm::Id>(buffer.size()));
std::copy(buffer.begin(), buffer.end(),
vtkm::cont::ArrayPortalToIteratorBegin(data.GetPortalControl()));
*this->Data = vtkm::cont::DynamicArrayHandle(data);
*this->Data = internal::CreateDynamicArrayHandle(buffer);
}
template <typename T>
@ -602,7 +658,7 @@ private:
{
for (vtkm::IdComponent j = 0; j < numComponents; ++j)
{
typename internal::TypeTraits<ComponentType>::AsciiReadType val;
typename internal::StreamIOType<ComponentType>::Type val;
this->DataFile->Stream >> val;
vtkm::VecTraits<T>::SetComponent(buffer[i], j,
static_cast<ComponentType>(val));
@ -647,7 +703,7 @@ private:
{
for (vtkm::IdComponent j = 0; j < numComponents; ++j)
{
typename internal::TypeTraits<ComponentType>::AsciiReadType val;
typename internal::StreamIOType<ComponentType>::Type val;
this->DataFile->Stream >> val;
}
}
@ -694,7 +750,7 @@ private:
}
} // vtkm::io::reader
VTKM_BASIC_TYPE_VECTOR(io::reader::internal::DummyFixed8Type)
VTKM_BASIC_TYPE_VECTOR(io::reader::internal::ColorChannel8)
VTKM_BASIC_TYPE_VECTOR(io::reader::internal::DummyBitType)
#endif // vtk_m_io_reader_VTKDataSetReaderBase_h

@ -22,6 +22,7 @@
#include <vtkm/Types.h>
#include <algorithm>
#include <cassert>
#include <string>
@ -118,6 +119,7 @@ inline DataType DataTypeId(const std::string &str)
return type;
}
struct DummyBitType
{
// Needs to work with streams' << operator
@ -127,6 +129,43 @@ struct DummyBitType
}
};
class ColorChannel8
{
public:
ColorChannel8() : Data()
{ }
ColorChannel8(vtkm::UInt8 val) : Data(val)
{ }
ColorChannel8(vtkm::Float32 val)
: Data(static_cast<vtkm::UInt8>(std::min(std::max(val, 1.0f), 0.0f) * 255))
{ }
operator vtkm::Float32() const
{
return static_cast<vtkm::Float32>(this->Data)/255.0f;
}
operator vtkm::UInt8() const
{
return this->Data;
}
private:
vtkm::UInt8 Data;
};
inline std::ostream& operator<<(std::ostream& out, const ColorChannel8 &val)
{
return out << static_cast<vtkm::Float32>(val);
}
inline std::istream& operator>>(std::istream& in, ColorChannel8 &val)
{
vtkm::Float32 fval;
in >> fval;
val = ColorChannel8(fval);
return in;
}
template <typename T, typename Functor>
inline void SelectVecTypeAndCall(T, vtkm::IdComponent numComponents, const Functor &functor)
{
@ -163,28 +202,28 @@ inline void SelectTypeAndCall(DataType dtype, vtkm::IdComponent numComponents,
SelectVecTypeAndCall(DummyBitType(), numComponents, functor);
break;
case DTYPE_UNSIGNED_CHAR:
SelectVecTypeAndCall(vtkm::Int8(), numComponents, functor);
break;
case DTYPE_CHAR:
SelectVecTypeAndCall(vtkm::UInt8(), numComponents, functor);
break;
case DTYPE_UNSIGNED_SHORT:
SelectVecTypeAndCall(vtkm::Int16(), numComponents, functor);
case DTYPE_CHAR:
SelectVecTypeAndCall(vtkm::Int8(), numComponents, functor);
break;
case DTYPE_SHORT:
case DTYPE_UNSIGNED_SHORT:
SelectVecTypeAndCall(vtkm::UInt16(), numComponents, functor);
break;
case DTYPE_UNSIGNED_INT:
SelectVecTypeAndCall(vtkm::Int32(), numComponents, functor);
case DTYPE_SHORT:
SelectVecTypeAndCall(vtkm::Int16(), numComponents, functor);
break;
case DTYPE_INT:
case DTYPE_UNSIGNED_INT:
SelectVecTypeAndCall(vtkm::UInt32(), numComponents, functor);
break;
case DTYPE_INT:
SelectVecTypeAndCall(vtkm::Int32(), numComponents, functor);
break;
case DTYPE_UNSIGNED_LONG:
SelectVecTypeAndCall(vtkm::Int64(), numComponents, functor);
SelectVecTypeAndCall(vtkm::UInt64(), numComponents, functor);
break;
case DTYPE_LONG:
SelectVecTypeAndCall(vtkm::UInt64(), numComponents, functor);
SelectVecTypeAndCall(vtkm::Int64(), numComponents, functor);
break;
case DTYPE_FLOAT:
SelectVecTypeAndCall(vtkm::Float32(), numComponents, functor);

@ -156,6 +156,69 @@ public:
}
};
template <typename T> struct DataTypeName
{
static const char* Name() { return "unknown"; }
};
template <> struct DataTypeName<vtkm::Int8>
{
static const char* Name() { return "char"; }
};
template <> struct DataTypeName<vtkm::UInt8>
{
static const char* Name() { return "unsigned_char"; }
};
template <> struct DataTypeName<vtkm::Int16>
{
static const char* Name() { return "short"; }
};
template <> struct DataTypeName<vtkm::UInt16>
{
static const char* Name() { return "unsigned_short"; }
};
template <> struct DataTypeName<vtkm::Int32>
{
static const char* Name() { return "int"; }
};
template <> struct DataTypeName<vtkm::UInt32>
{
static const char* Name() { return "unsigned_int"; }
};
template <> struct DataTypeName<vtkm::Int64>
{
static const char* Name() { return "long"; }
};
template <> struct DataTypeName<vtkm::UInt64>
{
static const char* Name() { return "unsigned_long"; }
};
template <> struct DataTypeName<vtkm::Float32>
{
static const char* Name() { return "float"; }
};
template <> struct DataTypeName<vtkm::Float64>
{
static const char* Name() { return "double"; }
};
class GetDataTypeName
{
public:
GetDataTypeName(std::string &name)
: Name(&name)
{ }
template <typename ArrayHandleType>
void operator()(const ArrayHandleType &) const
{
typedef typename vtkm::VecTraits<typename ArrayHandleType::ValueType>::ComponentType
DataType;
*this->Name = DataTypeName<DataType>::Name();
}
private:
std::string *Name;
};
}
namespace vtkm
@ -179,7 +242,10 @@ private:
vtkm::Id npoints = cdata.GetNumberOfValues();
out << "POINTS " << npoints << " float" << std::endl;
std::string typeName;
cdata.CastAndCall(GetDataTypeName(typeName));
out << "POINTS " << npoints << " " << typeName << " " << std::endl;
cdata.CastAndCall(OutputPointsFunctor(out));
}
@ -251,7 +317,10 @@ private:
out << "POINT_DATA " << npoints << std::endl;
wrote_header = true;
out << "SCALARS " << field.GetName() << " float "<< ncomps << std::endl;
std::string typeName;
field.GetData().CastAndCall(GetDataTypeName(typeName));
out << "SCALARS " << field.GetName() << " " << typeName << " " << ncomps << std::endl;
out << "LOOKUP_TABLE default" << std::endl;
field.GetData().CastAndCall(OutputFieldFunctor(out));
@ -281,7 +350,10 @@ private:
out << "CELL_DATA " << ncells << std::endl;
wrote_header = true;
out << "SCALARS " << field.GetName() << " float "<< ncomps << std::endl;
std::string typeName;
field.GetData().CastAndCall(GetDataTypeName(typeName));
out << "SCALARS " << field.GetName() << " " << typeName << " " << ncomps << std::endl;
out << "LOOKUP_TABLE default" << std::endl;
field.GetData().CastAndCall(OutputFieldFunctor(out));

@ -103,6 +103,20 @@ void swap(T &v1, T &v2)
v2 = temp;
}
template <typename T>
VTKM_EXEC_CONT_EXPORT
T Scale(const T &val, vtkm::Float64 scale)
{
return static_cast<T>(scale * static_cast<vtkm::Float64>(val));
}
template <typename T, vtkm::IdComponent NumComponents>
VTKM_EXEC_CONT_EXPORT
vtkm::Vec<T, NumComponents> Scale(const vtkm::Vec<T, NumComponents> &val,
vtkm::Float64 scale)
{
return val * scale;
}
template <typename DeviceAdapter>
class ExecutionConnectivityExplicit : vtkm::exec::ExecutionObjectBase
@ -261,7 +275,7 @@ public:
{
public:
typedef void ControlSignature(TopologyIn topology,
FieldInPoint<Scalar> scalars,
FieldInPoint<ScalarAll> scalars,
FieldOutCell<IdType> clipTableIdxs,
FieldOutCell<TypeClipStats> stats);
typedef void ExecutionSignature(_2, CellShape, FromCount, _3, _4);
@ -322,7 +336,7 @@ public:
{
public:
typedef void ControlSignature(TopologyIn topology,
FieldInPoint<Scalar> scalars,
FieldInPoint<ScalarAll> scalars,
FieldInCell<IdType> clipTableIdxs,
FieldInCell<TypeClipStats> cellSetIdxs,
ExecObject connectivityExplicit,
@ -623,9 +637,8 @@ public:
EdgeInterpolation ei = this->Interpolation.Get(idx);
T v1 = Field.Get(ei.Vertex1);
T v2 = Field.Get(ei.Vertex2);
typename VecTraits<T>::ComponentType w =
static_cast<typename VecTraits<T>::ComponentType>(ei.Weight);
Field.Set(this->NewPointsOffset + idx, (w * (v2 - v1)) + v1);
Field.Set(this->NewPointsOffset + idx,
internal::Scale(T(v2 - v1), ei.Weight) + v1);
}
private: