/usr/include/vigra/splineimageview.hxx is in libvigraimpex-dev 1.7.1+dfsg1-2ubuntu4.
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 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 | /************************************************************************/
/* */
/* Copyright 1998-2004 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_SPLINEIMAGEVIEW_HXX
#define VIGRA_SPLINEIMAGEVIEW_HXX
#include "mathutil.hxx"
#include "recursiveconvolution.hxx"
#include "splines.hxx"
#include "array_vector.hxx"
#include "basicimage.hxx"
#include "copyimage.hxx"
#include "tinyvector.hxx"
#include "fixedpoint.hxx"
#include "multi_array.hxx"
namespace vigra {
/********************************************************/
/* */
/* SplineImageView */
/* */
/********************************************************/
/** \brief Create a continuous view onto a discrete image using splines.
This class is very useful if image values or derivatives at arbitrary
real-valued coordinates are needed. Access at such coordinates is implemented by
interpolating the given discrete image values with a spline of the
specified <tt>ORDER</TT>. Continuous derivatives are available up to
degree <tt>ORDER-1</TT>. If the requested coordinates are near the image border,
reflective boundary conditions are applied. In principle, this class can also be used
for image resizing, but here the functions from the <tt>resize...</tt> family are
more efficient, since they exploit the regularity of the sampling grid.
The <tt>SplineImageView</tt> template is explicitly specialized to make it as efficient as possible.
In particular, unnecessary copying of the image is avoided when the iterators passed
in the constructor originate from a \ref vigra::BasicImage. In addition, these specializations
provide function <tt>unchecked(...)</tt> that do not perform bounds checking. If the original image
is not a variant of \ref vigra::BasicImage, one can customize the internal representation by
using \ref vigra::SplineImageView0 or \ref vigra::SplineImageView1.
<b>Usage:</b>
<b>\#include</b> \<<a href="splineimageview_8hxx-source.html">vigra/splineimageview.hxx</a>\><br>
Namespace: vigra
\code
BImage img(w,h);
... // fill img
// construct spline view for quadratic interpolation
SplineImageView<2, double> spi2(srcImageRange(img));
double x = ..., y = ...;
double v2 = spi2(x, y);
// construct spline view for linear interpolation
SplineImageView<1, UInt32> spi1(srcImageRange(img));
UInt32 v1 = spi1(x, y);
FixedPoint<16, 15> fx(...), fy(...);
UInt32 vf = spi1.unchecked(fx, fy); // caller is sure that (fx, fy) are valid coordinates
\endcode
*/
template <int ORDER, class VALUETYPE>
class SplineImageView
{
typedef typename NumericTraits<VALUETYPE>::RealPromote InternalValue;
public:
/** The view's value type (return type of access and derivative functions).
*/
typedef VALUETYPE value_type;
/** The view's size type.
*/
typedef Size2D size_type;
/** The view's difference type.
*/
typedef TinyVector<double, 2> difference_type;
/** The order of the spline used.
*/
enum StaticOrder { order = ORDER };
/** The type of the internal image holding the spline coefficients.
*/
typedef BasicImage<InternalValue> InternalImage;
private:
typedef typename InternalImage::traverser InternalTraverser;
typedef typename InternalTraverser::row_iterator InternalRowIterator;
typedef typename InternalTraverser::column_iterator InternalColumnIterator;
typedef BSpline<ORDER, double> Spline;
enum { ksize_ = ORDER + 1, kcenter_ = ORDER / 2 };
public:
/** Construct SplineImageView for the given image.
If <tt>skipPrefiltering = true</tt> (default: <tt>false</tt>), the recursive
prefilter of the cardinal spline function is not applied, resulting
in an approximating (smoothing) rather than interpolating spline. This is
especially useful if customized prefilters are to be applied.
*/
template <class SrcIterator, class SrcAccessor>
SplineImageView(SrcIterator is, SrcIterator iend, SrcAccessor sa, bool skipPrefiltering = false)
: w_(iend.x - is.x), h_(iend.y - is.y), w1_(w_-1), h1_(h_-1),
x0_(kcenter_), x1_(w_ - kcenter_ - 2), y0_(kcenter_), y1_(h_ - kcenter_ - 2),
image_(w_, h_),
x_(-1.0), y_(-1.0),
u_(-1.0), v_(-1.0)
{
copyImage(srcIterRange(is, iend, sa), destImage(image_));
if(!skipPrefiltering)
init();
}
/** Construct SplineImageView for the given image.
If <tt>skipPrefiltering = true</tt> (default: <tt>false</tt>), the recursive
prefilter of the cardinal spline function is not applied, resulting
in an approximating (smoothing) rather than interpolating spline. This is
especially useful if customized prefilters are to be applied.
*/
template <class SrcIterator, class SrcAccessor>
SplineImageView(triple<SrcIterator, SrcIterator, SrcAccessor> s, bool skipPrefiltering = false)
: w_(s.second.x - s.first.x), h_(s.second.y - s.first.y), w1_(w_-1), h1_(h_-1),
x0_(kcenter_), x1_(w_ - kcenter_ - 2), y0_(kcenter_), y1_(h_ - kcenter_ - 2),
image_(w_, h_),
x_(-1.0), y_(-1.0),
u_(-1.0), v_(-1.0)
{
copyImage(srcIterRange(s.first, s.second, s.third), destImage(image_));
if(!skipPrefiltering)
init();
}
/** Access interpolated function at real-valued coordinate <tt>(x, y)</tt>.
If <tt>(x, y)</tt> is near the image border or outside the image, the value
is calculated with reflective boundary conditions. An exception is thrown if the
coordinate is outside the first reflection.
*/
value_type operator()(double x, double y) const;
/** Access derivative of order <tt>(dx, dy)</tt> at real-valued coordinate <tt>(x, y)</tt>.
If <tt>(x, y)</tt> is near the image border or outside the image, the value
is calculated with reflective boundary conditions. An exception is thrown if the
coordinate is outside the first reflection.
*/
value_type operator()(double x, double y, unsigned int dx, unsigned int dy) const;
/** Access 1st derivative in x-direction at real-valued coordinate <tt>(x, y)</tt>.
Equivalent to <tt>splineView(x, y, 1, 0)</tt>.
*/
value_type dx(double x, double y) const
{ return operator()(x, y, 1, 0); }
/** Access 1st derivative in y-direction at real-valued coordinate <tt>(x, y)</tt>.
Equivalent to <tt>splineView(x, y, 0, 1)</tt>.
*/
value_type dy(double x, double y) const
{ return operator()(x, y, 0, 1); }
/** Access 2nd derivative in x-direction at real-valued coordinate <tt>(x, y)</tt>.
Equivalent to <tt>splineView(x, y, 2, 0)</tt>.
*/
value_type dxx(double x, double y) const
{ return operator()(x, y, 2, 0); }
/** Access mixed 2nd derivative at real-valued coordinate <tt>(x, y)</tt>.
Equivalent to <tt>splineView(x, y, 1, 1)</tt>.
*/
value_type dxy(double x, double y) const
{ return operator()(x, y, 1, 1); }
/** Access 2nd derivative in y-direction at real-valued coordinate <tt>(x, y)</tt>.
Equivalent to <tt>splineView(x, y, 0, 2)</tt>.
*/
value_type dyy(double x, double y) const
{ return operator()(x, y, 0, 2); }
/** Access 3rd derivative in x-direction at real-valued coordinate <tt>(x, y)</tt>.
Equivalent to <tt>splineView(x, y, 3, 0)</tt>.
*/
value_type dx3(double x, double y) const
{ return operator()(x, y, 3, 0); }
/** Access 3rd derivative in y-direction at real-valued coordinate <tt>(x, y)</tt>.
Equivalent to <tt>splineView(x, y, 0, 3)</tt>.
*/
value_type dy3(double x, double y) const
{ return operator()(x, y, 0, 3); }
/** Access mixed 3rd derivative dxxy at real-valued coordinate <tt>(x, y)</tt>.
Equivalent to <tt>splineView(x, y, 2, 1)</tt>.
*/
value_type dxxy(double x, double y) const
{ return operator()(x, y, 2, 1); }
/** Access mixed 3rd derivative dxyy at real-valued coordinate <tt>(x, y)</tt>.
Equivalent to <tt>splineView(x, y, 1, 2)</tt>.
*/
value_type dxyy(double x, double y) const
{ return operator()(x, y, 1, 2); }
/** Access interpolated function at real-valued coordinate <tt>d</tt>.
Equivalent to <tt>splineView(d[0], d[1])</tt>.
*/
value_type operator()(difference_type const & d) const
{ return operator()(d[0], d[1]); }
/** Access derivative of order <tt>(dx, dy)</tt> at real-valued coordinate <tt>d</tt>.
Equivalent to <tt>splineView(d[0], d[1], dx, dy)</tt>.
*/
value_type operator()(difference_type const & d, unsigned int dx, unsigned int dy) const
{ return operator()(d[0], d[1], dx, dy); }
/** Access 1st derivative in x-direction at real-valued coordinate <tt>d</tt>.
Equivalent to <tt>splineView.dx(d[0], d[1])</tt>.
*/
value_type dx(difference_type const & d) const
{ return dx(d[0], d[1]); }
/** Access 1st derivative in y-direction at real-valued coordinate <tt>d</tt>.
Equivalent to <tt>splineView.dy(d[0], d[1])</tt>.
*/
value_type dy(difference_type const & d) const
{ return dy(d[0], d[1]); }
/** Access 2nd derivative in x-direction at real-valued coordinate <tt>d</tt>.
Equivalent to <tt>splineView.dxx(d[0], d[1])</tt>.
*/
value_type dxx(difference_type const & d) const
{ return dxx(d[0], d[1]); }
/** Access mixed 2nd derivative at real-valued coordinate <tt>d</tt>.
Equivalent to <tt>splineView.dxy(d[0], d[1])</tt>.
*/
value_type dxy(difference_type const & d) const
{ return dxy(d[0], d[1]); }
/** Access 2nd derivative in y-direction at real-valued coordinate <tt>d</tt>.
Equivalent to <tt>splineView.dyy(d[0], d[1])</tt>.
*/
value_type dyy(difference_type const & d) const
{ return dyy(d[0], d[1]); }
/** Access 3rd derivative in x-direction at real-valued coordinate <tt>d</tt>.
Equivalent to <tt>splineView.dx3(d[0], d[1])</tt>.
*/
value_type dx3(difference_type const & d) const
{ return dx3(d[0], d[1]); }
/** Access 3rd derivative in y-direction at real-valued coordinate <tt>d</tt>.
Equivalent to <tt>splineView.dy3(d[0], d[1])</tt>.
*/
value_type dy3(difference_type const & d) const
{ return dy3(d[0], d[1]); }
/** Access mixed 3rd derivative dxxy at real-valued coordinate <tt>d</tt>.
Equivalent to <tt>splineView.dxxy(d[0], d[1])</tt>.
*/
value_type dxxy(difference_type const & d) const
{ return dxxy(d[0], d[1]); }
/** Access mixed 3rd derivative dxyy at real-valued coordinate <tt>d</tt>.
Equivalent to <tt>splineView.dxyy(d[0], d[1])</tt>.
*/
value_type dxyy(difference_type const & d) const
{ return dxyy(d[0], d[1]); }
/** Access gradient squared magnitude at real-valued coordinate <tt>(x, y)</tt>.
*/
value_type g2(double x, double y) const;
/** Access 1st derivative in x-direction of gradient squared magnitude
at real-valued coordinate <tt>(x, y)</tt>.
*/
value_type g2x(double x, double y) const;
/** Access 1st derivative in y-direction of gradient squared magnitude
at real-valued coordinate <tt>(x, y)</tt>.
*/
value_type g2y(double x, double y) const;
/** Access 2nd derivative in x-direction of gradient squared magnitude
at real-valued coordinate <tt>(x, y)</tt>.
*/
value_type g2xx(double x, double y) const;
/** Access mixed 2nd derivative of gradient squared magnitude
at real-valued coordinate <tt>(x, y)</tt>.
*/
value_type g2xy(double x, double y) const;
/** Access 2nd derivative in y-direction of gradient squared magnitude
at real-valued coordinate <tt>(x, y)</tt>.
*/
value_type g2yy(double x, double y) const;
/** Access gradient squared magnitude at real-valued coordinate <tt>d</tt>.
*/
value_type g2(difference_type const & d) const
{ return g2(d[0], d[1]); }
/** Access 1st derivative in x-direction of gradient squared magnitude
at real-valued coordinate <tt>d</tt>.
*/
value_type g2x(difference_type const & d) const
{ return g2x(d[0], d[1]); }
/** Access 1st derivative in y-direction of gradient squared magnitude
at real-valued coordinate <tt>d</tt>.
*/
value_type g2y(difference_type const & d) const
{ return g2y(d[0], d[1]); }
/** Access 2nd derivative in x-direction of gradient squared magnitude
at real-valued coordinate <tt>d</tt>.
*/
value_type g2xx(difference_type const & d) const
{ return g2xx(d[0], d[1]); }
/** Access mixed 2nd derivative of gradient squared magnitude
at real-valued coordinate <tt>d</tt>.
*/
value_type g2xy(difference_type const & d) const
{ return g2xy(d[0], d[1]); }
/** Access 2nd derivative in y-direction of gradient squared magnitude
at real-valued coordinate <tt>d</tt>.
*/
value_type g2yy(difference_type const & d) const
{ return g2yy(d[0], d[1]); }
/** The width of the image.
<tt>0 <= x <= width()-1</tt> is required for all access functions.
*/
unsigned int width() const
{ return w_; }
/** The height of the image.
<tt>0 <= y <= height()-1</tt> is required for all access functions.
*/
unsigned int height() const
{ return h_; }
/** The size of the image.
<tt>0 <= x <= size().x-1</tt> and <tt>0 <= y <= size().y-1</tt>
are required for all access functions.
*/
size_type size() const
{ return size_type(w_, h_); }
/** The shape of the image.
Same as size(), except for the return type.
*/
TinyVector<unsigned int, 2> shape() const
{ return TinyVector<unsigned int, 2>(w_, h_); }
/** The internal image holding the spline coefficients.
*/
InternalImage const & image() const
{
return image_;
}
/** Get the array of polynomial coefficients for the facet containing
the point <tt>(x, y)</tt>. The array <tt>res</tt> will be resized to
dimension <tt>(ORDER+1)x(ORDER+1)</tt>. From these coefficients, the
value of the interpolated function can be calculated by the following
algorithm
\code
SplineImageView<ORDER, float> view(...);
double x = ..., y = ...;
double dx, dy;
// calculate the local facet coordinates of x and y
if(ORDER % 2)
{
// odd order => facet coordinates between 0 and 1
dx = x - floor(x);
dy = y - floor(y);
}
else
{
// even order => facet coordinates between -0.5 and 0.5
dx = x - floor(x + 0.5);
dy = y - floor(y + 0.5);
}
BasicImage<float> coefficients;
view.coefficientArray(x, y, coefficients);
float f_x_y = 0.0;
for(int ny = 0; ny < ORDER + 1; ++ny)
for(int nx = 0; nx < ORDER + 1; ++nx)
f_x_y += pow(dx, nx) * pow(dy, ny) * coefficients(nx, ny);
assert(abs(f_x_y - view(x, y)) < 1e-6);
\endcode
*/
template <class Array>
void coefficientArray(double x, double y, Array & res) const;
/** Check if x is in the original image range.
Equivalent to <tt>0 <= x <= width()-1</tt>.
*/
bool isInsideX(double x) const
{
return x >= 0.0 && x <= width()-1.0;
}
/** Check if y is in the original image range.
Equivalent to <tt>0 <= y <= height()-1</tt>.
*/
bool isInsideY(double y) const
{
return y >= 0.0 && y <= height()-1.0;
}
/** Check if x and y are in the original image range.
Equivalent to <tt>0 <= x <= width()-1</tt> and <tt>0 <= y <= height()-1</tt>.
*/
bool isInside(double x, double y) const
{
return isInsideX(x) && isInsideY(y);
}
/** Check if x and y are in the valid range. Points outside the original image range are computed
by reflcective boundary conditions, but only within the first reflection.
Equivalent to <tt>-width() + ORDER/2 + 2 < x < 2*width() - ORDER/2 - 2</tt> and
<tt>-height() + ORDER/2 + 2 < y < 2*height() - ORDER/2 - 2</tt>.
*/
bool isValid(double x, double y) const
{
return x < w1_ + x1_ && x > -x1_ && y < h1_ + y1_ && y > -y1_;
}
/** Check whether the points <tt>(x0, y0)</tt> and <tt>(x1, y1)</tt> are in
the same spline facet. For odd order splines, facets span the range
<tt>(floor(x), floor(x)+1) x (floor(y), floor(y)+1)</tt> (i.e. we have
integer facet borders), whereas even order splines have facet between
half integer values
<tt>(floor(x)-0.5, floor(x)+0.5) x (floor(y)-0.5, floor(y)+0.5)</tt>.
*/
bool sameFacet(double x0, double y0, double x1, double y1) const
{
x0 = VIGRA_CSTD::floor((ORDER % 2) ? x0 : x0 + 0.5);
y0 = VIGRA_CSTD::floor((ORDER % 2) ? y0 : y0 + 0.5);
x1 = VIGRA_CSTD::floor((ORDER % 2) ? x1 : x1 + 0.5);
y1 = VIGRA_CSTD::floor((ORDER % 2) ? y1 : y1 + 0.5);
return x0 == x1 && y0 == y1;
}
protected:
void init();
void calculateIndices(double x, double y) const;
void coefficients(double t, double * const & c) const;
void derivCoefficients(double t, unsigned int d, double * const & c) const;
value_type convolve() const;
unsigned int w_, h_;
int w1_, h1_;
double x0_, x1_, y0_, y1_;
InternalImage image_;
Spline k_;
mutable double x_, y_, u_, v_, kx_[ksize_], ky_[ksize_];
mutable int ix_[ksize_], iy_[ksize_];
};
template <int ORDER, class VALUETYPE>
void SplineImageView<ORDER, VALUETYPE>::init()
{
ArrayVector<double> const & b = k_.prefilterCoefficients();
for(unsigned int i=0; i<b.size(); ++i)
{
recursiveFilterX(srcImageRange(image_), destImage(image_), b[i], BORDER_TREATMENT_REFLECT);
recursiveFilterY(srcImageRange(image_), destImage(image_), b[i], BORDER_TREATMENT_REFLECT);
}
}
namespace detail
{
template <int i>
struct SplineImageViewUnrollLoop1
{
template <class Array>
static void exec(int c0, Array c)
{
SplineImageViewUnrollLoop1<i-1>::exec(c0, c);
c[i] = c0 + i;
}
};
template <>
struct SplineImageViewUnrollLoop1<0>
{
template <class Array>
static void exec(int c0, Array c)
{
c[0] = c0;
}
};
template <int i, class ValueType>
struct SplineImageViewUnrollLoop2
{
template <class Array1, class RowIterator, class Array2>
static ValueType
exec(Array1 k, RowIterator r, Array2 x)
{
return ValueType(k[i] * r[x[i]]) + SplineImageViewUnrollLoop2<i-1, ValueType>::exec(k, r, x);
}
};
template <class ValueType>
struct SplineImageViewUnrollLoop2<0, ValueType>
{
template <class Array1, class RowIterator, class Array2>
static ValueType
exec(Array1 k, RowIterator r, Array2 x)
{
return ValueType(k[0] * r[x[0]]);
}
};
} // namespace detail
template <int ORDER, class VALUETYPE>
void
SplineImageView<ORDER, VALUETYPE>::calculateIndices(double x, double y) const
{
if(x == x_ && y == y_)
return; // still in cache
if(x > x0_ && x < x1_ && y > y0_ && y < y1_)
{
detail::SplineImageViewUnrollLoop1<ORDER>::exec(
(ORDER % 2) ? int(x - kcenter_) : int(x + 0.5 - kcenter_), ix_);
detail::SplineImageViewUnrollLoop1<ORDER>::exec(
(ORDER % 2) ? int(y - kcenter_) : int(y + 0.5 - kcenter_), iy_);
u_ = x - ix_[kcenter_];
v_ = y - iy_[kcenter_];
}
else
{
vigra_precondition(isValid(x,y),
"SplineImageView::calculateIndices(): coordinates out of range.");
int xCenter = (ORDER % 2) ?
(int)VIGRA_CSTD::floor(x) :
(int)VIGRA_CSTD::floor(x + 0.5);
int yCenter = (ORDER % 2) ?
(int)VIGRA_CSTD::floor(y) :
(int)VIGRA_CSTD::floor(y + 0.5);
if(x >= x1_)
{
for(int i = 0; i < ksize_; ++i)
ix_[i] = w1_ - vigra::abs(w1_ - xCenter - (i - kcenter_));
}
else
{
for(int i = 0; i < ksize_; ++i)
ix_[i] = vigra::abs(xCenter - (kcenter_ - i));
}
if(y >= y1_)
{
for(int i = 0; i < ksize_; ++i)
iy_[i] = h1_ - vigra::abs(h1_ - yCenter - (i - kcenter_));
}
else
{
for(int i = 0; i < ksize_; ++i)
iy_[i] = vigra::abs(yCenter - (kcenter_ - i));
}
u_ = x - xCenter;
v_ = y - yCenter;
}
x_ = x;
y_ = y;
}
template <int ORDER, class VALUETYPE>
void SplineImageView<ORDER, VALUETYPE>::coefficients(double t, double * const & c) const
{
t += kcenter_;
for(int i = 0; i<ksize_; ++i)
c[i] = k_(t-i);
}
template <int ORDER, class VALUETYPE>
void SplineImageView<ORDER, VALUETYPE>::derivCoefficients(double t,
unsigned int d, double * const & c) const
{
t += kcenter_;
for(int i = 0; i<ksize_; ++i)
c[i] = k_(t-i, d);
}
template <int ORDER, class VALUETYPE>
VALUETYPE SplineImageView<ORDER, VALUETYPE>::convolve() const
{
typedef typename NumericTraits<VALUETYPE>::RealPromote RealPromote;
RealPromote sum;
sum = RealPromote(
ky_[0]*detail::SplineImageViewUnrollLoop2<ORDER, RealPromote>::exec(kx_, image_.rowBegin(iy_[0]), ix_));
for(int j=1; j<ksize_; ++j)
{
sum += RealPromote(
ky_[j]*detail::SplineImageViewUnrollLoop2<ORDER, RealPromote>::exec(kx_, image_.rowBegin(iy_[j]), ix_));
}
return detail::RequiresExplicitCast<VALUETYPE>::cast(sum);
}
template <int ORDER, class VALUETYPE>
template <class Array>
void
SplineImageView<ORDER, VALUETYPE>::coefficientArray(double x, double y, Array & res) const
{
typename Spline::WeightMatrix & weights = Spline::weights();
double tmp[ksize_][ksize_];
calculateIndices(x, y);
for(int j=0; j<ksize_; ++j)
{
for(int i=0; i<ksize_; ++i)
{
tmp[i][j] = 0.0;
for(int k=0; k<ksize_; ++k)
{
tmp[i][j] += weights[i][k]*image_(ix_[k], iy_[j]);
}
}
}
res.resize(ksize_, ksize_);
for(int j=0; j<ksize_; ++j)
{
for(int i=0; i<ksize_; ++i)
{
res(i,j) = 0.0;
for(int k=0; k<ksize_; ++k)
{
res(i,j) += weights[j][k]*tmp[i][k];
}
}
}
}
template <int ORDER, class VALUETYPE>
VALUETYPE SplineImageView<ORDER, VALUETYPE>::operator()(double x, double y) const
{
calculateIndices(x, y);
coefficients(u_, kx_);
coefficients(v_, ky_);
return convolve();
}
template <int ORDER, class VALUETYPE>
VALUETYPE SplineImageView<ORDER, VALUETYPE>::operator()(double x, double y,
unsigned int dx, unsigned int dy) const
{
calculateIndices(x, y);
derivCoefficients(u_, dx, kx_);
derivCoefficients(v_, dy, ky_);
return convolve();
}
template <int ORDER, class VALUETYPE>
VALUETYPE SplineImageView<ORDER, VALUETYPE>::g2(double x, double y) const
{
return sq(dx(x,y)) + sq(dy(x,y));
}
template <int ORDER, class VALUETYPE>
VALUETYPE SplineImageView<ORDER, VALUETYPE>::g2x(double x, double y) const
{
return VALUETYPE(2.0)*(dx(x,y) * dxx(x,y) + dy(x,y) * dxy(x,y));
}
template <int ORDER, class VALUETYPE>
VALUETYPE SplineImageView<ORDER, VALUETYPE>::g2y(double x, double y) const
{
return VALUETYPE(2.0)*(dx(x,y) * dxy(x,y) + dy(x,y) * dyy(x,y));
}
template <int ORDER, class VALUETYPE>
VALUETYPE SplineImageView<ORDER, VALUETYPE>::g2xx(double x, double y) const
{
return VALUETYPE(2.0)*(sq(dxx(x,y)) + dx(x,y) * dx3(x,y) + sq(dxy(x,y)) + dy(x,y) * dxxy(x,y));
}
template <int ORDER, class VALUETYPE>
VALUETYPE SplineImageView<ORDER, VALUETYPE>::g2yy(double x, double y) const
{
return VALUETYPE(2.0)*(sq(dxy(x,y)) + dx(x,y) * dxyy(x,y) + sq(dyy(x,y)) + dy(x,y) * dy3(x,y));
}
template <int ORDER, class VALUETYPE>
VALUETYPE SplineImageView<ORDER, VALUETYPE>::g2xy(double x, double y) const
{
return VALUETYPE(2.0)*(dx(x,y) * dxxy(x,y) + dy(x,y) * dxyy(x,y) + dxy(x,y) * (dxx(x,y) + dyy(x,y)));
}
/********************************************************/
/* */
/* SplineImageView0 */
/* */
/********************************************************/
template <class VALUETYPE, class INTERNAL_INDEXER>
class SplineImageView0Base
{
typedef typename INTERNAL_INDEXER::value_type InternalValue;
public:
typedef VALUETYPE value_type;
typedef Size2D size_type;
typedef TinyVector<double, 2> difference_type;
enum StaticOrder { order = 0 };
public:
SplineImageView0Base(unsigned int w, unsigned int h)
: w_(w), h_(h)
{}
SplineImageView0Base(int w, int h, INTERNAL_INDEXER i)
: w_(w), h_(h), internalIndexer_(i)
{}
template <unsigned IntBits1, unsigned FractionalBits1,
unsigned IntBits2, unsigned FractionalBits2>
value_type unchecked(FixedPoint<IntBits1, FractionalBits1> x,
FixedPoint<IntBits2, FractionalBits2> y) const
{
return internalIndexer_(round(x), round(y));
}
template <unsigned IntBits1, unsigned FractionalBits1,
unsigned IntBits2, unsigned FractionalBits2>
value_type unchecked(FixedPoint<IntBits1, FractionalBits1> x,
FixedPoint<IntBits2, FractionalBits2> y,
unsigned int dx, unsigned int dy) const
{
if((dx != 0) || (dy != 0))
return NumericTraits<VALUETYPE>::zero();
return unchecked(x, y);
}
value_type unchecked(double x, double y) const
{
return internalIndexer_((int)(x + 0.5), (int)(y + 0.5));
}
value_type unchecked(double x, double y, unsigned int dx, unsigned int dy) const
{
if((dx != 0) || (dy != 0))
return NumericTraits<VALUETYPE>::zero();
return unchecked(x, y);
}
value_type operator()(double x, double y) const
{
int ix, iy;
if(x < 0.0)
{
ix = (int)(-x + 0.5);
vigra_precondition(ix <= (int)w_ - 1,
"SplineImageView::operator(): coordinates out of range.");
}
else
{
ix = (int)(x + 0.5);
if(ix >= (int)w_)
{
ix = 2*w_-2-ix;
vigra_precondition(ix >= 0,
"SplineImageView::operator(): coordinates out of range.");
}
}
if(y < 0.0)
{
iy = (int)(-y + 0.5);
vigra_precondition(iy <= (int)h_ - 1,
"SplineImageView::operator(): coordinates out of range.");
}
else
{
iy = (int)(y + 0.5);
if(iy >= (int)h_)
{
iy = 2*h_-2-iy;
vigra_precondition(iy >= 0,
"SplineImageView::operator(): coordinates out of range.");
}
}
return internalIndexer_(ix, iy);
}
value_type operator()(double x, double y, unsigned int dx, unsigned int dy) const
{
if((dx != 0) || (dy != 0))
return NumericTraits<VALUETYPE>::zero();
return operator()(x, y);
}
value_type dx(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dy(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxx(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxy(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dyy(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dx3(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dy3(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxxy(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxyy(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type operator()(difference_type const & d) const
{ return operator()(d[0], d[1]); }
value_type operator()(difference_type const & d, unsigned int dx, unsigned int dy) const
{ return operator()(d[0], d[1], dx, dy); }
value_type dx(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dy(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxx(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxy(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dyy(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dx3(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dy3(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxxy(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxyy(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2x(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2y(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2xx(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2xy(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2yy(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2x(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2y(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2xx(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2xy(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2yy(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
unsigned int width() const
{ return w_; }
unsigned int height() const
{ return h_; }
size_type size() const
{ return size_type(w_, h_); }
TinyVector<unsigned int, 2> shape() const
{ return TinyVector<unsigned int, 2>(w_, h_); }
template <class Array>
void coefficientArray(double x, double y, Array & res) const
{
res.resize(1, 1);
res(0, 0) = operator()(x,y);
}
bool isInsideX(double x) const
{
return x >= 0.0 && x <= width() - 1.0;
}
bool isInsideY(double y) const
{
return y >= 0.0 && y <= height() - 1.0;
}
bool isInside(double x, double y) const
{
return isInsideX(x) && isInsideY(y);
}
bool isValid(double x, double y) const
{
return x < 2.0*w_-2.0 && x > 1.0-w_ && y < 2.0*h_-2.0 && y > 1.0-h_;
}
bool sameFacet(double x0, double y0, double x1, double y1) const
{
x0 = VIGRA_CSTD::floor(x0 + 0.5);
y0 = VIGRA_CSTD::floor(y0 + 0.5);
x1 = VIGRA_CSTD::floor(x1 + 0.5);
y1 = VIGRA_CSTD::floor(y1 + 0.5);
return x0 == x1 && y0 == y1;
}
protected:
unsigned int w_, h_;
INTERNAL_INDEXER internalIndexer_;
};
/** \brief Create an image view for nearest-neighbor interpolation.
This class behaves like \ref vigra::SplineImageView<0, ...>, but one can pass
an additional template argument that determined the internal representation of the image.
If this is equal to the argument type passed in the constructor, the image is not copied.
By default, this works for \ref vigra::BasicImage, \ref vigra::BasicImageView,
\ref vigra::MultiArray<2, ...>, and \ref vigra::MultiArrayView<2, ...>.
*/
template <class VALUETYPE, class INTERNAL_TRAVERSER = typename BasicImage<VALUETYPE>::const_traverser>
class SplineImageView0
: public SplineImageView0Base<VALUETYPE, INTERNAL_TRAVERSER>
{
typedef SplineImageView0Base<VALUETYPE, INTERNAL_TRAVERSER> Base;
public:
typedef typename Base::value_type value_type;
typedef typename Base::size_type size_type;
typedef typename Base::difference_type difference_type;
enum StaticOrder { order = Base::order };
typedef BasicImage<VALUETYPE> InternalImage;
protected:
typedef typename IteratorTraits<INTERNAL_TRAVERSER>::mutable_iterator InternalTraverser;
typedef typename IteratorTraits<InternalTraverser>::DefaultAccessor InternalAccessor;
typedef typename IteratorTraits<INTERNAL_TRAVERSER>::const_iterator InternalConstTraverser;
typedef typename IteratorTraits<InternalConstTraverser>::DefaultAccessor InternalConstAccessor;
public:
/* when traverser and accessor types passed to the constructor are the same as the corresponding
internal types, we need not copy the image (speed up)
*/
SplineImageView0(InternalTraverser is, InternalTraverser iend, InternalAccessor sa)
: Base(iend.x - is.x, iend.y - is.y, is)
{}
SplineImageView0(triple<InternalTraverser, InternalTraverser, InternalAccessor> s)
: Base(s.second.x - s.first.x, s.second.y - s.first.y, s.first)
{}
SplineImageView0(InternalConstTraverser is, InternalConstTraverser iend, InternalConstAccessor sa)
: Base(iend.x - is.x, iend.y - is.y, is)
{}
SplineImageView0(triple<InternalConstTraverser, InternalConstTraverser, InternalConstAccessor> s)
: Base(s.second.x - s.first.x, s.second.y - s.first.y, s.first)
{}
template<class T, class SU>
SplineImageView0(MultiArrayView<2, T, SU> const & i)
: Base(i.shape(0), i.shape(1)),
image_(i.shape(0), i.shape(1))
{
for(unsigned int y=0; y<this->height(); ++y)
for(unsigned int x=0; x<this->width(); ++x)
image_(x,y) = detail::RequiresExplicitCast<VALUETYPE>::cast(i(x,y));
this->internalIndexer_ = image_.upperLeft();
}
template <class SrcIterator, class SrcAccessor>
SplineImageView0(SrcIterator is, SrcIterator iend, SrcAccessor sa)
: Base(iend.x - is.x, iend.y - is.y),
image_(iend - is)
{
copyImage(srcIterRange(is, iend, sa), destImage(image_));
this->internalIndexer_ = image_.upperLeft();
}
template <class SrcIterator, class SrcAccessor>
SplineImageView0(triple<SrcIterator, SrcIterator, SrcAccessor> s)
: Base(s.second.x - s.first.x, s.second.y - s.first.y),
image_(s.second - s.first)
{
copyImage(s, destImage(image_));
this->internalIndexer_ = image_.upperLeft();
}
InternalImage const & image() const
{ return image_; }
protected:
InternalImage image_;
};
template <class VALUETYPE, class StridedOrUnstrided>
class SplineImageView0<VALUETYPE, MultiArrayView<2, VALUETYPE, StridedOrUnstrided> >
: public SplineImageView0Base<VALUETYPE, MultiArrayView<2, VALUETYPE, StridedOrUnstrided> >
{
typedef SplineImageView0Base<VALUETYPE, MultiArrayView<2, VALUETYPE, StridedOrUnstrided> > Base;
public:
typedef typename Base::value_type value_type;
typedef typename Base::size_type size_type;
typedef typename Base::difference_type difference_type;
enum StaticOrder { order = Base::order };
typedef BasicImage<VALUETYPE> InternalImage;
protected:
typedef MultiArrayView<2, VALUETYPE, StridedOrUnstrided> InternalIndexer;
public:
/* when traverser and accessor types passed to the constructor are the same as the corresponding
internal types, we need not copy the image (speed up)
*/
SplineImageView0(InternalIndexer const & i)
: Base(i.shape(0), i.shape(1), i)
{}
template<class T, class SU>
SplineImageView0(MultiArrayView<2, T, SU> const & i)
: Base(i.shape(0), i.shape(1)),
image_(i.shape(0), i.shape(1))
{
for(unsigned int y=0; y<this->height(); ++y)
for(unsigned int x=0; x<this->width(); ++x)
image_(x,y) = detail::RequiresExplicitCast<VALUETYPE>::cast(i(x,y));
this->internalIndexer_ = InternalIndexer(typename InternalIndexer::difference_type(this->width(), this->height()),
image_.data());
}
template <class SrcIterator, class SrcAccessor>
SplineImageView0(SrcIterator is, SrcIterator iend, SrcAccessor sa)
: Base(iend.x - is.x, iend.y - is.y),
image_(iend-is)
{
copyImage(srcIterRange(is, iend, sa), destImage(image_));
this->internalIndexer_ = InternalIndexer(typename InternalIndexer::difference_type(this->width(), this->height()),
image_.data());
}
template <class SrcIterator, class SrcAccessor>
SplineImageView0(triple<SrcIterator, SrcIterator, SrcAccessor> s)
: Base(s.second.x - s.first.x, s.second.y - s.first.y),
image_(s.second - s.first)
{
copyImage(s, destImage(image_));
this->internalIndexer_ = InternalIndexer(typename InternalIndexer::difference_type(this->width(), this->height()),
image_.data());
}
InternalImage const & image() const
{ return image_; }
protected:
InternalImage image_;
};
template <class VALUETYPE>
class SplineImageView<0, VALUETYPE>
: public SplineImageView0<VALUETYPE>
{
typedef SplineImageView0<VALUETYPE> Base;
public:
typedef typename Base::value_type value_type;
typedef typename Base::size_type size_type;
typedef typename Base::difference_type difference_type;
enum StaticOrder { order = Base::order };
typedef typename Base::InternalImage InternalImage;
protected:
typedef typename Base::InternalTraverser InternalTraverser;
typedef typename Base::InternalAccessor InternalAccessor;
typedef typename Base::InternalConstTraverser InternalConstTraverser;
typedef typename Base::InternalConstAccessor InternalConstAccessor;
public:
/* when traverser and accessor types passed to the constructor are the same as the corresponding
internal types, we need not copy the image (speed up)
*/
SplineImageView(InternalTraverser is, InternalTraverser iend, InternalAccessor sa, bool /* unused */ = false)
: Base(is, iend, sa)
{}
SplineImageView(triple<InternalTraverser, InternalTraverser, InternalAccessor> s, bool /* unused */ = false)
: Base(s)
{}
SplineImageView(InternalConstTraverser is, InternalConstTraverser iend, InternalConstAccessor sa, bool /* unused */ = false)
: Base(is, iend, sa)
{}
SplineImageView(triple<InternalConstTraverser, InternalConstTraverser, InternalConstAccessor> s, bool /* unused */ = false)
: Base(s)
{}
template <class SrcIterator, class SrcAccessor>
SplineImageView(SrcIterator is, SrcIterator iend, SrcAccessor sa, bool /* unused */ = false)
: Base(is, iend, sa)
{
copyImage(srcIterRange(is, iend, sa), destImage(this->image_));
}
template <class SrcIterator, class SrcAccessor>
SplineImageView(triple<SrcIterator, SrcIterator, SrcAccessor> s, bool /* unused */ = false)
: Base(s)
{
copyImage(s, destImage(this->image_));
}
};
/********************************************************/
/* */
/* SplineImageView1 */
/* */
/********************************************************/
template <class VALUETYPE, class INTERNAL_INDEXER>
class SplineImageView1Base
{
typedef typename INTERNAL_INDEXER::value_type InternalValue;
public:
typedef VALUETYPE value_type;
typedef Size2D size_type;
typedef TinyVector<double, 2> difference_type;
enum StaticOrder { order = 1 };
public:
SplineImageView1Base(unsigned int w, unsigned int h)
: w_(w), h_(h)
{}
SplineImageView1Base(int w, int h, INTERNAL_INDEXER i)
: w_(w), h_(h), internalIndexer_(i)
{}
template <unsigned IntBits1, unsigned FractionalBits1,
unsigned IntBits2, unsigned FractionalBits2>
value_type unchecked(FixedPoint<IntBits1, FractionalBits1> x,
FixedPoint<IntBits2, FractionalBits2> y) const
{
int ix = floor(x);
FixedPoint<0, FractionalBits1> tx = frac(x - FixedPoint<IntBits1, FractionalBits1>(ix));
FixedPoint<0, FractionalBits1> dtx = dual_frac(tx);
if(ix == (int)w_ - 1)
{
--ix;
tx.value = FixedPoint<0, FractionalBits1>::ONE;
dtx.value = 0;
}
int iy = floor(y);
FixedPoint<0, FractionalBits2> ty = frac(y - FixedPoint<IntBits2, FractionalBits2>(iy));
FixedPoint<0, FractionalBits2> dty = dual_frac(ty);
if(iy == (int)h_ - 1)
{
--iy;
ty.value = FixedPoint<0, FractionalBits2>::ONE;
dty.value = 0;
}
return fixed_point_cast<value_type>(
dty*(dtx*fixedPoint(internalIndexer_(ix,iy)) +
tx*fixedPoint(internalIndexer_(ix+1,iy))) +
ty *(dtx*fixedPoint(internalIndexer_(ix,iy+1)) +
tx*fixedPoint(internalIndexer_(ix+1,iy+1))));
}
template <unsigned IntBits1, unsigned FractionalBits1,
unsigned IntBits2, unsigned FractionalBits2>
value_type unchecked(FixedPoint<IntBits1, FractionalBits1> x,
FixedPoint<IntBits2, FractionalBits2> y,
unsigned int dx, unsigned int dy) const
{
int ix = floor(x);
FixedPoint<0, FractionalBits1> tx = frac(x - FixedPoint<IntBits1, FractionalBits1>(ix));
FixedPoint<0, FractionalBits1> dtx = dual_frac(tx);
if(ix == (int)w_ - 1)
{
--ix;
tx.value = FixedPoint<0, FractionalBits1>::ONE;
dtx.value = 0;
}
int iy = floor(y);
FixedPoint<0, FractionalBits2> ty = frac(y - FixedPoint<IntBits2, FractionalBits2>(iy));
FixedPoint<0, FractionalBits2> dty = dual_frac(ty);
if(iy == (int)h_ - 1)
{
--iy;
ty.value = FixedPoint<0, FractionalBits2>::ONE;
dty.value = 0;
}
switch(dx)
{
case 0:
switch(dy)
{
case 0:
return fixed_point_cast<value_type>(
dty*(dtx*fixedPoint(internalIndexer_(ix,iy)) +
tx*fixedPoint(internalIndexer_(ix+1,iy))) +
ty *(dtx*fixedPoint(internalIndexer_(ix,iy+1)) +
tx*fixedPoint(internalIndexer_(ix+1,iy+1))));
case 1:
return fixed_point_cast<value_type>(
(dtx*fixedPoint(internalIndexer_(ix,iy+1)) + tx*fixedPoint(internalIndexer_(ix+1,iy+1))) -
(dtx*fixedPoint(internalIndexer_(ix,iy)) + tx*fixedPoint(internalIndexer_(ix+1,iy))));
default:
return NumericTraits<VALUETYPE>::zero();
}
case 1:
switch(dy)
{
case 0:
return fixed_point_cast<value_type>(
dty*(fixedPoint(internalIndexer_(ix+1,iy)) - fixedPoint(internalIndexer_(ix,iy))) +
ty *(fixedPoint(internalIndexer_(ix+1,iy+1)) - fixedPoint(internalIndexer_(ix,iy+1))));
case 1:
return detail::RequiresExplicitCast<value_type>::cast(
(internalIndexer_(ix+1,iy+1) - internalIndexer_(ix,iy+1)) -
(internalIndexer_(ix+1,iy) - internalIndexer_(ix,iy)));
default:
return NumericTraits<VALUETYPE>::zero();
}
default:
return NumericTraits<VALUETYPE>::zero();
}
}
value_type unchecked(double x, double y) const
{
int ix = (int)std::floor(x);
if(ix == (int)w_ - 1)
--ix;
double tx = x - ix;
int iy = (int)std::floor(y);
if(iy == (int)h_ - 1)
--iy;
double ty = y - iy;
return NumericTraits<value_type>::fromRealPromote(
(1.0-ty)*((1.0-tx)*internalIndexer_(ix,iy) + tx*internalIndexer_(ix+1,iy)) +
ty *((1.0-tx)*internalIndexer_(ix,iy+1) + tx*internalIndexer_(ix+1,iy+1)));
}
value_type unchecked(double x, double y, unsigned int dx, unsigned int dy) const
{
int ix = (int)std::floor(x);
if(ix == (int)w_ - 1)
--ix;
double tx = x - ix;
int iy = (int)std::floor(y);
if(iy == (int)h_ - 1)
--iy;
double ty = y - iy;
switch(dx)
{
case 0:
switch(dy)
{
case 0:
return detail::RequiresExplicitCast<value_type>::cast(
(1.0-ty)*((1.0-tx)*internalIndexer_(ix,iy) + tx*internalIndexer_(ix+1,iy)) +
ty *((1.0-tx)*internalIndexer_(ix,iy+1) + tx*internalIndexer_(ix+1,iy+1)));
case 1:
return detail::RequiresExplicitCast<value_type>::cast(
((1.0-tx)*internalIndexer_(ix,iy+1) + tx*internalIndexer_(ix+1,iy+1)) -
((1.0-tx)*internalIndexer_(ix,iy) + tx*internalIndexer_(ix+1,iy)));
default:
return NumericTraits<VALUETYPE>::zero();
}
case 1:
switch(dy)
{
case 0:
return detail::RequiresExplicitCast<value_type>::cast(
(1.0-ty)*(internalIndexer_(ix+1,iy) - internalIndexer_(ix,iy)) +
ty *(internalIndexer_(ix+1,iy+1) - internalIndexer_(ix,iy+1)));
case 1:
return detail::RequiresExplicitCast<value_type>::cast(
(internalIndexer_(ix+1,iy+1) - internalIndexer_(ix,iy+1)) -
(internalIndexer_(ix+1,iy) - internalIndexer_(ix,iy)));
default:
return NumericTraits<VALUETYPE>::zero();
}
default:
return NumericTraits<VALUETYPE>::zero();
}
}
value_type operator()(double x, double y) const
{
return operator()(x, y, 0, 0);
}
value_type operator()(double x, double y, unsigned int dx, unsigned int dy) const
{
value_type mul = NumericTraits<value_type>::one();
if(x < 0.0)
{
x = -x;
vigra_precondition(x <= w_ - 1.0,
"SplineImageView::operator(): coordinates out of range.");
if(dx % 2)
mul = -mul;
}
else if(x > w_ - 1.0)
{
x = 2.0*w_-2.0-x;
vigra_precondition(x >= 0.0,
"SplineImageView::operator(): coordinates out of range.");
if(dx % 2)
mul = -mul;
}
if(y < 0.0)
{
y = -y;
vigra_precondition(y <= h_ - 1.0,
"SplineImageView::operator(): coordinates out of range.");
if(dy % 2)
mul = -mul;
}
else if(y > h_ - 1.0)
{
y = 2.0*h_-2.0-y;
vigra_precondition(y >= 0.0,
"SplineImageView::operator(): coordinates out of range.");
if(dy % 2)
mul = -mul;
}
return mul*unchecked(x, y, dx, dy);
}
value_type dx(double x, double y) const
{ return operator()(x, y, 1, 0); }
value_type dy(double x, double y) const
{ return operator()(x, y, 0, 1); }
value_type dxx(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxy(double x, double y) const
{ return operator()(x, y, 1, 1); }
value_type dyy(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dx3(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dy3(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxxy(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxyy(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type operator()(difference_type const & d) const
{ return operator()(d[0], d[1]); }
value_type operator()(difference_type const & d, unsigned int dx, unsigned int dy) const
{ return operator()(d[0], d[1], dx, dy); }
value_type dx(difference_type const & d) const
{ return operator()(d[0], d[1], 1, 0); }
value_type dy(difference_type const & d) const
{ return operator()(d[0], d[1], 0, 1); }
value_type dxx(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxy(difference_type const & d) const
{ return operator()(d[0], d[1], 1, 1); }
value_type dyy(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dx3(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dy3(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxxy(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type dxyy(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2(double x, double y) const
{ return sq(dx(x,y)) + sq(dy(x,y)); }
value_type g2x(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2y(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2xx(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2xy(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2yy(double x, double y) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2(difference_type const & d) const
{ return g2(d[0], d[1]); }
value_type g2x(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2y(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2xx(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2xy(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
value_type g2yy(difference_type const & d) const
{ return NumericTraits<VALUETYPE>::zero(); }
unsigned int width() const
{ return w_; }
unsigned int height() const
{ return h_; }
size_type size() const
{ return size_type(w_, h_); }
TinyVector<unsigned int, 2> shape() const
{ return TinyVector<unsigned int, 2>(w_, h_); }
template <class Array>
void coefficientArray(double x, double y, Array & res) const;
void calculateIndices(double x, double y, int & ix, int & iy, int & ix1, int & iy1) const;
bool isInsideX(double x) const
{
return x >= 0.0 && x <= width() - 1.0;
}
bool isInsideY(double y) const
{
return y >= 0.0 && y <= height() - 1.0;
}
bool isInside(double x, double y) const
{
return isInsideX(x) && isInsideY(y);
}
bool isValid(double x, double y) const
{
return x < 2.0*w_-2.0 && x > 1.0-w_ && y < 2.0*h_-2.0 && y > 1.0-h_;
}
bool sameFacet(double x0, double y0, double x1, double y1) const
{
x0 = VIGRA_CSTD::floor(x0);
y0 = VIGRA_CSTD::floor(y0);
x1 = VIGRA_CSTD::floor(x1);
y1 = VIGRA_CSTD::floor(y1);
return x0 == x1 && y0 == y1;
}
protected:
unsigned int w_, h_;
INTERNAL_INDEXER internalIndexer_;
};
template <class VALUETYPE, class INTERNAL_INDEXER>
template <class Array>
void SplineImageView1Base<VALUETYPE, INTERNAL_INDEXER>::coefficientArray(double x, double y, Array & res) const
{
int ix, iy, ix1, iy1;
calculateIndices(x, y, ix, iy, ix1, iy1);
res.resize(2, 2);
res(0,0) = internalIndexer_(ix,iy);
res(1,0) = internalIndexer_(ix1,iy) - internalIndexer_(ix,iy);
res(0,1) = internalIndexer_(ix,iy1) - internalIndexer_(ix,iy);
res(1,1) = internalIndexer_(ix,iy) - internalIndexer_(ix1,iy) -
internalIndexer_(ix,iy1) + internalIndexer_(ix1,iy1);
}
template <class VALUETYPE, class INTERNAL_INDEXER>
void SplineImageView1Base<VALUETYPE, INTERNAL_INDEXER>::calculateIndices(double x, double y, int & ix, int & iy, int & ix1, int & iy1) const
{
if(x < 0.0)
{
x = -x;
vigra_precondition(x <= w_ - 1.0,
"SplineImageView::calculateIndices(): coordinates out of range.");
ix = (int)VIGRA_CSTD::ceil(x);
ix1 = ix - 1;
}
else if(x >= w_ - 1.0)
{
x = 2.0*w_-2.0-x;
vigra_precondition(x > 0.0,
"SplineImageView::calculateIndices(): coordinates out of range.");
ix = (int)VIGRA_CSTD::ceil(x);
ix1 = ix - 1;
}
else
{
ix = (int)VIGRA_CSTD::floor(x);
ix1 = ix + 1;
}
if(y < 0.0)
{
y = -y;
vigra_precondition(y <= h_ - 1.0,
"SplineImageView::calculateIndices(): coordinates out of range.");
iy = (int)VIGRA_CSTD::ceil(y);
iy1 = iy - 1;
}
else if(y >= h_ - 1.0)
{
y = 2.0*h_-2.0-y;
vigra_precondition(y > 0.0,
"SplineImageView::calculateIndices(): coordinates out of range.");
iy = (int)VIGRA_CSTD::ceil(y);
iy1 = iy - 1;
}
else
{
iy = (int)VIGRA_CSTD::floor(y);
iy1 = iy + 1;
}
}
/** \brief Create an image view for bi-linear interpolation.
This class behaves like \ref vigra::SplineImageView<1, ...>, but one can pass
an additional template argument that determined the internal representation of the image.
If this is equal to the argument type passed in the constructor, the image is not copied.
By default, this works for \ref vigra::BasicImage, \ref vigra::BasicImageView,
\ref vigra::MultiArray<2, ...>, and \ref vigra::MultiArrayView<2, ...>.
In addition to the function provided by \ref vigra::SplineImageView, there are functions
<tt>unchecked(x,y)</tt> and <tt>unchecked(x,y, xorder, yorder)</tt> which improve speed by
not applying bounds checking and reflective border treatment (<tt>isInside(x, y)</tt> must
be <tt>true</tt>), but otherwise behave identically to their checked counterparts.
In addition, <tt>x</tt> and <tt>y</tt> can have type \ref vigra::FixedPoint instead of
<tt>double</tt>.
*/
template <class VALUETYPE, class INTERNAL_TRAVERSER = typename BasicImage<VALUETYPE>::const_traverser>
class SplineImageView1
: public SplineImageView1Base<VALUETYPE, INTERNAL_TRAVERSER>
{
typedef SplineImageView1Base<VALUETYPE, INTERNAL_TRAVERSER> Base;
public:
typedef typename Base::value_type value_type;
typedef typename Base::size_type size_type;
typedef typename Base::difference_type difference_type;
enum StaticOrder { order = Base::order };
typedef BasicImage<VALUETYPE> InternalImage;
protected:
typedef typename IteratorTraits<INTERNAL_TRAVERSER>::mutable_iterator InternalTraverser;
typedef typename IteratorTraits<InternalTraverser>::DefaultAccessor InternalAccessor;
typedef typename IteratorTraits<INTERNAL_TRAVERSER>::const_iterator InternalConstTraverser;
typedef typename IteratorTraits<InternalConstTraverser>::DefaultAccessor InternalConstAccessor;
public:
/* when traverser and accessor types passed to the constructor are the same as the corresponding
internal types, we need not copy the image (speed up)
*/
SplineImageView1(InternalTraverser is, InternalTraverser iend, InternalAccessor sa)
: Base(iend.x - is.x, iend.y - is.y, is)
{}
SplineImageView1(triple<InternalTraverser, InternalTraverser, InternalAccessor> s)
: Base(s.second.x - s.first.x, s.second.y - s.first.y, s.first)
{}
SplineImageView1(InternalConstTraverser is, InternalConstTraverser iend, InternalConstAccessor sa)
: Base(iend.x - is.x, iend.y - is.y, is)
{}
SplineImageView1(triple<InternalConstTraverser, InternalConstTraverser, InternalConstAccessor> s)
: Base(s.second.x - s.first.x, s.second.y - s.first.y, s.first)
{}
template<class T, class SU>
SplineImageView1(MultiArrayView<2, T, SU> const & i)
: Base(i.shape(0), i.shape(1)),
image_(i.shape(0), i.shape(1))
{
for(unsigned int y=0; y<this->height(); ++y)
for(unsigned int x=0; x<this->width(); ++x)
image_(x,y) = detail::RequiresExplicitCast<VALUETYPE>::cast(i(x,y));
this->internalIndexer_ = image_.upperLeft();
}
template <class SrcIterator, class SrcAccessor>
SplineImageView1(SrcIterator is, SrcIterator iend, SrcAccessor sa)
: Base(iend.x - is.x, iend.y - is.y),
image_(iend - is)
{
copyImage(srcIterRange(is, iend, sa), destImage(image_));
this->internalIndexer_ = image_.upperLeft();
}
template <class SrcIterator, class SrcAccessor>
SplineImageView1(triple<SrcIterator, SrcIterator, SrcAccessor> s)
: Base(s.second.x - s.first.x, s.second.y - s.first.y),
image_(s.second - s.first)
{
copyImage(s, destImage(image_));
this->internalIndexer_ = image_.upperLeft();
}
InternalImage const & image() const
{ return image_; }
protected:
InternalImage image_;
};
template <class VALUETYPE, class StridedOrUnstrided>
class SplineImageView1<VALUETYPE, MultiArrayView<2, VALUETYPE, StridedOrUnstrided> >
: public SplineImageView1Base<VALUETYPE, MultiArrayView<2, VALUETYPE, StridedOrUnstrided> >
{
typedef SplineImageView1Base<VALUETYPE, MultiArrayView<2, VALUETYPE, StridedOrUnstrided> > Base;
public:
typedef typename Base::value_type value_type;
typedef typename Base::size_type size_type;
typedef typename Base::difference_type difference_type;
enum StaticOrder { order = Base::order };
typedef BasicImage<VALUETYPE> InternalImage;
protected:
typedef MultiArrayView<2, VALUETYPE, StridedOrUnstrided> InternalIndexer;
public:
/* when traverser and accessor types passed to the constructor are the same as the corresponding
internal types, we need not copy the image (speed up)
*/
SplineImageView1(InternalIndexer const & i)
: Base(i.shape(0), i.shape(1), i)
{}
template<class T, class SU>
SplineImageView1(MultiArrayView<2, T, SU> const & i)
: Base(i.shape(0), i.shape(1)),
image_(i.shape(0), i.shape(1))
{
for(unsigned int y=0; y<this->height(); ++y)
for(unsigned int x=0; x<this->width(); ++x)
image_(x,y) = detail::RequiresExplicitCast<VALUETYPE>::cast(i(x,y));
this->internalIndexer_ = InternalIndexer(typename InternalIndexer::difference_type(this->width(), this->height()),
image_.data());
}
template <class SrcIterator, class SrcAccessor>
SplineImageView1(SrcIterator is, SrcIterator iend, SrcAccessor sa)
: Base(iend.x - is.x, iend.y - is.y),
image_(iend-is)
{
copyImage(srcIterRange(is, iend, sa), destImage(image_));
this->internalIndexer_ = InternalIndexer(typename InternalIndexer::difference_type(this->width(), this->height()),
image_.data());
}
template <class SrcIterator, class SrcAccessor>
SplineImageView1(triple<SrcIterator, SrcIterator, SrcAccessor> s)
: Base(s.second.x - s.first.x, s.second.y - s.first.y),
image_(s.second - s.first)
{
copyImage(s, destImage(image_));
this->internalIndexer_ = InternalIndexer(typename InternalIndexer::difference_type(this->width(), this->height()),
image_.data());
}
InternalImage const & image() const
{ return image_; }
protected:
InternalImage image_;
};
template <class VALUETYPE>
class SplineImageView<1, VALUETYPE>
: public SplineImageView1<VALUETYPE>
{
typedef SplineImageView1<VALUETYPE> Base;
public:
typedef typename Base::value_type value_type;
typedef typename Base::size_type size_type;
typedef typename Base::difference_type difference_type;
enum StaticOrder { order = Base::order };
typedef typename Base::InternalImage InternalImage;
protected:
typedef typename Base::InternalTraverser InternalTraverser;
typedef typename Base::InternalAccessor InternalAccessor;
typedef typename Base::InternalConstTraverser InternalConstTraverser;
typedef typename Base::InternalConstAccessor InternalConstAccessor;
public:
/* when traverser and accessor types passed to the constructor are the same as the corresponding
internal types, we need not copy the image (speed up)
*/
SplineImageView(InternalTraverser is, InternalTraverser iend, InternalAccessor sa, bool /* unused */ = false)
: Base(is, iend, sa)
{}
SplineImageView(triple<InternalTraverser, InternalTraverser, InternalAccessor> s, bool /* unused */ = false)
: Base(s)
{}
SplineImageView(InternalConstTraverser is, InternalConstTraverser iend, InternalConstAccessor sa, bool /* unused */ = false)
: Base(is, iend, sa)
{}
SplineImageView(triple<InternalConstTraverser, InternalConstTraverser, InternalConstAccessor> s, bool /* unused */ = false)
: Base(s)
{}
template <class SrcIterator, class SrcAccessor>
SplineImageView(SrcIterator is, SrcIterator iend, SrcAccessor sa, bool /* unused */ = false)
: Base(is, iend, sa)
{
copyImage(srcIterRange(is, iend, sa), destImage(this->image_));
}
template <class SrcIterator, class SrcAccessor>
SplineImageView(triple<SrcIterator, SrcIterator, SrcAccessor> s, bool /* unused */ = false)
: Base(s)
{
copyImage(s, destImage(this->image_));
}
};
} // namespace vigra
#endif /* VIGRA_SPLINEIMAGEVIEW_HXX */
|