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