Viskores  1.0
AbstractContour.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 
19 #ifndef viskores_filter_contour_AbstractContour_h
20 #define viskores_filter_contour_AbstractContour_h
21 
22 #include <viskores/filter/Filter.h>
27 
28 namespace viskores
29 {
30 namespace filter
31 {
32 namespace contour
33 {
38 class VISKORES_FILTER_CONTOUR_EXPORT AbstractContour : public viskores::filter::Filter
39 {
40 public:
42  {
43  if (num >= 0)
44  {
45  this->IsoValues.resize(static_cast<std::size_t>(num));
46  }
47  }
48 
50  {
51  return static_cast<viskores::Id>(this->IsoValues.size());
52  }
53 
57  void SetIsoValue(viskores::Float64 v) { this->SetIsoValue(0, v); }
58 
64  {
65  std::size_t i = static_cast<std::size_t>(index);
66  if (i >= this->IsoValues.size())
67  {
68  this->IsoValues.resize(i + 1);
69  }
70  this->IsoValues[i] = v;
71  }
72 
90  void SetIsoValues(const std::vector<viskores::Float64>& values) { this->IsoValues = values; }
91 
94  {
95  return this->IsoValues[static_cast<std::size_t>(index)];
96  }
97 
105  void SetGenerateNormals(bool flag) { this->GenerateNormals = flag; }
108  bool GetGenerateNormals() const { return this->GenerateNormals; }
109 
113  void SetAddInterpolationEdgeIds(bool flag) { this->AddInterpolationEdgeIds = flag; }
117  bool GetAddInterpolationEdgeIds() const { return this->AddInterpolationEdgeIds; }
118 
129  void SetComputeFastNormals(bool flag) { this->ComputeFastNormals = flag; }
132  bool GetComputeFastNormals() const { return this->ComputeFastNormals; }
133 
136  void SetNormalArrayName(const std::string& name) { this->NormalArrayName = name; }
137 
140  const std::string& GetNormalArrayName() const { return this->NormalArrayName; }
141 
149  {
150  this->InputCellDimension = dimension;
151  }
152 
155  {
156  return this->InputCellDimension;
157  }
158 
165  {
166  this->SetInputCellDimension(viskores::filter::contour::ContourDimension::Auto);
167  }
168 
173  {
174  this->SetInputCellDimension(viskores::filter::contour::ContourDimension::All);
175  }
176 
181  {
182  this->SetInputCellDimension(viskores::filter::contour::ContourDimension::Polyhedra);
183  }
184 
189  {
190  this->SetInputCellDimension(viskores::filter::contour::ContourDimension::Polygons);
191  }
192 
197  {
198  this->SetInputCellDimension(viskores::filter::contour::ContourDimension::Lines);
199  }
200 
213  void SetMergeDuplicatePoints(bool on) { this->MergeDuplicatedPoints = on; }
214 
218  bool GetMergeDuplicatePoints() const { return this->MergeDuplicatedPoints; }
219 
220 protected:
225  template <typename WorkletType>
227  const viskores::cont::Field& field,
228  WorkletType& worklet)
229  {
230  if (field.IsPointField())
231  {
232  viskores::cont::UnknownArrayHandle inputArray = field.GetData();
233  viskores::cont::UnknownArrayHandle outputArray = inputArray.NewInstanceBasic();
234 
235  auto functor = [&](const auto& concrete)
236  {
237  using ComponentType = typename std::decay_t<decltype(concrete)>::ValueType::ComponentType;
238  auto fieldArray = outputArray.ExtractArrayFromComponents<ComponentType>();
239  worklet.ProcessPointField(concrete, fieldArray);
240  };
241  inputArray.CastAndCallWithExtractedArray(functor);
242  result.AddPointField(field.GetName(), outputArray);
243  return true;
244  }
245  else if (field.IsCellField())
246  {
247  // Use the precompiled field permutation function.
248  viskores::cont::ArrayHandle<viskores::Id> permutation = worklet.GetCellIdMap();
249  return viskores::filter::MapFieldPermutation(field, permutation, result);
250  }
251  else if (field.IsWholeDataSetField())
252  {
253  result.AddField(field);
254  return true;
255  }
256  return false;
257  }
258 
260  viskores::cont::DataSet& output,
262  {
263  if (this->GenerateNormals)
264  {
265  if (this->GetComputeFastNormals())
266  {
268  surfaceNormals.SetPointNormalsName(this->NormalArrayName);
269  surfaceNormals.SetGeneratePointNormals(true);
270  output = surfaceNormals.Execute(output);
271  }
272  else
273  {
274  output.AddField(viskores::cont::make_FieldPoint(this->NormalArrayName, normals));
275  }
276  }
277  }
278 
279  template <typename WorkletType>
281  WorkletType& worklet)
282  {
283  if (this->AddInterpolationEdgeIds)
284  {
285  viskores::cont::Field interpolationEdgeIdsField(this->InterpolationEdgeIdsArrayName,
287  worklet.GetInterpolationEdgeIds());
288  output.AddField(interpolationEdgeIdsField);
289  }
290  }
291 
293  virtual viskores::cont::DataSet DoExecute(
294  const viskores::cont::DataSet& result) = 0; // Needs to be overridden by contour implementations
295 
296  std::vector<viskores::Float64> IsoValues;
297  bool GenerateNormals = true;
298  bool ComputeFastNormals = false;
299 
302 
303  bool AddInterpolationEdgeIds = false;
304  bool MergeDuplicatedPoints = true;
305  std::string NormalArrayName = "normals";
306  std::string InterpolationEdgeIdsArrayName = "edgeIds";
307 };
308 } // namespace contour
309 } // namespace filter
310 } // namespace viskores
311 
312 #endif // viskores_filter_contour_AbstractContour_h
viskores::filter::contour::AbstractContour::SetNumberOfIsoValues
void SetNumberOfIsoValues(viskores::Id num)
Definition: AbstractContour.h:41
viskores::filter::contour::AbstractContour::SetInputCellDimensionToAuto
void SetInputCellDimensionToAuto()
Specifies an automatic selection of the input cell dimension.
Definition: AbstractContour.h:164
viskores::filter::contour::AbstractContour::SetInputCellDimensionToLines
void SetInputCellDimensionToLines()
Specifies running contours on lines.
Definition: AbstractContour.h:196
viskores::filter::contour::AbstractContour::GetNormalArrayName
const std::string & GetNormalArrayName() const
Get the name of the field for the generated normals.
Definition: AbstractContour.h:140
viskores::filter::contour::AbstractContour::SetIsoValue
void SetIsoValue(viskores::Id index, viskores::Float64 v)
Set a field value on which to extract a contour.
Definition: AbstractContour.h:63
viskores::cont::DataSet
Contains and manages the geometric data structures that Viskores operates on.
Definition: DataSet.h:66
viskores::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:218
viskores::filter::vector_analysis::SurfaceNormals
Computes normals for polygonal mesh.
Definition: SurfaceNormals.h:52
viskores::filter::contour::ContourDimension::Auto
@ Auto
Specifies an automatic selection of the input cell dimension.
viskores::cont::Field::GetData
const viskores::cont::UnknownArrayHandle & GetData() const
Get the array of the data for the field.
viskores::filter::Filter
Base class for all filters.
Definition: Filter.h:171
viskores::filter::contour::AbstractContour::SetIsoValue
void SetIsoValue(viskores::Float64 v)
Set a field value on which to extract a contour.
Definition: AbstractContour.h:57
viskores::cont::ArrayHandle< viskores::Id >
MapFieldPermutation.h
viskores::filter::contour::AbstractContour::SetInputCellDimensionToPolyhedra
void SetInputCellDimensionToPolyhedra()
Specifies running contours on polyhedra.
Definition: AbstractContour.h:180
viskores::filter::contour::AbstractContour::ExecuteGenerateNormals
void ExecuteGenerateNormals(viskores::cont::DataSet &output, const viskores::cont::ArrayHandle< viskores::Vec3f > &normals)
Definition: AbstractContour.h:259
viskores::cont::DataSet::AddPointField
void AddPointField(const std::string &fieldName, const viskores::cont::UnknownArrayHandle &field)
Adds a point field of a given name to the DataSet.
Definition: DataSet.h:245
viskores::filter::contour::AbstractContour::GetIsoValue
viskores::Float64 GetIsoValue(viskores::Id index=0) const
Return a value used to contour the mesh.
Definition: AbstractContour.h:93
viskores::cont::UnknownArrayHandle::CastAndCallWithExtractedArray
void CastAndCallWithExtractedArray(Functor &&functor, Args &&... args) const
Call a functor on an array extracted from the components.
Definition: UnknownArrayHandle.h:1320
viskores::filter::Filter::Execute
viskores::cont::DataSet Execute(const viskores::cont::DataSet &input)
Executes the filter on the input and produces a result dataset.
viskores::filter::contour::AbstractContour
Contour filter interface.
Definition: AbstractContour.h:38
viskores::cont::Field::IsPointField
bool IsPointField() const
Return true if this field is associated with points.
Definition: Field.h:127
viskores::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:213
viskores::filter::contour::ContourDimension::Polyhedra
@ Polyhedra
Specifies running contours on polyhedra.
viskores::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:117
viskores::cont::make_FieldPoint
viskores::cont::Field make_FieldPoint(std::string name, const viskores::cont::ArrayHandle< T, S > &data)
Convenience function to build point fields from viskores::cont::ArrayHandle.
Definition: Field.h:315
viskores::cont::DataSet::AddField
void AddField(const Field &field)
Adds a field to the DataSet.
viskores::filter::contour::AbstractContour::SetComputeFastNormals
void SetComputeFastNormals(bool flag)
Set whether the fast path should be used for normals computation.
Definition: AbstractContour.h:129
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::filter::contour::AbstractContour::GetNumberOfIsoValues
viskores::Id GetNumberOfIsoValues() const
Definition: AbstractContour.h:49
viskores::filter::contour::AbstractContour::IsoValues
std::vector< viskores::Float64 > IsoValues
Definition: AbstractContour.h:296
viskores::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:113
viskores_filter_contour_export.h
viskores::filter::contour::AbstractContour::GetInputCellDimension
viskores::filter::contour::ContourDimension GetInputCellDimension() const
Specify the dimension of cells on which to operate the contour.
Definition: AbstractContour.h:154
viskores::filter::contour::AbstractContour::SetInputCellDimension
void SetInputCellDimension(viskores::filter::contour::ContourDimension dimension)
Specify the dimension of cells on which to operate the contour.
Definition: AbstractContour.h:148
viskores::filter::contour::ContourDimension::Lines
@ Lines
Specifies running contours on lines.
viskores::filter::vector_analysis::SurfaceNormals::SetPointNormalsName
void SetPointNormalsName(const std::string &name)
Specify the name of the point normals field.
Definition: SurfaceNormals.h:95
viskores::filter::contour::ContourDimension::Polygons
@ Polygons
Specifies running contours on polygons.
viskores::cont::Field::GetName
const std::string & GetName() const
Return the name of the field.
Definition: Field.h:151
viskores::filter::contour::AbstractContour::GetGenerateNormals
bool GetGenerateNormals() const
Get whether normals should be generated.
Definition: AbstractContour.h:108
viskores::filter::contour::AbstractContour::DoMapField
static bool DoMapField(viskores::cont::DataSet &result, const viskores::cont::Field &field, WorkletType &worklet)
Map a given field to the output DataSet , depending on its type.
Definition: AbstractContour.h:226
viskores::filter::contour::AbstractContour::SetIsoValues
void SetIsoValues(const std::vector< viskores::Float64 > &values)
Set multiple iso values at once.
Definition: AbstractContour.h:90
SurfaceNormals.h
viskores::filter::contour::AbstractContour::SetNormalArrayName
void SetNormalArrayName(const std::string &name)
Set the name of the field for the generated normals.
Definition: AbstractContour.h:136
viskores::cont::UnknownArrayHandle::NewInstanceBasic
UnknownArrayHandle NewInstanceBasic() const
Create a new ArrayHandleBasic with the same ValueType as this array.
viskores::filter::MapFieldPermutation
bool MapFieldPermutation(const viskores::cont::Field &inputField, const viskores::cont::ArrayHandle< viskores::Id > &permutation, viskores::cont::Field &outputField, viskores::Float64 invalidValue=viskores::Nan< viskores::Float64 >())
Maps a field by permuting it by a given index array.
viskores::filter::vector_analysis::SurfaceNormals::SetGeneratePointNormals
void SetGeneratePointNormals(bool value)
Specify whether the point normals should be generated.
Definition: SurfaceNormals.h:81
viskores::cont::UnknownArrayHandle::ExtractArrayFromComponents
viskores::cont::ArrayHandleRecombineVec< BaseComponentType > ExtractArrayFromComponents(viskores::CopyFlag allowCopy=viskores::CopyFlag::On) const
Extract the array knowing only the component type of the array.
Definition: UnknownArrayHandle.h:873
viskores::filter::contour::AbstractContour::ExecuteAddInterpolationEdgeIds
void ExecuteAddInterpolationEdgeIds(viskores::cont::DataSet &output, WorkletType &worklet)
Definition: AbstractContour.h:280
viskores::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:451
viskores::Float64
double Float64
Base type to use for 64-bit floating-point numbers.
Definition: Types.h:169
ContourDimension.h
viskores::cont::Field::IsCellField
bool IsCellField() const
Return true if this field is associated with cells.
Definition: Field.h:125
viskores::cont::Field::Association::Points
@ Points
A field that applies to points.
viskores::cont::Field
A Field encapsulates an array on some piece of the mesh, such as the points, a cell set,...
Definition: Field.h:39
viskores::filter::contour::AbstractContour::SetInputCellDimensionToPolygons
void SetInputCellDimensionToPolygons()
Specifies running contours on polygons.
Definition: AbstractContour.h:188
viskores::cont::Field::IsWholeDataSetField
bool IsWholeDataSetField() const
Return true if this field is associated with the whole data set.
Definition: Field.h:129
viskores::filter::contour::AbstractContour::SetGenerateNormals
void SetGenerateNormals(bool flag)
Set whether normals should be generated.
Definition: AbstractContour.h:105
viskores::filter::contour::AbstractContour::SetInputCellDimensionToAll
void SetInputCellDimensionToAll()
Specifies a combination of all possible contours.
Definition: AbstractContour.h:172
viskores::filter::contour::AbstractContour::GetComputeFastNormals
bool GetComputeFastNormals() const
Get whether the fast path should be used for normals computation.
Definition: AbstractContour.h:132
viskores::filter::contour::ContourDimension::All
@ All
Specifies a combination of all possible contours.
viskores::filter::contour::ContourDimension
ContourDimension
Identifies what type cells will be contoured.
Definition: ContourDimension.h:32
Filter.h