oln::abstract::iter< Exact > Struct Template Reference

Iterator. More...

#include <iter.hh>

Inheritance diagram for oln::abstract::iter< Exact >:

Inheritance graph
[legend]
Collaboration diagram for oln::abstract::iter< Exact >:

Collaboration graph
[legend]
List of all members.

Public Types

typedef iter_traits< Exact
>::point_type 
point_type
 The associate image's type of point.
typedef iter_traits< Exact
>::dpoint_type 
dpoint_type
 The associate image's type of dpoint (move point).

Public Member Functions

const point_typepoint_ref () const
 Accessor to current iterator's point.
bool operator== (const abstract::point< point_type > &p) const
 Compare with the current iterator's point.
bool operator!= (const abstract::point< point_type > &p) const
 Compare with the current iterator's point.
point_type operator+ (const abstract::dpoint< dpoint_type > &dp) const
 Sum a move point to the current point.
point_type operator- (const abstract::dpoint< dpoint_type > &dp) const
 Minor a move to the current point.
 operator point_type () const
 Cast to exact point type.
point_type cur () const
 Syntax improvement.
mlc::begin_type operator= (mlc::begin_type b)
 Set current point to the first iterator's point.
mlc::end_type operator= (mlc::end_type e)
 Set current point to the last iterator's point.
bool operator== (mlc::end_type) const
 Compare current point and last point.
void operator++ ()
 Go to the next iterator's point.
bool operator!= (mlc::end_type e) const
 Compare current point and last point.

Static Public Member Functions

static std::string name ()
 Return the name of the type.

Protected Member Functions

 iter ()
 Constructor.

Protected Attributes

point_type p_
 The iterator's current point.

Detailed Description

template<class Exact>
struct oln::abstract::iter< Exact >

Iterator.

Allow iterable object (like image, window, ...) traversing.

Warning:
To know the type of iterator you need for an iterable object, use the macro oln_iter_type(Iterable) or oln_iter_type_(Iterable) (same without 'typename' keyword) rather than Iterable::iter_type.
Simple use of iterators:
 #include <oln/basics2d.hh>
 #include <ntg/all.hh>
 #include <iostream>
 #include <assert.h>
 using namespace oln;
 using namespace ntg;
 int main(int argc, char **argv)
 {
   image2d<bin> image1 = load(IMG_IN "se.pbm");
   assert(image1.has_impl());
   oln_iter_type_(image2d<bin>) i(image1);
   for_all(i)
   {
     std::cout << image1[i] << std::endl;
   }
 }

This code is equivalent to the previous one but DEPRECATED (prefer to use the for_all macro):

 #include <oln/basics2d.hh>
 #include <ntg/all.hh>
 #include <iostream>
 #include <assert.h>
 using namespace oln;
 using namespace ntg;
 int main(int argc, char **argv)
 {
   image2d<bin> image1 = load(IMG_IN "se.pbm");
   assert(image1.has_impl());
   for (int row = 0; row < image1.nrows(); ++row)
     for (int col = 0; col < image1.ncols(); ++col)
       std::cout << image1(row, col) << std::endl;
 }

You can use the same iterator on several image if they have the same size.

 #include <oln/basics2d.hh>
 #include <ntg/all.hh>
 #include <iostream>
 #include <assert.h>
 using namespace oln;
 using namespace ntg;
 int main(int argc, char **argv)
 {
   image2d<bin> image1 = load(IMG_IN "se.pbm");
   image2d<bin> image2 = load(IMG_IN "se.pbm");
   assert(image1.has_impl());
   assert(image2.has_impl());
   oln_iter_type_(image2d<bin>) i(image1);
   for_all(i)
   {
     std::cout << "image1:" << image1[i] << std::endl;
     std::cout << "image2:" << image2[i] << std::endl;
   }
   return 0;
 }

You can iterate not only image but windows. This example make a binary dilatation to show you how to use them:

 #include <oln/basics2d.hh>
 #include <ntg/all.hh>
 #include <iostream>
 #include <assert.h>
 using namespace oln;
 using namespace ntg;
 int main(int argc, char **argv)
 {
   image2d<bin> image1 = load(IMG_IN "object.pbm");
   assert(image1.has_impl());
   image2d<bin> image1_out(image1.size());
   oln_iter_type_(image2d<bin>) i(image1);
   for_all(i)
   {
     image1_out[i] = image1[i];
     if (!image1[i])
     {
       window2d win = win_c8_only();
       oln_iter_type_(window2d) j(win);
       bool change_color = false;
       for_all(j)
       {
         if (image1[i + j])
           change_color = true;
       }
       image1_out[i] = change_color;
     }
   }
   save(image1_out, IMG_OUT "oln_abstract_iter.pbm");
   return 0;
 }
object_pbm.png
=>
oln_abstract_iter.png

Definition at line 179 of file iter.hh.


Member Typedef Documentation

template<class Exact>
typedef iter_traits<Exact>::point_type oln::abstract::iter< Exact >::point_type

The associate image's type of point.

Warning:
Prefer the macros oln_point_type(Pointable) and oln_point_type_(Pointable) (the same without the 'typename' keyword)

Reimplemented in oln::bkd_iter1d< Exact >, oln::bkd_iter2d< Exact >, oln::bkd_iter3d< Exact >, oln::fwd_iter1d< Exact >, oln::fwd_iter2d< Exact >, and oln::fwd_iter3d< Exact >.

Definition at line 186 of file iter.hh.

template<class Exact>
typedef iter_traits<Exact>::dpoint_type oln::abstract::iter< Exact >::dpoint_type

The associate image's type of dpoint (move point).

Warning:
Prefer the macros oln_dpoint_type(Pointable) and oln_dpoint_type_(Pointable) (the same without the 'typename' keyword)

Definition at line 192 of file iter.hh.


Constructor & Destructor Documentation

template<class Exact>
oln::abstract::iter< Exact >::iter (  )  [inline, protected]

Constructor.

Do nothing, used only by sub-classes

Definition at line 377 of file iter.hh.

00378       {}


Member Function Documentation

template<class Exact>
const point_type& oln::abstract::iter< Exact >::point_ref (  )  const [inline]

Accessor to current iterator's point.

Just return the current point of the iterator which is traversing an image.

Definition at line 201 of file iter.hh.

00202       {
00203         return p_;
00204       }

template<class Exact>
bool oln::abstract::iter< Exact >::operator== ( const abstract::point< point_type > &  p  )  const [inline]

Compare with the current iterator's point.

Compare the current iterator's point with p (his argument). If successful, return true.

Definition at line 214 of file iter.hh.

Referenced by oln::abstract::iter< mlc::exact_vt< oln::fwd_iter1d< Exact >, Exact >::ret >::operator!=().

00215       {
00216         return p_ == p.exact();
00217       }

template<class Exact>
bool oln::abstract::iter< Exact >::operator!= ( const abstract::point< point_type > &  p  )  const [inline]

Compare with the current iterator's point.

Compare the current iterator's point with p (his argument). If they are different, return true.

Definition at line 227 of file iter.hh.

00228       {
00229         return p_ != p.exact();
00230       }

template<class Exact>
point_type oln::abstract::iter< Exact >::operator+ ( const abstract::dpoint< dpoint_type > &  dp  )  const [inline]

Sum a move point to the current point.

Definition at line 241 of file iter.hh.

00242       {
00243         precondition(*this != end);
00244         return p_ + dp.exact();
00245       }

template<class Exact>
point_type oln::abstract::iter< Exact >::operator- ( const abstract::dpoint< dpoint_type > &  dp  )  const [inline]

Minor a move to the current point.

Definition at line 256 of file iter.hh.

00257       {
00258         precondition(*this != end);
00259         return p_ - dp.exact();
00260       }

template<class Exact>
oln::abstract::iter< Exact >::operator point_type (  )  const [inline]

Cast to exact point type.

Returns:
The exact point type.
Return the exact point type by calling sub-classes methods.

Definition at line 268 of file iter.hh.

00269       {
00270         return this->exact().to_point();
00271       }

template<class Exact>
point_type oln::abstract::iter< Exact >::cur (  )  const [inline]

Syntax improvement.

It's convenient to type `it.cur()' instead of `(point)it' when necessary.

Definition at line 280 of file iter.hh.

00281       {
00282         return *this;
00283       }

template<class Exact>
mlc::begin_type oln::abstract::iter< Exact >::operator= ( mlc::begin_type  b  )  [inline]

Set current point to the first iterator's point.

Set current point of iterator to the first iterator's point.

Definition at line 298 of file iter.hh.

Referenced by oln::fwd_iter3d< Exact >::operator=(), oln::fwd_iter2d< Exact >::operator=(), oln::fwd_iter1d< Exact >::operator=(), oln::bkd_iter3d< Exact >::operator=(), oln::bkd_iter2d< Exact >::operator=(), and oln::bkd_iter1d< Exact >::operator=().

00299       {
00300         this->exact().goto_begin_();
00301         return b;
00302       }

template<class Exact>
mlc::end_type oln::abstract::iter< Exact >::operator= ( mlc::end_type  e  )  [inline]

Set current point to the last iterator's point.

Set current point of iterator to the last iterator's point.

Definition at line 310 of file iter.hh.

00311       {
00312         this->exact().goto_end_();
00313         return e;
00314       }

template<class Exact>
bool oln::abstract::iter< Exact >::operator== ( mlc::end_type   )  const [inline]

Compare current point and last point.

Returns:
True if they are the same.
Compare current point with last iterator's point.

Definition at line 323 of file iter.hh.

00324       {
00325         return this->exact().is_at_end_();
00326       }

template<class Exact>
void oln::abstract::iter< Exact >::operator++ (  )  [inline]

Go to the next iterator's point.

Precondition:
Instance != end.

Definition at line 333 of file iter.hh.

00334       {
00335         precondition(*this != end);
00336         this->exact().goto_next_();
00337       }

template<class Exact>
bool oln::abstract::iter< Exact >::operator!= ( mlc::end_type  e  )  const [inline]

Compare current point and last point.

Returns:
True if they are different.
Compare current point with last iterator's point.

Definition at line 356 of file iter.hh.

00357       {
00358         return ! this->operator==(e);
00359       }


The documentation for this struct was generated from the following file:
Generated on Tue Feb 20 20:25:16 2007 for Olena by  doxygen 1.5.1