VTK-m  2.1
AbstractContour.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 
11 #ifndef vtk_m_filter_contour_AbstractContour_h
12 #define vtk_m_filter_contour_AbstractContour_h
13 
14 #include <vtkm/filter/Filter.h>
18 
19 namespace vtkm
20 {
21 namespace filter
22 {
23 namespace contour
24 {
30 {
31 public:
33  {
34  if (num >= 0)
35  {
36  this->IsoValues.resize(static_cast<std::size_t>(num));
37  }
38  }
39 
40  vtkm::Id GetNumberOfIsoValues() const { return static_cast<vtkm::Id>(this->IsoValues.size()); }
41 
45  void SetIsoValue(vtkm::Float64 v) { this->SetIsoValue(0, v); }
46 
52  {
53  std::size_t i = static_cast<std::size_t>(index);
54  if (i >= this->IsoValues.size())
55  {
56  this->IsoValues.resize(i + 1);
57  }
58  this->IsoValues[i] = v;
59  }
60 
78  void SetIsoValues(const std::vector<vtkm::Float64>& values) { this->IsoValues = values; }
79 
82  {
83  return this->IsoValues[static_cast<std::size_t>(index)];
84  }
85 
92  VTKM_CONT
93  void SetGenerateNormals(bool flag) { this->GenerateNormals = flag; }
95  VTKM_CONT
96  bool GetGenerateNormals() const { return this->GenerateNormals; }
97 
100  VTKM_CONT
101  void SetAddInterpolationEdgeIds(bool flag) { this->AddInterpolationEdgeIds = flag; }
104  VTKM_CONT
105  bool GetAddInterpolationEdgeIds() const { return this->AddInterpolationEdgeIds; }
106 
116  VTKM_CONT
117  void SetComputeFastNormals(bool flag) { this->ComputeFastNormals = flag; }
119  VTKM_CONT
120  bool GetComputeFastNormals() const { return this->ComputeFastNormals; }
121 
123  VTKM_CONT
124  void SetNormalArrayName(const std::string& name) { this->NormalArrayName = name; }
125 
127  VTKM_CONT
128  const std::string& GetNormalArrayName() const { return this->NormalArrayName; }
129 
141  VTKM_CONT
142  void SetMergeDuplicatePoints(bool on) { this->MergeDuplicatedPoints = on; }
143 
146  VTKM_CONT
147  bool GetMergeDuplicatePoints() { return this->MergeDuplicatedPoints; }
148 
149 protected:
154  template <typename WorkletType>
156  const vtkm::cont::Field& field,
157  WorkletType& worklet)
158  {
159  if (field.IsPointField())
160  {
161  vtkm::cont::UnknownArrayHandle inputArray = field.GetData();
162  vtkm::cont::UnknownArrayHandle outputArray = inputArray.NewInstanceBasic();
163 
164  auto functor = [&](const auto& concrete) {
165  using ComponentType = typename std::decay_t<decltype(concrete)>::ValueType::ComponentType;
166  auto fieldArray = outputArray.ExtractArrayFromComponents<ComponentType>();
167  worklet.ProcessPointField(concrete, fieldArray);
168  };
169  inputArray.CastAndCallWithExtractedArray(functor);
170  result.AddPointField(field.GetName(), outputArray);
171  return true;
172  }
173  else if (field.IsCellField())
174  {
175  // Use the precompiled field permutation function.
176  vtkm::cont::ArrayHandle<vtkm::Id> permutation = worklet.GetCellIdMap();
177  return vtkm::filter::MapFieldPermutation(field, permutation, result);
178  }
179  else if (field.IsWholeDataSetField())
180  {
181  result.AddField(field);
182  return true;
183  }
184  return false;
185  }
186 
189  {
190  if (this->GenerateNormals)
191  {
192  if (this->GetComputeFastNormals())
193  {
195  surfaceNormals.SetPointNormalsName(this->NormalArrayName);
196  surfaceNormals.SetGeneratePointNormals(true);
197  output = surfaceNormals.Execute(output);
198  }
199  else
200  {
201  output.AddField(vtkm::cont::make_FieldPoint(this->NormalArrayName, normals));
202  }
203  }
204  }
205 
206  template <typename WorkletType>
208  {
209  if (this->AddInterpolationEdgeIds)
210  {
211  vtkm::cont::Field interpolationEdgeIdsField(this->InterpolationEdgeIdsArrayName,
213  worklet.GetInterpolationEdgeIds());
214  output.AddField(interpolationEdgeIdsField);
215  }
216  }
217 
218  VTKM_CONT
219  virtual vtkm::cont::DataSet DoExecute(
220  const vtkm::cont::DataSet& result) = 0; // Needs to be overridden by contour implementations
221 
222  std::vector<vtkm::Float64> IsoValues;
223  bool GenerateNormals = true;
224  bool ComputeFastNormals = false;
225 
226  bool AddInterpolationEdgeIds = false;
227  bool MergeDuplicatedPoints = true;
228  std::string NormalArrayName = "normals";
229  std::string InterpolationEdgeIdsArrayName = "edgeIds";
230 };
231 } // namespace contour
232 } // namespace filter
233 } // namespace vtkm
234 
235 #endif // vtk_m_filter_contour_AbstractContour_h
vtkm::filter::contour::AbstractContour
Contour filter interface.
Definition: AbstractContour.h:29
vtkm::cont::ArrayHandle< vtkm::Id >
vtkm::filter::contour::AbstractContour::GetAddInterpolationEdgeIds
bool GetAddInterpolationEdgeIds() const
Get whether to append the ids of the intersected edges to the vertices of the isosurface triangles.
Definition: AbstractContour.h:105
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::Field::IsCellField
bool IsCellField() const
Definition: Field.h:114
vtkm::filter::vector_analysis::SurfaceNormals::SetPointNormalsName
void SetPointNormalsName(const std::string &name)
Specify the name of the point normals field.
Definition: SurfaceNormals.h:87
vtkm::filter::MapFieldPermutation
bool MapFieldPermutation(const vtkm::cont::Field &inputField, const vtkm::cont::ArrayHandle< vtkm::Id > &permutation, vtkm::cont::Field &outputField, vtkm::Float64 invalidValue=vtkm::Nan< vtkm::Float64 >())
Maps a field by permuting it by a given index array.
vtkm::filter::contour::AbstractContour::SetNumberOfIsoValues
void SetNumberOfIsoValues(vtkm::Id num)
Definition: AbstractContour.h:32
vtkm::filter::contour::AbstractContour::GetIsoValue
vtkm::Float64 GetIsoValue(vtkm::Id index=0) const
Return a value used to contour the mesh.
Definition: AbstractContour.h:81
vtkm::filter::contour::AbstractContour::DoMapField
static bool DoMapField(vtkm::cont::DataSet &result, const vtkm::cont::Field &field, WorkletType &worklet)
Map a given field to the output DataSet , depending on its type.
Definition: AbstractContour.h:155
vtkm::cont::UnknownArrayHandle::NewInstanceBasic
UnknownArrayHandle NewInstanceBasic() const
Create a new ArrayHandleBasic with the same ValueType as this array.
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:430
vtkm::cont::DataSet
Contains and manages the geometric data structures that VTK-m operates on.
Definition: DataSet.h:57
vtkm::filter::contour::AbstractContour::SetIsoValues
void SetIsoValues(const std::vector< vtkm::Float64 > &values)
Set multiple iso values at once.
Definition: AbstractContour.h:78
MapFieldPermutation.h
vtkm::filter::contour::AbstractContour::SetComputeFastNormals
void SetComputeFastNormals(bool flag)
Set whether the fast path should be used for normals computation.
Definition: AbstractContour.h:117
vtkm::filter::contour::AbstractContour::SetAddInterpolationEdgeIds
void SetAddInterpolationEdgeIds(bool flag)
Set whether to append the ids of the intersected edges to the vertices of the isosurface triangles.
Definition: AbstractContour.h:101
vtkm::cont::UnknownArrayHandle::CastAndCallWithExtractedArray
void CastAndCallWithExtractedArray(Functor &&functor, Args &&... args) const
Call a functor on an array extracted from the components.
Definition: UnknownArrayHandle.h:1282
vtkm::filter::contour::AbstractContour::GetComputeFastNormals
bool GetComputeFastNormals() const
Get whether the fast path should be used for normals computation.
Definition: AbstractContour.h:120
vtkm::filter::contour::AbstractContour::SetIsoValue
void SetIsoValue(vtkm::Id index, vtkm::Float64 v)
Set a field value on which to extract a contour.
Definition: AbstractContour.h:51
vtkm::cont::Field::GetData
const vtkm::cont::UnknownArrayHandle & GetData() const
vtkm::filter::contour::AbstractContour::SetNormalArrayName
void SetNormalArrayName(const std::string &name)
Set the name of the field for the generated normals.
Definition: AbstractContour.h:124
vtkm::filter::vector_analysis::SurfaceNormals::SetGeneratePointNormals
void SetGeneratePointNormals(bool value)
Specify whether the point normals should be generated.
Definition: SurfaceNormals.h:73
vtkm::filter::contour::AbstractContour::IsoValues
std::vector< vtkm::Float64 > IsoValues
Definition: AbstractContour.h:222
vtkm::filter::contour::AbstractContour::SetGenerateNormals
void SetGenerateNormals(bool flag)
Set whether normals should be generated.
Definition: AbstractContour.h:93
vtkm::filter::contour::AbstractContour::GetMergeDuplicatePoints
bool GetMergeDuplicatePoints()
Get whether the points generated should be unique for every triangle or will duplicate points be merg...
Definition: AbstractContour.h:147
vtkm::filter::vector_analysis::SurfaceNormals
Computes normals for polygonal mesh.
Definition: SurfaceNormals.h:44
vtkm::cont::DataSet::AddField
void AddField(const Field &field)
Adds a field to the DataSet.
vtkm::cont::Field
A Field encapsulates an array on some piece of the mesh, such as the points, a cell set,...
Definition: Field.h:31
VTKM_FILTER_CONTOUR_EXPORT
#define VTKM_FILTER_CONTOUR_EXPORT
Definition: vtkm_filter_contour_export.h:44
vtkm::filter::Filter
Base class for all filters.
Definition: Filter.h:163
vtkm::filter::contour::AbstractContour::GetNormalArrayName
const std::string & GetNormalArrayName() const
Get the name of the field for the generated normals.
Definition: AbstractContour.h:128
vtkm::cont::Field::Association::Points
@ Points
A field that applies to points.
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::cont::Field::GetName
const std::string & GetName() const
Definition: Field.h:132
vtkm::cont::Field::IsWholeDataSetField
bool IsWholeDataSetField() const
Definition: Field.h:116
SurfaceNormals.h
vtkm::cont::Field::IsPointField
bool IsPointField() const
Definition: Field.h:115
vtkm::filter::Filter::Execute
vtkm::cont::DataSet Execute(const vtkm::cont::DataSet &input)
Executes the filter on the input and produces a result dataset.
vtkm::filter::contour::AbstractContour::GetGenerateNormals
bool GetGenerateNormals() const
Get whether normals should be generated.
Definition: AbstractContour.h:96
vtkm::Float64
double Float64
Base type to use for 64-bit floating-point numbers.
Definition: Types.h:161
vtkm::cont::DataSet::AddPointField
void AddPointField(const std::string &fieldName, const vtkm::cont::UnknownArrayHandle &field)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:222
vtkm::cont::UnknownArrayHandle::ExtractArrayFromComponents
vtkm::cont::ArrayHandleRecombineVec< BaseComponentType > ExtractArrayFromComponents(vtkm::CopyFlag allowCopy=vtkm::CopyFlag::On) const
Extract the array knowing only the component type of the array.
Definition: UnknownArrayHandle.h:849
vtkm::filter::contour::AbstractContour::GetNumberOfIsoValues
vtkm::Id GetNumberOfIsoValues() const
Definition: AbstractContour.h:40
vtkm::filter::contour::AbstractContour::SetIsoValue
void SetIsoValue(vtkm::Float64 v)
Set a field value on which to extract a contour.
Definition: AbstractContour.h:45
vtkm_filter_contour_export.h
vtkm::filter::contour::AbstractContour::ExecuteAddInterpolationEdgeIds
void ExecuteAddInterpolationEdgeIds(vtkm::cont::DataSet &output, WorkletType &worklet)
Definition: AbstractContour.h:207
vtkm::cont::make_FieldPoint
vtkm::cont::Field make_FieldPoint(std::string name, const vtkm::cont::ArrayHandle< T, S > &data)
Convenience function to build point fields from vtkm::cont::ArrayHandle.
Definition: Field.h:283
vtkm::filter::contour::AbstractContour::SetMergeDuplicatePoints
void SetMergeDuplicatePoints(bool on)
Set whether the points generated should be unique for every triangle or will duplicate points be merg...
Definition: AbstractContour.h:142
vtkm::filter::contour::AbstractContour::ExecuteGenerateNormals
void ExecuteGenerateNormals(vtkm::cont::DataSet &output, const vtkm::cont::ArrayHandle< vtkm::Vec3f > &normals)
Definition: AbstractContour.h:187
Filter.h