forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkSMPMergePoints.h
115 lines (96 loc) · 3.81 KB
/
vtkSMPMergePoints.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSMPMergePoints.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/**
* @class vtkSMPMergePoints
* @brief Class designed to help with merging of points in parallel
*
* vtkSMPMergePoints is a subclass of vtkMergePoints designed to help
* with merging of points generated by using multiple locators in parallel.
* Its main functionality is provided by the Merge function. It also
* has a few additional convenience functions.
* Merge is thread safe as long as no two threads are merging the same
* bin. The common way of using vtkSMPMergePoints is:
* - Initialize with outLocator->InitializeMerge()
* - Allocate points with outLocator->GetPoints()->Resize(numPts) (numPts should be >= total number
* of points)
* - Do bunch of merging with outLocator->Merge(inLocator[i], ...) (this can be done in parallel as
* long as no two bins are done at the same time)
* - Fix the size of points with outLocator->FixSizeOfPointArray()
*/
#ifndef vtkSMPMergePoints_h
#define vtkSMPMergePoints_h
#include "vtkFiltersSMPModule.h" // For export macro
#include "vtkIdList.h" // For inline functions
#include "vtkMergePoints.h"
#include "vtkType.h" // For vtkIdType
#include <atomic> // for std::atomic
class vtkPointData;
class VTKFILTERSSMP_EXPORT vtkSMPMergePoints : public vtkMergePoints
{
public:
vtkTypeMacro(vtkSMPMergePoints, vtkMergePoints);
static vtkSMPMergePoints* New();
void PrintSelf(ostream& os, vtkIndent indent) override;
/**
* This should be called from 1 thread before any call to Merge.
*/
void InitializeMerge();
/**
* Merge the points of one of the bins from the given locator to
* the same bin of the current locator. Note that this requires that
* the two locators have identical binning structures. This also
* merges point data given in the inPD argument to the outPd.
* Furthermore, it generates a map of the old ids of the input locator
* to the new ids. This is stored in the idList argument. The map
* is idList[oldId] = newId.
*/
void Merge(vtkSMPMergePoints* locator, vtkIdType idx, vtkPointData* outPd, vtkPointData* inPd,
vtkIdList* idList);
/**
* At the of the merge, this can be called to set the MaxId of the
* points array to the maximum id in the locator. The current design
* usage is as follows:
* - Allocate points with points->Resize(numPts). NumPts should be >= total number of points
* - Do bunch of merging with outLocator->Merge(inLocator[i], ...)
* - Fix the size of points with outLocator->FixSizeOfPointArray()
*/
void FixSizeOfPointArray();
/**
* Returns the biggest id in the locator.
*/
vtkIdType GetMaxId() { return this->AtomicInsertionId - 1; }
///@{
/**
* Returns the number of points in a bin.
*/
vtkIdType GetNumberOfIdsInBucket(vtkIdType idx)
{
if (!this->HashTable)
{
return 0;
}
vtkIdList* bucket = this->HashTable[idx];
return bucket ? bucket->GetNumberOfIds() : 0;
}
///@}
/**
* Returns the number of bins.
*/
vtkIdType GetNumberOfBuckets() override { return this->NumberOfBuckets; }
protected:
vtkSMPMergePoints();
~vtkSMPMergePoints() override;
std::atomic<vtkIdType> AtomicInsertionId;
private:
vtkSMPMergePoints(const vtkSMPMergePoints&) = delete;
void operator=(const vtkSMPMergePoints&) = delete;
};
#endif // vtkSMPMergePoints_h