vtkXdmfReader.cxx 91.7 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


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);
Dave Demarle's avatar
Dave Demarle committed
89
vtkCxxRevisionMacro(vtkXdmfReader, "1.16");
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()
    {
Jerry Clarke's avatar
Update    
Jerry Clarke 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()
    {
Jerry Clarke's avatar
Jerry Clarke committed
224
    this->DataItem = 0;
225
    this->ArrayConverter = vtkXdmfDataArray::New();
226
    this->NumberOfEnabledActualGrids=0;
227
228
229
    }
  ~vtkXdmfReaderInternal()
    {
Jerry Clarke's avatar
Jerry Clarke committed
230
    if ( this->DataItem )
231
      {
Jerry Clarke's avatar
Jerry Clarke committed
232
      // cout << "....Deleting DataItem " << this->DataItem << endl;
Jerry Clarke's avatar
Jerry Clarke committed
233
      delete this->DataItem;
Jerry Clarke's avatar
Jerry Clarke committed
234
      // cout << "....Back from Deleting DataItem " << this->DataItem << endl;
Jerry Clarke's avatar
Jerry Clarke committed
235
      this->DataItem = 0;
236
237
238
239
240
      }
    this->ArrayConverter->Delete();
    this->ArrayConverter = 0;
    }

241
  typedef vtkstd::vector<vtkstd::string> StringListType;
242
243

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

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

  StringListType DomainList;
Jerry Clarke's avatar
Jerry Clarke committed
276
  XdmfXmlNode DomainPtr;
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
{
  if ( !collectionName )
    {
    return 0;
    }
  vtkXdmfReaderActualGrid* actualGrid = &this->ActualGrids[collectionName];
  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;
    }
  return actualGrid->Collection;
}

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

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

  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;
    }
  grid->Grid = new vtkXdmfReaderGrid;
  return grid->Grid;
}

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

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

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

395
396
397
  // 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;
398
399
400
401
402
403
404
405
406
407

  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
408
    &vtkXdmfReader::SelectionModifiedCallback);
409
410
411
412
413
414
415
  this->SelectionObserver->SetClientData(this);
  this->PointDataArraySelection->AddObserver(vtkCommand::ModifiedEvent,
                                             this->SelectionObserver);
  this->CellDataArraySelection->AddObserver(vtkCommand::ModifiedEvent,
                                            this->SelectionObserver);

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

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

432
//----------------------------------------------------------------------------
Andy Cedilnik's avatar
Andy Cedilnik committed
433
vtkXdmfReader::~vtkXdmfReader()
434
435
436
437
438
439
440
441
442
443
444
445
446
{
  if ( this->DOM )
    {
    delete this->DOM;
    }

  this->CellDataArraySelection->RemoveObserver(this->SelectionObserver);
  this->PointDataArraySelection->RemoveObserver(this->SelectionObserver);
  this->SelectionObserver->Delete();
  this->CellDataArraySelection->Delete();
  this->PointDataArraySelection->Delete();

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

471
  delete this->Internals;
472
  H5garbage_collect();
473
474
  
  this->SetController(0);
Jerry Clarke's avatar
Jerry Clarke committed
475
476
}

477
478
479
480
481
//----------------------------------------------------------------------------
int vtkXdmfReader::ProcessRequest(vtkInformation* request,
                                  vtkInformationVector** inputVector,
                                  vtkInformationVector* outputVector)
{
482
  // create the output
483
484
  if(request->Has(vtkDemandDrivenPipeline::REQUEST_DATA_OBJECT()))
    {
485
486
487
488
489
490
491
492
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
    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();
    }
519
    // this->DOM->GlobalDebugOn();
Jerry Clarke's avatar
Jerry Clarke committed
520
  if ( !this->Internals->DataItem )
521
    {
Jerry Clarke's avatar
Jerry Clarke committed
522
523
    this->Internals->DataItem = new XdmfDataItem();
    this->Internals->DataItem->SetDOM(this->DOM);
524
525
526
527
528
529
530
531
    }
  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
532
    vtkDebugMacro( << ".!!............Preparing to Parse " << this->FileName);
533
    this->DOM->Parse();
534
535
    // Added By Jerry Clarke
    this->GridsModified = 1;
536
537
    }

Jerry Clarke's avatar
Jerry Clarke committed
538
  XdmfXmlNode domain = 0;
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
  int done = 0;
  this->Internals->DomainList.erase(this->Internals->DomainList.begin(),
    this->Internals->DomainList.end());
  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 ++ )
563
      {
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
      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);
582
      }
583
584
585
586
587
588
589
590
591
592
    }

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

  if ( !domain )
    {
    vtkErrorMacro("Cannot find any domain...");
593
594
    return 1;
    }
595
596
597
598
599
600
601
602
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

  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();
636
637

/*  
Jerry Clarke's avatar
Jerry Clarke committed
638
  if(1 !=this->GetNumberOfOutputPorts())
639
    {
Jerry Clarke's avatar
Jerry Clarke committed
640
    this->SetNumberOfOutputPorts(1);
641

642
643
644
645
646
    // 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();
    }
647
*/
648
649
650
651
652
653
654
  
  // for each output
  vtkXdmfReaderInternal::MapOfActualGrids::iterator currentGridIterator;
  currentGridIterator = this->Internals->ActualGrids.begin();
  int i=0;
  
  int someOutputChanged=0;
655
656
657
658
659
660
661
662
663
664
665
  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();
    }
    // Collapse on second level of Hierarchy
  output->SetNumberOfGroups(this->NumberOfEnabledActualGrids);
666
667
  //
  //while(currentGridIterator != this->Internals->ActualGrids.end())
668
669
670
671
672
673
674
  if(someOutputChanged)
    {
    this->GetPointDataArraySelection()->RemoveAllArrays();
    this->GetCellDataArraySelection()->RemoveAllArrays();
    }
  
  return 1;
675
676
}

677
678
//----------------------------------------------------------------------------
void vtkXdmfReader::SetGridName(const char* grid)
679
{
680
681
682
683
684
  this->DisableAllGrids();
  this->EnableGrid(grid);
}

//----------------------------------------------------------------------------
685
vtkDataObject *vtkXdmfReader::GetOutput()
Jerry Clarke's avatar
Jerry Clarke committed
686
{
687
  return this->GetOutput(0);
Jerry Clarke's avatar
Jerry Clarke committed
688
689
}

690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
//----------------------------------------------------------------------------
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 
    << "): setting Stride to (" << x << "," << y << "," << z << ")");
  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();
    }
}

709
//----------------------------------------------------------------------------
710
vtkDataObject *vtkXdmfReader::GetOutput(int idx)
711
{
712
  return this->GetExecutive()->GetOutputData(idx);
713
714
715
}

//----------------------------------------------------------------------------
716
int vtkXdmfReader::RequestData(
717
718
  vtkInformation *vtkNotUsed(request),
  vtkInformationVector **vtkNotUsed(inputVector),
719
  vtkInformationVector *outputVector)
720
{
721
  vtkDebugMacro("Execute");
722
723
724
  if ( !this->FileName )
    {
    vtkErrorMacro("File name not set");
725
    return 0;
Jerry Clarke's avatar
Jerry Clarke committed
726
    }
727
728
729

  if ( !this->DOM )
    {
730
    return 0;
731
    }
732
  
733
734
735
736
737
  int outputGrid = 0;
  vtkXdmfReaderInternal::MapOfActualGrids::iterator currentGridIterator;
  for ( currentGridIterator = this->Internals->ActualGrids.begin();
    currentGridIterator != this->Internals->ActualGrids.end();
    ++currentGridIterator )
738
    {
739
    if (currentGridIterator->second.Enabled )
740
      {
741
742
      this->Internals->RequestActualGridData(
        currentGridIterator->first.c_str(),&currentGridIterator->second,
743
        outputGrid, this->NumberOfEnabledActualGrids, outputVector);
744
      outputGrid++;
Jerry Clarke's avatar
Jerry Clarke committed
745
       // cout << "Progress " << 1.0 * outputGrid / this->NumberOfEnabledActualGrids << endl;
Jerry Clarke's avatar
Jerry Clarke committed
746
      this->UpdateProgress(1.0 * outputGrid / this->NumberOfEnabledActualGrids);
747
      }
748
    }
749
  
750
751
752
753
  return 1;
}

//----------------------------------------------------------------------------
754
755
756
757
int vtkXdmfReaderInternal::RequestActualGridData(
  const char* currentGridName,
  vtkXdmfReaderActualGrid* currentActualGrid,
  int outputGrid,
758
  int numberOfGrids,
759
  vtkInformationVector *outputVector)
760
{
761

762
763
764
765
  vtkInformation *info=outputVector->GetInformationObject(0);
  int procId=info->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER());
  int nbProcs=info->Get(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES());
  
766
  vtkInformation *outInfo = outputVector->GetInformationObject(0);
Jerry Clarke's avatar
Jerry Clarke committed
767
  vtkMultiGroupDataSet *mgd=vtkMultiGroupDataSet::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
768
769
770
771
772
773

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

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

901
902
903
904
905
//----------------------------------------------------------------------------
int vtkXdmfReaderInternal::RequestSingleGridData(
  const char* currentGridName,
  vtkXdmfReaderGrid *grid,
  vtkInformation *outInfo,
906
907
  vtkDataObject *output,
  int isSubBlock)
908
909
{
  int *readerStride = this->Reader->GetStride();
910

911
912
913
914
915
916
917
918
919
  vtkDataArraySelection* pointDataArraySelection = this->Reader->GetPointDataArraySelection();
  vtkDataArraySelection* cellDataArraySelection = this->Reader->GetCellDataArraySelection();

  // Handle single grid
  XdmfGrid* xdmfGrid = grid->XMGrid;
  XdmfDOM* xdmfDOM = xdmfGrid->GetDOM();
  
  if ( !grid->DataDescription )
    {
Jerry Clarke's avatar
Jerry Clarke committed
920
    grid->DataDescription = xdmfGrid->GetTopology()->GetShapeDesc();
921
922
923
    //continue;
    }
  
924
  vtkDebugWithObjectMacro( this->Reader, << "Reading Heavy Data for " << xdmfGrid->GetName());
925
926
927
928
  xdmfGrid->Update();
  
  // True for all 3d datasets except unstructured grids
  int globalrank = 3;
Jerry Clarke's avatar
Jerry Clarke committed
929
  switch(xdmfGrid->GetTopology()->GetTopologyType())
930
    {
931
932
    case XDMF_2DSMESH: case XDMF_2DRECTMESH: case XDMF_2DCORECTMESH:
      globalrank = 2;
933
    }
Jerry Clarke's avatar
Jerry Clarke committed
934
  if ( xdmfGrid->GetTopology()->GetClass() == XDMF_UNSTRUCTURED )
935
936
937
938
939
940
    {
    globalrank = 1;
    }
  
  
  vtkIdType cc;
Jerry Clarke's avatar
Jerry Clarke committed
941
942
943
944
  // XdmfXmlNode attrNode = this->DOM->FindElement("Attribute");
  // XdmfXmlNode dataNode = this->DOM->FindElement("DataStructure", 0, attrNode);
  XdmfXmlNode attrNode;
  XdmfXmlNode dataNode;
945
946
947
948
949
950
951
952
953
954
955
956
957
958
  // 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
959
  if( xdmfGrid->GetTopology()->GetClass() != XDMF_UNSTRUCTURED)
960
    {
961
    if(isSubBlock)
962
      {
963
964
965
      // the composite pipeline does not set update extent, so just take
      // the whole extent for as update extent.
      outInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), upext);
966
      }
967
    else
968
      {
969
      outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_EXTENT(), upext);
970
      }
971
    
972
973
    outInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), whext);
    
974
975
976
    start[2] = vtkMAX(0, upext[0]);
    start[1] = vtkMAX(0, upext[2]);
    start[0] = vtkMAX(0, upext[4]);
977
    
978
979
980
    count[2] = upext[1] - upext[0];
    count[1] = upext[3] - upext[2];
    count[0] = upext[5] - upext[4];
981
    }
982

983
984
985
986
  XdmfGeometry  *Geometry = xdmfGrid->GetGeometry();
    
    
  // Read Topology for Unstructured Grid
Jerry Clarke's avatar
Jerry Clarke committed
987
  if( xdmfGrid->GetTopology()->GetClass() == XDMF_UNSTRUCTURED ) 
988
989
990
991
992
993
994
995
996
997
998
999
    {
    vtkUnstructuredGrid  *vGrid = static_cast<vtkUnstructuredGrid *>(output);
    vtkCellArray                *verts;
    XdmfInt32           vType;
    XdmfInt32           NodesPerElement;
    vtkIdType           NumberOfElements;
    vtkIdType           i, j, index;    
    XdmfInt64           Length, *Connections;
    vtkIdType           *connections;
    int                 *cell_types, *ctp;
    
    vtkDebugWithObjectMacro(this->Reader,<< "Unstructured Topology is " 
Jerry Clarke's avatar
Jerry Clarke committed
1000
1001
                            << xdmfGrid->GetTopology()->GetTopologyTypeAsString() );
    switch ( xdmfGrid->GetTopology()->GetTopologyType() )
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
      {
      case  XDMF_POLYVERTEX :
        vType = VTK_POLY_VERTEX;
        break;
      case  XDMF_POLYLINE :
        vType = VTK_POLY_LINE;
        break;
      case  XDMF_POLYGON :
        vType = VTK_POLYGON;
        break;
      case  XDMF_TRI :
        vType = VTK_TRIANGLE;
        break;
      case  XDMF_QUAD :
        vType = VTK_QUAD;
        break;
      case  XDMF_TET :
        vType = VTK_TETRA;
        break;
      case  XDMF_PYRAMID :
        vType = VTK_PYRAMID;
Jerry Clarke's avatar
Jerry Clarke committed
1023
        break;
1024
1025
1026
1027
1028
1029
      case  XDMF_WEDGE :
        vType = VTK_WEDGE;
        break;
      case  XDMF_HEX :
        vType = VTK_HEXAHEDRON;
        break;
Jerry Clarke's avatar
Jerry Clarke committed
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
      case  XDMF_EDGE_3 :
        vType = VTK_QUADRATIC_EDGE ;
        break;
      case  XDMF_TRI_6 :
        vType = VTK_QUADRATIC_TRIANGLE ;
        break;
      case  XDMF_QUAD_8 :
        vType = VTK_QUADRATIC_QUAD ;
        break;
      case  XDMF_TET_10 :
        vType = VTK_QUADRATIC_TETRA ;
        break;
      case  XDMF_PYRAMID_13 :
        vType = VTK_QUADRATIC_PYRAMID ;
        break;
      case  XDMF_WEDGE_15 :
        vType = VTK_QUADRATIC_WEDGE ;
        break;
      case  XDMF_HEX_20 :
        vType = VTK_QUADRATIC_HEXAHEDRON ;
        break;
Jerry Clarke's avatar
Jerry Clarke committed
1051
1052
1053
      case XDMF_MIXED :
        vType = -1;
        break;
1054
      default :
Jerry Clarke's avatar
Jerry Clarke committed
1055
        XdmfErrorMessage("Unknown Topology Type = " << xdmfGrid->GetTopology()->GetTopologyType());
1056
        return 1;
1057
      }
Jerry Clarke's avatar
Jerry Clarke committed
1058
1059
1060
1061
1062
1063
      if( xdmfGrid->GetTopology()->GetTopologyType() != XDMF_MIXED){
        NodesPerElement = xdmfGrid->GetTopology()->GetNodesPerElement();
        if ( xdmfGrid->GetTopology()->GetConnectivity()->GetRank() == 2 )
          {
          NodesPerElement = xdmfGrid->GetTopology()->GetConnectivity()->GetDimension(1);
          }
1064
    
Jerry Clarke's avatar
Jerry Clarke committed
1065
1066
1067
1068
        /* Create Cell Type Array */
        Length = xdmfGrid->GetTopology()->GetConnectivity()->GetNumberOfElements();
        Connections = new XdmfInt64[ Length ];
        xdmfGrid->GetTopology()->GetConnectivity()->GetValues( 0, Connections, Length );
1069
    
Jerry Clarke's avatar
Jerry Clarke committed
1070
1071
        NumberOfElements = xdmfGrid->GetTopology()->GetShapeDesc()->GetNumberOfElements();
        ctp = cell_types = new int[ NumberOfElements ];
1072
    
Jerry Clarke's avatar
Jerry Clarke committed
1073
1074
        /* Create Cell Array */
        verts = vtkCellArray::New();
1075
    
Jerry Clarke's avatar
Jerry Clarke committed
1076
1077
1078
1079
        /* Get the pointer */
        connections = verts->WritePointer(
          NumberOfElements,
          NumberOfElements * ( 1 + NodesPerElement ));
1080
    
Jerry Clarke's avatar
Jerry Clarke committed
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
        /* Connections : N p1 p2 ... pN */
        /* i.e. Triangles : 3 0 1 2    3 3 4 5   3 6 7 8 */
        index = 0;
        for( j = 0 ; j < NumberOfElements; j++ )
          {
          *ctp++ = vType;
          *connections++ = NodesPerElement;
          for( i = 0 ; i < NodesPerElement; i++ )
            {
            *connections++ = Connections[index++];
            }
          }
    } else {
        // Mixed Topology
        /* Create Cell Type Array */
        vtkIdTypeArray *IdArray;
        vtkIdType RealSize;

        Length = xdmfGrid->GetTopology()->GetConnectivity()->GetNumberOfElements();
        Connections = new XdmfInt64[ Length ];
        xdmfGrid->GetTopology()->GetConnectivity()->GetValues( 0, Connections, Length );
        NumberOfElements = xdmfGrid->GetTopology()->GetShapeDesc()->GetNumberOfElements();
        ctp = cell_types = new int[ NumberOfElements ];
    
        /* Create Cell Array */
        verts = vtkCellArray::New();
    
        /* Get the pointer. Make it Big enough ... too big for now */
Jerry Clarke's avatar
Jerry Clarke committed
1109
        // cout << "::::: Length = " << Length << endl;
Jerry Clarke's avatar
Jerry Clarke committed
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
        connections = verts->WritePointer(
          NumberOfElements,
          Length);
        //   Length);
        /* Connections : N p1 p2 ... pN */
        /* i.e. Triangles : 3 0 1 2    3 3 4 5   3 6 7 8 */
        index = 0;
        for( j = 0 ; j < NumberOfElements; j++ )
          {
            switch ( Connections[index++] )
              {
              case  XDMF_POLYVERTEX :
                vType = VTK_POLY_VERTEX;
                NodesPerElement = Connections[index++];
                break;
              case  XDMF_POLYLINE :
                vType = VTK_POLY_LINE;
                NodesPerElement = Connections[index++];
                break;
              case  XDMF_POLYGON :
                vType = VTK_POLYGON;
                NodesPerElement = Connections[index++];
                break;
              case  XDMF_TRI :
                vType = VTK_TRIANGLE;
                NodesPerElement = 3;
                break;
              case  XDMF_QUAD :
                vType = VTK_QUAD;
                NodesPerElement = 4;
                break;
              case  XDMF_TET :
                vType = VTK_TETRA;
                NodesPerElement = 4;
                break;
              case  XDMF_PYRAMID :
                vType = VTK_PYRAMID;
                NodesPerElement = 5;
                break;
              case  XDMF_WEDGE :
                vType = VTK_WEDGE;
                NodesPerElement = 6;
                break;
              case  XDMF_HEX :
                vType = VTK_HEXAHEDRON;
                NodesPerElement = 8;
                break;
Jerry Clarke's avatar
Jerry Clarke committed
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
              case  XDMF_EDGE_3 :
                vType = VTK_QUADRATIC_EDGE ;
                NodesPerElement = 3;
                break;
              case  XDMF_TRI_6 :
                vType = VTK_QUADRATIC_TRIANGLE ;
                NodesPerElement = 6;
                break;
              case  XDMF_QUAD_8 :
                vType = VTK_QUADRATIC_QUAD ;
                NodesPerElement = 8;
                break;
              case  XDMF_TET_10 :
                vType = VTK_QUADRATIC_TETRA ;
                NodesPerElement = 10;
                break;
              case  XDMF_PYRAMID_13 :
                vType = VTK_QUADRATIC_PYRAMID ;
                NodesPerElement = 13;
                break;
              case  XDMF_WEDGE_15 :
                vType = VTK_QUADRATIC_WEDGE ;
                NodesPerElement = 15;
                break;
              case  XDMF_HEX_20 :
                vType = VTK_QUADRATIC_HEXAHEDRON ;
                NodesPerElement = 20;
                break;
Jerry Clarke's avatar
Jerry Clarke committed
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
              default :
                XdmfErrorMessage("Unknown Topology Type");
                return 1;
              }
          *ctp++ = vType;
          *connections++ = NodesPerElement;
          for( i = 0 ; i < NodesPerElement; i++ )
            {
            *connections++ = Connections[index++];
            }
          }
    // Resize the Array to the Proper Size
    IdArray = verts->GetData();
    RealSize = index - 1;
Jerry Clarke's avatar
Jerry Clarke committed
1199
    vtkDebugWithObjectMacro(this->Reader, "Resizing to " << RealSize << " elements");
Jerry Clarke's avatar
Jerry Clarke committed
1200
1201
    IdArray->Resize(RealSize);
    }
1202
1203
1204
1205
1206
1207
1208
    delete [] Connections;
    vGrid->SetCells(cell_types, verts);
    /* OK, because of reference counting */
    verts->Delete();
    delete [] cell_types;
    vGrid->Modified();
    }  // if( xdmfGrid->GetClass() == XDMF_UNSTRUCTURED ) 
Jerry Clarke's avatar
Jerry Clarke committed
1209
1210
  else if( xdmfGrid->GetTopology()->GetTopologyType() == XDMF_2DSMESH ||
           xdmfGrid->GetTopology()->GetTopologyType() == XDMF_3DSMESH )
1211
1212
1213
1214
1215
    {
    vtkDebugWithObjectMacro(this->Reader, << "Setting Extents for vtkStructuredGrid");
    vtkStructuredGrid  *vGrid = vtkStructuredGrid::SafeDownCast(output);
    vGrid->SetExtent(upext);    
    } 
Jerry Clarke's avatar
Jerry Clarke committed
1216
1217
  else if (xdmfGrid->GetTopology()->GetTopologyType() == XDMF_2DCORECTMESH ||
           xdmfGrid->GetTopology()->GetTopologyType() == XDMF_3DCORECTMESH ) 
1218
1219
1220
1221
1222
1223
1224
1225
    {
#ifdef USE_IMAGE_DATA
    vtkImageData *idata = vtkImageData::SafeDownCast(output);
#else
    vtkUniformGrid *idata = vtkUniformGrid::SafeDownCast(output);
#endif
    idata->SetExtent(upext);
    }
Jerry Clarke's avatar
Jerry Clarke committed
1226
1227
  else if ( xdmfGrid->GetTopology()->GetTopologyType() == XDMF_2DRECTMESH ||
            xdmfGrid->GetTopology()->GetTopologyType() == XDMF_3DRECTMESH )
1228
1229
1230
1231
1232
1233
1234
    {
    vtkRectilinearGrid *vGrid = vtkRectilinearGrid::SafeDownCast(output);
    vGrid->SetExtent(upext);    
    }
  else
    {
    vtkErrorWithObjectMacro(this->Reader,"Do not understand topology type: " 
Jerry Clarke's avatar
Jerry Clarke committed
1235
                            << xdmfGrid->GetTopology()->GetTopologyType());
1236
1237
1238
    }
  // Read Geometry
  if( ( Geometry->GetGeometryType() == XDMF_GEOMETRY_X_Y_Z ) ||
1239
      ( Geometry->GetGeometryType() == XDMF_GEOMETRY_XYZ ) ||
1240
      ( Geometry->GetGeometryType() == XDMF_GEOMETRY_X_Y ) ||
1241
      ( Geometry->GetGeometryType() == XDMF_GEOMETRY_XY ) )
1242
1243
1244
1245
1246
1247
1248
1249
    {
    XdmfInt64   Length;
    vtkPoints   *Points;
    vtkPointSet *Pointset = vtkPointSet::SafeDownCast(output);
    
    // Special flag, for structured data
    int structured_grid = 0;
    if ( vtkStructuredGrid::SafeDownCast(output) )
1250
      {
1251
1252
      structured_grid = 1;
      }
1253

1254
1255
1256
1257
1258
1259
1260
1261
1262
    Points = Pointset->GetPoints();
    if( !Points )
      {
      vtkDebugWithObjectMacro(this->Reader,<<  "Creating vtkPoints" );
      Points = vtkPoints::New();
      Pointset->SetPoints( Points );
      // OK Because of Reference Counting
      Points->Delete();
      }
1263

1264
1265
1266
    if( Geometry->GetPoints() )
      {
      if( Points )
1267
        {
1268
        if ( Geometry->GetPoints()->GetNumberType() == XDMF_FLOAT32_TYPE )
1269
          {
1270
          if ( Points->GetData()->GetDataType() != VTK_FLOAT)
1271
            {
1272
1273
1274
1275
            vtkFloatArray* da = vtkFloatArray::New();
            da->SetNumberOfComponents(3);
            Points->SetData(da);
            da->Delete();
1276
            }
1277
1278
1279
1280
          }
        else // means == XDMF_FLOAT64_TYPE
          {
          if ( Points->GetData()->GetDataType() != VTK_DOUBLE )
1281
            {
1282
1283