/usr/include/vigra/iteratortraits.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 | /************************************************************************/
/* */
/* Copyright 1998-2002 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_ITERATORTRAITS_HXX
#define VIGRA_ITERATORTRAITS_HXX
#include "accessor.hxx"
#include "imageiteratoradapter.hxx"
namespace vigra {
/** \addtogroup ImageIterators
*/
//@{
/** \brief Export associated information for each image iterator.
The IteratorTraits class contains the following fields:
\code
template <class T>
struct IteratorTraits
{
typedef T Iterator;
typedef Iterator iterator;
typedef typename iterator::iterator_category iterator_category;
typedef typename iterator::value_type value_type;
typedef typename iterator::reference reference;
typedef typename iterator::index_reference index_reference;
typedef typename iterator::pointer pointer;
typedef typename iterator::difference_type difference_type;
typedef typename iterator::row_iterator row_iterator;
typedef typename iterator::column_iterator column_iterator;
typedef typename
AccessorTraits<value_type>::default_accessor DefaultAccessor;
typedef DefaultAccessor default_accessor;
typedef VigraTrueType/VigraFalseType hasConstantStrides;
};
\endcode
By (partially) specializing this template for an iterator class
the defaults given above can be changed as appropriate. For example, iterators
for rgb images are associated with <TT>RGBAccessor<value_type></TT>
instead of <TT>StandardAccessor<value_type></TT>. To get the accessor
associated with a given iterator, use code like this:
\code
template <class Iterator>
void foo(Iterator i)
{
typedef typename IteratorTraits<Iterator>::DefaultAccessor Accessor;
Accessor a;
...
}
\endcode
This technique is, for example, used by the
\ref IteratorBasedArgumentObjectFactories. The possibility to retrieve the default accessor by means of a traits
class is especially important since this information is not
contained in the iterator directly.
The member <tt>hasConstantStrides</tt> is useful for certain
optimizations: it helps to decide whether we can replace iterator
operations such as <tt>iter++</tt> or <tt>iter += n</tt> with
corresponding pointer operations (which may be faster), where
the pointer is obtained as the address of iterator's pointee
(the object the iterator currently refers to).
This flag would be <tt>VigraFalseType</tt> for a
<tt>std::list<int>::iterator</tt>, but is <tt>VigraTrueType</tt>
for most VIGRA iterators.
<b>\#include</b> \<vigra/iteratortraits.hxx\>
Namespace: vigra
*/
template <class T>
struct IteratorTraits
{
typedef T Iterator;
typedef Iterator iterator;
typedef typename iterator::iterator_category iterator_category;
typedef typename iterator::value_type value_type;
typedef typename iterator::reference reference;
typedef typename iterator::index_reference index_reference;
typedef typename iterator::pointer pointer;
typedef typename iterator::difference_type difference_type;
typedef typename iterator::row_iterator row_iterator;
typedef typename iterator::column_iterator column_iterator;
typedef typename
AccessorTraits<value_type>::default_accessor DefaultAccessor;
typedef DefaultAccessor default_accessor;
// default: disable the constant strides optimization
typedef VigraFalseType hasConstantStrides;
};
template <class T>
struct IteratorTraitsBase
{
typedef T Iterator;
typedef Iterator iterator;
typedef typename iterator::iterator_category iterator_category;
typedef typename iterator::value_type value_type;
typedef typename iterator::reference reference;
typedef typename iterator::index_reference index_reference;
typedef typename iterator::pointer pointer;
typedef typename iterator::difference_type difference_type;
typedef typename iterator::row_iterator row_iterator;
typedef typename iterator::column_iterator column_iterator;
};
//@}
/***********************************************************/
/** \page ArgumentObjectFactories Argument Object Factories
Factory functions to create argument objects which simplify long argument lists.
<UL style="list-style-image:url(documents/bullet.gif)">
<LI> \ref ImageBasedArgumentObjectFactories
<LI> \ref MultiArrayBasedArgumentObjectFactories
<LI> \ref IteratorBasedArgumentObjectFactories
</UL>
Long argument lists provide for greater flexibility of functions,
but they are also tedious and error prone, when we don't need
the flexibility. Thus, we define argument objects which
automatically provide reasonable defaults for those arguments that we
didn't specify explicitly.
The argument objects are created via a number of factory functions.
Since these functions have descriptive names, they also serve
to improve readability: the name of each factory tells te purpose of its
argument object.
Consider the following example. Without argument objects we had to
write something like this (cf. \ref copyImageIf()):
\code
vigra::BImage img1, img2, img3;
// fill img1 and img2 ...
vigra::copyImageIf(img1.upperLeft(), img1.lowerRight(), img1.accessor(),
img2.upperLeft(), img2.accessor(),
img3.upperLeft(), img3.accessor());
\endcode
Using the argument object factories, this becomes much shorter and
more readable:
\code
vigra::copyImageIf(srcImageRange(img1),
maskImage(img2),
destImage(img3));
\endcode
The names of the factories clearly tell which image is source, mask,
and destination. In addition, the suffix <TT>Range</TT> must be used
for those argument objects that need to specify the lower right
corner of the region of interest. Typically, this is only the first
source argument, but sometimes the first destiniation argument must
also contain a range.
The factory functions come in two flavours: Iterator based and
image based factories. Above we have seen the image based variant.
The iterator based variant would look like this:
\code
vigra::copyImageIf(srcIterRange(img1.upperLeft(), img1.lowerRight()),
maskIter(img2.upperLeft()),
destIter(img3.upperLeft()));
\endcode
These factory functions contain the word <TT>Iter</TT> instead of the word
<TT>Image</TT>, They would normally be used if we couldn't access the
images (for example, within a function which got passed iterators)
or if we didn't want to operate on the entire image. The default
accessor is obtained via \ref vigra::IteratorTraits.
All factory functions also allow to specify accessors explicitly. This
is useful if we can't use the default accessor. This variant looks
like this:
\code
vigra::copyImageIf(srcImageRange(img1),
maskImage(img2, MaskPredicateAccessor()),
destImage(img3));
\endcode
or
\code
vigra::copyImageIf(srcIterRange(img1.upperLeft(), img1.lowerRight()),
maskIter(img2.upperLeft(), MaskPredicateAccessor()),
destIter(img3.upperLeft()));
\endcode
All versions can be mixed freely within one expression.
Technically, the argument objects are simply defined as
pairs and triples of iterators and accessor so that all algorithms
should declare a call interface version based on pairs and triples
(see for example \ref copyImageIf()).
\section ImageBasedArgumentObjectFactories Image Based Argument Object Factories
<b>Include:</b> automatically included with the image classes<br>
Namespace: vigra
These factories can be used to create argument objects when we
are given instances or subclasses of \ref vigra::BasicImage (see
\ref StandardImageTypes for instances defined per default).
These factory functions access <TT>img.upperLeft()</TT>,
<TT>img.lowerRight()</TT>, and <TT>img.accessor()</TT> to obtain the iterators
and accessor for the given image (unless the accessor is
given explicitly). The following factory functions are provided:
<table>
<tr><th bgcolor="#f0e0c0" colspan=2 align=left>
<TT>\ref vigra::BasicImage "vigra::BasicImage<SomeType>" img;</TT> or <br>
<TT>\ref vigra::BasicImageView "vigra::BasicImageView<SomeType>" img;</TT>
</th>
</tr>
<tr><td>
<TT>srcImageRange(img)</TT>
</td><td>
create argument object containing upper left, lower right, and
default accessor of source image
</td></tr>
<tr><td>
<TT>srcImageRange(img, Rect2D(...))</TT>
</td><td>
create argument object containing the ROI specified by <tt>\ref vigra::Rect2D</tt> and
default accessor of source image
</td></tr>
<tr><td>
<TT>srcImageRange(img, SomeAccessor())</TT>
</td><td>
create argument object containing upper left, lower right
of source image, and given accessor
</td></tr>
<tr><td>
<TT>srcImageRange(img, Rect2D(...), SomeAccessor())</TT>
</td><td>
create argument object containing the ROI specified by <tt>\ref vigra::Rect2D</tt> and
of source image, and given accessor
</td></tr>
<tr><td>
<TT>srcImage(img)</TT>
</td><td>
create argument object containing upper left, and
default accessor of source image
</td></tr>
<tr><td>
<TT>srcImage(img, Point2D(...))</TT>
</td><td>
create argument object with upper left at point given by <tt>\ref vigra::Point2D</tt>, and
default accessor of source image
</td></tr>
<tr><td>
<TT>srcImage(img, SomeAccessor())</TT>
</td><td>
create argument object containing upper left
of source image, and given accessor
</td></tr>
<tr><td>
<TT>srcImage(img, Point2D(...), SomeAccessor())</TT>
</td><td>
create argument object with upper left at point given by <tt>\ref vigra::Point2D</tt> of source image,
and given accessor
</td></tr>
<tr><td>
<TT>maskImage(img)</TT>
</td><td>
create argument object containing upper left, and
default accessor of mask image
</td></tr>
<tr><td>
<TT>maskImage(img, Point2D(...))</TT>
</td><td>
create argument object with upper left at point given by <tt>\ref vigra::Point2D</tt>, and
default accessor of mask image
</td></tr>
<tr><td>
<TT>maskImage(img, SomeAccessor())</TT>
</td><td>
create argument object containing upper left
of mask image, and given accessor
</td></tr>
<tr><td>
<TT>maskImage(img, Point2D(...), SomeAccessor())</TT>
</td><td>
create argument object with upper left at point given by <tt>\ref vigra::Point2D</tt> of mask image,
and given accessor
</td></tr>
<tr><td>
<TT>destImageRange(img)</TT>
</td><td>
create argument object containing upper left, lower right, and
default accessor of destination image
</td></tr>
<tr><td>
<TT>destImageRange(img, Rect2D(...))</TT>
</td><td>
create argument object containing the ROI specified by <tt>\ref vigra::Rect2D</tt> and
default accessor of destination image
</td></tr>
<tr><td>
<TT>destImageRange(img, SomeAccessor())</TT>
</td><td>
create argument object containing upper left, lower right
of destination image, and given accessor
</td></tr>
<tr><td>
<TT>destImageRange(img, Rect2D(...), SomeAccessor())</TT>
</td><td>
create argument object containing the ROI specified by <tt>\ref vigra::Rect2D</tt>
of destination image, and given accessor
</td></tr>
<tr><td>
<TT>destImage(img)</TT>
</td><td>
create argument object containing upper left, and
default accessor of destination image
</td></tr>
<tr><td>
<TT>destImage(img, Point2D(...))</TT>
</td><td>
create argument object with upper left at point given by <tt>\ref vigra::Point2D</tt>, and
default accessor of destination image
</td></tr>
<tr><td>
<TT>destImage(img, SomeAccessor())</TT>
</td><td>
create argument object containing upper left
of destination image, and given accessor
</td></tr>
<tr><td>
<TT>destImage(img, Point2D(...), SomeAccessor())</TT>
</td><td>
create argument object with upper left at point given by <tt>\ref vigra::Point2D</tt> of destination image,
and given accessor
</td></tr>
</table>
\section MultiArrayBasedArgumentObjectFactories MultiArrayView Based Argument Object Factories
<b>Include:</b> automatically included with
\<vigra/multi_array.hxx\><br>
Namespace: vigra
These factories can be used to create argument objects when we
are given instances or subclasses of \ref vigra::MultiArrayView.
These factory functions access <TT>array.traverser_begin()</TT>,
<TT>array.traverser_end()</TT> to obtain the iterators. If no accessor is
given, they use the <tt>AccessorTraits<T></tt> to determine the default
accessor associated with the array's value type <tt>T</tt>.
The following factory functions are provided:
<table>
<tr><th bgcolor="#f0e0c0" colspan=2 align=left>
<TT>\ref vigra::MultiArrayView "vigra::MultiArrayView<N, SomeType>" img;</TT>
</th>
</tr>
<tr><td>
<TT>srcMultiArrayRange(img)</TT>
</td><td>
create argument object containing a \ref vigra::MultiIterator
marking the begin of the array, a shape object giving the desired
shape of the array (possibly a subarray) and the default const accessor for
<tt>SomeType</tt>
</td></tr>
<tr><td>
<TT>srcMultiArrayRange(img, SomeAccessor())</TT>
</td><td>
create argument object containing a \ref vigra::MultiIterator
marking the begin of the array, a shape object giving the desired
shape of the array (possibly a subarray) and the given accessor
</td></tr>
<tr><td>
<TT>srcMultiArray(img)</TT>
</td><td>
create argument object containing a \ref vigra::MultiIterator
marking the begin of the array, and the default const accessor for
<tt>SomeType</tt>
</td></tr>
<tr><td>
<TT>srcMultiArray(img, SomeAccessor())</TT>
</td><td>
create argument object containing a \ref vigra::MultiIterator
marking the begin of the array and the given accessor
</td></tr>
<tr><td>
<TT>destMultiArrayRange(img)</TT>
</td><td>
create argument object containing a \ref vigra::MultiIterator
marking the begin of the array, a shape object giving the desired
shape of the array (possibly a subarray) and the default accessor for
<tt>SomeType</tt>
</td></tr>
<tr><td>
<TT>destMultiArrayRange(img, SomeAccessor())</TT>
</td><td>
create argument object containing a \ref vigra::MultiIterator's
marking the begin of the array, a shape object giving the desired
shape of the array (possibly a subarray) and the given accessor
</td></tr>
<tr><td>
<TT>destMultiArray(img)</TT>
</td><td>
create argument object containing a \ref vigra::MultiIterator
marking the begin of the array and the default accessor for
<tt>SomeType</tt>
</td></tr>
<tr><td>
<TT>destMultiArray(img, SomeAccessor())</TT>
</td><td>
create argument object containing a \ref vigra::MultiIterator's
marking the begin of the array and the given accessor
</td></tr>
</table>
\section IteratorBasedArgumentObjectFactories Iterator Based Argument Object Factories
<b>\#include</b> \<vigra/iteratortraits.hxx\>
Namespace: vigra
These factories can be used to create argument objects when we
are given \ref ImageIterators.
These factory functions use \ref vigra::IteratorTraits to
get the default accessor for the given iterator unless the
accessor is given explicitly. The following factory functions
are provided:
<table>
<tr><th bgcolor="#f0e0c0" colspan=2 align=left>
<TT>\ref vigra::BasicImage::Iterator "vigra::BasicImage<SomeType>::Iterator" i1, i2;</TT>
</th>
</tr>
<tr><td>
<TT>srcIterRange(i1, i2)</TT>
</td><td>
create argument object containing the given iterators and
corresponding default accessor (for source image)
</td></tr>
<tr><td>
<TT>srcIterRange(i1, i2, SomeAccessor())</TT>
</td><td>
create argument object containing given iterators and
accessor (for source image)
</td></tr>
<tr><td>
<TT>srcIter(i1)</TT>
</td><td>
create argument object containing the given iterator and
corresponding default accessor (for source image)
</td></tr>
<tr><td>
<TT>srcIter(i1, SomeAccessor())</TT>
</td><td>
create argument object containing given iterator and
accessor (for source image)
</td></tr>
<tr><td>
<TT>maskIter(i1)</TT>
</td><td>
create argument object containing the given iterator and
corresponding default accessor (for mask image)
</td></tr>
<tr><td>
<TT>maskIter(i1, SomeAccessor())</TT>
</td><td>
create argument object containing given iterator and
accessor (for mask image)
</td></tr>
<tr><td>
<TT>destIterRange(i1, i2)</TT>
</td><td>
create argument object containing the given iterators and
corresponding default accessor (for destination image)
</td></tr>
<tr><td>
<TT>destIterRange(i1, i2, SomeAccessor())</TT>
</td><td>
create argument object containing given iterators and
accessor (for destination image)
</td></tr>
<tr><td>
<TT>destIter(i1)</TT>
</td><td>
create argument object containing the given iterator and
corresponding default accessor (for destination image)
</td></tr>
<tr><td>
<TT>destIter(i1, SomeAccessor())</TT>
</td><td>
create argument object containing given iterator and
accessor (for destination image)
</td></tr>
</table>
*/
template <class Iterator, class Accessor>
inline triple<Iterator, Iterator, Accessor>
srcIterRange(Iterator const & upperleft, Iterator const & lowerright, Accessor a)
{
return triple<Iterator, Iterator, Accessor>(upperleft, lowerright, a);
}
template <class Iterator, class Accessor>
inline pair<Iterator, Accessor>
srcIter(Iterator const & upperleft, Accessor a)
{
return pair<Iterator, Accessor>(upperleft, a);
}
template <class Iterator, class Accessor>
inline pair<Iterator, Accessor>
maskIter(Iterator const & upperleft, Accessor a)
{
return pair<Iterator, Accessor>(upperleft, a);
}
template <class Iterator, class Accessor>
inline pair<Iterator, Accessor>
destIter(Iterator const & upperleft, Accessor a)
{
return pair<Iterator, Accessor>(upperleft, a);
}
template <class Iterator, class Accessor>
inline triple<Iterator, Iterator, Accessor>
destIterRange(Iterator const & upperleft, Iterator const & lowerright, Accessor a)
{
return triple<Iterator, Iterator, Accessor>(upperleft, lowerright, a);
}
template <class Iterator>
inline pair<Iterator, typename IteratorTraits<Iterator>::DefaultAccessor>
srcIter(Iterator const & upperleft)
{
return pair<Iterator, typename IteratorTraits<Iterator>::DefaultAccessor>(
upperleft,
typename IteratorTraits<Iterator>::DefaultAccessor());
}
template <class Iterator>
inline triple<Iterator, Iterator, typename IteratorTraits<Iterator>::DefaultAccessor>
srcIterRange(Iterator const & upperleft, Iterator const & lowerright)
{
return triple<Iterator, Iterator,
typename IteratorTraits<Iterator>::DefaultAccessor>(
upperleft, lowerright,
typename IteratorTraits<Iterator>::DefaultAccessor());
}
template <class Iterator>
inline pair<Iterator, typename IteratorTraits<Iterator>::DefaultAccessor>
maskIter(Iterator const & upperleft)
{
return pair<Iterator, typename IteratorTraits<Iterator>::DefaultAccessor>(
upperleft,
typename IteratorTraits<Iterator>::DefaultAccessor());
}
template <class Iterator>
inline pair<Iterator, typename IteratorTraits<Iterator>::DefaultAccessor>
destIter(Iterator const & upperleft)
{
return pair<Iterator, typename IteratorTraits<Iterator>::DefaultAccessor>(
upperleft,
typename IteratorTraits<Iterator>::DefaultAccessor());
}
template <class Iterator>
inline triple<Iterator, Iterator, typename IteratorTraits<Iterator>::DefaultAccessor>
destIterRange(Iterator const & upperleft, Iterator const & lowerright)
{
return triple<Iterator, Iterator,
typename IteratorTraits<Iterator>::DefaultAccessor>(
upperleft, lowerright,
typename IteratorTraits<Iterator>::DefaultAccessor());
}
} // namespace vigra
#endif // VIGRA_ITERATORTRAITS_HXX
|