Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleArray2D.cpp

Example for usage of class Array2D

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@example ExampleArray2D.cpp
@relates Array2D
@brief Example for usage of class Array2D
@ingroup g_examples
@author MIP
*/
#include <Base/Common/Array2D.hh>
#include <iostream>
using namespace BIAS;
using namespace std;
/** \cond POORLY_NAMED_EXAMPLE_CLASSES **/
/* foo */
class foo
{
public:
void set(const double d) { data=d; }
double get() const { return data; }
protected:
double data;
};
void print(Array2D<foo> &a)
{
const unsigned nr = a.nrows(), nc = a.ncols();
cout << nr << " x "<< nc <<" :\n";
for (unsigned r=0; r<nr; r++){
for (unsigned c=0; c<nc; c++){
cout << a(r,c).get() << "\t";
}
cout << "\n";
}
}
/** \endcond */
int main()
{
Array2D<foo> array;
cout << "empty Array2D: ";
print(array);
cout << "empty() = "<<boolalpha<<array.empty()<<endl;
array.resize(2,2);
cout << "empty Array2D of size 2x2 : ";
print(array);
foo f;
f.set(2.0);
array.fill(f);
cout << "filled Array2D of size 2x2 : ";
print(array);
array.resize(3,3);
cout << "partially filled Array2D of size 3x3 : ";
print(array);
int i=0;
for (it = array.begin(); it!=array.end(); it++, i++){
it->set((double)i);
}
cout << "filled Array2D of size 3x3 : ";
print(array);
cout << "array[1][1] = "<<array[1][1].get()<<endl;
// should throw
//cout << array(3,3).get()<<endl;
return 0;
}