Commit 2f352f90 authored by Robert Maynard's avatar Robert Maynard Committed by Kitware Robot

Merge topic 'vtkm_filters'

e4237c3a Fix warnings found by the dashboard machines.
179b48e0 Reduce compile time for MarchingCubes by passing less info by Invoke.
8e4a47ef Update IsosurfaceUniformGrid to use the marching cubes filter.
d370155e MarchingCubes filter now generates coordinates when point merging is enabled.
c00fb53b Marching Cubes now generates vertices when merge duplicates is enabled.
f699c986 Renamed the ```Convert``` method to ```ApplyPolicy```
8e72ec8e Switch filter::threshold over to have a lower and upper bounds.
bcee8270 First draft of vtkm::filter design.
...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !311
parents e9040745 e4237c3a
......@@ -24,7 +24,7 @@
#define VTKM_DEVICE_ADAPTER VTKM_DEVICE_ADAPTER_SERIAL
#endif
#include <vtkm/worklet/MarchingCubes.h>
#include <vtkm/filter/MarchingCubes.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/Math.h>
......@@ -48,10 +48,7 @@
#include <vector>
typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
vtkm::Id3 dims(16,16,16);
vtkm::worklet::MarchingCubes<vtkm::Float32, DeviceAdapter> *isosurfaceFilter;
vtkm::Id3 dims(256, 256, 256);
vtkm::cont::ArrayHandle<vtkm::Vec<vtkm::Float32,3> > verticesArray, normalsArray;
vtkm::cont::ArrayHandle<vtkm::Float32> scalarsArray;
Quaternion qrot;
......@@ -233,27 +230,29 @@ void mouseCall(int button, int state, int x, int y)
// Compute and render an isosurface for a uniform grid example
int main(int argc, char* argv[])
{
typedef vtkm::cont::DeviceAdapterTraits<DeviceAdapter> DeviceAdapterTraits;
typedef vtkm::cont::CellSetStructured<3> CellSet;
std::cout << "Running IsosurfaceUniformGrid example on device adapter: "
<< DeviceAdapterTraits::GetName() << std::endl;
vtkm::cont::DataSet dataSet = MakeIsosurfaceTestDataSet(dims);
vtkm::cont::ArrayHandle<vtkm::Float32> fieldArray;
dataSet.GetField("nodevar").GetData().CopyTo(fieldArray);
isosurfaceFilter = new vtkm::worklet::MarchingCubes<vtkm::Float32, DeviceAdapter>();
vtkm::filter::MarchingCubes filter;
filter.SetGenerateNormals(true);
filter.SetMergeDuplicatePoints( false );
filter.SetIsoValue( 0.5 );
vtkm::filter::DataSetResult result = filter.Execute( dataSet,
dataSet.GetField("nodevar") );
filter.MapFieldOntoOutput(result, dataSet.GetField("nodevar"));
//need to extract vertices, normals, and scalars
vtkm::cont::DataSet& outputData = result.GetDataSet();
isosurfaceFilter->Run(0.5,
dataSet.GetCellSet().Cast<CellSet>(),
dataSet.GetCoordinateSystem(),
fieldArray,
verticesArray,
normalsArray);
typedef vtkm::cont::ArrayHandle< vtkm::Vec<vtkm::Float32,3> > VertType;
vtkm::cont::CoordinateSystem coords = outputData.GetCoordinateSystem();
isosurfaceFilter->MapFieldOntoIsosurface(fieldArray,
scalarsArray);
verticesArray = coords.GetData().Cast<VertType>();
normalsArray = outputData.GetField("normals").GetData().Cast<VertType>();
scalarsArray = outputData.GetField("nodevar").GetData().Cast< vtkm::cont::ArrayHandle<vtkm::Float32> >();
std::cout << "Number of output vertices: " << verticesArray.GetNumberOfValues() << std::endl;
......
......@@ -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)
......
......@@ -140,14 +140,14 @@ public:
this->Superclass::GetData());
}
template<typename DeviceAdapterTag, typename TypeList>
template<typename DeviceAdapterTag>
VTKM_CONT_EXPORT
const vtkm::cont::ArrayHandle<vtkm::Float64>& GetBounds(DeviceAdapterTag,
TypeList) const
void GetBounds(vtkm::Float64 *bounds, DeviceAdapterTag) const
{
return this->Superclass::GetBounds(
this->Superclass::GetBounds(
bounds,
DeviceAdapterTag(),
TypeList(),
VTKM_DEFAULT_COORDINATE_SYSTEM_TYPE_LIST_TAG(),
VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
}
......@@ -156,11 +156,23 @@ public:
void GetBounds(vtkm::Float64 *bounds, DeviceAdapterTag, TypeList) const
{
this->Superclass::GetBounds(
bounds, DeviceAdapterTag(),
bounds,
DeviceAdapterTag(),
TypeList(),
VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
}
template<typename DeviceAdapterTag, typename TypeList, typename StorageList>
VTKM_CONT_EXPORT
void GetBounds(vtkm::Float64 *bounds, DeviceAdapterTag, TypeList, StorageList) const
{
this->Superclass::GetBounds(
bounds,
DeviceAdapterTag(),
TypeList(),
StorageList());
}
template<typename DeviceAdapterTag>
VTKM_CONT_EXPORT
const vtkm::cont::ArrayHandle<vtkm::Float64>& GetBounds(DeviceAdapterTag) const
......@@ -171,17 +183,31 @@ public:
VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
}
template<typename DeviceAdapterTag>
template<typename DeviceAdapterTag, typename TypeList>
VTKM_CONT_EXPORT
void GetBounds(vtkm::Float64 *bounds, DeviceAdapterTag) const
const vtkm::cont::ArrayHandle<vtkm::Float64>& GetBounds(DeviceAdapterTag,
TypeList) const
{
this->Superclass::GetBounds(
bounds,
return this->Superclass::GetBounds(
DeviceAdapterTag(),
VTKM_DEFAULT_COORDINATE_SYSTEM_TYPE_LIST_TAG(),
TypeList(),
VTKM_DEFAULT_COORDINATE_SYSTEM_STORAGE_LIST_TAG());
}
template<typename DeviceAdapterTag, typename TypeList, typename StorageList>
VTKM_CONT_EXPORT
const vtkm::cont::ArrayHandle<vtkm::Float64>& GetBounds(DeviceAdapterTag,
TypeList,
StorageList) const
{
return this->Superclass::GetBounds(
DeviceAdapterTag(),
TypeList(),
StorageList());
}
VTKM_CONT_EXPORT
virtual void PrintSummary(std::ostream &out) const
{
......
......@@ -481,7 +481,7 @@ public:
Field()
: Name(),
Order(),
Association(),
Association(ASSOC_ANY),
AssocCellSetName(),
AssocLogicalDim(),
Data(),
......
......@@ -50,7 +50,7 @@ public:
// 3D explicit datasets.
vtkm::cont::DataSet Make3DExplicitDataSet0();
vtkm::cont::DataSet Make3DExplicitDataSet1();
vtkm::cont::DataSet Make3DExplicitDataSetCowNose(double *pBounds = NULL);
vtkm::cont::DataSet Make3DExplicitDataSetCowNose();
};
......@@ -287,7 +287,7 @@ MakeTestDataSet::Make3DExplicitDataSet1()
}
inline vtkm::cont::DataSet
MakeTestDataSet::Make3DExplicitDataSetCowNose(double *pBounds)
MakeTestDataSet::Make3DExplicitDataSetCowNose()
{
// prepare data array
const int nVerts = 17;
......@@ -333,7 +333,6 @@ MakeTestDataSet::Make3DExplicitDataSetCowNose(double *pBounds)
0, 15, 10,
7, 6, 0
};
double _bounds[6] = {-0.000169, 0.048088, 0.001378, 0.250062, 0.053925, 0.200755};
// create DataSet
vtkm::cont::DataSet dataSet;
......@@ -352,15 +351,6 @@ MakeTestDataSet::Make3DExplicitDataSetCowNose(double *pBounds)
cellSet.Fill(connectivity);
dataSet.AddCellSet(cellSet);
// copy bounds
if (pBounds != NULL)
{
for (vtkm::IdComponent i=0; i<6; i++)
{
pBounds[i] = _bounds[i];
}
}
return dataSet;
}
......
##============================================================================
## 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);