1 //============================================================================
2 //  Copyright (c) Kitware, Inc.
3 //  All rights reserved.
4 //  See LICENSE.txt for details.
5 //  This software is distributed WITHOUT ANY WARRANTY; without even
6 //  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 //  PURPOSE.  See the above copyright notice for more information.
8 //
9 //  Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 //  Copyright 2014 UT-Battelle, LLC.
11 //  Copyright 2014 Los Alamos National Security.
12 //
13 //  Under the terms of Contract DE-NA0003525 with NTESS,
14 //  the U.S. Government retains certain rights in this software.
15 //
16 //  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 //  Laboratory (LANL), the U.S. Government retains certain rights in
18 //  this software.
19 //============================================================================
20 
21 namespace vtkm
22 {
23 namespace filter
24 {
25 
26 //-----------------------------------------------------------------------------
VertexClustering()27 inline VTKM_CONT VertexClustering::VertexClustering()
28   : vtkm::filter::FilterDataSet<VertexClustering>()
29   , NumberOfDivisions(256, 256, 256)
30 {
31 }
32 
33 //-----------------------------------------------------------------------------
34 template <typename DerivedPolicy, typename DeviceAdapter>
DoExecute(const vtkm::cont::DataSet & input,const vtkm::filter::PolicyBase<DerivedPolicy> & policy,const DeviceAdapter & tag)35 inline VTKM_CONT vtkm::cont::DataSet VertexClustering::DoExecute(
36   const vtkm::cont::DataSet& input,
37   const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
38   const DeviceAdapter& tag)
39 {
40   // todo this code needs to obey the policy for what storage types
41   // the output should use
42   //need to compute bounds first
43   vtkm::Bounds bounds = input.GetCoordinateSystem().GetBounds();
44 
45   vtkm::cont::DataSet outDataSet =
46     this->Worklet.Run(vtkm::filter::ApplyPolicyUnstructured(input.GetCellSet(), policy),
47                       input.GetCoordinateSystem(),
48                       bounds,
49                       this->GetNumberOfDivisions(),
50                       tag);
51 
52   return outDataSet;
53 }
54 
55 //-----------------------------------------------------------------------------
56 template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
DoMapField(vtkm::cont::DataSet & result,const vtkm::cont::ArrayHandle<T,StorageType> & input,const vtkm::filter::FieldMetadata & fieldMeta,const vtkm::filter::PolicyBase<DerivedPolicy> &,const DeviceAdapter & device)57 inline VTKM_CONT bool VertexClustering::DoMapField(
58   vtkm::cont::DataSet& result,
59   const vtkm::cont::ArrayHandle<T, StorageType>& input,
60   const vtkm::filter::FieldMetadata& fieldMeta,
61   const vtkm::filter::PolicyBase<DerivedPolicy>&,
62   const DeviceAdapter& device)
63 {
64   vtkm::cont::ArrayHandle<T> fieldArray;
65 
66   if (fieldMeta.IsPointField())
67   {
68     fieldArray = this->Worklet.ProcessPointField(input, device);
69   }
70   else if (fieldMeta.IsCellField())
71   {
72     fieldArray = this->Worklet.ProcessCellField(input, device);
73   }
74   else
75   {
76     return false;
77   }
78 
79   //use the same meta data as the input so we get the same field name, etc.
80   result.AddField(fieldMeta.AsField(fieldArray));
81 
82   return true;
83 }
84 }
85 }
86