vtkXdmfReader.cxx 109 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
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkCellArray.h"
59
#include "vtkCharArray.h"
60
#include "vtkXMLParser.h"
61
#include "vtkImageData.h"
62
#include "vtkUniformGrid.h"
63
#include "vtkMultiBlockDataSet.h"
64
65
#include "vtkCompositeDataPipeline.h"
#include "vtkMultiProcessController.h"
66
#include "vtkDataObjectTypes.h"
67
#include "vtkSmartPointer.h"
68

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

80
#include <sys/stat.h>
81
82
#include <vtkstd/set>
#include <vtkstd/map>
83
84
#include <vtkstd/string>
#include <vtkstd/vector>
85
#include <vtksys/SystemTools.hxx>
86
#include <assert.h>
87
88
#include <functional>
#include <algorithm>
89
90

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

92
//----------------------------------------------------------------------------
Andy Cedilnik's avatar
Andy Cedilnik committed
93
vtkStandardNewMacro(vtkXdmfReader);
94
vtkCxxRevisionMacro(vtkXdmfReader, "1.72");
95

96
//----------------------------------------------------------------------------
97
vtkCxxSetObjectMacro(vtkXdmfReader,Controller,vtkMultiProcessController);
98
99
100
101
102
103
104
105

#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
106

107
108
109
#define vtkMAX(x, y) (((x)>(y))?(x):(y))
#define vtkMIN(x, y) (((x)<(y))?(x):(y))

110
#define PRINT_EXTENT(x) "[" << (x)[0] << " " << (x)[1] << " " << (x)[2] << " " << (x)[3] << " " << (x)[4] << " " << (x)[5] << "]" 
111
//----------------------------------------------------------------------------
112
113
114
class vtkXdmfReaderGrid
{
public:
115
  //
116
117
  vtkXdmfReaderGrid() 
  {
Jerry Clarke's avatar
Jerry Clarke committed
118
119
120
      this->XMGrid = 0;
      this->DataDescription = 0;
      this->Enabled = 0;
121
122

      // this->Enabled = 1;
Jerry Clarke's avatar
Jerry Clarke committed
123
124
125
      this->vtkType = -1;
      this->Time = -1.0;
      this->TimeIndex = 0;
126
127
      this->isTemporal = 0; // 1 if Temporal 2 if Tempoal Collection
      this->isCollection = 0;
128
      this->isParallel = 0;
129

130
131
  }

132
  ~vtkXdmfReaderGrid()
133
134
  {
    delete this->XMGrid;
135
    vtkstd::vector<vtkXdmfReaderGrid*>::iterator it;
136
137
    for (it = Children.begin(); it != Children.end(); it++)
      {
138
      delete *it;
139
140
141
142
143
      }
  }

  vtkXdmfReaderGrid* GetChild(const char *childName);
  vtkXdmfReaderGrid* GetChild(int idx);
144
145
146
147
148
149
150
151
  vtkInformation* GetInformation()
    {
    if (!this->Information) 
      {
      this->Information = vtkSmartPointer<vtkInformation>::New();
      }
    return this->Information;
    }
152
153
154

  XdmfGrid       *XMGrid;
  XdmfDataDesc   *DataDescription;
155
156
157
  XdmfFloat64   Time;
  XdmfInt32     TimeIndex;
  XdmfInt32     isTemporal;
158
  XdmfInt32     isCollection;
159
  XdmfInt32     isParallel; // Read in parallel if possible
160
  vtkstd::string Name;
161
162
  int Enabled;
  int vtkType;
163

164
  vtkstd::vector<vtkXdmfReaderGrid*> Children;
165
  vtkSmartPointer<vtkInformation> Information;
166
167
168
};

//----------------------------------------------------------------------------
169
class vtkXdmfReaderMatchName : public vtkstd::binary_function<vtkXdmfReaderGrid *, const char *, bool>
170
{
171
172
  public:
    bool operator()(vtkXdmfReaderGrid *child, const char *name) const
173
    {
174
      return (child->Name==name);
175
    }
176
177
178
179
180
181
182
183
184
185
186
187
};
//----------------------------------------------------------------------------
vtkXdmfReaderGrid* vtkXdmfReaderGrid::GetChild(const char *gridName)
{
  vtkstd::vector<vtkXdmfReaderGrid *>::iterator it = 
    vtkstd::find_if(this->Children.begin(), this->Children.end(), 
    vtkstd::bind2nd(vtkXdmfReaderMatchName(),gridName));
  if (it!=this->Children.end()) 
  {
    return *it;
  }
  return NULL;
188
189
}

190
//----------------------------------------------------------------------------
191
vtkXdmfReaderGrid* vtkXdmfReaderGrid::GetChild(int idx)
192
{
193
  if ( idx<0 || idx>=(int)this->Children.size())
194
    {
195
    return NULL;
196
    }
197
198
199
  return this->Children[idx];
/*
  vtkstd::vector<vtkXdmfReaderGrid *>::iterator it;
200
  int cnt = 0;
201
  for ( it = this->Children.begin(); it != this->Children.end(); ++ it )
202
    {
203
204
    if ( cnt == idx )
      {
205
      return *it;
206
207
      }
    cnt ++;
208
    }
209
  return NULL;
210
*/
211
212
}

213
//============================================================================
214
class vtkXdmfReaderInternal
215
216
{
public:
217
  vtkXdmfReaderInternal()
Dave Demarle's avatar
Dave Demarle committed
218
  {
219
220
221
    this->DataItem = NULL;
    this->ArrayConverter = vtkXdmfDataArray::New();
    this->Data = NULL;
222
    this->DsmBuffer = NULL;
223
    this->InputString = 0;
224
    this->InputStringLength = 0;
225
226
    // this->ParallelLevel = 0;
    this->ParallelLevels.clear();
227
    this->LargestLevel = 0;
228
229
    this->UpdatePiece     = 0;
    this->UpdateNumPieces = 1;
230
    this->mostChildren = 0;
231
232
233
234
235
  }

  ~vtkXdmfReaderInternal()
  {
    if ( this->Data )
Dave Demarle's avatar
Dave Demarle committed
236
      {
237
238
239
240
241
242
243
      delete this->Data;
      this->Data = NULL;
      }    
    if ( this->DataItem )
      {
      delete this->DataItem;
      this->DataItem = 0;
Dave Demarle's avatar
Dave Demarle committed
244
      }
245
246
    this->ArrayConverter->Delete();
    this->ArrayConverter = NULL;
247
248
    delete [] this->InputString;
    this->InputString = 0;
Dave Demarle's avatar
Dave Demarle committed
249
  }
250

251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271

  // Returns the domain node for the domain with given name. If none such domain
  // exists, returns the 1st domain, if any.
  XdmfXmlNode GetDomain(const char* domainName)
    {
    if (domainName)
      {
      vtkstd::map<vtkstd::string, XdmfXmlNode>::iterator iter =
        this->DomainMap.find(domainName);
      if (iter != this->DomainMap.end())
        {
        return iter->second;
        }
      }
    if (this->DomainList.size() > 0)
      {
      return this->GetDomain(this->DomainList[0].c_str());
      }
    return 0;
    }

272
273
  vtkXdmfReaderGrid* GetGrid(const char* gridName);
  vtkXdmfReaderGrid* GetGrid(int idx);
274
  vtkXdmfReaderGrid *AddGrid(
275
276
    vtkXdmfReaderGrid *parent,
    const char *gridName);
277
  void DeleteChildren(vtkXdmfReaderGrid* parent);
278

279
280
  // Temporary method to update the list of arrays provided by the grid.
  int UpdateArrays(vtkXdmfReaderGrid *grid);
281
  int RequestGridInformation(vtkXdmfReaderGrid *grid, vtkInformation *destInfo);
282
  int FindParallelism(vtkXdmfReaderGrid *grid = 0);
283

284
285
286
  int RequestGridData(/*const char* currentGridName,*/
    vtkXdmfReaderGrid *grid,
    vtkDataObject *output,
287
    int timeIndex,
288
289
    int isSubBlock,
    double progressS, double progressE);
290
  
291
 
292
  vtkstd::vector<XdmfFloat64> TimeValues;
293
  vtkstd::vector<vtkstd::string> DomainList;
294
  vtkstd::map<vtkstd::string, XdmfXmlNode> DomainMap;
295
  vtkXdmfReaderGrid *Data;
296
297
  // vtkXdmfReaderGrid *ParallelLevel;
  vtkstd::vector<vtkXdmfReaderGrid*> ParallelLevels;
298
  vtkXdmfReaderGrid *LargestLevel;
299
  vtkXdmfReader* Reader;
Jerry Clarke's avatar
Jerry Clarke committed
300
  XdmfDataItem *DataItem;
301
  XdmfDsmBuffer *DsmBuffer;
302
  char *InputString;
303
  unsigned int InputStringLength;
304
  unsigned int mostChildren;
305
306
307

  // For converting arrays from XDMF to VTK format
  vtkXdmfDataArray *ArrayConverter;
308

Utkarsh Ayachit's avatar
Utkarsh Ayachit committed
309
  unsigned int UpdatePiece;
310
  unsigned int UpdateNumPieces;
311

312
313
};

314
//----------------------------------------------------------------------------
315
vtkXdmfReaderGrid* vtkXdmfReaderInternal::GetGrid(const char* gridName)
316
{
317
  if (!this->Data)
318
    {
319
    return NULL;
320
    }
321
322
  return this->Data->GetChild(gridName);
}
323

324
325
326
327
//----------------------------------------------------------------------------
vtkXdmfReaderGrid* vtkXdmfReaderInternal::GetGrid(int idx)
{
  if (!this->Data)
328
    {
329
    return NULL;
330
    }
331
  return this->Data->GetChild(idx);
332
333
334
}

//----------------------------------------------------------------------------
335
vtkXdmfReaderGrid* 
336
  vtkXdmfReaderInternal::AddGrid(
337
338
    vtkXdmfReaderGrid* parent,    
    const char *gridName)
339
{
340
  if ( !parent || !gridName )
341
342
343
344
    {
    return 0;
    }

345
  //finds or makes up an ActualGrid in the global list
346
347
348
//  vtkXdmfReaderGrid* grid = parent->GetChild(gridName);
//  if ( !grid )
//    {
349
    vtkXdmfReaderGrid* grid = new vtkXdmfReaderGrid; 
350
351
352
    grid->Name = gridName;
    parent->Children.push_back(grid);
//    }
353
354
  return grid;
}
355
356
357
358
359
360
361
362
363
364
365
366
367
368
void vtkXdmfReaderInternal::DeleteChildren(vtkXdmfReaderGrid* parent)
{
  if (!parent)
    {
    return;
    }

  vtkstd::vector<vtkXdmfReaderGrid*>::iterator it;
  for (it = parent->Children.begin(); it != parent->Children.end(); it++)
    {
    delete *it;
    }
  parent->Children.clear();
}
369
370
371
372
373
374
375
376
377
378
379

//============================================================================
class vtkXdmfReaderTester : public vtkXMLParser
{
public:
  vtkTypeMacro(vtkXdmfReaderTester, vtkXMLParser);
  static vtkXdmfReaderTester* New();
  int TestReadFile()
    {
      this->Valid = 0;
      if(!this->FileName)
380
381
382
        {
        return 0;
        }
383
384
385

      ifstream inFile(this->FileName);
      if(!inFile)
386
        {
387
        return 0;
388
        }
389

390
391
392
393
394
395
396
397
398
399
400
401
      this->SetStream(&inFile);
      this->Done = 0;

      this->Parse();

      if(this->Done && this->Valid )
        {
        return 1;
        }
      return 0;
    }
  void StartElement(const char* name, const char**)
402
    {
403
404
405
406
407
      this->Done = 1;
      if(strcmp(name, "Xdmf") == 0)
        {
        this->Valid = 1;
        }
408
409
    }

410
411
protected:
  vtkXdmfReaderTester()
412
    {
413
414
      this->Valid = 0;
      this->Done = 0;
415
    }
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443

private:
  void ReportStrayAttribute(const char*, const char*, const char*) {}
  void ReportMissingAttribute(const char*, const char*) {}
  void ReportBadAttribute(const char*, const char*, const char*) {}
  void ReportUnknownElement(const char*) {}
  void ReportXmlParseError() {}

  int ParsingComplete() { return this->Done; }
  int Valid;
  int Done;
  vtkXdmfReaderTester(const vtkXdmfReaderTester&); // Not implemented
  void operator=(const vtkXdmfReaderTester&); // Not implemented
};

vtkStandardNewMacro(vtkXdmfReaderTester);

//============================================================================
vtkXdmfReader::vtkXdmfReader()
{  
  this->Internals = new vtkXdmfReaderInternal;
  this->Internals->Reader = this;

  this->DOM = 0;

  this->DomainName = 0;
  this->GridName = 0;
  this->NumberOfEnabledActualGrids=0;
444
  this->DsmBuffer = 0;
445
446
  
  for (int i = 0; i < 3; i ++ )
447
    {
448
    this->Stride[i] = 1;
449
    }
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466

  this->Controller = 0;
  this->SetController(vtkMultiProcessController::GetGlobalController());

  // Setup the selection callback to modify this object when an array
  // selection is changed.
  this->PointDataArraySelection = vtkDataArraySelection::New();
  this->CellDataArraySelection = vtkDataArraySelection::New();
  this->SelectionObserver = vtkCallbackCommand::New();
  this->SelectionObserver->SetCallback(
    &vtkXdmfReader::SelectionModifiedCallback);
  this->SelectionObserver->SetClientData(this);
  this->PointDataArraySelection->AddObserver(vtkCommand::ModifiedEvent,
                                             this->SelectionObserver);
  this->CellDataArraySelection->AddObserver(vtkCommand::ModifiedEvent,
                                            this->SelectionObserver);

467
468
469
470
  this->OutputVTKType  = -1;
  this->OutputTemporal = 0;
  this->TimeStep       = 0;
  this->ActualTimeStep = 0;
471
472
  this->TimeStepRange[0] = 0;
  this->TimeStepRange[1] = 0;
473
  // this->DebugOn();
474
475
}

476
//----------------------------------------------------------------------------
477
vtkXdmfReader::~vtkXdmfReader()
478
{
479
480
481
482
483
484
  this->CellDataArraySelection->RemoveObserver(this->SelectionObserver);
  this->PointDataArraySelection->RemoveObserver(this->SelectionObserver);
  this->SelectionObserver->Delete();
  this->CellDataArraySelection->Delete();
  this->PointDataArraySelection->Delete();

485
486
  delete [] this->DomainName;
  this->DomainName = 0;
487
  
488
  delete this->Internals;
489

490
  if ( this->DOM )
491
    {
492
    delete this->DOM;
Jerry Clarke's avatar
Jerry Clarke committed
493
    }
494

495
496
  H5garbage_collect();  
  this->SetController(0);
Jerry Clarke's avatar
Jerry Clarke committed
497
498
}

499
500
501
502
503
504
505
506
507
508
void
vtkXdmfReader::SetDsmBuffer(void *Bufp){
    this->DsmBuffer = (XdmfDsmBuffer *)Bufp;
}

void *
vtkXdmfReader::GetDsmBuffer(){
    return(this->DsmBuffer);
}

509
//----------------------------------------------------------------------------
510
511
void vtkXdmfReader::SelectionModifiedCallback(vtkObject*, unsigned long,
                                              void* clientdata, void*)
512
{
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
  static_cast<vtkXdmfReader*>(clientdata)->Modified();
}

//----------------------------------------------------------------------------
int vtkXdmfReader::GetNumberOfPointArrays()
{
  return this->PointDataArraySelection->GetNumberOfArrays();
}

//----------------------------------------------------------------------------
int vtkXdmfReader::GetNumberOfCellArrays()
{
  return this->CellDataArraySelection->GetNumberOfArrays();
}

//----------------------------------------------------------------------------
const char* vtkXdmfReader::GetPointArrayName(int index)
{
  return this->PointDataArraySelection->GetArrayName(index);
}

//----------------------------------------------------------------------------
const char* vtkXdmfReader::GetCellArrayName(int index)
{
  return this->CellDataArraySelection->GetArrayName(index);
}

//----------------------------------------------------------------------------
int vtkXdmfReader::GetPointArrayStatus(const char* name)
{
  return this->PointDataArraySelection->ArrayIsEnabled(name);
}

//----------------------------------------------------------------------------
int vtkXdmfReader::GetCellArrayStatus(const char* name)
{
  return this->CellDataArraySelection->ArrayIsEnabled(name);
}

//----------------------------------------------------------------------------
void vtkXdmfReader::SetPointArrayStatus(const char* name, int status)
{
  vtkDebugMacro("Set point array \"" << name << "\" status to: " << status);
  if(status)
557
    {
558
    this->PointDataArraySelection->EnableArray(name);
559
    }
560
  else
561
    {
562
    this->PointDataArraySelection->DisableArray(name);
563
    }
564
565
566
567
568
569
570
}

//----------------------------------------------------------------------------
void vtkXdmfReader::SetCellArrayStatus(const char* name, int status)
{
  vtkDebugMacro("Set cell array \"" << name << "\" status to: " << status);
  if(status)
571
    {
572
    this->CellDataArraySelection->EnableArray(name);
573
    }
574
575
576
577
578
  else
    {
    this->CellDataArraySelection->DisableArray(name);
    }
}
579

580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
//----------------------------------------------------------------------------
void vtkXdmfReader::EnableAllArrays()
{
  vtkDebugMacro("Enable all point and cell arrays");
  this->PointDataArraySelection->EnableAllArrays();
  this->CellDataArraySelection->EnableAllArrays();
}

//----------------------------------------------------------------------------
void vtkXdmfReader::DisableAllArrays()
{
  vtkDebugMacro("Disable all point and cell arrays");
  this->PointDataArraySelection->DisableAllArrays();
  this->CellDataArraySelection->DisableAllArrays();
}

//----------------------------------------------------------------------------
int vtkXdmfReader::GetNumberOfParameters()
{
  if(!this->DOM) 
600
    {
601
    return(-1);
602
    }
603
604
605
606
607
608
609
610
611
612
  // return(this->DOM->FindNumberOfParameters());
  return(0);
}

//----------------------------------------------------------------------------
int vtkXdmfReader::GetParameterType(const char *vtkNotUsed(parameterName))
{
  /*
    XdmfParameter *Param;
    if(!this->DOM) 
613
    {
614
615
616
617
618
619
620
    return(0);
    }
    Param = this->DOM->FindParameter(parameterName);
    if(Param) 
    {
    return(Param->GetParameterType());
    } 
621
    else 
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
    {
    return(0);
    }
  */
  return(0);
}
//----------------------------------------------------------------------------
const char *vtkXdmfReader::GetParameterTypeAsString(const char *vtkNotUsed(parameterName))
{
  /*
    if (this->GetParameterType(parameterName) == XDMF_PARAMETER_RANGE_TYPE) 
    {
    return("RANGE");
    } 
  */
  return("LIST");
}
//----------------------------------------------------------------------------
int vtkXdmfReader::GetParameterType(int vtkNotUsed(index))
{
  /*
    XdmfParameter *Param;
    if(!this->DOM) 
    {
    return(0);
    }
    Param = this->DOM->GetParameter(index);
    if(Param) 
    {
    return(Param->GetParameterType());
    } 
    else 
    {
    return(0);
    }
  */
  return(0);
}
660

661
662
663
664
665
//----------------------------------------------------------------------------
const char *vtkXdmfReader::GetParameterTypeAsString(int vtkNotUsed(index))
{
  /*
    if (this->GetParameterType(index) == XDMF_PARAMETER_RANGE_TYPE) 
666
    {
667
    return("RANGE");
668
    } 
669
670
671
672
673
674
675
676
677
678
679
  */
  return("LIST");
}

//----------------------------------------------------------------------------
int vtkXdmfReader::GetParameterRange(int vtkNotUsed(index), int vtkNotUsed(Shape)[3])
{
  /*
    XdmfParameter *Param;
    XdmfArray  *Parray;
    if(!this->DOM) 
680
    {
681
    return(0);
682
    }
683
684
    Param = this->DOM->GetParameter(index);
    if(Param) 
685
    {
686
687
688
689
690
691
692
693
694
695
    if( Param->GetParameterType() == XDMF_PARAMETER_RANGE_TYPE )
    {
    Parray = Param->GetArray();
    Shape[0] = Parray->GetValueAsInt64(0);
    Shape[1] = Parray->GetValueAsInt64(1);
    Shape[2] = Parray->GetValueAsInt64(2);
    } else {
    Shape[0] = 0;
    Shape[1] = 1;
    Shape[2] = Param->GetNumberOfElements();
696
    }
697
698
699
700
701
702
703
704
705
706
707
708
709
    return(Shape[2]);
    }
  */
  return(0);
}

//----------------------------------------------------------------------------
int vtkXdmfReader::GetParameterRange(const char *vtkNotUsed(parameterName), int vtkNotUsed(Shape)[3])
{
  /*
    XdmfParameter *Param;
    XdmfArray  *Parray;
    if(!this->DOM) 
710
    {
711
    return(0);
712
    }
713
714
    Param = this->DOM->FindParameter(parameterName);
    if(Param) 
715
    {
716
    if( Param->GetParameterType() == XDMF_PARAMETER_RANGE_TYPE )
717
    {
718
719
720
721
722
723
724
725
726
727
    Parray = Param->GetArray();
    Shape[0] = Parray->GetValueAsInt64(0);
    Shape[1] = Parray->GetValueAsInt64(1);
    Shape[2] = Parray->GetValueAsInt64(2);
    } 
    else 
    {
    Shape[0] = 0;
    Shape[1] = 1;
    Shape[2] = Param->GetNumberOfElements();
728
    }
729
730
731
732
733
734
735
736
737
738
739
740
741
    return(Shape[2]);
    }
  */
  return(0);
}

//----------------------------------------------------------------------------
const char *vtkXdmfReader::GetParameterRangeAsString(int vtkNotUsed(index))
{
  /*
    int Range[3];
    ostrstream StringOutput;
    if(this->GetParameterRange(index, Range) <= 0)
742
    {
743
    return(NULL);
744
    }
745
746
747
748
749
750
    StringOutput << ICE_64BIT_CAST Range[0] << " ";
    StringOutput << ICE_64BIT_CAST Range[1] << " ";
    StringOutput << ICE_64BIT_CAST Range[2] << ends;
    return(StringOutput.str());
  */
  return(0);
751
}
752

753
754
//----------------------------------------------------------------------------
const char *vtkXdmfReader::GetParameterRangeAsString(const char *vtkNotUsed(parameterName))
755
{
756
757
758
759
760
761
762
763
764
765
766
767
768
769
  /*
    int Range[3];
    ostrstream StringOutput;
    if (this->GetParameterRange(parameterName, Range) <= 0) 
    {
    return(NULL);
    }
    StringOutput << ICE_64BIT_CAST Range[0] << " ";
    StringOutput << ICE_64BIT_CAST Range[1] << " ";
    StringOutput << ICE_64BIT_CAST Range[2] << ends;
    return(StringOutput.str());
  */
  return(0);
}
770

771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
//----------------------------------------------------------------------------
const char *vtkXdmfReader::GetParameterName(int vtkNotUsed(index))
{
  /*
    XdmfParameter *Param;
    if(!this->DOM) 
    {
    return(0);
    }
    Param = this->DOM->GetParameter(index);
    if(Param) 
    {
    return(Param->GetParameterName());
    } 
    else 
    {
    return(0);
    }
  */
  return(0);
}

//----------------------------------------------------------------------------
int vtkXdmfReader::SetParameterIndex(int vtkNotUsed(Index), int vtkNotUsed(CurrentIndex)) 
{
  /*
    XdmfParameter *Param;
    if(!this->DOM) 
    {
    return(0);
    }
    Param = this->DOM->GetParameter(Index);
    if(!Param) 
    {
    return(-1);
    }
    this->Modified();
    return(Param->SetCurrentIndex(CurrentIndex));
  */
  return(0);
}
812

813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
//----------------------------------------------------------------------------
int vtkXdmfReader::GetParameterIndex(int vtkNotUsed(Index)) 
{
  /*
    XdmfParameter *Param;
    if(!this->DOM) 
    {
    return(0);
    }
    Param = this->DOM->GetParameter(Index);
    if(!Param) 
    {
    return(-1);
    }
    return(Param->GetCurrentIndex());
  */
  return(0);
}
831

832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
//----------------------------------------------------------------------------
int vtkXdmfReader::SetParameterIndex(const char *vtkNotUsed(ParameterName),
                                     int vtkNotUsed(CurrentIndex)) 
{
  /*
    XdmfParameter *Param;
    int Status=-1;
    if(!this->DOM) 
    {
    return(0);
    }
    for(int i=0 ; i < this->DOM->FindNumberOfParameters() ;  i++)
    {
    Param = this->DOM->GetParameter(i);
    if(!Param) 
    {
    return(-1);
    }
    if(XDMF_WORD_CMP(Param->GetParameterName(), ParameterName))
    {
    Status = Param->SetCurrentIndex(CurrentIndex);
    this->Modified();
    if(Status <= 0 ) 
    {
    return(Status);
    }
    }
    }
    return(Status);
  */
  return(0);
}
864

865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
//----------------------------------------------------------------------------
int vtkXdmfReader::GetParameterIndex(const char *vtkNotUsed(parameterName)) 
{
  /*
    XdmfParameter *Param;
    if(!this->DOM) 
    {
    return(0);
    }
    Param = this->DOM->FindParameter(parameterName);
    if(!Param) 
    {
    return(-1);
    }
    return(Param->GetCurrentIndex());
  */
  return(0);
}
883

884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
//----------------------------------------------------------------------------
int vtkXdmfReader::GetParameterLength(int vtkNotUsed(index))
{
  /*
    XdmfParameter *Param;
    if(!this->DOM) 
    {
    return(0);
    }
    Param = this->DOM->GetParameter(index);
    if(Param) 
    {
    return(Param->GetNumberOfElements());
    } 
    else 
    {
    return(0);
    }
  */
  return(0);
}

//----------------------------------------------------------------------------
int vtkXdmfReader::GetParameterLength(const char *vtkNotUsed(parameterName))
{
  /*
    XdmfParameter *Param;
    if(!this->DOM) 
    {
    return(0);
    }
    Param = this->DOM->FindParameter(parameterName);
    if(Param) 
    {
    return(Param->GetNumberOfElements());
    } 
    else 
    {
    return(0);
923
    }
924
  */
Berk Geveci's avatar
Berk Geveci committed
925
  return 0;
926
}
927

928
929
//----------------------------------------------------------------------------
const char *vtkXdmfReader::GetParameterValue(const char *vtkNotUsed(parameterName)) 
930
{
931
932
933
  /*
    XdmfParameter *Param;
    if(!this->DOM) 
934
    {
935
    return(0);
936
    }
937
938
    Param = this->DOM->FindParameter(parameterName);
    if(!Param) 
939
    {
940
    return(0);
941
    }
942
943
944
945
    Param->Update();
    return(Param->GetParameterValue());
  */
  return 0;
Jerry Clarke's avatar
Jerry Clarke committed
946
947
}

948
949
//----------------------------------------------------------------------------
const char *vtkXdmfReader::GetParameterValue(int vtkNotUsed(index)) 
950
{
951
952
953
  /*
    XdmfParameter *Param;
    if(!this->DOM) 
954
    {
955
956
957
958
959
960
961
962
963
964
965
966
    return(0);
    }
    Param = this->DOM->GetParameter(index);
    if(!Param) 
    {
    return(0);
    }
    Param->Update();
    return(Param->GetParameterValue());
  */
  return 0;
}
967

968
969
970
971
972
//----------------------------------------------------------------------------
int vtkXdmfReader::GetNumberOfDomains()
{
  return this->Internals->DomainList.size();
}
973

974
975
976
977
978
979
//----------------------------------------------------------------------------
void vtkXdmfReader::SetDomainName(const char* domain)
{
  if ( this->DomainName == domain )
    {
    return;
980
    }
981
  if ( this->DomainName && domain && strcmp(this->DomainName, domain) == 0 )
982
    {
983
    return;
Jerry Clarke's avatar
Jerry Clarke committed
984
    }
985
986
987
988

  delete [] this->DomainName;
  this->DomainName = 0;
  if (domain)
989
990
991
992
    {
    this->DomainName = new char [ strlen(domain) + 1 ];
    strcpy(this->DomainName, domain);
    }
993
994
995
996

  // Since selected domain changed, we need to populate the grids available in
  // this domain.
  this->UpdateRootGrid();
997
}
Jerry Clarke's avatar
Jerry Clarke committed
998

999
1000
//----------------------------------------------------------------------------
const char* vtkXdmfReader::GetDomainName(int idx)
1001
{
1002
1003
  return this->Internals->DomainList[idx].c_str();
}
1004

1005
1006
1007
1008
1009
1010
//----------------------------------------------------------------------------
void vtkXdmfReader::SetGridName(const char* grid)
{
  this->DisableAllGrids();
  this->EnableGrid(grid);
}
1011

1012
1013
1014
1015
//----------------------------------------------------------------------------
int vtkXdmfReader::GetNumberOfGrids()
{
  if (this->Internals->Data)
1016
    {
1017
    return this->Internals->Data->Children.size();
1018
    }
1019
  return 0;
1020
1021
1022
}

//----------------------------------------------------------------------------
1023
const char* vtkXdmfReader::GetGridName(int idx)
1024
{
1025
  if ( idx<0 || idx>=(int)this->Internals->Data->Children.size())
1026
    {
1027
1028
    return 0;
    }
1029
1030
1031
  return this->Internals->Data->Children[idx]->Name.c_str();
/*
  vtkstd::vector<vtkXdmfReaderGrid *>::iterator it;
1032
1033
1034
1035
1036
1037
  int cnt = 0;
  for ( it = this->Internals->Data->Children.begin();
        it != this->Internals->Data->Children.end();
        ++ it )
    {
    if ( cnt == idx )
1038
      {
1039
      return (*it)->Name.c_str();
1040
      }
1041
    cnt ++;
Jerry Clarke's avatar
Jerry Clarke committed
1042
    }
1043
  return 0;
1044
*/
1045
}
1046

1047
1048
1049
1050
//----------------------------------------------------------------------------
int vtkXdmfReader::GetGridIndex(const char* name)
{
  if ( !name )
1051
    {
1052
1053
    return -1;
    }
1054
  vtkstd::vector<vtkXdmfReaderGrid *>::iterator it;
1055
1056
1057
1058
1059
  int cnt = 0;
  for ( it = this->Internals->Data->Children.begin();
        it != this->Internals->Data->Children.end();
        ++ it )
    {
1060
    if ( (*it)->Name == name )
1061
1062
1063
1064
      {
      return cnt;
      }
    cnt ++;
1065
    }
1066

1067
  return -1;
1068
1069
1070
}

//----------------------------------------------------------------------------
1071
void vtkXdmfReader::EnableGrid(const char* name)
1072
{
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
  vtkDebugMacro("Enable grid " << name);
  vtkXdmfReaderGrid* grid = this->Internals->GetGrid(name);
  if ( !grid ) //work around an undo/redo crash
    {
    return;
    }
  if(!grid->Enabled)
    {
    ++this->NumberOfEnabledActualGrids;
    grid->Enabled = 1;
    this->Modified();
1084
    //this->UpdateInformation();
1085
    }
1086
1087
1088
}

//----------------------------------------------------------------------------
1089
void vtkXdmfReader::EnableGrid(int idx)
1090
{
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
  vtkDebugMacro("Enable grid " << idx);
  vtkXdmfReaderGrid* grid = this->Internals->GetGrid(idx);
  if ( !grid )
    {
    return;
    }
  
  if(!grid->Enabled)
    {
    ++this->NumberOfEnabledActualGrids;
    grid->Enabled = 1;
1102
1103
    //this->PointDataArraySelection->RemoveAllArrays();
    //this->CellDataArraySelection->RemoveAllArrays();
1104
    this->Modified();
1105
    //this->UpdateInformation();
1106
    }
1107
1108
}

1109
//----------------------------------------------------------------------------
1110
void vtkXdmfReader::EnableAllGrids()
1111
{
1112
  vtkDebugMacro("Enable all grids");
1113
  vtkstd::vector<vtkXdmfReaderGrid *>::iterator it;
1114
1115
1116
1117
1118
  int changed=0;
  for ( it = this->Internals->Data->Children.begin();
        it != this->Internals->Data->Children.end();
        ++ it )
    {
1119
    if(!(*it)->Enabled)
1120
      {
1121
      (*it)->Enabled = 1;
1122
1123
1124
1125
1126
1127
      ++this->NumberOfEnabledActualGrids;
      changed=1;
      }
    }
  if(changed)
    {
1128
1129
    //this->PointDataArraySelection->RemoveAllArrays();
    //this->CellDataArraySelection->RemoveAllArrays();
1130
    this->Modified();
1131
    //this->UpdateInformation();
1132
    }
1133
1134
1135
}

//----------------------------------------------------------------------------
1136
void vtkXdmfReader::DisableGrid(const char* name)
1137
{
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
  vtkDebugMacro("Disable grid " << name);
  vtkXdmfReaderGrid* grid = this->Internals->GetGrid(name);
  if ( !grid )
    {
    return;
    }
  
  if(grid->Enabled)
    {
    grid->Enabled = 0;
    --this->NumberOfEnabledActualGrids;
1149
1150
    //this->PointDataArraySelection->RemoveAllArrays();
    //this->CellDataArraySelection->RemoveAllArrays();
1151
1152

    this->Modified();
1153
    //this->UpdateInformation();
1154
    }
1155
1156
}

1157
//----------------------------------------------------------------------------
1158
void vtkXdmfReader::DisableGrid(int idx)
1159
{
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
  vtkDebugMacro("Disable grid " << idx);
  vtkXdmfReaderGrid* grid = this->Internals->GetGrid(idx);
  if ( !grid )
    {
    return;
    }
  
  if(grid->Enabled)
    {
    grid->Enabled = 0;
    --this->NumberOfEnabledActualGrids;
1171
1172
    //this->PointDataArraySelection->RemoveAllArrays();