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