2022-02-02 02:45:07 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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.
|
|
|
|
//============================================================================
|
2022-01-05 20:30:40 +00:00
|
|
|
#include <vtkm/cont/Initialize.h>
|
|
|
|
|
2022-02-07 20:34:18 +00:00
|
|
|
#include <vtkm/io/VTKDataSetReader.h>
|
|
|
|
#include <vtkm/io/VTKDataSetWriter.h>
|
2022-01-05 20:30:40 +00:00
|
|
|
|
|
|
|
#include <vtkm/worklet/WorkletMapTopology.h>
|
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
|
|
|
|
|
|
|
struct ConvertPointFieldToCells : vtkm::worklet::WorkletVisitCellsWithPoints
|
|
|
|
{
|
|
|
|
using ControlSignature = void(CellSetIn topology,
|
|
|
|
FieldInPoint inPointField,
|
|
|
|
FieldOutCell outCellField);
|
|
|
|
using ExecutionSignature = void(_2 inPointField, _3 outCellField);
|
|
|
|
using InputDomain = _1;
|
|
|
|
|
|
|
|
template <typename InPointFieldVecType, typename OutCellFieldType>
|
2022-02-04 16:43:00 +00:00
|
|
|
VTKM_EXEC void operator()(const InPointFieldVecType& inPointFieldVec,
|
|
|
|
OutCellFieldType& outCellField) const
|
2022-01-05 20:30:40 +00:00
|
|
|
{
|
|
|
|
vtkm::IdComponent numPoints = inPointFieldVec.GetNumberOfComponents();
|
|
|
|
|
|
|
|
outCellField = OutCellFieldType(0);
|
|
|
|
for (vtkm::IdComponent pointIndex = 0; pointIndex < numPoints; ++pointIndex)
|
|
|
|
{
|
|
|
|
outCellField = outCellField + inPointFieldVec[pointIndex];
|
|
|
|
}
|
2022-02-16 20:16:07 +00:00
|
|
|
outCellField =
|
|
|
|
static_cast<OutCellFieldType>(outCellField / static_cast<vtkm::FloatDefault>(numPoints));
|
2022-01-05 20:30:40 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace worklet
|
|
|
|
} // namespace vtkm
|
|
|
|
|
2024-02-10 20:33:46 +00:00
|
|
|
#include <vtkm/filter/Filter.h>
|
2022-01-05 20:30:40 +00:00
|
|
|
|
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace filter
|
|
|
|
{
|
|
|
|
|
2024-02-10 20:33:46 +00:00
|
|
|
struct ConvertPointFieldToCells : vtkm::filter::Filter
|
2022-01-05 20:30:40 +00:00
|
|
|
{
|
2022-05-26 18:52:08 +00:00
|
|
|
VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& inDataSet) override;
|
2022-01-05 20:30:40 +00:00
|
|
|
};
|
|
|
|
|
2022-05-26 18:52:08 +00:00
|
|
|
VTKM_CONT cont::DataSet ConvertPointFieldToCells::DoExecute(const vtkm::cont::DataSet& inDataSet)
|
2022-01-05 20:30:40 +00:00
|
|
|
{
|
2022-05-26 18:52:08 +00:00
|
|
|
const auto& inField = this->GetFieldFromDataSet(inDataSet);
|
2022-01-05 20:30:40 +00:00
|
|
|
|
2022-05-26 18:52:08 +00:00
|
|
|
vtkm::cont::UnknownArrayHandle outArray;
|
2022-10-12 00:23:44 +00:00
|
|
|
auto resolveType = [&](const auto& inConcrete) {
|
|
|
|
using ValueType = typename std::decay_t<decltype(inConcrete)>::ValueType;
|
2022-01-05 20:30:40 +00:00
|
|
|
|
2022-10-12 00:23:44 +00:00
|
|
|
vtkm::cont::ArrayHandle<ValueType> outConcrete;
|
2022-05-26 18:52:08 +00:00
|
|
|
this->Invoke(
|
2022-10-12 00:23:44 +00:00
|
|
|
vtkm::worklet::ConvertPointFieldToCells{}, inDataSet.GetCellSet(), inConcrete, outConcrete);
|
|
|
|
outArray = outConcrete;
|
2022-05-26 18:52:08 +00:00
|
|
|
};
|
|
|
|
this->CastAndCallScalarField(inField, resolveType);
|
2022-01-05 20:30:40 +00:00
|
|
|
|
|
|
|
std::string outFieldName = this->GetOutputFieldName();
|
|
|
|
if (outFieldName == "")
|
|
|
|
{
|
2022-05-26 18:52:08 +00:00
|
|
|
outFieldName = inField.GetName();
|
2022-01-05 20:30:40 +00:00
|
|
|
}
|
2022-05-26 18:52:08 +00:00
|
|
|
return this->CreateResultFieldCell(inDataSet, outFieldName, outArray);
|
2022-01-05 20:30:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace filter
|
|
|
|
} // namespace vtkm
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
auto opts = vtkm::cont::InitializeOptions::DefaultAnyDevice;
|
|
|
|
vtkm::cont::InitializeResult config = vtkm::cont::Initialize(argc, argv, opts);
|
|
|
|
|
|
|
|
const char* input = "data/kitchen.vtk";
|
|
|
|
vtkm::io::VTKDataSetReader reader(input);
|
|
|
|
vtkm::cont::DataSet ds_from_file = reader.ReadDataSet();
|
|
|
|
|
|
|
|
vtkm::filter::ConvertPointFieldToCells pointToCell;
|
|
|
|
pointToCell.SetActiveField("c1");
|
|
|
|
vtkm::cont::DataSet ds_from_convert = pointToCell.Execute(ds_from_file);
|
|
|
|
|
|
|
|
vtkm::io::VTKDataSetWriter writer("out_point_to_cell.vtk");
|
|
|
|
writer.WriteDataSet(ds_from_convert);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|