File: vtkDataSetAttributes.cxx

package info (click to toggle)
vtk6 6.3.0%2Bdfsg2-8.1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 118,972 kB
  • sloc: cpp: 1,442,790; ansic: 113,395; python: 72,383; tcl: 46,998; xml: 8,119; yacc: 4,525; java: 4,239; perl: 3,108; lex: 1,694; sh: 1,093; asm: 154; makefile: 68; objc: 17
file content (2292 lines) | stat: -rw-r--r-- 71,373 bytes parent folder | download | duplicates (3)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
/*=========================================================================

  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 "vtkMappedDataArray.h"
#include "vtkUnsignedLongArray.h"
#include "vtkDoubleArray.h"
#include "vtkFloatArray.h"
#include "vtkIdTypeArray.h"
#include "vtkObjectFactory.h"
#include "vtkTypedDataArrayIterator.h"
#include "vtkInformation.h"

#include <vector>

namespace
{
  // pair.first it used to indicate if pair.second is valid.
  typedef  std::vector<std::pair<bool, 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)->GetDataType() != VTK_ID_TYPE)
        {
        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)->GetDataType() != VTK_ID_TYPE)
            {
            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);
    }
}

//----------------------------------------------------------------------------
// This is a version of vtkDataSetAttributesCopyValues adapted to work with
// vtkTypedDataArrayIterators.
template <class Scalar>
void vtkTypedIteratorDataSetAttributesCopyValues(
    vtkTypedDataArrayIterator<Scalar> destIter, const int *outExt,
    vtkIdType outIncs[3],
    vtkTypedDataArrayIterator<Scalar> srcIter, const int *inExt,
    vtkIdType inIncs[3])
{
  // For vtkMappedDataArray subclasses.
  vtkTypedDataArrayIterator<Scalar> inZIter;
  vtkTypedDataArrayIterator<Scalar> outZIter;
  vtkTypedDataArrayIterator<Scalar> inYIter;
  vtkTypedDataArrayIterator<Scalar> outYIter;
  vtkTypedDataArrayIterator<Scalar> inIter;
  vtkTypedDataArrayIterator<Scalar> outIter;

  // Set the starting iterators.
  inZIter = srcIter +
      (outExt[0] - inExt[0]) * inIncs[0] +
      (outExt[2] - inExt[2]) * inIncs[1] +
      (outExt[4] - inExt[4]) * inIncs[2];
  outZIter = destIter;

  int rowLength = outIncs[1];

  for (int zIdx = outExt[4]; zIdx <= outExt[5]; ++zIdx)
    {
    inIter = inZIter;
    outIter = outZIter;
    for (int yIdx = outExt[2]; yIdx <= outExt[3]; ++yIdx)
      {
      for (int c = 0; c < rowLength; ++c)
        {
        *outIter = *inIter;
        ++outIter;
        ++inIter;
        }
      inIter += inIncs[1];
      outIter += outIncs[1];
      }
    inZIter += inIncs[2];
    outZIter += outIncs[2];
    }
}

//----------------------------------------------------------------------------
template <class iterT>
void vtkDataSetAttributesCopyValues(
  iterT* destIter, const int* outExt, vtkIdType outIncs[3],
  iterT* srcIter, const int* inExt, vtkIdType inIncs[3])
{
  // For vtkDataArray subclasses.
  int data_type_size = srcIter->GetArray()->GetDataTypeSize();
  vtkIdType rowLength = outIncs[1];
  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] - inExt[0]) * inIncs[0] * data_type_size +
      (outExt[2] - inExt[2]) * inIncs[1] * data_type_size +
      (outExt[4] - inExt[4]) * inIncs[2] * data_type_size;

  // Get output pointer.
  outZPtr =
    static_cast<unsigned char*>(destIter->GetArray()->GetVoidPointer(0));

  // Loop over z axis.
  for (int zIdx = outExt[4]; zIdx <= outExt[5]; ++zIdx)
    {
    inPtr = inZPtr;
    outPtr = outZPtr;
    for (int 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,
  vtkIdType outIncs[3],
  vtkArrayIteratorTemplate<vtkStdString>* srcIter,
  const int* inExt, vtkIdType inIncs[3])
{
  vtkIdType inZIndex = (outExt[0] - inExt[0])*inIncs[0] +
    (outExt[2] - inExt[2])*inIncs[1] +
    (outExt[4] - inExt[4])*inIncs[2] ;

  vtkIdType outZIndex = 0;
  vtkIdType rowLength = outIncs[1];

  for (int zIdx = outExt[4]; zIdx <= outExt[5]; ++zIdx)
    {
    vtkIdType inIndex = inZIndex;
    vtkIdType outIndex = outZIndex;
    for (int yIdx = outExt[2]; yIdx <= outExt[3]; ++yIdx)
      {
      for (int 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())
    {
    vtkAbstractArray *inArray = fromPd->Data[i];
    vtkAbstractArray *outArray = this->Data[this->TargetIndices[i]];
    vtkIdType inIncs[3];
    vtkIdType outIncs[3];
    vtkIdType zIdx;

    // Compute increments
    inIncs[0] = 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);

    // Make sure the input extents match the actual array lengths.
    zIdx = inIncs[2]/inIncs[0]*(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 = outIncs[2]/outIncs[0]*(outExt[5]-outExt[4]+1);
    if (outArray->GetNumberOfTuples() != zIdx)
      {
      // The "CopyAllocate" method only sets the size, not the number of tuples.
      outArray->SetNumberOfTuples(zIdx);
      }

    if (inArray->HasStandardMemoryLayout() &&
        outArray->HasStandardMemoryLayout())
      {
      vtkArrayIterator* srcIter = inArray->NewIterator();
      vtkArrayIterator* destIter = outArray->NewIterator();

      switch (inArray->GetDataType())
        {
        vtkArrayIteratorTemplateMacro(
          vtkDataSetAttributesCopyValues(
            static_cast<VTK_TT*>(destIter), outExt, outIncs,
            static_cast<VTK_TT*>(srcIter), inExt, inIncs));
        }
      srcIter->Delete();
      destIter->Delete();
      }
    else
      {
      switch (inArray->GetDataType())
        {
        vtkTemplateMacro(
          vtkTypedDataArray<VTK_TT> *typedIn =
            vtkTypedDataArray<VTK_TT>::FastDownCast(inArray);
          vtkTypedDataArray<VTK_TT> *typedOut =
            vtkTypedDataArray<VTK_TT>::FastDownCast(outArray);
          if (typedIn == NULL || typedOut == NULL)
            {
            vtkGenericWarningMacro("Cannot copy to/from a mapped data array "
                                   "from/into an array that does not derive "
                                   "from vtkTypedDataArray.");
            continue;
            }
          vtkTypedIteratorDataSetAttributesCopyValues(
                vtkTypedDataArrayIterator<VTK_TT>(typedOut), outExt, outIncs,
                vtkTypedDataArrayIterator<VTK_TT>(typedIn), inExt, inIncs)
              ); // end vtkTemplateMacro
        }
      }
    }
}

//--------------------------------------------------------------------------
// 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::CopyData(vtkDataSetAttributes *fromPd,
                                    vtkIdList *fromIds, vtkIdList *toIds)
{
  int i;
  for(i=this->RequiredArrays.BeginIndex(); !this->RequiredArrays.End();
      i=this->RequiredArrays.NextIndex())
    {
    this->CopyTuples(fromPd->Data[i], this->Data[this->TargetIndices[i]],
        fromIds, toIds);
    }
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::CopyData(vtkDataSetAttributes *fromPd,
                                    vtkIdType dstStart, vtkIdType n,
                                    vtkIdType srcStart)
{
  for (int i = this->RequiredArrays.BeginIndex(); !this->RequiredArrays.End();
       i = this->RequiredArrays.NextIndex())
    {
    this->CopyTuples(fromPd->Data[i], this->Data[this->TargetIndices[i]],
                     dstStart, n, srcStart);
    }
}

//--------------------------------------------------------------------------
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);
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::CopyTuples(vtkAbstractArray *fromData,
                                      vtkAbstractArray *toData,
                                      vtkIdList *fromIds, vtkIdList *toIds)
{
  toData->InsertTuples(toIds, fromIds, fromData);
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::CopyTuples(vtkAbstractArray *fromData,
                                      vtkAbstractArray *toData,
                                      vtkIdType dstStart, vtkIdType n,
                                      vtkIdType srcStart)
{
  toData->InsertTuples(dstStart, n, srcStart, 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);
}

//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetTensors(const char* name)
{
  if (name == NULL || name[0] == '\0')
    {
    return this->GetTensors();
    }
  return this->GetArray(name);
}

//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetGlobalIds(const char* name)
{
  if (name == NULL || name[0] == '\0')
    {
    return this->GetGlobalIds();
    }
  return this->GetArray(name);
}

//--------------------------------------------------------------------------
vtkAbstractArray* vtkDataSetAttributes::GetPedigreeIds(const char* name)
{
  if (name == NULL || name[0] == '\0')
    {
    return this->GetPedigreeIds();
    }
  return this->GetAbstractArray(name);
}

//--------------------------------------------------------------------------
int vtkDataSetAttributes::SetActiveAttribute(int index, int attributeType)
{
  if ( (index >= 0) && (index < this->GetNumberOfArrays()))
    {
    if (attributeType != PEDIGREEIDS)
      {
      vtkDataArray* darray = vtkDataArray::SafeDownCast(
        this->Data[index]);
      if (!darray)
        {
        vtkWarningMacro("Can not set attribute "
          << vtkDataSetAttributes::AttributeNames[attributeType]
          << ". Only vtkDataArray subclasses can be set as active attributes.");
        return -1;
        }
      if (!this->CheckNumberOfComponents(darray, attributeType))
        {
        vtkWarningMacro("Can not set attribute "
                        << vtkDataSetAttributes::AttributeNames[attributeType]
                        << ". Incorrect number of components.");
        return -1;
        }
      }

    this->AttributeIndices[attributeType] = index;
    this->Modified();
    return index;
    }
  else if (index == -1)
    {
    this->AttributeIndices[attributeType] = index;
    this->Modified();
    }

  return -1;
}

//--------------------------------------------------------------------------
const int vtkDataSetAttributes
::NumberOfAttributeComponents[vtkDataSetAttributes::NUM_ATTRIBUTES] =
{ 0,
  3,
  3,
  3,
  9,
  1,
  1,
  1};

//--------------------------------------------------------------------------
// Scalars set to NOLIMIT
const int vtkDataSetAttributes
::AttributeLimits[vtkDataSetAttributes::NUM_ATTRIBUTES] =
{ NOLIMIT,
  EXACT,
  EXACT,
  MAX,
  EXACT,
  EXACT,
  EXACT,
  EXACT};

//--------------------------------------------------------------------------
int vtkDataSetAttributes::CheckNumberOfComponents(vtkAbstractArray* aa,
                                                  int attributeType)
{
  int numComp = aa->GetNumberOfComponents();

  if ( vtkDataSetAttributes::AttributeLimits[attributeType] == MAX )
    {
    if ( numComp >
         vtkDataSetAttributes::NumberOfAttributeComponents[attributeType] )
      {
      return 0;
      }
    else
      {
      return 1;
      }
    }
  else if ( vtkDataSetAttributes::AttributeLimits[attributeType] == EXACT )
    {
    if ( numComp !=
         vtkDataSetAttributes::NumberOfAttributeComponents[attributeType] )
      {
      return 0;
      }
    else
      {
      return 1;
      }
    }
  else if ( vtkDataSetAttributes::AttributeLimits[attributeType] == NOLIMIT )
    {
    return 1;
    }
  else
    {
    return 0;
    }
}

//--------------------------------------------------------------------------
vtkDataArray* vtkDataSetAttributes::GetAttribute(int attributeType)
{
  int index = this->AttributeIndices[attributeType];
  if (index == -1)
    {
    return 0;
    }
  else
    {
    return vtkDataArray::SafeDownCast(this->Data[index]);
    }
}

//--------------------------------------------------------------------------
vtkAbstractArray* vtkDataSetAttributes::GetAbstractAttribute(int attributeType)
{
  int index = this->AttributeIndices[attributeType];
  if (index == -1)
    {
    return 0;
    }
  else
    {
    return this->Data[index];
    }
}

//--------------------------------------------------------------------------
// This method lets the user add an array and make it the current
// scalars, vectors etc... (this is determined by the attribute type
// which is an enum defined vtkDataSetAttributes)
int vtkDataSetAttributes::SetAttribute(vtkAbstractArray* aa, int attributeType)
{
  if (aa && attributeType != PEDIGREEIDS && !vtkDataArray::SafeDownCast(aa))
    {
    vtkWarningMacro("Can not set attribute "
                    << vtkDataSetAttributes::AttributeNames[attributeType]
                    << ". This attribute must be a subclass of vtkDataArray.");
    return -1;
    }
  if (aa && !this->CheckNumberOfComponents(aa, attributeType))
    {
    vtkWarningMacro("Can not set attribute "
                    << vtkDataSetAttributes::AttributeNames[attributeType]
                    << ". Incorrect number of components.");
    return -1;
    }

  int currentAttribute = this->AttributeIndices[attributeType];

  // If there is an existing attribute, replace it
  if ( (currentAttribute >= 0) &&
       (currentAttribute < this->GetNumberOfArrays()) )
    {
    if (this->GetAbstractArray(currentAttribute) == aa)
      {
      return currentAttribute;
      }
    this->RemoveArray(currentAttribute);
    }

  if (aa)
    {
    // Add the array
    currentAttribute = this->AddArray(aa);
    this->AttributeIndices[attributeType] = currentAttribute;
    }
  else
    {
    this->AttributeIndices[attributeType] = -1; //attribute of this type doesn't exist
    }
  this->Modified();
  return this->AttributeIndices[attributeType];
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);

  // Print the copy flags
  int i;
  os << indent << "Copy Tuple Flags: ( ";
  for (i=0; i<NUM_ATTRIBUTES; i++)
    {
    os << this->CopyAttributeFlags[COPYTUPLE][i] << " ";
    }
  os << ")" << endl;
  os << indent << "Interpolate Flags: ( ";
  for (i=0; i<NUM_ATTRIBUTES; i++)
    {
    os << this->CopyAttributeFlags[INTERPOLATE][i] << " ";
    }
  os << ")" << endl;
  os << indent << "Pass Through Flags: ( ";
  for (i=0; i<NUM_ATTRIBUTES; i++)
    {
    os << this->CopyAttributeFlags[PASSDATA][i] << " ";
    }
  os << ")" << endl;

  // Now print the various attributes
  vtkAbstractArray* aa;
  int attributeType;
  for (attributeType=0; attributeType<NUM_ATTRIBUTES; attributeType++)
    {
    os << indent << vtkDataSetAttributes::AttributeNames[attributeType]
       << ": ";
    if ( (aa=this->GetAbstractAttribute(attributeType)) )
      {
      os << endl;
      aa->PrintSelf(os, indent.GetNextIndent());
      }
    else
      {
      os << "(none)" << endl;
      }
    }

}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::GetAttributeIndices(int* indexArray)
{
  int i;
  for(i=0; i<NUM_ATTRIBUTES; i++)
    {
    indexArray[i] = this->AttributeIndices[i];
    }
}

//--------------------------------------------------------------------------
int vtkDataSetAttributes::IsArrayAnAttribute(int idx)
{
  int i;
  for (i=0; i<NUM_ATTRIBUTES; i++)
    {
    if ( idx == this->AttributeIndices[i] )
      {
      return i;
      }
    }
  return -1;
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::SetCopyAttribute (int index, int value, int ctype)
{
  if (ctype == vtkDataSetAttributes::ALLCOPY)
    {
    int t;
    for (t = COPYTUPLE; t < vtkDataSetAttributes::ALLCOPY; t++)
      {
      if (this->CopyAttributeFlags[t][ index ] != value)
        {
        this->CopyAttributeFlags[t][ index ] = value;
        this->Modified();
        }
      }
    }
  else
    {
    if (this->CopyAttributeFlags[ctype][ index ] != value)
      {
      this->CopyAttributeFlags[ctype][ index ] = value;
      this->Modified();
      }
    }
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::SetCopyScalars(int i, int ctype)
{
  this->SetCopyAttribute(SCALARS, i, ctype);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::GetCopyScalars(int ctype) {
  if (ctype == vtkDataSetAttributes::ALLCOPY)
    {
    return
      this->CopyAttributeFlags[COPYTUPLE][SCALARS] &&
      this->CopyAttributeFlags[INTERPOLATE][SCALARS] &&
      this->CopyAttributeFlags[PASSDATA][SCALARS];
    }
  else
    {
    return
      this->CopyAttributeFlags[ctype][SCALARS];
    }
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::SetCopyVectors(int i, int ctype)
{
  this->SetCopyAttribute(VECTORS, i, ctype);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::GetCopyVectors(int ctype)
{
  if (ctype == vtkDataSetAttributes::ALLCOPY)
    {
    return
      this->CopyAttributeFlags[COPYTUPLE][VECTORS] &&
      this->CopyAttributeFlags[INTERPOLATE][VECTORS] &&
      this->CopyAttributeFlags[PASSDATA][VECTORS];
    }
  else
    {
    return
      this->CopyAttributeFlags[ctype][VECTORS];
    }
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::SetCopyNormals(int i, int ctype)
{
  this->SetCopyAttribute(NORMALS, i, ctype);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::GetCopyNormals(int ctype)
{
  if (ctype == vtkDataSetAttributes::ALLCOPY)
    {
    return
      this->CopyAttributeFlags[COPYTUPLE][NORMALS] &&
      this->CopyAttributeFlags[INTERPOLATE][NORMALS] &&
      this->CopyAttributeFlags[PASSDATA][NORMALS];
    }
  else
    {
    return
      this->CopyAttributeFlags[ctype][NORMALS];
    }
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::SetCopyTCoords(int i, int ctype)
{
  this->SetCopyAttribute(TCOORDS, i, ctype);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::GetCopyTCoords(int ctype)
{
  if (ctype == vtkDataSetAttributes::ALLCOPY)
    {
    return
      this->CopyAttributeFlags[COPYTUPLE][TCOORDS] &&
      this->CopyAttributeFlags[INTERPOLATE][TCOORDS] &&
      this->CopyAttributeFlags[PASSDATA][TCOORDS];
    }
  else
    {
    return
      this->CopyAttributeFlags[ctype][TCOORDS];
    }
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::SetCopyTensors(int i, int ctype)
{
  this->SetCopyAttribute(TENSORS, i, ctype);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::GetCopyTensors(int ctype)
{
  if (ctype == vtkDataSetAttributes::ALLCOPY)
    {
    return
      this->CopyAttributeFlags[COPYTUPLE][TENSORS] &&
      this->CopyAttributeFlags[INTERPOLATE][TENSORS] &&
      this->CopyAttributeFlags[PASSDATA][TENSORS];
    }
  else
    {
    return
      this->CopyAttributeFlags[ctype][TENSORS];
    }
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::SetCopyGlobalIds(int i, int ctype)
{
  this->SetCopyAttribute(GLOBALIDS, i, ctype);
}
//--------------------------------------------------------------------------
int vtkDataSetAttributes::GetCopyGlobalIds(int ctype)
{
  if (ctype == vtkDataSetAttributes::ALLCOPY)
    {
    return
      this->CopyAttributeFlags[COPYTUPLE][GLOBALIDS] &&
      this->CopyAttributeFlags[INTERPOLATE][GLOBALIDS] &&
      this->CopyAttributeFlags[PASSDATA][GLOBALIDS];
    }
  else
    {
    return
      this->CopyAttributeFlags[ctype][GLOBALIDS];
    }
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::SetCopyPedigreeIds(int i, int ctype)
{
  this->SetCopyAttribute(PEDIGREEIDS, i, ctype);
}

//--------------------------------------------------------------------------
int vtkDataSetAttributes::GetCopyPedigreeIds(int ctype)
{
  if (ctype == vtkDataSetAttributes::ALLCOPY)
    {
    return
      this->CopyAttributeFlags[COPYTUPLE][PEDIGREEIDS] &&
      this->CopyAttributeFlags[INTERPOLATE][PEDIGREEIDS] &&
      this->CopyAttributeFlags[PASSDATA][PEDIGREEIDS];
    }
  else
    {
    return
      this->CopyAttributeFlags[ctype][PEDIGREEIDS];
    }
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::RemoveArray(const char *name)
{
  int i;
  this->GetAbstractArray(name, i);
  this->RemoveArray(i);
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::CopyAllocate(
  vtkDataSetAttributes::FieldList& list,
  vtkIdType sze, vtkIdType ext)
{
  this->InternalCopyAllocate(list, COPYTUPLE, sze, ext);
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::InterpolateAllocate(
  vtkDataSetAttributes::FieldList& list, vtkIdType sze,
  vtkIdType ext)
{
  this->InternalCopyAllocate(list, INTERPOLATE, sze, ext);
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::InternalCopyAllocate(
  vtkDataSetAttributes::FieldList& list,
  int ctype,
  vtkIdType sze, vtkIdType ext)
{
  vtkAbstractArray* newAA=0;
  vtkDataArray* newDA=0;
  int i;

  // Allocate attributes if any
  for (i=0; i < list.NumberOfFields; i++)
    {
    if ( list.FieldIndices[i] >= 0 )
      {
      newAA = vtkAbstractArray::CreateArray(list.FieldTypes[i]);
      newAA->SetName(list.Fields[i]);
      newAA->SetNumberOfComponents(list.FieldComponents[i]);

      if ( list.FieldComponentsNames[i] )
        {
        for (unsigned int j=0; j < list.FieldComponentsNames[i]->size(); ++j)
          {
          if (list.FieldComponentsNames[i]->at(j).first)
            {
            newAA->SetComponentName(j,
              list.FieldComponentsNames[i]->at(j).second.c_str());
            }
          }
        }
      if (list.FieldInformation[i])
        {
        newAA->CopyInformation(list.FieldInformation[i],/*deep=*/1);
        }

      if ( sze > 0 )
        {
        newAA->Allocate(sze,ext);
        }
      else
        {
        newAA->Allocate(list.NumberOfTuples,ext);
        }

      if ( (newDA = vtkDataArray::SafeDownCast(newAA)) )
        {
        newDA->SetLookupTable(list.LUT[i]);
        }


      // If attribute data, do something extra
      if ( i < NUM_ATTRIBUTES )
        {
        // since attributes can only be DataArray, newDA must be non-null.
        if ( this->CopyAttributeFlags[ctype][i] && newDA)
          {
          list.FieldIndices[i] = this->AddArray(newDA);
          this->SetActiveAttribute(list.FieldIndices[i], i);
          }
        else
          {
          list.FieldIndices[i] = -1;
          }
        }
      else //check if this field is to be copied
        {
        if ( (this->GetFlag(list.Fields[i]) != 0) &&
             !(this->DoCopyAllOff && (this->GetFlag(list.Fields[i]) != 1)) )
          {
          list.FieldIndices[i] = this->AddArray(newAA);
          }
        else
          {
          list.FieldIndices[i] = -1;
          }
        }

      newAA->Delete(); //okay, reference counting
      }//data array defined
    }
}

//--------------------------------------------------------------------------
// Description:
// A special form of CopyData() to be used with FieldLists. Use it when you are
// copying data from a set of vtkDataSetAttributes. Make sure that you have
// called the special form of CopyAllocate that accepts FieldLists.
void vtkDataSetAttributes::CopyData(vtkDataSetAttributes::FieldList& list,
                                    vtkDataSetAttributes* fromDSA,
                                    int idx, vtkIdType fromId, vtkIdType toId)
{
  vtkAbstractArray *fromDA;
  vtkAbstractArray *toDA;

  int i;
  for (i=0; i < list.NumberOfFields; i++)
    {
    if ( list.FieldIndices[i] >= 0 && list.DSAIndices[idx][i] >= 0 )
      {
      toDA = this->GetAbstractArray(list.FieldIndices[i]);
      fromDA = fromDSA->GetAbstractArray(list.DSAIndices[idx][i]);
      this->CopyTuple(fromDA, toDA, fromId, toId);
      }
    }
}

//--------------------------------------------------------------------------
// Interpolate data from points and interpolation weights. Make sure that the
// method InterpolateAllocate() has been invoked before using this method.
void vtkDataSetAttributes::InterpolatePoint(
  vtkDataSetAttributes::FieldList& list,
  vtkDataSetAttributes *fromPd,
  int idx,
  vtkIdType toId, vtkIdList *ptIds,
  double *weights)
{
  vtkAbstractArray *fromArray;
  vtkAbstractArray *toArray;

  for (int i=0; i < list.NumberOfFields; i++)
    {
    if ( list.FieldIndices[i] >= 0 && list.DSAIndices[idx][i] >= 0 )
      {
      toArray = this->GetAbstractArray(list.FieldIndices[i]);
      fromArray = fromPd->GetAbstractArray(list.DSAIndices[idx][i]);
      toArray->InterpolateTuple(toId, ptIds, fromArray, weights);
      }
    }
}

//--------------------------------------------------------------------------
const char* vtkDataSetAttributes::GetAttributeTypeAsString(int attributeType)
{
  if (attributeType < 0 || attributeType >= NUM_ATTRIBUTES)
    {
    vtkGenericWarningMacro("Bad attribute type.");
    return NULL;
    }
  return vtkDataSetAttributes::AttributeNames[attributeType];
}

//--------------------------------------------------------------------------
const char* vtkDataSetAttributes::GetLongAttributeTypeAsString(int attributeType)
{
  if (attributeType < 0 || attributeType >= NUM_ATTRIBUTES)
    {
    vtkGenericWarningMacro("Bad attribute type.");
    return NULL;
    }
  return vtkDataSetAttributes::LongAttributeNames[attributeType];
}

//=============================================================================
vtkDataSetAttributes::FieldList::FieldList(int numInputs)
{
  this->Fields = 0;
  this->FieldTypes = 0;
  this->FieldComponents = 0;
  this->FieldComponentsNames = 0;
  this->FieldIndices = 0;
  this->NumberOfFields = 0;
  this->LUT = 0;
  this->FieldInformation = 0;
  this->DSAIndices = 0;
  this->NumberOfDSAIndices = 0;
  //
  if (numInputs)
    {
    this->NumberOfDSAIndices = numInputs;
    this->DSAIndices = new int*[numInputs];
    int i;
    for (i=0; i<numInputs; i++)
      {
      this->DSAIndices[i] = 0;
      }
    }
}

//--------------------------------------------------------------------------
vtkDataSetAttributes::FieldList::~FieldList()
{
  this->ClearFields();
  delete [] this->DSAIndices;
  this->DSAIndices = 0;
}

//----------------------------------------------------------------------------
// To perform intersection of attribute data, use IntializeFieldList() to grab
// an initial vtkDataSetAttributes. Then use IntersectFieldList() to add (and
// intersect) additional vtkDataSetAttributes.
void vtkDataSetAttributes::FieldList::InitializeFieldList(
  vtkDataSetAttributes* dsa)
{
  int i;
  this->ClearFields();
  // Allocate space for the arrays plus five attributes
  this->NumberOfFields = dsa->GetNumberOfArrays() + NUM_ATTRIBUTES;
  this->Fields = new char*[this->NumberOfFields];
  this->FieldTypes = new int [this->NumberOfFields];
  this->FieldComponents = new int [this->NumberOfFields];
  this->FieldComponentsNames =
    new vtkDataSetAttributes::vtkInternalComponentNames*[this->NumberOfFields];
  this->FieldIndices = new int [this->NumberOfFields];
  this->LUT = new vtkLookupTable* [this->NumberOfFields];
  this->FieldInformation = new vtkInformation* [this->NumberOfFields];
  for(i=0; i < this->NumberOfFields; i++)
    {
    this->Fields[i] = 0;
    this->FieldTypes[i] = -1;
    this->FieldComponents[i] = 0;
    this->FieldComponentsNames[i] = 0;
    this->FieldIndices[i] = -1;
    this->LUT[i] = 0;
    this->FieldInformation[i] = 0;
    }
  this->CurrentInput = 0;
  this->NumberOfTuples = 0;

  //there may be no data hence dsa->Data
  for(i=0; dsa->Data && i < dsa->GetNumberOfArrays(); i++)
    {
    int attrType = dsa->IsArrayAnAttribute(i);
    if ( attrType != -1 ) //it's an attribute
      {
      this->FieldIndices[attrType] = i;
      this->SetField(attrType, dsa->Data[i]);
      }
    else
      {
      this->FieldIndices[NUM_ATTRIBUTES+i] = i;
      this->SetField(NUM_ATTRIBUTES+i, dsa->Data[i]);
      }
    }

  // The first dataset is added to the field list
  this->IntersectFieldList(dsa);
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::FieldList::UnionFieldList(vtkDataSetAttributes* dsa)
{
  vtkAbstractArray* aa;
  vtkDataArray* da;
  // Keep a running total of the number of tuples...might be useful
  // for later allocation.
  if ( (aa=dsa->GetAbstractArray(0)) )
    {
    this->NumberOfTuples += aa->GetNumberOfTuples();
    }

  // unlike Intersection, with Union the the total number of fields may change,
  // so we have to be careful with that.
  std::vector<int> dsaIndices;
  dsaIndices.resize(this->NumberOfFields, -1);

  // Intersect the active attributes. (Even though we are taking a union, we
  // intersect the active attributes).
  int attributeIndices[NUM_ATTRIBUTES];
  dsa->GetAttributeIndices(attributeIndices);
  for (int i=0; i < NUM_ATTRIBUTES; i++)
    {
    if (this->FieldIndices[i] >= 0)
      {
      da = dsa->GetAttribute(i);
      if ((da) && (da->GetDataType() == this->FieldTypes[i]) &&
          (da->GetNumberOfComponents() == this->FieldComponents[i]))
        {
        dsaIndices[i] = attributeIndices[i];
        }
      else
        {
        // doh! A attribute is not available in this new dsa. But it was
        // available until now.

        // In InitializeFieldList(), if an array is an active attribute, its
        // information is noted only in the first "set". Now since we are
        // marking it as not-an-attribute, we still don't want to lose the
        // array. So we enable it in the second "set". But all DSAIndices until
        // the CurrentInput referred to this array in it's location in the
        // first "set" so we have to move those as well. That's what's
        // happening here.
        int offset = this->FieldIndices[i];
        this->FieldIndices[NUM_ATTRIBUTES + offset] = this->FieldIndices[i];
        this->Fields[offset+NUM_ATTRIBUTES] = this->Fields[i];
        this->FieldTypes[offset+NUM_ATTRIBUTES] = this->FieldTypes[i];
        this->FieldComponents[offset+NUM_ATTRIBUTES] = this->FieldComponents[i];
        this->FieldComponentsNames[offset+NUM_ATTRIBUTES] = this->FieldComponentsNames[i];
        this->LUT[offset+NUM_ATTRIBUTES] = this->LUT[i];
        this->FieldInformation[offset+NUM_ATTRIBUTES] = this->FieldInformation[i];

        this->FieldIndices[i] = -1; //Attribute not present
        this->Fields[i] = NULL;
        this->FieldTypes[i] = -1;
        this->FieldComponents[i] = 0;
        this->FieldComponentsNames[i] = NULL;
        this->LUT[i] = NULL;
        this->FieldInformation[i] = NULL;

        for (int cc=0; cc < this->CurrentInput && cc < this->NumberOfDSAIndices;
          cc++)
          {
          this->DSAIndices[cc][offset+NUM_ATTRIBUTES] = this->DSAIndices[cc][i];
          this->DSAIndices[cc][i] = -1;
          }
        }
      }
    }

  std::vector<bool> dsaMarkedArrays;
  dsaMarkedArrays.resize(dsa->GetNumberOfArrays(), false);

  // * Try to match the existing fields with those in dsa.
  for (int i = NUM_ATTRIBUTES; i < this->NumberOfFields; i++)
    {
    // FieldIndices should really be a bool.
    if (this->FieldIndices[i] < 0)
      {
      continue;
      }
    int index;
    aa = dsa->GetAbstractArray(this->Fields[i], index);
    if ((aa) && (aa->GetDataType() == this->FieldTypes[i]) &&
      (aa->GetNumberOfComponents() == this->FieldComponents[i]))
      {
      dsaIndices[i] = index;
      dsaMarkedArrays[index] = true;
      }
    }

  // * Now every array in dsaMarkedArrays that has a false, implies that it did not
  // match with any of the existing fields. So those will be appended to the
  // end of the field list.
  std::vector<int> dsaPendingIndices;
  for (size_t cc=0; cc < dsaMarkedArrays.size(); cc++)
    {
    if (dsaMarkedArrays[cc] == false)
      {
      dsaPendingIndices.push_back(static_cast<int>(cc));
      }
    }

  if (dsaPendingIndices.size() != 0)
    {
    size_t old_size = dsaIndices.size();
    size_t new_size = old_size + dsaPendingIndices.size();

    // * If dsaPendingIndices != empty, then we need to grow the num of fields.
    this->GrowBy(static_cast<unsigned int>(dsaPendingIndices.size()));

    dsaIndices.resize(new_size, -1);
    for (size_t cc=0; cc < dsaPendingIndices.size(); cc++)
      {
      this->FieldIndices[old_size+cc] =
        static_cast<int>((old_size+cc) - NUM_ATTRIBUTES);
      this->SetField(static_cast<int>(old_size+cc),
        dsa->GetAbstractArray(dsaPendingIndices[cc]));
      dsaIndices[old_size + cc] = dsaPendingIndices[cc];
      }
    }

  this->DSAIndices[this->CurrentInput] = new int [this->NumberOfFields];
  memcpy(this->DSAIndices[this->CurrentInput], &dsaIndices[0],
    sizeof(int)*this->NumberOfFields);

  this->CurrentInput++;
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::FieldList::GrowBy(unsigned int delta)
{
  if (delta == 0)
    {
    return;
    }

  int old_size = this->NumberOfFields;
  int new_size = this->NumberOfFields + delta;

  char** newFields = new char*[new_size];
  int* newFieldTypes = new int[new_size];
  int* newFieldComponents = new int [new_size];
  vtkDataSetAttributes::vtkInternalComponentNames** newFieldComponentsNames
    = new vtkDataSetAttributes::vtkInternalComponentNames* [ new_size ];

  int* newFieldIndices = new int [new_size];
  vtkLookupTable** newLUT = new vtkLookupTable* [new_size];
  vtkInformation** newFieldInformation = new vtkInformation* [new_size];

  // copy the old fields.
  for(int i=0; i < old_size; i++)
    {
    if (this->Fields[i])
      {
      newFields[i] = strdup(this->Fields[i]);
      }
    else
      {
      newFields[i] = NULL;
      }
    if ( this->FieldComponentsNames[i] )
      {
      newFieldComponentsNames[i] =
        new vtkDataSetAttributes::vtkInternalComponentNames(
        *this->FieldComponentsNames[i]);
      }
    else
      {
      newFieldComponentsNames[i] = NULL;
      }
    }
  memcpy(newFieldTypes, this->FieldTypes, sizeof(int)*old_size);
  memcpy(newFieldComponents, this->FieldComponents, sizeof(int)*old_size);
  memcpy(newFieldIndices, this->FieldIndices, sizeof(int)*old_size);
  memcpy(newLUT, this->LUT, sizeof(vtkLookupTable*)*old_size);
  memcpy(newFieldInformation, this->FieldInformation,
    sizeof(vtkInformation*)*old_size);

  // initialize the rest.
  for (int i=old_size; i < new_size; i++)
    {
    newFields[i] = NULL;
    newFieldTypes[i] = -1;
    newFieldComponents[i] = 0;
    newFieldIndices[i] = -1;
    newLUT[i] = NULL;
    newFieldInformation[i] = NULL;
    newFieldComponentsNames[i] = NULL;
    }

  int **newDSAIndices = new int*[this->NumberOfDSAIndices];
  for (int cc=0; cc < this->NumberOfDSAIndices; cc++)
    {
    if (this->DSAIndices[cc] != NULL)
      {
      newDSAIndices[cc] = new int[new_size];
      memcpy(newDSAIndices[cc], this->DSAIndices[cc], sizeof(int)*old_size);
      for (int kk=old_size; kk < new_size; kk++)
        {
        newDSAIndices[cc][kk] = -1;
        }
      }
    else
      {
      newDSAIndices[cc] = NULL;
      }
    }

  int currentInput = this->CurrentInput;
  int numberOfDSAIndices = this->NumberOfDSAIndices;

  this->ClearFields();

  this->NumberOfFields = new_size;
  this->NumberOfDSAIndices = numberOfDSAIndices;
  this->CurrentInput = currentInput;
  this->Fields = newFields;
  this->FieldTypes = newFieldTypes;
  this->FieldComponents = newFieldComponents;
  this->FieldComponentsNames = newFieldComponentsNames;
  this->FieldIndices = newFieldIndices;
  this->LUT = newLUT;
  this->FieldInformation = newFieldInformation;
  this->DSAIndices = newDSAIndices;
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::FieldList::IntersectFieldList(vtkDataSetAttributes* dsa)
{
  int i;
  vtkDataArray *da;
  vtkAbstractArray* aa;

  // Initialize the indices for this dataset
  this->DSAIndices[this->CurrentInput] = new int [this->NumberOfFields];
  for (i=0; i < this->NumberOfFields; i++)
    {
    this->DSAIndices[this->CurrentInput][i]= -1;
    }

  // Keep a running total of the number of tuples...might be useful
  // for later allocation.
  if ( (da=dsa->GetArray(0)) )
    {
    this->NumberOfTuples += da->GetNumberOfTuples();
    }

  // Intersect the attributes
  int attributeIndices[NUM_ATTRIBUTES];
  dsa->GetAttributeIndices(attributeIndices);
  for(i=0; i < NUM_ATTRIBUTES; i++)
    {
    if ( this->FieldIndices[i] >= 0 )
      {
      da = dsa->GetAttribute(i);
      if ((da) && (da->GetDataType() == this->FieldTypes[i]) &&
          (da->GetNumberOfComponents() == this->FieldComponents[i]))
        {
        this->DSAIndices[this->CurrentInput][i] = attributeIndices[i];
        }
      else
        {
        this->FieldIndices[i] = -1; //Attribute not present
        }
      }
    }
  // Intersect the fields
  int index;
  for(i=NUM_ATTRIBUTES; i < this->NumberOfFields; i++)
    {
    if (this->FieldIndices[i] >= 0)
      {
      aa = dsa->GetAbstractArray(this->Fields[i], index);
      if ((aa) && (aa->GetDataType() == this->FieldTypes[i]) &&
          (aa->GetNumberOfComponents() == this->FieldComponents[i]))
        {
        this->DSAIndices[this->CurrentInput][i] = index;
        }
      else
        {
        this->FieldIndices[i] = -1; //Field not present
        }
      }
    }

  this->CurrentInput++;
}

//--------------------------------------------------------------------------
int vtkDataSetAttributes::FieldList::IsAttributePresent(int attrType)
{
  return this->FieldIndices[attrType];
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::FieldList::ClearFields()
{
  int i;
  if ( this->Fields )
    {
    for (i=0; i<this->NumberOfFields; i++)
      {
      delete [] this->Fields[i];
      this->Fields[i] = 0;
      }
    }
  if ( this->DSAIndices )
    {
    for (i=0; i<this->NumberOfDSAIndices; i++)
      {
      delete[] this->DSAIndices[i];
      this->DSAIndices[i] = 0;
      }
    }
  //
  delete [] this->Fields;
  this->Fields = 0;

  delete [] this->FieldInformation;
  this->FieldInformation = 0;

  delete [] this->LUT;
  this->LUT = 0;

  delete [] this->FieldTypes;
  this->FieldTypes = 0;

  delete [] this->FieldComponents;
  this->FieldComponents = 0;

  if ( this->FieldComponentsNames )
    {
    for (i=0; i<this->NumberOfFields; i++)
      {
      delete this->FieldComponentsNames[i];
      }
    delete [] this->FieldComponentsNames;
    this->FieldComponentsNames = 0;
    }

  delete [] this->FieldIndices;
  this->FieldIndices = 0;

  this->NumberOfFields = 0;
  this->CurrentInput = 0;
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::FieldList::SetField(
        int index,
        vtkAbstractArray *aa)
{
  // Store the field name
  delete [] this->Fields[index];
  this->Fields[index] = 0;
  const char* name=aa->GetName();
  if (name)
    {
    int len = static_cast<int>(strlen(name));
    if (len > 0)
      {
      this->Fields[index] = new char[len+1];
      strcpy(this->Fields[index], name);
      }
    }
  // Store the data type
  this->FieldTypes[index] = aa->GetDataType();

  //we unallocate the names before we update the field components
  //so we unallocate correctly
  delete this->FieldComponentsNames[index];
  this->FieldComponentsNames[index] = NULL;

  //store the components names
  int numberOfComponents = aa->GetNumberOfComponents();
  if ( aa->HasAComponentName() )
    {
    this->FieldComponentsNames[index] =
      new vtkDataSetAttributes::vtkInternalComponentNames();
    this->FieldComponentsNames[index]->resize(numberOfComponents,
      std::pair<bool, vtkStdString>(false, vtkStdString()));
    name = NULL;
    for ( vtkIdType i=0; i < numberOfComponents; ++i)
      {
      name = aa->GetComponentName(i);
      if ( name )
        {
        this->FieldComponentsNames[index]->at(i) =
          std::pair<bool, vtkStdString>(true, name);
        name = NULL;
        }
      }
    }

  // Store the components
  this->FieldComponents[index] = numberOfComponents;

  // Store the lookup table
  this->LUT[index]=0;
  if (vtkDataArray::SafeDownCast(aa))
    {
    this->LUT[index]=vtkDataArray::SafeDownCast(aa)->GetLookupTable();
    }
  // Store the information
  this->FieldInformation[index] = 0;
  if (aa->HasInformation())
    {
    this->FieldInformation[index] = aa->GetInformation();
    }
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::FieldList::RemoveField(const char *name)
{
  if ( !name )
    {
    return;
    }

  int i;
  for (i=NUM_ATTRIBUTES; i < this->NumberOfFields; i++)
    {
    if ( this->Fields[i] && !strcmp(this->Fields[i],name) )
      {
      delete [] this->Fields[i];
      this->Fields[i] = 0;
      this->FieldTypes[i] = -1;
      this->FieldComponents[i] = 0;

      delete this->FieldComponentsNames[i];
      this->FieldComponentsNames[i] = 0;

      this->FieldIndices[i] = -1;
      this->LUT[i] = 0;
      this->FieldInformation[i] = 0;
      return;
      }
    }
}

//--------------------------------------------------------------------------
void vtkDataSetAttributes::FieldList::PrintSelf(ostream &os, vtkIndent indent)
{
  os << indent << "Number of Fields:" << this->NumberOfFields << endl;
  vtkIndent nextIndent=indent.GetNextIndent();
  for (int i=0; i<this->NumberOfFields; ++i)
    {
    os << indent << "Field " << i << " {" << endl
       << nextIndent
       << (this->Fields[i]==0?"NULL":this->Fields[i]) << ", "
       << this->FieldTypes[i] << ", "
       << this->FieldComponents[i] << ", "
       << this->FieldIndices[i] << ", "
       << this->FieldInformation[i]
       << "}" << endl;
    }
}