vtkGeometryRepresentationInternal.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-License-Identifier: BSD-3-Clause
3 
4 #ifndef vtkGeometryRepresentationInternal_h
5 #define vtkGeometryRepresentationInternal_h
6 
7 #include "vtkInformation.h" // for vtkInformation
8 #include "vtkInformationVector.h" // for vtkInformationVector
9 #include "vtkPolyData.h" // for vtkPolyData
10 
11 // We'll use the VTKm decimation filter if TBB is enabled, otherwise we'll
12 // fallback to vtkQuadricClustering, since vtkmLevelOfDetail is slow on the
13 // serial backend.
14 #if VTK_MODULE_ENABLE_VTK_vtkm
15 #include "vtkmConfigFilters.h" // for VTKM_ENABLE_TBB
16 #endif
17 
18 #if defined(VTKM_ENABLE_TBB) && VTK_MODULE_ENABLE_VTK_AcceleratorsVTKmFilters
19 #include "vtkCellArray.h" // for vtkCellArray
20 #include "vtkQuadricClustering.h" // for vtkQuadricClustering
21 #include "vtkmLevelOfDetail.h"
23 {
24 class DecimationFilterType : public vtkmLevelOfDetail
25 {
26 public:
27  static DecimationFilterType* New();
28  vtkTypeMacro(DecimationFilterType, vtkmLevelOfDetail);
29 
30  // See note on the vtkQuadricClustering implementation below.
31  void SetLODFactor(double factor)
32  {
33  factor = vtkMath::ClampValue(factor, 0., 1.);
34 
35  // This produces the following number of divisions for 'factor':
36  // 0.0 --> 64
37  // 0.5 --> 256 (default)
38  // 1.0 --> 1024
39  int divs = static_cast<int>(std::pow(2, 4. * factor + 6.));
40  this->SetNumberOfDivisions(divs, divs, divs);
41  }
42 
43 protected:
45  {
46  this->Fallback->SetUseInputPoints(1);
47  this->Fallback->SetCopyCellData(1);
48  this->Fallback->SetUseInternalTriangles(0);
49  }
50 
51  int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
52  vtkInformationVector* outputVector) override
53  {
54  // The accelerated implementation only supports triangle meshes. Fallback to
55  // vtkQuadricClustering if needed:
56  vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
58  if (!input)
59  {
60  vtkErrorMacro("Expected polydata.");
61  return 0;
62  }
63 
64  // This filter only handles triangles. This code to detect all triangles is
65  // adapted from tovtkm::Convert for vtkPolyData:
66  vtkCellArray* polys = input->GetPolys();
67  const int maxPolySize = polys->GetMaxCellSize();
68  const vtkIdType numCells = input->GetNumberOfCells();
69  // deduce if we only have triangles. We use maxCellSize+1 so
70  // that we handle the length entry in the cell array for each cell
71  polys->Squeeze();
72  const bool allSameType = ((numCells * (maxPolySize + 1)) == polys->GetSize());
73  if (allSameType && maxPolySize == 3)
74  { // All triangles. Try the accelerated implementation:
75  if (this->Superclass::RequestData(request, inputVector, outputVector))
76  {
77  return 1;
78  }
79  }
80 
81  // Otherwise fallback to quadric clustering:
82  vtkInformation* outInfo = outputVector->GetInformationObject(0);
84 
85  this->Fallback->SetInputData(input);
86  this->Fallback->Update();
87  output->ShallowCopy(this->Fallback->GetOutput(0));
88 
89  return 1;
90  }
91 
93 };
94 }
95 #else // VTKM_ENABLE_TBB
96 #include "vtkQuadricClustering.h"
98 {
100 {
101 public:
102  static DecimationFilterType* New();
104 
105  // This version gets slower as the grid increases, while the VTKM version
106  // scales with number of points. This means we can get away with a much finer
107  // grid with the VTKM filter, so we'll just reduce the mesh quality a bit
108  // here.
109  void SetLODFactor(double factor)
110  {
111  factor = vtkMath::ClampValue(factor, 0., 1.);
112 
113  // This is the same equation used in the old implementation:
114  // 0.0 --> 10
115  // 0.5 --> 85 (default)
116  // 1.0 --> 160
117  int divs = static_cast<int>(150 * factor) + 10;
118  this->SetNumberOfDivisions(divs, divs, divs);
119  }
120 
121 protected:
123  {
124  this->SetUseInputPoints(1);
125  this->SetCopyCellData(1);
126  this->SetUseInternalTriangles(0);
127  }
128 };
129 }
130 #endif // VTKM_ENABLE_TBB
131 
132 #endif
133 
134 // VTK-HeaderTest-Exclude: vtkGeometryRepresentationInternal.h
vtkIdType GetNumberOfCells()
virtual void SetUseInputPoints(int)
vtkInformation * GetInformationObject(int index)
int vtkIdType
void SetNumberOfDivisions(int div[3])
void ShallowCopy(vtkDataObject *src)
void Squeeze()
virtual void SetCopyCellData(int)
static vtkPolyData * SafeDownCast(vtkObjectBase *o)
vtkCellArray * GetPolys()
virtual void SetUseInternalTriangles(int)
static vtkInformationDataObjectKey * DATA_OBJECT()
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
static T ClampValue(const T &value, const T &min, const T &max)
vtkIdType GetSize()
VTKCOMMONCORE_EXPORT int Get(vtkInformationIntegerKey *key)
int GetMaxCellSize()