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