vtkGeometryRepresentationInternal.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: vtkGeometryRepresentation.cxx
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 #ifndef vtkGeometryRepresentationInternal_h
17 #define vtkGeometryRepresentationInternal_h
18 
19 #include "vtkInformation.h" // for vtkInformation
20 #include "vtkInformationVector.h" // for vtkInformationVector
21 #include "vtkPolyData.h" // for vtkPolyData
22 
23 // We'll use the VTKm decimation filter if TBB is enabled, otherwise we'll
24 // fallback to vtkQuadricClustering, since vtkmLevelOfDetail is slow on the
25 // serial backend.
26 #if VTK_MODULE_ENABLE_VTK_vtkm
27 #include "vtkmConfigFilters.h" // for VTKM_ENABLE_TBB
28 #endif
29 
30 #if defined(VTKM_ENABLE_TBB) && VTK_MODULE_ENABLE_VTK_AcceleratorsVTKmFilters
31 #include "vtkCellArray.h" // for vtkCellArray
32 #include "vtkQuadricClustering.h" // for vtkQuadricClustering
33 #include "vtkmLevelOfDetail.h"
35 {
36 class DecimationFilterType : public vtkmLevelOfDetail
37 {
38 public:
39  static DecimationFilterType* New();
40  vtkTypeMacro(DecimationFilterType, vtkmLevelOfDetail);
41 
42  // See note on the vtkQuadricClustering implementation below.
43  void SetLODFactor(double factor)
44  {
45  factor = vtkMath::ClampValue(factor, 0., 1.);
46 
47  // This produces the following number of divisions for 'factor':
48  // 0.0 --> 64
49  // 0.5 --> 256 (default)
50  // 1.0 --> 1024
51  int divs = static_cast<int>(std::pow(2, 4. * factor + 6.));
52  this->SetNumberOfDivisions(divs, divs, divs);
53  }
54 
55 protected:
57  {
58  this->Fallback->SetUseInputPoints(1);
59  this->Fallback->SetCopyCellData(1);
60  this->Fallback->SetUseInternalTriangles(0);
61  }
62 
63  int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
64  vtkInformationVector* outputVector) override
65  {
66  // The accelerated implementation only supports triangle meshes. Fallback to
67  // vtkQuadricClustering if needed:
68  vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
70  if (!input)
71  {
72  vtkErrorMacro("Expected polydata.");
73  return 0;
74  }
75 
76  // This filter only handles triangles. This code to detect all triangles is
77  // adapted from tovtkm::Convert for vtkPolyData:
78  vtkCellArray* polys = input->GetPolys();
79  const int maxPolySize = polys->GetMaxCellSize();
80  const vtkIdType numCells = input->GetNumberOfCells();
81  // deduce if we only have triangles. We use maxCellSize+1 so
82  // that we handle the length entry in the cell array for each cell
83  polys->Squeeze();
84  const bool allSameType = ((numCells * (maxPolySize + 1)) == polys->GetSize());
85  if (allSameType && maxPolySize == 3)
86  { // All triangles. Try the accelerated implementation:
87  if (this->Superclass::RequestData(request, inputVector, outputVector))
88  {
89  return 1;
90  }
91  }
92 
93  // Otherwise fallback to quadric clustering:
94  vtkInformation* outInfo = outputVector->GetInformationObject(0);
96 
97  this->Fallback->SetInputData(input);
98  this->Fallback->Update();
99  output->ShallowCopy(this->Fallback->GetOutput(0));
100 
101  return 1;
102  }
103 
105 };
107 }
108 #else // VTKM_ENABLE_TBB
109 #include "vtkQuadricClustering.h"
111 {
113 {
114 public:
115  static DecimationFilterType* New();
117 
118  // This version gets slower as the grid increases, while the VTKM version
119  // scales with number of points. This means we can get away with a much finer
120  // grid with the VTKM filter, so we'll just reduce the mesh quality a bit
121  // here.
122  void SetLODFactor(double factor)
123  {
124  factor = vtkMath::ClampValue(factor, 0., 1.);
125 
126  // This is the same equation used in the old implementation:
127  // 0.0 --> 10
128  // 0.5 --> 85 (default)
129  // 1.0 --> 160
130  int divs = static_cast<int>(150 * factor) + 10;
131  this->SetNumberOfDivisions(divs, divs, divs);
132  }
133 
134 protected:
136  {
137  this->SetUseInputPoints(1);
138  this->SetCopyCellData(1);
139  this->SetUseInternalTriangles(0);
140  }
141 };
143 }
144 #endif // VTKM_ENABLE_TBB
145 
146 #endif
147 
148 // VTK-HeaderTest-Exclude: vtkGeometryRepresentationInternal.h
vtkIdType GetNumberOfCells()
virtual void SetUseInputPoints(int)
vtkInformation * GetInformationObject(int index)
int vtkIdType
void SetNumberOfDivisions(int div[3])
vtkStandardNewMacro(DecimationFilterType)
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()