vtkXMLStructuredDataReader.cxx 20.6 KB
Newer Older
1
2
3
4
5
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkXMLStructuredDataReader.cxx

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

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

=========================================================================*/
#include "vtkXMLStructuredDataReader.h"
16

Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
17
#include "vtkArrayIteratorIncludes.h"
18
19
#include "vtkDataArray.h"
#include "vtkDataSet.h"
20
21
#include "vtkInformation.h"
#include "vtkStreamingDemandDrivenPipeline.h"
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "vtkXMLDataElement.h"
#include "vtkXMLDataParser.h"


//----------------------------------------------------------------------------
vtkXMLStructuredDataReader::vtkXMLStructuredDataReader()
{
  this->PieceExtents = 0;
  this->PiecePointDimensions = 0;
  this->PiecePointIncrements = 0;
  this->PieceCellDimensions = 0;
  this->PieceCellIncrements = 0;
  this->WholeSlices = 1;
35
36
37
38
39
40
41
42
43

  // Initialize these in case someone calls GetNumberOfPoints or
  // GetNumberOfCells before UpdateInformation is called.
  this->PointDimensions[0] = 0;
  this->PointDimensions[1] = 0;
  this->PointDimensions[2] = 0;
  this->CellDimensions[0] = 0;
  this->CellDimensions[1] = 0;
  this->CellDimensions[2] = 0;
44

45
46
47
48
49
50
  this->WholeExtent[0] = 0;
  this->WholeExtent[1] = -1;
  this->WholeExtent[2] = 0;
  this->WholeExtent[3] = -1;
  this->WholeExtent[4] = 0;
  this->WholeExtent[5] = -1;
51
52
53
54
55
}

//----------------------------------------------------------------------------
vtkXMLStructuredDataReader::~vtkXMLStructuredDataReader()
{
56
  if (this->NumberOfPieces)
57
58
59
    {
    this->DestroyPieces();
    }
60
61
62
63
64
65
66
67
68
69
70
71
}

//----------------------------------------------------------------------------
void vtkXMLStructuredDataReader::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os, indent);
  os << indent << "WholeSlices: " << this->WholeSlices << "\n";
}

//----------------------------------------------------------------------------
int vtkXMLStructuredDataReader::ReadPrimaryElement(vtkXMLDataElement* ePrimary)
{
72
  // Get the whole extent attribute.
73
  int extent[6];
74
  if (ePrimary->GetVectorAttribute("WholeExtent", 6, extent) == 6)
75
    {
76
    memcpy(this->WholeExtent, extent, 6*sizeof(int));
77

78
    // Set the output's whole extent.
79
80
81
    vtkInformation* outInfo = this->GetCurrentOutputInformation();
    outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
        extent, 6);
82
83

    // Check each axis to see if it has cells.
84
    for (int a = 0; a < 3; ++a)
85
      {
86
      this->AxesEmpty[a] = (extent[2*a+1] > extent[2*a]) ? 0 : 1;
87
      }
88
89
90
91
92
93
    }
  else
    {
    vtkErrorMacro(<< this->GetDataSetName() << " element has no WholeExtent.");
    return 0;
    }
94
95

  return this->Superclass::ReadPrimaryElement(ePrimary);
96
97
}

98
99
100
101
102
103
104
105
106
//----------------------------------------------------------------------------
void vtkXMLStructuredDataReader::SetupOutputInformation(
  vtkInformation *outInfo)
{
  this->Superclass::SetupOutputInformation(outInfo);

  outInfo->Set(CAN_PRODUCE_SUB_EXTENT(), 1);
}

107
108
109
110
111
112
113
114
115
//----------------------------------------------------------------------------
void
vtkXMLStructuredDataReader::CopyOutputInformation(vtkInformation* outInfo,
                                                  int port)
{
  // Let the superclass copy information first.
  this->Superclass::CopyOutputInformation(outInfo, port);

  // All structured data has a whole extent.
116
  vtkInformation *localInfo =
117
118
    this->GetExecutive()->GetOutputInformation(port);
  if (localInfo->Has(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT()))
119
    {
120
121
    outInfo->CopyEntry(
      localInfo, vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
122
123
124
    }
}

125
126
127
//----------------------------------------------------------------------------
void vtkXMLStructuredDataReader::SetupEmptyOutput()
{
128
  this->GetCurrentOutput()->Initialize();
129
130
}

131
132
133
134
135
136
//----------------------------------------------------------------------------
void vtkXMLStructuredDataReader::SetupPieces(int numPieces)
{
  this->Superclass::SetupPieces(numPieces);
  this->PieceExtents = new int[numPieces*6];
  this->PiecePointDimensions = new int[numPieces*3];
137
  this->PiecePointIncrements = new vtkIdType[numPieces*3];
138
  this->PieceCellDimensions = new int[numPieces*3];
139
  this->PieceCellIncrements = new vtkIdType[numPieces*3];
140
141

  for (int i = 0; i < numPieces; ++i)
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
    {
    int* extent = this->PieceExtents + i*6;
    extent[0]=0; extent[1]=-1;
    extent[2]=0; extent[3]=-1;
    extent[4]=0; extent[5]=-1;
    }
}

//----------------------------------------------------------------------------
void vtkXMLStructuredDataReader::DestroyPieces()
{
  delete [] this->PieceExtents;
  delete [] this->PiecePointDimensions;
  delete [] this->PiecePointIncrements;
  delete [] this->PieceCellDimensions;
  delete [] this->PieceCellIncrements;
  this->PieceExtents = 0;
  this->PiecePointDimensions = 0;
  this->PiecePointIncrements = 0;
  this->PieceCellDimensions = 0;
  this->PieceCellIncrements = 0;
163
  this->Superclass::DestroyPieces();
164
165
166
167
168
}

//----------------------------------------------------------------------------
vtkIdType vtkXMLStructuredDataReader::GetNumberOfPoints()
{
169
170
171
  return (static_cast<vtkIdType>(this->PointDimensions[0]) *
          static_cast<vtkIdType>(this->PointDimensions[1]) *
          static_cast<vtkIdType>(this->PointDimensions[2]));
172
173
174
175
176
}

//----------------------------------------------------------------------------
vtkIdType vtkXMLStructuredDataReader::GetNumberOfCells()
{
177
178
179
  return (static_cast<vtkIdType>(this->CellDimensions[0]) *
          static_cast<vtkIdType>(this->CellDimensions[1]) *
          static_cast<vtkIdType>(this->CellDimensions[2]));
180
181
182
183
184
}

//----------------------------------------------------------------------------
int vtkXMLStructuredDataReader::ReadPiece(vtkXMLDataElement* ePiece)
{
185
  if (!this->Superclass::ReadPiece(ePiece))
186
187
188
    {
    return 0;
    }
189
  int* pieceExtent = this->PieceExtents + this->Piece * 6;
190

191
  // Read the extent of the piece.
192
  if (strcmp(ePiece->GetName(), "Piece") == 0)
193
    {
194
    if (!ePiece->GetAttribute("Extent"))
195
196
197
      {
      vtkErrorMacro("Piece has no extent.");
      }
198
    if (ePiece->GetVectorAttribute("Extent", 6, pieceExtent) < 6)
199
200
201
202
203
      {
      vtkErrorMacro("Extent attribute is not 6 integers.");
      return 0;
      }
    }
204
  else if (ePiece->GetVectorAttribute("WholeExtent", 6, pieceExtent) < 6)
205
206
207
208
    {
    vtkErrorMacro("WholeExtent attribute is not 6 integers.");
    return 0;
    }
209

210
  // Compute the dimensions and increments for this piece's extent.
211
212
213
214
215
216
217
218
219
  int* piecePointDimensions =
    this->PiecePointDimensions + this->Piece * 3;
  vtkIdType* piecePointIncrements =
    this->PiecePointIncrements + this->Piece * 3;
  int* pieceCellDimensions =
    this->PieceCellDimensions + this->Piece * 3;
  vtkIdType* pieceCellIncrements =
    this->PieceCellIncrements + this->Piece * 3;

220
221
222
223
  this->ComputePointDimensions(pieceExtent, piecePointDimensions);
  this->ComputePointIncrements(pieceExtent, piecePointIncrements);
  this->ComputeCellDimensions(pieceExtent, pieceCellDimensions);
  this->ComputeCellIncrements(pieceExtent, pieceCellIncrements);
224

225
226
227
228
229
230
231
  return 1;
}

//----------------------------------------------------------------------------
void vtkXMLStructuredDataReader::ReadXMLData()
{
  // Get the requested Update Extent.
232
233
234
  vtkInformation* outInfo = this->GetCurrentOutputInformation();
  outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(),
      this->UpdateExtent);
235

236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
  // For debugging
  /*
  int numPieces = outInfo->Get(
    vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES());
  int piece = outInfo->Get(
    vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER());
  int numGhosts = outInfo->Get(
    vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS());

  if (piece == 0)
    {
    cout << "Piece:" << piece << " " << numPieces << " " << numGhosts << endl;
    cout << "Extent: "
         << this->UpdateExtent[0] << " "
         << this->UpdateExtent[1] << " "
         << this->UpdateExtent[2] << " "
         << this->UpdateExtent[3] << " "
         << this->UpdateExtent[4] << " "
         << this->UpdateExtent[5] << endl;
    }
  */

258
  vtkDebugMacro("Updating extent "
259
260
261
    << this->UpdateExtent[0] << " " << this->UpdateExtent[1] << " "
    << this->UpdateExtent[2] << " " << this->UpdateExtent[3] << " "
    << this->UpdateExtent[4] << " " << this->UpdateExtent[5] << "\n");
262

263
  // Prepare increments for the update extent.
264
265
266
267
  this->ComputePointDimensions(this->UpdateExtent, this->PointDimensions);
  this->ComputePointIncrements(this->UpdateExtent, this->PointIncrements);
  this->ComputeCellDimensions(this->UpdateExtent, this->CellDimensions);
  this->ComputeCellIncrements(this->UpdateExtent, this->CellIncrements);
268

269
270
  // Let superclasses read data.  This also allocates output data.
  this->Superclass::ReadXMLData();
271

272
273
  // Split current progress range based on fraction contributed by
  // each piece.
274
  float progressRange[2] = { 0.f, 0.f };
275
  this->GetProgressRange(progressRange);
276

277
278
279
280
  // Calculate the cumulative fraction of data contributed by each
  // piece (for progress).
  float* fractions = new float[this->NumberOfPieces+1];
  fractions[0] = 0;
281
  for (int i = 0; i < this->NumberOfPieces; ++i)
282
283
    {
    int* pieceExtent = this->PieceExtents + i*6;
284
285
    int pieceDims[3] = {0,0,0};
    // Intersect the extents to get the part we need to read.
286
287
    if (this->IntersectExtents(
      pieceExtent, this->UpdateExtent, this->SubExtent))
288
      {
289
      this->ComputePointDimensions(this->SubExtent, pieceDims);
290
291
      fractions[i+1] =
        fractions[i] + pieceDims[0] * pieceDims[1] * pieceDims[2];
292
      }
293
294
295
296
    else
      {
      fractions[i+1] = 0;
      }
297
    }
298
  if (fractions[this->NumberOfPieces] == 0)
299
300
301
    {
    fractions[this->NumberOfPieces] = 1;
    }
302
  for (int i = 1;i <= this->NumberOfPieces; ++i)
303
304
305
    {
    fractions[i] = fractions[i] / fractions[this->NumberOfPieces];
    }
306

307
  // Read the data needed from each piece.
308
309
  for (int i = 0;
    (i < this->NumberOfPieces && !this->AbortExecute && !this->DataError); ++i)
310
311
    {
    // Set the range of progress for this piece.
312
    this->SetProgressRange(progressRange, i, fractions);
313

314
    // Intersect the extents to get the part we need to read.
315
316
    int* pieceExtent = this->PieceExtents + i * 6;
    if (this->IntersectExtents(pieceExtent, this->UpdateExtent,
317
318
319
                              this->SubExtent))
      {
      vtkDebugMacro("Reading extent "
320
321
322
323
        << this->SubExtent[0] << " " << this->SubExtent[1] << " "
        << this->SubExtent[2] << " " << this->SubExtent[3] << " "
        << this->SubExtent[4] << " " << this->SubExtent[5]
        << " from piece " << i);
324

325
326
      this->ComputePointDimensions(this->SubExtent, this->SubPointDimensions);
      this->ComputeCellDimensions(this->SubExtent, this->SubCellDimensions);
327

328
      // Read the data from this piece.
329
      if (!this->ReadPieceData(i))
330
331
332
333
        {
        // An error occurred while reading the piece.
        this->DataError = 1;
        }
334
335
      }
    }
336

337
  delete [] fractions;
338

339
  // We filled the exact update extent in the output.
340
  this->SetOutputExtent(this->UpdateExtent);
341
342
343
344
}

//----------------------------------------------------------------------------
int vtkXMLStructuredDataReader::ReadArrayForPoints(vtkXMLDataElement* da,
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
345
                                                   vtkAbstractArray* outArray)
346
347
348
{
  int* pieceExtent = this->PieceExtents + this->Piece*6;
  int* piecePointDimensions = this->PiecePointDimensions + this->Piece*3;
349
  vtkIdType* piecePointIncrements = this->PiecePointIncrements + this->Piece*3;
350
  if (!this->ReadSubExtent(pieceExtent, piecePointDimensions,
351
352
353
354
355
356
                          piecePointIncrements, this->UpdateExtent,
                          this->PointDimensions, this->PointIncrements,
                          this->SubExtent, this->SubPointDimensions,
                          da, outArray))
    {
    vtkErrorMacro("Error reading extent "
357
358
359
360
      << this->SubExtent[0] << " " << this->SubExtent[1] << " "
      << this->SubExtent[2] << " " << this->SubExtent[3] << " "
      << this->SubExtent[4] << " " << this->SubExtent[5]
      << " from piece " << this->Piece);
361
362
363
364
365
366
367
    return 0;
    }
  return 1;
}

//----------------------------------------------------------------------------
int vtkXMLStructuredDataReader::ReadArrayForCells(vtkXMLDataElement* da,
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
368
                                                  vtkAbstractArray* outArray)
369
370
371
{
  int* pieceExtent = this->PieceExtents + this->Piece*6;
  int* pieceCellDimensions = this->PieceCellDimensions + this->Piece*3;
372
  vtkIdType* pieceCellIncrements = this->PieceCellIncrements + this->Piece*3;
373
  if (!this->ReadSubExtent(pieceExtent, pieceCellDimensions,
374
375
376
377
378
379
                          pieceCellIncrements, this->UpdateExtent,
                          this->CellDimensions, this->CellIncrements,
                          this->SubExtent, this->SubCellDimensions,
                          da, outArray))
    {
    vtkErrorMacro("Error reading extent "
380
381
382
383
      << this->SubExtent[0] << " " << this->SubExtent[1] << " "
      << this->SubExtent[2] << " " << this->SubExtent[3] << " "
      << this->SubExtent[4] << " " << this->SubExtent[5]
      << " from piece " << this->Piece);
384
385
386
387
388
    return 0;
    }
  return 1;
}

Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
389
390
//----------------------------------------------------------------------------
template <class iterT>
391
void vtkXMLStructuredDataReaderSubExtentCopyValues(
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
392
393
394
395
396
397
398
399
400
401
402
  iterT* destIter, vtkIdType destIndex,
  iterT* srcIter, vtkIdType srcIndex,
  vtkIdType numValues)
{
  // for all contiguous fixed-size arrays ie. vtkDataArray.
  memcpy(destIter->GetArray()->GetVoidPointer(destIndex),
    srcIter->GetArray()->GetVoidPointer(srcIndex),
    numValues);
}
//----------------------------------------------------------------------------
VTK_TEMPLATE_SPECIALIZE
403
void vtkXMLStructuredDataReaderSubExtentCopyValues(
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
404
405
406
407
408
  vtkArrayIteratorTemplate<vtkStdString>* destIter, vtkIdType destIndex,
  vtkArrayIteratorTemplate<vtkStdString>* srcIter, vtkIdType srcIndex,
  vtkIdType numValues)
{
  vtkIdType maxIndex = destIndex + numValues;
409
  for (vtkIdType cc = destIndex; cc < maxIndex; ++cc)
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
410
411
412
413
414
415
    {
    destIter->GetValue(cc) =
      srcIter->GetValue(srcIndex++);
    }
}

416
//----------------------------------------------------------------------------
417
418
419
420
421
int vtkXMLStructuredDataReader::ReadSubExtent(
  int* inExtent, int* inDimensions, vtkIdType* inIncrements,
  int* outExtent, int* outDimensions, vtkIdType* outIncrements,
  int* subExtent, int* subDimensions, vtkXMLDataElement* da,
  vtkAbstractArray* array)
422
{
423
  int components = array->GetNumberOfComponents();
424

425
  if ((inDimensions[0] == outDimensions[0]) &&
426
427
428
429
     (subDimensions[0] == outDimensions[0]) &&
     (inDimensions[1] == outDimensions[1]) &&
     (subDimensions[1] == outDimensions[1])
    )
430
    {
431
432
433
    if ((inDimensions[2] == outDimensions[2]) &&
        (subDimensions[2] == outDimensions[2])
      )
434
      {
435
436
      // Read the whole volume at once.  This fills the array's entire
      // progress range.
437
      vtkIdType volumeTuples =
438
439
440
        (static_cast<vtkIdType>(inDimensions[0])*
         static_cast<vtkIdType>(inDimensions[1])*
         static_cast<vtkIdType>(inDimensions[2]));
441
442
443
444
445
446
447
448

      vtkIdType sourceTuple =
        this->GetStartTuple(inExtent, inIncrements,
                            subExtent[0], subExtent[2], subExtent[4]);
      vtkIdType destTuple =
        this->GetStartTuple(outExtent, outIncrements,
                            subExtent[0], subExtent[2], subExtent[4]);

449
      if (!this->ReadArrayValues(da, destTuple*components, array,
450
          sourceTuple*components, volumeTuples*components))
451
452
453
454
455
456
        {
        return 0;
        }
      }
    else
      {
457
458
      // Read an entire slice at a time.  Split progress range by
      // slice.
459
      float progressRange[2] = { 0.f, 0.f };
460
      this->GetProgressRange(progressRange);
461
462
463
464
      vtkIdType sliceTuples =
        static_cast<vtkIdType>(inDimensions[0])*
        static_cast<vtkIdType>(inDimensions[1]);

465
      for (int k = 0; k < subDimensions[2] && !this->AbortExecute; ++k)
466
        {
467
        // Calculate the starting tuples for source and destination.
468
        vtkIdType sourceTuple =
469
470
          this->GetStartTuple(inExtent, inIncrements,
                              subExtent[0], subExtent[2], subExtent[4]+k);
471
        vtkIdType destTuple =
472
473
          this->GetStartTuple(outExtent, outIncrements,
                              subExtent[0], subExtent[2], subExtent[4]+k);
474

475
476
        // Set the range of progress for this slice.
        this->SetProgressRange(progressRange, k, subDimensions[2]);
477

478
        // Read the slice.
479
        if (!this->ReadArrayValues(da, destTuple*components, array,
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
480
            sourceTuple*components, sliceTuples*components))
481
482
483
484
485
486
487
488
          {
          return 0;
          }
        }
      }
    }
  else
    {
489
    if (!this->WholeSlices)
490
      {
491
      // Read a row at a time.  Split progress range by row.
492
      float progressRange[2] = { 0.f, 0.f };
493
      this->GetProgressRange(progressRange);
494
      vtkIdType rowTuples = subDimensions[0];
495
      for (int k = 0; k < subDimensions[2] && !this->AbortExecute; ++k)
496
        {
497
        for (int j = 0;j < subDimensions[1] && !this->AbortExecute; ++j)
498
          {
499
          // Calculate the starting tuples for source and destination.
500
          vtkIdType sourceTuple =
501
502
            this->GetStartTuple(inExtent, inIncrements,
                                subExtent[0], subExtent[2]+j, subExtent[4]+k);
503
          vtkIdType destTuple =
504
505
            this->GetStartTuple(outExtent, outIncrements,
                                subExtent[0], subExtent[2]+j, subExtent[4]+k);
506

507
508
509
          // Set the range of progress for this row.
          this->SetProgressRange(progressRange, subDimensions[1]*k+j,
                                 subDimensions[2]*subDimensions[1]);
510

511
          // Read the row.
512
          if (!this->ReadArrayValues(da, destTuple*components,
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
513
514
              array, sourceTuple*components,
              rowTuples*components))
515
516
517
518
519
520
521
522
            {
            return 0;
            }
          }
        }
      }
    else
      {
523
524
      // Read in each slice and copy the needed rows from it.  Split
      // progress range by slice.
525
      float progressRange[2] = { 0.f, 0.f };
526
      this->GetProgressRange(progressRange);
527
      vtkIdType rowTuples = subDimensions[0];
528
529
530
      vtkIdType partialSliceTuples =
        static_cast<vtkIdType>(inDimensions[0]) *
        static_cast<vtkIdType>(subDimensions[1]);
531
      int tupleSize = components*array->GetDataTypeSize();
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
532
      vtkAbstractArray* temp = array->NewInstance();
533
      temp->SetNumberOfComponents(array->GetNumberOfComponents());
534
      temp->SetNumberOfTuples(partialSliceTuples);
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
535
536
537
      vtkArrayIterator* srcIter = temp->NewIterator();
      vtkArrayIterator* destIter = array->NewIterator();

538
      for (int k = 0; k < subDimensions[2] && !this->AbortExecute; ++k)
539
        {
540
        // Calculate the starting tuple from the input.
541
        vtkIdType inTuple =
542
          this->GetStartTuple(inExtent, inIncrements,
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
543
            inExtent[0], subExtent[2], subExtent[4]+k);
544
545
546
547
548
549
550
        int memExtent[6];
        memExtent[0] = inExtent[0];
        memExtent[1] = inExtent[1];
        memExtent[2] = subExtent[2];
        memExtent[3] = subExtent[3];
        memExtent[4] = subExtent[4]+k;
        memExtent[5] = subExtent[4]+k;
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
551

552
553
        // Set the range of progress for this slice.
        this->SetProgressRange(progressRange, k, subDimensions[2]);
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
554

555
        // Read the slice.
556
        if (!this->ReadArrayValues(da, 0, temp, inTuple*components,
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
557
            partialSliceTuples*components))
558
559
560
561
          {
          temp->Delete();
          return 0;
          }
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
562
563
564
        // since arrays have changed, reinit the iters.
        destIter->Initialize(array);
        srcIter->Initialize(temp);
565
        // Copy the portion of the slice we need.
566
        for (int j = 0;j < subDimensions[1]; ++j)
567
          {
568
          vtkIdType sourceTuple =
569
            this->GetStartTuple(memExtent, inIncrements,
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
570
              subExtent[0], subExtent[2]+j, subExtent[4]+k);
571
          vtkIdType destTuple =
572
            this->GetStartTuple(outExtent, outIncrements,
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
573
574
575
576
577
578
              subExtent[0], subExtent[2]+j, subExtent[4]+k);

          switch (array->GetDataType())
            {
            vtkArrayIteratorTemplateMacro(
              vtkXMLStructuredDataReaderSubExtentCopyValues(
579
                static_cast<VTK_TT*>(destIter),
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
580
                destTuple*components,
581
                static_cast<VTK_TT*>(srcIter),
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
582
583
584
585
                sourceTuple*components, tupleSize*rowTuples));
          default:
            vtkErrorMacro("Array not supported : " << array->GetDataTypeAsString());
            break;
586
            }
587
588
          }
        }
Utkarsh Ayachit's avatar
ENH:    
Utkarsh Ayachit committed
589
590
      srcIter->Delete();
      destIter->Delete();
591
592
593
594
595
      temp->Delete();
      }
    }
  return 1;
}