1 /*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkPointConnectivityFilter.cxx
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm 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 #include "vtkPointConnectivityFilter.h"
16
17 #include "vtkIdList.h"
18 #include "vtkUnsignedIntArray.h"
19 #include "vtkCellData.h"
20 #include "vtkPointData.h"
21 #include "vtkDataSet.h"
22 #include "vtkObjectFactory.h"
23 #include "vtkInformation.h"
24 #include "vtkInformationVector.h"
25 #include "vtkSMPTools.h"
26 #include "vtkSMPThreadLocalObject.h"
27
28 #include "vtkNew.h"
29 #include "vtkSmartPointer.h"
30
31 vtkStandardNewMacro(vtkPointConnectivityFilter);
32
33 //----------------------------------------------------------------------------
34 vtkPointConnectivityFilter::vtkPointConnectivityFilter() = default;
35
36 //----------------------------------------------------------------------------
37 vtkPointConnectivityFilter::~vtkPointConnectivityFilter() = default;
38
39 //----------------------------------------------------------------------------
40 namespace {
41
42 // This class is general purpose for all dataset types.
43 struct UpdateConnectivityCount
44 {
45 vtkDataSet *Input;
46 unsigned int *ConnCount;
47 vtkSMPThreadLocalObject<vtkIdList> CellIds;
48
UpdateConnectivityCount__anon082628c00111::UpdateConnectivityCount49 UpdateConnectivityCount(vtkDataSet *input, unsigned int *connPtr) :
50 Input(input), ConnCount(connPtr)
51 {
52 }
53
Initialize__anon082628c00111::UpdateConnectivityCount54 void Initialize()
55 {
56 vtkIdList*& cellIds = this->CellIds.Local();
57 cellIds->Allocate(128); //allocate some memory
58 }
59
operator ()__anon082628c00111::UpdateConnectivityCount60 void operator() (vtkIdType ptId, vtkIdType endPtId)
61 {
62 vtkIdList*& cellIds = this->CellIds.Local();
63 for ( ; ptId < endPtId; ++ptId )
64 {
65 this->Input->GetPointCells(ptId, cellIds);
66 this->ConnCount[ptId] = cellIds->GetNumberOfIds();
67 }
68 }
69
Reduce__anon082628c00111::UpdateConnectivityCount70 void Reduce()
71 {
72 }
73 };
74
75 } // end anon namespace
76
77 //----------------------------------------------------------------------------
78 // This is the generic non-optimized method
RequestData(vtkInformation * vtkNotUsed (request),vtkInformationVector ** inputVector,vtkInformationVector * outputVector)79 int vtkPointConnectivityFilter::RequestData(
80 vtkInformation *vtkNotUsed(request),
81 vtkInformationVector **inputVector,
82 vtkInformationVector *outputVector)
83 {
84 vtkSmartPointer<vtkDataSet> input = vtkDataSet::GetData(inputVector[0]);
85 vtkDataSet *output = vtkDataSet::GetData(outputVector);
86
87 // First, copy the input to the output as a starting point
88 output->CopyStructure( input );
89 output->GetPointData()->PassData(input->GetPointData());
90 output->GetCellData()->PassData(input->GetCellData());
91
92 // Check input
93 vtkIdType numPts;
94 if ( input == nullptr || (numPts=input->GetNumberOfPoints()) < 1 )
95 {
96 return 1;
97 }
98
99 // Create integral array and populate it
100 vtkNew<vtkUnsignedIntArray> connCount;
101 connCount->SetNumberOfTuples(numPts);
102 connCount->SetName("Point Connectivity Count");
103 unsigned int *connPtr = static_cast<unsigned int*>(connCount->GetVoidPointer(0));
104
105 // Loop over all points, retrieving connectivity count
106 // The first GetPointCells() primes the pump (builds internal structures, etc.)
107 vtkNew<vtkIdList> cellIds;
108 input->GetPointCells(0, cellIds);
109 UpdateConnectivityCount updateCount(input,connPtr);
110 vtkSMPTools::For(0,numPts, updateCount);
111
112 // Pass array to the output
113 output->GetPointData()->AddArray(connCount);
114
115 return 1;
116 }
117
118 //----------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)119 void vtkPointConnectivityFilter::PrintSelf(ostream& os, vtkIndent indent)
120 {
121 this->Superclass::PrintSelf(os,indent);
122 }
123