VTK  9.1.0
vtkLabelHierarchyPrivate.h
Go to the documentation of this file.
1#ifndef vtkLabelHierarchyPrivate_h
2#define vtkLabelHierarchyPrivate_h
3
4#include <set>
5
6#include "octree/octree"
7
8//----------------------------------------------------------------------------
9// vtkLabelHierarchy::Implementation
10
12{
13public:
15 {
16 this->Hierarchy2 = nullptr;
17 this->Hierarchy3 = nullptr;
18 this->ActualDepth = 5;
19 this->Z2 = 0.;
20 }
21
23 {
24 delete this->Hierarchy2;
25 delete this->Hierarchy3;
26 }
27
29 {
30 vtkDataArray* priorities = this->Husk->GetPriorities();
31 return priorities ? priorities->GetTuple1(a) > priorities->GetTuple1(b) : a < b;
32 }
33
35 {
37
39 {
40 // See comment near declaration of Current for more info:
42 }
43
44 PriorityComparator(vtkLabelHierarchy* h) { this->Hierarchy = h; }
45
46 PriorityComparator(const PriorityComparator& src) { this->Hierarchy = src.Hierarchy; }
47
49 {
50 if (this != &rhs)
51 {
52 this->Hierarchy = rhs.Hierarchy;
53 }
54 return *this;
55 }
56
58
59 bool operator()(const vtkIdType& a, const vtkIdType& b) const
60 {
61 if (nullptr == this->Hierarchy)
62 {
63 vtkGenericWarningMacro("error: NULL this->Hierarchy in PriorityComparator");
64 return a < b;
65 }
66
67 if (nullptr == this->Hierarchy->GetImplementation())
68 {
69 vtkGenericWarningMacro(
70 "error: NULL this->Hierarchy->GetImplementation() in PriorityComparator");
71 return a < b;
72 }
73
74 return this->Hierarchy->GetImplementation()->ComparePriorities(a, b);
75 }
76 };
77
78 class LabelSet : public std::multiset<vtkIdType, PriorityComparator>
79 {
80 public:
82 : std::multiset<vtkIdType, PriorityComparator>(PriorityComparator(hierarchy))
83 {
84 this->TotalAnchors = 0;
85 this->Size = 1.;
86 for (int i = 0; i < 3; ++i)
87 {
88 this->Center[i] = 0.;
89 }
90 }
91
92 LabelSet(const LabelSet& src)
93 : std::multiset<vtkIdType, PriorityComparator>(src)
94 {
95 this->TotalAnchors = src.TotalAnchors;
96 this->Size = src.Size;
97 for (int i = 0; i < 3; ++i)
98 {
99 this->Center[i] = src.Center[i];
100 }
101 }
102
104 : std::multiset<vtkIdType, PriorityComparator>()
105 {
106 this->TotalAnchors = 0;
107 this->Size = 1.;
108 for (int i = 0; i < 3; ++i)
109 {
110 this->Center[i] = 0.;
111 }
112 }
113
115 {
116 if (this != &rhs)
117 {
118 std::multiset<vtkIdType, PriorityComparator>::operator=(rhs);
119 this->TotalAnchors = rhs.TotalAnchors;
120 this->Size = rhs.Size;
121 for (int i = 0; i < 3; ++i)
122 {
123 this->Center[i] = rhs.Center[i];
124 }
125 }
126 return *this;
127 }
128 const double* GetCenter() const { return this->Center; }
129 double GetSize() const { return this->Size; }
130 void SetGeometry(const double center[3], double length);
131 void SetChildGeometry(octree<LabelSet, 2>::octree_node_pointer self);
132 void SetChildGeometry(octree<LabelSet, 3>::octree_node_pointer self);
133 void AddChildren(octree<LabelSet, 2>::octree_node_pointer self, LabelSet& emptyNode);
134 void AddChildren(octree<LabelSet, 3>::octree_node_pointer self, LabelSet& emptyNode);
135 void Insert(vtkIdType anchor)
136 {
137 this->insert(anchor);
138 ++this->TotalAnchors;
139 }
140 void Increment() { ++this->TotalAnchors; }
141 vtkIdType GetLocalAnchorCount() const { return static_cast<vtkIdType>(this->size()); }
143
144 vtkIdType TotalAnchors; // Count of all anchors stored in this node and its children.
145 double Center[3]; // Geometric coordinates of this node's center.
146 double Size; // Length of each edge of this node.
147 };
148
149 typedef octree<LabelSet, 2> HierarchyType2;
150 typedef octree<LabelSet, 2>::cursor HierarchyCursor2;
151 typedef octree<LabelSet, 2>::iterator HierarchyIterator2;
152
153 typedef octree<LabelSet> HierarchyType3;
154 typedef octree<LabelSet>::cursor HierarchyCursor3;
155 typedef octree<LabelSet>::iterator HierarchyIterator3;
156
157 // typedef std::map<Coord,std::pair<int,std::set<vtkIdType> > >::iterator MapCoordIter;
158
159 // Description:
160 // Computes the depth of the generated hierarchy.
161 // void ComputeActualDepth();
162
163 // Description:
164 // Routines called by ComputeHierarchy()
165 void BinAnchorsToLevel(int level);
167 void DemoteAnchors(int level);
170
171 // Description:
172 // Routines called by ComputeHierarchy()
175 void DropAnchor2(vtkIdType anchor);
176 void DropAnchor3(vtkIdType anchor);
177 void SmudgeAnchor2(HierarchyCursor2& cursor, vtkIdType anchor, double* x);
178 void SmudgeAnchor3(HierarchyCursor3& cursor, vtkIdType anchor, double* x);
179
180 double Z2; // common z-coordinate of all label anchors when quadtree (Hierarchy2) is used.
181 HierarchyType2* Hierarchy2; // 2-D quadtree of label anchors (all input points have same z coord)
183 Hierarchy3; // 3-D octree of label anchors (input point bounds have non-zero z range)
185 HierarchyType3::size_type ActualDepth;
187
189};
190
192 const double center[3], double length)
193{
194 for (int i = 0; i < 3; ++i)
195 {
196 this->Center[i] = center[i];
197 }
198 this->Size = length;
199}
200
202 octree<LabelSet, 2>::octree_node_pointer self)
203{
204 double sz2 = this->Size / 2.;
205 double x[3];
206 for (int i = 0; i < self->num_children(); ++i)
207 {
208 for (int j = 0; j < 2; ++j)
209 {
210 x[j] = this->Center[j] + ((i & (1 << j)) ? 0.5 : -0.5) * sz2;
211 }
212 x[2] = this->Center[2];
213 (*self)[i].value().SetGeometry(x, sz2);
214 }
215}
216
218 octree<LabelSet, 3>::octree_node_pointer self)
219{
220 double sz2 = this->Size / 2.;
221 double x[3];
222 for (int i = 0; i < self->num_children(); ++i)
223 {
224 for (int j = 0; j < 3; ++j)
225 {
226 x[j] = this->Center[j] + ((i & (1 << j)) ? 0.5 : -0.5) * sz2;
227 }
228 (*self)[i].value().SetGeometry(x, sz2);
229 }
230}
231
233 octree<LabelSet, 2>::octree_node_pointer self, LabelSet& emptyNode)
234{
235 self->add_children(emptyNode);
236 this->SetChildGeometry(self);
237}
238
240 octree<LabelSet, 3>::octree_node_pointer self, LabelSet& emptyNode)
241{
242 self->add_children(emptyNode);
243 this->SetChildGeometry(self);
244}
245
246#endif // vtkLabelHierarchyPrivate_h
247// VTK-HeaderTest-Exclude: vtkLabelHierarchyPrivate.h
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:159
double GetTuple1(vtkIdType tupleIdx)
These methods are included as convenience for the wrappers.
double Center[3]
Definition: vtkDataSet.h:603
vtkFrustumSelector is a vtkSelector that selects elements based on whether they are inside or interse...
void AddChildren(octree< LabelSet, 2 >::octree_node_pointer self, LabelSet &emptyNode)
void SetChildGeometry(octree< LabelSet, 2 >::octree_node_pointer self)
void SetGeometry(const double center[3], double length)
void SmudgeAnchor3(HierarchyCursor3 &cursor, vtkIdType anchor, double *x)
void SmudgeAnchor2(HierarchyCursor2 &cursor, vtkIdType anchor, double *x)
bool ComparePriorities(vtkIdType a, vtkIdType b)
octree< LabelSet, 2 >::cursor HierarchyCursor2
void DropAnchor3(vtkIdType anchor)
void FillHierarchyRoot(LabelSet &anchors)
void RecursiveNodeDivide(HierarchyCursor2 &cursor)
void DropAnchor2(vtkIdType anchor)
void RecursiveNodeDivide(HierarchyCursor3 &cursor)
octree< LabelSet >::cursor HierarchyCursor3
void PrepareSortedAnchors(LabelSet &anchors)
octree< LabelSet >::iterator HierarchyIterator3
octree< LabelSet, 2 >::iterator HierarchyIterator2
contains an octree of labels
Implementation * GetImplementation()
virtual vtkDataArray * GetPriorities()
Set/get the array specifying the importance (priority) of each label.
record modification and/or execution time
Definition: vtkTimeStamp.h:52
bool operator()(const vtkIdType &a, const vtkIdType &b) const
PriorityComparator & operator=(const PriorityComparator &rhs)
int vtkIdType
Definition: vtkType.h:332