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