/usr/include/vigra/numpy_array_taggedshape.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 | /************************************************************************/
/* */
/* Copyright 2009 by Ullrich Koethe and Hans Meine */
/* */
/* 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_NUMPY_ARRAY_TAGGEDSHAPE_HXX
#define VIGRA_NUMPY_ARRAY_TAGGEDSHAPE_HXX
#include <string>
#include "array_vector.hxx"
#include "python_utility.hxx"
#include "axistags.hxx"
namespace vigra {
namespace detail {
inline
python_ptr getArrayTypeObject()
{
python_ptr arraytype((PyObject*)&PyArray_Type);
python_ptr vigra(PyImport_ImportModule("vigra"));
if(!vigra)
PyErr_Clear();
return pythonGetAttr(vigra, "standardArrayType", arraytype);
}
inline
std::string defaultOrder(std::string defaultValue = "C")
{
python_ptr arraytype = getArrayTypeObject();
return pythonGetAttr(arraytype, "defaultOrder", defaultValue);
}
inline
python_ptr defaultAxistags(int ndim, std::string order = "")
{
if(order == "")
order = defaultOrder();
python_ptr arraytype = getArrayTypeObject();
python_ptr func(PyString_FromString("defaultAxistags"), python_ptr::keep_count);
python_ptr d(PyInt_FromLong(ndim), python_ptr::keep_count);
python_ptr o(PyString_FromString(order.c_str()), python_ptr::keep_count);
python_ptr axistags(PyObject_CallMethodObjArgs(arraytype, func.get(), d.get(), o.get(), NULL),
python_ptr::keep_count);
if(axistags)
return axistags;
PyErr_Clear();
return python_ptr();
}
inline
python_ptr emptyAxistags(int ndim)
{
python_ptr arraytype = getArrayTypeObject();
python_ptr func(PyString_FromString("_empty_axistags"), python_ptr::keep_count);
python_ptr d(PyInt_FromLong(ndim), python_ptr::keep_count);
python_ptr axistags(PyObject_CallMethodObjArgs(arraytype, func.get(), d.get(), NULL),
python_ptr::keep_count);
if(axistags)
return axistags;
PyErr_Clear();
return python_ptr();
}
inline
void
getAxisPermutationImpl(ArrayVector<npy_intp> & permute,
python_ptr object, const char * name,
AxisInfo::AxisType type, bool ignoreErrors)
{
python_ptr func(PyString_FromString(name), python_ptr::keep_count);
python_ptr t(PyInt_FromLong((long)type), python_ptr::keep_count);
python_ptr permutation(PyObject_CallMethodObjArgs(object, func.get(), t.get(), NULL),
python_ptr::keep_count);
if(!permutation && ignoreErrors)
{
PyErr_Clear();
return;
}
pythonToCppException(permutation);
if(!PySequence_Check(permutation))
{
if(ignoreErrors)
return;
std::string message = std::string(name) + "() did not return a sequence.";
PyErr_SetString(PyExc_ValueError, message.c_str());
pythonToCppException(false);
}
ArrayVector<npy_intp> res(PySequence_Length(permutation));
for(int k=0; k<(int)res.size(); ++k)
{
python_ptr i(PySequence_GetItem(permutation, k), python_ptr::keep_count);
if(!PyInt_Check(i))
{
if(ignoreErrors)
return;
std::string message = std::string(name) + "() did not return a sequence of int.";
PyErr_SetString(PyExc_ValueError, message.c_str());
pythonToCppException(false);
}
res[k] = PyInt_AsLong(i);
}
res.swap(permute);
}
inline
void
getAxisPermutationImpl(ArrayVector<npy_intp> & permute,
python_ptr object, const char * name, bool ignoreErrors)
{
getAxisPermutationImpl(permute, object, name, AxisInfo::AllAxes, ignoreErrors);
}
} // namespace detail
/********************************************************/
/* */
/* PyAxisTags */
/* */
/********************************************************/
// FIXME: right now, we implement this class using the standard
// Python C-API only. It would be easier and more efficient
// to use boost::python here, but it would cause NumpyArray
// to depend on boost, making it more difficult to use
// NumpyArray in connection with other glue code generators.
class PyAxisTags
{
public:
typedef PyObject * pointer;
python_ptr axistags;
PyAxisTags(python_ptr tags = python_ptr(), bool createCopy = false)
{
if(!tags)
return;
// FIXME: do a more elaborate type check here?
if(!PySequence_Check(tags))
{
PyErr_SetString(PyExc_TypeError,
"PyAxisTags(tags): tags argument must have type 'AxisTags'.");
pythonToCppException(false);
}
else if(PySequence_Length(tags) == 0)
{
return;
}
if(createCopy)
{
python_ptr func(PyString_FromString("__copy__"), python_ptr::keep_count);
axistags = python_ptr(PyObject_CallMethodObjArgs(tags, func.get(), NULL),
python_ptr::keep_count);
}
else
{
axistags = tags;
}
}
PyAxisTags(PyAxisTags const & other, bool createCopy = false)
{
if(!other.axistags)
return;
if(createCopy)
{
python_ptr func(PyString_FromString("__copy__"), python_ptr::keep_count);
axistags = python_ptr(PyObject_CallMethodObjArgs(other.axistags, func.get(), NULL),
python_ptr::keep_count);
}
else
{
axistags = other.axistags;
}
}
PyAxisTags(int ndim, std::string const & order = "")
{
if(order != "")
axistags = detail::defaultAxistags(ndim, order);
else
axistags = detail::emptyAxistags(ndim);
}
long size() const
{
return axistags
? PySequence_Length(axistags)
: 0;
}
long channelIndex(long defaultVal) const
{
return pythonGetAttr(axistags, "channelIndex", defaultVal);
}
long channelIndex() const
{
return channelIndex(size());
}
bool hasChannelAxis() const
{
return channelIndex() != size();
}
long innerNonchannelIndex(long defaultVal) const
{
return pythonGetAttr(axistags, "innerNonchannelIndex", defaultVal);
}
long innerNonchannelIndex() const
{
return innerNonchannelIndex(size());
}
void setChannelDescription(std::string const & description)
{
if(!axistags)
return;
python_ptr d(PyString_FromString(description.c_str()), python_ptr::keep_count);
python_ptr func(PyString_FromString("setChannelDescription"), python_ptr::keep_count);
python_ptr res(PyObject_CallMethodObjArgs(axistags, func.get(), d.get(), NULL),
python_ptr::keep_count);
pythonToCppException(res);
}
double resolution(long index)
{
if(!axistags)
return 0.0;
python_ptr func(PyString_FromString("resolution"), python_ptr::keep_count);
python_ptr i(PyInt_FromLong(index), python_ptr::keep_count);
python_ptr res(PyObject_CallMethodObjArgs(axistags, func.get(), i.get(), NULL),
python_ptr::keep_count);
pythonToCppException(res);
if(!PyFloat_Check(res))
{
PyErr_SetString(PyExc_TypeError, "AxisTags.resolution() did not return float.");
pythonToCppException(false);
}
return PyFloat_AsDouble(res);
}
void setResolution(long index, double resolution)
{
if(!axistags)
return;
python_ptr func(PyString_FromString("setResolution"), python_ptr::keep_count);
python_ptr i(PyInt_FromLong(index), python_ptr::keep_count);
python_ptr r(PyFloat_FromDouble(resolution), python_ptr::keep_count);
python_ptr res(PyObject_CallMethodObjArgs(axistags, func.get(), i.get(), r.get(), NULL),
python_ptr::keep_count);
pythonToCppException(res);
}
void scaleResolution(long index, double factor)
{
if(!axistags)
return;
python_ptr func(PyString_FromString("scaleResolution"), python_ptr::keep_count);
python_ptr i(PyInt_FromLong(index), python_ptr::keep_count);
python_ptr f(PyFloat_FromDouble(factor), python_ptr::keep_count);
python_ptr res(PyObject_CallMethodObjArgs(axistags, func.get(), i.get(), f.get(), NULL),
python_ptr::keep_count);
pythonToCppException(res);
}
void toFrequencyDomain(long index, int size, int sign = 1)
{
if(!axistags)
return;
python_ptr func(sign == 1
? PyString_FromString("toFrequencyDomain")
: PyString_FromString("fromFrequencyDomain"),
python_ptr::keep_count);
python_ptr i(PyInt_FromLong(index), python_ptr::keep_count);
python_ptr s(PyInt_FromLong(size), python_ptr::keep_count);
python_ptr res(PyObject_CallMethodObjArgs(axistags, func.get(), i.get(), s.get(), NULL),
python_ptr::keep_count);
pythonToCppException(res);
}
void fromFrequencyDomain(long index, int size)
{
toFrequencyDomain(index, size, -1);
}
ArrayVector<npy_intp>
permutationToNormalOrder(bool ignoreErrors = false) const
{
ArrayVector<npy_intp> permute;
detail::getAxisPermutationImpl(permute, axistags, "permutationToNormalOrder", ignoreErrors);
return permute;
}
ArrayVector<npy_intp>
permutationToNormalOrder(AxisInfo::AxisType types, bool ignoreErrors = false) const
{
ArrayVector<npy_intp> permute;
detail::getAxisPermutationImpl(permute, axistags,
"permutationToNormalOrder", types, ignoreErrors);
return permute;
}
ArrayVector<npy_intp>
permutationFromNormalOrder(bool ignoreErrors = false) const
{
ArrayVector<npy_intp> permute;
detail::getAxisPermutationImpl(permute, axistags,
"permutationFromNormalOrder", ignoreErrors);
return permute;
}
ArrayVector<npy_intp>
permutationFromNormalOrder(AxisInfo::AxisType types, bool ignoreErrors = false) const
{
ArrayVector<npy_intp> permute;
detail::getAxisPermutationImpl(permute, axistags,
"permutationFromNormalOrder", types, ignoreErrors);
return permute;
}
void dropChannelAxis()
{
if(!axistags)
return;
python_ptr func(PyString_FromString("dropChannelAxis"),
python_ptr::keep_count);
python_ptr res(PyObject_CallMethodObjArgs(axistags, func.get(), NULL),
python_ptr::keep_count);
pythonToCppException(res);
}
void insertChannelAxis()
{
if(!axistags)
return;
python_ptr func(PyString_FromString("insertChannelAxis"),
python_ptr::keep_count);
python_ptr res(PyObject_CallMethodObjArgs(axistags, func.get(), NULL),
python_ptr::keep_count);
pythonToCppException(res);
}
operator pointer()
{
return axistags.get();
}
bool operator!() const
{
return !axistags;
}
};
/********************************************************/
/* */
/* TaggedShape */
/* */
/********************************************************/
class TaggedShape
{
public:
enum ChannelAxis { first, last, none };
ArrayVector<npy_intp> shape, original_shape;
PyAxisTags axistags;
ChannelAxis channelAxis;
std::string channelDescription;
explicit TaggedShape(MultiArrayIndex size)
: shape(size),
axistags(size),
channelAxis(none)
{}
template <class U, int N>
TaggedShape(TinyVector<U, N> const & sh, PyAxisTags tags)
: shape(sh.begin(), sh.end()),
original_shape(sh.begin(), sh.end()),
axistags(tags),
channelAxis(none)
{}
template <class T>
TaggedShape(ArrayVector<T> const & sh, PyAxisTags tags)
: shape(sh.begin(), sh.end()),
original_shape(sh.begin(), sh.end()),
axistags(tags),
channelAxis(none)
{}
template <class U, int N>
explicit TaggedShape(TinyVector<U, N> const & sh)
: shape(sh.begin(), sh.end()),
original_shape(sh.begin(), sh.end()),
channelAxis(none)
{}
template <class T>
explicit TaggedShape(ArrayVector<T> const & sh)
: shape(sh.begin(), sh.end()),
original_shape(sh.begin(), sh.end()),
channelAxis(none)
{}
template <class U, int N>
TaggedShape & resize(TinyVector<U, N> const & sh)
{
int start = channelAxis == first
? 1
: 0,
stop = channelAxis == last
? (int)size()-1
: (int)size();
vigra_precondition(N == stop - start || size() == 0,
"TaggedShape.resize(): size mismatch.");
if(size() == 0)
shape.resize(N);
for(int k=0; k<N; ++k)
shape[k+start] = sh[k];
return *this;
}
TaggedShape & resize(MultiArrayIndex v1)
{
return resize(TinyVector<MultiArrayIndex, 1>(v1));
}
TaggedShape & resize(MultiArrayIndex v1, MultiArrayIndex v2)
{
return resize(TinyVector<MultiArrayIndex, 2>(v1, v2));
}
TaggedShape & resize(MultiArrayIndex v1, MultiArrayIndex v2, MultiArrayIndex v3)
{
return resize(TinyVector<MultiArrayIndex, 3>(v1, v2, v3));
}
TaggedShape & resize(MultiArrayIndex v1, MultiArrayIndex v2,
MultiArrayIndex v3, MultiArrayIndex v4)
{
return resize(TinyVector<MultiArrayIndex, 4>(v1, v2, v3, v4));
}
npy_intp & operator[](int i)
{
return shape[i];
}
npy_intp operator[](int i) const
{
return shape[i];
}
unsigned int size() const
{
return shape.size();
}
TaggedShape & operator+=(int v)
{
int start = channelAxis == first
? 1
: 0,
stop = channelAxis == last
? (int)size()-1
: (int)size();
for(int k=start; k<stop; ++k)
shape[k] += v;
return *this;
}
TaggedShape & operator-=(int v)
{
return operator+=(-v);
}
TaggedShape & operator*=(int factor)
{
int start = channelAxis == first
? 1
: 0,
stop = channelAxis == last
? (int)size()-1
: (int)size();
for(int k=start; k<stop; ++k)
shape[k] *= factor;
return *this;
}
void rotateToNormalOrder()
{
if(axistags && channelAxis == last)
{
int ndim = (int)size();
npy_intp channelCount = shape[ndim-1];
for(int k=ndim-1; k>0; --k)
shape[k] = shape[k-1];
shape[0] = channelCount;
channelCount = original_shape[ndim-1];
for(int k=ndim-1; k>0; --k)
original_shape[k] = original_shape[k-1];
original_shape[0] = channelCount;
channelAxis = first;
}
}
TaggedShape & setChannelDescription(std::string const & description)
{
// we only remember the description here, and will actually set
// it in the finalize function
channelDescription = description;
return *this;
}
TaggedShape & setChannelIndexLast()
{
// FIXME: add some checks?
channelAxis = last;
return *this;
}
// transposeShape() means: only shape and resolution are transposed, not the axis keys
template <class U, int N>
TaggedShape & transposeShape(TinyVector<U, N> const & p)
{
int ntags = axistags.size();
ArrayVector<npy_intp> permute = axistags.permutationToNormalOrder();
int tstart = (axistags.channelIndex(ntags) < ntags)
? 1
: 0;
int sstart = (channelAxis == first)
? 1
: 0;
int ndim = ntags - tstart;
vigra_precondition(N == ndim,
"TaggedShape.transposeShape(): size mismatch.");
PyAxisTags newAxistags(axistags.axistags); // force copy
for(int k=0; k<ndim; ++k)
{
original_shape[k+sstart] = shape[p[k]+sstart];
newAxistags.setResolution(permute[k+tstart], axistags.resolution(permute[p[k]+tstart]));
}
shape = original_shape;
axistags = newAxistags;
return *this;
}
TaggedShape & toFrequencyDomain(int sign = 1)
{
int ntags = axistags.size();
ArrayVector<npy_intp> permute = axistags.permutationToNormalOrder();
int tstart = (axistags.channelIndex(ntags) < ntags)
? 1
: 0;
int sstart = (channelAxis == first)
? 1
: 0;
int send = (channelAxis == last)
? (int)size()-1
: (int)size();
int size = send - sstart;
for(int k=0; k<size; ++k)
{
axistags.toFrequencyDomain(permute[k+tstart], shape[k+sstart], sign);
}
return *this;
}
TaggedShape & fromFrequencyDomain()
{
return toFrequencyDomain(-1);
}
bool compatible(TaggedShape const & other) const
{
if(channelCount() != other.channelCount())
return false;
int start = channelAxis == first
? 1
: 0,
stop = channelAxis == last
? (int)size()-1
: (int)size();
int ostart = other.channelAxis == first
? 1
: 0,
ostop = other.channelAxis == last
? (int)other.size()-1
: (int)other.size();
int len = stop - start;
if(len != ostop - ostart)
return false;
for(int k=0; k<len; ++k)
if(shape[k+start] != other.shape[k+ostart])
return false;
return true;
}
TaggedShape & setChannelCount(int count)
{
switch(channelAxis)
{
case first:
if(count > 0)
{
shape[0] = count;
}
else
{
shape.erase(shape.begin());
original_shape.erase(original_shape.begin());
channelAxis = none;
}
break;
case last:
if(count > 0)
{
shape[size()-1] = count;
}
else
{
shape.pop_back();
original_shape.pop_back();
channelAxis = none;
}
break;
case none:
if(count > 0)
{
shape.push_back(count);
original_shape.push_back(count);
channelAxis = last;
}
break;
}
return *this;
}
int channelCount() const
{
switch(channelAxis)
{
case first:
return shape[0];
case last:
return shape[size()-1];
default:
return 1;
}
}
};
inline
void scaleAxisResolution(TaggedShape & tagged_shape)
{
if(tagged_shape.size() != tagged_shape.original_shape.size())
return;
int ntags = tagged_shape.axistags.size();
ArrayVector<npy_intp> permute = tagged_shape.axistags.permutationToNormalOrder();
int tstart = (tagged_shape.axistags.channelIndex(ntags) < ntags)
? 1
: 0;
int sstart = (tagged_shape.channelAxis == TaggedShape::first)
? 1
: 0;
int size = (int)tagged_shape.size() - sstart;
for(int k=0; k<size; ++k)
{
int sk = k + sstart;
if(tagged_shape.shape[sk] == tagged_shape.original_shape[sk])
continue;
double factor = (tagged_shape.original_shape[sk] - 1.0) / (tagged_shape.shape[sk] - 1.0);
tagged_shape.axistags.scaleResolution(permute[k+tstart], factor);
}
}
inline
void unifyTaggedShapeSize(TaggedShape & tagged_shape)
{
PyAxisTags axistags = tagged_shape.axistags;
ArrayVector<npy_intp> & shape = tagged_shape.shape;
int ndim = (int)shape.size();
int ntags = axistags.size();
long channelIndex = axistags.channelIndex();
if(tagged_shape.channelAxis == TaggedShape::none)
{
// shape has no channel axis
if(channelIndex == ntags)
{
// std::cerr << "branch (shape, axitags) 0 0\n";
// axistags have no channel axis either => sizes should match
vigra_precondition(ndim == ntags,
"constructArray(): size mismatch between shape and axistags.");
}
else
{
// std::cerr << "branch (shape, axitags) 0 1\n";
if(ndim+1 == ntags)
{
// std::cerr << " drop channel axis\n";
// axistags have one additional element => drop the channel tag
// FIXME: would it be cleaner to make this an error ?
axistags.dropChannelAxis();
}
else
{
vigra_precondition(ndim == ntags,
"constructArray(): size mismatch between shape and axistags.");
}
}
}
else
{
// shape has a channel axis
if(channelIndex == ntags)
{
// std::cerr << "branch (shape, axitags) 1 0\n";
// axistags have no channel axis => should be one element shorter
vigra_precondition(ndim == ntags+1,
"constructArray(): size mismatch between shape and axistags.");
if(shape[0] == 1)
{
// std::cerr << " drop channel axis\n";
// we have a singleband image => drop the channel axis
shape.erase(shape.begin());
ndim -= 1;
}
else
{
// std::cerr << " insert channel axis\n";
// we have a multiband image => add a channel tag
axistags.insertChannelAxis();
}
}
else
{
// std::cerr << "branch (shape, axitags) 1 1\n";
// axistags have channel axis => sizes should match
vigra_precondition(ndim == ntags,
"constructArray(): size mismatch between shape and axistags.");
}
}
}
inline
ArrayVector<npy_intp> finalizeTaggedShape(TaggedShape & tagged_shape)
{
if(tagged_shape.axistags)
{
tagged_shape.rotateToNormalOrder();
// we assume here that the axistag object belongs to the array to be created
// so that we can freely edit it
scaleAxisResolution(tagged_shape);
// this must be after scaleAxisResolution(), because the latter requires
// shape and original_shape to be still in sync
unifyTaggedShapeSize(tagged_shape);
if(tagged_shape.channelDescription != "")
tagged_shape.axistags.setChannelDescription(tagged_shape.channelDescription);
}
return tagged_shape.shape;
}
} // namespace vigra
#endif // VIGRA_NUMPY_ARRAY_TAGGEDSHAPE_HXX
|