#ifndef ARRAY3D_HH #define ARRAY3D_HH /////////////////////////////////////////////////////////////////////// //! file="amma/Contain/Array/Array3/Array3d.hh" //! lib=Marr3 //! author="Radek Marik" //! date="2/5/1993" //! docentry="Containers.Arrays.3-D Arrays" //! rcsid="$Id: Array3d.hh,v 1.18 2000/10/04 12:40:17 ees1cg Exp $" #include "amma/Index3d.hh" #include "amma/Array2d.hh" class istream; class ostream; //======================================================================== //================= Array3dC ============================================= //======================================================================== //! userlevel=Basic //: 3 Dimensional Array // The class Array3dC is a general container with index access. // It is reference counted, eg. it behaves as a big object. template class Array3dC : public Array2dC< RangeBufferAccessC > { public: // Constructors, copy, assigment, and destructor. // ---------------------------------------------- Array3dC(const SizeT dim1 = 0, const SizeT dim2 = 0, const SizeT dim3 = 0); //: Creates a 3D array which value are set by default constructor //: of an item. The range of indexes is <(0,0,0); (dim1-1, dim2-1, dim3-1)>. Array3dC(const Index3dC & maxIndex); //: Creates 3D array with range <(0,0,0); maxIndex>. Array3dC(const IndexRangeC & rng1, const IndexRangeC & rng2, const IndexRangeC & rng3); //: Creates a 3D array which value are set by the default constructor //: of an item. The range of indexed is determined by ranges 'rng1', 'rng2', //: and 'rng3'. void Fill(const DataC &v); //: Fill array with values. Array3dC Copy() const; //: Creates a physical copy of this object. // Access to the information about the object. // ------------------------------------------- const IndexRangeC & Range3() const; //: Returns the range of the third index. inline RangeBufferAccessC > & operator[](const IndexT i) { return Array2dC< RangeBufferAccessC > ::operator[](i); } //: access to the array[i] inline const RangeBufferAccessC > & operator[](const IndexT i) const { return Array2dC< RangeBufferAccessC > ::operator[](i); } //: return array[i] const RangeBufferAccessC & operator[](const Index2dC i) const; //: Access to an item of the constant object. RangeBufferAccessC& operator[](const Index2dC i); //: Access to an item of the object. const DataC & operator[](const Index3dC & i) const; //: Access to an item of the constant object. DataC & operator[](const Index3dC & i); //: Access to an item of the object. // Logical operations on the object. // --------------------------------- BooleanT Contains(const IndexT i1, const IndexT i2, const IndexT i3) const; //: Returns TRUE, if the triple (i1, i2, i3) addresses the item of the //: object. BooleanT Contains(const Index3dC & i) const; //: Returns TRUE, if the index 'i' addresses the item of the object. protected: void ConstructAccess(); //: Construct access to array. private: // The representation of an object. // -------------------------------- IndexRangeC range3; // The range of the third index. BufferRC data; // Raw data stored in array. }; //template //ostream & operator<<(ostream & s, const Array3dC & arr); //template //istream & operator>>(istream & s, Array3dC & arr); #define FOR_ARRAY3D(array, index1, index2, index3) \ for(IndexT index1 = array.Range1().Min(); \ index1 <= array.Range1().Max() ; index1++) \ for(IndexT index2 = array.Range2().Min(); \ index2 <= array.Range2().Max() ; index2++) \ for(IndexT index3 = array.Range3().Min(); \ index3 <= array.Range3().Max() ; index3++) //: Slow, Use iterators... #include "amma/Arr2Iter.hh" template BooleanT Array3dC::Contains(const IndexT i1, const IndexT i2, const IndexT i3) const //============================================== { return Range1().Contains(i1) && Range2().Contains(i2) && Range3().Contains(i3); } template BooleanT Array3dC::Contains(const Index3dC & i) const //================================================= { return Range1().Contains(i.I()) && Range2().Contains(i.J()) && Range3().Contains(i.K()); } template const IndexRangeC &Array3dC::Range3() const { return range3; } template void Array3dC::ConstructAccess() { const int d3Size = range3.Size(); DataC *at = data.Access().ReferenceElm(); for(Array2dIterC > it(*this); it.IsElm();it.Next(),at += d3Size) it.Data() = RangeBufferAccessC (at,range3); } template Array3dC::Array3dC(const SizeT dim1, const SizeT dim2, const SizeT dim3) : Array2dC< RangeBufferAccessC >(dim1,dim2), range3(0, dim3-1), data(dim1 * dim2 * dim3) { ConstructAccess(); } template Array3dC::Array3dC(const Index3dC & maxIndex) : Array2dC< RangeBufferAccessC >(maxIndex[0],maxIndex[1]), range3(0, maxIndex[2]-1), data(maxIndex[0]*maxIndex[1]*maxIndex[2]) { ConstructAccess(); } template Array3dC::Array3dC(const IndexRangeC & rng1, const IndexRangeC & rng2, const IndexRangeC & rng3) : Array2dC< RangeBufferAccessC >(rng1,rng2), range3(rng3), data(rng1.Size() * rng2.Size() * rng3.Size()) { ConstructAccess(); } template RangeBufferAccessC & Array3dC::operator[](const Index2dC i) { return Array2dC< RangeBufferAccessC >::operator[](i); } template const RangeBufferAccessC & Array3dC::operator[](const Index2dC i) const { return Array2dC< RangeBufferAccessC >::operator[](i); } template const DataC & Array3dC::operator[](const Index3dC & i) const { return Array2dC< RangeBufferAccessC >::operator[](Index2dC(i.I(),i.J()))[i.K()]; } template DataC & Array3dC::operator[](const Index3dC & i) { return Array2dC< RangeBufferAccessC >::operator[](Index2dC(i.I(),i.J()))[i.K()]; } template void Array3dC::Fill(const DataC &v) { for(Array2dIterC > it(*this);it.IsElm();it.Next()) it.Data().Fill(v); } template Array3dC Array3dC::Copy() const //=========================== { Array3dC ret(Range1(),Range2(),Range3()); for(RangeBufferAccessIter2C > ,RangeBufferAccessC > > it(ret,*this); it.IsElm();it.Next()) for(RangeBufferAccessIter2C,RangeBufferAccessC > it2(it.Data1(),it.Data2()); it2.IsElm();it2.Next()) for(RangeBufferAccessIter2C it3(it2.Data1(),it2.Data2()); it3.IsElm();it3.Next()) it3.Data1() = it3.Data2(); return ret; } template ostream & operator<<(ostream & s, const Array3dC & arr) //================================================== { s << arr.Range1() << ' ' << arr.Range2() << ' ' << arr.Range3() << '\n'; for(Array2dIterC > it(arr);it.IsElm();it.Next()) s << it.Data(); return s; } template istream & operator>>(istream & s, Array3dC & arr) //============================================ { IndexRangeC ir1,ir2,ir3; s >> ir1 >> ir2 >> ir3; arr = Array3dC(ir1,ir2,ir3); for(Array2dIterC > it(arr);it.IsElm();it.Next()) s >> it.Data(); return s; } #endif // IAPS - Image analysis program system. // End of include file Array3d.hh