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_AcceleratorsVTKmFilters
15 #include "vtkmConfigFilters.h" // for VISKORES_ENABLE_TBB
16 #endif
17 
18 #if defined(VISKORES_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 = polys->GetNumberOfCells() == numCells &&
73  polys->GetNumberOfConnectivityIds() == numCells * maxPolySize;
74  if (allSameType && maxPolySize == 3)
75  { // All triangles. Try the accelerated implementation:
76  if (this->Superclass::RequestData(request, inputVector, outputVector))
77  {
78  return 1;
79  }
80  }
81 
82  // Otherwise fallback to quadric clustering:
83  vtkInformation* outInfo = outputVector->GetInformationObject(0);
85 
86  this->Fallback->SetInputData(input);
87  this->Fallback->Update();
88  output->ShallowCopy(this->Fallback->GetOutput(0));
89 
90  return 1;
91  }
92 
94 };
95 }
96 #else // VISKORES_ENABLE_TBB
97 #include "vtkQuadricClustering.h"
99 {
101 {
102 public:
103  static DecimationFilterType* New();
105 
106  // This version gets slower as the grid increases, while the VISKORES version
107  // scales with number of points. This means we can get away with a much finer
108  // grid with the VISKORES filter, so we'll just reduce the mesh quality a bit
109  // here.
110  void SetLODFactor(double factor)
111  {
112  factor = vtkMath::ClampValue(factor, 0., 1.);
113 
114  // This is the same equation used in the old implementation:
115  // 0.0 --> 10
116  // 0.5 --> 85 (default)
117  // 1.0 --> 160
118  int divs = static_cast<int>(150 * factor) + 10;
119  this->SetNumberOfDivisions(divs, divs, divs);
120  }
121 
122 protected:
124  {
125  this->SetUseInputPoints(1);
126  this->SetCopyCellData(1);
127  this->SetUseInternalTriangles(0);
128  }
129 };
130 }
131 #endif // VISKORES_ENABLE_TBB
132 
133 #endif
134 
135 // VTK-HeaderTest-Exclude: vtkGeometryRepresentationInternal.h
vtkIdType GetNumberOfCells()
virtual void SetUseInputPoints(int)
vtkInformation * GetInformationObject(int index)
int vtkIdType
void SetNumberOfDivisions(int div[3])
virtual vtkIdType GetNumberOfCells()
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)
VTKCOMMONCORE_EXPORT int Get(vtkInformationIntegerKey *key)
int GetMaxCellSize()