forked from Kitware/VTK
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvtkDataSetAttributes.cxx
2195 lines (1993 loc) · 66.4 KB
/
vtkDataSetAttributes.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
/*=========================================================================
Program: Visualization Toolkit
Module: vtkDataSetAttributes.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkDataSetAttributes.h"
#include "vtkArrayIteratorIncludes.h"
#include "vtkCell.h"
#include "vtkMath.h"
#include "vtkCharArray.h"
#include "vtkUnsignedCharArray.h"
#include "vtkShortArray.h"
#include "vtkUnsignedShortArray.h"
#include "vtkIntArray.h"
#include "vtkUnsignedIntArray.h"
#include "vtkLongArray.h"
#include "vtkUnsignedLongArray.h"
#include "vtkDoubleArray.h"
#include "vtkFloatArray.h"
#include "vtkIdTypeArray.h"
#include "vtkObjectFactory.h"
#include "vtkInformation.h"
#include <vtkstd/vector>
namespace
{
typedef vtkstd::vector< vtkStdString* > vtkInternalComponentNameBase;
}
class vtkDataSetAttributes::vtkInternalComponentNames : public vtkInternalComponentNameBase {};
vtkStandardNewMacro(vtkDataSetAttributes);
//--------------------------------------------------------------------------
const char vtkDataSetAttributes
::AttributeNames[vtkDataSetAttributes::NUM_ATTRIBUTES][12] =
{ "Scalars",
"Vectors",
"Normals",
"TCoords",
"Tensors",
"GlobalIds",
"PedigreeIds",
"EdgeFlag"
};
const char vtkDataSetAttributes
::LongAttributeNames[vtkDataSetAttributes::NUM_ATTRIBUTES][35] =
{ "vtkDataSetAttributes::SCALARS",
"vtkDataSetAttributes::VECTORS",
"vtkDataSetAttributes::NORMALS",
"vtkDataSetAttributes::TCOORDS",
"vtkDataSetAttributes::TENSORS",
"vtkDataSetAttributes::GLOBALIDS",
"vtkDataSetAttributes::PEDIGREEIDS",
"vtkDataSetAttributes::EDGEFLAG"
};
//--------------------------------------------------------------------------
// Construct object with copying turned on for all data.
vtkDataSetAttributes::vtkDataSetAttributes()
{
int attributeType;
for(attributeType=0; attributeType<NUM_ATTRIBUTES; attributeType++)
{
this->AttributeIndices[attributeType] = -1;
this->CopyAttributeFlags[COPYTUPLE][attributeType] = 1;
this->CopyAttributeFlags[INTERPOLATE][attributeType] = 1;
this->CopyAttributeFlags[PASSDATA][attributeType] = 1;
}
//Global IDs should not be interpolated because they are labels, not "numbers"
//Global IDs should not be copied either, unless doing so preserves meaning.
//Passing through is ussually OK because it is 1:1.
this->CopyAttributeFlags[COPYTUPLE][GLOBALIDS] = 0;
this->CopyAttributeFlags[INTERPOLATE][GLOBALIDS] = 0;
//Pedigree IDs should not be interpolated because they are labels, not "numbers"
//Pedigree IDs may be copied since they do not require 1:1 mapping.
this->CopyAttributeFlags[INTERPOLATE][PEDIGREEIDS] = 0;
this->TargetIndices=0;
}
//--------------------------------------------------------------------------
// Destructor for the vtkDataSetAttributes objects.
vtkDataSetAttributes::~vtkDataSetAttributes()
{
this->Initialize();
delete[] this->TargetIndices;
this->TargetIndices = 0;
}
//--------------------------------------------------------------------------
// Turn on copying of all data.
void vtkDataSetAttributes::CopyAllOn(int ctype)
{
this->vtkFieldData::CopyAllOn();
this->SetCopyScalars(1, ctype);
this->SetCopyVectors(1, ctype);
this->SetCopyNormals(1, ctype);
this->SetCopyTCoords(1, ctype);
this->SetCopyTensors(1, ctype);
this->SetCopyGlobalIds(1, ctype);
this->SetCopyPedigreeIds(1, ctype);
}
//--------------------------------------------------------------------------
// Turn off copying of all data.
void vtkDataSetAttributes::CopyAllOff(int ctype)
{
this->vtkFieldData::CopyAllOff();
this->SetCopyScalars(0, ctype);
this->SetCopyVectors(0, ctype);
this->SetCopyNormals(0, ctype);
this->SetCopyTCoords(0, ctype);
this->SetCopyTensors(0, ctype);
this->SetCopyGlobalIds(0, ctype);
this->SetCopyPedigreeIds(0, ctype);
}
//--------------------------------------------------------------------------
// Deep copy of data (i.e., create new data arrays and
// copy from input data). Note that attribute data is
// not copied.
void vtkDataSetAttributes::DeepCopy(vtkFieldData *fd)
{
this->Initialize(); //free up memory
vtkDataSetAttributes* dsa = vtkDataSetAttributes::SafeDownCast(fd);
// If the source is a vtkDataSetAttributes
if (dsa)
{
int numArrays = fd->GetNumberOfArrays();
int attributeType, i;
vtkAbstractArray *data, *newData;
// Allocate space for numArrays
this->AllocateArrays(numArrays);
for (i=0; i < numArrays; i++ )
{
data = fd->GetAbstractArray(i);
newData = data->NewInstance(); //instantiate same type of object
newData->DeepCopy(data);
newData->SetName(data->GetName());
this->AddArray(newData);
newData->Delete();
}
// Copy the copy flags
for(attributeType=0; attributeType<NUM_ATTRIBUTES; attributeType++)
{
// If an array is an attribute in the source, then mark it as a attribute
// in the clone as well.
this->AttributeIndices[attributeType] = dsa->AttributeIndices[attributeType];
this->CopyAttributeFlags[COPYTUPLE][attributeType] =
dsa->CopyAttributeFlags[COPYTUPLE][attributeType];
this->CopyAttributeFlags[INTERPOLATE][attributeType] =
dsa->CopyAttributeFlags[INTERPOLATE][attributeType];
this->CopyAttributeFlags[PASSDATA][attributeType] =
dsa->CopyAttributeFlags[PASSDATA][attributeType];
}
this->CopyFlags(dsa);
}
// If the source is field data, do a field data copy
else
{
this->vtkFieldData::DeepCopy(fd);
}
}
//--------------------------------------------------------------------------
// Shallow copy of data (i.e., use reference counting).
void vtkDataSetAttributes::ShallowCopy(vtkFieldData *fd)
{
this->Initialize(); //free up memory
vtkDataSetAttributes* dsa = vtkDataSetAttributes::SafeDownCast(fd);
// If the source is a vtkDataSetAttributes
if (dsa)
{
int numArrays = fd->GetNumberOfArrays();
int attributeType, i;
// Allocate space for numArrays
this->AllocateArrays(numArrays);
this->NumberOfActiveArrays = 0;
for (i=0; i < numArrays; i++ )
{
this->NumberOfActiveArrays++;
this->SetArray(i, fd->GetAbstractArray(i));
}
// Copy the copy flags
for(attributeType=0; attributeType<NUM_ATTRIBUTES; attributeType++)
{
// If an array is an attribute in the source, then mark it as a attribute
// in the clone as well.
this->AttributeIndices[attributeType] = dsa->AttributeIndices[attributeType];
this->CopyAttributeFlags[COPYTUPLE][attributeType] =
dsa->CopyAttributeFlags[COPYTUPLE][attributeType];
this->CopyAttributeFlags[INTERPOLATE][attributeType] =
dsa->CopyAttributeFlags[INTERPOLATE][attributeType];
this->CopyAttributeFlags[PASSDATA][attributeType] =
dsa->CopyAttributeFlags[PASSDATA][attributeType];
}
this->CopyFlags(dsa);
}
// If the source is field data, do a field data copy
else
{
this->vtkFieldData::ShallowCopy(fd);
}
}
//--------------------------------------------------------------------------
// Initialize all of the object's data to NULL
void vtkDataSetAttributes::InitializeFields()
{
this->vtkFieldData::InitializeFields();
int attributeType;
for(attributeType=0; attributeType<NUM_ATTRIBUTES; attributeType++)
{
this->AttributeIndices[attributeType] = -1;
this->CopyAttributeFlags[COPYTUPLE][attributeType] = 1;
this->CopyAttributeFlags[INTERPOLATE][attributeType] = 1;
this->CopyAttributeFlags[PASSDATA][attributeType] = 1;
}
this->CopyAttributeFlags[COPYTUPLE][GLOBALIDS] = 0;
this->CopyAttributeFlags[INTERPOLATE][GLOBALIDS] = 0;
this->CopyAttributeFlags[INTERPOLATE][PEDIGREEIDS] = 0;
}
//--------------------------------------------------------------------------
// Initialize all of the object's data to NULL
void vtkDataSetAttributes::Initialize()
{
//
// We don't modify ourselves because the "ReleaseData" methods depend upon
// no modification when initialized.
//
// Call superclass' Initialize()
this->vtkFieldData::Initialize();
//
// Free up any memory
// And don't forget to reset the attribute copy flags.
int attributeType;
for(attributeType=0; attributeType<NUM_ATTRIBUTES; attributeType++)
{
this->AttributeIndices[attributeType] = -1;
this->CopyAttributeFlags[COPYTUPLE][attributeType] = 1;
this->CopyAttributeFlags[INTERPOLATE][attributeType] = 1;
this->CopyAttributeFlags[PASSDATA][attributeType] = 1;
}
this->CopyAttributeFlags[COPYTUPLE][GLOBALIDS] = 0;
this->CopyAttributeFlags[INTERPOLATE][GLOBALIDS] = 0;
this->CopyAttributeFlags[INTERPOLATE][PEDIGREEIDS] = 0;
}
//--------------------------------------------------------------------------
// This method is used to determine which arrays
// will be copied to this object
vtkFieldData::BasicIterator vtkDataSetAttributes::ComputeRequiredArrays(
vtkDataSetAttributes* pd, int ctype)
{
if ((ctype < COPYTUPLE) || (ctype > PASSDATA))
{
vtkErrorMacro("Must call compute required with COPYTUPLE, INTERPOLATE or PASSDATA");
ctype = COPYTUPLE;
}
// We need to do some juggling to find the number of arrays
// which will be passed.
// First, find the number of arrays to be copied because they
// are in the list of _fields_ to be copied (and the actual data
// pointer is non-NULL). Also, we keep those indices in a list.
int* copyFlags = new int[pd->GetNumberOfArrays()];
int index, i, numArrays = 0;
for(i=0; i<pd->GetNumberOfArrays(); i++)
{
const char* arrayName = pd->GetArrayName(i);
// If there is no blocker for the given array
// and both CopyAllOff and CopyOn for that array are not true
if ( (this->GetFlag(arrayName) != 0) &&
!(this->DoCopyAllOff && (this->GetFlag(arrayName) != 1)) &&
pd->GetAbstractArray(i))
{
// Cannot interpolate idtype arrays
if (ctype != INTERPOLATE ||
!pd->GetAbstractArray(i)->IsA("vtkIdTypeArray"))
{
copyFlags[numArrays] = i;
numArrays++;
}
}
}
// Next, we check the arrays to be copied because they are one of
// the _attributes_ to be copied (and the data array in non-NULL).
// We make sure that we don't count anything twice.
int alreadyCopied;
int attributeType, j;
for(attributeType=0; attributeType<NUM_ATTRIBUTES; attributeType++)
{
index = pd->AttributeIndices[attributeType];
int flag = this->GetFlag(pd->GetArrayName(index));
// If this attribute is to be copied
if (this->CopyAttributeFlags[ctype][attributeType] && flag)
{
// Find out if it is also in the list of fields to be copied
// Since attributes can only be vtkDataArray, we use GetArray() call.
if (pd->GetArray(index))
{
alreadyCopied = 0;
for(i=0; i<numArrays; i++)
{
if ( index == copyFlags[i] )
{
alreadyCopied = 1;
}
}
// If not, increment the number of arrays to be copied.
if (!alreadyCopied)
{
// Cannot interpolate idtype arrays
if (ctype != INTERPOLATE ||
!pd->GetArray(index)->IsA("vtkIdTypeArray"))
{
copyFlags[numArrays] = index;
numArrays++;
}
}
}
}
// If it is not to be copied and it is in the list (from the
// previous pass), remove it
else
{
for(i=0; i<numArrays; i++)
{
if ( index == copyFlags[i] )
{
for(j=i; j<numArrays-1; j++)
{
copyFlags[j] = copyFlags[j+1];
}
numArrays--;
i--;
}
}
}
}
vtkFieldData::BasicIterator it(copyFlags, numArrays);
delete[] copyFlags;
return it;
}
//--------------------------------------------------------------------------
// Pass entire arrays of input data through to output. Obey the "copy"
// flags.
void vtkDataSetAttributes::PassData(vtkFieldData* fd)
{
if (!fd)
{
return;
}
vtkDataSetAttributes* dsa = vtkDataSetAttributes::SafeDownCast(fd);
if (dsa)
{
// Create an iterator to iterate over the fields which will
// be passed, i.e. fields which are either:
// 1> in the list of _fields_ to be copied or
// 2> in the list of _attributes_ to be copied.
// Note that NULL data arrays are not copied
vtkFieldData::BasicIterator it = this->ComputeRequiredArrays(dsa, PASSDATA);
if ( it.GetListSize() > this->NumberOfArrays )
{
this->AllocateArrays(it.GetListSize());
}
if (it.GetListSize() == 0)
{
return;
}
// Since we are replacing, remove old attributes
int attributeType; //will change//
for(attributeType=0; attributeType<NUM_ATTRIBUTES; attributeType++)
{
if (this->CopyAttributeFlags[PASSDATA][attributeType])
{
this->RemoveArray(this->AttributeIndices[attributeType]);
this->AttributeIndices[attributeType] = -1;
}
}
int i, arrayIndex;
for(i=it.BeginIndex(); !it.End(); i=it.NextIndex())
{
arrayIndex = this->AddArray(dsa->GetAbstractArray(i));
// If necessary, make the array an attribute
if ( ((attributeType = dsa->IsArrayAnAttribute(i)) != -1 ) &&
this->CopyAttributeFlags[PASSDATA][attributeType] )
{
this->SetActiveAttribute(arrayIndex, attributeType);
}
}
}
else
{
this->vtkFieldData::PassData(fd);
}
}
//----------------------------------------------------------------------------
template <class iterT>
void vtkDataSetAttributesCopyValues(
iterT* destIter, const int* outExt, int outIncs[3], int rowLength,
iterT* srcIter, const int* vtkNotUsed(inExt), int inIncs[3])
{
// For vtkDataArray subclasses.
int data_type_size = srcIter->GetArray()->GetDataTypeSize();
unsigned char *inPtr;
unsigned char *outPtr;
unsigned char *inZPtr;
unsigned char *outZPtr;
// Get the starting input pointer.
inZPtr = static_cast<unsigned char*>(srcIter->GetArray()->GetVoidPointer(0));
// Shift to the start of the subextent.
inZPtr += (outExt[0]-outExt[0])*inIncs[0] * data_type_size +
(outExt[2] - outExt[2])*inIncs[1] * data_type_size +
(outExt[4] - outExt[4])*inIncs[2] * data_type_size;
// Get output pointer.
outZPtr =
static_cast<unsigned char*>(destIter->GetArray()->GetVoidPointer(0));
// Loop over z axis.
int zIdx, yIdx;
for (zIdx = outExt[4]; zIdx <= outExt[5]; ++zIdx)
{
inPtr = inZPtr;
outPtr = outZPtr;
for (yIdx = outExt[2]; yIdx <= outExt[3]; ++yIdx)
{
memcpy(outPtr, inPtr, rowLength * data_type_size);
inPtr += inIncs[1] * data_type_size;
outPtr += outIncs[1] * data_type_size;
}
inZPtr += inIncs[2] * data_type_size;
outZPtr += outIncs[2] * data_type_size;
}
}
//----------------------------------------------------------------------------
VTK_TEMPLATE_SPECIALIZE
void vtkDataSetAttributesCopyValues(
vtkArrayIteratorTemplate<vtkStdString>* destIter, const int* outExt,
int outIncs[3], int rowLength,
vtkArrayIteratorTemplate<vtkStdString>* srcIter,
const int* vtkNotUsed(inExt), int inIncs[3])
{
int inZIndex = (outExt[0]-outExt[0])*inIncs[0] +
(outExt[2] - outExt[2])*inIncs[1] +
(outExt[4] - outExt[4])*inIncs[2] ;
int outZIndex = 0;
int inIndex;
int outIndex;
int zIdx, yIdx, xIdx;
for (zIdx = outExt[4]; zIdx <= outExt[5]; ++zIdx)
{
inIndex = inZIndex;
outIndex = outZIndex;
for (yIdx = outExt[2]; yIdx <= outExt[3]; ++yIdx)
{
for (xIdx = 0; xIdx < rowLength; ++xIdx)
{
destIter->GetValue(outIndex + xIdx) = srcIter->GetValue(inIndex + xIdx);
}
inIndex += inIncs[1];
outIndex += outIncs[1];
}
inZIndex += inIncs[2];
outZIndex += outIncs[2];
}
}
//----------------------------------------------------------------------------
// This is used in the imaging pipeline for copying arrays.
// CopyAllocate needs to be called before this method.
void vtkDataSetAttributes::CopyStructuredData(vtkDataSetAttributes *fromPd,
const int *inExt, const int *outExt)
{
int i;
for(i=this->RequiredArrays.BeginIndex(); !this->RequiredArrays.End();
i=this->RequiredArrays.NextIndex())
{
vtkDataArray *inArray = vtkDataArray::SafeDownCast(fromPd->Data[i]);
vtkDataArray *outArray = vtkDataArray::SafeDownCast(this->Data[this->TargetIndices[i]]);
int inIncs[3];
int outIncs[3];
int rowLength;
int zIdx;
// Compute increments
inIncs[0] = /*inArray->GetDataTypeSize() * */ inArray->GetNumberOfComponents();
inIncs[1] = inIncs[0] * (inExt[1]-inExt[0]+1);
inIncs[2] = inIncs[1] * (inExt[3]-inExt[2]+1);
outIncs[0] = inIncs[0];
outIncs[1] = outIncs[0] * (outExt[1]-outExt[0]+1);
outIncs[2] = outIncs[1] * (outExt[3]-outExt[2]+1);
// Length of continuous data to copy (one row).
rowLength = (outExt[1]-outExt[0]+1)*outIncs[0];
// Make sure the input extents match the actual array lengths.
zIdx = (inExt[1]-inExt[0]+1)*(inExt[3]-inExt[2]+1)*(inExt[5]-inExt[4]+1);
if (inArray->GetNumberOfTuples() != zIdx)
{
vtkErrorMacro("Input extent (" << inExt[0] << ", " << inExt[1] << ", "
<< inExt[2] << ", " << inExt[3] << ", " << inExt[4] << ", "
<< inExt[5] << ") does not match array length: " << zIdx);
// Skip copying this array.
continue;
}
// Make sure the output extents match the actual array lengths.
zIdx = (outExt[1]-outExt[0]+1)*(outExt[3]-outExt[2]+1)*(outExt[5]-outExt[4]+1);
if (outArray->GetNumberOfTuples() != zIdx)
{
// The "CopyAllocate" method only sets the size, not the number of tuples.
outArray->SetNumberOfTuples(zIdx);
}
vtkArrayIterator* srcIter = inArray->NewIterator();
vtkArrayIterator* destIter = outArray->NewIterator();
switch (inArray->GetDataType())
{
vtkArrayIteratorTemplateMacro(
vtkDataSetAttributesCopyValues(
static_cast<VTK_TT*>(destIter), outExt, outIncs, rowLength,
static_cast<VTK_TT*>(srcIter), inExt, inIncs));
}
srcIter->Delete();
destIter->Delete();
}
}
//--------------------------------------------------------------------------
// Allocates point data for point-by-point (or cell-by-cell) copy operation.
// If sze=0, then use the input DataSetAttributes to create (i.e., find
// initial size of) new objects; otherwise use the sze variable.
void vtkDataSetAttributes::InternalCopyAllocate(vtkDataSetAttributes* pd,
int ctype,
vtkIdType sze, vtkIdType ext,
int shallowCopyArrays)
{
vtkAbstractArray* newAA;
int i;
// Create various point data depending upon input
//
if ( !pd )
{
return;
}
if ((ctype < COPYTUPLE) || (ctype > PASSDATA))
{
return;
}
this->RequiredArrays = this->ComputeRequiredArrays(pd, ctype);
if (this->RequiredArrays.GetListSize() == 0)
{
return;
}
delete[] this->TargetIndices;
this->TargetIndices = new int[pd->GetNumberOfArrays()];
for(i=0; i<pd->GetNumberOfArrays(); i++)
{
this->TargetIndices[i] = -1;
}
vtkAbstractArray* aa=0;
// If we are not copying on self
if ( pd != this )
{
int attributeType;
for(i=this->RequiredArrays.BeginIndex(); !this->RequiredArrays.End();
i=this->RequiredArrays.NextIndex())
{
// Create all required arrays
aa = pd->GetAbstractArray(i);
if (shallowCopyArrays)
{
newAA = aa;
}
else
{
newAA = aa->NewInstance();
newAA->SetNumberOfComponents(aa->GetNumberOfComponents());
newAA->CopyComponentNames( aa );
newAA->SetName(aa->GetName());
if (aa->HasInformation())
{
newAA->CopyInformation(aa->GetInformation(),/*deep=*/1);
}
if ( sze > 0 )
{
newAA->Allocate(sze*aa->GetNumberOfComponents(),ext);
}
else
{
newAA->Allocate(aa->GetNumberOfTuples());
}
vtkDataArray* newDA = vtkDataArray::SafeDownCast(newAA);
if (newDA)
{
vtkDataArray* da = vtkDataArray::SafeDownCast(aa);
newDA->SetLookupTable(da->GetLookupTable());
}
}
this->TargetIndices[i] = this->AddArray(newAA);
// If necessary, make the array an attribute
if ( ((attributeType = pd->IsArrayAnAttribute(i)) != -1 ) &&
this->CopyAttributeFlags[ctype][attributeType] )
{
this->SetActiveAttribute(this->TargetIndices[i], attributeType);
}
if (!shallowCopyArrays)
{
newAA->Delete();
}
}
}
else
{
// If copying on self, resize the arrays and initialize
// TargetIndices
for(i=this->RequiredArrays.BeginIndex(); !this->RequiredArrays.End();
i=this->RequiredArrays.NextIndex())
{
aa = pd->GetAbstractArray(i);
aa->Resize(sze);
this->TargetIndices[i] = i;
}
}
}
//--------------------------------------------------------------------------
void vtkDataSetAttributes::RemoveArray(int index)
{
if ( (index<0) || (index>=this->NumberOfActiveArrays))
{
return;
}
this->Superclass::RemoveArray(index);
int attributeType;
for(attributeType = 0; attributeType < NUM_ATTRIBUTES; attributeType++)
{
if (this->AttributeIndices[attributeType] == index)
{
this->AttributeIndices[attributeType] = -1;
}
else if (this->AttributeIndices[attributeType] > index)
{
this->AttributeIndices[attributeType]--;
}
}
}
//--------------------------------------------------------------------------
// Copy the attribute data from one id to another. Make sure CopyAllocate() has
// been invoked before using this method.
void vtkDataSetAttributes::CopyData(vtkDataSetAttributes* fromPd,
vtkIdType fromId, vtkIdType toId)
{
int i;
for(i=this->RequiredArrays.BeginIndex(); !this->RequiredArrays.End();
i=this->RequiredArrays.NextIndex())
{
this->CopyTuple(fromPd->Data[i], this->Data[this->TargetIndices[i]],
fromId, toId);
}
}
//--------------------------------------------------------------------------
void vtkDataSetAttributes::CopyAllocate(vtkDataSetAttributes* pd,
vtkIdType sze, vtkIdType ext,
int shallowCopyArrays)
{
this->InternalCopyAllocate(pd, COPYTUPLE, sze, ext, shallowCopyArrays);
}
// Initialize point interpolation method.
void vtkDataSetAttributes::InterpolateAllocate(vtkDataSetAttributes* pd,
vtkIdType sze, vtkIdType ext,
int shallowCopyArrays)
{
this->InternalCopyAllocate(pd, INTERPOLATE, sze, ext, shallowCopyArrays);
}
//--------------------------------------------------------------------------
// Interpolate data from points and interpolation weights. Make sure that the
// method InterpolateAllocate() has been invoked before using this method.
void vtkDataSetAttributes::InterpolatePoint(vtkDataSetAttributes *fromPd,
vtkIdType toId, vtkIdList *ptIds,
double *weights)
{
int i;
for(i=this->RequiredArrays.BeginIndex(); !this->RequiredArrays.End();
i=this->RequiredArrays.NextIndex())
{
vtkAbstractArray* fromArray = this->Data[this->TargetIndices[i]];
fromArray->InterpolateTuple(toId, ptIds, fromPd->Data[i], weights);
}
}
//--------------------------------------------------------------------------
// Interpolate data from the two points p1,p2 (forming an edge) and an
// interpolation factor, t, along the edge. The weight ranges from (0,1),
// with t=0 located at p1. Make sure that the method InterpolateAllocate()
// has been invoked before using this method.
void vtkDataSetAttributes::InterpolateEdge(vtkDataSetAttributes *fromPd,
vtkIdType toId, vtkIdType p1,
vtkIdType p2, double t)
{
int i;
for(i=this->RequiredArrays.BeginIndex(); !this->RequiredArrays.End();
i=this->RequiredArrays.NextIndex())
{
vtkAbstractArray* fromArray = fromPd->Data[i];
vtkAbstractArray* toArray = this->Data[this->TargetIndices[i]];
//check if the destination array needs nearest neighbor interpolation
int attributeIndex = this->IsArrayAnAttribute(this->TargetIndices[i]);
if (attributeIndex != -1
&&
this->CopyAttributeFlags[INTERPOLATE][attributeIndex]==2)
{
double bt = (t < 0.5) ? 0.0 : 1.0;
toArray->InterpolateTuple(toId, p1, fromArray, p2, fromArray, bt);
}
else
{
toArray->InterpolateTuple(toId, p1, fromArray, p2, fromArray, t);
}
}
}
//--------------------------------------------------------------------------
// Interpolate data from the two points p1,p2 (forming an edge) and an
// interpolation factor, t, along the edge. The weight ranges from (0,1),
// with t=0 located at p1. Make sure that the method InterpolateAllocate()
// has been invoked before using this method.
void vtkDataSetAttributes::InterpolateTime(vtkDataSetAttributes *from1,
vtkDataSetAttributes *from2,
vtkIdType id, double t)
{
int attributeType;
for(attributeType=0; attributeType<NUM_ATTRIBUTES; attributeType++)
{
// If this attribute is to be copied
if (this->CopyAttributeFlags[INTERPOLATE][attributeType])
{
if (from1->GetAttribute(attributeType) &&
from2->GetAttribute(attributeType))
{
vtkAbstractArray* toArray = this->GetAttribute(attributeType);
//check if the destination array needs nearest neighbor interpolation
if (this->CopyAttributeFlags[INTERPOLATE][attributeType]==2)
{
double bt = (t < 0.5) ? 0.0 : 1.0;
toArray->InterpolateTuple(id, id, from1->GetAttribute(attributeType),
id, from2->GetAttribute(attributeType), bt);
}
else
{
toArray->InterpolateTuple(id, id, from1->GetAttribute(attributeType),
id, from2->GetAttribute(attributeType), t);
}
}
}
}
}
//--------------------------------------------------------------------------
// Copy a tuple of data from one data array to another. This method (and
// following ones) assume that the fromData and toData objects are of the
// same type, and have the same number of components. This is true if you
// invoke CopyAllocate() or InterpolateAllocate().
void vtkDataSetAttributes::CopyTuple(vtkAbstractArray *fromData,
vtkAbstractArray *toData, vtkIdType fromId,
vtkIdType toId)
{
toData->InsertTuple(toId, fromId, fromData);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetScalars(vtkDataArray* da)
{
return this->SetAttribute(da, SCALARS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetActiveScalars(const char* name)
{
return this->SetActiveAttribute(name, SCALARS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetActiveAttribute(const char* name,
int attributeType)
{
int index;
this->GetAbstractArray(name, index);
return this->SetActiveAttribute(index, attributeType);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetScalars()
{
return this->GetAttribute(SCALARS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetVectors(vtkDataArray* da)
{
return this->SetAttribute(da, VECTORS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetActiveVectors(const char* name)
{
return this->SetActiveAttribute(name, VECTORS);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetVectors()
{
return this->GetAttribute(VECTORS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetNormals(vtkDataArray* da)
{
return this->SetAttribute(da, NORMALS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetActiveNormals(const char* name)
{
return this->SetActiveAttribute(name, NORMALS);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetNormals()
{
return this->GetAttribute(NORMALS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetTCoords(vtkDataArray* da)
{
return this->SetAttribute(da, TCOORDS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetActiveTCoords(const char* name)
{
return this->SetActiveAttribute(name, TCOORDS);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetTCoords()
{
return this->GetAttribute(TCOORDS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetTensors(vtkDataArray* da)
{
return this->SetAttribute(da, TENSORS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetActiveTensors(const char* name)
{
return this->SetActiveAttribute(name, TENSORS);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetTensors()
{
return this->GetAttribute(TENSORS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetGlobalIds(vtkDataArray* da)
{
return this->SetAttribute(da, GLOBALIDS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetActiveGlobalIds(const char* name)
{
return this->SetActiveAttribute(name, GLOBALIDS);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetGlobalIds()
{
return this->GetAttribute(GLOBALIDS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetPedigreeIds(vtkAbstractArray* aa)
{
return this->SetAttribute(aa, PEDIGREEIDS);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetActivePedigreeIds(const char* name)
{
return this->SetActiveAttribute(name, PEDIGREEIDS);
}
//--------------------------------------------------------------------------
vtkAbstractArray* vtkDataSetAttributes::GetPedigreeIds()
{
return this->GetAbstractAttribute(PEDIGREEIDS);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetScalars(const char* name)
{
if (name == NULL || name[0] == '\0')
{
return this->GetScalars();
}
return this->GetArray(name);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetVectors(const char* name)
{
if (name == NULL || name[0] == '\0')
{
return this->GetVectors();
}
return this->GetArray(name);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetNormals(const char* name)
{
if (name == NULL || name[0] == '\0')
{
return this->GetNormals();
}
return this->GetArray(name);
}
//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetTCoords(const char* name)
{
if (name == NULL || name[0] == '\0')
{
return this->GetTCoords();
}
return this->GetArray(name);
}