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
|
/*=========================================================================
Program: ParaView
Module: vtkSMArrayListDomain.cxx
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 "vtkSMArrayListDomain.h"
#include "vtkDataSetAttributes.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPVArrayInformation.h"
#include "vtkPVCompositeDataInformation.h"
#include "vtkPVDataInformation.h"
#include "vtkPVDataSetAttributesInformation.h"
#include "vtkPVXMLElement.h"
#include "vtkSMInputArrayDomain.h"
#include "vtkSMProperty.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMSourceProxy.h"
#include "vtkSMStringVectorProperty.h"
#include "vtkSMUncheckedPropertyHelper.h"
#include "vtkStdString.h"
#include "vtkStringList.h"
#include <cassert>
#include <set>
#include <vector>
#include <algorithm>
#include <sstream>
vtkStandardNewMacro(vtkSMArrayListDomain);
struct vtkSMArrayListDomainInformationKey
{
vtkStdString Location;
vtkStdString Name;
int Strategy;
};
struct vtkSMArrayListDomainArrayInformation
{
vtkStdString ArrayName;
bool IsPartial;
// data association for this array on input.
int FieldAssociation;
// desired association for this array.
int DomainAssociation;
int ArrayAttributeType;
vtkSMArrayListDomainArrayInformation():
IsPartial(false),
FieldAssociation(vtkDataObject::POINT),
DomainAssociation(vtkDataObject::POINT),
ArrayAttributeType(-1)
{
}
bool operator==(const vtkSMArrayListDomainArrayInformation& other) const
{
return this->ArrayName == other.ArrayName &&
this->IsPartial == other.IsPartial &&
this->FieldAssociation == other.FieldAssociation &&
this->DomainAssociation == other.DomainAssociation &&
this->ArrayAttributeType == other.ArrayAttributeType;
}
// helps keep the set sorted in preferred order.
bool operator < (const vtkSMArrayListDomainArrayInformation& other) const
{
if (this->DomainAssociation == other.DomainAssociation)
{
if (this->FieldAssociation == other.FieldAssociation)
{
if (this->ArrayName == other.ArrayName)
{
// don't treat partial and non-partial arrays as different.
//if (this->IsPartial == other.IsPartial)
// {
return this->ArrayAttributeType < other.ArrayAttributeType;
// }
// return this->IsPartial < other.IsPartial;
}
return this->ArrayName < other.ArrayName;
}
return this->FieldAssociation < other.FieldAssociation;
}
return this->DomainAssociation < other.DomainAssociation;
}
};
class vtkSMArrayListDomainInternals
{
public:
std::vector<vtkSMArrayListDomainInformationKey> InformationKeys;
std::vector<int> DataTypes;
typedef std::vector<vtkSMArrayListDomainArrayInformation> DomainValuesVector;
DomainValuesVector DomainValues;
typedef std::set<vtkSMArrayListDomainArrayInformation> DomainValuesSet;
// Builds the list of acceptable arrays in result.
// association is the association requested by the domain
// required_number_of_components is the num-of-comps
void BuildArrayList(DomainValuesSet & result,
vtkSMArrayListDomain* self,
int association,
int required_number_of_components,
vtkPVDataInformation* dataInfo);
std::vector<vtkStdString> GetDomainValueStrings()
{
std::vector<vtkStdString> values;
for (DomainValuesVector::const_iterator iter = this->DomainValues.begin(),
end = this->DomainValues.end(); iter != end; ++iter)
{
values.push_back(iter->ArrayName);
}
return values;
}
const vtkSMArrayListDomainArrayInformation* FindAttribute(int array_attribute)
{
for (DomainValuesVector::const_iterator iter = this->DomainValues.begin(),
end = this->DomainValues.end(); iter != end; ++iter)
{
if (iter->ArrayAttributeType == array_attribute)
{
return &(*iter);
}
}
return NULL;
}
private:
bool IsArrayDataTypeAcceptable(vtkPVArrayInformation* arrayInfo) const
{
for (size_t cc=0, max=this->DataTypes.size(); cc < max; ++cc)
{
if (this->DataTypes[cc] == VTK_VOID ||
this->DataTypes[cc] == arrayInfo->GetDataType())
{
return true;
}
}
return (this->DataTypes.size() == 0);
}
bool AreArrayInformationKeysAcceptable(vtkPVArrayInformation* arrayInfo)
{
for (size_t cc=0, max=this->InformationKeys.size(); cc < max; ++cc)
{
vtkSMArrayListDomainInformationKey& key = this->InformationKeys[cc];
int hasInfo = arrayInfo->HasInformationKey(key.Location, key.Name);
if (hasInfo && key.Strategy == vtkSMArrayListDomain::REJECT_KEY)
{
return false;
}
if (!hasInfo && key.Strategy == vtkSMArrayListDomain::NEED_KEY)
{
return false;
}
}
return true;
}
};
//---------------------------------------------------------------------------
void vtkSMArrayListDomainInternals::BuildArrayList(
vtkSMArrayListDomainInternals::DomainValuesSet & result,
vtkSMArrayListDomain* self,
int association,
int required_number_of_components,
vtkPVDataInformation* dataInfo)
{
if (self->GetNoneString() && result.size() == 0)
{
vtkSMArrayListDomainArrayInformation info;
info.ArrayName = self->GetNoneString();
info.IsPartial = false;
info.FieldAssociation = 0;
info.DomainAssociation = 0;
result.insert(info);
}
// iterate over attributes arrays in dataInfo and add acceptable arrays to the
// domain.
for (int type=vtkSMInputArrayDomain::POINT;
type < vtkSMInputArrayDomain::NUMBER_OF_ATTRIBUTE_TYPES;
type++)
{
if (type == vtkSMInputArrayDomain::ANY)
{
continue;
}
vtkPVDataSetAttributesInformation* attrInfo = dataInfo->GetAttributeInformation(type);
int acceptable_as = type;
if (attrInfo == NULL ||
!vtkSMInputArrayDomain::IsAttributeTypeAcceptable(association, type, &acceptable_as))
{
continue;
}
assert(acceptable_as != vtkSMInputArrayDomain::ANY && acceptable_as != vtkSMInputArrayDomain::ANY_EXCEPT_FIELD);
// iterate over all arrays and add them to the list, if acceptable.
for (int idx=0, maxIdx=attrInfo->GetNumberOfArrays(); idx < maxIdx; ++idx)
{
vtkPVArrayInformation* arrayInfo = attrInfo->GetArrayInformation(idx);
// First check if the array is acceptable based on the component requirements.
if (arrayInfo == NULL||
!vtkSMInputArrayDomain::IsArrayAcceptable(required_number_of_components, arrayInfo))
{
continue;
}
// Then, check if the array name is acceptable
if (self->IsFilteredArray(dataInfo, type, arrayInfo->GetName()))
{
continue;
}
// Next, check if the array is acceptable based on the data-type
// limitations specified on self.
if (!this->IsArrayDataTypeAcceptable(arrayInfo))
{
continue;
}
// Next, check if the array is acceptable based on the information-key
// magic.
if (!this->AreArrayInformationKeysAcceptable(arrayInfo))
{
continue;
}
// ACCEPTABLE ARRAY FOUND!!!
// Add it to the list.
if (required_number_of_components == 0 ||
required_number_of_components == arrayInfo->GetNumberOfComponents())
{
// the array is directly acceptable (no need to split out components)
vtkSMArrayListDomainArrayInformation info;
info.ArrayName = arrayInfo->GetName();
info.IsPartial = (arrayInfo->GetIsPartial() != 0);
info.FieldAssociation = acceptable_as;
info.DomainAssociation = type;
info.ArrayAttributeType = attrInfo->IsArrayAnAttribute(idx);
result.insert(info);
}
else
{
// array has number of components that doesn't directly match the required
// component count. The array is being accepted due to automatic property
// conversion. So we need to split up components and add them individually.
assert(required_number_of_components == 1 &&
vtkSMInputArrayDomain::GetAutomaticPropertyConversion() == true &&
arrayInfo->GetNumberOfComponents() > 1);
for (int cc=0, maxCC=arrayInfo->GetNumberOfComponents();
cc <= maxCC; ++cc)
{
if (cc == maxCC && arrayInfo->GetDataType() == VTK_STRING)
{
// magnitude is added only for numeric arrays.
continue;
}
vtkSMArrayListDomainArrayInformation info;
info.ArrayName = vtkSMArrayListDomain::CreateMangledName(arrayInfo, cc);
info.IsPartial = (arrayInfo->GetIsPartial() != 0);
info.FieldAssociation = acceptable_as;
info.DomainAssociation = type;
info.ArrayAttributeType = attrInfo->IsArrayAnAttribute(idx);
result.insert(info);
}
}
} // end of for each array
} // end of for each attribute type
}
//---------------------------------------------------------------------------
vtkSMArrayListDomain::vtkSMArrayListDomain()
{
this->AttributeType = vtkDataSetAttributes::SCALARS;
this->InputDomainName = 0;
this->NoneString = 0;
this->ALDInternals = new vtkSMArrayListDomainInternals;
this->PickFirstAvailableArrayByDefault = true;
}
//---------------------------------------------------------------------------
vtkSMArrayListDomain::~vtkSMArrayListDomain()
{
this->SetInputDomainName(0);
this->SetNoneString(0);
delete this->ALDInternals;
this->ALDInternals = NULL;
}
//---------------------------------------------------------------------------
int vtkSMArrayListDomain::IsArrayPartial(unsigned int idx)
{
if (static_cast<size_t>(idx) < this->ALDInternals->DomainValues.size())
{
return this->ALDInternals->DomainValues[idx].IsPartial? 1 : 0;
}
vtkErrorMacro("Index out of range: " << idx);
return 0;
}
//---------------------------------------------------------------------------
int vtkSMArrayListDomain::GetDomainAssociation(unsigned int idx )
{
if (static_cast<size_t>(idx) < this->ALDInternals->DomainValues.size())
{
return this->ALDInternals->DomainValues[idx].DomainAssociation;
}
vtkErrorMacro("Index out of range: " << idx);
return -1;
}
//---------------------------------------------------------------------------
int vtkSMArrayListDomain::GetFieldAssociation(unsigned int idx)
{
if (static_cast<size_t>(idx) < this->ALDInternals->DomainValues.size())
{
return this->ALDInternals->DomainValues[idx].FieldAssociation;
}
vtkErrorMacro("Index out of range: " << idx);
return -1;
}
//---------------------------------------------------------------------------
void vtkSMArrayListDomain::Update(vtkSMProperty*)
{
vtkSMProperty* input = this->GetRequiredProperty("Input");
if (!input)
{
vtkErrorMacro("Missing require property 'Input'. Update failed.");
return;
}
vtkPVDataInformation* dataInfo = this->GetInputDataInformation("Input");
if (!dataInfo)
{
return;
}
vtkSMProperty* fieldDataSelection = this->GetRequiredProperty("FieldDataSelection");
vtkSMInputArrayDomain* iad = this->InputDomainName?
vtkSMInputArrayDomain::SafeDownCast(input->GetDomain(this->InputDomainName)):
vtkSMInputArrayDomain::SafeDownCast(input->FindDomain("vtkSMInputArrayDomain"));
int association = vtkSMInputArrayDomain::ANY;
int required_number_of_components = 0;
if (iad)
{
association = iad->GetAttributeType();
required_number_of_components = iad->GetNumberOfComponents();
}
if (fieldDataSelection)
{
vtkSMUncheckedPropertyHelper helper(fieldDataSelection);
if (helper.GetNumberOfElements()==1)
{
association = helper.GetAsInt(0);
}
else if (helper.GetNumberOfElements() == 5)
{
association = helper.GetAsInt(3);
}
else
{
vtkWarningMacro("FieldDataSelection property not supported, will be ignored.");
}
}
// validate association.
if (association < vtkSMInputArrayDomain::POINT ||
association >= vtkSMInputArrayDomain::NUMBER_OF_ATTRIBUTE_TYPES)
{
vtkWarningMacro("Invalid association. Ignoring.");
association = vtkSMInputArrayDomain::ANY;
}
if (required_number_of_components <0)
{
required_number_of_components = 0;
}
// we use a set so that the list gets sorted as well as helps us
// avoid duplicates esp. when processing two datainformation objects.
vtkSMArrayListDomainInternals::DomainValuesSet set;
this->ALDInternals->BuildArrayList(set, this,
association, required_number_of_components, dataInfo);
vtkPVDataInformation* extraInfo = this->GetExtraDataInformation();
if (extraInfo)
{
this->ALDInternals->BuildArrayList(set, this,
association, required_number_of_components, extraInfo);
}
vtkSMArrayListDomainInternals::DomainValuesVector values;
values.insert(values.end(), set.begin(), set.end());
if (values != this->ALDInternals->DomainValues)
{
this->ALDInternals->DomainValues = values;
this->SetStrings(this->ALDInternals->GetDomainValueStrings());
// FIXME: there is still a possibility that the above may not trigger
// DomainModified(). How do we handle that without unnecessarily
// firing the signal twice?
}
}
//---------------------------------------------------------------------------
int vtkSMArrayListDomain::ReadXMLAttributes(
vtkSMProperty* prop, vtkPVXMLElement* element)
{
if (!this->Superclass::ReadXMLAttributes(prop, element))
{
return 0;
}
const char* input_domain_name =
element->GetAttribute("input_domain_name");
if (input_domain_name)
{
this->SetInputDomainName(input_domain_name);
}
// Search for attribute type with matching name.
const char* none_string = element->GetAttribute("none_string");
if (none_string)
{
this->SetNoneString(none_string);
}
const char* key_locations = element->GetAttribute("key_locations");
const char* key_names = element->GetAttribute("key_names");
const char* key_strategies = element->GetAttribute("key_strategies");
if(key_locations == NULL)
{
// Default value : add a needed information key vtkAbstractArray::GUI_HIDE
this->AddInformationKey("vtkAbstractArray", "GUI_HIDE", vtkSMArrayListDomain::REJECT_KEY);
}
else
{
std::stringstream locations(key_locations);
std::stringstream names(key_names);
std::stringstream strategies(key_strategies);
std::string location, name, strategy, last_strategy;
int strat;
// default value for the strategy
last_strategy = "need_key";
while(locations >> location)
{
if(! (names >> name) )
{
vtkErrorMacro("The number of key names must be equal to the number of key locations");
break;
}
if(! (strategies >> strategy))
{
strategy = last_strategy;
}
last_strategy = strategy;
if(strategy == "need_key" || strategy == "NEED_KEY")
{
strat = vtkSMArrayListDomain::NEED_KEY;
}
else if(strategy == "reject_key" || strategy == "REJECT_KEY")
{
strat = vtkSMArrayListDomain::REJECT_KEY;
}
else
{
// maybe the strategy was coded as an integer.
strat=atoi(strategy.c_str());
}
this->AddInformationKey(location.c_str(), name.c_str(), strat);
}
}
// Search for attribute type to use when picking a default.
const char* attribute_type = element->GetAttribute("attribute_type");
if (attribute_type)
{
for(unsigned int i=0; i<vtkDataSetAttributes::NUM_ATTRIBUTES; ++i)
{
if(strcmp(vtkDataSetAttributes::GetAttributeTypeAsString(i),
attribute_type) == 0)
{
this->SetAttributeType(i);
break;
}
}
}
const char* data_type = element->GetAttribute("data_type");
if (data_type)
{
// data_type can be a space delimited list of types
// vlaid for the domain
std::istringstream dataTypeStream(data_type);
while (dataTypeStream.good())
{
std::string thisType;
dataTypeStream >> thisType;
if ( thisType=="VTK_VOID" )
{
this->ALDInternals->DataTypes.push_back(VTK_VOID);
}
else if ( thisType=="VTK_BIT" )
{
this->ALDInternals->DataTypes.push_back(VTK_BIT);
}
else if ( thisType=="VTK_CHAR" )
{
this->ALDInternals->DataTypes.push_back(VTK_CHAR);
}
else if ( thisType=="VTK_SIGNED_CHAR" )
{
this->ALDInternals->DataTypes.push_back(VTK_SIGNED_CHAR);
}
else if ( thisType=="VTK_UNSIGNED_CHAR" )
{
this->ALDInternals->DataTypes.push_back(VTK_UNSIGNED_CHAR);
}
else if ( thisType=="VTK_SHORT" )
{
this->ALDInternals->DataTypes.push_back(VTK_SHORT);
}
else if ( thisType=="VTK_UNSIGNED_SHORT" )
{
this->ALDInternals->DataTypes.push_back(VTK_UNSIGNED_SHORT);
}
else if ( thisType=="VTK_INT" )
{
this->ALDInternals->DataTypes.push_back(VTK_INT);
}
else if ( thisType=="VTK_UNSIGNED_INT" )
{
this->ALDInternals->DataTypes.push_back(VTK_UNSIGNED_INT);
}
else if ( thisType=="VTK_LONG" )
{
this->ALDInternals->DataTypes.push_back(VTK_LONG);
}
else if ( thisType=="VTK_FLOAT" )
{
this->ALDInternals->DataTypes.push_back(VTK_FLOAT);
}
else if ( thisType=="VTK_DOUBLE" )
{
this->ALDInternals->DataTypes.push_back(VTK_DOUBLE);
}
else if ( thisType=="VTK_ID_TYPE" )
{
this->ALDInternals->DataTypes.push_back(VTK_ID_TYPE);
}
else if ( thisType=="VTK_STRING" )
{
this->ALDInternals->DataTypes.push_back(VTK_STRING);
}
else if ( thisType=="VTK_OPAQUE" )
{
this->ALDInternals->DataTypes.push_back(VTK_OPAQUE);
}
else if ( thisType=="VTK_LONG_LONG" )
{
this->ALDInternals->DataTypes.push_back(VTK_LONG_LONG);
}
else if ( thisType=="VTK_UNSIGNED_LONG_LONG" )
{
this->ALDInternals->DataTypes.push_back(VTK_UNSIGNED_LONG_LONG);
}
else if ( thisType=="VTK___INT64" )
{
this->ALDInternals->DataTypes.push_back(VTK___INT64);
}
else if ( thisType=="VTK_UNSIGNED___INT64" )
{
this->ALDInternals->DataTypes.push_back(VTK_UNSIGNED___INT64);
}
else if ( thisType=="VTK_DATA_ARRAY" )
{
this->ALDInternals->DataTypes.push_back(VTK_BIT);
this->ALDInternals->DataTypes.push_back(VTK_CHAR);
this->ALDInternals->DataTypes.push_back(VTK_SIGNED_CHAR);
this->ALDInternals->DataTypes.push_back(VTK_UNSIGNED_CHAR);
this->ALDInternals->DataTypes.push_back(VTK_SHORT);
this->ALDInternals->DataTypes.push_back(VTK_UNSIGNED_SHORT);
this->ALDInternals->DataTypes.push_back(VTK_INT);
this->ALDInternals->DataTypes.push_back(VTK_UNSIGNED_INT);
this->ALDInternals->DataTypes.push_back(VTK_LONG);
this->ALDInternals->DataTypes.push_back(VTK_FLOAT);
this->ALDInternals->DataTypes.push_back(VTK_DOUBLE);
this->ALDInternals->DataTypes.push_back(VTK_ID_TYPE);
this->ALDInternals->DataTypes.push_back(VTK_LONG_LONG);
this->ALDInternals->DataTypes.push_back(VTK_UNSIGNED_LONG);
this->ALDInternals->DataTypes.push_back(VTK_UNSIGNED_LONG_LONG);
this->ALDInternals->DataTypes.push_back(VTK___INT64);
this->ALDInternals->DataTypes.push_back(VTK_UNSIGNED___INT64);
}
else
{
int maybeType=atoi(thisType.c_str()); //?
this->ALDInternals->DataTypes.push_back(maybeType);
}
}
}
return 1;
}
//---------------------------------------------------------------------------
int vtkSMArrayListDomain::SetDefaultValues(vtkSMProperty* prop, bool use_unchecked_values)
{
vtkSMStringVectorProperty* svp = vtkSMStringVectorProperty::SafeDownCast(prop);
if (!svp)
{
return 0;
}
vtkSMPropertyHelper helper(prop);
helper.SetUseUnchecked(use_unchecked_values);
// If vtkSMStringVectorProperty has a default value which is in domain, just
// use it.
const char* defaultValue = svp->GetDefaultValue(0);
unsigned int temp;
if (defaultValue && this->IsInDomain(defaultValue, temp))
{
if (helper.GetNumberOfElements() == 5)
{
helper.Set(4, defaultValue);
return 1;
}
else if (helper.GetNumberOfElements() == 1)
{
helper.Set(0, defaultValue);
return 1;
}
}
const vtkSMArrayListDomainArrayInformation* info =
this->ALDInternals->FindAttribute(this->AttributeType);
if (info == NULL &&
this->ALDInternals->DomainValues.size() > 0 &&
this->PickFirstAvailableArrayByDefault == true)
{
info = &this->ALDInternals->DomainValues[0];
}
if (info)
{
if (helper.GetNumberOfElements() == 5)
{
vtkNew<vtkStringList> values;
if (use_unchecked_values)
{
svp->GetUncheckedElements(values.GetPointer());
}
else
{
svp->GetElements(values.GetPointer());
}
std::ostringstream ass;
ass << info->FieldAssociation;
values->SetString(3, ass.str().c_str());
values->SetString(4, info->ArrayName.c_str());
if (use_unchecked_values)
{
svp->SetUncheckedElements(values.GetPointer());
}
else
{
svp->SetElements(values.GetPointer());
}
return 1;
}
else if (svp->GetNumberOfElements() == 1)
{
helper.Set(0, info->ArrayName.c_str());
return 1;
}
}
return this->Superclass::SetDefaultValues(prop, use_unchecked_values);
}
//---------------------------------------------------------------------------
unsigned int vtkSMArrayListDomain::AddInformationKey(const char* location, const char *name, int strategy)
{
vtkSMArrayListDomainInformationKey key;
key.Location = location;
key.Name = name;
key.Strategy = strategy;
this->ALDInternals->InformationKeys.push_back(key);
return static_cast<unsigned int>(this->ALDInternals->InformationKeys.size() - 1);
}
//---------------------------------------------------------------------------
unsigned int vtkSMArrayListDomain::RemoveInformationKey(const char* location, const char *name)
{
std::vector<vtkSMArrayListDomainInformationKey>::iterator it
= this->ALDInternals->InformationKeys.begin();
int index = 0;
while(it != this->ALDInternals->InformationKeys.end())
{
vtkSMArrayListDomainInformationKey& key = *it;
if(key.Location == location && key.Name == name)
{
this->ALDInternals->InformationKeys.erase(it);
return index;
}
it++;
index++;
}
return 0;
}
//---------------------------------------------------------------------------
unsigned int vtkSMArrayListDomain::GetNumberOfInformationKeys()
{
return static_cast<unsigned int>(this->ALDInternals->InformationKeys.size());
}
//---------------------------------------------------------------------------
void vtkSMArrayListDomain::RemoveAllInformationKeys()
{
this->ALDInternals->InformationKeys.clear();
}
//---------------------------------------------------------------------------
const char* vtkSMArrayListDomain::GetInformationKeyLocation(unsigned int index)
{
if(index < this->ALDInternals->InformationKeys.size())
{
return this->ALDInternals->InformationKeys[index].Location;
}
return NULL;
}
//---------------------------------------------------------------------------
const char* vtkSMArrayListDomain::GetInformationKeyName(unsigned int index)
{
if(index < this->ALDInternals->InformationKeys.size())
{
return this->ALDInternals->InformationKeys[index].Name;
}
return NULL;
}
//---------------------------------------------------------------------------
int vtkSMArrayListDomain::GetInformationKeyStrategy(unsigned int index)
{
if(index < this->ALDInternals->InformationKeys.size())
{
return this->ALDInternals->InformationKeys[index].Strategy;
}
return -1;
}
//---------------------------------------------------------------------------
void vtkSMArrayListDomain::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "AttributeType: " << this->AttributeType << endl;
int nDataTypes=static_cast<int>(this->ALDInternals->DataTypes.size());
for (int i=0; i<nDataTypes; ++i)
{
os << indent << "DataType: " << this->ALDInternals->DataTypes[i] << endl;
}
for(unsigned int i=0; i<this->ALDInternals->InformationKeys.size(); i++)
{
vtkSMArrayListDomainInformationKey& key = this->ALDInternals->InformationKeys[i];
os << key.Location << "::" << key.Name << " ";
if(key.Strategy == vtkSMArrayListDomain::NEED_KEY)
{
os << "NEED_KEY";
}
else if(key.Strategy == vtkSMArrayListDomain::REJECT_KEY)
{
os << "REJECT_KEY";
}
else
{
os << "UNKNOWN KEY STRATEGY : " << key.Strategy;
}
os << endl;
}
}
//---------------------------------------------------------------------------
vtkStdString vtkSMArrayListDomain::CreateMangledName(
vtkPVArrayInformation *arrayInfo, int component)
{
std::ostringstream stream;
if ( component != arrayInfo->GetNumberOfComponents() )
{
stream << arrayInfo->GetName() << "_" <<
arrayInfo->GetComponentName(component);
}
else
{
stream << arrayInfo->GetName() << "_Magnitude";
}
return stream.str();
}
//---------------------------------------------------------------------------
vtkStdString vtkSMArrayListDomain::ArrayNameFromMangledName(
const char* name)
{
vtkStdString extractedName = name;
size_t pos = extractedName.rfind("_");
if (pos == vtkStdString::npos)
{
return extractedName;
}
return extractedName.substr(0,pos);
}
//---------------------------------------------------------------------------
int vtkSMArrayListDomain::ComponentIndexFromMangledName(
vtkPVArrayInformation *info, const char* name)
{
vtkStdString extractedName = name;
size_t pos = extractedName.rfind("_");
if (pos == vtkStdString::npos)
{
return -1;
}
vtkStdString compName = extractedName.substr(pos+1,extractedName.length()-pos);
int numComps = info->GetNumberOfComponents();
if ( compName == "Magnitude" )
{
return numComps;
}
for ( int i=0; i < numComps; ++i)
{
if ( compName == info->GetComponentName(i) )
{
return i;
}
}
return -1;
}
//---------------------------------------------------------------------------
bool vtkSMArrayListDomain::IsFilteredArray(vtkPVDataInformation*, int, const char*)
{
return false;
}
|