2016-01-19 14:59:31 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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/cont/ArrayHandlePermutation.h>
|
|
|
|
#include <vtkm/cont/CellSetPermutation.h>
|
|
|
|
|
|
|
|
#include <vtkm/worklet/DispatcherMapTopology.h>
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2016-02-15 16:49:48 +00:00
|
|
|
class ThresholdRange
|
2016-01-19 14:59:31 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
VTKM_CONT_EXPORT
|
2016-02-15 16:49:48 +00:00
|
|
|
ThresholdRange(const vtkm::Float64& lower,
|
|
|
|
const vtkm::Float64& upper) :
|
|
|
|
Lower(lower),
|
|
|
|
Upper(upper)
|
2016-01-19 14:59:31 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
VTKM_EXEC_EXPORT
|
|
|
|
bool operator()(const T& value) const
|
|
|
|
{
|
2016-02-15 16:49:48 +00:00
|
|
|
return value >= static_cast<T>(this->Lower) &&
|
|
|
|
value <= static_cast<T>(this->Upper);
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-02-15 16:49:48 +00:00
|
|
|
vtkm::Float64 Lower;
|
|
|
|
vtkm::Float64 Upper;
|
2016-01-19 14:59:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AddPermutationCellSet
|
|
|
|
{
|
|
|
|
vtkm::cont::DataSet* Output;
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id>* ValidIds;
|
|
|
|
public:
|
|
|
|
AddPermutationCellSet(vtkm::cont::DataSet& data,
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id>& validIds):
|
|
|
|
Output(&data),
|
|
|
|
ValidIds(&validIds)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
template<typename CellSetType>
|
|
|
|
void operator()(const CellSetType& cellset ) const
|
|
|
|
{
|
2016-04-08 17:49:51 +00:00
|
|
|
typedef vtkm::cont::CellSetPermutation<CellSetType> PermutationCellSetType;
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
PermutationCellSetType permCellSet(*this->ValidIds, cellset,
|
2016-05-13 18:26:59 +00:00
|
|
|
cellset.GetName());
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
this->Output->AddCellSet(permCellSet);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace vtkm {
|
|
|
|
namespace filter {
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
Threshold::Threshold():
|
2016-05-05 18:42:46 +00:00
|
|
|
vtkm::filter::FilterDataSetWithField<Threshold>(),
|
2016-02-15 16:49:48 +00:00
|
|
|
LowerValue(0),
|
|
|
|
UpperValue(0),
|
2016-01-19 14:59:31 +00:00
|
|
|
ValidCellIds()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template<typename T,
|
|
|
|
typename StorageType,
|
|
|
|
typename DerivedPolicy,
|
|
|
|
typename DeviceAdapter>
|
2016-05-05 21:07:55 +00:00
|
|
|
vtkm::filter::ResultDataSet Threshold::DoExecute(const vtkm::cont::DataSet& input,
|
2016-01-19 14:59:31 +00:00
|
|
|
const vtkm::cont::ArrayHandle<T, StorageType>& field,
|
|
|
|
const vtkm::filter::FieldMetadata& fieldMeta,
|
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
|
|
|
|
const DeviceAdapter&)
|
|
|
|
{
|
|
|
|
//get the cells and coordinates of the dataset
|
|
|
|
const vtkm::cont::DynamicCellSet& cells =
|
|
|
|
input.GetCellSet(this->GetActiveCellSetIndex());
|
|
|
|
|
2016-02-15 16:49:48 +00:00
|
|
|
ThresholdRange predicate( this->GetLowerThreshold(), this->GetUpperThreshold() );
|
2016-01-19 14:59:31 +00:00
|
|
|
vtkm::cont::ArrayHandle<bool> passFlags;
|
|
|
|
if(fieldMeta.IsPointField())
|
|
|
|
{
|
|
|
|
typedef vtkm::worklet::Threshold Worklets;
|
2016-02-15 16:49:48 +00:00
|
|
|
typedef Worklets::ThresholdByPointField< ThresholdRange > ThresholdWorklet;
|
2016-01-19 14:59:31 +00:00
|
|
|
ThresholdWorklet worklet(predicate);
|
|
|
|
vtkm::worklet::DispatcherMapTopology<ThresholdWorklet, DeviceAdapter> dispatcher(worklet);
|
2016-02-15 16:38:51 +00:00
|
|
|
dispatcher.Invoke(vtkm::filter::ApplyPolicy(cells, policy), field, passFlags);
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
else if(fieldMeta.IsCellField())
|
|
|
|
{
|
|
|
|
typedef vtkm::worklet::Threshold Worklets;
|
2016-02-15 16:49:48 +00:00
|
|
|
typedef Worklets::ThresholdByCellField< ThresholdRange > ThresholdWorklet;
|
2016-01-19 14:59:31 +00:00
|
|
|
ThresholdWorklet worklet(predicate);
|
|
|
|
vtkm::worklet::DispatcherMapTopology<ThresholdWorklet, DeviceAdapter> dispatcher(worklet);
|
2016-02-15 16:38:51 +00:00
|
|
|
dispatcher.Invoke(vtkm::filter::ApplyPolicy(cells, policy), field, passFlags);
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//todo: we need to mark this as a failure of input, not a failure
|
|
|
|
//of the algorithm
|
2016-05-05 21:07:55 +00:00
|
|
|
return vtkm::filter::ResultDataSet();
|
2016-01-19 14:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> Algorithm;
|
|
|
|
|
|
|
|
Algorithm::StreamCompact(passFlags, this->ValidCellIds);
|
|
|
|
|
|
|
|
vtkm::cont::DataSet output;
|
|
|
|
output.AddCoordinateSystem(
|
|
|
|
input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()) );
|
|
|
|
|
|
|
|
//now generate the output cellset. We are going to need to do a cast
|
|
|
|
//and call to generate the correct form of output.
|
|
|
|
//todo: see if we can make this into a helper class that other filters
|
|
|
|
//can use to reduce code duplication, and make it easier to write filters
|
|
|
|
//that return complex dataset types.
|
|
|
|
AddPermutationCellSet addCellSet(output, this->ValidCellIds);
|
2016-08-05 19:24:17 +00:00
|
|
|
vtkm::cont::CastAndCall(vtkm::filter::ApplyPolicy(cells, policy),
|
|
|
|
addCellSet);
|
2016-01-19 14:59:31 +00:00
|
|
|
|
|
|
|
//todo: We need to generate a new output policy that replaces
|
|
|
|
//the original storage tag with a new storage tag where everything is
|
|
|
|
//wrapped in CellSetPermutation.
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
template<typename T,
|
|
|
|
typename StorageType,
|
|
|
|
typename DerivedPolicy,
|
|
|
|
typename DeviceAdapter>
|
2016-05-05 21:07:55 +00:00
|
|
|
bool Threshold::DoMapField(vtkm::filter::ResultDataSet& result,
|
2016-01-19 14:59:31 +00:00
|
|
|
const vtkm::cont::ArrayHandle<T, StorageType>& input,
|
|
|
|
const vtkm::filter::FieldMetadata& fieldMeta,
|
|
|
|
const vtkm::filter::PolicyBase<DerivedPolicy>&,
|
|
|
|
const DeviceAdapter&)
|
|
|
|
{
|
|
|
|
if(fieldMeta.IsPointField())
|
|
|
|
{
|
|
|
|
//we copy the input handle to the result dataset, reusing the metadata
|
|
|
|
result.GetDataSet().AddField( fieldMeta.AsField(input) );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(fieldMeta.IsCellField())
|
|
|
|
{
|
|
|
|
//todo: We need to generate a new output policy that replaces
|
|
|
|
//the original storage tag with a new storage tag where everything is
|
|
|
|
//wrapped in ArrayHandlePermutation.
|
|
|
|
typedef vtkm::cont::ArrayHandlePermutation<
|
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id>,
|
|
|
|
vtkm::cont::ArrayHandle<T, StorageType> > PermutationType;
|
|
|
|
|
|
|
|
PermutationType permutation =
|
|
|
|
vtkm::cont::make_ArrayHandlePermutation(this->ValidCellIds, input);
|
|
|
|
|
|
|
|
result.GetDataSet().AddField( fieldMeta.AsField(permutation) );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|