Commit bcee8270 authored by Robert Maynard's avatar Robert Maynard

First draft of vtkm::filter design.

parent 531decec
......@@ -65,6 +65,10 @@ add_subdirectory(exec)
#add the worklet folder
add_subdirectory(worklet)
#-----------------------------------------------------------------------------
#add the filter folder
add_subdirectory(filter)
#-----------------------------------------------------------------------------
#add the benchmarking folder
add_subdirectory(benchmarking)
......
##============================================================================
## 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 2014 Sandia Corporation.
## Copyright 2014 UT-Battelle, LLC.
## Copyright 2014 Los Alamos National Security.
##
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
## the U.S. Government retains certain rights in this software.
##
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
## Laboratory (LANL), the U.S. Government retains certain rights in
## this software.
##============================================================================
set(headers
CellAverage.h
CellFilter.h
DataSetFilter.h
DataSetWithFieldFilter.h
DefaultPolicy.h
ExternalFaces.h
FieldFilter.h
FieldMetadata.h
FilterTraits.h
MarchingCubes.h
PointElevation.h
PolicyBase.h
Threshold.h
VertexClustering.h
)
set(header_template_sources
CellAverage.hxx
CellFilter.hxx
DataSetFilter.hxx
DataSetWithFieldFilter.hxx
ExternalFaces.hxx
FieldFilter.hxx
MarchingCubes.hxx
PointElevation.hxx
Threshold.hxx
VertexClustering.hxx
)
vtkm_declare_headers(${headers})
vtkm_install_headers(${header_template_sources})
add_subdirectory(internal)
#-----------------------------------------------------------------------------
add_subdirectory(testing)
//============================================================================
// 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 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_filter_CellAverage_h
#define vtk_m_filter_CellAverage_h
#include <vtkm/filter/CellFilter.h>
#include <vtkm/worklet/CellAverage.h>
namespace vtkm {
namespace filter {
class CellAverage : public vtkm::filter::CellFilter<CellAverage>
{
public:
VTKM_CONT_EXPORT
CellAverage();
template<typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
VTKM_CONT_EXPORT
vtkm::filter::FieldResult DoExecute(const vtkm::cont::DataSet &input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& tag);
private:
vtkm::worklet::CellAverage Worklet;
};
}
} // namespace vtkm::filter
#include <vtkm/filter/CellAverage.hxx>
#endif // vtk_m_filter_CellAverage_h
\ No newline at end of file
//============================================================================
// 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 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
namespace vtkm {
namespace filter {
//-----------------------------------------------------------------------------
CellAverage::CellAverage():
vtkm::filter::CellFilter<CellAverage>(),
Worklet()
{
}
//-----------------------------------------------------------------------------
template<typename T,
typename StorageType,
typename DerivedPolicy,
typename DeviceAdapter>
vtkm::filter::FieldResult CellAverage::DoExecute(const vtkm::cont::DataSet &input,
const vtkm::cont::ArrayHandle<T, StorageType>& field,
const vtkm::filter::FieldMetadata&,
const vtkm::filter::PolicyBase<DerivedPolicy>&,
const DeviceAdapter&)
{
vtkm::cont::DynamicCellSet cellSet =
input.GetCellSet(this->GetActiveCellSetIndex());
//todo: we need to ask the policy what storage type we should be using
//If the input is implicit, we should know what to fall back to
vtkm::cont::ArrayHandle<T> outArray = field;
vtkm::worklet::DispatcherMapTopology<vtkm::worklet::CellAverage,
DeviceAdapter > dispatcher(this->Worklet);
//todo: we need to use the policy to determine the valid conversions
//that the dispatcher should do, including the result from GetCellSet
dispatcher.Invoke(field, cellSet, outArray);
vtkm::cont::Field outField(this->GetOutputFieldName(), 1,
vtkm::cont::Field::ASSOC_CELL_SET,
cellSet.GetCellSet().GetName(),
outArray);
return vtkm::filter::FieldResult(outField);
}
}
} // namespace vtkm::filter
//============================================================================
// 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 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_filter_CellFilter_h
#define vtk_m_filter_CellFilter_h
#include <vtkm/filter/FieldFilter.h>
namespace vtkm {
namespace filter {
template<class Derived>
class CellFilter : public vtkm::filter::FieldFilter< Derived >
{
public:
VTKM_CONT_EXPORT
CellFilter();
VTKM_CONT_EXPORT
void SetActiveCellSet(vtkm::Id index)
{ this->CellSetIndex = index; }
VTKM_CONT_EXPORT
vtkm::Id GetActiveCellSetIndex() const
{ return this->CellSetIndex; }
protected:
vtkm::Id CellSetIndex;
};
}
} // namespace vtkm::filter
#include <vtkm/filter/CellFilter.hxx>
#endif // vtk_m_filter_CellFilter_h
\ No newline at end of file
//============================================================================
// 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 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
namespace vtkm {
namespace filter {
//----------------------------------------------------------------------------
template<class Derived>
CellFilter<Derived>::CellFilter():
vtkm::filter::FieldFilter< Derived >(),
CellSetIndex(0)
{
}
}
}
\ No newline at end of file
//============================================================================
// 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 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_filter_DataSetFilter_h
#define vtk_m_filter_DataSetFilter_h
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/Field.h>
#include <vtkm/filter/PolicyBase.h>
#include <vtkm/filter/internal/RuntimeDeviceTracker.h>
namespace vtkm {
namespace filter {
class DataSetResult
{
public:
VTKM_CONT_EXPORT
DataSetResult(): Valid(false), Data()
{ }
VTKM_CONT_EXPORT
DataSetResult(const vtkm::cont::DataSet& ds): Valid(true), Data(ds)
{ }
VTKM_CONT_EXPORT
bool IsValid() const { return this->Valid; }
VTKM_CONT_EXPORT
const vtkm::cont::DataSet& GetDataSet() const { return this->Data; }
VTKM_CONT_EXPORT
vtkm::cont::DataSet& GetDataSet() { return this->Data; }
private:
bool Valid;
vtkm::cont::DataSet Data;
};
template<class Derived>
class DataSetFilter
{
public:
VTKM_CONT_EXPORT
DataSetFilter();
VTKM_CONT_EXPORT
void SetActiveCellSet(vtkm::Id index)
{ this->CellSetIndex = index; }
VTKM_CONT_EXPORT
vtkm::Id GetActiveCellSetIndex() const
{ return this->CellSetIndex; }
VTKM_CONT_EXPORT
void SetActiveCoordinateSystem(vtkm::Id index)
{ this->CoordinateSystemIndex = index; }
VTKM_CONT_EXPORT
vtkm::Id GetActiveCoordinateSystemIndex() const
{ return this->CoordinateSystemIndex; }
VTKM_CONT_EXPORT
DataSetResult Execute(const vtkm::cont::DataSet &input);
template<typename DerivedPolicy>
VTKM_CONT_EXPORT
DataSetResult Execute(const vtkm::cont::DataSet &input,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy );
//From the field we can extract the association component
// ASSOC_ANY -> unable to map
// ASSOC_WHOLE_MESH -> (I think this is points)
// ASSOC_POINTS -> map using point mapping
// ASSOC_CELL_SET -> how do we map this?
// ASSOC_LOGICAL_DIM -> unable to map?
VTKM_CONT_EXPORT
bool MapFieldOntoOutput(DataSetResult& result,
const vtkm::cont::Field& field);
template<typename DerivedPolicy>
VTKM_CONT_EXPORT
bool MapFieldOntoOutput(DataSetResult& result,
const vtkm::cont::Field& field,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy);
private:
template<typename DerivedPolicy>
VTKM_CONT_EXPORT
DataSetResult PrepareForExecution(const vtkm::cont::DataSet& input,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy);
std::string OutputFieldName;
vtkm::Id CellSetIndex;
vtkm::Id CoordinateSystemIndex;
vtkm::filter::internal::RuntimeDeviceTracker Tracker;
};
}
} // namespace vtkm::filter
#include <vtkm/filter/DataSetFilter.hxx>
#endif // vtk_m_filter_DataSetFilter_h
\ No newline at end of file
//============================================================================
// 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 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/filter/DefaultPolicy.h>
#include <vtkm/filter/FieldMetadata.h>
#include <vtkm/filter/FilterTraits.h>
#include <vtkm/filter/internal/ResolveFieldTypeAndExecute.h>
#include <vtkm/filter/internal/ResolveFieldTypeAndMap.h>
#include <vtkm/cont/Error.h>
#include <vtkm/cont/ErrorControlBadAllocation.h>
#include <vtkm/cont/ErrorExecution.h>
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
namespace vtkm {
namespace filter {
//----------------------------------------------------------------------------
template<class Derived>
DataSetFilter<Derived>::DataSetFilter():
OutputFieldName(),
CellSetIndex(0),
CoordinateSystemIndex(0),
Tracker()
{
}
//-----------------------------------------------------------------------------
template<typename Derived>
DataSetResult DataSetFilter<Derived>::Execute(const vtkm::cont::DataSet &input)
{
return this->Execute(input, vtkm::filter::DefaultPolicy());
}
//-----------------------------------------------------------------------------
template<typename Derived>
template<typename DerivedPolicy>
DataSetResult DataSetFilter<Derived>::Execute(const vtkm::cont::DataSet &input,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy )
{
return this->PrepareForExecution(input, policy);
}
//-----------------------------------------------------------------------------
template<typename Derived>
template<typename DerivedPolicy>
DataSetResult DataSetFilter<Derived>::PrepareForExecution(const vtkm::cont::DataSet &input,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy )
{
typedef vtkm::cont::DeviceAdapterTagCuda CudaTag;
typedef vtkm::cont::DeviceAdapterTagTBB TBBTag;
typedef vtkm::cont::DeviceAdapterTagSerial SerialTag;
DataSetResult result = run_if_valid<DataSetResult>( static_cast<Derived*>(this),
input,
policy,
this->Tracker,
CudaTag() );
if( !result.IsValid() )
{
result = run_if_valid<DataSetResult>( static_cast<Derived*>(this),
input,
policy,
this->Tracker,
TBBTag() );
}
if( !result.IsValid() )
{
result = run_if_valid<DataSetResult>( static_cast<Derived*>(this),
input,
policy,
this->Tracker,
SerialTag() );
}
return result;
}
//-----------------------------------------------------------------------------
template<typename Derived>
bool DataSetFilter<Derived>::MapFieldOntoOutput(DataSetResult& result,
const vtkm::cont::Field& field)
{
return this->MapFieldOntoOutput(result, field, vtkm::filter::DefaultPolicy());
}
//-----------------------------------------------------------------------------
template<typename Derived>
template<typename DerivedPolicy>
bool DataSetFilter<Derived>::MapFieldOntoOutput(DataSetResult& result,
const vtkm::cont::Field& field,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy)
{
bool valid = false;
if(result.IsValid())
{
typedef internal::ResolveFieldTypeAndMap< Derived,
DerivedPolicy > FunctorType;
FunctorType functor(static_cast<Derived*>(this),
result,
vtkm::filter::FieldMetadata(field),
policy,
this->Tracker,
valid);
typedef vtkm::filter::FilterTraits< Derived > Traits;
vtkm::filter::Convert(field, policy, Traits()).CastAndCall(functor);
}
//the bool valid will be modified by the map algorithm to hold if the
//mapping occurred or not. If the mapping was good a new field has been
//added to the DataSetResult that was passed in.
return valid;
}
}
}
//============================================================================
// 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 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_filter_DataSetWithFieldFilter_h
#define vtk_m_filter_DataSetWithFieldFilter_h
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DynamicCellSet.h>
#include <vtkm/cont/CoordinateSystem.h>
#include <vtkm/cont/Field.h>
#include <vtkm/filter/PolicyBase.h>
#include <vtkm/filter/DataSetFilter.h>
#include <vtkm/filter/internal/RuntimeDeviceTracker.h>
namespace vtkm {
namespace filter {
template<class Derived>
class DataSetWithFieldFilter
{
public:
VTKM_CONT_EXPORT
DataSetWithFieldFilter();
VTKM_CONT_EXPORT
void SetActiveCellSet(vtkm::Id index)
{ this->CellSetIndex = index; }
VTKM_CONT_EXPORT
vtkm::Id GetActiveCellSetIndex() const
{ return this->CellSetIndex; }
VTKM_CONT_EXPORT
void SetActiveCoordinateSystem(vtkm::Id index)