SurfaceNormals.h 3.9 KB
Newer Older
1 2 3 4 5 6 7 8
//============================================================================
//  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.
//
Kenneth Moreland's avatar
Kenneth Moreland committed
9
//  Copyright 2017 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 11 12
//  Copyright 2017 UT-Battelle, LLC.
//  Copyright 2017 Los Alamos National Security.
//
Kenneth Moreland's avatar
Kenneth Moreland committed
13
//  Under the terms of Contract DE-NA0003525 with NTESS,
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
//  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_SurfaceNormals_h
#define vtk_m_filter_SurfaceNormals_h

#include <vtkm/filter/FilterCell.h>

namespace vtkm
{
namespace filter
{

30 31
/// \brief compute normals for polygonal mesh
///
32 33 34 35
/// Compute surface normals on points and/or cells of a polygonal dataset.
/// The cell normals are faceted and are computed based on the plane where a
/// face lies. The point normals are smooth normals, computed by averaging
/// the face normals of incident cells.
36 37 38
class SurfaceNormals : public vtkm::filter::FilterCell<SurfaceNormals>
{
public:
Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
39 40 41
  /// Create SurfaceNormals filter. This calls
  /// this->SetUseCoordinateSystemAsField(true) since that is the most common
  /// use-case for surface normals.
42 43 44 45 46 47
  SurfaceNormals();

  /// Set/Get if cell normals should be generated. Default is off.
  void SetGenerateCellNormals(bool value) { this->GenerateCellNormals = value; }
  bool GetGenerateCellNormals() const { return this->GenerateCellNormals; }

48 49 50 51 52 53 54 55
  /// Set/Get if the cell normals should be normalized. Default value is true.
  /// The intended use case of this flag is for faster, approximate point
  /// normals generation by skipping the normalization of the face normals.
  /// Note that when set to false, the result cell normals will not be unit
  /// length normals and the point normals will be different.
  void SetNormalizeCellNormals(bool value) { this->NormalizeCellNormals = value; }
  bool GetNormalizeCellNormals() const { return this->NormalizeCellNormals; }

56 57 58 59
  /// Set/Get if the point normals should be generated. Default is on.
  void SetGeneratePointNormals(bool value) { this->GeneratePointNormals = value; }
  bool GetGeneratePointNormals() const { return this->GeneratePointNormals; }

luz.paz's avatar
luz.paz committed
60
  /// Set/Get the name of the cell normals field. Default is "Normals".
61 62 63
  void SetCellNormalsName(const std::string& name) { this->CellNormalsName = name; }
  const std::string& GetCellNormalsName() const { return this->CellNormalsName; }

luz.paz's avatar
luz.paz committed
64
  /// Set/Get the name of the point normals field. Default is "Normals".
65 66 67
  void SetPointNormalsName(const std::string& name) { this->PointNormalsName = name; }
  const std::string& GetPointNormalsName() const { return this->PointNormalsName; }

68
  template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
69 70 71 72 73
  vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
                                const vtkm::cont::ArrayHandle<vtkm::Vec<T, 3>, StorageType>& points,
                                const vtkm::filter::FieldMetadata& fieldMeta,
                                const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
                                const DeviceAdapter& device);
74 75 76

private:
  bool GenerateCellNormals;
77
  bool NormalizeCellNormals;
78 79 80 81
  bool GeneratePointNormals;

  std::string CellNormalsName;
  std::string PointNormalsName;
82 83 84 85 86 87
};

template <>
class FilterTraits<SurfaceNormals>
{
public:
88
  using InputFieldTypeList = vtkm::TypeListTagFieldVec3;
89 90 91 92 93 94 95
};
}
} // vtkm::filter

#include <vtkm/filter/SurfaceNormals.hxx>

#endif // vtk_m_filter_SurfaceNormals_h