Boost logo

Boost Users :

Subject: Re: [Boost-users] [GIL] Some questions about 2D iteration
From: Brett Gmoser (bgmoser_at_[hidden])
Date: 2010-04-09 00:56:01


On 4/7/2010 2:39 AM, Nicolas Lelong wrote:
> Brett,
>
> For your first question, it's probable that using 1d iterators would
> not speed things, as they're less performant for 2d traversal. To gain
> some speed, you could try storing the results of 'src.height()' and
> 'src.row_end(y)' into variables, this would allow the compiler to know
> for sure that these values are constant.
>
> Also note that using numerical values are not really a problem for
> your algorithm reusability : you could feed it with, say, a view
> transformed with 'flipped_up_down_view
> <http://www.boost.org/doc/libs/1_42_0/libs/gil/doc/html/g_i_l_0163.html>'
> so it could operate bottom-up, and so on.
>
> For your second question, I'd look at creating a 'subimage_view' from
> your source view, and then use 'copy_pixels' to copy it to your
> destination image. This should be pretty close to optimal gil usage.
>
Nicolas,

Thanks so much for your help! Your suggestions really helped me out. I
was able to use the subimg_view's for the moving around in the
destination image (I hadn't thought of it that way), and the
flipped_up_down view stuff really helped to make my "find extents"
algorithm more generic (I wound up using the roated_90cw, rotated_90ccw,
rotated_180 views).

The only thing I'm confused about is that you say that using 1d
iterators wouldn't help much (and, btw, I was able to use the iterators
correctly now that I didn't need to add to the x/y coordinates in the
destination view). The documentation clearly says that v(x, y) is slower
than iteration. Would you mind clarifying what you mean? What I'm doing
now, and what a lot of the samples do, is something like this:

for(int x = 0; x < width, ++x)
   for(y_iterator y = src.y_begin(x); y != src.y_end(x); ++y)
     /* ... */

My confusion earlier was that apparently you cannot use iterators for
both the inner and outer loop - one of them needs to be an integer,
which doesn't seem to be an issue. It makes sense that v(x, y) would be
slower because it needs to calculate both the x and y position.

Thanks again for your help! I'm a lot better off now having understood
your response to my question.

Brett



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net