File: vtkUnstructuredGridCellIterator.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 118,972 kB
  • sloc: cpp: 1,442,790; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 68; objc: 17
file content (242 lines) | stat: -rw-r--r-- 8,099 bytes parent folder | download | duplicates (5)
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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkUnstructuredGridCellIterator.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.

=========================================================================*/

#include "vtkUnstructuredGridCellIterator.h"

#include "vtkCellArray.h"
#include "vtkIdList.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"
#include "vtkUnsignedCharArray.h"
#include "vtkUnstructuredGrid.h"

#include <cassert>

vtkStandardNewMacro(vtkUnstructuredGridCellIterator)

//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::PrintSelf(ostream &os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  // Cast the 'unsigned char*' members to void* to prevent the compiler from
  // interpreting them as strings.
  os << indent << "CellTypeBegin: "
     << static_cast<void*>(this->CellTypeBegin) << endl;
  os << indent << "CellTypePtr: "
     << static_cast<void*>(this->CellTypePtr) << endl;
  os << indent << "CellTypeEnd: "
     << static_cast<void*>(this->CellTypeEnd) << endl;
  os << indent << "ConnectivityBegin: " << this->ConnectivityBegin << endl;
  os << indent << "ConnectivityPtr: " << this->ConnectivityPtr << endl;
  os << indent << "FacesBegin: " << this->FacesBegin<< endl;
  os << indent << "FacesLocsBegin: " << this->FacesLocsBegin << endl;
  os << indent << "FacesLocsPtr: " << this->FacesLocsPtr << endl;
  os << indent << "SkippedCells: " << this->SkippedCells << endl;
  os << indent << "UnstructuredGridPoints: " <<
        this->UnstructuredGridPoints.GetPointer() << endl;
}

//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::SetUnstructuredGrid(
    vtkUnstructuredGrid *ug)
{
  // If the unstructured grid has not been initialized yet, these may not exist:
  vtkUnsignedCharArray *cellTypeArray = ug ? ug->GetCellTypesArray() : NULL;
  vtkCellArray *cellArray = ug ? ug->GetCells() : NULL;
  vtkPoints *points = ug ? ug->GetPoints() : NULL;

  if (ug && cellTypeArray && cellArray && points)
    {
    // Cell types
    this->CellTypeBegin = this->CellTypeEnd = this->CellTypePtr
        = cellTypeArray ? cellTypeArray->GetPointer(0) : NULL;
    this->CellTypeEnd += cellTypeArray ? cellTypeArray->GetNumberOfTuples() : 0;

    // CellArray
    this->ConnectivityBegin = this->ConnectivityPtr = cellArray->GetPointer();

    // Point
    this->UnstructuredGridPoints = points;

    // Faces
    vtkIdTypeArray *faces = ug->GetFaces();
    vtkIdTypeArray *facesLocs = ug->GetFaceLocations();
    if (faces && facesLocs)
      {
      this->FacesBegin = faces->GetPointer(0);
      this->FacesLocsBegin = this->FacesLocsPtr = facesLocs->GetPointer(0);
      }
    else
      {
      this->FacesBegin = NULL;
      this->FacesLocsBegin = NULL;
      this->FacesLocsPtr = NULL;
      }
    }
  else
    {
    this->CellTypeBegin = NULL;
    this->CellTypePtr = NULL;
    this->CellTypeEnd = NULL;
    this->FacesBegin = NULL;
    this->FacesLocsBegin = NULL;
    this->FacesLocsPtr = NULL;
    this->ConnectivityBegin= NULL;
    this->ConnectivityPtr = NULL;
    this->UnstructuredGridPoints = NULL;
    }

  this->SkippedCells = 0;
}

//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::CatchUpSkippedCells()
{
  // catch up on skipped cells -- cache misses make incrementing Connectivity
  // in IncrementToNextCell() too expensive, so we delay it until here. Special
  // cases are used for 0 or 1 skipped cells to reduce the number of jumps.
  switch (this->SkippedCells)
    {
    default:
      while (this->SkippedCells > 1)
        {
        this->ConnectivityPtr += *this->ConnectivityPtr + 1;
        this->SkippedCells--;
        }
      assert(this->SkippedCells == 1);
      VTK_FALLTHROUGH;
    case 1:
      this->ConnectivityPtr += *this->ConnectivityPtr + 1;
      --this->SkippedCells;
      VTK_FALLTHROUGH;
    case 0:
      // do nothing.
      break;
  }
}

//------------------------------------------------------------------------------
bool vtkUnstructuredGridCellIterator::IsDoneWithTraversal()
{
  return this->CellTypePtr >= this->CellTypeEnd;
}

//------------------------------------------------------------------------------
vtkIdType vtkUnstructuredGridCellIterator::GetCellId()
{
  return static_cast<vtkIdType>(this->CellTypePtr - this->CellTypeBegin);
}

//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::IncrementToNextCell()
{
  ++this->CellTypePtr;

  // Bookkeeping for ConnectivityPtr
  ++this->SkippedCells;

  // Note that we may be incrementing an invalid pointer here...check
  // if FacesLocsBegin is NULL before dereferencing this!
  ++this->FacesLocsPtr;
}

//------------------------------------------------------------------------------
vtkUnstructuredGridCellIterator::vtkUnstructuredGridCellIterator()
  : vtkCellIterator(),
    CellTypeBegin(NULL),
    CellTypePtr(NULL),
    CellTypeEnd(NULL),
    ConnectivityBegin(NULL),
    ConnectivityPtr(NULL),
    FacesBegin(NULL),
    FacesLocsBegin(NULL),
    FacesLocsPtr(NULL),
    SkippedCells(0),
    UnstructuredGridPoints(NULL)
{
}

//------------------------------------------------------------------------------
vtkUnstructuredGridCellIterator::~vtkUnstructuredGridCellIterator()
{
}

//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::ResetToFirstCell()
{
  this->CellTypePtr = this->CellTypeBegin;
  this->FacesLocsPtr = this->FacesLocsBegin;
  this->ConnectivityPtr = this->ConnectivityBegin;
  this->SkippedCells = 0;
}

//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::FetchCellType()
{
  this->CellType = *this->CellTypePtr;
}

//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::FetchPointIds()
{
  CatchUpSkippedCells();
  const vtkIdType *connPtr = this->ConnectivityPtr;
  vtkIdType numCellPoints = *(connPtr++);
  this->PointIds->SetNumberOfIds(numCellPoints);
  vtkIdType *cellPtr = this->PointIds->GetPointer(0);
  std::copy(connPtr, connPtr + numCellPoints, cellPtr);
}

//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::FetchPoints()
{
  this->UnstructuredGridPoints->GetPoints(this->GetPointIds(), this->Points);
}

//------------------------------------------------------------------------------
// Given a pointer into a set of faces, traverse the faces and return the total
// number of ids (including size hints) in the face set.
namespace {
inline vtkIdType FaceSetSize(vtkIdType *begin)
{
  vtkIdType *result = begin;
  vtkIdType numFaces = *(result++);
  while (numFaces-- > 0)
    {
    result += *result + 1;
    }
  return result - begin;
}
} // end anon namespace

//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::FetchFaces()
{
  // FacesLocsPtr may be non-null and invalid (this is done to prevent branching
  // in IncrementToNextCell()). Check FacesLocsBegin to determine validity of
  // the pointer.
  if (this->FacesLocsBegin && *this->FacesLocsPtr >= 0)
    {
    vtkIdType *faceSet = this->FacesBegin + *this->FacesLocsPtr;
    vtkIdType facesSize = FaceSetSize(faceSet);
    this->Faces->SetNumberOfIds(facesSize);
    vtkIdType *tmpPtr = this->Faces->GetPointer(0);
    std::copy(faceSet, faceSet + facesSize, tmpPtr);
    }
  else
    {
    this->Faces->SetNumberOfIds(0);
    }
}