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
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkGenericDataArray.txx
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.
=========================================================================*/
#ifndef vtkGenericDataArray_txx
#define vtkGenericDataArray_txx
#include "vtkGenericDataArray.h"
#include "vtkIdList.h"
#include "vtkMath.h"
#include "vtkVariantCast.h"
//-----------------------------------------------------------------------------
VTK_ABI_NAMESPACE_BEGIN
template <class DerivedT, class ValueTypeT>
double* vtkGenericDataArray<DerivedT, ValueTypeT>::GetTuple(vtkIdType tupleIdx)
{
assert(!this->LegacyTuple.empty() && "Number of components is nonzero.");
this->GetTuple(tupleIdx, &this->LegacyTuple[0]);
return &this->LegacyTuple[0];
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::GetTuple(vtkIdType tupleIdx, double* tuple)
{
for (int c = 0; c < this->NumberOfComponents; ++c)
{
tuple[c] = static_cast<double>(this->GetTypedComponent(tupleIdx, c));
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::InterpolateTuple(
vtkIdType dstTupleIdx, vtkIdList* ptIndices, vtkAbstractArray* source, double* weights)
{
// First, check for the common case of typeid(source) == typeid(this). This
// way we don't waste time redoing the other checks in the superclass, and
// can avoid doing a dispatch for the most common usage of this method.
DerivedT* other = vtkArrayDownCast<DerivedT>(source);
if (!other)
{
// Let the superclass handle dispatch/fallback.
this->Superclass::InterpolateTuple(dstTupleIdx, ptIndices, source, weights);
return;
}
int numComps = this->GetNumberOfComponents();
if (other->GetNumberOfComponents() != numComps)
{
vtkErrorMacro("Number of components do not match: Source: "
<< other->GetNumberOfComponents() << " Dest: " << this->GetNumberOfComponents());
return;
}
vtkIdType numIds = ptIndices->GetNumberOfIds();
vtkIdType* ids = ptIndices->GetPointer(0);
for (int c = 0; c < numComps; ++c)
{
double val = 0.;
for (vtkIdType tupleId = 0; tupleId < numIds; ++tupleId)
{
vtkIdType t = ids[tupleId];
double weight = weights[tupleId];
val += weight * static_cast<double>(other->GetTypedComponent(t, c));
}
ValueType valT;
vtkMath::RoundDoubleToIntegralIfNecessary(val, &valT);
this->InsertTypedComponent(dstTupleIdx, c, valT);
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::InterpolateTuple(vtkIdType dstTupleIdx,
vtkIdType srcTupleIdx1, vtkAbstractArray* source1, vtkIdType srcTupleIdx2,
vtkAbstractArray* source2, double t)
{
// First, check for the common case of typeid(source) == typeid(this). This
// way we don't waste time redoing the other checks in the superclass, and
// can avoid doing a dispatch for the most common usage of this method.
DerivedT* other1 = vtkArrayDownCast<DerivedT>(source1);
DerivedT* other2 = other1 ? vtkArrayDownCast<DerivedT>(source2) : nullptr;
if (!other1 || !other2)
{
// Let the superclass handle dispatch/fallback.
this->Superclass::InterpolateTuple(
dstTupleIdx, srcTupleIdx1, source1, srcTupleIdx2, source2, t);
return;
}
if (srcTupleIdx1 >= source1->GetNumberOfTuples())
{
vtkErrorMacro("Tuple 1 out of range for provided array. "
"Requested tuple: "
<< srcTupleIdx1
<< " "
"Tuples: "
<< source1->GetNumberOfTuples());
return;
}
if (srcTupleIdx2 >= source2->GetNumberOfTuples())
{
vtkErrorMacro("Tuple 2 out of range for provided array. "
"Requested tuple: "
<< srcTupleIdx2
<< " "
"Tuples: "
<< source2->GetNumberOfTuples());
return;
}
int numComps = this->GetNumberOfComponents();
if (other1->GetNumberOfComponents() != numComps)
{
vtkErrorMacro("Number of components do not match: Source: "
<< other1->GetNumberOfComponents() << " Dest: " << this->GetNumberOfComponents());
return;
}
if (other2->GetNumberOfComponents() != numComps)
{
vtkErrorMacro("Number of components do not match: Source: "
<< other2->GetNumberOfComponents() << " Dest: " << this->GetNumberOfComponents());
return;
}
const double oneMinusT = 1. - t;
double val;
ValueType valT;
for (int c = 0; c < numComps; ++c)
{
val = other1->GetTypedComponent(srcTupleIdx1, c) * oneMinusT +
other2->GetTypedComponent(srcTupleIdx2, c) * t;
vtkMath::RoundDoubleToIntegralIfNecessary(val, &valT);
this->InsertTypedComponent(dstTupleIdx, c, valT);
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::SetComponent(
vtkIdType tupleIdx, int compIdx, double value)
{
// Reimplemented for efficiency (base impl allocates heap memory)
this->SetTypedComponent(tupleIdx, compIdx, static_cast<ValueType>(value));
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
double vtkGenericDataArray<DerivedT, ValueTypeT>::GetComponent(vtkIdType tupleIdx, int compIdx)
{
// Reimplemented for efficiency (base impl allocates heap memory)
return static_cast<double>(this->GetTypedComponent(tupleIdx, compIdx));
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::RemoveTuple(vtkIdType id)
{
if (id < 0 || id >= this->GetNumberOfTuples())
{
// Nothing to be done
return;
}
if (id == (this->GetNumberOfTuples() - 1))
{
// To remove last item, just decrease the size by one
this->RemoveLastTuple();
return;
}
// This is a very slow implementation since it uses generic API. Subclasses
// are encouraged to provide a faster implementation.
assert(((this->GetNumberOfTuples() - id) - 1) /* (length) */ > 0);
int numComps = this->GetNumberOfComponents();
vtkIdType fromTuple = id + 1;
vtkIdType toTuple = id;
vtkIdType endTuple = this->GetNumberOfTuples();
for (; fromTuple != endTuple; ++toTuple, ++fromTuple)
{
for (int comp = 0; comp < numComps; ++comp)
{
this->SetTypedComponent(toTuple, comp, this->GetTypedComponent(fromTuple, comp));
}
}
this->SetNumberOfTuples(this->GetNumberOfTuples() - 1);
this->DataChanged();
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::SetVoidArray(void*, vtkIdType, int)
{
vtkErrorMacro("SetVoidArray is not supported by this class.");
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::SetVoidArray(void*, vtkIdType, int, int)
{
vtkErrorMacro("SetVoidArray is not supported by this class.");
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::SetArrayFreeFunction(void (*)(void*))
{
vtkErrorMacro("SetArrayFreeFunction is not supported by this class.");
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void* vtkGenericDataArray<DerivedT, ValueTypeT>::WriteVoidPointer(vtkIdType, vtkIdType)
{
vtkErrorMacro("WriteVoidPointer is not supported by this class.");
return nullptr;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
typename vtkGenericDataArray<DerivedT, ValueTypeT>::ValueType*
vtkGenericDataArray<DerivedT, ValueTypeT>::WritePointer(vtkIdType id, vtkIdType number)
{
return static_cast<ValueType*>(this->WriteVoidPointer(id, number));
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
int vtkGenericDataArray<DerivedT, ValueTypeT>::GetDataType() const
{
return vtkTypeTraits<ValueType>::VTK_TYPE_ID;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
int vtkGenericDataArray<DerivedT, ValueTypeT>::GetDataTypeSize() const
{
return static_cast<int>(sizeof(ValueType));
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
bool vtkGenericDataArray<DerivedT, ValueTypeT>::HasStandardMemoryLayout() const
{
// False by default, AoS should set true.
return false;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void* vtkGenericDataArray<DerivedT, ValueTypeT>::GetVoidPointer(vtkIdType)
{
vtkErrorMacro("GetVoidPointer is not supported by this class.");
return nullptr;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
typename vtkGenericDataArray<DerivedT, ValueTypeT>::ValueType*
vtkGenericDataArray<DerivedT, ValueTypeT>::GetPointer(vtkIdType id)
{
return static_cast<ValueType*>(this->GetVoidPointer(id));
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkIdType vtkGenericDataArray<DerivedT, ValueTypeT>::LookupValue(vtkVariant valueVariant)
{
bool valid = true;
ValueType value = vtkVariantCast<ValueType>(valueVariant, &valid);
if (valid)
{
return this->LookupTypedValue(value);
}
return -1;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkIdType vtkGenericDataArray<DerivedT, ValueTypeT>::LookupTypedValue(ValueType value)
{
return this->Lookup.LookupValue(value);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::LookupValue(vtkVariant valueVariant, vtkIdList* ids)
{
ids->Reset();
bool valid = true;
ValueType value = vtkVariantCast<ValueType>(valueVariant, &valid);
if (valid)
{
this->LookupTypedValue(value, ids);
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::LookupTypedValue(ValueType value, vtkIdList* ids)
{
ids->Reset();
this->Lookup.LookupValue(value, ids);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::ClearLookup()
{
this->Lookup.ClearLookup();
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::DataChanged()
{
this->Lookup.ClearLookup();
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::SetVariantValue(
vtkIdType valueIdx, vtkVariant valueVariant)
{
bool valid = true;
ValueType value = vtkVariantCast<ValueType>(valueVariant, &valid);
if (valid)
{
this->SetValue(valueIdx, value);
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkVariant vtkGenericDataArray<DerivedT, ValueTypeT>::GetVariantValue(vtkIdType valueIdx)
{
return vtkVariant(this->GetValue(valueIdx));
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::InsertVariantValue(
vtkIdType valueIdx, vtkVariant valueVariant)
{
bool valid = true;
ValueType value = vtkVariantCast<ValueType>(valueVariant, &valid);
if (valid)
{
this->InsertValue(valueIdx, value);
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkTypeBool vtkGenericDataArray<DerivedT, ValueTypeT>::Allocate(
vtkIdType size, vtkIdType vtkNotUsed(ext))
{
// Allocator must updated this->Size and this->MaxId properly.
this->MaxId = -1;
if (size > this->Size || size == 0)
{
this->Size = 0;
// let's keep the size an integral multiple of the number of components.
size = size < 0 ? 0 : size;
int numComps = this->GetNumberOfComponents() > 0 ? this->GetNumberOfComponents() : 1;
double ceilNum = ceil(static_cast<double>(size) / static_cast<double>(numComps));
vtkIdType numTuples = static_cast<vtkIdType>(ceilNum);
// NOTE: if numTuples is 0, AllocateTuples is expected to release the
// memory.
if (this->AllocateTuples(numTuples) == false)
{
vtkErrorMacro(
"Unable to allocate " << size << " elements of size " << sizeof(ValueType) << " bytes. ");
#if !defined NDEBUG
// We're debugging, crash here preserving the stack
abort();
#elif !defined VTK_DONT_THROW_BAD_ALLOC
// We can throw something that has universal meaning
throw std::bad_alloc();
#else
// We indicate that alloc failed by return
return 0;
#endif
}
this->Size = numTuples * numComps;
}
this->DataChanged();
return 1;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkTypeBool vtkGenericDataArray<DerivedT, ValueTypeT>::Resize(vtkIdType numTuples)
{
int numComps = this->GetNumberOfComponents();
vtkIdType curNumTuples = this->Size / (numComps > 0 ? numComps : 1);
if (numTuples > curNumTuples)
{
// Requested size is bigger than current size. Allocate enough
// memory to fit the requested size and be more than double the
// currently allocated memory.
numTuples = curNumTuples + numTuples;
}
else if (numTuples == curNumTuples)
{
return 1;
}
else
{
// Requested size is smaller than current size. Squeeze the
// memory.
this->DataChanged();
}
assert(numTuples >= 0);
if (!this->ReallocateTuples(numTuples))
{
vtkErrorMacro("Unable to allocate " << numTuples * numComps << " elements of size "
<< sizeof(ValueType) << " bytes. ");
#if !defined NDEBUG
// We're debugging, crash here preserving the stack
abort();
#elif !defined VTK_DONT_THROW_BAD_ALLOC
// We can throw something that has universal meaning
throw std::bad_alloc();
#else
// We indicate that malloc failed by return
return 0;
#endif
}
// Allocation was successful. Save it.
this->Size = numTuples * numComps;
// Update MaxId if we truncated:
if ((this->Size - 1) < this->MaxId)
{
this->MaxId = (this->Size - 1);
}
return 1;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::SetNumberOfComponents(int num)
{
this->vtkDataArray::SetNumberOfComponents(num);
this->LegacyTuple.resize(num);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::SetNumberOfTuples(vtkIdType number)
{
vtkIdType newSize = number * this->NumberOfComponents;
if (this->Allocate(newSize, 0))
{
this->MaxId = newSize - 1;
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::Initialize()
{
this->Resize(0);
this->DataChanged();
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::Squeeze()
{
this->Resize(this->GetNumberOfTuples());
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::SetTuple(
vtkIdType dstTupleIdx, vtkIdType srcTupleIdx, vtkAbstractArray* source)
{
// First, check for the common case of typeid(source) == typeid(this). This
// way we don't waste time redoing the other checks in the superclass, and
// can avoid doing a dispatch for the most common usage of this method.
DerivedT* other = vtkArrayDownCast<DerivedT>(source);
if (!other)
{
// Let the superclass handle dispatch/fallback.
this->Superclass::SetTuple(dstTupleIdx, srcTupleIdx, source);
return;
}
int numComps = this->GetNumberOfComponents();
if (source->GetNumberOfComponents() != numComps)
{
vtkErrorMacro("Number of components do not match: Source: "
<< source->GetNumberOfComponents() << " Dest: " << this->GetNumberOfComponents());
return;
}
for (int c = 0; c < numComps; ++c)
{
this->SetTypedComponent(dstTupleIdx, c, other->GetTypedComponent(srcTupleIdx, c));
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::InsertTuples(
vtkIdList* dstIds, vtkIdList* srcIds, vtkAbstractArray* source)
{
// First, check for the common case of typeid(source) == typeid(this). This
// way we don't waste time redoing the other checks in the superclass, and
// can avoid doing a dispatch for the most common usage of this method.
DerivedT* other = vtkArrayDownCast<DerivedT>(source);
if (!other)
{
// Let the superclass handle dispatch/fallback.
this->Superclass::InsertTuples(dstIds, srcIds, source);
return;
}
if (dstIds->GetNumberOfIds() == 0)
{
return;
}
if (dstIds->GetNumberOfIds() != srcIds->GetNumberOfIds())
{
vtkErrorMacro("Mismatched number of tuples ids. Source: "
<< srcIds->GetNumberOfIds() << " Dest: " << dstIds->GetNumberOfIds());
return;
}
int numComps = this->GetNumberOfComponents();
if (other->GetNumberOfComponents() != numComps)
{
vtkErrorMacro("Number of components do not match: Source: "
<< other->GetNumberOfComponents() << " Dest: " << this->GetNumberOfComponents());
return;
}
vtkIdType maxSrcTupleId = srcIds->GetId(0);
vtkIdType maxDstTupleId = dstIds->GetId(0);
for (int i = 0; i < dstIds->GetNumberOfIds(); ++i)
{
// parenthesis around std::max prevent MSVC macro replacement when
// inlined:
maxSrcTupleId = (std::max)(maxSrcTupleId, srcIds->GetId(i));
maxDstTupleId = (std::max)(maxDstTupleId, dstIds->GetId(i));
}
if (maxSrcTupleId >= other->GetNumberOfTuples())
{
vtkErrorMacro("Source array too small, requested tuple at index "
<< maxSrcTupleId << ", but there are only " << other->GetNumberOfTuples()
<< " tuples in the array.");
return;
}
vtkIdType newSize = (maxDstTupleId + 1) * this->NumberOfComponents;
if (this->Size < newSize)
{
if (!this->Resize(maxDstTupleId + 1))
{
vtkErrorMacro("Resize failed.");
return;
}
}
// parenthesis around std::max prevent MSVC macro replacement when
// inlined:
this->MaxId = (std::max)(this->MaxId, newSize - 1);
vtkIdType numTuples = srcIds->GetNumberOfIds();
for (vtkIdType t = 0; t < numTuples; ++t)
{
vtkIdType srcT = srcIds->GetId(t);
vtkIdType dstT = dstIds->GetId(t);
for (int c = 0; c < numComps; ++c)
{
this->SetTypedComponent(dstT, c, other->GetTypedComponent(srcT, c));
}
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::InsertTuplesStartingAt(
vtkIdType dstStart, vtkIdList* srcIds, vtkAbstractArray* source)
{
// First, check for the common case of typeid(source) == typeid(this). This
// way we don't waste time redoing the other checks in the superclass, and
// can avoid doing a dispatch for the most common usage of this method.
DerivedT* other = vtkArrayDownCast<DerivedT>(source);
if (!other)
{
// Let the superclass handle dispatch/fallback.
this->Superclass::InsertTuplesStartingAt(dstStart, srcIds, source);
return;
}
int numComps = this->GetNumberOfComponents();
if (other->GetNumberOfComponents() != numComps)
{
vtkErrorMacro("Number of components do not match: Source: "
<< other->GetNumberOfComponents() << " Dest: " << this->GetNumberOfComponents());
return;
}
vtkIdType maxSrcTupleId = srcIds->GetId(0);
vtkIdType maxDstTupleId = dstStart + srcIds->GetNumberOfIds() - 1;
for (int i = 0; i < srcIds->GetNumberOfIds(); ++i)
{
// parenthesis around std::max prevent MSVC macro replacement when
// inlined:
maxSrcTupleId = (std::max)(maxSrcTupleId, srcIds->GetId(i));
}
if (maxSrcTupleId >= other->GetNumberOfTuples())
{
vtkErrorMacro("Source array too small, requested tuple at index "
<< maxSrcTupleId << ", but there are only " << other->GetNumberOfTuples()
<< " tuples in the array.");
return;
}
vtkIdType newSize = (maxDstTupleId + 1) * this->NumberOfComponents;
if (this->Size < newSize)
{
if (!this->Resize(maxDstTupleId + 1))
{
vtkErrorMacro("Resize failed.");
return;
}
}
// parenthesis around std::max prevent MSVC macro replacement when
// inlined:
this->MaxId = (std::max)(this->MaxId, newSize - 1);
vtkIdType numTuples = srcIds->GetNumberOfIds();
for (vtkIdType t = 0; t < numTuples; ++t)
{
vtkIdType srcT = srcIds->GetId(t);
vtkIdType dstT = dstStart + t;
for (int c = 0; c < numComps; ++c)
{
this->SetTypedComponent(dstT, c, other->GetTypedComponent(srcT, c));
}
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::InsertTuple(
vtkIdType i, vtkIdType j, vtkAbstractArray* source)
{
this->EnsureAccessToTuple(i);
this->SetTuple(i, j, source);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::InsertTuple(vtkIdType i, const float* source)
{
this->EnsureAccessToTuple(i);
this->SetTuple(i, source);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::InsertTuple(vtkIdType i, const double* source)
{
this->EnsureAccessToTuple(i);
this->SetTuple(i, source);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::InsertComponent(
vtkIdType tupleIdx, int compIdx, double value)
{
// Update MaxId to the inserted component (not the complete tuple) for
// compatibility with InsertNextValue.
vtkIdType newMaxId = tupleIdx * this->NumberOfComponents + compIdx;
if (newMaxId < this->MaxId)
{
newMaxId = this->MaxId;
}
this->EnsureAccessToTuple(tupleIdx);
assert("Sufficient space allocated." && this->MaxId >= newMaxId);
if (this->MaxId != newMaxId)
{
this->MaxId = newMaxId;
}
this->SetComponent(tupleIdx, compIdx, value);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkIdType vtkGenericDataArray<DerivedT, ValueTypeT>::InsertNextTuple(
vtkIdType srcTupleIdx, vtkAbstractArray* source)
{
vtkIdType nextTuple = this->GetNumberOfTuples();
this->InsertTuple(nextTuple, srcTupleIdx, source);
return nextTuple;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkIdType vtkGenericDataArray<DerivedT, ValueTypeT>::InsertNextTuple(const float* tuple)
{
vtkIdType nextTuple = this->GetNumberOfTuples();
this->InsertTuple(nextTuple, tuple);
return nextTuple;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkIdType vtkGenericDataArray<DerivedT, ValueTypeT>::InsertNextTuple(const double* tuple)
{
vtkIdType nextTuple = this->GetNumberOfTuples();
this->InsertTuple(nextTuple, tuple);
return nextTuple;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::GetTuples(
vtkIdList* tupleIds, vtkAbstractArray* output)
{
// First, check for the common case of typeid(source) == typeid(this). This
// way we don't waste time redoing the other checks in the superclass, and
// can avoid doing a dispatch for the most common usage of this method.
DerivedT* other = vtkArrayDownCast<DerivedT>(output);
if (!other)
{
// Let the superclass handle dispatch/fallback.
this->Superclass::GetTuples(tupleIds, output);
return;
}
int numComps = this->GetNumberOfComponents();
if (other->GetNumberOfComponents() != numComps)
{
vtkErrorMacro("Number of components for input and output do not match.\n"
"Source: "
<< this->GetNumberOfComponents()
<< "\n"
"Destination: "
<< other->GetNumberOfComponents());
return;
}
vtkIdType* srcTuple = tupleIds->GetPointer(0);
vtkIdType* srcTupleEnd = tupleIds->GetPointer(tupleIds->GetNumberOfIds());
vtkIdType dstTuple = 0;
while (srcTuple != srcTupleEnd)
{
for (int c = 0; c < numComps; ++c)
{
other->SetTypedComponent(dstTuple, c, this->GetTypedComponent(*srcTuple, c));
}
++srcTuple;
++dstTuple;
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::GetTuples(
vtkIdType p1, vtkIdType p2, vtkAbstractArray* output)
{
// First, check for the common case of typeid(source) == typeid(this). This
// way we don't waste time redoing the other checks in the superclass, and
// can avoid doing a dispatch for the most common usage of this method.
DerivedT* other = vtkArrayDownCast<DerivedT>(output);
if (!other)
{
// Let the superclass handle dispatch/fallback.
this->Superclass::GetTuples(p1, p2, output);
return;
}
int numComps = this->GetNumberOfComponents();
if (other->GetNumberOfComponents() != numComps)
{
vtkErrorMacro("Number of components for input and output do not match.\n"
"Source: "
<< this->GetNumberOfComponents()
<< "\n"
"Destination: "
<< other->GetNumberOfComponents());
return;
}
// p1-p2 are inclusive
for (vtkIdType srcT = p1, dstT = 0; srcT <= p2; ++srcT, ++dstT)
{
for (int c = 0; c < numComps; ++c)
{
other->SetTypedComponent(dstT, c, this->GetTypedComponent(srcT, c));
}
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkArrayIterator* vtkGenericDataArray<DerivedT, ValueTypeT>::NewIterator()
{
vtkWarningMacro(<< "No vtkArrayIterator defined for " << this->GetClassName() << " arrays.");
return nullptr;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkIdType vtkGenericDataArray<DerivedT, ValueTypeT>::InsertNextValue(ValueType value)
{
vtkIdType nextValueIdx = this->MaxId + 1;
if (nextValueIdx >= this->Size)
{
vtkIdType tuple = nextValueIdx / this->NumberOfComponents;
this->EnsureAccessToTuple(tuple);
// Since EnsureAccessToTuple will update the MaxId to point to the last
// component in the last tuple, we move it back to support this method on
// multi-component arrays.
this->MaxId = nextValueIdx;
}
// Extending array without needing to reallocate:
if (this->MaxId < nextValueIdx)
{
this->MaxId = nextValueIdx;
}
this->SetValue(nextValueIdx, value);
return nextValueIdx;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::InsertValue(vtkIdType valueIdx, ValueType value)
{
vtkIdType tuple = valueIdx / this->NumberOfComponents;
// Update MaxId to the inserted component (not the complete tuple) for
// compatibility with InsertNextValue.
vtkIdType newMaxId = valueIdx > this->MaxId ? valueIdx : this->MaxId;
if (this->EnsureAccessToTuple(tuple))
{
assert("Sufficient space allocated." && this->MaxId >= newMaxId);
this->MaxId = newMaxId;
this->SetValue(valueIdx, value);
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::InsertTypedTuple(
vtkIdType tupleIdx, const ValueType* t)
{
if (this->EnsureAccessToTuple(tupleIdx))
{
this->SetTypedTuple(tupleIdx, t);
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkIdType vtkGenericDataArray<DerivedT, ValueTypeT>::InsertNextTypedTuple(const ValueType* t)
{
vtkIdType nextTuple = this->GetNumberOfTuples();
this->InsertTypedTuple(nextTuple, t);
return nextTuple;
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::InsertTypedComponent(
vtkIdType tupleIdx, int compIdx, ValueType val)
{
// Update MaxId to the inserted component (not the complete tuple) for
// compatibility with InsertNextValue.
vtkIdType newMaxId = tupleIdx * this->NumberOfComponents + compIdx;
if (this->MaxId > newMaxId)
{
newMaxId = this->MaxId;
}
this->EnsureAccessToTuple(tupleIdx);
assert("Sufficient space allocated." && this->MaxId >= newMaxId);
if (this->MaxId != newMaxId)
{
this->MaxId = newMaxId;
}
this->SetTypedComponent(tupleIdx, compIdx, val);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
typename vtkGenericDataArray<DerivedT, ValueTypeT>::ValueType*
vtkGenericDataArray<DerivedT, ValueTypeT>::GetValueRange(int comp)
{
this->LegacyValueRange.resize(2);
this->GetValueRange(this->LegacyValueRange.data(), comp);
return &this->LegacyValueRange[0];
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
typename vtkGenericDataArray<DerivedT, ValueTypeT>::ValueType*
vtkGenericDataArray<DerivedT, ValueTypeT>::GetFiniteValueRange(int comp)
{
this->LegacyValueRange.resize(2);
this->GetFiniteValueRange(this->LegacyValueRange.data(), comp);
return &this->LegacyValueRange[0];
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::GetFiniteValueRange(ValueType range[2], int comp)
{
this->GetFiniteValueRange(range, comp, nullptr);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::GetFiniteValueRange(
ValueType range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
{
this->ComputeFiniteValueRange(range, comp, ghosts, ghostsToSkip);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::FillTypedComponent(int compIdx, ValueType value)
{
if (compIdx < 0 || compIdx >= this->NumberOfComponents)
{
vtkErrorMacro(<< "Specified component " << compIdx << " is not in [0, "
<< this->NumberOfComponents << ")");
return;
}
for (vtkIdType i = 0; i < this->GetNumberOfTuples(); ++i)
{
this->SetTypedComponent(i, compIdx, value);
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::FillValue(ValueType value)
{
for (int i = 0; i < this->NumberOfComponents; ++i)
{
this->FillTypedComponent(i, value);
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::FillComponent(int compIdx, double value)
{
this->FillTypedComponent(compIdx, static_cast<ValueType>(value));
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkGenericDataArray<DerivedT, ValueTypeT>::vtkGenericDataArray()
{
// Initialize internal data structures:
this->Lookup.SetArray(this);
this->SetNumberOfComponents(this->NumberOfComponents);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
vtkGenericDataArray<DerivedT, ValueTypeT>::~vtkGenericDataArray() = default;
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
bool vtkGenericDataArray<DerivedT, ValueTypeT>::EnsureAccessToTuple(vtkIdType tupleIdx)
{
if (tupleIdx < 0)
{
return false;
}
vtkIdType minSize = (1 + tupleIdx) * this->NumberOfComponents;
vtkIdType expectedMaxId = minSize - 1;
if (this->MaxId < expectedMaxId)
{
if (this->Size < minSize)
{
if (!this->Resize(tupleIdx + 1))
{
return false;
}
}
this->MaxId = expectedMaxId;
}
return true;
}
// The following introduces a layer of indirection that allows us to use the
// optimized range computation logic in vtkDataArrayPrivate.txx for common
// arrays, but fallback to computing the range at double precision and then
// converting to the valuetype for unknown array types, or for types where
// the conversion from double->ValueType doesn't lose precision.
template <typename ValueType>
class vtkAOSDataArrayTemplate;
template <typename ValueType>
class vtkSOADataArrayTemplate;
#ifdef VTK_USE_SCALED_SOA_ARRAYS
template <typename ValueType>
class vtkScaledSOADataArrayTemplate;
#endif
VTK_ABI_NAMESPACE_END
namespace vtk_GDA_detail
{
VTK_ABI_NAMESPACE_BEGIN
// Arrays templates with compiled-in support for value ranges in
// vtkGenericDataArray.cxx
template <typename ArrayType>
struct ATIsSupported : public std::false_type
{
};
template <typename ValueType>
struct ATIsSupported<vtkAOSDataArrayTemplate<ValueType>> : public std::true_type
{
};
template <typename ValueType>
struct ATIsSupported<vtkSOADataArrayTemplate<ValueType>> : public std::true_type
{
};
#ifdef VTK_USE_SCALED_SOA_ARRAYS
template <typename ValueType>
struct ATIsSupported<vtkScaledSOADataArrayTemplate<ValueType>> : public std::true_type
{
};
#endif
// ValueTypes with compiled-in support for value ranges in
// vtkGenericDataArray.cxx
template <typename ValueType>
struct VTIsSupported : public std::false_type
{
};
template <>
struct VTIsSupported<long> : public std::true_type
{
};
template <>
struct VTIsSupported<unsigned long> : public std::true_type
{
};
template <>
struct VTIsSupported<long long> : public std::true_type
{
};
template <>
struct VTIsSupported<unsigned long long> : public std::true_type
{
};
// Full array types with compiled-in support for value ranges in
// vtkGenericDataArray.cxx
template <typename ArrayType, typename ValueType>
struct IsSupported
: public std::integral_constant<bool,
(ATIsSupported<ArrayType>::value && VTIsSupported<ValueType>::value)>
{
};
VTK_ABI_NAMESPACE_END
} // end namespace vtk_GDA_detail
VTK_ABI_NAMESPACE_BEGIN
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::ComputeValueRange(
ValueType range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
{
using namespace vtk_GDA_detail;
using Supported = IsSupported<DerivedT, ValueTypeT>;
// For array / value types without specific implementations compiled into
// vtkGenericDataArray.cxx, fall back to the GetRange computations in
// vtkDataArray. In these cases, either a) the ValueType's full range is
// expressible as a double, or b) we aren't aware of the array type.
// This reduces the number of specialized range implementations we need to
// compile, and is also faster since we're able to cache the GetValue
// computation (See #17666).
if (!Supported::value)
{
double tmpRange[2];
this->ComputeRange(tmpRange, comp, ghosts, ghostsToSkip);
range[0] = static_cast<ValueType>(tmpRange[0]);
range[1] = static_cast<ValueType>(tmpRange[1]);
return;
}
range[0] = vtkTypeTraits<ValueType>::Max();
range[1] = vtkTypeTraits<ValueType>::Min();
if (comp > this->NumberOfComponents)
{
return;
}
if (comp < 0 && this->NumberOfComponents == 1)
{
comp = 0;
}
// TODO this should eventually cache the results, but we do not have support
// for all of the information keys we need to cover all possible value types.
if (comp < 0)
{
this->ComputeVectorValueRange(range, ghosts, ghostsToSkip);
}
else
{
this->LegacyValueRangeFull.resize(this->NumberOfComponents * 2);
if (this->ComputeScalarValueRange(this->LegacyValueRangeFull.data(), ghosts, ghostsToSkip))
{
range[0] = this->LegacyValueRangeFull[comp * 2];
range[1] = this->LegacyValueRangeFull[comp * 2 + 1];
}
}
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::GetValueRange(ValueType range[2], int comp)
{
this->GetValueRange(range, comp, nullptr);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::GetValueRange(
ValueType range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
{
this->ComputeValueRange(range, comp, ghosts, ghostsToSkip);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
void vtkGenericDataArray<DerivedT, ValueTypeT>::ComputeFiniteValueRange(
ValueType range[2], int comp, const unsigned char* ghosts, unsigned char ghostsToSkip)
{
using namespace vtk_GDA_detail;
using Supported = IsSupported<DerivedT, ValueTypeT>;
// For array / value types without specific implementations compiled into
// vtkGenericDataArray.cxx, fall back to the GetRange computations in
// vtkDataArray. In these cases, either a) the ValueType's full range is
// expressible as a double, or b) we aren't aware of the array type.
// This reduces the number of specialized range implementations we need to
// compile, and is also faster since we're able to cache the GetValue
// computation (See #17666).
if (!Supported::value)
{
double tmpRange[2];
this->ComputeFiniteRange(tmpRange, comp);
range[0] = static_cast<ValueType>(tmpRange[0]);
range[1] = static_cast<ValueType>(tmpRange[1]);
return;
}
range[0] = vtkTypeTraits<ValueType>::Max();
range[1] = vtkTypeTraits<ValueType>::Min();
if (comp > this->NumberOfComponents)
{
return;
}
if (comp < 0 && this->NumberOfComponents == 1)
{
comp = 0;
}
// TODO this should eventually cache the results, but we do not have support
// for all of the information keys we need to cover all possible value types.
if (comp < 0)
{
this->ComputeFiniteVectorValueRange(range, ghosts, ghostsToSkip);
}
else
{
this->LegacyValueRangeFull.resize(this->NumberOfComponents * 2);
if (this->ComputeFiniteScalarValueRange(
this->LegacyValueRangeFull.data(), ghosts, ghostsToSkip))
{
range[0] = this->LegacyValueRangeFull[comp * 2];
range[1] = this->LegacyValueRangeFull[comp * 2 + 1];
}
}
}
VTK_ABI_NAMESPACE_END
namespace vtk_GDA_detail
{
VTK_ABI_NAMESPACE_BEGIN
template <typename ArrayType, typename ValueType, typename Tag>
bool ComputeScalarValueRangeImpl(ArrayType* array, ValueType* range, Tag tag, std::true_type,
const unsigned char* ghosts, unsigned char ghostsToSkip)
{
return ::vtkDataArrayPrivate::DoComputeScalarRange(array, range, tag, ghosts, ghostsToSkip);
}
template <typename ArrayType, typename ValueType, typename Tag>
bool ComputeScalarValueRangeImpl(ArrayType* array, ValueType* range, Tag tag, std::false_type,
const unsigned char* ghosts, unsigned char ghostsToSkip)
{
// Compute the range at double precision.
std::size_t numComps = static_cast<size_t>(array->GetNumberOfComponents());
std::vector<double> tmpRange(numComps * 2);
if (!::vtkDataArrayPrivate::DoComputeScalarRange(
static_cast<vtkDataArray*>(array), tmpRange.data(), tag, ghosts, ghostsToSkip))
{
return false;
}
for (std::size_t i = 0; i < numComps * 2; ++i)
{
range[i] = static_cast<ValueType>(tmpRange[i]);
}
return true;
}
template <typename ArrayType, typename ValueType, typename Tag>
bool ComputeVectorValueRangeImpl(ArrayType* array, ValueType range[2], Tag tag, std::true_type,
const unsigned char* ghosts, unsigned char ghostsToSkip)
{
return ::vtkDataArrayPrivate::DoComputeVectorRange(array, range, tag, ghosts, ghostsToSkip);
}
template <typename ArrayType, typename ValueType, typename Tag>
bool ComputeVectorValueRangeImpl(ArrayType* array, ValueType range[2], Tag tag, std::false_type,
const unsigned char* ghosts, unsigned char ghostsToSkip)
{
// Compute the range at double precision.
double tmpRange[2];
if (!::vtkDataArrayPrivate::DoComputeVectorRange(
static_cast<vtkDataArray*>(array), tmpRange, tag, ghosts, ghostsToSkip))
{
return false;
}
range[0] = static_cast<ValueType>(tmpRange[0]);
range[1] = static_cast<ValueType>(tmpRange[1]);
return true;
}
VTK_ABI_NAMESPACE_END
} // namespace vtk_GDA_detail
VTK_ABI_NAMESPACE_BEGIN
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
bool vtkGenericDataArray<DerivedT, ValueTypeT>::ComputeScalarValueRange(
ValueType* ranges, const unsigned char* ghosts, unsigned char ghostsToSkip)
{
using namespace vtk_GDA_detail;
using Supported = IsSupported<DerivedT, ValueTypeT>;
return ComputeScalarValueRangeImpl(static_cast<DerivedT*>(this), ranges,
vtkDataArrayPrivate::AllValues{}, Supported{}, ghosts, ghostsToSkip);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
bool vtkGenericDataArray<DerivedT, ValueTypeT>::ComputeVectorValueRange(
ValueType range[2], const unsigned char* ghosts, unsigned char ghostsToSkip)
{
using namespace vtk_GDA_detail;
using Supported = IsSupported<DerivedT, ValueTypeT>;
return ComputeVectorValueRangeImpl(static_cast<DerivedT*>(this), range,
vtkDataArrayPrivate::AllValues{}, Supported{}, ghosts, ghostsToSkip);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
bool vtkGenericDataArray<DerivedT, ValueTypeT>::ComputeFiniteScalarValueRange(
ValueType* range, const unsigned char* ghosts, unsigned char ghostsToSkip)
{
using namespace vtk_GDA_detail;
using Supported = IsSupported<DerivedT, ValueTypeT>;
return ComputeScalarValueRangeImpl(static_cast<DerivedT*>(this), range,
vtkDataArrayPrivate::FiniteValues{}, Supported{}, ghosts, ghostsToSkip);
}
//-----------------------------------------------------------------------------
template <class DerivedT, class ValueTypeT>
bool vtkGenericDataArray<DerivedT, ValueTypeT>::ComputeFiniteVectorValueRange(
ValueType range[2], const unsigned char* ghosts, unsigned char ghostsToSkip)
{
using namespace vtk_GDA_detail;
using Supported = IsSupported<DerivedT, ValueTypeT>;
return ComputeVectorValueRangeImpl(static_cast<DerivedT*>(this), range,
vtkDataArrayPrivate::FiniteValues{}, Supported{}, ghosts, ghostsToSkip);
}
#undef vtkGenericDataArrayT
VTK_ABI_NAMESPACE_END
#endif // header guard
|