Commit 0ed98d93 authored by Berk Geveci's avatar Berk Geveci

Added vtkmAverageToPoints.

This filter is the equivalent of vtkCellDataToPointData filter.
Except that it uses VTK-m and hence is SMP parallel.
parent 312e679b
......@@ -32,6 +32,7 @@ set(lib_srcs
#needed to properly setup language wrappers
set(headers
vtkmAverageToPoints.h
vtkmClip.h
vtkmContour.h
vtkmThreshold.h
......@@ -42,6 +43,7 @@ set(headers
#implementation of the algorithms for cpu accelerators
set(cpu_accelerator_srcs
vtkmAverageToPoints.cxx
vtkmClip.cxx
vtkmContour.cxx
vtkmThreshold.cxx
......@@ -56,6 +58,7 @@ set(cpu_accelerator_srcs
#implementation of the algorithms for gpu accelerators
set(cuda_accelerator_srcs
vtkmAverageToPoints.cu
vtkmClip.cu
vtkmContour.cu
vtkmThreshold.cu
......
vtk_add_test_python(
NO_DATA NO_VALID NO_OUTPUT
TestVTKMAverageToPoints.py
)
import sys
try:
import numpy
except ImportError:
print("Numpy (http://numpy.scipy.org) not found.")
print("This test requires numpy!")
sys.exit(0)
import vtk
from vtk.numpy_interface import dataset_adapter as dsa
from vtk.numpy_interface import algorithms as algs
rt = vtk.vtkRTAnalyticSource()
p2c = vtk.vtkPointDataToCellData()
p2c.SetInputConnection(rt.GetOutputPort())
p2c.Update()
c2p = vtk.vtkCellDataToPointData()
c2p.SetInputConnection(p2c.GetOutputPort())
c2p.Update()
d1 = dsa.WrapDataObject(c2p.GetOutput())
c2p = vtk.vtkmAverageToPoints()
c2p.SetInputData(p2c.GetOutput())
c2p.SetInputArrayToProcess(0, 0, 0, vtk.vtkDataObject.FIELD_ASSOCIATION_CELLS, "RTData")
c2p.Update()
d2 = dsa.WrapDataObject(c2p.GetOutput())
assert (algs.max(algs.abs(d1.PointData['RTData'] - d2.PointData['RTData'])) < 10E-4)
//=============================================================================
//
// 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.
//
// Copyright 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
#include "vtkmAverageToPoints.cxx"
//=============================================================================
//
// 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.
//
// Copyright 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
#include "vtkmAverageToPoints.h"
#include "vtkDataSet.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkmlib/Storage.h"
#include "vtkmlib/DataSetConverters.h"
#include "vtkmlib/ArrayConverters.h"
#include "vtkmCellSetExplicit.h"
#include "vtkmCellSetSingleType.h"
#include "vtkmFilterPolicy.h"
#include <vtkm/filter/PointAverage.h>
vtkStandardNewMacro(vtkmAverageToPoints)
//------------------------------------------------------------------------------
vtkmAverageToPoints::vtkmAverageToPoints()
{
}
//------------------------------------------------------------------------------
vtkmAverageToPoints::~vtkmAverageToPoints()
{
}
//------------------------------------------------------------------------------
int vtkmAverageToPoints::RequestData(vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation *outInfo = outputVector->GetInformationObject(0);
vtkDataSet *input = vtkDataSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkDataSet* output = vtkDataSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
output->ShallowCopy(input);
//grab the input array to process to determine the field we want to average
int association = this->GetInputArrayAssociation(0, inputVector);
if(association != vtkDataObject::FIELD_ASSOCIATION_CELLS)
{
vtkErrorMacro( << "Must be asked to average a cell based field.");
return 1;
}
//convert the input dataset to a vtkm::cont::DataSet
vtkm::cont::DataSet in = tovtkm::Convert(input);
//convert the array over to vtkm
vtkDataArray* inputArray = this->GetInputArrayToProcess(0, inputVector);
vtkm::cont::Field field = tovtkm::Convert( inputArray, association );
const bool dataSetValid =
in.GetNumberOfCoordinateSystems() >0 && in.GetNumberOfCellSets() > 0;
const bool fieldValid =
(field.GetAssociation() == vtkm::cont::Field::ASSOC_CELL_SET) &&
(field.GetName() != std::string());
if(! (dataSetValid && fieldValid) )
{
vtkErrorMacro( << "Unable convert dataset over to VTK-m for input.");
return 0;
}
vtkmInputFilterPolicy policy;
vtkm::filter::PointAverage filter;
filter.SetOutputFieldName(field.GetName()); //should we expose this control?
vtkm::filter::ResultField result = filter.Execute( in, field, policy );
if(result.IsValid())
{
//convert back the dataset to VTK, and add the field as a point field
vtkDataArray* resultingArray = fromvtkm::Convert(result.GetField());
output->GetPointData()->AddArray(resultingArray);
return 1;
}
return 0;
}
//------------------------------------------------------------------------------
void vtkmAverageToPoints::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
//=============================================================================
//
// 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.
//
// Copyright 2012 Sandia Corporation.
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
//=============================================================================
/**
* @class vtkmAverageToPoints
* @brief Accelerated cell to point interpolation filter.
*
* vtkmAverageToPoints is a filter that transforms cell data (i.e., data
* specified per cell) into point data (i.e., data specified at cell
* points). The method of transformation is based on averaging the data
* values of all cells using a particular point. This filter will also
* pass through any existing point and cell arrays.
*
*/
#ifndef vtkmAverageToPoints_h
#define vtkmAverageToPoints_h
#include "vtkDataSetAlgorithm.h"
#include "vtkAcceleratorsVTKmModule.h" //required for correct implementation
class VTKACCELERATORSVTKM_EXPORT vtkmAverageToPoints : public vtkDataSetAlgorithm
{
public:
vtkTypeMacro(vtkmAverageToPoints,vtkDataSetAlgorithm)
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
static vtkmAverageToPoints* New();
protected:
vtkmAverageToPoints();
~vtkmAverageToPoints();
virtual int RequestData(vtkInformation *,
vtkInformationVector **,
vtkInformationVector *) VTK_OVERRIDE;
private:
vtkmAverageToPoints(const vtkmAverageToPoints&) VTK_DELETE_FUNCTION;
void operator=(const vtkmAverageToPoints&) VTK_DELETE_FUNCTION;
};
#endif // vtkmAverageToPoints_h
// VTK-HeaderTest-Exclude: vtkmAverageToPoints.h
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