VTK-m  2.3
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>
19 
20 namespace vtkm
21 {
22 namespace filter
23 {
24 namespace contour
25 {
31 {
32 public:
34  {
35  if (num >= 0)
36  {
37  this->IsoValues.resize(static_cast<std::size_t>(num));
38  }
39  }
40 
41  vtkm::Id GetNumberOfIsoValues() const { return static_cast<vtkm::Id>(this->IsoValues.size()); }
42 
46  void SetIsoValue(vtkm::Float64 v) { this->SetIsoValue(0, v); }
47 
53  {
54  std::size_t i = static_cast<std::size_t>(index);
55  if (i >= this->IsoValues.size())
56  {
57  this->IsoValues.resize(i + 1);
58  }
59  this->IsoValues[i] = v;
60  }
61 
79  void SetIsoValues(const std::vector<vtkm::Float64>& values) { this->IsoValues = values; }
80 
83  {
84  return this->IsoValues[static_cast<std::size_t>(index)];
85  }
86 
93  VTKM_CONT
94  void SetGenerateNormals(bool flag) { this->GenerateNormals = flag; }
96  VTKM_CONT
97  bool GetGenerateNormals() const { return this->GenerateNormals; }
98 
101  VTKM_CONT
102  void SetAddInterpolationEdgeIds(bool flag) { this->AddInterpolationEdgeIds = flag; }
105  VTKM_CONT
106  bool GetAddInterpolationEdgeIds() const { return this->AddInterpolationEdgeIds; }
107 
117  VTKM_CONT
118  void SetComputeFastNormals(bool flag) { this->ComputeFastNormals = flag; }
120  VTKM_CONT
121  bool GetComputeFastNormals() const { return this->ComputeFastNormals; }
122 
124  VTKM_CONT
125  void SetNormalArrayName(const std::string& name) { this->NormalArrayName = name; }
126 
128  VTKM_CONT
129  const std::string& GetNormalArrayName() const { return this->NormalArrayName; }
130 
138  {
139  this->InputCellDimension = dimension;
140  }
141 
144  {
145  return this->InputCellDimension;
146  }
147 
154  {
155  this->SetInputCellDimension(vtkm::filter::contour::ContourDimension::Auto);
156  }
157 
162  {
163  this->SetInputCellDimension(vtkm::filter::contour::ContourDimension::All);
164  }
165 
170  {
171  this->SetInputCellDimension(vtkm::filter::contour::ContourDimension::Polyhedra);
172  }
173 
178  {
179  this->SetInputCellDimension(vtkm::filter::contour::ContourDimension::Polygons);
180  }
181 
186  {
187  this->SetInputCellDimension(vtkm::filter::contour::ContourDimension::Lines);
188  }
189 
201  VTKM_CONT
202  void SetMergeDuplicatePoints(bool on) { this->MergeDuplicatedPoints = on; }
203 
206  VTKM_CONT
207  bool GetMergeDuplicatePoints() const { return this->MergeDuplicatedPoints; }
208 
209 protected:
214  template <typename WorkletType>
216  const vtkm::cont::Field& field,
217  WorkletType& worklet)
218  {
219  if (field.IsPointField())
220  {
221  vtkm::cont::UnknownArrayHandle inputArray = field.GetData();
222  vtkm::cont::UnknownArrayHandle outputArray = inputArray.NewInstanceBasic();
223 
224  auto functor = [&](const auto& concrete) {
225  using ComponentType = typename std::decay_t<decltype(concrete)>::ValueType::ComponentType;
226  auto fieldArray = outputArray.ExtractArrayFromComponents<ComponentType>();
227  worklet.ProcessPointField(concrete, fieldArray);
228  };
229  inputArray.CastAndCallWithExtractedArray(functor);
230  result.AddPointField(field.GetName(), outputArray);
231  return true;
232  }
233  else if (field.IsCellField())
234  {
235  // Use the precompiled field permutation function.
236  vtkm::cont::ArrayHandle<vtkm::Id> permutation = worklet.GetCellIdMap();
237  return vtkm::filter::MapFieldPermutation(field, permutation, result);
238  }
239  else if (field.IsWholeDataSetField())
240  {
241  result.AddField(field);
242  return true;
243  }
244  return false;
245  }
246 
249  {
250  if (this->GenerateNormals)
251  {
252  if (this->GetComputeFastNormals())
253  {
255  surfaceNormals.SetPointNormalsName(this->NormalArrayName);
256  surfaceNormals.SetGeneratePointNormals(true);
257  output = surfaceNormals.Execute(output);
258  }
259  else
260  {
261  output.AddField(vtkm::cont::make_FieldPoint(this->NormalArrayName, normals));
262  }
263  }
264  }
265 
266  template <typename WorkletType>
268  {
269  if (this->AddInterpolationEdgeIds)
270  {
271  vtkm::cont::Field interpolationEdgeIdsField(this->InterpolationEdgeIdsArrayName,
273  worklet.GetInterpolationEdgeIds());
274  output.AddField(interpolationEdgeIdsField);
275  }
276  }
277 
278  VTKM_CONT
279  virtual vtkm::cont::DataSet DoExecute(
280  const vtkm::cont::DataSet& result) = 0; // Needs to be overridden by contour implementations
281 
282  std::vector<vtkm::Float64> IsoValues;
283  bool GenerateNormals = true;
284  bool ComputeFastNormals = false;
285 
288 
289  bool AddInterpolationEdgeIds = false;
290  bool MergeDuplicatedPoints = true;
291  std::string NormalArrayName = "normals";
292  std::string InterpolationEdgeIdsArrayName = "edgeIds";
293 };
294 } // namespace contour
295 } // namespace filter
296 } // namespace vtkm
297 
298 #endif // vtk_m_filter_contour_AbstractContour_h
vtkm::filter::contour::AbstractContour
Contour filter interface.
Definition: AbstractContour.h:30
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:106
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::Field::IsCellField
bool IsCellField() const
Return true if this field is associated with cells.
Definition: Field.h:117
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::contour::AbstractContour::GetMergeDuplicatePoints
bool GetMergeDuplicatePoints() const
Get whether the points generated should be unique for every triangle or will duplicate points be merg...
Definition: AbstractContour.h:207
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:33
vtkm::filter::contour::AbstractContour::GetIsoValue
vtkm::Float64 GetIsoValue(vtkm::Id index=0) const
Return a value used to contour the mesh.
Definition: AbstractContour.h:82
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:215
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::filter::contour::AbstractContour::SetInputCellDimensionToPolyhedra
void SetInputCellDimensionToPolyhedra()
Specifies running contours on polyhedra.
Definition: AbstractContour.h:169
vtkm::filter::contour::AbstractContour::GetInputCellDimension
vtkm::filter::contour::ContourDimension GetInputCellDimension() const
Specify the dimension of cells on which to operate the contour.
Definition: AbstractContour.h:143
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:79
MapFieldPermutation.h
vtkm::filter::contour::ContourDimension::Polyhedra
@ Polyhedra
Specifies running contours on polyhedra.
vtkm::filter::contour::AbstractContour::SetComputeFastNormals
void SetComputeFastNormals(bool flag)
Set whether the fast path should be used for normals computation.
Definition: AbstractContour.h:118
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:102
vtkm::cont::UnknownArrayHandle::CastAndCallWithExtractedArray
void CastAndCallWithExtractedArray(Functor &&functor, Args &&... args) const
Call a functor on an array extracted from the components.
Definition: UnknownArrayHandle.h:1284
vtkm::filter::contour::AbstractContour::GetComputeFastNormals
bool GetComputeFastNormals() const
Get whether the fast path should be used for normals computation.
Definition: AbstractContour.h:121
vtkm::filter::contour::ContourDimension::Auto
@ Auto
Specifies an automatic selection of the input cell dimension.
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:52
vtkm::cont::Field::GetData
const vtkm::cont::UnknownArrayHandle & GetData() const
Get the array of the data for the field.
vtkm::filter::contour::AbstractContour::SetNormalArrayName
void SetNormalArrayName(const std::string &name)
Set the name of the field for the generated normals.
Definition: AbstractContour.h:125
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:282
vtkm::filter::contour::AbstractContour::SetGenerateNormals
void SetGenerateNormals(bool flag)
Set whether normals should be generated.
Definition: AbstractContour.h:94
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::filter::contour::ContourDimension::All
@ All
Specifies a combination of all possible contours.
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::contour::AbstractContour::SetInputCellDimensionToLines
void SetInputCellDimensionToLines()
Specifies running contours on lines.
Definition: AbstractContour.h:185
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:129
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::filter::contour::ContourDimension
ContourDimension
Identifies what type cells will be contoured.
Definition: ContourDimension.h:24
vtkm::cont::Field::GetName
const std::string & GetName() const
Return the name of the field.
Definition: Field.h:143
vtkm::cont::Field::IsWholeDataSetField
bool IsWholeDataSetField() const
Return true if this field is associated with the whole data set.
Definition: Field.h:121
SurfaceNormals.h
vtkm::cont::Field::IsPointField
bool IsPointField() const
Return true if this field is associated with points.
Definition: Field.h:119
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::SetInputCellDimensionToAuto
void SetInputCellDimensionToAuto()
Specifies an automatic selection of the input cell dimension.
Definition: AbstractContour.h:153
vtkm::filter::contour::AbstractContour::GetGenerateNormals
bool GetGenerateNormals() const
Get whether normals should be generated.
Definition: AbstractContour.h:97
vtkm::filter::contour::AbstractContour::SetInputCellDimensionToPolygons
void SetInputCellDimensionToPolygons()
Specifies running contours on polygons.
Definition: AbstractContour.h:177
vtkm::Float64
double Float64
Base type to use for 64-bit floating-point numbers.
Definition: Types.h:161
vtkm::filter::contour::AbstractContour::SetInputCellDimension
void SetInputCellDimension(vtkm::filter::contour::ContourDimension dimension)
Specify the dimension of cells on which to operate the contour.
Definition: AbstractContour.h:137
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:232
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:847
vtkm::filter::contour::AbstractContour::GetNumberOfIsoValues
vtkm::Id GetNumberOfIsoValues() const
Definition: AbstractContour.h:41
ContourDimension.h
vtkm::filter::contour::AbstractContour::SetIsoValue
void SetIsoValue(vtkm::Float64 v)
Set a field value on which to extract a contour.
Definition: AbstractContour.h:46
vtkm_filter_contour_export.h
vtkm::filter::contour::AbstractContour::ExecuteAddInterpolationEdgeIds
void ExecuteAddInterpolationEdgeIds(vtkm::cont::DataSet &output, WorkletType &worklet)
Definition: AbstractContour.h:267
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:304
vtkm::filter::contour::AbstractContour::SetInputCellDimensionToAll
void SetInputCellDimensionToAll()
Specifies a combination of all possible contours.
Definition: AbstractContour.h:161
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:202
vtkm::filter::contour::ContourDimension::Polygons
@ Polygons
Specifies running contours on polygons.
vtkm::filter::contour::AbstractContour::ExecuteGenerateNormals
void ExecuteGenerateNormals(vtkm::cont::DataSet &output, const vtkm::cont::ArrayHandle< vtkm::Vec3f > &normals)
Definition: AbstractContour.h:247
vtkm::filter::contour::ContourDimension::Lines
@ Lines
Specifies running contours on lines.
Filter.h