File: vtkMultiGroupDataIterator.cxx

package info (click to toggle)
paraview 3.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 124,600 kB
  • ctags: 133,728
  • sloc: cpp: 958,817; ansic: 509,658; tcl: 45,787; xml: 23,401; python: 19,574; perl: 3,112; yacc: 1,787; java: 1,517; sh: 665; asm: 471; lex: 400; makefile: 168; objc: 28
file content (265 lines) | stat: -rw-r--r-- 7,634 bytes parent folder | download
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    $RCSfile: vtkMultiGroupDataIterator.cxx,v $

  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.

=========================================================================*/
#include "vtkMultiGroupDataIterator.h"

#include "vtkInformation.h"
#include "vtkMultiGroupDataInformation.h"
#include "vtkMultiGroupDataSet.h"
#include "vtkMultiGroupDataSetInternal.h"
#include "vtkObjectFactory.h"

vtkCxxRevisionMacro(vtkMultiGroupDataIterator, "$Revision: 1.3 $");
vtkStandardNewMacro(vtkMultiGroupDataIterator);

class vtkMultiGroupDataIteratorInternal
{
public:
  // We store two iterators.
  // DSIterator (DataSets) iterators over the groups
  // LDSIteator (GroupDataSets) iterates over the nodes in the current group
  vtkMultiGroupDataSetInternal::GroupDataSetsIterator LDSIterator;
  vtkMultiGroupDataSetInternal::DataSetsIterator DSIterator;

  vtkSmartPointer<vtkCompositeDataIterator> SubIterator;
};

//----------------------------------------------------------------------------
vtkMultiGroupDataIterator::vtkMultiGroupDataIterator()
{
  this->DataSet = 0;
  this->Internal = new vtkMultiGroupDataIteratorInternal;
}

//----------------------------------------------------------------------------
vtkMultiGroupDataIterator::~vtkMultiGroupDataIterator()
{
  this->SetDataSet(0);
  delete this->Internal;
}

//----------------------------------------------------------------------------
void vtkMultiGroupDataIterator::SetDataSet(vtkMultiGroupDataSet* dataset)
{
  if (this->DataSet != dataset)
    {
    if (this->DataSet) 
      { 
      this->DataSet->UnRegister(this); 
      }
    this->DataSet = dataset;
    if (this->DataSet) 
      { 
      this->DataSet->Register(this); 
      this->GoToFirstItem();
      }
    this->Modified();
    }   
}

//----------------------------------------------------------------------------
void vtkMultiGroupDataIterator::GoToFirstItem()
{
  if (!this->DataSet)
    {
    vtkErrorMacro("No data object has been set.");
    return;
    }
  // Initialize to the first group
  this->Internal->DSIterator = this->DataSet->Internal->DataSets.begin();
  if ( !this->DataSet->Internal->DataSets.empty() )
    {
    // Initialize to the first node in the first group
    this->Internal->LDSIterator = this->Internal->DSIterator->begin();
    if (this->Internal->LDSIterator == this->Internal->DSIterator->end())
      {
      this->GoToNextNonEmptyGroup();
      }
    // Skip nodes with NULL dataset pointers.
    if (!this->IsDoneWithTraversal())
      {
      vtkDataObject* cur = this->GetCurrentDataObject();
      if (!cur)
        {
        this->GoToNextItem();
        }
      else if (this->VisitOnlyLeaves && cur->IsA("vtkCompositeDataSet"))
        {
        this->Internal->SubIterator.TakeReference( 
          static_cast<vtkCompositeDataSet*>(cur)->NewIterator());
        this->Internal->SubIterator->GoToFirstItem();
        if (this->Internal->SubIterator->IsDoneWithTraversal())
          {
          this->Internal->SubIterator = 0;
          this->GoToNextItem();
          }
        }
      }
    }
}

//----------------------------------------------------------------------------
void vtkMultiGroupDataIterator::GoToNextNonEmptyGroup()
{
  if (!this->IsDoneWithTraversal())
    {
    while (1)
      {
      this->Internal->DSIterator++;
      if (this->IsDoneWithTraversal())
        {
        break;
        }
      this->Internal->LDSIterator = this->Internal->DSIterator->begin();
      if (this->Internal->LDSIterator != this->Internal->DSIterator->end())
        {
        break;
        }
      }
    }
}

//----------------------------------------------------------------------------
void vtkMultiGroupDataIterator::GoToNextItem()
{
  if (!this->DataSet)
    {
    vtkErrorMacro("No data object has been set.");
    return;
    }
  if (!this->IsDoneWithTraversal())
    {
    // In case the first group is empty
    if (this->Internal->LDSIterator == this->Internal->DSIterator->end())
      {
      this->GoToNextNonEmptyGroup();
      if (this->IsDoneWithTraversal())
        {
        return;
        }
      }

    if (this->Internal->SubIterator)
      {
      this->Internal->SubIterator->GoToNextItem();
      if (!this->Internal->SubIterator->IsDoneWithTraversal())
        {
        return;
        }
      this->Internal->SubIterator = 0;
      }

    this->Internal->LDSIterator++;
    if (this->Internal->LDSIterator == this->Internal->DSIterator->end())
      {
      this->GoToNextNonEmptyGroup();
      if (this->IsDoneWithTraversal())
        {
        return;
        }
      }
    // Skip nodes with NULL dataset pointers. If current dataset is
    // composite and VisitOnlyLeaves is on, go into the sub-dataset.
    vtkDataObject* cur = this->GetCurrentDataObject();
    if (!this->GetCurrentDataObject())
      {
      this->GoToNextItem();
      }
    else if (this->VisitOnlyLeaves && cur->IsA("vtkCompositeDataSet"))
      {
      this->Internal->SubIterator.TakeReference( 
        static_cast<vtkCompositeDataSet*>(cur)->NewIterator());
      this->Internal->SubIterator->GoToFirstItem();
      if (this->Internal->SubIterator->IsDoneWithTraversal())
        {
        this->Internal->SubIterator = 0;
        this->GoToNextItem();
        }
      }
    }
}

//----------------------------------------------------------------------------
int vtkMultiGroupDataIterator::IsDoneWithTraversal()
{
  if (!this->DataSet)
    {
    vtkErrorMacro("No data object has been set.");
    return 1;
    }

  if ( this->DataSet->Internal->DataSets.empty() || 
       this->Internal->DSIterator == this->DataSet->Internal->DataSets.end() )
    {
    return 1;
    }
  return 0;
}

//----------------------------------------------------------------------------
vtkInformation* vtkMultiGroupDataIterator::GetCurrentInformationObject()
{
  if ( !this->DataSet || this->DataSet->Internal->DataSets.empty() )
    {
    return 0;
    }
  if (this->Internal->SubIterator)
    {
    return this->Internal->SubIterator->GetCurrentInformationObject();
    }
  unsigned int group = 
    this->Internal->DSIterator - this->DataSet->Internal->DataSets.begin();
  unsigned int idx =
    this->Internal->LDSIterator - this->Internal->DSIterator->begin();

  vtkMultiGroupDataInformation* mgInfo =
    this->DataSet->GetMultiGroupDataInformation();
  if (!mgInfo)
    {
    return 0;
    }
  return mgInfo->GetInformation(group, idx);
}

//----------------------------------------------------------------------------
vtkDataObject* vtkMultiGroupDataIterator::GetCurrentDataObject()
{
  if ( !this->DataSet || this->DataSet->Internal->DataSets.empty() )
    {
    return 0;
    }
  if (this->Internal->SubIterator)
    {
    return this->Internal->SubIterator->GetCurrentDataObject();
    }
  return this->Internal->LDSIterator->GetPointer();
}

//----------------------------------------------------------------------------
void vtkMultiGroupDataIterator::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);

  os << indent << "DataSet: ";
  if (this->DataSet)
    {
    os << endl;
    this->DataSet->PrintSelf(os, indent.GetNextIndent());
    }
  else
    {
    os << "(none)" << endl;
    }
}