~ubuntu-branches/ubuntu/trusty/enblend-enfuse/trusty

« back to all changes in this revision

Viewing changes to include/vigra/diff2d.hxx

  • Committer: Package Import Robot
  • Author(s): Jackson Doak
  • Date: 2014-01-22 06:23:44 UTC
  • mfrom: (5.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140122062344-gdj5nf671oxprqq7
Tags: 4.1.2+dfsg-2ubuntu1
* Merge from Debian, remaining changes:
  - Build-depend on libglew-dev rather than libglew1.5-dev | libglew1.4-dev
    | libglew-dev.
  - Build using -O1 on arm

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/************************************************************************/
2
 
/*                                                                      */
3
 
/*                  Copyright 1998-2003 by Hans Meine                   */
4
 
/*       Cognitive Systems Group, University of Hamburg, Germany        */
5
 
/*                                                                      */
6
 
/*    This file is part of the VIGRA computer vision library.           */
7
 
/*    The VIGRA Website is                                              */
8
 
/*        http://kogs-www.informatik.uni-hamburg.de/~koethe/vigra/      */
9
 
/*    Please direct questions, bug reports, and contributions to        */
10
 
/*        koethe@informatik.uni-hamburg.de          or                  */
11
 
/*        vigra@kogs1.informatik.uni-hamburg.de                         */
12
 
/*                                                                      */
13
 
/*    Permission is hereby granted, free of charge, to any person       */
14
 
/*    obtaining a copy of this software and associated documentation    */
15
 
/*    files (the "Software"), to deal in the Software without           */
16
 
/*    restriction, including without limitation the rights to use,      */
17
 
/*    copy, modify, merge, publish, distribute, sublicense, and/or      */
18
 
/*    sell copies of the Software, and to permit persons to whom the    */
19
 
/*    Software is furnished to do so, subject to the following          */
20
 
/*    conditions:                                                       */
21
 
/*                                                                      */
22
 
/*    The above copyright notice and this permission notice shall be    */
23
 
/*    included in all copies or substantial portions of the             */
24
 
/*    Software.                                                         */
25
 
/*                                                                      */
26
 
/*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
27
 
/*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
28
 
/*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
29
 
/*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
30
 
/*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
31
 
/*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
32
 
/*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
33
 
/*    OTHER DEALINGS IN THE SOFTWARE.                                   */
34
 
/*                                                                      */
35
 
/************************************************************************/
36
 
 
37
 
#ifndef VIGRA_DIFF2D_HXX
38
 
#define VIGRA_DIFF2D_HXX
39
 
 
40
 
#include <cmath> // for sqrt()
41
 
#include <iosfwd>
42
 
#include "vigra/config.hxx"
43
 
#include "vigra/iteratortags.hxx"
44
 
#include "vigra/iteratortraits.hxx"
45
 
#include "vigra/iteratoradapter.hxx"
46
 
#include "vigra/tuple.hxx"
47
 
 
48
 
namespace vigra {
49
 
 
50
 
template <class Diff>
51
 
class Diff2DConstRowIteratorPolicy
52
 
{
53
 
  public:
54
 
    typedef Diff                            BaseType;
55
 
    typedef Diff                            value_type;
56
 
    typedef typename Diff::MoveX            difference_type;
57
 
    typedef Diff const &                    reference;
58
 
    typedef Diff                            index_reference;
59
 
    typedef Diff const *                    pointer;
60
 
    typedef std::random_access_iterator_tag iterator_category;
61
 
 
62
 
    static void initialize(BaseType &) {}
63
 
 
64
 
    static reference dereference(BaseType const & d)
65
 
        { return d; }
66
 
 
67
 
    static index_reference dereference(BaseType d, difference_type n)
68
 
    {
69
 
        d.x += n;
70
 
        return d;
71
 
    }
72
 
 
73
 
    static bool equal(BaseType const & d1, BaseType const & d2)
74
 
        { return d1.x == d2.x; }
75
 
 
76
 
    static bool less(BaseType const & d1, BaseType const & d2)
77
 
        { return d1.x < d2.x; }
78
 
 
79
 
    static difference_type difference(BaseType const & d1, BaseType const & d2)
80
 
        { return d1.x - d2.x; }
81
 
 
82
 
    static void increment(BaseType & d)
83
 
        { ++d.x; }
84
 
 
85
 
    static void decrement(BaseType & d)
86
 
        { --d.x; }
87
 
 
88
 
    static void advance(BaseType & d, difference_type n)
89
 
        { d.x += n; }
90
 
};
91
 
 
92
 
template <class Diff>
93
 
class Diff2DConstColumnIteratorPolicy
94
 
{
95
 
  public:
96
 
    typedef Diff                            BaseType;
97
 
    typedef Diff                            value_type;
98
 
    typedef typename Diff::MoveY            difference_type;
99
 
    typedef Diff const &                    reference;
100
 
    typedef Diff                            index_reference;
101
 
    typedef Diff const *                    pointer;
102
 
    typedef std::random_access_iterator_tag iterator_category;
103
 
 
104
 
    static void initialize(BaseType & /*d*/) {}
105
 
 
106
 
    static reference dereference(BaseType const & d)
107
 
        { return d; }
108
 
 
109
 
    static index_reference dereference(BaseType d, difference_type n)
110
 
    {
111
 
        d.y += n;
112
 
        return d;
113
 
    }
114
 
 
115
 
    static bool equal(BaseType const & d1, BaseType const & d2)
116
 
        { return d1.y == d2.y; }
117
 
 
118
 
    static bool less(BaseType const & d1, BaseType const & d2)
119
 
        { return d1.y < d2.y; }
120
 
 
121
 
    static difference_type difference(BaseType const & d1, BaseType const & d2)
122
 
        { return d1.y - d2.y; }
123
 
 
124
 
    static void increment(BaseType & d)
125
 
        { ++d.y; }
126
 
 
127
 
    static void decrement(BaseType & d)
128
 
        { --d.y; }
129
 
 
130
 
    static void advance(BaseType & d, difference_type n)
131
 
        { d.y += n; }
132
 
};
133
 
 
134
 
/** \addtogroup RangesAndPoints Two-dimensional Ranges and Points
135
 
 
136
 
    Specify a 2D position, extent, or rectangle.
137
 
*/
138
 
//@{
139
 
 
140
 
/********************************************************/
141
 
/*                                                      */
142
 
/*                      Diff2D                          */
143
 
/*                                                      */
144
 
/********************************************************/
145
 
 
146
 
/** \brief Two dimensional difference vector.
147
 
 
148
 
    This class acts primarily as a difference vector for specifying
149
 
    pixel coordinates and region sizes. In addition, Diff2D fulfills
150
 
    the requirements of an \ref ImageIterator, so that it can be used to
151
 
    simulate an image whose pixels' values equal their coordinates. This
152
 
    secondary usage is explained on page \ref CoordinateIterator.
153
 
 
154
 
    Standard usage as a difference vector is mainly needed in the context
155
 
    of images. For example, Diff2D may be used as an index for <TT>operator[]</TT>:
156
 
 
157
 
    \code
158
 
    vigra::Diff2D location(...);
159
 
 
160
 
    value = image[location];
161
 
    \endcode
162
 
 
163
 
    This is especially important in connection with accessors, where the
164
 
    offset variant of <TT>operator()</TT> takes only one offset object:
165
 
 
166
 
    \code
167
 
    // accessor(iterator, dx, dy); is not allowed
168
 
    value = accessor(iterator, vigra::Diff2D(dx, dy));
169
 
    \endcode
170
 
 
171
 
 
172
 
    Diff2D is also returned by <TT>image.size()</TT>, so that we can create
173
 
    new images by calculating their size using Diff2D's arithmetic
174
 
    functions:
175
 
 
176
 
    \code
177
 
    // create an image that is 10 pixels smaller in each direction
178
 
    Image new_image(old_image.size() - Diff2D(10,10));
179
 
    \endcode
180
 
 
181
 
    <b>\#include</b> "<a href="diff2d_8hxx-source.html">vigra/utilities.hxx</a>"<br>
182
 
    Namespace: vigra
183
 
*/
184
 
class Diff2D
185
 
{
186
 
  public:
187
 
        /** The iterator's value type: a coordinate.
188
 
        */
189
 
    typedef Diff2D PixelType;
190
 
 
191
 
        /** The iterator's value type: a coordinate.
192
 
        */
193
 
    typedef Diff2D value_type;
194
 
 
195
 
        /** the iterator's reference type (return type of <TT>*iter</TT>)
196
 
        */
197
 
    typedef Diff2D const &       reference;
198
 
 
199
 
        /** the iterator's index reference type (return type of <TT>iter[diff]</TT>)
200
 
        */
201
 
    typedef Diff2D               index_reference;
202
 
 
203
 
        /** the iterator's pointer type (return type of <TT>iter.operator->()</TT>)
204
 
        */
205
 
    typedef Diff2D const *       pointer;
206
 
 
207
 
        /** the iterator's difference type (argument type of <TT>iter[diff]</TT>)
208
 
        */
209
 
    typedef Diff2D               difference_type;
210
 
 
211
 
        /** the iterator tag (image traverser)
212
 
        */
213
 
    typedef image_traverser_tag  iterator_category;
214
 
 
215
 
        /** The associated row iterator.
216
 
        */
217
 
    typedef IteratorAdaptor<Diff2DConstRowIteratorPolicy<Diff2D> >    row_iterator;
218
 
 
219
 
        /** The associated column iterator.
220
 
        */
221
 
   typedef IteratorAdaptor<Diff2DConstColumnIteratorPolicy<Diff2D> > column_iterator;
222
 
 
223
 
        /** type of the iterator's x-navigator
224
 
        */
225
 
    typedef int MoveX;
226
 
        /** type of the iterator's y-navigator
227
 
        */
228
 
    typedef int MoveY;
229
 
 
230
 
 
231
 
        /** Default Constructor. Init iterator at position (0,0)
232
 
        */
233
 
    Diff2D()
234
 
    : x(0), y(0)
235
 
    {}
236
 
 
237
 
        /** Construct at given position.
238
 
        */
239
 
    Diff2D(int ax, int ay)
240
 
    : x(ax), y(ay)
241
 
    {}
242
 
 
243
 
        /** Copy Constructor.
244
 
        */
245
 
    Diff2D(Diff2D const & v)
246
 
    : x(v.x), y(v.y)
247
 
    {}
248
 
 
249
 
        /** Copy Assigment.
250
 
        */
251
 
    Diff2D & operator=(Diff2D const & v)
252
 
    {
253
 
        if(this != &v)
254
 
        {
255
 
            x = v.x;
256
 
            y = v.y;
257
 
        }
258
 
        return *this;
259
 
    }
260
 
 
261
 
        /** Unary negation.
262
 
        */
263
 
    Diff2D operator-() const
264
 
    {
265
 
        return Diff2D(-x, -y);
266
 
    }
267
 
 
268
 
        /** Increase coordinate by specified offset.
269
 
        */
270
 
    Diff2D & operator+=(Diff2D const & offset)
271
 
    {
272
 
        x += offset.x;
273
 
        y += offset.y;
274
 
        return *this;
275
 
    }
276
 
 
277
 
        /** Decrease coordinate by specified vector.
278
 
        */
279
 
    Diff2D & operator-=(Diff2D const & offset)
280
 
    {
281
 
        x -= offset.x;
282
 
        y -= offset.y;
283
 
        return *this;
284
 
    }
285
 
 
286
 
       /** Create vector by scaling by factor.
287
 
        */
288
 
    Diff2D & operator*=(int factor)
289
 
    {
290
 
        x *= factor;
291
 
        y *= factor;
292
 
        return *this;
293
 
    }
294
 
 
295
 
       /** Create vector by scaling by factor.
296
 
        */
297
 
    Diff2D & operator*=(double factor)
298
 
    {
299
 
        x = (int)(x * factor);
300
 
        y = (int)(y * factor);
301
 
        return *this;
302
 
    }
303
 
 
304
 
       /** Create vector by scaling by 1/factor.
305
 
        */
306
 
    Diff2D & operator/=(int factor)
307
 
    {
308
 
        x /= factor;
309
 
        y /= factor;
310
 
        return *this;
311
 
    }
312
 
 
313
 
       /** Create vector by scaling by 1/factor.
314
 
        */
315
 
    Diff2D & operator/=(double factor)
316
 
    {
317
 
        x = (int)(x / factor);
318
 
        y = (int)(y / factor);
319
 
        return *this;
320
 
    }
321
 
 
322
 
       /** Create vector by scaling by factor.
323
 
        */
324
 
    Diff2D operator*(int factor) const
325
 
    {
326
 
        return Diff2D(x * factor, y * factor);
327
 
    }
328
 
 
329
 
       /** Create vector by scaling by factor.
330
 
        */
331
 
    Diff2D operator*(double factor) const
332
 
    {
333
 
        return Diff2D((int)(x * factor), (int)(y * factor));
334
 
    }
335
 
 
336
 
       /** Create vector by scaling by 1/factor.
337
 
        */
338
 
    Diff2D operator/(int factor) const
339
 
    {
340
 
        return Diff2D(x / factor, y / factor);
341
 
    }
342
 
 
343
 
       /** Create vector by scaling by 1/factor.
344
 
        */
345
 
    Diff2D operator/(double factor) const
346
 
    {
347
 
        return Diff2D((int)(x / factor), (int)(y / factor));
348
 
    }
349
 
 
350
 
        /** Calculate length of difference vector.
351
 
        */
352
 
    int squaredMagnitude() const
353
 
    {
354
 
        return x*x + y*y;
355
 
    }
356
 
 
357
 
        /** Calculate length of difference vector.
358
 
        */
359
 
    double magnitude() const
360
 
    {
361
 
        return VIGRA_CSTD::sqrt((double)squaredMagnitude());
362
 
    }
363
 
 
364
 
        /** Equality.
365
 
        */
366
 
    bool operator==(Diff2D const & r) const
367
 
    {
368
 
        return (x == r.x) && (y == r.y);
369
 
    }
370
 
 
371
 
        /** Inequality.
372
 
        */
373
 
    bool operator!=(Diff2D const & r) const
374
 
    {
375
 
        return (x != r.x) || (y != r.y);
376
 
    }
377
 
 
378
 
        /** Used for both access to the current x-coordinate \em and
379
 
            to specify that an iterator navigation command is to be
380
 
            applied in x-direction. <br>
381
 
            usage:  <TT> x = diff2d.x </TT> (use \p Diff2D::x  as component of difference vector) <br>
382
 
            or <TT>&nbsp; ++diff.x &nbsp; </TT> (use Diff2D as iterator, move right)
383
 
         */
384
 
    int x;
385
 
        /** Used for both access to the current y-coordinate \em and
386
 
            to specify that an iterator navigation command is to be
387
 
            applied in y-direction. <br>
388
 
            usage:  <TT> y = diff2d.y </TT> (use \p Diff2D::y as component of difference vector) <br>
389
 
            or <TT>&nbsp; ++diff.y &nbsp; </TT> (use Diff2D as iterator, move right)
390
 
        */
391
 
    int y;
392
 
 
393
 
        /** Access current coordinate.
394
 
        */
395
 
    reference operator*() const
396
 
    {
397
 
        return *this;
398
 
    }
399
 
 
400
 
        /** Read coordinate at an offset.
401
 
        */
402
 
    index_reference operator()(int const & dx, int const & dy) const
403
 
    {
404
 
        return Diff2D(x + dx, y + dy);
405
 
    }
406
 
 
407
 
        /** Read coordinate at an offset.
408
 
        */
409
 
    index_reference operator[](Diff2D const & offset) const
410
 
    {
411
 
        return Diff2D(x + offset.x, y + offset.y);
412
 
    }
413
 
 
414
 
        /** Read vector components.
415
 
        */
416
 
    int operator[](int index) const
417
 
    {
418
 
        return (&x)[index];
419
 
    }
420
 
 
421
 
        /** Access current coordinate.
422
 
        */
423
 
    pointer operator->() const
424
 
    {
425
 
        return this;
426
 
    }
427
 
 
428
 
        /** Get a row iterator at the current position.
429
 
        */
430
 
    row_iterator rowIterator() const
431
 
        { return row_iterator(*this); }
432
 
 
433
 
        /** Get a column iterator at the current position.
434
 
        */
435
 
    column_iterator columnIterator() const
436
 
        { return column_iterator(*this); }
437
 
};
438
 
 
439
 
 
440
 
template <>
441
 
struct IteratorTraits<Diff2D >
442
 
{
443
 
    typedef Diff2D                               Iterator;
444
 
    typedef Iterator                             iterator;
445
 
    typedef Iterator                             const_iterator;
446
 
    // typedef                                   multable_iterator; undefined
447
 
    typedef iterator::iterator_category          iterator_category;
448
 
    typedef iterator::value_type                 value_type;
449
 
    typedef iterator::reference                  reference;
450
 
    typedef iterator::index_reference            index_reference;
451
 
    typedef iterator::pointer                    pointer;
452
 
    typedef iterator::difference_type            difference_type;
453
 
    typedef iterator::row_iterator               row_iterator;
454
 
    typedef iterator::column_iterator            column_iterator;
455
 
    typedef StandardConstValueAccessor<Diff2D>   DefaultAccessor;
456
 
    typedef StandardConstValueAccessor<Diff2D>   default_accessor;
457
 
    typedef VigraTrueType                        hasConstantStrides;
458
 
 
459
 
};
460
 
 
461
 
 
462
 
/********************************************************/
463
 
/*                                                      */
464
 
/*                      Size2D                          */
465
 
/*                                                      */
466
 
/********************************************************/
467
 
 
468
 
/** \brief Two dimensional size object.
469
 
 
470
 
    Specializes \ref Diff2D for the specification of a 2-dimensional
471
 
    extent, in contrast to a point or position (for the latter
472
 
    use \ref Point2D).
473
 
 
474
 
    \code
475
 
    // create an image that is 10 pixels squared
476
 
    Image new_image(Size2D(10,10));
477
 
    \endcode
478
 
 
479
 
    <b>\#include</b> "<a href="diff2d_8hxx-source.html">vigra/utilities.hxx</a>"<br>
480
 
    Namespace: vigra
481
 
*/
482
 
class Size2D : public Diff2D
483
 
{
484
 
public:
485
 
        /** Default Constructor. Init point at position (0,0)
486
 
        */
487
 
    Size2D()
488
 
    {}
489
 
 
490
 
        /** Construct point at given position.
491
 
        */
492
 
    Size2D(int width, int height)
493
 
    : Diff2D(width, height)
494
 
    {}
495
 
 
496
 
        /** Copy Constructor.
497
 
        */
498
 
    Size2D(Size2D const & v)
499
 
    : Diff2D(v)
500
 
    {}
501
 
 
502
 
        /** Explicit conversion Constructor.
503
 
        */
504
 
    explicit Size2D(Diff2D const & v)
505
 
    : Diff2D(v)
506
 
    {}
507
 
 
508
 
        /** Query the width.
509
 
         */
510
 
    int width() const
511
 
    {
512
 
        return x;
513
 
    }
514
 
 
515
 
        /** Query the height.
516
 
         */
517
 
    int height() const
518
 
    {
519
 
        return y;
520
 
    }
521
 
 
522
 
        /** Change the width.
523
 
         */
524
 
    void setWidth(int w)
525
 
    {
526
 
        x = w;
527
 
    }
528
 
 
529
 
        /** Change the height.
530
 
         */
531
 
    void setHeight(int h)
532
 
    {
533
 
        y = h;
534
 
    }
535
 
 
536
 
        /** Returns width()*height(), the area of a rectangle of this size.
537
 
         */
538
 
    int area() const
539
 
    {
540
 
        return width()*height();
541
 
    }
542
 
 
543
 
        /** Copy Assigment.
544
 
        */
545
 
    Size2D & operator=(Diff2D const & v)
546
 
    {
547
 
        return static_cast<Size2D &>(Diff2D::operator=(v));
548
 
    }
549
 
 
550
 
        /** Unary negation.
551
 
        */
552
 
    Size2D operator-() const
553
 
    {
554
 
        return Size2D(-x, -y);
555
 
    }
556
 
 
557
 
        /** Increase size by specified offset.
558
 
        */
559
 
    Size2D & operator+=(Diff2D const & offset)
560
 
    {
561
 
        return static_cast<Size2D &>(Diff2D::operator+=(offset));
562
 
    }
563
 
 
564
 
        /** Decrease size by specified offset.
565
 
        */
566
 
    Size2D & operator-=(Diff2D const & offset)
567
 
    {
568
 
        return static_cast<Size2D &>(Diff2D::operator-=(offset));
569
 
    }
570
 
};
571
 
 
572
 
/********************************************************/
573
 
/*                                                      */
574
 
/*                     Point2D                          */
575
 
/*                                                      */
576
 
/********************************************************/
577
 
 
578
 
/** \brief Two dimensional point or position.
579
 
 
580
 
    Specializes \ref Diff2D for the specification of a 2-dimensional
581
 
    point or position, in contrast to an extent (for the latter
582
 
    use \ref Size2D).
583
 
 
584
 
    \code
585
 
    // access an image at a point
586
 
    value = image[Point2D(10, 20)];
587
 
    \endcode
588
 
 
589
 
    <b>\#include</b> "<a href="diff2d_8hxx-source.html">vigra/utilities.hxx</a>"<br>
590
 
    Namespace: vigra
591
 
*/
592
 
class Point2D : public Diff2D
593
 
{
594
 
public:
595
 
        /** The iterator's value type: a coordinate.
596
 
        */
597
 
    typedef Point2D PixelType;
598
 
 
599
 
        /** The iterator's value type: a coordinate.
600
 
        */
601
 
    typedef Point2D value_type;
602
 
 
603
 
        /** the iterator's reference type (return type of <TT>*iter</TT>)
604
 
        */
605
 
    typedef Point2D const & reference;
606
 
 
607
 
        /** the iterator's index reference type (return type of <TT>iter[diff]</TT>)
608
 
        */
609
 
    typedef Point2D         index_reference;
610
 
 
611
 
        /** the iterator's pointer type (return type of <TT>iter.operator->()</TT>)
612
 
        */
613
 
    typedef Point2D const * pointer;
614
 
 
615
 
        /** Default Constructor. Init point at position (0,0)
616
 
        */
617
 
    Point2D()
618
 
    {}
619
 
 
620
 
        /** Construct point at given position.
621
 
        */
622
 
    Point2D(int x, int y)
623
 
    : Diff2D(x, y)
624
 
    {}
625
 
 
626
 
        /** Copy Constructor.
627
 
        */
628
 
    Point2D(Point2D const & v)
629
 
    : Diff2D(v)
630
 
    {}
631
 
 
632
 
        /** Explicit conversion Constructor.
633
 
        */
634
 
    explicit Point2D(Diff2D const & v)
635
 
    : Diff2D(v)
636
 
    {}
637
 
 
638
 
        /** Query the points' x coordinate
639
 
         */
640
 
    int px() const
641
 
    {
642
 
        return x;
643
 
    }
644
 
 
645
 
        /** Query the points' y coordinate
646
 
         */
647
 
    int py() const
648
 
    {
649
 
        return y;
650
 
    }
651
 
 
652
 
        /** Copy Assigment.
653
 
        */
654
 
    Point2D & operator=(Diff2D const & v)
655
 
    {
656
 
        return static_cast<Point2D &>(Diff2D::operator=(v));
657
 
    }
658
 
 
659
 
        /** Unary negation.
660
 
        */
661
 
    Point2D operator-() const
662
 
    {
663
 
        return Point2D(-x, -y);
664
 
    }
665
 
 
666
 
        /** Increase point coordinates by specified offset.
667
 
        */
668
 
    Point2D & operator+=(Diff2D const & offset)
669
 
    {
670
 
        return static_cast<Point2D &>(Diff2D::operator+=(offset));
671
 
    }
672
 
 
673
 
        /** Decrease point coordinates by specified offset.
674
 
        */
675
 
    Point2D & operator-=(Diff2D const & offset)
676
 
    {
677
 
        return static_cast<Point2D &>(Diff2D::operator-=(offset));
678
 
    }
679
 
 
680
 
        /** Access current point coordinate.
681
 
        */
682
 
    reference operator*() const
683
 
    {
684
 
        return *this;
685
 
    }
686
 
 
687
 
        /** Read point coordinate at an offset.
688
 
        */
689
 
    index_reference operator()(int const & dx, int const & dy) const
690
 
    {
691
 
        return Point2D(x + dx, y + dy);
692
 
    }
693
 
 
694
 
        /** Read point coordinate at an offset.
695
 
        */
696
 
    index_reference operator[](Diff2D const & offset) const
697
 
    {
698
 
        return Point2D(x + offset.x, y + offset.y);
699
 
    }
700
 
 
701
 
        /** Access current point coordinate.
702
 
        */
703
 
    pointer operator->() const
704
 
    {
705
 
        return this;
706
 
    }
707
 
};
708
 
 
709
 
/** Create vector by subtracting specified offset.
710
 
 */
711
 
inline Diff2D operator-(Diff2D const &a, Diff2D const &b)
712
 
{
713
 
    return Diff2D(a.x - b.x, a.y - b.y);
714
 
}
715
 
 
716
 
/** Create size by subtracting specified offset.
717
 
 */
718
 
inline Size2D operator-(Size2D const & s, Diff2D const &offset)
719
 
{
720
 
    return Size2D(s.x - offset.x, s.y - offset.y);
721
 
}
722
 
 
723
 
/** Calculate size of rect between two points.
724
 
 */
725
 
inline Point2D operator-(Point2D const & s, Diff2D const & offset)
726
 
{
727
 
    return Point2D(s.x - offset.x, s.y - offset.y);
728
 
}
729
 
 
730
 
/** The difference of two points is a size
731
 
 */
732
 
inline Size2D operator-(Point2D const & s, Point2D const & p)
733
 
{
734
 
    return Size2D(s.x - p.x, s.y - p.y);
735
 
}
736
 
 
737
 
/** Create vector by adding specified offset.
738
 
 */
739
 
inline Diff2D operator+(Diff2D const &a, Diff2D const &b)
740
 
{
741
 
    return Diff2D(a.x + b.x, a.y + b.y);
742
 
}
743
 
 
744
 
/** Create size by adding specified offset.
745
 
 */
746
 
inline Size2D operator+(Size2D const &a, Diff2D const &b)
747
 
{
748
 
    return Size2D(a.x + b.x, a.y + b.y);
749
 
}
750
 
 
751
 
/** Create point by adding specified offset.
752
 
 */
753
 
inline Point2D operator+(Point2D const &a, Diff2D const &b)
754
 
{
755
 
    return Point2D(a.x + b.x, a.y + b.y);
756
 
}
757
 
 
758
 
/** Add size and point
759
 
 */
760
 
inline Point2D operator+(Size2D const & s, Point2D const & p)
761
 
{
762
 
    return Point2D(s.x + p.x, s.y + p.y);
763
 
}
764
 
 
765
 
inline Point2D operator*(Point2D l, double r)
766
 
{
767
 
    l *= r;
768
 
    return l;
769
 
}
770
 
 
771
 
inline Point2D operator*(double l, Point2D r)
772
 
{
773
 
    r *= l;
774
 
    return r;
775
 
}
776
 
 
777
 
inline Size2D operator*(Size2D l, double r)
778
 
{
779
 
    l *= r;
780
 
    return l;
781
 
}
782
 
 
783
 
inline Size2D operator*(double l, Size2D r)
784
 
{
785
 
    r *= l;
786
 
    return r;
787
 
}
788
 
 
789
 
inline Point2D operator/(Point2D l, double r)
790
 
{
791
 
    l /= r;
792
 
    return l;
793
 
}
794
 
 
795
 
inline Size2D operator/(Size2D l, double r)
796
 
{
797
 
    l /= r;
798
 
    return l;
799
 
}
800
 
 
801
 
inline Point2D operator*(Point2D l, int r)
802
 
{
803
 
    l *= r;
804
 
    return l;
805
 
}
806
 
 
807
 
inline Point2D operator*(int l, Point2D r)
808
 
{
809
 
    r *= l;
810
 
    return r;
811
 
}
812
 
 
813
 
inline Size2D operator*(Size2D l, int r)
814
 
{
815
 
    l *= r;
816
 
    return l;
817
 
}
818
 
 
819
 
inline Size2D operator*(int l, Size2D r)
820
 
{
821
 
    r *= l;
822
 
    return r;
823
 
}
824
 
 
825
 
inline Point2D operator/(Point2D l, int r)
826
 
{
827
 
    l /= r;
828
 
    return l;
829
 
}
830
 
 
831
 
inline Size2D operator/(Size2D l, int r)
832
 
{
833
 
    l /= r;
834
 
    return l;
835
 
}
836
 
 
837
 
 
838
 
/********************************************************/
839
 
/*                                                      */
840
 
/*                      Rect2D                          */
841
 
/*                                                      */
842
 
/********************************************************/
843
 
 
844
 
/** \brief Two dimensional rectangle.
845
 
 
846
 
    This class stores a 2-dimensional rectangular range or region. Thus,
847
 
    it follows the VIGRA convention that the upper left corner is inside
848
 
    the rectangle, while the lower right is 1 pixel to the right and below the
849
 
    last pixel in the rectangle.
850
 
 
851
 
    A major advantage of this class is that it can be constructed from either
852
 
    a pair of \ref Point2D, or from a \ref Point2D and an extend
853
 
    (\ref Size2D). Rect2D overloads operators |=, &=, |, & to realize set
854
 
    union (in the sense of a minimal bounding rectangle) and set intersection.
855
 
 
856
 
    \code
857
 
    Rect2D r1(Point2D(0,0), Point2D(10, 20)),
858
 
           r2(Point2D(10, 15), Size2D(20, 20));
859
 
    Point2D p(0,100);
860
 
 
861
 
    Rect2D r3 =  r1 | r2; // upper left is (0,0), lower right is (30, 35)
862
 
    assert(r3.contains(r2));
863
 
    assert(!r3.contains(p));
864
 
 
865
 
    r3 |= p;       // lower right now (30,101) so that p is inside r3
866
 
    assert(r3.contains(p));
867
 
    \endcode
868
 
 
869
 
    <b>\#include</b> "<a href="diff2d_8hxx-source.html">vigra/utilities.hxx</a>"<br>
870
 
    Namespace: vigra
871
 
*/
872
 
class Rect2D
873
 
{
874
 
    Point2D upperLeft_, lowerRight_;
875
 
 
876
 
public:
877
 
        /** Construct a null rectangle (isEmpty() will return true)
878
 
         */
879
 
    Rect2D()
880
 
    {}
881
 
 
882
 
        /** Construct a rectangle representing the given range
883
 
         * (lowerRight is considered to be outside the rectangle as
884
 
         * usual in the VIGRA)
885
 
         */
886
 
    Rect2D(Point2D const &upperLeft, Point2D const &lowerRight)
887
 
    : upperLeft_(upperLeft), lowerRight_(lowerRight)
888
 
    {}
889
 
 
890
 
        /** Construct a rectangle representing the given range
891
 
         */
892
 
    Rect2D(int left, int top, int right, int bottom)
893
 
    : upperLeft_(left, top), lowerRight_(right, bottom)
894
 
    {}
895
 
 
896
 
        /** Construct a rectangle of given position and size
897
 
         */
898
 
    Rect2D(Point2D const &upperLeft, Size2D const &size)
899
 
    : upperLeft_(upperLeft), lowerRight_(upperLeft + size)
900
 
    {}
901
 
 
902
 
        /** Construct a rectangle of given size at position (0,0)
903
 
         */
904
 
    explicit Rect2D(Size2D const &size)
905
 
    : lowerRight_(Point2D(size))
906
 
    {}
907
 
 
908
 
        /** Return the first point (scan-order wise) which is
909
 
         * considered to be "in" the rectangle.
910
 
         */
911
 
    Point2D const & upperLeft() const
912
 
    {
913
 
        return upperLeft_;
914
 
    }
915
 
 
916
 
        /** Return the first point to the right and below the
917
 
         * rectangle.
918
 
         */
919
 
    Point2D const & lowerRight() const
920
 
    {
921
 
        return lowerRight_;
922
 
    }
923
 
 
924
 
        /** Change upperLeft() without changing lowerRight(), which
925
 
         * will change the size most probably.
926
 
         */
927
 
    void setUpperLeft(Point2D const &ul)
928
 
    {
929
 
        upperLeft_ = ul;
930
 
    }
931
 
 
932
 
        /** Change lowerRight() without changing upperLeft(), which
933
 
         * will change the size most probably.
934
 
         */
935
 
    void setLowerRight(Point2D const &lr)
936
 
    {
937
 
        lowerRight_ = lr;
938
 
    }
939
 
 
940
 
        /** Move the whole rectangle so that the given point will be
941
 
         * upperLeft() afterwards.
942
 
         */
943
 
    void moveTo(Point2D const &newUpperLeft)
944
 
    {
945
 
        lowerRight_ += newUpperLeft - upperLeft_;
946
 
        upperLeft_ = newUpperLeft;
947
 
    }
948
 
 
949
 
        /** Move the whole rectangle so that upperLeft() will become
950
 
         * Point2D(left, top) afterwards.
951
 
         */
952
 
    void moveTo(int left, int top)
953
 
    {
954
 
        moveTo(Point2D(left, top));
955
 
    }
956
 
 
957
 
        /** Move the whole rectangle by the given 2D offset.
958
 
         */
959
 
    void moveBy(Diff2D const &offset)
960
 
    {
961
 
        upperLeft_ += offset;
962
 
        lowerRight_ += offset;
963
 
    }
964
 
 
965
 
        /** Move the whole rectangle by the given x- and y-offsets.
966
 
         */
967
 
    void moveBy(int xOffset, int yOffset)
968
 
    {
969
 
        moveBy(Diff2D(xOffset, yOffset));
970
 
    }
971
 
 
972
 
        /** Return the left coordinate of this rectangle.
973
 
         */
974
 
    int left() const
975
 
    {
976
 
        return upperLeft_.x;
977
 
    }
978
 
 
979
 
        /** Return the top coordinate of this rectangle.
980
 
         */
981
 
    int top() const
982
 
    {
983
 
        return upperLeft_.y;
984
 
    }
985
 
 
986
 
        /** Return the right coordinate of this rectangle. That is the
987
 
         * first column to the right of the rectangle.
988
 
         */
989
 
    int right() const
990
 
    {
991
 
        return lowerRight_.x;
992
 
    }
993
 
 
994
 
        /** Return the bottom coordinate of this rectangle. That is the
995
 
         * first row below the rectangle.
996
 
         */
997
 
    int bottom() const
998
 
    {
999
 
        return lowerRight_.y;
1000
 
    }
1001
 
 
1002
 
        /** Determine and return the width of this rectangle. It might be
1003
 
         * zero or even negative, and if so, isEmpty() will return true.
1004
 
         */
1005
 
    int width() const
1006
 
    {
1007
 
        return lowerRight_.x - upperLeft_.x;
1008
 
    }
1009
 
 
1010
 
        /** Determine and return the height of this rectangle. It might be
1011
 
         * zero or even negative, and if so, isEmpty() will return true.
1012
 
         */
1013
 
    int height() const
1014
 
    {
1015
 
        return lowerRight_.y - upperLeft_.y;
1016
 
    }
1017
 
 
1018
 
        /** Determine and return the area of this rectangle. That is, if
1019
 
         * this rect isEmpty(), returns zero, otherwise returns
1020
 
         * width()*height().
1021
 
         */
1022
 
    long long area() const
1023
 
    {
1024
 
        return isEmpty() ? 0LL : (long long)width()*(long long)height();
1025
 
    }
1026
 
 
1027
 
        /** Determine and return the size of this rectangle. The width
1028
 
         * and/or height might be zero or even negative, and if so,
1029
 
         * isEmpty() will return true.
1030
 
         */
1031
 
    Size2D size() const
1032
 
    {
1033
 
        return lowerRight_ - upperLeft_;
1034
 
    }
1035
 
 
1036
 
        /** Resize this rectangle to the given extents. This will move
1037
 
         * the lower right corner only.
1038
 
         */
1039
 
    void setSize(Size2D const &size)
1040
 
    {
1041
 
        lowerRight_ = upperLeft_ + size;
1042
 
    }
1043
 
 
1044
 
        /** Resize this rectangle to the given extents. This will move
1045
 
         * the lower right corner only.
1046
 
         */
1047
 
    void setSize(int width, int height)
1048
 
    {
1049
 
        lowerRight_ = upperLeft_ + Size2D(width, height);
1050
 
    }
1051
 
 
1052
 
        /** Increase the size of the rectangle by the given offset. This
1053
 
         * will move the lower right corner only. (If any of offset's
1054
 
         * components is negative, the rectangle will get smaller
1055
 
         * accordingly.)
1056
 
         */
1057
 
    void addSize(Size2D const &offset)
1058
 
    {
1059
 
        lowerRight_ += offset;
1060
 
    }
1061
 
 
1062
 
        /** Adds a border of the given width around the rectangle. That
1063
 
         * means, upperLeft()'s components are moved by -borderWidth
1064
 
         * and lowerRight()'s by borderWidth. (If borderWidth is
1065
 
         * negative, the rectangle will get smaller accordingly.)
1066
 
         */
1067
 
    void addBorder(int borderWidth)
1068
 
    {
1069
 
        upperLeft_ += Diff2D(-borderWidth, -borderWidth);
1070
 
        lowerRight_ += Diff2D(borderWidth, borderWidth);
1071
 
    }
1072
 
 
1073
 
        /** Adds a border with possibly different widths in x- and
1074
 
         * y-directions around the rectangle. That means, each x
1075
 
         * component is moved borderWidth pixels and each y component
1076
 
         * is moved borderHeight pixels to the outside. (If
1077
 
         * borderWidth is negative, the rectangle will get smaller
1078
 
         * accordingly.)
1079
 
         */
1080
 
    void addBorder(int borderWidth, int borderHeight)
1081
 
    {
1082
 
        upperLeft_ += Diff2D(-borderWidth, -borderHeight);
1083
 
        lowerRight_ += Diff2D(borderWidth, borderHeight);
1084
 
    }
1085
 
 
1086
 
        /// equality check
1087
 
    bool operator==(Rect2D const &r) const
1088
 
    {
1089
 
        return (upperLeft_ == r.upperLeft_) && (lowerRight_ == r.lowerRight_);
1090
 
    }
1091
 
 
1092
 
        /// inequality check
1093
 
    bool operator!=(Rect2D const &r) const
1094
 
    {
1095
 
        return (upperLeft_ != r.upperLeft_) || (lowerRight_ != r.lowerRight_);
1096
 
    }
1097
 
 
1098
 
        /** Return whether this rectangle is considered empty. It is
1099
 
         * non-empty if both coordinates of the lower right corner are
1100
 
         * greater than the corresponding coordinate of the upper left
1101
 
         * corner. Uniting an empty rectangle with something will return
1102
 
         * the bounding rectangle of the 'something', intersecting with an
1103
 
         * empty rectangle will yield again an empty rectangle.
1104
 
         */
1105
 
    bool isEmpty() const
1106
 
    {
1107
 
        return ((lowerRight_.x <= upperLeft_.x) ||
1108
 
                (lowerRight_.y <= upperLeft_.y));
1109
 
    }
1110
 
 
1111
 
        /** Return whether this rectangle contains the given point. That
1112
 
         * is, if the point lies within the valid range of an
1113
 
         * ImageIterator walking from upperLeft() to lowerRight()
1114
 
         * (excluding the latter).
1115
 
         */
1116
 
    bool contains(Point2D const &p) const
1117
 
    {
1118
 
        return ((upperLeft_.x <= p.x) &&
1119
 
                (upperLeft_.y <= p.y) &&
1120
 
                (p.x < lowerRight_.x) &&
1121
 
                (p.y < lowerRight_.y));
1122
 
    }
1123
 
 
1124
 
        /** Return whether this rectangle contains the given
1125
 
         * one. <tt>r1.contains(r2)</tt> returns the same as
1126
 
         * <tt>r1 == (r1|r2)</tt> (but is of course more
1127
 
         * efficient). That also means, a rectangle (even an empty one!)
1128
 
         * contains() any empty rectangle.
1129
 
         */
1130
 
    bool contains(Rect2D const &r) const
1131
 
    {
1132
 
        return r.isEmpty() ||
1133
 
            (contains(r.upperLeft()) && contains(r.lowerRight()-Diff2D(1,1)));
1134
 
    }
1135
 
 
1136
 
        /** Return whether this rectangle overlaps with the given
1137
 
         * one. <tt>r1.intersects(r2)</tt> returns the same as
1138
 
         * <tt>!(r1&r2).isEmpty()</tt> (but is of course much more
1139
 
         * efficient).
1140
 
         */
1141
 
    bool intersects(Rect2D const &r) const
1142
 
    {
1143
 
        return ((r.upperLeft_.x < lowerRight_.x) &&
1144
 
                (upperLeft_.x < r.lowerRight_.x) &&
1145
 
                (r.upperLeft_.y < lowerRight_.y) &&
1146
 
                (upperLeft_.y < r.lowerRight_.y))
1147
 
            && !r.isEmpty();
1148
 
    }
1149
 
 
1150
 
        /** Modifies this rectangle by including the given point. The
1151
 
         * result is the bounding rectangle of the rectangle and the
1152
 
         * point. If isEmpty returns true, the union will be a
1153
 
         * rectangle containing only the given point.
1154
 
         */
1155
 
    Rect2D &operator|=(Point2D const &p)
1156
 
    {
1157
 
        if(isEmpty())
1158
 
        {
1159
 
            upperLeft_ = p;
1160
 
            lowerRight_ = p + Diff2D(1, 1);
1161
 
        }
1162
 
        else
1163
 
        {
1164
 
            if(p.x < upperLeft_.x)
1165
 
                upperLeft_.x = p.x;
1166
 
            if(p.y < upperLeft_.y)
1167
 
                upperLeft_.y = p.y;
1168
 
            if(lowerRight_.x <= p.x)
1169
 
                lowerRight_.x = p.x + 1;
1170
 
            if(lowerRight_.y <= p.y)
1171
 
                lowerRight_.y = p.y + 1;
1172
 
        }
1173
 
        return *this;
1174
 
    }
1175
 
 
1176
 
        /** Returns the union of this rectangle and the given
1177
 
         * point. The result is the bounding rectangle of the
1178
 
         * rectangle and the point. If isEmpty returns true, the union
1179
 
         * will be a rectangle containing only the given point.
1180
 
         */
1181
 
    Rect2D operator|(Point2D const &p) const
1182
 
    {
1183
 
        Rect2D result(*this);
1184
 
        result |= p;
1185
 
        return result;
1186
 
    }
1187
 
 
1188
 
        /** Modifies this rectangle by uniting it with the given
1189
 
         * one. The result is the bounding rectangle of both
1190
 
         * rectangles. If one of the rectangles isEmpty(), the union
1191
 
         * will be the other one.
1192
 
         */
1193
 
    Rect2D &operator|=(Rect2D const &r)
1194
 
    {
1195
 
        if(r.isEmpty())
1196
 
            return *this;
1197
 
        if(isEmpty())
1198
 
            return operator=(r);
1199
 
 
1200
 
        if(r.upperLeft_.x < upperLeft_.x)
1201
 
            upperLeft_.x = r.upperLeft_.x;
1202
 
        if(r.upperLeft_.y < upperLeft_.y)
1203
 
            upperLeft_.y = r.upperLeft_.y;
1204
 
        if(lowerRight_.x < r.lowerRight_.x)
1205
 
            lowerRight_.x = r.lowerRight_.x;
1206
 
        if(lowerRight_.y < r.lowerRight_.y)
1207
 
            lowerRight_.y = r.lowerRight_.y;
1208
 
        return *this;
1209
 
    }
1210
 
 
1211
 
        /** Returns the union of this rectangle and the given one. The
1212
 
         * result is the bounding rectangle of both rectangles. If one
1213
 
         * of the rectangles isEmpty(), the union will be the other
1214
 
         * one.
1215
 
         */
1216
 
    Rect2D operator|(Rect2D const &r) const
1217
 
    {
1218
 
        Rect2D result(*this);
1219
 
        result |= r;
1220
 
        return result;
1221
 
    }
1222
 
 
1223
 
        /** Modifies this rectangle by intersecting it with the given
1224
 
         * point. The result is the bounding rect of the point (with
1225
 
         * width and height equal to 1) if it was contained in the
1226
 
         * original rect, or an empty rect otherwise.
1227
 
         */
1228
 
    Rect2D &operator&=(Point2D const &p)
1229
 
    {
1230
 
        if(contains(p))
1231
 
        {
1232
 
            upperLeft_ = p;
1233
 
            lowerRight_ = p + Diff2D(1, 1);
1234
 
        }
1235
 
        else
1236
 
            lowerRight_ = upperLeft_;
1237
 
        return *this;
1238
 
    }
1239
 
 
1240
 
        /** Intersects this rectangle with the given point. The result
1241
 
         * is the bounding rect of the point (with width and height
1242
 
         * equal to 1) if it was contained in the original rect, or an
1243
 
         * empty rect otherwise.
1244
 
         */
1245
 
    Rect2D operator&(Point2D const &p) const
1246
 
    {
1247
 
        Rect2D result(*this);
1248
 
        result &= p;
1249
 
        return result;
1250
 
    }
1251
 
 
1252
 
        /** Modifies this rectangle by intersecting it with the given
1253
 
         * one. The result is the maximal rectangle contained in both
1254
 
         * original ones. Intersecting with an empty rectangle will
1255
 
         * yield again an empty rectangle.
1256
 
         */
1257
 
    Rect2D &operator&=(Rect2D const &r)
1258
 
    {
1259
 
        if(isEmpty())
1260
 
            return *this;
1261
 
        if(r.isEmpty())
1262
 
            return operator=(r);
1263
 
 
1264
 
        if(upperLeft_.x < r.upperLeft_.x)
1265
 
            upperLeft_.x = r.upperLeft_.x;
1266
 
        if(upperLeft_.y < r.upperLeft_.y)
1267
 
            upperLeft_.y = r.upperLeft_.y;
1268
 
        if(r.lowerRight_.x < lowerRight_.x)
1269
 
            lowerRight_.x = r.lowerRight_.x;
1270
 
        if(r.lowerRight_.y < lowerRight_.y)
1271
 
            lowerRight_.y = r.lowerRight_.y;
1272
 
        return *this;
1273
 
    }
1274
 
 
1275
 
        /** Intersects this rectangle with the given one. The result
1276
 
         * is the maximal rectangle contained in both original ones.
1277
 
         * Intersecting with an empty rectangle will yield again an
1278
 
         * empty rectangle.
1279
 
         */
1280
 
    Rect2D operator&(Rect2D const &r) const
1281
 
    {
1282
 
        Rect2D result(*this);
1283
 
        result &= r;
1284
 
        return result;
1285
 
    }
1286
 
 
1287
 
    /** create iterators to iterate over this ROI
1288
 
     *
1289
 
     *  @param image     iterators to source image
1290
 
     *
1291
 
     *  @return iterator set, to iterate over this ROI
1292
 
     */
1293
 
    template <typename ImgIter, typename ImgAccessor>
1294
 
    vigra::triple<ImgIter, ImgIter, ImgAccessor>
1295
 
    apply(vigra::triple<ImgIter, ImgIter, ImgAccessor> image) const
1296
 
    {
1297
 
        return vigra::make_triple(image.first + upperLeft_, image.first + lowerRight_, image.third);
1298
 
    }
1299
 
 
1300
 
    /** create iterators to iterate over the ROI
1301
 
     *
1302
 
     *  @param image     iterators to source image (the source image should
1303
 
     *                   cover the whole ROI)
1304
 
     *
1305
 
     *  @return iterator set, to iterate over this ROI
1306
 
     */
1307
 
    template <typename ImgIter, typename ImgAccessor>
1308
 
    std::pair<ImgIter, ImgAccessor>
1309
 
    apply(std::pair<ImgIter, ImgAccessor> image) const
1310
 
    {
1311
 
        return std::make_pair(image.first + upperLeft_, image.second);
1312
 
    }
1313
 
 
1314
 
};
1315
 
 
1316
 
/********************************************************/
1317
 
/*                                                      */
1318
 
/*                      Dist2D                          */
1319
 
/*                                                      */
1320
 
/********************************************************/
1321
 
 
1322
 
/** @deprecated use \ref vigra::Diff2D instead
1323
 
*/
1324
 
class Dist2D
1325
 
{
1326
 
  public:
1327
 
    Dist2D(int the_width, int the_height)
1328
 
    : width(the_width),
1329
 
      height(the_height)
1330
 
    {}
1331
 
 
1332
 
    Dist2D(Dist2D const & s)
1333
 
    : width(s.width),
1334
 
      height(s.height)
1335
 
    {}
1336
 
 
1337
 
    Dist2D & operator=(Dist2D const & s)
1338
 
    {
1339
 
        if(this != &s)
1340
 
        {
1341
 
            width = s.width;
1342
 
            height = s.height;
1343
 
        }
1344
 
        return *this;
1345
 
    }
1346
 
 
1347
 
    Dist2D & operator+=(Dist2D const & s)
1348
 
    {
1349
 
        width += s.width;
1350
 
        height += s.height;
1351
 
 
1352
 
        return *this;
1353
 
    }
1354
 
 
1355
 
    Dist2D  operator+(Dist2D const & s) const
1356
 
    {
1357
 
        Dist2D ret(*this);
1358
 
        ret += s;
1359
 
 
1360
 
        return ret;
1361
 
    }
1362
 
 
1363
 
    operator Diff2D()
1364
 
        { return Diff2D(width, height); }
1365
 
 
1366
 
    int width;
1367
 
    int height;
1368
 
 };
1369
 
 
1370
 
//@}
1371
 
 
1372
 
/**
1373
 
 * Output a \ref vigra::Diff2D as a tuple.
1374
 
 * Example Diff2D(-12, 13) -> "(-12, 13)"
1375
 
 */
1376
 
inline
1377
 
std::ostream & operator<<(std::ostream & o, vigra::Diff2D const & d)
1378
 
{
1379
 
    o << '(' << d.x << ", " << d.y << ')';
1380
 
    return o;
1381
 
}
1382
 
 
1383
 
/**
1384
 
 * Output a \ref vigra::Size2D.
1385
 
 * Example Size2D(100, 200) -> "(100x200)"
1386
 
 */
1387
 
inline
1388
 
std::ostream &operator <<(std::ostream &s, vigra::Size2D const &d)
1389
 
{
1390
 
    s << '(' << d.x << 'x' << d.y << ')';
1391
 
    return s;
1392
 
}
1393
 
 
1394
 
/**
1395
 
 * Output a description of a \ref vigra::Rect2D.
1396
 
 * Example Rect2D(10, 10, 30, 20) -> "[(10, 10) to (30, 20) = (20x10)]"
1397
 
 */
1398
 
inline
1399
 
std::ostream &operator <<(std::ostream &s, vigra::Rect2D const &r)
1400
 
{
1401
 
    s << "[" << r.upperLeft() << " to " << r.lowerRight()
1402
 
      << " = " << r.size() << "]";
1403
 
    return s;
1404
 
}
1405
 
 
1406
 
} // namespace vigra
1407
 
 
1408
 
#endif // VIGRA_DIFF2D_HXX