/usr/include/vigra/axistags.hxx is in libvigraimpex-dev 1.9.0+dfsg-10+b2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /************************************************************************/
/* */
/* Copyright 2010-2011 by Ullrich Koethe */
/* */
/* This file is part of the VIGRA computer vision library. */
/* The VIGRA Website is */
/* http://hci.iwr.uni-heidelberg.de/vigra/ */
/* Please direct questions, bug reports, and contributions to */
/* ullrich.koethe@iwr.uni-heidelberg.de or */
/* vigra@informatik.uni-hamburg.de */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following */
/* conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the */
/* Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
/* OTHER DEALINGS IN THE SOFTWARE. */
/* */
/************************************************************************/
#ifndef VIGRA_AXISTAGS_HXX
#define VIGRA_AXISTAGS_HXX
#include "utilities.hxx"
#include "array_vector.hxx"
#include "algorithm.hxx"
#include "error.hxx"
#include "functorexpression.hxx"
#include <string>
#include <sstream>
#include <iomanip>
namespace vigra {
class AxisInfo
{
public:
// this particular assignment of bits to types is crucial for
// canonical axis ordering
enum AxisType { Channels = 1,
Space = 2,
Angle = 4,
Time = 8,
Frequency = 16,
UnknownAxisType = 32,
NonChannel = Space | Angle | Time | Frequency | UnknownAxisType,
AllAxes = 2*UnknownAxisType-1 };
AxisInfo(std::string key = "?", AxisType typeFlags = UnknownAxisType,
double resolution = 0.0, std::string description = "")
: key_(key),
description_(description),
resolution_(resolution),
flags_(typeFlags)
{}
std::string key() const
{
return key_;
}
std::string description() const
{
return description_;
}
void setDescription(std::string const & description)
{
description_ = description;
}
double resolution() const
{
return resolution_;
}
void setResolution(double resolution)
{
resolution_ = resolution;
}
AxisType typeFlags() const
{
return flags_ == 0
? UnknownAxisType
: flags_;
}
bool isUnknown() const
{
return isType(UnknownAxisType);
}
bool isSpatial() const
{
return isType(Space);
}
bool isTemporal() const
{
return isType(Time);
}
bool isChannel() const
{
return isType(Channels);
}
bool isFrequency() const
{
return isType(Frequency);
}
bool isAngular() const
{
return isType(Angle);
}
bool isType(AxisType type) const
{
return (typeFlags() & type) != 0;
}
std::string repr() const
{
std::string res("AxisInfo: '");
res += key_ + "' (type:";
if(isUnknown())
{
res += " none";
}
else
{
if(isChannel())
res += " Channels";
if(isSpatial())
res += " Space";
if(isTemporal())
res += " Time";
if(isAngular())
res += " Angle";
if(isFrequency())
res += " Frequency";
}
if(resolution_ > 0.0)
{
res += ", resolution=";
res += asString(resolution_);
}
res += ")";
if(description_ != "")
{
res += " ";
res += description_;
}
return res;
}
AxisInfo toFrequencyDomain(unsigned int size = 0, int sign = 1) const
{
AxisType type;
if(sign == 1)
{
vigra_precondition(!isFrequency(),
"AxisInfo::toFrequencyDomain(): axis is already in the Fourier domain.");
type = AxisType(Frequency | flags_);
}
else
{
vigra_precondition(isFrequency(),
"AxisInfo::fromFrequencyDomain(): axis is not in the Fourier domain.");
type = AxisType(~Frequency & flags_);
}
AxisInfo res(key(), type, 0.0, description_);
if(resolution_ > 0.0 && size > 0u)
res.resolution_ = 1.0 / (resolution_ * size);
return res;
}
AxisInfo fromFrequencyDomain(unsigned int size = 0) const
{
return toFrequencyDomain(size, -1);
}
bool compatible(AxisInfo const & other) const
{
return isUnknown() || other.isUnknown() ||
((typeFlags() & ~Frequency) == (other.typeFlags() & ~Frequency) &&
key() == other.key());
}
bool operator==(AxisInfo const & other) const
{
return typeFlags() == other.typeFlags() && key() == other.key();
}
bool operator!=(AxisInfo const & other) const
{
return !operator==(other);
}
// the primary ordering is according to axis type:
// Channels < Space < Angle < Time < Frequency < Unknown
// the secondary ordering is the lexicographic ordering of the keys
// "x" < "y" < "z"
bool operator<(AxisInfo const & other) const
{
return (typeFlags() < other.typeFlags()) ||
(typeFlags() == other.typeFlags() && key() < other.key());
}
bool operator<=(AxisInfo const & other) const
{
return !(other < *this);
}
bool operator>(AxisInfo const & other) const
{
return other < *this;
}
bool operator>=(AxisInfo const & other) const
{
return !(*this < other);
}
// factory functions for standard tags
static AxisInfo x(double resolution = 0.0, std::string const & description = "")
{
return AxisInfo("x", Space, resolution, description);
}
static AxisInfo y(double resolution = 0.0, std::string const & description = "")
{
return AxisInfo("y", Space, resolution, description);
}
static AxisInfo z(double resolution = 0.0, std::string const & description = "")
{
return AxisInfo("z", Space, resolution, description);
}
static AxisInfo t(double resolution = 0.0, std::string const & description = "")
{
return AxisInfo("t", Time, resolution, description);
}
static AxisInfo fx(double resolution = 0.0, std::string const & description = "")
{
return AxisInfo("x", AxisType(Space | Frequency), resolution, description);
}
static AxisInfo fy(double resolution = 0.0, std::string const & description = "")
{
return AxisInfo("y", AxisType(Space | Frequency), resolution, description);
}
static AxisInfo fz(double resolution = 0.0, std::string const & description = "")
{
return AxisInfo("z", AxisType(Space | Frequency), resolution, description);
}
static AxisInfo ft(double resolution = 0.0, std::string const & description = "")
{
return AxisInfo("t", AxisType(Time | Frequency), resolution, description);
}
static AxisInfo c(std::string const & description = "")
{
return AxisInfo("c", Channels, 0.0, description);
}
std::string key_, description_;
double resolution_;
AxisType flags_;
};
class AxisTags
{
public:
AxisTags()
{}
AxisTags(int size)
: axes_(size)
{}
AxisTags(AxisInfo const & i1)
{
push_back(i1);
}
AxisTags(AxisInfo const & i1, AxisInfo const & i2)
{
push_back(i1);
push_back(i2);
}
AxisTags(AxisInfo const & i1, AxisInfo const & i2, AxisInfo const & i3)
{
push_back(i1);
push_back(i2);
push_back(i3);
}
AxisTags(AxisInfo const & i1, AxisInfo const & i2,
AxisInfo const & i3, AxisInfo const & i4)
{
push_back(i1);
push_back(i2);
push_back(i3);
push_back(i4);
}
AxisTags(AxisInfo const & i1, AxisInfo const & i2,
AxisInfo const & i3, AxisInfo const & i4, AxisInfo const & i5)
{
push_back(i1);
push_back(i2);
push_back(i3);
push_back(i4);
push_back(i5);
}
// static AxisTags fromJSON(std::string const & repr);
std::string toJSON() const
{
std::stringstream s;
s << "{\n \"axes\": [";
for(unsigned int k=0; k<size(); ++k)
{
if(k > 0)
s << ",";
s << "\n";
s << " {\n";
s << " \"key\": \"" << axes_[k].key() << "\",\n";
s << " \"typeFlags\": " << (unsigned int)axes_[k].typeFlags() << ",\n";
s << " \"resolution\": " << std::setprecision(17) << axes_[k].resolution() << ",\n";
s << " \"description\": \"" << axes_[k].description() << "\"\n";
s << " }";
}
s << "\n ]\n}";
return s.str();
}
unsigned int size() const
{
return axes_.size();
}
int axisTypeCount(AxisInfo::AxisType type) const
{
int res = 0;
for(unsigned int k=0; k<size(); ++k)
if(axes_[k].isType(type))
++res;
return res;
}
std::string repr() const
{
std::string res;
if(size() > 0)
res += axes_[0].key();
for(unsigned int k=1; k<size(); ++k)
{
res += " ";
res += axes_[k].key();
}
return res;
}
AxisInfo & get(int k)
{
checkIndex(k);
if(k < 0)
k += size();
return axes_[k];
}
AxisInfo & get(std::string const & key)
{
return get(index(key));
}
AxisInfo const & get(int k) const
{
checkIndex(k);
if(k < 0)
k += size();
return axes_[k];
}
AxisInfo const & get(std::string const & key) const
{
return get(index(key));
}
void set(int k, AxisInfo const & info)
{
checkIndex(k);
if(k < 0)
k += size();
checkDuplicates(k, info);
axes_[k] = info;
}
void set(std::string const & key, AxisInfo const & info)
{
set(index(key), info);
}
void insert(int k, AxisInfo const & i)
{
if(k == (int)size())
{
push_back(i);
}
else
{
checkIndex(k);
if(k < 0)
k += size();
checkDuplicates(size(), i);
axes_.insert(axes_.begin()+k, i);
}
}
void push_back(AxisInfo const & i)
{
checkDuplicates(size(), i);
axes_.push_back(i);
}
void dropAxis(int k)
{
checkIndex(k);
ArrayVector<AxisInfo>::iterator i = k < 0
? axes_.end() + k
: axes_.begin() + k;
axes_.erase(i, i+1);
}
void dropAxis(std::string const & key)
{
dropAxis(index(key));
}
void dropChannelAxis()
{
int k = channelIndex();
if(k < (int)size())
axes_.erase(axes_.begin() + k, axes_.begin() + k + 1);
}
int index(std::string const & key) const
{
for(unsigned int k=0; k<size(); ++k)
if(axes_[k].key() == key)
return k;
return (int)size();
}
double resolution(int k) const
{
return get(k).resolution_;
}
double resolution(std::string const & key) const
{
return resolution(index(key));
}
void setResolution(int k, double r)
{
get(k).resolution_ = r;
}
void setResolution(std::string const & key, double r)
{
setResolution(index(key), r);
}
void scaleResolution(int k, double factor)
{
get(k).resolution_ *= factor;
}
void scaleResolution(std::string const & key, double factor)
{
get(key).resolution_ *= factor;
}
std::string description(int k) const
{
return get(k).description_;
}
std::string description(std::string const & key) const
{
return description(index(key));
}
void setDescription(int k, std::string const & d)
{
get(k).setDescription(d);
}
void setDescription(std::string const & key, std::string const & d)
{
setDescription(index(key), d);
}
void setChannelDescription(std::string const & description)
{
int k = channelIndex();
if(k < (int)size())
axes_[k].setDescription(description);
}
void toFrequencyDomain(int k, int size = 0, int sign = 1)
{
get(k) = get(k).toFrequencyDomain(size, sign);
}
void toFrequencyDomain(std::string const & key, int size = 0, int sign = 1)
{
toFrequencyDomain(index(key), size, sign);
}
void fromFrequencyDomain(int k, int size = 0)
{
toFrequencyDomain(k, size, -1);
}
void fromFrequencyDomain(std::string const & key, int size = 0)
{
toFrequencyDomain(key, size, -1);
}
bool hasChannelAxis() const
{
return channelIndex() != (int)size();
}
// FIXME: cache the results of these functions?
int channelIndex() const
{
for(unsigned int k=0; k<size(); ++k)
if(axes_[k].isChannel())
return k;
return (int)size();
}
int innerNonchannelIndex() const
{
int k = 0;
for(; k<(int)size(); ++k)
if(!axes_[k].isChannel())
break;
for(int i=k+1; i<(int)size(); ++i)
{
if(axes_[i].isChannel())
continue;
if(axes_[i] < axes_[k])
k = i;
}
return k;
}
void swapaxes(int i1, int i2)
{
checkIndex(i1);
checkIndex(i2);
if(i1 < 0)
i1 += size();
if(i2 < 0)
i2 += size();
std::swap(axes_[i1], axes_[i2]);
}
template <class T>
void transpose(ArrayVector<T> const & permutation)
{
if(permutation.size() == 0)
{
transpose();
}
else
{
vigra_precondition(permutation.size() == size(),
"AxisTags::transpose(): Permutation has wrong size.");
ArrayVector<AxisInfo> newAxes(size());
applyPermutation(permutation.begin(), permutation.end(), axes_.begin(), newAxes.begin());
axes_.swap(newAxes);
}
}
void transpose()
{
std::reverse(axes_.begin(), axes_.end());
}
template <class T>
void
permutationToNormalOrder(ArrayVector<T> & permutation) const
{
permutation.resize(size());
indexSort(axes_.begin(), axes_.end(), permutation.begin());
}
template <class T>
void
permutationToNormalOrder(ArrayVector<T> & permutation, AxisInfo::AxisType types) const
{
ArrayVector<AxisInfo> matchingAxes;
for(int k=0; k<(int)size(); ++k)
if(axes_[k].isType(types))
matchingAxes.push_back(axes_[k]);
permutation.resize(matchingAxes.size());
indexSort(matchingAxes.begin(), matchingAxes.end(), permutation.begin());
}
template <class T>
void
permutationFromNormalOrder(ArrayVector<T> & inverse_permutation) const
{
ArrayVector<T> permutation;
permutationToNormalOrder(permutation);
inverse_permutation.resize(permutation.size());
indexSort(permutation.begin(), permutation.end(), inverse_permutation.begin());
}
template <class T>
void
permutationFromNormalOrder(ArrayVector<T> & inverse_permutation, AxisInfo::AxisType types) const
{
ArrayVector<T> permutation;
permutationToNormalOrder(permutation, types);
inverse_permutation.resize(permutation.size());
indexSort(permutation.begin(), permutation.end(), inverse_permutation.begin());
}
template <class T>
void permutationToNumpyOrder(ArrayVector<T> & permutation) const
{
permutationToNormalOrder(permutation);
std::reverse(permutation.begin(), permutation.end());
}
template <class T>
void permutationFromNumpyOrder(ArrayVector<T> & inverse_permutation) const
{
ArrayVector<T> permutation;
permutationToNumpyOrder(permutation);
inverse_permutation.resize(permutation.size());
indexSort(permutation.begin(), permutation.end(), inverse_permutation.begin());
}
template <class T>
void permutationToVigraOrder(ArrayVector<T> & permutation) const
{
permutation.resize(size());
indexSort(axes_.begin(), axes_.end(), permutation.begin());
int channel = channelIndex();
if(channel < (int)size())
{
for(int k=1; k<(int)size(); ++k)
permutation[k-1] = permutation[k];
permutation.back() = channel;
}
}
template <class T>
void permutationFromVigraOrder(ArrayVector<T> & inverse_permutation) const
{
ArrayVector<T> permutation;
permutationToVigraOrder(permutation);
inverse_permutation.resize(permutation.size());
indexSort(permutation.begin(), permutation.end(), inverse_permutation.begin());
}
template <class T>
void permutationToOrder(ArrayVector<T> & permutation, std::string const & order) const
{
if(order == "A")
{
permutation.resize(size());
linearSequence(permutation.begin(), permutation.end());
}
else if(order == "C")
{
permutationToNumpyOrder(permutation);
}
else if(order == "F")
{
permutationToNormalOrder(permutation);
}
else if(order == "V")
{
permutationToVigraOrder(permutation);
}
else
{
vigra_precondition(false,
"AxisTags::permutationToOrder(): unknown order '" + order + "'.");
}
}
#if 0
ArrayVector<UInt32> matchOrdering(AxisTags const & other)
{
vigra_precondition(size() == other.size(),
"AxisTags::matchOrdering(): size mismatch.");
ArrayVector<UInt32> permutation(size());
for(unsigned int k = 0; k<size(); ++k)
{
std::string key = other.get(k).key();
unsigned int l=0;
for(; l<size(); ++l)
{
if(key == get(l).key())
break;
}
vigra_precondition(l < size(),
"AxisTags::matchOrdering(): key mismatch.");
permutation[k] = l;
}
return permutation;
}
#endif
bool compatible(AxisTags const & other) const
{
if(size() == 0 || other.size() == 0)
return true;
if(size() != other.size())
return false;
for(unsigned int k=0; k<size(); ++k)
if(!axes_[k].compatible(other.axes_[k]))
return false;
return true;
}
bool operator==(AxisTags const & other) const
{
if(size() != other.size())
return false;
return std::equal(axes_.begin(), axes_.end(), other.axes_.begin());
}
bool operator!=(AxisTags const & other) const
{
return !operator==(other);
}
protected:
void checkIndex(int k) const
{
vigra_precondition(k < (int)size() && k >= -(int)size(),
"AxisTags::checkIndex(): index out of range.");
}
void checkDuplicates(int i, AxisInfo const & info)
{
if(info.isChannel())
{
for(int k=0; k<(int)size(); ++k)
{
vigra_precondition(k == i || !axes_[k].isChannel(),
"AxisTags::checkDuplicates(): can only have one channel axis.");
}
}
else if(!info.isUnknown())
{
for(int k=0; k<(int)size(); ++k)
{
vigra_precondition(k == i || axes_[k].key() != info.key(),
std::string("AxisTags::checkDuplicates(): axis key '" +
info.key() + "' already exists."));
}
}
}
ArrayVector<AxisInfo> axes_;
};
// #if 0
// struct PyGetFunctor
// {
// AxisInfo const & operator()(python::object const & o) const
// {
// return python::extract<AxisInfo const &>(o)();
// }
// };
// class PyAxisTags
// : public AxisTags<python::object, PyGetFunctor>
// {
// typedef AxisTags<python::object, PyGetFunctor> BaseType;
// public:
// PyAxisTags()
// {}
// PyAxisTags(python::object i1, python::object i2,
// python::object i3, python::object i4, python::object i5)
// {
// if(PySequence_Check(i1.ptr()))
// {
// int size = len(i1);
// for(int k=0; k<size; ++k)
// if(python::extract<AxisInfo const &>(i1[k]).check())
// push_back(i1[k]);
// }
// else if(PyInt_Check(i1.ptr()))
// {
// int size = python::extract<int>(i1)();
// for(int k=0; k<size; ++k)
// push_back(python::object(AxisInfo()));
// }
// else
// {
// if(python::extract<AxisInfo const &>(i1).check())
// push_back(i1);
// if(python::extract<AxisInfo const &>(i2).check())
// push_back(i2);
// if(python::extract<AxisInfo const &>(i3).check())
// push_back(i3);
// if(python::extract<AxisInfo const &>(i4).check())
// push_back(i4);
// if(python::extract<AxisInfo const &>(i5).check())
// push_back(i5);
// }
// }
// python::object getitem(int k)
// {
// if(!checkIndex(k))
// {
// PyErr_SetString(PyExc_IndexError, "AxisInfo::getitem(): Invalid index or key.");
// python::throw_error_already_set();
// }
// if(k < 0)
// k += this->size();
// return this->axes_[k];
// }
// python::object getitem(std::string const & key)
// {
// return getitem(this->findKey(key));
// }
// void setitem(int k, python::object i)
// {
// if(!this->checkIndex(k))
// {
// PyErr_SetString(PyExc_IndexError, "AxisInfo::setitem(): Invalid index or key.");
// python::throw_error_already_set();
// }
// if(!python::extract<AxisInfo const &>(i).check())
// {
// PyErr_SetString(PyExc_TypeError, "AxisInfo::setitem(): Item type must be AxisInfo.");
// python::throw_error_already_set();
// }
// if(k < 0)
// k += this->size();
// this->axes_[k] = i;
// }
// void setitem(std::string const & key, python::object i)
// {
// setitem(this->findKey(key), i);
// }
// void append(python::object i)
// {
// insert(size(), i);
// }
// void insert(int k, python::object i)
// {
// if(k < 0)
// k += this->size();
// if(k < 0)
// k = 0;
// if(k > (int)this->size())
// k = this->size();
// if(!python::extract<AxisInfo const &>(i).check())
// {
// PyErr_SetString(PyExc_TypeError, "AxisInfo::insert(): Item type must be AxisInfo.");
// python::throw_error_already_set();
// }
// this->axes_.insert(this->axes_.begin()+k, i);
// }
// void insert(std::string const & key, python::object i)
// {
// insert(this->findKey(key), i);
// }
// python::list axesByFlag(AxisType typeFlags) const
// {
// python::list res;
// for(unsigned int k=0; k<this->size(); ++k)
// if(this->get(k).typeFlags() == typeFlags)
// res.append(k);
// return res;
// }
// python::list spatialAxes() const
// {
// python::list res;
// for(unsigned int k=0; k<this->size(); ++k)
// if(this->get(k).isSpatial())
// res.append(k);
// return res;
// }
// python::list temporalAxes() const
// {
// python::list res;
// for(unsigned int k=0; k<this->size(); ++k)
// if(this->get(k).isTemporal())
// res.append(k);
// return res;
// }
// python::list channelAxes() const
// {
// python::list res;
// for(unsigned int k=0; k<this->size(); ++k)
// if(this->get(k).isChannel())
// res.append(k);
// return res;
// }
// python::list frequencyAxes() const
// {
// python::list res;
// for(unsigned int k=0; k<this->size(); ++k)
// if(this->get(k).isFrequency())
// res.append(k);
// return res;
// }
// python::list angularAxes() const
// {
// python::list res;
// for(unsigned int k=0; k<this->size(); ++k)
// if(this->get(k).isAngular())
// res.append(k);
// return res;
// }
// python::list untaggedAxes() const
// {
// python::list res;
// for(unsigned int k=0; k<this->size(); ++k)
// if(this->get(k).isUnknown())
// res.append(k);
// return res;
// }
// template <class U>
// python::list vectorToPython(ArrayVector<U> const & v) const
// {
// python::list res;
// for(unsigned int k=0; k<v.size(); ++k)
// res.append(v[k]);
// return res;
// }
// python::list canonicalOrdering()
// {
// return vectorToPython(BaseType::canonicalOrdering());
// }
// python::list matchOrdering(PyAxisTags const & other)
// {
// return vectorToPython(BaseType::matchOrdering(other));
// }
// void transpose(python::object const & o)
// {
// unsigned int osize = len(o);
// ArrayVector<UInt32> permutation(osize);
// for(unsigned int k=0; k<this->size(); ++k)
// permutation[k] = python::extract<UInt32>(o[k])();
// BaseType::transpose(permutation);
// }
// void transpose()
// {
// BaseType::transpose();
// }
// };
// class TaggedShape
// {
// public:
// ArrayVector<npy_intp> shape;
// python_ptr axistags;
// npy_intp channelCount;
// std::string channelDescription;
// TaggedShape(MultiArrayIndex size)
// : shape(size)
// {}
// template <int N>
// TaggedShape(typename MultiArrayShape<N>::type const & sh)
// : shape(sh.begin(), sh.end())
// {}
// npy_intp & operator[](int i)
// {
// // rotate indices so that channels are located at index 0
// return shape[(i+1) % shape.size()];
// }
// npy_intp operator[](int i) const
// {
// return shape[(i+1) % shape.size()];
// }
// unsigned int size() const
// {
// return shape.size();
// }
// // void setChannelDescription(std::string const & description)
// // {
// // if(axistags)
// // {
// // python_ptr func(PyString_FromString("setChannelDescription"),
// // python_ptr::keep_count);
// // pythonToCppException(res);
// // python_ptr d(PyString_FromString(d.c_str()), python_ptr::keep_count);
// // pythonToCppException(d);
// // python_ptr res(PyObject_CallMethodObjArgs(axistags, func, d.get(), NULL),
// // python_ptr::keep_count);
// // pythonToCppException(res);
// // }
// // }
// // void setChannelCount(int channelCount)
// // {
// // shape[0] = channelCount;
// // }
// void setChannelDescription(std::string const & description)
// {
// channelDescription = description;
// }
// void setChannelCount(int count)
// {
// channelCount = count;
// }
// void setChannelConfig(int channelCount, std::string const & description)
// {
// setChannelCount(channelCount);
// setChannelDescription(description);
// }
// };
// #endif
} // namespace vigra
#endif /* VIGRA_AXISTAGS_HXX */
|