Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2004-12-15 18:20:40


Eli Pulsifer wrote:
> Hello,
>
> I have a situation which is probably quite common and already addressed
> by boost.
> So rather than write it my self, maybe someone can point me to the
> answer.
>
> I've got a geometry class that needs to expose iterators for the
> underling vertex components.
> Example:
>
> Class Vertex
> {
> positions_iterator PositionsBegin();
> positions_iterator PositionsEnd();
> normals_iterator NormalsBegin();
> normals _iterator NormalsEnd();
> ...
> }
>
> The first problem is depending on the format of the underling vertices,
> the stride between the data elements will change.
> Is there some easy way to implement this?
>
> I think writing my own using the boost::iterator_adapter is probably the
> way to go.

Sounds like you have the right idea.

> Second problem is more involved.
>
> The texture data not only has a stride but a variable number of
> elements.
> Some vertices have 2 texture coordinates, some 3, some even more.
>
> Id love to define this iterator like this:
> stride_iterator< pair<float_iterator, float_iterator> >
> tex_coord_iterator;
>
> then create the iterator:
>
> stride_tupel_iterator< pair<float_iterator, float_iterator> >(
> pFirstTexCoord, texCoordStride, texCoordCount );
>
> then use it:
>
> stride_tupel_iterator< pair<float_iterator, float_iterator> > it;
>
> for( it = vertex.PositionBegin() ; it != vertex.PositionEnd() ; ++it)
> {
> pair<float_iterator, float_iterator> coords;
> float_iterator iCoord;
>
> for(iCoord = coords.first ; iCoord != coords.last ;
> ++iCoord)
> {
> }
> }
>
> This will probably also require me to create my own highly special
> iterator class or is there a better way.

Isn't this just a strided iterator adapter composed with zip_iterator?

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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