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 #include "vtkInformation.h"
17 #include "vtkInformationVector.h"
18 #include "vtkPolyData.h"
19 
20 // We'll use the VTKm decimation filter if TBB is enabled, otherwise we'll
21 // fallback to vtkQuadricClustering, since vtkmLevelOfDetail is slow on the
22 // serial backend.
23 #ifndef __VTK_WRAP__
24 #if VTK_MODULE_ENABLE_VTK_vtkm
25 #include "vtkmConfig.h" // for VTKM_ENABLE_TBB
26 #endif
27 
28 #if defined(VTKM_ENABLE_TBB) && VTK_MODULE_ENABLE_VTK_AcceleratorsVTKm
29 #include "vtkCellArray.h"
30 #include "vtkQuadricClustering.h"
31 #include "vtkmLevelOfDetail.h"
33 {
34 class DecimationFilterType : public vtkmLevelOfDetail
35 {
36 public:
37  static DecimationFilterType* New();
38  vtkTypeMacro(DecimationFilterType, vtkmLevelOfDetail)
39 
40  // See note on the vtkQuadricClustering implementation below.
41  void SetLODFactor(double factor)
42  {
43  factor = vtkMath::ClampValue(factor, 0., 1.);
44 
45  // This produces the following number of divisions for 'factor':
46  // 0.0 --> 64
47  // 0.5 --> 256 (default)
48  // 1.0 --> 1024
49  int divs = static_cast<int>(std::pow(2, 4. * factor + 6.));
50  this->SetNumberOfDivisions(divs, divs, divs);
51  }
52 
53 protected:
55  {
56  this->Fallback->SetUseInputPoints(1);
57  this->Fallback->SetCopyCellData(1);
58  this->Fallback->SetUseInternalTriangles(0);
59  }
60 
61  int RequestData(vtkInformation* request, vtkInformationVector** inputVector,
62  vtkInformationVector* outputVector) override
63  {
64  // The accelerated implementation only supports triangle meshes. Fallback to
65  // vtkQuadricClustering if needed:
66  vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
68  if (!input)
69  {
70  vtkErrorMacro("Expected polydata.");
71  return 0;
72  }
73 
74  // This filter only handles triangles. This code to detect all triangles is
75  // adapted from tovtkm::Convert for vtkPolyData:
76  vtkCellArray* polys = input->GetPolys();
77  const int maxPolySize = polys->GetMaxCellSize();
78  const vtkIdType numCells = input->GetNumberOfCells();
79  // deduce if we only have triangles. We use maxCellSize+1 so
80  // that we handle the length entry in the cell array for each cell
81  polys->Squeeze();
82  const bool allSameType = ((numCells * (maxPolySize + 1)) == polys->GetSize());
83  if (allSameType && maxPolySize == 3)
84  { // All triangles. Try the accelerated implementation:
85  if (this->Superclass::RequestData(request, inputVector, outputVector))
86  {
87  return 1;
88  }
89  }
90 
91  // Otherwise fallback to quadric clustering:
92  vtkInformation* outInfo = outputVector->GetInformationObject(0);
94 
95  this->Fallback->SetInputData(input);
96  this->Fallback->Update();
97  output->ShallowCopy(this->Fallback->GetOutput(0));
98 
99  return 1;
100  }
101 
103 };
105 }
106 #else // VTKM_ENABLE_TBB
107 #include "vtkQuadricClustering.h"
109 {
111 {
112 public:
113  static DecimationFilterType* New();
115 
116  // This version gets slower as the grid increases, while the VTKM version
117  // scales with number of points. This means we can get away with a much finer
118  // grid with the VTKM filter, so we'll just reduce the mesh quality a bit
119  // here.
120  void SetLODFactor(double factor)
121  {
122  factor = vtkMath::ClampValue(factor, 0., 1.);
123 
124  // This is the same equation used in the old implementation:
125  // 0.0 --> 10
126  // 0.5 --> 85 (default)
127  // 1.0 --> 160
128  int divs = static_cast<int>(150 * factor) + 10;
129  this->SetNumberOfDivisions(divs, divs, divs);
130  }
131 
132 protected:
134  {
135  this->SetUseInputPoints(1);
136  this->SetCopyCellData(1);
137  this->SetUseInternalTriangles(0);
138  }
139 };
141 }
142 #endif // VTKM_ENABLE_TBB
143 #endif // __VTK_WRAP__
144 // 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()
#define vtkStandardNewMacro(thisClass)
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()