How to make an iterator with a stride... and more
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.
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
Maybe you should be looking at std::advance? 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.
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
> tex_coord_iterator; then create the iterator:
stride_tupel_iterator< pair
>( pFirstTexCoord, texCoordStride, texCoordCount ); then use it:
stride_tupel_iterator< pair
> it; for( it = vertex.PositionBegin() ; it != vertex.PositionEnd() ; ++it)
{
pair
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.
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
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
> tex_coord_iterator; then create the iterator:
stride_tupel_iterator< pair
>( pFirstTexCoord, texCoordStride, texCoordCount ); then use it:
stride_tupel_iterator< pair
> it; for( it = vertex.PositionBegin() ; it != vertex.PositionEnd() ; ++it) { pair
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
I think I may help you, but your problem is not clear to me yet. On Wed, 15 Dec 2004, Eli Pulsifer wrote:
The first problem is depending on the format of the underling vertices, the stride between the data elements will change.
I didn't understand this. What is a stride between data elements? Why does it change? Why is that a problem?
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.
Can't you have an internal container and return iterators to this container?
for( it = vertex.PositionBegin() ; it != vertex.PositionEnd() ; ++it) { pair
coords; float_iterator iCoord; for(iCoord = coords.first ; iCoord != coords.last ; ++iCoord) { } }
It looks like 'it' is not being used inside the loop, so I don't
understand this example.
Let me tell you why I think I may help you. I have written an iterator
adaptor that uses the elements through which the base iterator iterates in
order to determine a range to be recursively iterated. An example:
int[] a1 = {1,2,3};
int[] a2 = {4,5};
list<int> sublist1(a1, a1 + 3);
list<int> sublist2(a2, a2 + 2);
list::iterator>, range_getter> ni;
for (ni = make_nested_iterator(l.begin(),l.end());
ni != make_nested_iterator(l.end(),l.end());
ni++)
{
// ni points successively to 1, 2, 3, 4, 5
}
range_getter is an adaptable unary function class returning the
begin(),end() range of the container passed to it.
That is to say, a nested_iterator makes a bunch of ranges look as if they
are one. Would this be helpful to you?
Best,
Rodrigo
participants (4)
-
David Abrahams
-
Eli Pulsifer
-
Jeffrey Holle
-
Rodrigo de Salvo Braz