Commit ab8f0f6d authored by David C. Lonie's avatar David C. Lonie
Browse files

Map cell data arrays through vtkmContour.

parent bac05de3
......@@ -15,6 +15,7 @@
//=============================================================================
#include "vtkActor.h"
#include "vtkCellData.h"
#include "vtkCountVertices.h"
#include "vtkmContour.h"
#include "vtkElevationFilter.h"
#include "vtkImageData.h"
......@@ -70,12 +71,29 @@ int RunVTKPipeline(T *t, int argc, char* argv[])
retVal = vtkRegressionTester::PASSED;
}
if (!cubes->GetOutput()->GetPointData()->GetNormals())
vtkDataSet *output = cubes->GetOutput();
if (!output->GetPointData()->GetNormals())
{
std::cerr << "Output normals not set.\n";
return EXIT_FAILURE;
}
vtkDataArray *cellvar = output->GetCellData()->GetArray("Vertex Count");
if (!cellvar)
{
std::cerr << "Cell data missing.\n";
return EXIT_FAILURE;
}
if (cellvar->GetNumberOfTuples() != output->GetNumberOfCells())
{
std::cerr << "Mapped cell field does not match number of output cells.\n"
<< "Expected: " << output->GetNumberOfCells() << " Actual: "
<< cellvar->GetNumberOfTuples() << "\n";
return EXIT_FAILURE;
}
return (!retVal);
}
......@@ -96,6 +114,9 @@ int TestVTKMMarchingCubes(int argc, char* argv[])
elevation->SetLowPoint(-1.75, 0.0, 1.0);
elevation->SetHighPoint(0.75, 0.0, 1.0);
vtkNew<vtkCountVertices> countVerts;
countVerts->SetInputConnection(elevation->GetOutputPort());
//run the pipeline
return RunVTKPipeline(elevation.GetPointer(),argc,argv);
return RunVTKPipeline(countVerts.GetPointer(),argc,argv);
}
......@@ -15,6 +15,7 @@
//=============================================================================
#include "vtkmContour.h"
#include "vtkCellData.h"
#include "vtkDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
......@@ -83,9 +84,9 @@ int vtkmContour::RequestData(vtkInformation* request,
filter.SetIsoValue(i, this->GetValue(i));
}
// convert the input dataset to a vtkm::cont::DataSet
vtkm::cont::DataSet in = tovtkm::Convert(input);
vtkm::cont::DataSet in = tovtkm::Convert(input,
tovtkm::FieldsFlag::PointsAndCells);
// we need to map the given property to the data set
int association = this->GetInputArrayAssociation(0, inputVector);
......@@ -108,7 +109,6 @@ int vtkmContour::RequestData(vtkInformation* request,
vtkWarningMacro(<< "Will not be able to use VTKm field type is unknown");
}
vtkm::filter::ResultDataSet result;
bool convertedDataSet = false;
if (dataSetValid && fieldValid)
......@@ -123,30 +123,19 @@ int vtkmContour::RequestData(vtkInformation* request,
return this->Superclass::RequestData(request, inputVector, outputVector);
}
// convert other scalar arrays
if (this->GetComputeScalars())
vtkm::Id numFields = static_cast<vtkm::Id>(in.GetNumberOfFields());
for (vtkm::Id fieldIdx = 0; fieldIdx < numFields; ++fieldIdx)
{
vtkPointData* pd = input->GetPointData();
for (vtkIdType i = 0; i < pd->GetNumberOfArrays(); i++)
const vtkm::cont::Field &field = in.GetField(fieldIdx);
try
{
filter.MapFieldOntoOutput(result, field, policy);
}
catch (vtkm::cont::Error &e)
{
vtkDataArray* array = pd->GetArray(i);
if (array == NULL)
{
continue;
}
vtkm::cont::Field pfield =
tovtkm::Convert(array, vtkDataObject::FIELD_ASSOCIATION_POINTS);
try
{
filter.MapFieldOntoOutput(result, pfield, policy);
}
catch (vtkm::cont::Error&)
{ // nothing to do for now
vtkWarningMacro(<< "Unable to use VTKm to convert field( "
<< array->GetName() << " ) to the MarchingCubes"
<< "output.");
}
vtkWarningMacro(<< "Unable to use VTKm to convert point field( "
<< field.GetName() << " ) to the MarchingCubes"
<< " output: " << e.what());
}
}
......@@ -162,6 +151,11 @@ int vtkmContour::RequestData(vtkInformation* request,
}
if (this->ComputeScalars)
{
output->GetPointData()->SetActiveScalars(inputArray->GetName());
}
if (this->ComputeNormals)
{
output->GetPointData()->SetActiveAttribute(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment