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 vtkStandardNewMacro(DecimationFilterType);
95 }
96 #else // VTKM_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 VTKM version
107  // scales with number of points. This means we can get away with a much finer
108  // grid with the VTKM 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 vtkStandardNewMacro(DecimationFilterType);
131 }
132 #endif // VTKM_ENABLE_TBB
133 
134 #endif
135 
136 // VTK-HeaderTest-Exclude: vtkGeometryRepresentationInternal.h
vtkGeometryRepresentation_detail::DecimationFilterType
Definition: vtkGeometryRepresentationInternal.h:100
vtkCellArray::GetMaxCellSize
int GetMaxCellSize()
vtkPolyData.h
vtkPolyData::GetNumberOfCells
vtkIdType GetNumberOfCells()
vtkQuadricClustering::SetCopyCellData
virtual void SetCopyCellData(int)
vtkIdType
int vtkIdType
vtkInformationVector
vtkDataObject::DATA_OBJECT
static vtkInformationDataObjectKey * DATA_OBJECT()
vtkGeometryRepresentation_detail::vtkStandardNewMacro
vtkStandardNewMacro(DecimationFilterType)
vtkQuadricClustering.h
vtkCellArray.h
vtkGeometryRepresentation_detail
Definition: vtkGeometryRepresentation.h:36
vtkInformationVector.h
vtkPolyData::ShallowCopy
void ShallowCopy(vtkDataObject *src)
vtkQuadricClustering::SetUseInputPoints
virtual void SetUseInputPoints(int)
vtkQuadricClustering::SetNumberOfDivisions
void SetNumberOfDivisions(int div[3])
vtkQuadricClustering
vtkMath::ClampValue
static T ClampValue(const T &value, const T &min, const T &max)
vtkCellArray::Squeeze
void Squeeze()
vtkGeometryRepresentation_detail::DecimationFilterType::DecimationFilterType
DecimationFilterType()
Definition: vtkGeometryRepresentationInternal.h:123
vtkCellArray
vtkPolyData::SafeDownCast
static vtkPolyData * SafeDownCast(vtkObjectBase *o)
vtkInformation::Get
VTKCOMMONCORE_EXPORT int Get(vtkInformationIntegerKey *key)
vtkGeometryRepresentation_detail::DecimationFilterType::New
static DecimationFilterType * New()
vtkNew
vtkGeometryRepresentation_detail::DecimationFilterType::SetLODFactor
void SetLODFactor(double factor)
Definition: vtkGeometryRepresentationInternal.h:110
vtkInformation
vtkInformationVector::GetInformationObject
vtkInformation * GetInformationObject(int index)
vtkCellArray::GetSize
vtkIdType GetSize()
vtkInformation.h
vtkPolyData
vtkPolyData::GetPolys
vtkCellArray * GetPolys()
vtkQuadricClustering::RequestData
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *)
vtkQuadricClustering::SetUseInternalTriangles
virtual void SetUseInternalTriangles(int)