File: vtkGeoTreeNodeCache.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 118,532 kB
  • ctags: 138,251
  • sloc: cpp: 1,443,749; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,127; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 471; makefile: 95; objc: 17
file content (168 lines) | stat: -rw-r--r-- 4,634 bytes parent folder | download | duplicates (13)
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkGeoTreeNodeCache.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
/*-------------------------------------------------------------------------
  Copyright 2008 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/

#include "vtkGeoTreeNodeCache.h"

#include "vtkGeoTreeNode.h"
#include "vtkObjectFactory.h"
#include "vtkSmartPointer.h"

vtkStandardNewMacro(vtkGeoTreeNodeCache);
//----------------------------------------------------------------------------
vtkGeoTreeNodeCache::vtkGeoTreeNodeCache()
{
  this->Oldest = 0;
  this->Newest = 0;
  this->Size = 0;
  this->CacheMaximumLimit = 500;
  this->CacheMinimumLimit = 250;
}

//----------------------------------------------------------------------------
vtkGeoTreeNodeCache::~vtkGeoTreeNodeCache()
{
  // Break reference loops by explicitly setting all prev/next pointers to null.
  vtkGeoTreeNode* cur;
  for (cur = this->Newest; cur; cur = cur->GetOlder())
    {
    cur->SetOlder(0);
    cur->SetNewer(0);
    }
}

//----------------------------------------------------------------------------
void vtkGeoTreeNodeCache::SendToFront(vtkGeoTreeNode* node)
{
  if (node == this->Newest)
    {
    return;
    }

  // Remove from the list if in the list already
  this->RemoveNode(node);

  // Add to the beginning of the list
  if (this->Size > 0)
    {
    node->SetNewer(0);
    node->SetOlder(this->Newest);
    this->Newest->SetNewer(node);
    this->Newest = node;
    }
  else
    {
    node->SetNewer(0);
    node->SetOlder(0);
    this->Newest = node;
    this->Oldest = node;
    }
  this->Size++;
  if (this->Size > this->CacheMaximumLimit)
    {
    this->TrimToCacheMinimum();
    }
}

//----------------------------------------------------------------------------
void vtkGeoTreeNodeCache::TrimToCacheMinimum()
{
  while (this->Size > this->CacheMinimumLimit)
    {
    vtkGeoTreeNode* node = this->Oldest;
    node->GetNewer()->SetOlder(0);
    this->Oldest = node->GetNewer();
    node->SetOlder(0);
    node->SetNewer(0);

    // If this was the last of a set of siblings to leave the list,
    // delete data from all siblings.
    this->DeleteDataFromSiblings(node);

    this->Size--;
    }
}

//----------------------------------------------------------------------------
void vtkGeoTreeNodeCache::DeleteDataFromSiblings(vtkGeoTreeNode* node)
{
  // Delete data from node or siblings if possible.
  vtkGeoTreeNode* parent = node->GetParentTreeNode();
  if (!parent)
    {
    return;
    }
  bool canDeleteSiblings = true;
  for (int c = 0; c < 4; ++c)
    {
    vtkGeoTreeNode* child = parent->GetChildTreeNode(c);
    if (!child || child->GetOlder() || child->GetNewer() || child == this->Newest)
      {
      canDeleteSiblings = false;
      break;
      }
    }
  if (canDeleteSiblings)
    {
    for (int c = 0; c < 4; ++c)
      {
      vtkGeoTreeNode* child = parent->GetChildTreeNode(c);
      child->DeleteData();
      }
    }
}

//----------------------------------------------------------------------------
void vtkGeoTreeNodeCache::RemoveNode(vtkGeoTreeNode* node)
{
  if (!node->GetNewer() && !node->GetOlder() && node != this->Newest)
    {
    // The node is not in the list
    return;
    }

  if (!node->GetNewer())
    {
    this->Newest = node->GetOlder();
    }
  else
    {
    node->GetNewer()->SetOlder(node->GetOlder());
    }
  if (!node->GetOlder())
    {
    this->Oldest = node->GetNewer();
    }
  else
    {
    node->GetOlder()->SetNewer(node->GetNewer());
    }
  node->SetOlder(0);
  node->SetNewer(0);
  this->Size--;
}

//----------------------------------------------------------------------------
void vtkGeoTreeNodeCache::PrintSelf(ostream & os, vtkIndent indent)
{
  this->Superclass::PrintSelf( os, indent );
  os << indent << "CacheMinimumLimit: " << this->CacheMinimumLimit << endl;
  os << indent << "CacheMaximumLimit: " << this->CacheMaximumLimit << endl;
  os << indent << "Size: " << this->Size << endl;
}