DotProduct.h 5.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
//============================================================================
//  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 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
//  Copyright 2014 UT-Battelle, LLC.
//  Copyright 2014 Los Alamos National Security.
//
//  Under the terms of Contract DE-NA0003525 with NTESS,
//  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_DotProduct_h
#define vtk_m_filter_DotProduct_h

#include <vtkm/filter/FilterField.h>
#include <vtkm/worklet/DotProduct.h>

namespace vtkm
{
namespace filter
{

class DotProduct : public vtkm::filter::FilterField<DotProduct>
{
public:
  VTKM_CONT
  DotProduct();

38 39 40
  //@{
  /// Choose the primary field to operate on. In the cross product operation A x B, A is
  /// the primary field.
41
  VTKM_CONT
42 43
  void SetPrimaryField(
    const std::string& name,
44
    vtkm::cont::Field::Association association = vtkm::cont::Field::Association::ANY)
45 46 47 48
  {
    this->SetActiveField(name, association);
  }

49
  VTKM_CONT const std::string& GetPrimaryFieldName() const { return this->SecondaryFieldName; }
50
  VTKM_CONT vtkm::cont::Field::Association GetPrimaryFieldAssociation() const
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
  {
    return this->SecondaryFieldAssociation;
  }
  //@}

  //@{
  /// When set to true, uses a coordinate system as the primary field instead of the one selected
  /// by name. Use SetPrimaryCoordinateSystem to select which coordinate system.
  VTKM_CONT
  void SetUseCoordinateSystemAsPrimaryField(bool flag)
  {
    this->SetUseCoordinateSystemAsField(flag);
  }
  VTKM_CONT
  bool GetUseCoordinateSystemAsPrimaryField() const
  {
    return this->GetUseCoordinateSystemAsField();
  }
  //@}

  //@{
  /// Select the coordinate system index to use as the primary field. This only has an effect when
  /// UseCoordinateSystemAsPrimaryField is true.
  VTKM_CONT
  void SetPrimaryCoordinateSystem(vtkm::Id index) { this->SetActiveCoordinateSystem(index); }
  VTKM_CONT
  vtkm::Id GetPrimaryCoordinateSystemIndex() const
  {
    return this->GetActiveCoordinateSystemIndex();
  }
  //@}

  //@{
  /// Choose the secondary field to operate on. In the cross product operation A x B, B is
  /// the secondary field.
86 87 88
  VTKM_CONT
  void SetSecondaryField(
    const std::string& name,
89
    vtkm::cont::Field::Association association = vtkm::cont::Field::Association::ANY)
90 91 92 93
  {
    this->SecondaryFieldName = name;
    this->SecondaryFieldAssociation = association;
  }
94

95
  VTKM_CONT const std::string& GetSecondaryFieldName() const { return this->GetActiveFieldName(); }
96
  VTKM_CONT vtkm::cont::Field::Association GetSecondaryFieldAssociation() const
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
  {
    return this->GetActiveFieldAssociation();
  }
  //@}

  //@{
  /// When set to true, uses a coordinate system as the primary field instead of the one selected
  /// by name. Use SetPrimaryCoordinateSystem to select which coordinate system.
  VTKM_CONT
  void SetUseCoordinateSystemAsSecondaryField(bool flag)
  {
    this->UseCoordinateSystemAsSecondaryField = flag;
  }
  VTKM_CONT
  bool GetUseCoordinateSystemAsSecondaryField() const
  {
    return this->UseCoordinateSystemAsSecondaryField;
  }
  //@}

  //@{
  /// Select the coordinate system index to use as the primary field. This only has an effect when
  /// UseCoordinateSystemAsPrimaryField is true.
  VTKM_CONT
  void SetSecondaryCoordinateSystem(vtkm::Id index)
  {
    this->SecondaryCoordinateSystemIndex = index;
  }
  VTKM_CONT
  vtkm::Id GetSecondaryCoordinateSystemIndex() const
  {
    return this->SecondaryCoordinateSystemIndex;
  }
  //@}

132
  template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
133
  VTKM_CONT vtkm::cont::DataSet DoExecute(
134 135 136 137 138 139
    const vtkm::cont::DataSet& input,
    const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>& field,
    const vtkm::filter::FieldMetadata& fieldMeta,
    const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
    const DeviceAdapter& tag);

Dave Pugmire's avatar
Dave Pugmire committed
140
  template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
141
  VTKM_CONT bool DoMapField(vtkm::cont::DataSet& result,
Dave Pugmire's avatar
Dave Pugmire committed
142 143 144 145 146
                            const vtkm::cont::ArrayHandle<T, StorageType>& input,
                            const vtkm::filter::FieldMetadata& fieldMeta,
                            const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
                            DeviceAdapter tag);

147 148
private:
  std::string SecondaryFieldName;
149
  vtkm::cont::Field::Association SecondaryFieldAssociation;
150 151
  bool UseCoordinateSystemAsSecondaryField;
  vtkm::Id SecondaryCoordinateSystemIndex;
152 153 154 155 156 157
};

template <>
class FilterTraits<DotProduct>
{ //currently the DotProduct filter only works on vector data.
public:
158
  using InputFieldTypeList = TypeListTagVecCommon;
159 160 161 162 163 164 165
};
}
} // namespace vtkm::filter

#include <vtkm/filter/DotProduct.hxx>

#endif // vtk_m_filter_DotProduct_h