vtkXdmfReader.cxx 90.9 KB
Newer Older
1
/*=========================================================================
Jerry Clarke's avatar
Jerry Clarke committed
2

3
4
5
6
7
  Program:   Visualization Toolkit
  Module:    vtkXdmfReader.cxx
  Language:  C++
  Date:      $Date$
  Version:   $Revision$
Jerry Clarke's avatar
Jerry Clarke committed
8
9


Berk Geveci's avatar
Berk Geveci committed
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
  Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen  
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.

  * Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
  of any contributors may be used to endorse or promote products derived
  from this software without specific prior written permission.

  * Modified source versions must be plainly marked as such, and must not be
  misrepresented as being the original software.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

  =========================================================================*/
Andy Cedilnik's avatar
Andy Cedilnik committed
42
#include "vtkXdmfReader.h"
43
44
45
46
47

#include "vtkCallbackCommand.h"
#include "vtkDataArraySelection.h"
#include "vtkDataSet.h"
#include "vtkDoubleArray.h"
48
49
#include "vtkInformation.h"
#include "vtkInformationVector.h"
50
51
#include "vtkObjectFactory.h"
#include "vtkRectilinearGrid.h"
52
#include "vtkStreamingDemandDrivenPipeline.h"
53
54
55
#include "vtkStructuredGrid.h"
#include "vtkUnstructuredGrid.h"
#include "vtkXdmfDataArray.h"
56
57
58
59
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkCell.h"
#include "vtkCellArray.h"
60
#include "vtkCharArray.h"
61
#include "vtkXMLParser.h"
62
#include "vtkImageData.h"
63
#include "vtkUniformGrid.h"
64
#include "vtkMultiGroupDataInformation.h"
65
66
#include "vtkMultiGroupDataSet.h"
// #include "vtkHierarchicalDataSet.h"
67
68
#include "vtkCompositeDataPipeline.h"
#include "vtkMultiProcessController.h"
69

70
#include "XdmfArray.h"
Jerry Clarke's avatar
Jerry Clarke committed
71
#include "XdmfAttribute.h"
72
73
#include "XdmfDOM.h"
#include "XdmfDataDesc.h"
Jerry Clarke's avatar
Jerry Clarke committed
74
#include "XdmfDataItem.h"
75
#include "XdmfGrid.h"
Jerry Clarke's avatar
Jerry Clarke committed
76
#include "XdmfTopology.h"
Andy Cedilnik's avatar
Andy Cedilnik committed
77
#include "XdmfGeometry.h"
Jerry Clarke's avatar
Jerry Clarke committed
78

79
#include <sys/stat.h>
80
81
#include <vtkstd/set>
#include <vtkstd/map>
82
83
#include <vtkstd/string>
#include <vtkstd/vector>
84
85
86
#include <assert.h>

#define USE_IMAGE_DATA // otherwise uniformgrid
Jerry Clarke's avatar
Jerry Clarke committed
87

Andy Cedilnik's avatar
Andy Cedilnik committed
88
vtkStandardNewMacro(vtkXdmfReader);
Amy Squillacote's avatar
Amy Squillacote committed
89
vtkCxxRevisionMacro(vtkXdmfReader, "1.22");
90
91

vtkCxxSetObjectMacro(vtkXdmfReader,Controller,vtkMultiProcessController);
92
93
94
95
96
97
98
99

#if defined(_WIN32) && (defined(_MSC_VER) || defined(__BORLANDC__))
#  include <direct.h>
#  define GETCWD _getcwd
#else
#include <unistd.h>
#  define GETCWD getcwd
#endif
Jerry Clarke's avatar
Jerry Clarke committed
100
101


102
103
104
#define vtkMAX(x, y) (((x)>(y))?(x):(y))
#define vtkMIN(x, y) (((x)<(y))?(x):(y))

105
106
#define PRINT_EXTENT(x) "[" << (x)[0] << " " << (x)[1] << " " << (x)[2] << " " << (x)[3] << " " << (x)[4] << " " << (x)[5] << "]" 

107
108
109
110
111
112
113
//----------------------------------------------------------------------------
class vtkXdmfReaderGrid
{
public:
  vtkXdmfReaderGrid() : XMGrid(0), DataDescription(0) {}
  ~vtkXdmfReaderGrid()
    {
Berk Geveci's avatar
Berk Geveci committed
114
      delete this->XMGrid;
115
116
117
118
119
    }

  XdmfGrid       *XMGrid;
  XdmfDataDesc   *DataDescription;
  vtkstd::string Name;
120
  int Level;
121
122
123
124
125
126
};

//----------------------------------------------------------------------------
class vtkXdmfReaderGridCollection
{
public:
127
128
  vtkXdmfReaderGrid* GetXdmfGrid(const char* gridName,
                                 int level);
129
130
131

  typedef vtkstd::map<vtkstd::string, vtkXdmfReaderGrid*> SetOfGrids;
  SetOfGrids Grids;
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
  // Update number of levels and number of datasets.
  void UpdateCounts();
  
  // Return the last number of levels computed by UpdateCounts.
  int GetNumberOfLevels()
    {
      return this->NumberOfLevels;
    }
  // Return the last number of dataset for a given level
  // computed by UpdateCounts.
  int GetNumberOfDataSets(int level)
    {
      assert("pre: valid_level" && level>=0 && level<GetNumberOfLevels());
      return this->NumberOfDataSets[level];
    }
  
protected:
  int NumberOfLevels;
  vtkstd::vector<int> NumberOfDataSets;
151
152
153
};

//----------------------------------------------------------------------------
154
vtkXdmfReaderGrid* vtkXdmfReaderGridCollection::GetXdmfGrid(
155
156
  const char *gridName,
  int level)
157
158
159
160
161
162
{
  vtkXdmfReaderGridCollection::SetOfGrids::iterator it = this->Grids.find(gridName);
  if ( it == this->Grids.end() || it->second == 0 )
    {
    this->Grids[gridName] = new vtkXdmfReaderGrid;
    }
163
  this->Grids[gridName]->Level=level;
164
165
166
  return this->Grids[gridName];
}

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
//----------------------------------------------------------------------------
void vtkXdmfReaderGridCollection::UpdateCounts()
{
  // Update the number of levels.
  vtkXdmfReaderGridCollection::SetOfGrids::iterator it;
  vtkXdmfReaderGridCollection::SetOfGrids::iterator itEnd;
  
  int maxLevel=0;
  it=this->Grids.begin();
  itEnd=this->Grids.end();
  while(it!=itEnd)
    {
    int level=it->second->Level;
    if(level>maxLevel)
      {
      maxLevel=level;
      }
    ++it;
    }
  this->NumberOfLevels=maxLevel+1;
  this->NumberOfDataSets.resize(this->NumberOfLevels);
 
  // Update the number of datasets
  int l=this->NumberOfLevels;
  int i=0;
  while(i<l)
    {
    this->NumberOfDataSets[i]=0;
    ++i;
    }
  
  it=this->Grids.begin();
  while(it!=itEnd)
    {
    int level=it->second->Level;
    ++this->NumberOfDataSets[level];
    ++it;
    }
}

207
208
209
210
211
212
213
214
215
216
217
218
//----------------------------------------------------------------------------
class vtkXdmfReaderActualGrid
{
public:
  vtkXdmfReaderActualGrid() : Enabled(0), Grid(0), Collection(0) {}

  int Enabled;
  vtkXdmfReaderGrid* Grid;
  vtkXdmfReaderGridCollection* Collection;
};

//----------------------------------------------------------------------------
Andy Cedilnik's avatar
Andy Cedilnik committed
219
class vtkXdmfReaderInternal
220
221
{
public:
222
223
  vtkXdmfReaderInternal()
    {
Berk Geveci's avatar
Berk Geveci committed
224
225
226
      this->DataItem = 0;
      this->ArrayConverter = vtkXdmfDataArray::New();
      this->NumberOfEnabledActualGrids=0;
227
228
229
    }
  ~vtkXdmfReaderInternal()
    {
Berk Geveci's avatar
Berk Geveci committed
230
231
232
233
234
235
236
237
238
      if ( this->DataItem )
        {
        // cout << "....Deleting DataItem " << this->DataItem << endl;
        delete this->DataItem;
        // cout << "....Back from Deleting DataItem " << this->DataItem << endl;
        this->DataItem = 0;
        }
      this->ArrayConverter->Delete();
      this->ArrayConverter = 0;
239
240
    }

241
  typedef vtkstd::vector<vtkstd::string> StringListType;
242
243
  StringListType DomainList;
  XdmfXmlNode DomainPtr;
244
245

  int RequestSingleGridData(const char* currentGridName,
246
247
                            vtkXdmfReaderGrid *grid,
                            vtkInformation *outInfo,
248
249
                            vtkDataObject *output,
                            int isSubBlock);
250
251
252
253
  
  int RequestActualGridData(const char* currentGridName,
                            vtkXdmfReaderActualGrid* currentActualGrid,
                            int outputGrid,
254
                            int numberOfGrids,
255
256
257
258
259
260
261
262
                            vtkInformationVector *outputVector);
  
  // outInfo is null in the  multi-block case.
  int RequestSingleGridInformation(vtkXdmfReaderGrid *grid,
                                   vtkInformation *outInfo);

  int RequestActualGridInformation(vtkXdmfReaderActualGrid* currentActualGrid,
                                   int outputGrid,
Berk Geveci's avatar
Berk Geveci committed
263
                                   int numberOfGrids,
264
265
266
                                   vtkInformationVector* outputVector);
  
  typedef vtkstd::map<vtkstd::string,vtkXdmfReaderActualGrid> MapOfActualGrids;
267
  MapOfActualGrids ActualGrids;
268
269
  int NumberOfEnabledActualGrids;
  
270
271
272
  vtkXdmfReaderGridCollection* GetCollection(const char* collectionName);
  vtkXdmfReaderActualGrid* GetGrid(const char* gridName);
  vtkXdmfReaderActualGrid* GetGrid(int idx);
273
  vtkXdmfReaderGrid *GetXdmfGrid(const char *gridName,
274
275
                                 const char *collectionName,
                                 const char *levelName);
276
277

  vtkXdmfReader* Reader;
Jerry Clarke's avatar
Jerry Clarke committed
278
  XdmfDataItem *DataItem;
279
280
281

  // For converting arrays from XDMF to VTK format
  vtkXdmfDataArray *ArrayConverter;
282
283
};

284
//----------------------------------------------------------------------------
285
286
vtkXdmfReaderGridCollection* vtkXdmfReaderInternal::GetCollection(
  const char* collectionName)
287
288
289
290
291
{
  if ( !collectionName )
    {
    return 0;
    }
292

293
  vtkXdmfReaderActualGrid* actualGrid = &this->ActualGrids[collectionName];
294

295
296
297
298
299
300
301
302
303
  if ( !actualGrid->Collection )
    {
    if ( actualGrid->Grid )
      {
      cerr << "Trying to create collection with the same name as an existing grid" << endl;
      return 0;
      }
    actualGrid->Collection = new vtkXdmfReaderGridCollection;
    }
304

305
306
307
308
  return actualGrid->Collection;
}

//----------------------------------------------------------------------------
309
vtkXdmfReaderGrid* vtkXdmfReaderInternal::GetXdmfGrid(
310
311
312
  const char *gridName,
  const char *collectionName,
  const char *levelName)
313
314
315
316
317
318
319
320
{
  if ( !gridName )
    {
    return 0;
    }

  if ( collectionName )
    {
321
    vtkXdmfReaderGridCollection *collection=this->GetCollection(collectionName);
322
323
324
325
    if ( !collection )
      {
      return 0;
      }
326
327
328
329
330
331
332
    int level;
    if(levelName==0)
      {
      level=0;
      }
    else
      {
333
334
335
      char *tmp=new char[strlen(levelName)+1];
      strcpy(tmp,levelName);
      istrstream s(tmp,strlen(tmp));
336
337
338
      s>>level;
      if(level<0)
        {
339
340
        cerr << "Expect a positive Level value, level=" << level <<endl;
        delete[] tmp;
341
342
        return 0;
        }
343
344
345
346
      else
        {
        delete[] tmp;
        }
347
348
      }
    return collection->GetXdmfGrid(gridName,level);
349
350
351
352
353
354
355
356
    }

  vtkXdmfReaderActualGrid* grid = this->GetGrid(gridName);
  if ( grid->Collection )
    {
    cerr << "Trying to create a grid with the same name as an existing collection" << endl;
    return 0;
    }
357
  grid->Grid = new vtkXdmfReaderGrid; 
358
359
360
361
362
363
364
365
366
367
368
369
  return grid->Grid;
}

//----------------------------------------------------------------------------
vtkXdmfReaderActualGrid* vtkXdmfReaderInternal::GetGrid(const char* gridName)
{
  return &this->ActualGrids[gridName];
}

//----------------------------------------------------------------------------
vtkXdmfReaderActualGrid* vtkXdmfReaderInternal::GetGrid(int idx)
{
370
371
372
373
  if ( idx < 0 )
    {
    return 0;
    }
374
375
376
  vtkXdmfReaderInternal::MapOfActualGrids::iterator it;
  int cnt = 0;
  for ( it = this->ActualGrids.begin();
Berk Geveci's avatar
Berk Geveci committed
377
378
        it != this->ActualGrids.end();
        ++ it )
379
380
381
382
383
384
385
386
387
388
    {
    if ( cnt == idx )
      {
      return &it->second;
      }
    cnt ++;
    }
  return 0;
}

389
//----------------------------------------------------------------------------
Andy Cedilnik's avatar
Andy Cedilnik committed
390
vtkXdmfReader::vtkXdmfReader()
391
{
392
393
//this->SetNumberOfInputPorts(0);
//this->SetNumberOfOutputPorts(0);
394
  
Andy Cedilnik's avatar
Andy Cedilnik committed
395
  this->Internals = new vtkXdmfReaderInternal;
396
  this->Internals->Reader = this;
397

398
399
400
  // I have this flag because I do not want to change the initialization
  // of the output to the generic output.  It might break something;
  this->OutputsInitialized = 0;
401
402
403
404
405
406
407
408
409
410

  this->DOM = 0;

  this->PointDataArraySelection = vtkDataArraySelection::New();
  this->CellDataArraySelection = vtkDataArraySelection::New();

  // Setup the selection callback to modify this object when an array
  // selection is changed.
  this->SelectionObserver = vtkCallbackCommand::New();
  this->SelectionObserver->SetCallback(
Andy Cedilnik's avatar
Andy Cedilnik committed
411
    &vtkXdmfReader::SelectionModifiedCallback);
412
413
414
415
416
417
418
  this->SelectionObserver->SetClientData(this);
  this->PointDataArraySelection->AddObserver(vtkCommand::ModifiedEvent,
                                             this->SelectionObserver);
  this->CellDataArraySelection->AddObserver(vtkCommand::ModifiedEvent,
                                            this->SelectionObserver);

  this->DomainName = 0;
419
  this->Internals->DomainPtr = 0;
420
421
422
423
424
  this->GridName = 0;
  
  for (int i = 0; i < 3; i ++ )
    {
    this->Stride[i] = 1;
Jerry Clarke's avatar
Jerry Clarke committed
425
    }
426

427
  this->GridsModified = 0;
428
429
430
431
432
  
  this->NumberOfEnabledActualGrids=0;
  
  this->Controller = 0;
  this->SetController(vtkMultiProcessController::GetGlobalController());
Jerry Clarke's avatar
Jerry Clarke committed
433
434
}

435
//----------------------------------------------------------------------------
Andy Cedilnik's avatar
Andy Cedilnik committed
436
vtkXdmfReader::~vtkXdmfReader()
437
438
439
440
441
442
443
444
{
  this->CellDataArraySelection->RemoveObserver(this->SelectionObserver);
  this->PointDataArraySelection->RemoveObserver(this->SelectionObserver);
  this->SelectionObserver->Delete();
  this->CellDataArraySelection->Delete();
  this->PointDataArraySelection->Delete();

  this->SetDomainName(0);
445
  
446
447
  vtkXdmfReaderInternal::MapOfActualGrids::iterator actualGridIt;
  for ( actualGridIt = this->Internals->ActualGrids.begin();
Berk Geveci's avatar
Berk Geveci committed
448
449
        actualGridIt != this->Internals->ActualGrids.end();
        ++ actualGridIt )
Andy Cedilnik's avatar
Andy Cedilnik committed
450
    {
451
452
453
454
455
456
457
458
    vtkXdmfReaderActualGrid* grid = &actualGridIt->second;
    if ( grid->Grid )
      {
      delete grid->Grid;
      }
    if ( grid->Collection )
      {
      vtkXdmfReaderGridCollection::SetOfGrids::iterator gridIt;
459
      int i =0;
460
      for ( gridIt = grid->Collection->Grids.begin();
Berk Geveci's avatar
Berk Geveci committed
461
462
            gridIt != grid->Collection->Grids.end();
            ++ gridIt )
463
464
        {
        delete gridIt->second;
465
        i++;
466
        }
467
      grid->Collection->Grids.clear();
468
469
      delete grid->Collection;
      }
Andy Cedilnik's avatar
Andy Cedilnik committed
470
    }
471
  this->Internals->ActualGrids.clear();
Andy Cedilnik's avatar
Andy Cedilnik committed
472

473
  delete this->Internals;
474
475
476
477
478
479

  if ( this->DOM )
    {
    delete this->DOM;
    }

480
  H5garbage_collect();
481
482
  
  this->SetController(0);
Jerry Clarke's avatar
Jerry Clarke committed
483
484
}

485
486
487
488
489
//----------------------------------------------------------------------------
int vtkXdmfReader::ProcessRequest(vtkInformation* request,
                                  vtkInformationVector** inputVector,
                                  vtkInformationVector* outputVector)
{
490
  // create the output
491
492
  if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA_OBJECT()))
    {
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
    return this->RequestDataObject(outputVector);
    }
  return this->Superclass::ProcessRequest(request, inputVector, outputVector);
}

//----------------------------------------------------------------------------
int vtkXdmfReader::RequestDataObject(vtkInformationVector *outputVector)
{
  // Set the number of outputs and the create the output data objects
  // needed because we may change the number of output ports
  // inside RequestDataObject. So we may change the output vector.
  vtkInformationVector *newOutputVector=outputVector;
  
  ////////////
  vtkIdType cc;
  XdmfConstString CurrentFileName;

  if ( !this->FileName )
    {
    vtkErrorMacro("File name not set");
    return 1;
    }
  // First make sure the file exists.  This prevents an empty file
  // from being created on older compilers.
  struct stat fs;
  if(stat(this->FileName, &fs) != 0)
    {
    vtkErrorMacro("Error opening file " << this->FileName);
    return 1;
    }
  if ( !this->DOM )
    {
    this->DOM = new XdmfDOM();
    }
Berk Geveci's avatar
Berk Geveci committed
527
  // this->DOM->GlobalDebugOn();
Jerry Clarke's avatar
Jerry Clarke committed
528
  if ( !this->Internals->DataItem )
529
    {
Jerry Clarke's avatar
Jerry Clarke committed
530
531
    this->Internals->DataItem = new XdmfDataItem();
    this->Internals->DataItem->SetDOM(this->DOM);
532
533
534
535
536
537
538
539
    }
  CurrentFileName = this->DOM->GetInputFileName();
  
  // Don't Re-Parse : Could Reset Parameters
  if((CurrentFileName == NULL) ||
     (STRCASECMP(CurrentFileName, this->FileName) != 0 ))
    {
    this->DOM->SetInputFileName(this->FileName);
Jerry Clarke's avatar
works    
Jerry Clarke committed
540
    vtkDebugMacro( << ".!!............Preparing to Parse " << this->FileName);
541
    this->DOM->Parse();
542
543
    // Added By Jerry Clarke
    this->GridsModified = 1;
544
545
    }

Jerry Clarke's avatar
Jerry Clarke committed
546
  XdmfXmlNode domain = 0;
547
548
  int done = 0;
  this->Internals->DomainList.erase(this->Internals->DomainList.begin(),
Berk Geveci's avatar
Berk Geveci committed
549
                                    this->Internals->DomainList.end());
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
  for ( cc = 0; !done; cc ++ )
    {
    ostrstream str1, str2;
    domain = this->DOM->FindElement("Domain", cc);
    if ( !domain )
      {
      break;
      }
    XdmfConstString domainName = this->DOM->Get( domain, "Name" );
    ostrstream str;
    if ( !domainName )
      {
      str << "Domain" << cc << ends;
      domainName = str.str();
      }
    this->Internals->DomainList.push_back(domainName);
    str.rdbuf()->freeze(0);
    }
  if ( this->DomainName )
    {
    for ( cc = 0; !done; cc ++ )
571
      {
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
      domain = this->DOM->FindElement("Domain", cc);
      if ( !domain )
        {
        break;
        }
      XdmfConstString domainName = this->DOM->Get( domain, "Name" );
      ostrstream str;
      if ( !domainName )
        {
        str << "Domain" << cc << ends;
        domainName = str.str();
        }
      if( domainName && strcmp(domainName, this->DomainName) == 0)
        {
        str.rdbuf()->freeze(0);
        break;
        }      
      str.rdbuf()->freeze(0);
590
      }
591
592
593
594
595
596
597
598
599
600
    }

  if ( !domain )
    {
    domain = this->DOM->FindElement("Domain", 0); // 0 - domain index    
    }

  if ( !domain )
    {
    vtkErrorMacro("Cannot find any domain...");
601
602
    return 1;
    }
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643

  this->Internals->DomainPtr = domain;
//  this->UpdateGrids();

  char* filename = 0;
  if ( this->FileName )
    {
    filename = new char[ strlen(this->FileName)+ 1];
    strcpy(filename, this->FileName);
    }
  int len = static_cast<int>(strlen(filename));
  for ( cc = len-1; cc >= 0; cc -- )
    {
    if ( filename[cc] != '/' && filename[cc] != '\\' )
      {
      filename[cc] = 0;
      }
    else
      {
      break;
      }
    }
  if ( filename[0] == 0 )
    {
    char buffer[1024];
    if ( GETCWD(buffer, 1023) )
      {
      delete [] filename;
      if ( buffer )
        {
        filename = new char[ strlen(buffer)+ 1];
        strcpy(filename, buffer);
        }
      }
    }
  this->DOM->SetWorkingDirectory(filename);
  delete [] filename;
////////////////
  
  
  this->UpdateGrids();
644
645

/*  
Berk Geveci's avatar
Berk Geveci committed
646
    if(1 !=this->GetNumberOfOutputPorts())
647
    {
Jerry Clarke's avatar
Jerry Clarke committed
648
    this->SetNumberOfOutputPorts(1);
649

650
651
652
653
654
    // We have to refresh the outputVector with this new number of ports.
    // The one in argument was given by the executive.
    // The only way to do that, is to ask the output vector from the executive.
    newOutputVector=this->GetExecutive()->GetOutputInformation();
    }
655
*/
656
657
658
659
  
  // for each output
  vtkXdmfReaderInternal::MapOfActualGrids::iterator currentGridIterator;
  currentGridIterator = this->Internals->ActualGrids.begin();
660

661
662
  
  int someOutputChanged=0;
663
664
665
666
667
668
669
670
671
  vtkInformation *jinfo=newOutputVector->GetInformationObject(0);
  vtkMultiGroupDataSet *output=vtkMultiGroupDataSet::SafeDownCast(jinfo->Get(vtkDataObject::DATA_OBJECT()));
  if(output==0)
    {
    someOutputChanged=1;
    output=vtkMultiGroupDataSet::New();
    output->SetPipelineInformation(jinfo);
    output->Delete();
    }
Berk Geveci's avatar
Berk Geveci committed
672
  // Collapse on second level of Hierarchy
673
  output->SetNumberOfGroups(this->NumberOfEnabledActualGrids);
674
675
  //
  //while(currentGridIterator != this->Internals->ActualGrids.end())
676
677
678
679
680
681
682
  if(someOutputChanged)
    {
    this->GetPointDataArraySelection()->RemoveAllArrays();
    this->GetCellDataArraySelection()->RemoveAllArrays();
    }
  
  return 1;
683
684
}

685
686
//----------------------------------------------------------------------------
void vtkXdmfReader::SetGridName(const char* grid)
687
{
688
689
690
691
692
  this->DisableAllGrids();
  this->EnableGrid(grid);
}

//----------------------------------------------------------------------------
693
vtkDataObject *vtkXdmfReader::GetOutput()
Jerry Clarke's avatar
Jerry Clarke committed
694
{
695
  return this->GetOutput(0);
Jerry Clarke's avatar
Jerry Clarke committed
696
697
}

698
699
700
701
702
703
704
705
706
//----------------------------------------------------------------------------
void vtkXdmfReader::SetStride(int x, int y, int z)
{
  if ( x <= 0 || y <= 0 || z <= 0 )
    {
    vtkErrorMacro("Strides have to be greater than 0.");
    return;
    }
  vtkDebugMacro(<< this->GetClassName() << " (" << this 
Berk Geveci's avatar
Berk Geveci committed
707
                << "): setting Stride to (" << x << "," << y << "," << z << ")");
708
709
710
711
712
713
714
715
716
  if ((this->Stride[0] != x)||(this->Stride[1] != y)||(this->Stride[2] != z))
    {
    this->Stride[0] = x;
    this->Stride[1] = y;
    this->Stride[2] = z;
    this->Modified();
    }
}

717
//----------------------------------------------------------------------------
718
vtkDataObject *vtkXdmfReader::GetOutput(int idx)
719
{
720
  return this->GetExecutive()->GetOutputData(idx);
721
722
723
}

//----------------------------------------------------------------------------
724
int vtkXdmfReader::RequestData(
725
726
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **vtkNotUsed(inputVector),
727
  vtkInformationVector *outputVector)
728
{
729
  vtkDebugMacro("Execute");
730
731
732
  if ( !this->FileName )
    {
    vtkErrorMacro("File name not set");
733
    return 0;
Jerry Clarke's avatar
Jerry Clarke committed
734
    }
735
736
737

  if ( !this->DOM )
    {
738
    return 0;
739
    }
740
  
741
742
743
  int outputGrid = 0;
  vtkXdmfReaderInternal::MapOfActualGrids::iterator currentGridIterator;
  for ( currentGridIterator = this->Internals->ActualGrids.begin();
Berk Geveci's avatar
Berk Geveci committed
744
745
        currentGridIterator != this->Internals->ActualGrids.end();
        ++currentGridIterator )
746
    {
747
    if (currentGridIterator->second.Enabled )
748
      {
749
750
      this->Internals->RequestActualGridData(
        currentGridIterator->first.c_str(),&currentGridIterator->second,
751
        outputGrid, this->NumberOfEnabledActualGrids, outputVector);
752
      outputGrid++;
Jerry Clarke's avatar
Jerry Clarke committed
753
      this->UpdateProgress(1.0 * outputGrid / this->NumberOfEnabledActualGrids);
754
      }
755
    }
756
  
757
758
759
760
  return 1;
}

//----------------------------------------------------------------------------
761
int vtkXdmfReaderInternal::RequestActualGridData(
762
  const char* vtkNotUsed(currentGridName),
763
764
  vtkXdmfReaderActualGrid* currentActualGrid,
  int outputGrid,
765
  int vtkNotUsed(numberOfGrids),
766
  vtkInformationVector *outputVector)
767
{
768
  vtkInformation *info=outputVector->GetInformationObject(0);
Berk Geveci's avatar
Berk Geveci committed
769
770
771
772
  int procId=info->Get(
    vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER());
  int nbProcs=info->Get(
    vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES());
773
  
774
  vtkInformation *outInfo = outputVector->GetInformationObject(0);
Jerry Clarke's avatar
Jerry Clarke committed
775
  vtkMultiGroupDataSet *mgd=vtkMultiGroupDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
776
777
778
779
780
781

  if (!currentActualGrid->Collection)
    {
    return 0; //work around an undo/redo bug
    }

Berk Geveci's avatar
Berk Geveci committed
782
  unsigned int numberOfDataSets=currentActualGrid->Collection->Grids.size();
783
    
Berk Geveci's avatar
Berk Geveci committed
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
  currentActualGrid->Collection->UpdateCounts();
  int levels=currentActualGrid->Collection->GetNumberOfLevels();
  // mgd->SetNumberOfLevels(levels);
  // int levels = 1;
  
  int level=0;
  mgd->SetNumberOfDataSets(outputGrid, currentActualGrid->Collection->GetNumberOfDataSets(level));
  while(level<levels)
    {
    // mgd->SetNumberOfDataSets(level,currentActualGrid->Collection->GetNumberOfDataSets(level));
    ++level;
    }
  
  vtkXdmfReaderGridCollection::SetOfGrids::iterator gridIt;
  vtkXdmfReaderGridCollection::SetOfGrids::iterator gridItEnd;
799
    
Berk Geveci's avatar
Berk Geveci committed
800
801
  int numBlocksPerProcess=numberOfDataSets/nbProcs;
  int leftOverBlocks=numberOfDataSets-(numBlocksPerProcess*nbProcs);
802
    
Berk Geveci's avatar
Berk Geveci committed
803
804
  int blockStart;
  int blockEnd;
805
    
Berk Geveci's avatar
Berk Geveci committed
806
807
808
809
810
811
812
813
814
815
  if(procId<leftOverBlocks)
    {
    blockStart=(numBlocksPerProcess+1)*procId;
    blockEnd=blockStart+(numBlocksPerProcess+1)-1;
    }
  else
    {
    blockStart=numBlocksPerProcess*procId+leftOverBlocks;
    blockEnd=blockStart+numBlocksPerProcess-1;
    }
816
    
Berk Geveci's avatar
Berk Geveci committed
817
818
819
  gridIt=currentActualGrid->Collection->Grids.begin();
  gridItEnd=currentActualGrid->Collection->Grids.end();
  int result=1;
820
    
Berk Geveci's avatar
Berk Geveci committed
821
  int datasetIdx=0;
822
    
Berk Geveci's avatar
Berk Geveci committed
823
824
825
  vtkMultiGroupDataInformation *compInfo =
    vtkMultiGroupDataInformation::SafeDownCast(
      info->Get(vtkCompositeDataPipeline::COMPOSITE_DATA_INFORMATION()));
826
    
Berk Geveci's avatar
Berk Geveci committed
827
828
829
830
831
832
833
834
  // currentIndex in each level.
  vtkstd::vector<int> currentIndex(levels);
  level=0;
  while(level<levels)
    {
    currentIndex[level]=0;
    ++level;
    }
835
    
Berk Geveci's avatar
Berk Geveci committed
836
837
838
839
840
841
  while(gridIt != gridItEnd && result)
    {
    vtkXdmfReaderGrid *subgrid=gridIt->second;
    level=subgrid->Level;
    int index=currentIndex[level];
    if(datasetIdx<blockStart || datasetIdx>blockEnd)
842
      {
Berk Geveci's avatar
Berk Geveci committed
843
844
      // mgd->SetDataSet(level,index,0); // empty, on another processor
      mgd->SetDataSet(outputGrid, index, 0); // empty, on another processor
845
      }
Berk Geveci's avatar
Berk Geveci committed
846
    else
847
      {
Berk Geveci's avatar
Berk Geveci committed
848
849
850
851
852
853
854
855
856
857
858
      XdmfGrid *xdmfGrid=subgrid->XMGrid;
      if( xdmfGrid->GetTopology()->GetClass() == XDMF_UNSTRUCTURED ) 
        {
        vtkUnstructuredGrid *ds=vtkUnstructuredGrid::New();
        ds->SetMaximumNumberOfPieces(1);
        // mgd->SetDataSet(level,index,ds);
        mgd->SetDataSet(outputGrid, index, ds);
        ds->Delete();
        } 
      else if( xdmfGrid->GetTopology()->GetTopologyType() == XDMF_2DSMESH ||
               xdmfGrid->GetTopology()->GetTopologyType() == XDMF_3DSMESH )
859
        {
Berk Geveci's avatar
Berk Geveci committed
860
861
862
863
        vtkStructuredGrid *ds=vtkStructuredGrid::New();
        // mgd->SetDataSet(level,index,ds);
        mgd->SetDataSet(outputGrid, index, ds);
        ds->Delete();
864
        }
Berk Geveci's avatar
Berk Geveci committed
865
866
867
      else if 
        (xdmfGrid->GetTopology()->GetTopologyType() == XDMF_2DCORECTMESH ||
         xdmfGrid->GetTopology()->GetTopologyType() == XDMF_3DCORECTMESH )
868
        {
869
#ifdef USE_IMAGE_DATA
Berk Geveci's avatar
Berk Geveci committed
870
        vtkImageData *ds=vtkImageData::New();
871
#else
Berk Geveci's avatar
Berk Geveci committed
872
        vtkUniformGrid *ds=vtkUniformGrid::New();
873
#endif
874
875
        //mgd->SetDataSet(level,index,ds);
        mgd->SetDataSet(outputGrid,index,ds);
Berk Geveci's avatar
Berk Geveci committed
876
        ds->Delete();
877
        }
Berk Geveci's avatar
Berk Geveci committed
878
879
880
881
882
      else if ( 
        xdmfGrid->GetTopology()->GetTopologyType() == XDMF_2DRECTMESH ||
        xdmfGrid->GetTopology()->GetTopologyType() == XDMF_3DRECTMESH )
        {
        vtkRectilinearGrid *ds=vtkRectilinearGrid::New();
883
884
        //mgd->SetDataSet(level,index,ds);
        mgd->SetDataSet(outputGrid,index,ds);
Berk Geveci's avatar
Berk Geveci committed
885
886
887
888
889
890
891
892
893
894
895
        ds->Delete();
        }
      else
        {
        // Unknown type for this sub grid. 
        return 0;
        }
      // vtkDataObject *ds=mgd->GetDataSet(level,index);
      vtkDataObject *ds=mgd->GetDataSet(outputGrid,index);
      vtkInformation *subInfo=compInfo->GetInformation(level,index);
      result=this->RequestSingleGridData("",gridIt->second,subInfo,ds,1);
896
      }
Berk Geveci's avatar
Berk Geveci committed
897
898
899
900
901
902
    ++currentIndex[level];
    ++gridIt;
    ++datasetIdx;
    this->Reader->UpdateProgress(1.0 * datasetIdx / numberOfDataSets);
    }
  return result;
903
}
904

905
906
907
908
909
//----------------------------------------------------------------------------
int vtkXdmfReaderInternal::RequestSingleGridData(
  const char* currentGridName,
  vtkXdmfReaderGrid *grid,
  vtkInformation *outInfo,
910
911
  vtkDataObject *output,
  int isSubBlock)
912
913
{
  int *readerStride = this->Reader->GetStride();
914
  
Berk Geveci's avatar
Berk Geveci committed
915
916
917
918
  vtkDataArraySelection* pointDataArraySelection = 
    this->Reader->GetPointDataArraySelection();
  vtkDataArraySelection* cellDataArraySelection = 
    this->Reader->GetCellDataArraySelection();
919
  
920
921
922
923
924
925
  // Handle single grid
  XdmfGrid* xdmfGrid = grid->XMGrid;
  XdmfDOM* xdmfDOM = xdmfGrid->GetDOM();
  
  if ( !grid->DataDescription )
    {
Jerry Clarke's avatar
Jerry Clarke committed
926
    grid->DataDescription = xdmfGrid->GetTopology()->GetShapeDesc();
927
928
929
    //continue;
    }
  
Berk Geveci's avatar
Berk Geveci committed
930
931
932
  vtkDebugWithObjectMacro(this->Reader, 
                          << "Reading Heavy Data for " 
                          << xdmfGrid->GetName());
933
934
935
936
  xdmfGrid->Update();
  
  // True for all 3d datasets except unstructured grids
  int globalrank = 3;
Jerry Clarke's avatar
Jerry Clarke committed
937
  switch(xdmfGrid->GetTopology()->GetTopologyType())
938
    {
939
940
    case XDMF_2DSMESH: case XDMF_2DRECTMESH: case XDMF_2DCORECTMESH:
      globalrank = 2;
941
    }
Jerry Clarke's avatar
Jerry Clarke committed
942
  if ( xdmfGrid->GetTopology()->GetClass() == XDMF_UNSTRUCTURED )
943
944
945
946
947
948
    {
    globalrank = 1;
    }
  
  
  vtkIdType cc;
Jerry Clarke's avatar
Jerry Clarke committed
949
950
951
952
  // XdmfXmlNode attrNode = this->DOM->FindElement("Attribute");
  // XdmfXmlNode dataNode = this->DOM->FindElement("DataStructure", 0, attrNode);
  XdmfXmlNode attrNode;
  XdmfXmlNode dataNode;
953
954
955
956
957
958
959
960
961
962
963
964
965
966
  // XdmfInt64 start[3]  = { 0, 0, 0 };
  // XdmfInt64 stride[3] = { 1, 1, 1 };
  // XdmfInt64 count[3] = { 0, 0, 0 };
  // XdmfInt64 end[3] = { 0, 0, 0 };
  // Must Account for Vectors and Tensors
  XdmfInt64 start[4]  = { 0, 0, 0, 0 };
  XdmfInt64 stride[4] = { 1, 1, 1, 1 };
  XdmfInt64 count[4] = { 0, 0, 0, 0 };
  // XdmfInt64 end[4] = { 0, 0, 0, 0 };
  grid->DataDescription->GetShape(count);

  int upext[6];
  int whext[6];
  
Jerry Clarke's avatar
Jerry Clarke committed
967
  if( xdmfGrid->GetTopology()->GetClass() != XDMF_UNSTRUCTURED)
968
    {
969
    if(isSubBlock)
970
      {
971
972
973
      // the composite pipeline does not set update extent, so just take
      // the whole extent for as update extent.
      outInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), upext);
974
      }
975
    else
976
      {
977
      outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(), upext);
978
      }
979
    
980
981
    outInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), whext);
    
982
983
984
    start[2] = vtkMAX(0, upext[0]);
    start[1] = vtkMAX(0, upext[2]);
    start[0] = vtkMAX(0, upext[4]);
985
    
986
987
988
    count[2] = upext[1] - upext[0];
    count[1] = upext[3] - upext[2];
    count[0] = upext[5] - upext[4];
989
    }
990
  
991
  XdmfGeometry  *Geometry = xdmfGrid->GetGeometry();
992
993
  
  
994
  // Read Topology for Unstructured Grid
Jerry Clarke's avatar
Jerry Clarke committed
995
  if( xdmfGrid->GetTopology()->GetClass() == XDMF_UNSTRUCTURED ) 
996
997
998
999
1000
    {
    vtkUnstructuredGrid  *vGrid = static_cast<vtkUnstructuredGrid *>(output);
    vtkCellArray                *verts;
    XdmfInt32           vType;
    XdmfInt32           NodesPerElement;
For faster browsing, not all history is shown. View entire blame