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