#ifndef NARRAY2D_HH #define NARRAY2D_HH ///////////////////////////////////////////////////////////////////////// //! file="amma/StdType/StdArray/NArray2d.hh" //! lib=MstdArr //! userlevel=Normal //! author="Radek Marik" //! docentry="Containers.Arrays.2-D Arrays" //! rcsid="$Id: NArray2d.hh,v 1.11 2000/10/04 12:41:55 ees1cg Exp $" //! date="06/08/95" #include #include "amma/Index.hh" #include "amma/IndexR2d.hh" #include "amma/Array1d.hh" #include "amma/Array2d.hh" #include "amma/NArray1d.hh" class Index2dC; class IndexRectangleC; //: A 2 dimensional numerical array template class NumArray2dC: public Array2dC { public: NumArray2dC(); //: Default constructor. // Creates an empty array. NumArray2dC(const Array2dC & vv); //: Constructor from normal array. NumArray2dC(const SizeT rdim, const SizeT cdim); //: Constructor NumArray2dC(const IndexRangeC & rowRange, const IndexRangeC & colRange); //: Range constructor. NumArray2dC(const IndexRange2dC & range); //: Range constructor. NumArray2dC(const IndexRectangleC & rect); // Creates 2D array with the range covering indexes in 'rect'. NumArray2dC(const NumArray2dC & vv); //: Copy constructor. NumArray2dC Copy() const; //: Make a copy. NumArray2dC & SetZero(); // Sets all value of the array to be zero. NumArray2dC & Set(const DataC & data); // Sets all items of the array to be 'data'. void SetRow(IndexT r, const DataC & data); // Sets all items in the row 'r' to be 'data'. void SetCol(IndexT c, const DataC & data); // Sets all items in the column 'c' to be 'data'. inline Index2dC RangeMin() const; // Returns the minimum index of the array. inline Index2dC RangeMax() const; // Returns the maximum index of the array. inline BooleanT Contains(const Index2dC & i) const; // Returns TRUE, if there is an item of the 2D array. void DebugAddresses() const; // Prints addresses. // friend istream & operator>>(istream & s, NumArray2dC & arr); }; template ostream & operator<<(ostream & s, const NumArray2dC & arr) { return operator<<(s,(const Array2dC &) arr); } template istream & operator>>(istream & s, NumArray2dC & arr) { return operator>>(s,(Array2dC &) arr); } #include #include "amma/StdStrm.hh" #include "amma/Index2d.hh" #include "amma/IndRect.hh" template NumArray2dC::NumArray2dC() {} template NumArray2dC::NumArray2dC(const Array2dC & vv) : Array2dC(vv) {} template NumArray2dC::NumArray2dC(const SizeT rdim, const SizeT cdim) : Array2dC(rdim,cdim) {} template NumArray2dC::NumArray2dC(const IndexRangeC & rowRange, const IndexRangeC & colRange) : Array2dC< DataC >(rowRange,colRange) {} template NumArray2dC::NumArray2dC(const IndexRange2dC & range) : Array2dC< DataC >(range.RowRange(),range.ColRange()) {} template NumArray2dC::NumArray2dC(const IndexRectangleC & rect) : Array2dC< DataC >(rect) {} //IndexRangeC(rect.Origin().Row(),rect.End().Row()) template NumArray2dC::NumArray2dC(const NumArray2dC & vv) : Array2dC< DataC >(vv) {} template NumArray2dC NumArray2dC::Copy() const { return Array2dC::Copy(); } template NumArray2dC & NumArray2dC::SetZero() { Fill(0); return *this; } template NumArray2dC & NumArray2dC::Set(const DataC & data) { Fill(data); return *this; } template inline Index2dC NumArray2dC::RangeMin() const //================================== { return Index2dC(Range1().Min(), Range2().Min()); } template inline Index2dC NumArray2dC::RangeMax() const //================================== { return Index2dC(Range1().Max(), Range2().Max()); } template inline void NumArray2dC::SetRow(IndexT r, const DataC & data) //====================================================== { IndexRangeC range(Range2()); for (Index2dC i(r, range.Min()); i.Col() <= range.Max(); i.Col()++) (*this)[i] = data; } template inline void NumArray2dC::SetCol(IndexT c, const DataC & data) //====================================================== { IndexRangeC range(Range1()); for (Index2dC i(range.Min(), c); i.Row() <= range.Max(); i.Row()++) (*this)[i] = data; } template inline BooleanT NumArray2dC::Contains(const Index2dC & i) const //==================================================== { return Range1().Contains(i.Row()) && Range2().Contains(i.Col()); } template void NumArray2dC::DebugAddresses() const //======================================= { cerrAMMA << "NumArray2dC::DebugAddresses() "; Array1dC< NumArray1dC >::DebugAddresses(); FOR_ARRAY1(*this, i) { cerrAMMA << i << ' '; (*this)[i].DebugAddresses(); } } #endif // IAPS - Image analysis program system. // End of include file NArray2d.hh