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{
13public:
15 {
16 this->Hierarchy2 = 0;
17 this->Hierarchy3 = 0;
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 (0 == this->Hierarchy)
72 {
73 vtkGenericWarningMacro( "error: NULL this->Hierarchy in PriorityComparator" );
74 return a < b;
75 }
76
77 if (0 == 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 this->size(); }
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()
176 void DemoteAnchors( int level );
179
180 // Description:
181 // Routines called by ComputeHierarchy()
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
208inline 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
223inline 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
237inline 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
243inline 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
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
double GetTuple1(vtkIdType tupleIdx)
These methods are included as convenience for the wrappers.
double Center[3]
Definition: vtkDataSet.h:496
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()
record modification and/or execution time
Definition: vtkTimeStamp.h:36
@ 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:287