//============================================================================ // 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 #include #include #include #include namespace { class ThresholdRange { public: VTKM_CONT ThresholdRange(const vtkm::Float64& lower, const vtkm::Float64& upper) : Lower(lower) , Upper(upper) { } template VTKM_EXEC bool operator()(const T& value) const { return value >= static_cast(this->Lower) && value <= static_cast(this->Upper); } private: vtkm::Float64 Lower; vtkm::Float64 Upper; }; template struct CallWorklet { vtkm::cont::DynamicCellSet& Output; vtkm::worklet::Threshold& Worklet; const vtkm::cont::ArrayHandle& Field; const vtkm::cont::Field::AssociationEnum FieldType; const ThresholdRange& Predicate; CallWorklet(vtkm::cont::DynamicCellSet& output, vtkm::worklet::Threshold& worklet, const vtkm::cont::ArrayHandle& field, const vtkm::cont::Field::AssociationEnum fieldType, const ThresholdRange& predicate) : Output(output) , Worklet(worklet) , Field(field) , FieldType(fieldType) , Predicate(predicate) { } template void operator()(const CellSetType& cellSet) const { this->Output = this->Worklet.Run(cellSet, this->Field, this->FieldType, this->Predicate, DeviceTag()); } }; } // end anon namespace namespace vtkm { namespace filter { //----------------------------------------------------------------------------- inline VTKM_CONT Threshold::Threshold() : vtkm::filter::FilterDataSetWithField() , LowerValue(0) , UpperValue(0) { } //----------------------------------------------------------------------------- template inline VTKM_CONT vtkm::filter::ResultDataSet Threshold::DoExecute( const vtkm::cont::DataSet& input, const vtkm::cont::ArrayHandle& field, const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::PolicyBase& policy, const DeviceAdapter&) { using Worker = CallWorklet; //get the cells and coordinates of the dataset const vtkm::cont::DynamicCellSet& cells = input.GetCellSet(this->GetActiveCellSetIndex()); vtkm::cont::DynamicCellSet cellOut; ThresholdRange predicate(this->GetLowerThreshold(), this->GetUpperThreshold()); Worker worker(cellOut, this->Worklet, field, fieldMeta.GetAssociation(), predicate); vtkm::filter::ApplyPolicy(cells, policy).CastAndCall(worker); vtkm::cont::DataSet output; output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex())); output.AddCellSet(worker.Output); return output; } //----------------------------------------------------------------------------- template inline VTKM_CONT bool Threshold::DoMapField(vtkm::filter::ResultDataSet& result, const vtkm::cont::ArrayHandle& input, const vtkm::filter::FieldMetadata& fieldMeta, const vtkm::filter::PolicyBase&, const DeviceAdapter& device) { if (fieldMeta.IsPointField()) { //we copy the input handle to the result dataset, reusing the metadata result.GetDataSet().AddField(fieldMeta.AsField(input)); return true; } else if (fieldMeta.IsCellField()) { vtkm::cont::ArrayHandle out = this->Worklet.ProcessCellField(input, device); result.GetDataSet().AddField(fieldMeta.AsField(out)); return true; } else { return false; } } } }