vtk-m/vtkm/filter/contour/ContourMarchingCells.cxx
Louis Gombert dcdda3065a Split flying edges and marching cells into separate filters
In order to compile the contour filter more efficiently, we split the contour filter into two separate translation units, corresponding to the new filters ContourFlyingEdges and ContourMarchingCells. The API for Contour filter is left totally unchanged, and tries to use flying edges if the dataset is structured and uniform.
All three contour filters inherit from the `AbstractContour` class, providing utility methods used in the implementations.
2023-05-04 15:20:20 +02:00

86 lines
2.8 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/cont/CellSetSingleType.h>
#include <vtkm/cont/ErrorFilterExecution.h>
#include <vtkm/cont/UnknownCellSet.h>
#include <vtkm/filter/contour/ContourMarchingCells.h>
#include <vtkm/filter/contour/worklet/ContourMarchingCells.h>
namespace vtkm
{
namespace filter
{
namespace contour
{
//-----------------------------------------------------------------------------
vtkm::cont::DataSet ContourMarchingCells::DoExecute(const vtkm::cont::DataSet& inDataSet)
{
vtkm::worklet::ContourMarchingCells worklet;
worklet.SetMergeDuplicatePoints(this->GetMergeDuplicatePoints());
if (!this->GetFieldFromDataSet(inDataSet).IsPointField())
{
throw vtkm::cont::ErrorFilterExecution("Point field expected.");
}
if (this->IsoValues.empty())
{
throw vtkm::cont::ErrorFilterExecution("No iso-values provided.");
}
//get the inputCells and coordinates of the dataset
const vtkm::cont::UnknownCellSet& inputCells = inDataSet.GetCellSet();
const vtkm::cont::CoordinateSystem& inputCoords =
inDataSet.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex());
using Vec3HandleType = vtkm::cont::ArrayHandle<vtkm::Vec3f>;
Vec3HandleType vertices;
Vec3HandleType normals;
vtkm::cont::CellSetSingleType<> outputCells;
auto resolveFieldType = [&](const auto& concrete) {
// use std::decay to remove const ref from the decltype of concrete.
using T = typename std::decay_t<decltype(concrete)>::ValueType;
std::vector<T> ivalues(this->IsoValues.size());
for (std::size_t i = 0; i < ivalues.size(); ++i)
{
ivalues[i] = static_cast<T>(this->IsoValues[i]);
}
if (this->GenerateNormals && !this->GetComputeFastNormals())
{
outputCells =
worklet.Run(ivalues, inputCells, inputCoords.GetData(), concrete, vertices, normals);
}
else
{
outputCells = worklet.Run(ivalues, inputCells, inputCoords.GetData(), concrete, vertices);
}
};
this->CastAndCallScalarField(this->GetFieldFromDataSet(inDataSet), resolveFieldType);
auto mapper = [&](auto& result, const auto& f) { this->DoMapField(result, f, worklet); };
vtkm::cont::DataSet output = this->CreateResultCoordinateSystem(
inDataSet, outputCells, inputCoords.GetName(), vertices, mapper);
this->ExecuteGenerateNormals(output, normals);
this->ExecuteAddInterpolationEdgeIds(output, worklet);
return output;
}
} // namespace contour
} // namespace filter
} // namespace vtkm