#line 1 "/user/cvsspst/ees1cg/RAVL/RAVL-0.7/Core/Container/Array/Array2dSqr31Iter2.hh"
// This file is part of RAVL, Recognition And Vision Library
// Copyright (C) 2001, University of Surrey
// This code may be redistributed under the terms of the GNU Lesser
// General Public License (LGPL). See the lgpl.licence file for details or
// see http://www.gnu.org/copyleft/lesser.html
// file-header-ends-here
#ifndef RAVL_ARRAY2DSQR31ITER2_HEADER
#define RAVL_ARRAY2DSQR31ITER2_HEADER 1
//////////////////////////////////////////////////////////////////
//! rcsid="$Id: Array2dSqr31Iter2.hh,v 1.6 2002/04/29 18:13:06 craftit Exp $"
//! docentry="Ravl.Core.Arrays.2D"
//! author="Charles Galambos"
//! lib=RavlCore
//! file="Ravl/Core/Container/Array/Array2dSqr31Iter2.hh"
#include "Ravl/Array2d.hh"
#include "Ravl/BfAcc2Iter2.hh"
namespace RavlN {
//! userlevel=Normal
//: Iterate through an array accessing 3x3 area.
// The square can be accessed with DataBL,DataBR etc...
// which access the following array elements.
// TL TM TR
// ML MM MR
// BL BM BR
// for the first array.
template
class Array2dSqr31Iter2C
: protected BufferAccess2dIter2C
{
public:
Array2dSqr31Iter2C()
{}
//: Default constructor.
Array2dSqr31Iter2C(const Array2dC &narray1,const Array2dC &narray2)
: array1(narray1),
array2(narray2)
{ First(); }
//: Constructor.
bool First() {
// Setup second index size for the two arrays.
rng1 = IndexRangeC(array1.Range2().Min()+1,array1.Range2().Max()-1);
rng2 = array2.Range2();
rng2.ClipBy(rng1);
// Setup first index for the two arrays.
IndexRangeC srng1(array1.Range1().Min()+1,array1.Range1().Max()-1);
IndexRangeC srng2 = array2.Range1();
srng2.ClipBy(srng1);
if(!rit.First(array1,srng1,
array2,srng2)) {
cit.Invalidate();
return false;
}
cit.First(rit.Data1(),rng1,
rit.Data2(),rng2);
if(!cit) {
cit.Invalidate();
return false;
}
up = &((&(rit.Data1()))[-1][rng1.Min()]);
dn = &((&(rit.Data1()))[ 1][rng1.Min()]);
return true;
}
//: Goto first element in the array.
bool Next() {
up++;
dn++;
cit++;
if(cit)
return true;
up = &((rit.Data1())[rng1.Min()]);
dn = &((&(rit.Data1()))[2][rng1.Min()]);
rit++;
if(!rit)
return false;
cit.First(rit.Data1(),rng1,
rit.Data2(),rng2);
return false;
}
//: Goto next element.
bool IsElm() const
{ return cit.IsElm(); }
//: Test if iterator is at a valid element.
operator bool() const
{ return cit.IsElm(); }
//: Test if iterator is at a valid element.
void operator++()
{ Next(); }
//: Goto next element.
void operator++(int)
{ Next(); }
//: Goto next element.
Data1T &DataBL1()
{ return dn[-1]; }
//: Access bottom left data element
const Data1T &DataBL1() const
{ return dn[-1]; }
//: Access bottom left data element
Data1T &DataBM1()
{ return *dn; }
//: Access bottom mid data element
const Data1T &DataBM1() const
{ return *dn; }
//: Access bottom mid data element
Data1T &DataBR1()
{ return dn[1]; }
//: Access bottom right data element
const Data1T &DataBR1() const
{ return dn[1]; }
//: Access bottom right data element
Data1T &DataML1()
{ return (&(cit.Data1()))[-1]; }
//: Access middle left data element
const Data1T &DataML1() const
{ return (&(cit.Data1()))[-1]; }
//: Access middle left data element
Data1T &DataMM1()
{ return cit.Data1(); }
//: Access middle data element
const Data1T &DataMM1() const
{ return cit.Data1(); }
//: Access middle data element
Data1T &DataMR1()
{ return (&(cit.Data1()))[1]; }
//: Access middle right data element
const Data1T &DataMR1() const
{ return (&(cit.Data1()))[1]; }
//: Access middle right data element
Data1T &DataTL1()
{ return up[-1]; }
//: Access top left data element.
const Data1T &DataTL1() const
{ return up[-1]; }
//: Access top left data element
Data1T &DataTM1()
{ return *up; }
//: Access top middle element
const Data1T &DataTM1() const
{ return *up; }
//: Access top middle element
Data1T &DataTR1()
{ return up[1]; }
//: Access top right data element
const Data1T &DataTR1() const
{ return up[1]; }
//: Access top right data element
Data2T &Data2()
{ return cit.Data2(); }
//: Access middle data element of second array.
const Data2T &Data2() const
{ return cit.Data2(); }
//: Access middle data element of second array.
protected:
Array2dC array1;
Array2dC array2;
Data1T *up;
Data1T *dn;
};
}
#endif