forked from biddisco/pv-meshless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvtkH5PartReader.cxx
1582 lines (1520 loc) · 50.8 KB
/
vtkH5PartReader.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
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
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
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
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
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
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
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
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
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*=========================================================================
Project : pv-meshless
Module : vtkH5PartReader.h
Revision of last commit : $Rev: 884 $
Author of last commit : $Author: biddisco $
Date of last commit : $Date:: 2010-04-06 12:03:55 +0200 #$
Copyright (C) CSCS - Swiss National Supercomputing Centre.
You may use modify and and distribute this code freely providing
1) This copyright notice appears on all copies of source code
2) An acknowledgment appears with any substantial usage of the code
3) If this code is contributed to any other open source project, it
must not be reformatted such that the indentation, bracketing or
overall style is modified significantly.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
=========================================================================*/
// For PARAVIEW_USE_MPI
#include "vtkPVConfig.h"
#ifdef PARAVIEW_USE_MPI
#include "vtkMPI.h"
#include "vtkMPIController.h"
#include "vtkMPICommunicator.h"
#endif
#include "vtkDummyController.h"
//
#include "vtkH5PartReader.h"
//
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkDataArraySelection.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkDataArray.h"
//
#include "vtkCharArray.h"
#include "vtkUnsignedCharArray.h"
#include "vtkShortArray.h"
#include "vtkUnsignedShortArray.h"
#include "vtkLongArray.h"
#include "vtkUnsignedLongArray.h"
#include "vtkLongLongArray.h"
#include "vtkUnsignedLongLongArray.h"
#include "vtkIntArray.h"
#include "vtkUnsignedIntArray.h"
#include "vtkFloatArray.h"
#include "vtkDoubleArray.h"
#include "vtkCellArray.h"
#include "vtkOutlineSource.h"
#include "vtkAppendPolyData.h"
#include "vtkBoundingBox.h"
//
#include <vtksys/SystemTools.hxx>
#include <vtksys/RegularExpression.hxx>
#include <vector>
//
#include "vtkCharArray.h"
#include "vtkUnsignedCharArray.h"
#include "vtkCharArray.h"
#include "vtkShortArray.h"
#include "vtkUnsignedShortArray.h"
#include "vtkIntArray.h"
#include "vtkLongArray.h"
#include "vtkFloatArray.h"
#include "vtkDoubleArray.h"
#include "vtkSmartPointer.h"
#include "vtkExtentTranslator.h"
#include "vtkParticleBoxTreeBSP.h"
#include "vtkBoundingBox.h"
#include "vtkIdListCollection.h"
//
#include <functional>
#include <algorithm>
#include <numeric>
#include "H5Part.h"
//
#include "vtkBoundsExtentTranslator.h"
//
#include "Testing/TestUtils.h" // random class
//----------------------------------------------------------------------------
extern char H5PART_GROUPNAME_STEP[256];
//----------------------------------------------------------------------------
vtkCxxSetObjectMacro(vtkH5PartReader, Controller, vtkMultiProcessController);
//----------------------------------------------------------------------------
/*!
\ingroup h5part_utility
This function can be used to query the Type of a dataset
It is not used by the core H5Part library but is useful when
reading generic data from the file.
An example of usage would be (H5Tequal(datatype,H5T_NATIVE_FLOAT))
any NATIVE type can be used to test.
\return \c an hdf5 handle to the native type of the data
*/
static hid_t H5PartGetNativeDatasetType(H5PartFile *f, const char *name)
{
hid_t dataset, datatype, datatypen;
if (!f->timegroup)
{
H5PartSetStep(f,f->timestep); /* choose current step */
}
#if (!H5_USE_16_API && ((H5_VERS_MAJOR>1)||((H5_VERS_MAJOR==1)&&(H5_VERS_MINOR>=8))))
dataset=H5Dopen(f->timegroup, name, H5P_DEFAULT);
#else
dataset=H5Dopen(f->timegroup, name);
#endif
datatype = H5Dget_type(dataset);
datatypen = H5Tget_native_type(datatype, H5T_DIR_DEFAULT);
H5Tclose(datatype);
H5Dclose(dataset);
return datatypen;
}
//----------------------------------------------------------------------------
hid_t H5PartGetDiskShape(H5PartFile *f, hid_t dataset)
{
hid_t space = H5Dget_space(dataset);
if (H5PartHasView(f))
{
int r;
hsize_t stride, count;
hsize_t range[2];
/* so, is this selection inclusive or exclusive? */
range[0]=f->viewstart;
range[1]=f->viewend;
count = range[1]-range[0]; /* to be inclusive */
stride=1;
/* now we select a subset */
if (f->diskshape>0)
{
r=H5Sselect_hyperslab(f->diskshape,H5S_SELECT_SET,
range/* only using first element */,
&stride,&count,NULL);
}
/* now we select a subset */
r=H5Sselect_hyperslab(space,H5S_SELECT_SET,
range,&stride,&count,NULL);
if (r<0)
{
fprintf(stderr,"Abort: Selection Failed!\n");
return space;
}
}
return space;
}
//----------------------------------------------------------------------------
//#define JB_DEBUG__
#ifdef JB_DEBUG__
#define OUTPUTTEXT(a) std::cout << (a) << std::endl; std::cout.flush();
#undef vtkDebugMacro
#define vtkDebugMacro(a) \
{ \
if (this->UpdatePiece>=0) { \
vtkOStreamWrapper::EndlType endl; \
vtkOStreamWrapper::UseEndl(endl); \
vtkOStrStreamWrapper vtkmsg; \
vtkmsg << "P(" << this->UpdatePiece << "): " a << "\n"; \
OUTPUTTEXT(vtkmsg.str()); \
vtkmsg.rdbuf()->freeze(0); \
} \
}
#undef vtkErrorMacro
#define vtkErrorMacro(a) vtkDebugMacro(a)
#endif
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkH5PartReader);
//----------------------------------------------------------------------------
vtkH5PartReader::vtkH5PartReader()
{
this->SetNumberOfInputPorts(0);
//
this->NumberOfTimeSteps = 0;
this->TimeStep = 0;
this->ActualTimeStep = 0;
this->TimeStepTolerance = 1E-6;
this->CombineVectorComponents = 1;
this->UseStridedMultiComponentRead = 0;
this->MultiComponentArraysAsFieldData = 0;
this->GenerateVertexCells = 0;
this->FileName = NULL;
this->H5FileId = NULL;
this->Xarray = NULL;
this->Yarray = NULL;
this->Zarray = NULL;
this->StepName = NULL;
this->UpdatePiece = 0;
this->UpdateNumPieces = 0;
this->TimeOutOfRange = 0;
this->MaskOutOfTimeRangeOutput = 0;
this->IntegerTimeStepValues = 0;
this->IgnorePartitionBoxes = 0;
this->DisplayPartitionBoxes = 0;
this->DisplayPieceBoxes = 0;
this->UseLinearBoxPartitioning = 1;
this->RandomizePartitionExtents = 0;
this->PointDataArraySelection = vtkDataArraySelection::New();
this->ExtentTranslator = vtkBoundsExtentTranslator::New();
this->SetXarray("Coords_0");
this->SetYarray("Coords_1");
this->SetZarray("Coords_2");
this->Controller = NULL;
this->SetController(vtkMultiProcessController::GetGlobalController());
if (this->Controller == NULL) {
this->SetController(vtkSmartPointer<vtkDummyController>::New());
}
}
//----------------------------------------------------------------------------
vtkH5PartReader::~vtkH5PartReader()
{
this->CloseFile();
delete [] this->FileName;
this->FileName = NULL;
delete [] this->Xarray;
this->Xarray = NULL;
delete [] this->Yarray;
this->Yarray = NULL;
delete [] this->Zarray;
this->Zarray = NULL;
delete [] this->StepName;
this->StepName = NULL;
this->PointDataArraySelection->FastDelete();
this->PointDataArraySelection = 0;
this->ExtentTranslator->FastDelete();
this->SetController(NULL);
}
//----------------------------------------------------------------------------
bool vtkH5PartReader::HasStep(int Step)
{
if (!this->OpenFile())
{
return false;
}
if (H5PartHasStep(this->H5FileId, Step))
{
return true;
}
return false;
}
//----------------------------------------------------------------------------
void vtkH5PartReader::SetFileName(char *filename)
{
if (this->FileName == NULL && filename == NULL)
{
return;
}
if (this->FileName && filename && (!strcmp(this->FileName,filename)))
{
return;
}
delete [] this->FileName;
this->FileName = NULL;
if (filename)
{
this->FileName = vtksys::SystemTools::DuplicateString(filename);
this->SetFileModified();
}
this->Modified();
}
//----------------------------------------------------------------------------
void vtkH5PartReader::SetFileModified()
{
this->FileModifiedTime.Modified();
this->Modified();
}
//----------------------------------------------------------------------------
void vtkH5PartReader::CloseFile()
{
if (this->H5FileId != NULL)
{
H5PartCloseFile(this->H5FileId);
this->H5FileId = NULL;
}
}
//----------------------------------------------------------------------------
void vtkH5PartReader::CloseFileIntermediate()
{
}
//----------------------------------------------------------------------------
int vtkH5PartReader::OpenFile()
{
if (this->StepName != NULL) {
strcpy(H5PART_GROUPNAME_STEP, this->StepName);
}
if (!this->FileName)
{
vtkErrorMacro(<<"FileName must be specified.");
return 0;
}
if (FileModifiedTime>FileOpenedTime)
{
this->CloseFile();
}
if (!this->H5FileId)
{
this->H5FileId = H5PartOpenFile(this->FileName, H5PART_READ);
this->FileOpenedTime.Modified();
}
if (!this->H5FileId)
{
vtkErrorMacro(<< "Initialize: Could not open file " << this->FileName);
return 0;
}
return 1;
}
//----------------------------------------------------------------------------
int vtkH5PartReader::IndexOfVectorComponent(const char *name)
{
if (!this->CombineVectorComponents)
{
return 0;
}
//
vtksys::RegularExpression re1(".*_([0-9]+)");
if (re1.find(name))
{
int index = atoi(re1.match(1).c_str());
return index+1;
}
return 0;
}
//----------------------------------------------------------------------------
std::string vtkH5PartReader::NameOfVectorComponent(const char *name)
{
if (!this->CombineVectorComponents)
{
return name;
}
//
vtksys::RegularExpression re1("(.*)_[0-9]+");
if (re1.find(name))
{
return re1.match(1);
}
return name;
}
//----------------------------------------------------------------------------
int vtkH5PartReader::RequestInformation(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **vtkNotUsed(inputVector),
vtkInformationVector *outputVector)
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
//
this->UpdatePiece = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER());
this->UpdateNumPieces = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES());
//
outInfo->Set(CAN_HANDLE_PIECE_REQUEST(), 1);
bool NeedToReadInformation = (FileModifiedTime>FileOpenedTime || !this->H5FileId);
if (NeedToReadInformation)
{
if (!this->OpenFile())
{
return 0;
}
this->NumberOfTimeSteps = H5PartGetNumSteps(this->H5FileId);
H5PartSetStep(this->H5FileId, 0);
int nds = H5PartGetNumDatasets(this->H5FileId);
char name[512];
for (int i=0; i<nds; i++)
{
// return 0 for no, 1,2,3,4,5 etc for index (1 based offset)
H5PartGetDatasetName(this->H5FileId, i, name, 512);
this->PointDataArraySelection->AddArray(name);
}
this->TimeStepValues.assign(this->NumberOfTimeSteps, 0.0);
int validTimes = 0;
for (int i=0; i<this->NumberOfTimeSteps; ++i)
{
H5PartSetStep(this->H5FileId, i);
// Get the time value if it exists
h5part_int64_t numAttribs = H5PartGetNumStepAttribs(this->H5FileId);
if (numAttribs>0)
{
char attribName[128];
h5part_int64_t attribNameLength = 128;
h5part_int64_t attribType = 0;
h5part_int64_t attribNelem = 0;
for (h5part_int64_t a=0; a<numAttribs; a++)
{
h5part_int64_t status = H5PartGetStepAttribInfo (
this->H5FileId, a, attribName, attribNameLength,
&attribType, &attribNelem);
if (status==H5PART_SUCCESS && !strncmp("TimeValue",attribName,attribNameLength))
{
if (H5Tequal(attribType,H5T_NATIVE_DOUBLE) && attribNelem==1)
{
status=H5PartReadStepAttrib(this->H5FileId, attribName, &this->TimeStepValues[i]);
if (status==H5PART_SUCCESS)
{
validTimes++;
}
}
}
}
}
}
H5PartSetStep(this->H5FileId, 0);
if (this->NumberOfTimeSteps==0)
{
vtkErrorMacro(<<"No time steps in data");
return 0;
}
// if TIME information was either not present ot not consistent, then
// set something so that consumers of this data can iterate sensibly
if (this->IntegerTimeStepValues || (this->NumberOfTimeSteps>0 && this->NumberOfTimeSteps!=validTimes))
{
for (int i=0; i<this->NumberOfTimeSteps; i++)
{
// insert read of Time array here
this->TimeStepValues[i] = i;
}
}
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),
&this->TimeStepValues[0],
static_cast<int>(this->TimeStepValues.size()));
double timeRange[2];
timeRange[0] = this->TimeStepValues.front();
timeRange[1] = this->TimeStepValues.back();
if (this->TimeStepValues.size()>1)
{
this->TimeStepTolerance = 0.01*(this->TimeStepValues[1]-this->TimeStepValues[0]);
}
else
{
this->TimeStepTolerance = 1E-3;
}
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, 2);
//
// If the file has bounding box partition support
//
vtkIdType partitions = this->IgnorePartitionBoxes ? 0 : this->ReadBoundingBoxes();
if (partitions>0)
{
outInfo->Set(vtkBoundsExtentTranslator::META_DATA(), this->ExtentTranslator);
}
else {
this->PartitionCount.clear();
this->PartitionOffset.clear();
this->PieceId.clear();
this->PartitionBoundsTable.clear();
this->PartitionBoundsTableHalo.clear();
}
}
this->CloseFileIntermediate();
return 1;
}
//----------------------------------------------------------------------------
int GetVTKDataType(int datatype)
{
if (H5Tequal(datatype,H5T_NATIVE_FLOAT))
{
return VTK_FLOAT;
}
else if (H5Tequal(datatype,H5T_NATIVE_DOUBLE))
{
return VTK_DOUBLE;
}
else if (H5Tequal(datatype,H5T_NATIVE_SCHAR))
{
return VTK_CHAR;
}
else if (H5Tequal(datatype,H5T_NATIVE_UCHAR))
{
return VTK_UNSIGNED_CHAR;
}
else if (H5Tequal(datatype,H5T_NATIVE_SHORT))
{
return VTK_SHORT;
}
else if (H5Tequal(datatype,H5T_NATIVE_USHORT))
{
return VTK_UNSIGNED_SHORT;
}
else if (H5Tequal(datatype,H5T_NATIVE_INT))
{
return VTK_INT;
}
else if (H5Tequal(datatype,H5T_NATIVE_UINT))
{
return VTK_UNSIGNED_INT;
}
else if (H5Tequal(datatype,H5T_NATIVE_LONG))
{
return VTK_LONG;
}
else if (H5Tequal(datatype,H5T_NATIVE_ULONG))
{
return VTK_UNSIGNED_LONG;
}
else if (H5Tequal(datatype,H5T_NATIVE_LLONG))
{
return VTK_LONG_LONG;
}
else if (H5Tequal(datatype,H5T_NATIVE_ULLONG))
{
return VTK_UNSIGNED_LONG_LONG;
}
return VTK_VOID;
}
//----------------------------------------------------------------------------
template <class T1, class T2>
void CopyIntoTuple(int offset, vtkDataArray *source, vtkDataArray *dest)
{
vtkIdType N = source->GetNumberOfTuples();
T1 *sptr = static_cast<T1*>(source->GetVoidPointer(0));
T2 *dptr = static_cast<T2*>(dest->WriteVoidPointer(0,N)) + offset;
for (vtkIdType i=0; i<N; ++i) {
*dptr = *sptr++;
dptr += 3;
}
}
//----------------------------------------------------------------------------
template <class T2>
void vtkH5PartReader::CopyIntoVector(int offset, vtkDataArray *source, vtkDataArray *dest)
{
switch (source->GetDataType())
{
case VTK_CHAR:
case VTK_SIGNED_CHAR:
case VTK_UNSIGNED_CHAR:
CopyIntoTuple<char,T2>(offset, source, dest);
break;
case VTK_SHORT:
CopyIntoTuple<short int,T2>(offset, source, dest);
break;
case VTK_UNSIGNED_SHORT:
CopyIntoTuple<unsigned short int,T2>(offset, source, dest);
break;
case VTK_INT:
CopyIntoTuple<int,T2>(offset, source, dest);
break;
case VTK_UNSIGNED_INT:
CopyIntoTuple<unsigned int,T2>(offset, source, dest);
break;
case VTK_LONG:
CopyIntoTuple<long int,T2>(offset, source, dest);
break;
case VTK_UNSIGNED_LONG:
CopyIntoTuple<unsigned long int,T2>(offset, source, dest);
break;
case VTK_LONG_LONG:
CopyIntoTuple<long long,T2>(offset, source, dest);
break;
case VTK_UNSIGNED_LONG_LONG:
CopyIntoTuple<unsigned long long,T2>(offset, source, dest);
break;
case VTK_FLOAT:
CopyIntoTuple<float,T2>(offset, source, dest);
break;
case VTK_DOUBLE:
CopyIntoTuple<double,T2>(offset, source, dest);
break;
case VTK_ID_TYPE:
CopyIntoTuple<vtkIdType,T2>(offset, source, dest);
break;
default:
break;
vtkErrorMacro(<<"Unexpected data type");
}
}
//----------------------------------------------------------------------------
/*
std::pair<double, double> GetClosest(std::vector<double> &sortedlist, const double& val) const
{
std::vector<double>::const_iterator it = std::lower_bound(sortedlist.begin(), sortedlist.end(), val);
if (it == sortedlist.end()) return std::make_pair(sortedlist.back(), sortedlist.back());
else if (it == sortedlist.begin()) return std::make_pair(sortedlist.front(), sortedlist.front());
else return std::make_pair(*(it - 1), *(it));
}
*/
class H5PartToleranceCheck: public std::binary_function<double, double, bool>
{
public:
H5PartToleranceCheck(double tol) { this->tolerance = tol; }
double tolerance;
//
result_type operator()(first_argument_type a, second_argument_type b) const
{
bool result = (fabs(a-b)<=(this->tolerance));
return (result_type)result;
}
};
//----------------------------------------------------------------------------
#if (!H5_USE_16_API && ((H5_VERS_MAJOR>1)||((H5_VERS_MAJOR==1)&&(H5_VERS_MINOR>=8))))
#define h_params ,H5P_DEFAULT
#else
#define h_params
#endif
//----------------------------------------------------------------------------
int vtkH5PartReader::RequestData(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **vtkNotUsed(inputVector),
vtkInformationVector *outputVector)
{
vtkInformation *outInfo = outputVector->GetInformationObject(0);
vtkPolyData *output = vtkPolyData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
//
this->UpdatePiece = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER());
this->UpdateNumPieces = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES());
//
typedef std::map< std::string, std::vector<std::string> > FieldMap;
FieldMap scalarFields;
//
if (this->TimeStepValues.size()==0) return 0;
//
// Make sure that the user selected arrays for coordinates are represented
//
std::vector<std::string> coordarrays(3, "");
//
int N = this->PointDataArraySelection->GetNumberOfArrays();
for (int i=0; i<N; i++)
{
const char *name = this->PointDataArraySelection->GetArrayName(i);
// Do we want to load this array
bool processarray = false;
if (!vtksys::SystemTools::Strucmp(name,this->Xarray))
{
processarray = true;
coordarrays[0] = name;
}
if (!vtksys::SystemTools::Strucmp(name,this->Yarray))
{
processarray = true;
coordarrays[1] = name;
}
if (!vtksys::SystemTools::Strucmp(name,this->Zarray))
{
processarray = true;
coordarrays[2] = name;
}
if (this->PointDataArraySelection->ArrayIsEnabled(name))
{
processarray = true;
}
if (!processarray)
{
continue;
}
// make sure we cater for multi-component vector fields
int vectorcomponent;
if ((vectorcomponent=this->IndexOfVectorComponent(name))>0)
{
std::string vectorname = this->NameOfVectorComponent(name) + "_v";
FieldMap::iterator pos = scalarFields.find(vectorname);
if (pos==scalarFields.end())
{
std::vector<std::string> arraylist(1, name);
FieldMap::value_type element(vectorname, arraylist);
scalarFields.insert(element);
}
else
{
pos->second.reserve(vectorcomponent);
pos->second.resize(std::max((int)(pos->second.size()), vectorcomponent));
pos->second[vectorcomponent-1] = name;
}
}
else
{
std::vector<std::string> arraylist(1, name);
FieldMap::value_type element(name, arraylist);
scalarFields.insert(element);
}
}
//
FieldMap::iterator coordvector=scalarFields.end();
for (FieldMap::iterator pos=scalarFields.begin(); pos!=scalarFields.end(); ++pos)
{
if (pos->second.size()==3 &&
(pos->second[0]==coordarrays[0]) &&
(pos->second[1]==coordarrays[1]) &&
(pos->second[2]==coordarrays[2]))
{
// change the keyname of this entry to "coords" to ensure we use it as such
FieldMap::value_type element("Coords", pos->second);
scalarFields.erase(pos);
coordvector = scalarFields.insert(element).first;
break;
}
}
if (coordvector==scalarFields.end())
{
FieldMap::value_type element("Coords", coordarrays);
scalarFields.insert(element);
}
if (!this->MultiComponentArraysAsFieldData) {
FieldMap::iterator posx=scalarFields.find(coordarrays[0]);
if (posx!=scalarFields.end()) scalarFields.erase(posx);
FieldMap::iterator posy=scalarFields.find(coordarrays[1]);
if (posy!=scalarFields.end()) scalarFields.erase(posy);
FieldMap::iterator posz=scalarFields.find(coordarrays[2]);
if (posz!=scalarFields.end()) scalarFields.erase(posz);
}
//
// Get the TimeStep Requested from the information if present
//
this->TimeOutOfRange = 0;
this->ActualTimeStep = this->TimeStep;
if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()))
{
double requestedTimeValue = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
this->ActualTimeStep = std::find_if(
this->TimeStepValues.begin(), this->TimeStepValues.end(),
std::bind2nd( H5PartToleranceCheck(
this->IntegerTimeStepValues ? 0.5 : this->TimeStepTolerance ), requestedTimeValue ))
- this->TimeStepValues.begin();
//
if (requestedTimeValue<this->TimeStepValues.front() || requestedTimeValue>this->TimeStepValues.back())
{
this->TimeOutOfRange = 1;
}
output->GetInformation()->Set(vtkDataObject::DATA_TIME_STEP(), requestedTimeValue);
}
else
{
double timevalue[1];
unsigned int index = this->ActualTimeStep;
if (index<this->TimeStepValues.size())
{
timevalue[0] = this->TimeStepValues[index];
}
else
{
timevalue[0] = this->TimeStepValues[0];
}
output->GetInformation()->Set(vtkDataObject::DATA_TIME_STEP(), timevalue[0]);
}
if (this->TimeOutOfRange && this->MaskOutOfTimeRangeOutput)
{
// don't do anything, just return success
return 1;
}
// open the file if not already done
if (!this->OpenFile())
{
return 0;
}
// Set the TimeStep on the H5 file
H5PartSetStep(this->H5FileId, this->ActualTimeStep);
//
// Get the number of particles for this timestep
//
vtkIdType Nparticles = H5PartGetNumParticles(this->H5FileId);
//
// Split particles up per process for parallel load
//
std::vector<vtkIdType> minIds, maxIds, Ids;
vtkIdType ParticleStart;
vtkIdType ParticleEnd;
//
if (this->PartitionCount.size()>0 && this->PartitionByBoundingBoxes(minIds,maxIds,this->PieceBounds,this->PieceBoundsHalo)) {
ParticleStart = minIds[this->UpdatePiece];
ParticleEnd = maxIds[this->UpdatePiece];
this->ExtentTranslator->SetBoundsHalosEnabled(1);
this->ExtentTranslator->SetNumberOfPieces(this->PieceBounds.size());
for (int i=0; i<this->PieceBounds.size(); i++) {
double bounds[6];
this->PieceBounds[i].GetBounds(bounds);
this->ExtentTranslator->SetBoundsForPiece(i, bounds);
this->PieceBoundsHalo[i].GetBounds(bounds);
this->ExtentTranslator->SetBoundsHaloForPiece(i, bounds);
}
this->ExtentTranslator->InitWholeBounds();
}
else {
if (this->RandomizePartitionExtents) {
this->PartitionByExtentsRandomized(Nparticles, Ids);
}
else {
this->PartitionByExtents(Nparticles, Ids);
}
ParticleStart = Ids[0];
ParticleEnd = Ids[1];
}
vtkIdType Nt = ParticleEnd - ParticleStart + 1;
//
// Setup arrays for reading data
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
vtkSmartPointer<vtkDataArray> coords = NULL;
for (FieldMap::iterator it=scalarFields.begin(); it!=scalarFields.end(); it++)
{
// use the type of the first array for all if it is a vector field
std::vector<std::string> &arraylist = (*it).second;
const char *array_name = arraylist[0].c_str();
std::string rootname = this->NameOfVectorComponent(array_name);
int Nc = static_cast<int>(arraylist.size());
//
vtkSmartPointer<vtkDataArray> dataarray = NULL;
hid_t datatype = H5PartGetNativeDatasetType(H5FileId,array_name);
int vtk_datatype = GetVTKDataType(datatype);
if (vtk_datatype == VTK_VOID)
{
H5Tclose(datatype);
vtkErrorMacro("An unexpected data type was encountered");
return 0;
}
dataarray.TakeReference(vtkDataArray::CreateDataArray(vtk_datatype));
dataarray->SetNumberOfComponents(Nc);
dataarray->SetNumberOfTuples(Nt);
dataarray->SetName(rootname.c_str());
// now read the data components.
herr_t r;
hsize_t count1_mem[] = { (hsize_t)(Nt*Nc) };
hsize_t count2_mem[] = { (hsize_t)(Nt) };
hsize_t offset_mem[] = { (hsize_t)(0) };
hsize_t stride_mem[] = { (hsize_t)(Nc) };
hsize_t count1_dsk[] = { (hsize_t)(Nt) };
hsize_t offset_dsk[] = { (hsize_t)(ParticleStart) };
hsize_t stride_dsk[] = { (hsize_t)(1) };
//
for (int c=0; c<Nc; c++)
{
const char *name = arraylist[c].c_str();
hid_t dataset = H5Dopen(H5FileId->timegroup, name h_params);
hid_t diskshape = H5PartGetDiskShape(H5FileId,dataset);
/* parallel read needs hyperslab for disk */
r = H5Sselect_hyperslab(diskshape, H5S_SELECT_SET,
offset_dsk, stride_dsk, count1_dsk, NULL);
if (Nc==1 || this->UseStridedMultiComponentRead)
{
hid_t memspace = H5Screate_simple(1, count1_mem, NULL);
hid_t component_datatype = H5PartGetNativeDatasetType(H5FileId, name);
/* read x/y/z arrays into strided mem - use hyperslab */
offset_mem[0] = c;
r = H5Sselect_hyperslab(
memspace, H5S_SELECT_SET,
offset_mem, stride_mem, count2_mem, NULL);
if (H5Tequal(component_datatype,datatype))
{
H5Dread(dataset, datatype, memspace,
diskshape, H5P_DEFAULT, dataarray->GetVoidPointer(0));
}
else
{
// read data into a temporary array of the right type and then copy it
// over to the "dataarray".
// This can be optimized to create a single component array. But I
// don't understand the stride/offset stuff too well to fix that.
vtkDataArray* temparray =
vtkDataArray::CreateDataArray(GetVTKDataType(component_datatype));
temparray->SetNumberOfComponents(Nc);
temparray->SetNumberOfTuples(Nt);
r = H5Sselect_hyperslab(
memspace, H5S_SELECT_SET,
offset_mem, stride_mem, count2_mem, NULL);
H5Dread(dataset, component_datatype, memspace,
diskshape, H5P_DEFAULT, temparray->GetVoidPointer(0));
dataarray->CopyComponent(c, temparray, c);
temparray->FastDelete();
}
H5Sclose(memspace);
H5Tclose(component_datatype);
}
else
{
vtkSmartPointer<vtkDataArray> onearray = NULL;
onearray.TakeReference(vtkDataArray::CreateDataArray(vtk_datatype));
onearray->SetNumberOfComponents(1);
onearray->SetNumberOfTuples(Nt);
onearray->SetName(name);
offset_mem[0] = 0;
count1_mem[0] = Nt;
stride_mem[0] = 1;
hid_t memspace = H5Screate_simple(1, count1_mem, NULL);
hid_t component_datatype = H5PartGetNativeDatasetType(H5FileId, name);
r = H5Sselect_hyperslab(
memspace, H5S_SELECT_SET,
offset_mem, stride_mem, count2_mem, NULL);
if (H5Tequal(component_datatype,datatype))
{
H5Dread(dataset, datatype, memspace,
diskshape, H5P_DEFAULT, onearray->GetVoidPointer(0));
}
else
{
vtkErrorMacro("H5Part : Unhandled type change condition")
}
switch (dataarray->GetDataType())
{
case VTK_FLOAT:
this->CopyIntoVector<float>(c,onearray,dataarray);
break;
case VTK_DOUBLE:
this->CopyIntoVector<double>(c,onearray,dataarray);
break;
case VTK_CHAR:
case VTK_SIGNED_CHAR:
case VTK_UNSIGNED_CHAR:
this->CopyIntoVector<char>(c,onearray,dataarray);
break;
case VTK_SHORT:
CopyIntoVector<short int>(c,onearray,dataarray);
break;
case VTK_UNSIGNED_SHORT:
CopyIntoVector<unsigned short int>(c,onearray,dataarray);
break;
case VTK_INT:
CopyIntoVector<int>(c,onearray,dataarray);
break;
case VTK_UNSIGNED_INT:
CopyIntoVector<unsigned int>(c,onearray,dataarray);
break;
case VTK_LONG:
CopyIntoVector<long int>(c,onearray,dataarray);
break;
case VTK_UNSIGNED_LONG:
CopyIntoVector<unsigned long int>(c,onearray,dataarray);
break;
case VTK_LONG_LONG:
CopyIntoVector<long long>(c,onearray,dataarray);
break;
case VTK_UNSIGNED_LONG_LONG:
CopyIntoVector<unsigned long long>(c,onearray,dataarray);
break;
case VTK_ID_TYPE:
CopyIntoVector<vtkIdType>(c,onearray,dataarray);
break;
default:
vtkErrorMacro("H5Part : Unhandled vector type")
}
H5Sclose(memspace);
H5Tclose(component_datatype);
// if the array we read for the vector component is a field array
// then skip reading it twice.
if (this->MultiComponentArraysAsFieldData) {
output->GetPointData()->AddArray(onearray);
}
}
H5Sclose(diskshape);
H5Dclose(dataset);
}
H5Tclose(datatype);
//
if (dataarray)
{
if ((*it).first=="Coords") {
coords = dataarray;
coords->SetName("Coordinates");
}
else
{
output->GetPointData()->AddArray(dataarray);
if (!output->GetPointData()->GetScalars())
{
output->GetPointData()->SetActiveScalars(dataarray->GetName());
}
}
}
}
//
// generate cells
//
if (this->GenerateVertexCells)
{
vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
vtkIdType *cells = vertices->WritePointer(Nt, 2*Nt);