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
|
/*=========================================================================
Program: ParaView
Module: vtkPVArrayInformation.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
cxx the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPVArrayInformation.h"
#include "vtkAbstractArray.h"
#include "vtkClientServerStream.h"
#include "vtkDataArray.h"
#include "vtkObjectFactory.h"
#include "vtkInformation.h"
#include "vtkInformationKey.h"
#include "vtkInformationIterator.h"
#include "vtkNew.h"
#include "vtkStringArray.h"
#include "vtkStdString.h"
#include "vtkPVPostFilter.h"
#include "vtkVariant.h"
#include "vtkVariantArray.h"
#include <map>
#include <set>
#include <vector>
#include <sstream>
namespace
{
typedef std::vector<vtkStdString*> vtkInternalComponentNameBase;
struct vtkPVArrayInformationInformationKey
{
vtkStdString Location;
vtkStdString Name;
};
typedef std::vector<vtkPVArrayInformationInformationKey> vtkInternalInformationKeysBase;
}
class vtkPVArrayInformation::vtkInternalComponentNames:
public vtkInternalComponentNameBase
{
};
class vtkPVArrayInformation::vtkInternalInformationKeys:
public vtkInternalInformationKeysBase
{
};
vtkStandardNewMacro(vtkPVArrayInformation);
//----------------------------------------------------------------------------
vtkPVArrayInformation::vtkPVArrayInformation()
{
this->Name = 0;
this->Ranges = 0;
this->ComponentNames = 0;
this->DefaultComponentName = 0;
this->InformationKeys = 0;
this->Initialize();
}
//----------------------------------------------------------------------------
vtkPVArrayInformation::~vtkPVArrayInformation()
{
this->Initialize();
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::Initialize()
{
this->SetName(0);
this->DataType = VTK_VOID;
this->NumberOfComponents = 0;
this->NumberOfTuples = 0;
if (this->ComponentNames)
{
for ( unsigned int i=0; i < this->ComponentNames->size(); ++i)
{
if ( this->ComponentNames->at(i) )
{
delete this->ComponentNames->at(i);
}
}
this->ComponentNames->clear();
delete this->ComponentNames;
this->ComponentNames = 0;
}
if (this->DefaultComponentName)
{
delete this->DefaultComponentName;
this->DefaultComponentName = 0;
}
if (this->Ranges)
{
delete[] this->Ranges;
this->Ranges = 0;
}
this->IsPartial = 0;
if(this->InformationKeys)
{
this->InformationKeys->clear();
delete this->InformationKeys;
this->InformationKeys = 0;
}
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::PrintSelf(ostream& os, vtkIndent indent)
{
int num, idx;
vtkIndent i2 = indent.GetNextIndent();
this->Superclass::PrintSelf(os, indent);
if (this->Name)
{
os << indent << "Name: " << this->Name << endl;
}
os << indent << "DataType: " << this->DataType << endl;
os << indent << "NumberOfComponents: " << this->NumberOfComponents << endl;
if (this->ComponentNames)
{
os << indent << "ComponentNames:" << endl;
for (unsigned int i = 0; i < this->ComponentNames->size(); ++i)
{
os << i2 << this->ComponentNames->at(i) << endl;
}
}
os << indent << "NumberOfTuples: " << this->NumberOfTuples << endl;
os << indent << "IsPartial: " << this->IsPartial << endl;
os << indent << "Ranges :" << endl;
num = this->NumberOfComponents;
if (num > 1)
{
++num;
}
for (idx = 0; idx < num; ++idx)
{
os << i2 << this->Ranges[2 * idx] << ", " << this->Ranges[2 * idx + 1]
<< endl;
}
os << indent << "InformationKeys :" << endl;
if(this->InformationKeys)
{
num = this->GetNumberOfInformationKeys();
for (idx = 0; idx < num; ++idx)
{
os << i2 << this->GetInformationKeyLocation(idx) << "::"
<< this->GetInformationKeyName(idx) << endl;
}
}
else
{
os << i2 << "None" << endl;
}
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::SetNumberOfComponents(int numComps)
{
if (this->NumberOfComponents == numComps)
{
return;
}
if (this->Ranges)
{
delete[] this->Ranges;
this->Ranges = NULL;
}
this->NumberOfComponents = numComps;
if (numComps <= 0)
{
this->NumberOfComponents = 0;
return;
}
if (numComps > 1)
{ // Extra range for vector magnitude (first in array).
numComps = numComps + 1;
}
int idx;
this->Ranges = new double[numComps * 2];
for (idx = 0; idx < numComps; ++idx)
{
this->Ranges[2 * idx] = VTK_DOUBLE_MAX;
this->Ranges[2 * idx + 1] = -VTK_DOUBLE_MAX;
}
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::SetComponentName(vtkIdType component,
const char *name)
{
if (component < 0 || name == NULL)
{
return;
}
unsigned int index = static_cast<unsigned int> (component);
if (this->ComponentNames == NULL)
{
//delayed allocate
this->ComponentNames
= new vtkPVArrayInformation::vtkInternalComponentNames();
}
if (index == this->ComponentNames->size())
{
//the array isn't large enough, so we will resize
this->ComponentNames->push_back(new vtkStdString(name));
return;
}
else if (index > this->ComponentNames->size())
{
this->ComponentNames->resize(index + 1, NULL);
}
//replace an exisiting element
vtkStdString *compName = this->ComponentNames->at(index);
if (!compName)
{
compName = new vtkStdString(name);
this->ComponentNames->at(index) = compName;
}
else
{
compName->assign(name);
}
}
//----------------------------------------------------------------------------
const char* vtkPVArrayInformation::GetComponentName(vtkIdType component)
{
unsigned int index = static_cast<unsigned int> (component);
//check signed component for less than zero
if (this->ComponentNames && component >= 0 && index
< this->ComponentNames->size())
{
vtkStdString *compName = this->ComponentNames->at(index);
if (compName)
{
return compName->c_str();
}
}
else if (this->ComponentNames && component == -1
&& this->ComponentNames->size() == 1)
{
// the array is a scalar i.e. single component. In that case, when one asks
// for the magnitude (i.e. component == -1) it's same as asking for the
// scalar. So return the scalar's component name.
vtkStdString *compName = this->ComponentNames->at(0);
if (compName)
{
return compName->c_str();
}
}
//we have failed to find a user set component name, use the default component name
this->DetermineDefaultComponentName(component, this->GetNumberOfComponents());
return this->DefaultComponentName->c_str();
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::SetComponentRange(int comp, double min, double max)
{
if (comp >= this->NumberOfComponents || this->NumberOfComponents <= 0)
{
vtkErrorMacro("Bad component");
}
if (this->NumberOfComponents > 1)
{ // Shift over vector mag range.
++comp;
}
if (comp < 0)
{ // anything less than 0 just defaults to the vector mag.
comp = 0;
}
this->Ranges[comp * 2] = min;
this->Ranges[comp * 2 + 1] = max;
}
//----------------------------------------------------------------------------
double* vtkPVArrayInformation::GetComponentRange(int comp)
{
if (comp >= this->NumberOfComponents || this->NumberOfComponents <= 0)
{
vtkErrorMacro("Bad component");
return NULL;
}
if (this->NumberOfComponents > 1)
{ // Shift over vector mag range.
++comp;
}
if (comp < 0)
{ // anything less than 0 just defaults to the vector mag.
comp = 0;
}
return this->Ranges + comp * 2;
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::GetComponentRange(int comp, double *range)
{
double *ptr;
ptr = this->GetComponentRange(comp);
if (ptr == NULL)
{
range[0] = VTK_DOUBLE_MAX;
range[1] = -VTK_DOUBLE_MAX;
return;
}
range[0] = ptr[0];
range[1] = ptr[1];
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::GetDataTypeRange(double range[2])
{
int dataType = this->GetDataType();
switch (dataType)
{
case VTK_BIT:
range[0] = VTK_BIT_MAX;
range[1] = VTK_BIT_MAX;
break;
case VTK_UNSIGNED_CHAR:
range[0] = VTK_UNSIGNED_CHAR_MIN;
range[1] = VTK_UNSIGNED_CHAR_MAX;
break;
case VTK_CHAR:
range[0] = VTK_CHAR_MIN;
range[1] = VTK_CHAR_MAX;
break;
case VTK_UNSIGNED_SHORT:
range[0] = VTK_UNSIGNED_SHORT_MIN;
range[1] = VTK_UNSIGNED_SHORT_MAX;
break;
case VTK_SHORT:
range[0] = VTK_SHORT_MIN;
range[1] = VTK_SHORT_MAX;
break;
case VTK_UNSIGNED_INT:
range[0] = VTK_UNSIGNED_INT_MIN;
range[1] = VTK_UNSIGNED_INT_MAX;
break;
case VTK_INT:
range[0] = VTK_INT_MIN;
range[1] = VTK_INT_MAX;
break;
case VTK_UNSIGNED_LONG:
range[0] = VTK_UNSIGNED_LONG_MIN;
range[1] = VTK_UNSIGNED_LONG_MAX;
break;
case VTK_LONG:
range[0] = VTK_LONG_MIN;
range[1] = VTK_LONG_MAX;
break;
case VTK_FLOAT:
range[0] = VTK_FLOAT_MIN;
range[1] = VTK_FLOAT_MAX;
break;
case VTK_DOUBLE:
range[0] = VTK_DOUBLE_MIN;
range[1] = VTK_DOUBLE_MAX;
break;
default:
// Default value:
range[0] = 0;
range[1] = 1;
break;
}
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::AddRanges(vtkPVArrayInformation *info)
{
double *range;
double *ptr = this->Ranges;
int idx;
if (this->NumberOfComponents != info->GetNumberOfComponents())
{
vtkErrorMacro("Component mismatch.");
}
if (this->NumberOfComponents > 1)
{
range = info->GetComponentRange(-1);
if (range[0] < ptr[0])
{
ptr[0] = range[0];
}
if (range[1] > ptr[1])
{
ptr[1] = range[1];
}
ptr += 2;
}
for (idx = 0; idx < this->NumberOfComponents; ++idx)
{
range = info->GetComponentRange(idx);
if (range[0] < ptr[0])
{
ptr[0] = range[0];
}
if (range[1] > ptr[1])
{
ptr[1] = range[1];
}
ptr += 2;
}
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::DeepCopy( vtkPVArrayInformation* info )
{
int num, idx;
this->SetName(info->GetName());
this->DataType = info->GetDataType();
this->SetNumberOfComponents(info->GetNumberOfComponents());
this->SetNumberOfTuples(info->GetNumberOfTuples());
num = 2 * this->NumberOfComponents;
if (this->NumberOfComponents > 1)
{
num += 2;
}
for (idx = 0; idx < num; ++idx)
{
this->Ranges[idx] = info->Ranges[idx];
}
//clear the vector of old data
if (this->ComponentNames)
{
for ( unsigned int i=0; i < this->ComponentNames->size(); ++i)
{
if ( this->ComponentNames->at(i) )
{
delete this->ComponentNames->at(i);
}
}
this->ComponentNames->clear();
delete this->ComponentNames;
this->ComponentNames = 0;
}
if (info->ComponentNames)
{
this->ComponentNames
= new vtkPVArrayInformation::vtkInternalComponentNames();
//copy the passed in components if they exist
this->ComponentNames->reserve(info->ComponentNames->size());
const char *name;
for (unsigned i = 0; i < info->ComponentNames->size(); ++i)
{
name = info->GetComponentName(i);
if (name)
{
this->SetComponentName(i, name);
}
}
}
if (!this->InformationKeys)
{
this->InformationKeys
= new vtkPVArrayInformation::vtkInternalInformationKeys();
}
//clear the vector of old data
this->InformationKeys->clear();
if (info->InformationKeys)
{
//copy the passed in components if they exist
for (unsigned i = 0; i < info->InformationKeys->size(); ++i)
{
this->InformationKeys->push_back(info->InformationKeys->at(i));
}
}
}
//----------------------------------------------------------------------------
int vtkPVArrayInformation::Compare(vtkPVArrayInformation *info)
{
if (info == NULL)
{
return 0;
}
if (strcmp(info->GetName(), this->Name) == 0 && info->GetNumberOfComponents()
== this->NumberOfComponents && this->GetNumberOfInformationKeys()
== info->GetNumberOfInformationKeys())
{
return 1;
}
return 0;
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::CopyFromObject(vtkObject* obj)
{
if (!obj)
{
this->Initialize();
}
vtkAbstractArray* const array = vtkAbstractArray::SafeDownCast(obj);
if (!array)
{
vtkErrorMacro("Cannot downcast to abstract array.");
this->Initialize();
return;
}
this->SetName(array->GetName());
this->DataType = array->GetDataType();
this->SetNumberOfComponents(array->GetNumberOfComponents());
this->SetNumberOfTuples(array->GetNumberOfTuples());
if (array->HasAComponentName())
{
const char *name;
//copy the component names over
for (int i = 0; i < this->GetNumberOfComponents(); ++i)
{
name = array->GetComponentName(i);
if (name)
{
//each component doesn't have to be named
this->SetComponentName(i, name);
}
}
}
if (vtkDataArray* const data_array = vtkDataArray::SafeDownCast(obj))
{
double range[2];
double *ptr;
int idx;
ptr = this->Ranges;
if (this->NumberOfComponents > 1)
{
// First store range of vector magnitude.
data_array->GetRange(range, -1);
*ptr++ = range[0];
*ptr++ = range[1];
}
for (idx = 0; idx < this->NumberOfComponents; ++idx)
{
data_array->GetRange(range, idx);
*ptr++ = range[0];
*ptr++ = range[1];
}
}
if(this->InformationKeys)
{
this->InformationKeys->clear();
delete this->InformationKeys;
this->InformationKeys = 0;
}
if (array->HasInformation())
{
vtkInformation* info = array->GetInformation();
vtkInformationIterator* it = vtkInformationIterator::New();
it->SetInformationWeak(info);
it->GoToFirstItem();
while (!it->IsDoneWithTraversal())
{
vtkInformationKey* key = it->GetCurrentKey();
this->AddInformationKey(key->GetLocation(), key->GetName());
it->GoToNextItem();
}
it->Delete();
}
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::AddInformation(vtkPVInformation* info)
{
if (!info)
{
return;
}
vtkPVArrayInformation* aInfo = vtkPVArrayInformation::SafeDownCast(info);
if (!aInfo)
{
vtkErrorMacro("Could not downcast info to array info.");
return;
}
if (aInfo->GetNumberOfComponents() > 0)
{
if (this->NumberOfComponents == 0)
{
// If this object is uninitialized, copy.
this->DeepCopy(aInfo);
}
else
{
// Leave everything but ranges and unique values as original, add ranges and unique values.
this->AddRanges(aInfo);
this->AddInformationKeys(aInfo);
}
}
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::CopyToStream(vtkClientServerStream* css)
{
css->Reset();
*css << vtkClientServerStream::Reply;
// Array name, data type, and number of components.
*css << this->Name;
*css << this->DataType;
*css << this->NumberOfTuples;
*css << this->NumberOfComponents;
*css << this->IsPartial;
// Range of each component.
int num = this->NumberOfComponents;
if (this->NumberOfComponents > 1)
{
// First range is range of vector magnitude.
++num;
}
for (int i = 0; i < num; ++i)
{
*css << vtkClientServerStream::InsertArray(this->Ranges + 2 * i, 2);
}
//add in the component names
num = static_cast<int> (this->ComponentNames ? this->ComponentNames->size()
: 0);
*css << num;
vtkStdString *compName;
for (int i = 0; i < num; ++i)
{
compName = this->ComponentNames->at(i);
*css << (compName? compName->c_str() : static_cast<const char*>(NULL));
}
int nkeys = this->GetNumberOfInformationKeys();
*css << nkeys;
for (int key = 0; key < nkeys; key++)
{
const char* location = this->GetInformationKeyLocation(key);
const char* name = this->GetInformationKeyName(key);
*css << location << name;
}
*css << vtkClientServerStream::End;
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::CopyFromStream(const vtkClientServerStream* css)
{
// Array name.
const char* name = 0;
if (!css->GetArgument(0, 0, &name))
{
vtkErrorMacro("Error parsing array name from message.");
return;
}
this->SetName(name);
// Data type.
if (!css->GetArgument(0, 1, &this->DataType))
{
vtkErrorMacro("Error parsing array data type from message.");
return;
}
// Number of tuples.
if (!css->GetArgument(0, 2, &this->NumberOfTuples))
{
vtkErrorMacro("Error parsing number of tuples from message.");
return;
}
// Number of components.
int num;
if (!css->GetArgument(0, 3, &num))
{
vtkErrorMacro("Error parsing number of components from message.");
return;
}
// This needs to be called since it allocates the this->Ranges array.
this->SetNumberOfComponents(num);
if (num > 1)
{
num++;
}
// Is Partial
if (!css->GetArgument(0, 4, &this->IsPartial))
{
vtkErrorMacro("Error parsing IsPartial from message.");
return;
}
// Range of each component.
for (int i = 0; i < num; ++i)
{
if (!css->GetArgument(0, 5 + i, this->Ranges + 2 * i, 2))
{
vtkErrorMacro("Error parsing range of component.");
return;
}
}
int pos = 5 + num;
int numOfComponentNames;
if (!css->GetArgument(0, pos++, &numOfComponentNames))
{
vtkErrorMacro("Error parsing number of component names.");
return;
}
if (numOfComponentNames > 0)
{
//clear the vector of old data
if (this->ComponentNames)
{
for ( unsigned int i=0; i < this->ComponentNames->size(); ++i)
{
if ( this->ComponentNames->at(i) )
{
delete this->ComponentNames->at(i);
}
}
this->ComponentNames->clear();
delete this->ComponentNames;
this->ComponentNames = 0;
}
this->ComponentNames
= new vtkPVArrayInformation::vtkInternalComponentNames();
this->ComponentNames->reserve(numOfComponentNames);
for (int cc=0; cc < numOfComponentNames; cc++)
{
const char* comp_name;
if (!css->GetArgument(0, pos++, &comp_name))
{
vtkErrorMacro("Error parsing component name from message.");
return;
}
// note comp_name may be NULL, but that's okay.
this->SetComponentName(cc, comp_name);
}
}
// information keys
int nkeys;
if (!css->GetArgument(0, pos++, &nkeys))
{
return;
}
// Location and name for each key.
if (this->InformationKeys)
{
this->InformationKeys->clear();
delete this->InformationKeys;
this->InformationKeys = 0;
}
for (int i = 0; i < nkeys; ++i)
{
if (!css->GetArgument(0, pos++, &name))
{
vtkErrorMacro("Error parsing information key location from message.");
return;
}
vtkStdString key_location = name;
if (!css->GetArgument(0, pos++, &name))
{
vtkErrorMacro("Error parsing information key name from message.");
return;
}
vtkStdString key_name = name;
this->AddInformationKey(key_location, key_name);
}
}
//-----------------------------------------------------------------------------
void vtkPVArrayInformation::DetermineDefaultComponentName(
const int &component_no, const int &num_components)
{
if (!this->DefaultComponentName)
{
this->DefaultComponentName = new vtkStdString();
}
this->DefaultComponentName->assign(vtkPVPostFilter::DefaultComponentName(component_no, num_components));
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::AddInformationKeys(vtkPVArrayInformation *info)
{
for (int k = 0; k < info->GetNumberOfInformationKeys(); k++)
{
this->AddUniqueInformationKey(info->GetInformationKeyLocation(k),
info->GetInformationKeyName(k));
}
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::AddInformationKey(const char* location,
const char* name)
{
if(this->InformationKeys == NULL)
{
this->InformationKeys = new vtkInternalInformationKeys();
}
vtkPVArrayInformationInformationKey info = vtkPVArrayInformationInformationKey();
info.Location = location;
info.Name = name;
this->InformationKeys->push_back(info);
}
//----------------------------------------------------------------------------
void vtkPVArrayInformation::AddUniqueInformationKey(const char* location,
const char* name)
{
if (!this->HasInformationKey(location, name))
{
this->AddInformationKey(location, name);
}
}
//----------------------------------------------------------------------------
int vtkPVArrayInformation::GetNumberOfInformationKeys()
{
return static_cast<int>(this->InformationKeys ? this->InformationKeys->size() : 0);
}
//----------------------------------------------------------------------------
const char* vtkPVArrayInformation::GetInformationKeyLocation(int index)
{
if (index < 0 || index >= this->GetNumberOfInformationKeys())
return NULL;
return this->InformationKeys->at(index).Location;
}
//----------------------------------------------------------------------------
const char* vtkPVArrayInformation::GetInformationKeyName(int index)
{
if (index < 0 || index >= this->GetNumberOfInformationKeys())
return NULL;
return this->InformationKeys->at(index).Name;
}
//----------------------------------------------------------------------------
int vtkPVArrayInformation::HasInformationKey(const char* location,
const char* name)
{
for (int k = 0; k < this->GetNumberOfInformationKeys(); k++)
{
const char* key_location = this->GetInformationKeyLocation(k);
const char* key_name = this->GetInformationKeyName(k);
if (strcmp(location, key_location) == 0 && strcmp(name, key_name) == 0)
{
return 1;
}
}
return 0;
}
|