VTK  9.0.20200706
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 {
13 public:
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 
57  ~PriorityComparator() = default;
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()); }
142  vtkIdType GetTotalAnchorCount() const { return this->TotalAnchors; }
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);
166  void PromoteAnchors();
167  void DemoteAnchors(int level);
170 
171  // Description:
172  // Routines called by ComputeHierarchy()
173  void PrepareSortedAnchors(LabelSet& anchors);
174  void FillHierarchyRoot(LabelSet& anchors);
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
vtkLabelHierarchy::Implementation::DropAnchor2
void DropAnchor2(vtkIdType anchor)
vtkLabelHierarchy::Implementation::PriorityComparator::operator()
bool operator()(const vtkIdType &a, const vtkIdType &b) const
Definition: vtkLabelHierarchyPrivate.h:59
vtkLabelHierarchy::Implementation::PriorityComparator::operator=
PriorityComparator & operator=(const PriorityComparator &rhs)
Definition: vtkLabelHierarchyPrivate.h:48
vtkLabelHierarchy::Implementation
Definition: vtkLabelHierarchyPrivate.h:11
vtkLabelHierarchy::Implementation::PriorityComparator::PriorityComparator
PriorityComparator(const PriorityComparator &src)
Definition: vtkLabelHierarchyPrivate.h:46
vtkLabelHierarchy::Implementation::HierarchyCursor3
octree< LabelSet >::cursor HierarchyCursor3
Definition: vtkLabelHierarchyPrivate.h:154
vtkLabelHierarchy::Implementation::DropAnchor3
void DropAnchor3(vtkIdType anchor)
vtkLabelHierarchy::Implementation::Hierarchy2
HierarchyType2 * Hierarchy2
Definition: vtkLabelHierarchyPrivate.h:181
vtkLabelHierarchy
contains an octree of labels
Definition: vtkLabelHierarchy.h:79
vtkLabelHierarchy::Implementation::~Implementation
~Implementation()
Definition: vtkLabelHierarchyPrivate.h:22
vtkDataSet::Center
double Center[3]
Definition: vtkDataSet.h:494
vtkLabelHierarchy::Implementation::SmudgeAnchor2
void SmudgeAnchor2(HierarchyCursor2 &cursor, vtkIdType anchor, double *x)
vtkIdType
int vtkIdType
Definition: vtkType.h:330
vtkLabelHierarchy::Implementation::LabelSet::GetLocalAnchorCount
vtkIdType GetLocalAnchorCount() const
Definition: vtkLabelHierarchyPrivate.h:141
vtkTimeStamp
record modification and/or execution time
Definition: vtkTimeStamp.h:32
vtkLabelHierarchy::Implementation::LabelSet::AddChildren
void AddChildren(octree< LabelSet, 2 >::octree_node_pointer self, LabelSet &emptyNode)
Definition: vtkLabelHierarchyPrivate.h:232
vtkLabelHierarchy::Implementation::ComparePriorities
bool ComparePriorities(vtkIdType a, vtkIdType b)
Definition: vtkLabelHierarchyPrivate.h:28
vtkLabelHierarchy::Implementation::HierarchyIterator2
octree< LabelSet, 2 >::iterator HierarchyIterator2
Definition: vtkLabelHierarchyPrivate.h:151
vtkX3D::length
Definition: vtkX3D.h:399
vtkLabelHierarchy::Implementation::LabelSet::Size
double Size
Definition: vtkLabelHierarchyPrivate.h:146
vtkX3D::center
Definition: vtkX3D.h:236
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtkLabelHierarchy::Implementation::LabelSet::SetChildGeometry
void SetChildGeometry(octree< LabelSet, 2 >::octree_node_pointer self)
Definition: vtkLabelHierarchyPrivate.h:201
vtkLabelHierarchy::Implementation::PrepareSortedAnchors
void PrepareSortedAnchors(LabelSet &anchors)
vtkLabelHierarchy::Implementation::HierarchyTime
vtkTimeStamp HierarchyTime
Definition: vtkLabelHierarchyPrivate.h:184
vtkLabelHierarchy::Implementation::RecursiveNodeDivide
void RecursiveNodeDivide(HierarchyCursor2 &cursor)
vtkLabelHierarchy::Implementation::LabelSet::Increment
void Increment()
Definition: vtkLabelHierarchyPrivate.h:140
vtkLabelHierarchy::Implementation::LabelSet::SetGeometry
void SetGeometry(const double center[3], double length)
Definition: vtkLabelHierarchyPrivate.h:191
vtkX3D::level
Definition: vtkX3D.h:401
vtkLabelHierarchy::Implementation::LabelSet::operator=
LabelSet & operator=(const LabelSet &rhs)
Definition: vtkLabelHierarchyPrivate.h:114
vtkLabelHierarchy::Implementation::ActualDepth
HierarchyType3::size_type ActualDepth
Definition: vtkLabelHierarchyPrivate.h:185
vtkLabelHierarchy::Implementation::LabelSet
Definition: vtkLabelHierarchyPrivate.h:78
vtkLabelHierarchy::Implementation::Hierarchy3
HierarchyType3 * Hierarchy3
Definition: vtkLabelHierarchyPrivate.h:183
vtkLabelHierarchy::Implementation::PriorityComparator::PriorityComparator
PriorityComparator(vtkLabelHierarchy *h)
Definition: vtkLabelHierarchyPrivate.h:44
vtkLabelHierarchy::Implementation::LabelSet::GetCenter
const double * GetCenter() const
Definition: vtkLabelHierarchyPrivate.h:128
vtkLabelHierarchy::Implementation::LabelSet::LabelSet
LabelSet(const LabelSet &src)
Definition: vtkLabelHierarchyPrivate.h:92
vtkLabelHierarchy::Implementation::Implementation
Implementation()
Definition: vtkLabelHierarchyPrivate.h:14
vtkLabelHierarchy::Implementation::LabelSet::GetTotalAnchorCount
vtkIdType GetTotalAnchorCount() const
Definition: vtkLabelHierarchyPrivate.h:142
vtkX3D::size
Definition: vtkX3D.h:259
vtkLabelHierarchy::Implementation::LabelSet::LabelSet
LabelSet(vtkLabelHierarchy *hierarchy)
Definition: vtkLabelHierarchyPrivate.h:81
vtkLabelHierarchy::Implementation::PriorityComparator::PriorityComparator
PriorityComparator()
Definition: vtkLabelHierarchyPrivate.h:38
vtkLabelHierarchy::Implementation::Husk
vtkLabelHierarchy * Husk
Definition: vtkLabelHierarchyPrivate.h:186
vtkLabelHierarchy::GetPriorities
virtual vtkDataArray * GetPriorities()
vtkLabelHierarchy::Implementation::BinAnchorsToLevel
void BinAnchorsToLevel(int level)
vtkLabelHierarchy::Implementation::PriorityComparator::Hierarchy
vtkLabelHierarchy * Hierarchy
Definition: vtkLabelHierarchyPrivate.h:36
vtkLabelHierarchy::Implementation::LabelSet::Insert
void Insert(vtkIdType anchor)
Definition: vtkLabelHierarchyPrivate.h:135
vtkLabelHierarchy::Implementation::LabelSet::Center
double Center[3]
Definition: vtkLabelHierarchyPrivate.h:145
vtkLabelHierarchy::Implementation::Current
static vtkLabelHierarchy * Current
Definition: vtkLabelHierarchyPrivate.h:188
vtkLabelHierarchy::Implementation::LabelSet::GetSize
double GetSize() const
Definition: vtkLabelHierarchyPrivate.h:129
vtkLabelHierarchy::Implementation::HierarchyIterator3
octree< LabelSet >::iterator HierarchyIterator3
Definition: vtkLabelHierarchyPrivate.h:155
vtkLabelHierarchy::Implementation::Z2
double Z2
Definition: vtkLabelHierarchyPrivate.h:180
vtkLabelHierarchy::Implementation::PromoteAnchors
void PromoteAnchors()
vtkLabelHierarchy::Implementation::HierarchyType3
octree< LabelSet > HierarchyType3
Definition: vtkLabelHierarchyPrivate.h:153
vtkLabelHierarchy::GetImplementation
Implementation * GetImplementation()
Definition: vtkLabelHierarchy.h:238
vtkLabelHierarchy::Implementation::SmudgeAnchor3
void SmudgeAnchor3(HierarchyCursor3 &cursor, vtkIdType anchor, double *x)
vtkLabelHierarchy::Implementation::PriorityComparator::~PriorityComparator
~PriorityComparator()=default
vtkLabelHierarchy::Implementation::LabelSet::LabelSet
LabelSet()
Definition: vtkLabelHierarchyPrivate.h:103
vtkLabelHierarchy::Implementation::HierarchyType2
octree< LabelSet, 2 > HierarchyType2
Definition: vtkLabelHierarchyPrivate.h:149
vtkLabelHierarchy::Implementation::PriorityComparator
Definition: vtkLabelHierarchyPrivate.h:34
vtkLabelHierarchy::Implementation::HierarchyCursor2
octree< LabelSet, 2 >::cursor HierarchyCursor2
Definition: vtkLabelHierarchyPrivate.h:150
vtkLabelHierarchy::Implementation::FillHierarchyRoot
void FillHierarchyRoot(LabelSet &anchors)
vtkLabelHierarchy::Implementation::DemoteAnchors
void DemoteAnchors(int level)
vtkLabelHierarchy::Implementation::LabelSet::TotalAnchors
vtkIdType TotalAnchors
Definition: vtkLabelHierarchyPrivate.h:144
vtkDataArray::GetTuple1
double GetTuple1(vtkIdType tupleIdx)
These methods are included as convenience for the wrappers.
h