8b133288ce
There was an error that caused deprecation warnings in VTK-m to be suppressed, which meant that many uses of deprecated features went unnoticed. This fixes those deprecation warnings. The majority of the warnings were caused by the use of the deprecated `Cast`, `CopyTo`, and `ResetTypes` methods of `UnknownArrayHandle` (or `VariantArrayHandle`). Both `Cast` and `CopyTo` have been subsumed by `AsArrayHandle` (to make the functionality more clear). `ResetTypes` now requires a second template argument to define the storage types to try. Also fixed some issues with `SerializableField` being deprecated. This class is no longer necessary because `Field` can now be directly serialized.
82 lines
2.4 KiB
C++
82 lines
2.4 KiB
C++
//============================================================================
|
|
// 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.
|
|
//============================================================================
|
|
|
|
#include <vtkm/io/ImageWriterBase.h>
|
|
|
|
#include <vtkm/cont/Logging.h>
|
|
|
|
namespace vtkm
|
|
{
|
|
namespace io
|
|
{
|
|
|
|
ImageWriterBase::ImageWriterBase(const char* filename)
|
|
: FileName(filename)
|
|
{
|
|
}
|
|
|
|
ImageWriterBase::ImageWriterBase(const std::string& filename)
|
|
: FileName(filename)
|
|
{
|
|
}
|
|
|
|
ImageWriterBase::~ImageWriterBase() noexcept {}
|
|
|
|
void ImageWriterBase::WriteDataSet(const vtkm::cont::DataSet& dataSet,
|
|
const std::string& colorFieldName)
|
|
{
|
|
using CellSetType = vtkm::cont::CellSetStructured<2>;
|
|
if (!dataSet.GetCellSet().IsType<CellSetType>())
|
|
{
|
|
throw vtkm::cont::ErrorBadType(
|
|
"Image writers can only write data sets with 2D structured data.");
|
|
}
|
|
CellSetType cellSet = dataSet.GetCellSet().Cast<CellSetType>();
|
|
vtkm::Id2 cellDimensions = cellSet.GetCellDimensions();
|
|
// Number of points is one more in each dimension than number of cells
|
|
vtkm::Id width = cellDimensions[0] + 1;
|
|
vtkm::Id height = cellDimensions[1] + 1;
|
|
|
|
vtkm::cont::Field colorField;
|
|
if (!colorFieldName.empty())
|
|
{
|
|
if (!dataSet.HasPointField(colorFieldName))
|
|
{
|
|
throw vtkm::cont::ErrorBadValue("Data set does not have requested field " + colorFieldName);
|
|
}
|
|
colorField = dataSet.GetPointField(colorFieldName);
|
|
}
|
|
else
|
|
{
|
|
// Find a field of the correct type.
|
|
vtkm::Id numFields = dataSet.GetNumberOfFields();
|
|
bool foundField = false;
|
|
for (vtkm::Id fieldId = 0; fieldId < numFields; ++fieldId)
|
|
{
|
|
colorField = dataSet.GetField(fieldId);
|
|
if ((colorField.GetAssociation() == vtkm::cont::Field::Association::POINTS) &&
|
|
(colorField.GetData().IsType<ColorArrayType>()))
|
|
{
|
|
foundField = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!foundField)
|
|
{
|
|
throw vtkm::cont::ErrorBadValue(
|
|
"Data set does not have any fields that look like color data.");
|
|
}
|
|
}
|
|
|
|
this->Write(width, height, colorField.GetData().AsArrayHandle<ColorArrayType>());
|
|
}
|
|
}
|
|
} // namespace vtkm::io
|