#include <Imagine/Common.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
using namespace std;
void base() {
cout <<
"Imagine++ version is " <<
VERSION << endl;
cout <<
"File named xxx in source path is replaced by: " <<
srcPath(
"xxx") << endl;
string name="xxx";
cout <<
"File named string xxx in source path is replaced by: " <<
stringSrcPath(name) << endl;
}
void fArrays() {
cout << "Testing FArray functions!" << endl;
char tt[]={'a','b','c'};
dd=b;
di=a;
cout << a.
size() << endl;
char x,y;
x=a[0];
c[0]=x;
x=y;
cout << *cit << endl;
*it='x';
if (a==b) cout << "a equals b" << endl;
if (a!=b) cout << "a is different from b" << endl;
range(a);
ofstream out("tmp.bin",ios::binary);
write(out,a);
out.close();
ifstream in("tmp.bin",ios::binary);
read(in,a);
in.close();
out.open("tmp.txt");
out << a << endl;
out.close();
in.open("tmp.txt");
in >> a;
in.close();
}
void fVectors() {
cout << "Testing FVector functions!" << endl;
double tt[]={1,2,3};
dd=c;
di=c;
double x,y,z;
x=f.x();
f.x()=x;
y=f.y();
f.y()=y;
z=f.z();
f.z()=z;
c=a+b;
c=a-b;
c+=a;
c-=a;
c=a+3.;
c=a-3.;
c+=3.;
c-=3.;
b=-a;
x=a*b;
c=a^b;
c=a*2;
c=a/2;
c*=2;
c/=2;
c=2.*a;
c=2.+a;
c=2.-a;
x=norm2(a);
x=norm(a);
c=normalized(dd);
dd.normalize();
x=maxNorm(a);
int i=intNorm2(di);
i=intNorm1(di);
(void)i;
x=doubleNorm2(di);
x=doubleNorm(di);
x=doubleNorm1(di);
x=sum(a);
c=mult(a,b);
c=div(a,b);
c=sqrt(a);
c=log(a);
c=exp(a);
c=pmin(a,b);
c=pmax(a,b);
x=squaredDist(di,di);
x=dist(di,di);
x=intL1Dist(di,di);
x=L1Dist(di,di);
}
void fMatrices() {
cout << "Testing FMatrix functions!" << endl;
double t1[6]={1,2,3,4,5,6};
double t2[2][3]={{1,2,3},{4,5,6}};
Ed=B;
Ei=B;
double x;
x=A(1,2);
A(1,2)=x;
x=A[4];
A[4]=x;
if (A==B) cout << "A equals B" << endl;
if (A!=B) cout << "A is different from B" << endl;
C=A+B;
C=A-B;
C+=A;
C-=A;
C=A+3.;
C=A-3.;
C+=3.;
C-=3.;
B=-A;
C=A*2;
C=A/2;
C*=2;
C/=2;
C=2.*A;
C=2.+A;
C=2.-A;
A34=A32*A24;
v3=A32*v2;
double t9[]={1,2,9,3,4,6,5,7,2};
v2=A23.getCol(0);
A23.setCol(0,v2);
v3=A23.getRow(0);
A23.setRow(0,v3);
x=norm2(A);
x=norm(A);
ofstream out("tmp.bin",ios::binary);
write(out,A);
out.close();
ifstream in("tmp.bin",ios::binary);
read(in,A);
in.close();
out.open("tmp.txt");
out << A << endl;
out.close();
in.open("tmp.txt");
in >> A;
in.close();
}
void colors() {
cout << "Testing Color functions!" << endl;
double t1[]={.2,1.,.23};
double x;
x=e.r();
e.r()=x;
x=e.g();
e.g()=x;
x=e.b();
e.b()=x;
x = (byte)123;
double t2[]={.2,1.,.23,.3};
x=n.r();
n.r()=x;
x=n.g();
n.g()=x;
x=n.b();
n.b()=x;
x=n.a();
n.a()=x;
col=YUV2RGB<byte>(yuv);
}
void arrays() {
cout << "Testing Array functions!" << endl;
char t[4]={'a','b','c','d'};
char* t2=new char[3];
list<char>l;
l.push_front('a');
b.setSize(5);
a=b;
di=b;
cout<< "a is empty" << endl;
b.fill('x');
char x;
x=b[2];
b[2]=x;
x=b.data()[2];
b.data()[2]=x;
cout << *cit << endl;
*it='x';
e=b.getSubArray(1,2);
if (a==b) cout << "a equals b" << endl;
if (a!=b) cout << "a is different from b" << endl;
range(a);
prange(f);
ofstream out("tmp.bin",ios::binary);
write(out,a);
out.close();
ifstream in("tmp.bin",ios::binary);
read(in,a);
in.close();
out.open("tmp.txt");
out << a << endl;
out.close();
in.open("tmp.txt");
in >> a;
in.close();
}
void coords() {
cout << "Testing coords functions!" << endl;
int t[]={1,2,3};
(void)d; (void)e;
it1=it2;
if (it1==it2) cout << "it1 equals it2" << endl;
if (it1!=it2) cout << "it1 is different from it2" << endl;
cout << *it << endl;
cout << it++->x() << endl;
f.prod();
}
void multiArrays() {
cout << "Testing multi Array functions!" << endl;
char t[6]={'a','b','c','d','e','f'};
char *t2=new char[6];
g.setSize(3,3);
i.setSize(3,2,1);
a=b;
ji=jc;
c3.width();
c3.height();
c3.depth();
c3.stride(1);
c2.offset(1,0);
c3.offset(1,0,1);
char x;
x=a(0,1);
a(0,1)=x;
x=c3(1,0,1);
c3(1,0,1)=x;
cout << "[" << *it << "]=" << i(*it) << endl;
ofstream out("tmp.bin",ios::binary);
write(out,i);
out.close();
ifstream in("tmp.bin",ios::binary);
read(in,i);
in.close();
out.open("tmp.txt");
out << i << endl;
out.close();
in.open("tmp.txt");
in >> i;
in.close();
}
void rands() {
cout << "Testing random functions!"<<endl;
}
void timers() {
cout << "Testing Timer functions!"<<endl;
(void)x;
}
void io() {
cout << "Testing IO functions!"<<endl;
}
int main(int argc, char* argv[]) {
typedef void (*FUNC)();
vector< pair<string,FUNC> > tests;
#define ADD_TEST(func) \
tests.push_back(make_pair(string(#func), func));
ADD_TEST(base);
ADD_TEST(fArrays);
ADD_TEST(fVectors);
ADD_TEST(fMatrices);
ADD_TEST(colors);
ADD_TEST(arrays);
ADD_TEST(coords);
ADD_TEST(multiArrays);
ADD_TEST(rands);
ADD_TEST(timers);
ADD_TEST(io);
std::vector< pair<string,FUNC> >::const_iterator it;
if(argc<=1)
for(it=tests.begin(); it!=tests.end(); ++it) {
cout << "---" << it->first << "---" << std::endl;
it->second();
}
else {
bool fail=false;
for(int i=1; i<argc; i++) {
for(it=tests.begin(); it!=tests.end(); ++it) {
if(it->first == argv[i]) {
cout << "---" << it->first << "---" << std::endl;
it->second();
break;
}
}
if(it==tests.end()) {
std::cout << "Unknown test " << argv[i] << endl;
fail = true;
}
}
if(fail) {
cout << "--- Available tests:" << endl;
for(it=tests.begin(); it!=tests.end(); ++it)
cout << it->first << ' ';
cout << endl;
return 0;
}
}
return 0;
}
Array of variable size.
Definition: Array.h:20
size_t size() const
Size.
Definition: Array.h:194
Array clone() const
Cloning.
Definition: Array.h:175
iterator begin()
Begin iterator.
Definition: Array.h:231
const T * const_iterator
Const iterator type.
Definition: Array.h:73
T * iterator
Iterator type.
Definition: Array.h:71
iterator end()
End iterator.
Definition: Array.h:245
bool empty() const
Is empty.
Definition: Array.h:187
Iterator on Coordinates.
Definition: Coords.h:83
Array of fixed size.
Definition: FArray.h:17
const T * data() const
Data pointer (read).
Definition: FArray.h:188
FArray & fill(const T &v)
Filling.
Definition: FArray.h:109
const T * const_iterator
Const iterator type.
Definition: FArray.h:27
T * iterator
Iterator type.
Definition: FArray.h:25
FArray & copy(const T2 t[S])
C array of different type copy.
Definition: FArray.h:121
int size() const
Size.
Definition: FArray.h:159
Matrix of fixed dimension.
Definition: FMatrix.h:17
const T * data() const
Data pointer (read).
Definition: FMatrix.h:182
FMatrix & fill(const T &v)
Filling.
Definition: FMatrix.h:78
int ncol() const
Number of columns.
Definition: FMatrix.h:129
int nrow() const
Number of rows.
Definition: FMatrix.h:122
int size() const
Size.
Definition: FMatrix.h:115
Vector of fixed size.
Definition: FVector.h:17
FVector & fill(const T &v)
Filling.
Definition: FVector.h:75
nD array of variable size.
Definition: MultiArray.h:21
FArray< size_t, dim > stride() const
Stride.
Definition: MultiArray.h:253
MultiArray getSubArray(const Coords< dim > &offset, const Coords< dim > &sz) const
Sub array.
Definition: MultiArray.h:269
MultiArray & fill(T x)
Filling.
Definition: MultiArray.h:204
size_t totalSize() const
Total Size.
Definition: MultiArray.h:218
int size(int i) const
ith size.
Definition: MultiArray.h:225
MultiArray clone() const
Cloning.
Definition: MultiArray.h:191
Coords< dim > sizes() const
Sizes.
Definition: MultiArray.h:211
RED GREEN BLUE Alpha color.
Definition: Color.h:138
RED GREEN BLUE color.
Definition: Color.h:26
Timers.
Definition: Timer.h:15
void reset()
Reset.
Definition: Timer.h:51
double lap() const
Lap.
Definition: Timer.h:43
FMatrix< T, M, O > multt(const FMatrix< T, M, N > &A, const FMatrix< T, O, N > &B)
Product.
Definition: FMatrix.h:630
void initRandom(unsigned int s)
Init with seed.
Definition: Random.h:18
FMatrix< T, M, M > Diagonal(const FVector< T, M > &d)
Diagonal.
Definition: FMatrix.h:743
bool saveText(const T &obj, std::string filename, int precision=-1)
Object saving.
Definition: IO.h:67
T det(const FMatrix< T, M, M > &A)
Determinant.
Definition: FMatrix.h:717
#define srcPath(s)
Transform relative file path to absolute path.
Definition: Base.h:51
const Color PURPLE
Predefined color.
Definition: Color.h:341
unsigned int uintRandom(unsigned int a)
Uniform unsigned int.
Definition: Random.h:66
const Color CYAN
Predefined color.
Definition: Color.h:323
const Color BLACK
Predefined color.
Definition: Color.h:293
const Color YELLOW
Predefined color.
Definition: Color.h:317
bool loadBinary(T &obj, std::string filename)
Object loading.
Definition: IO.h:47
#define stringSrcPath(s)
Transform relative file path to absolute path.
Definition: Base.h:52
const Color WHITE
Predefined color.
Definition: Color.h:287
FMatrix< T, M, M > inverse(const FMatrix< T, M, M > &A)
Inverse.
Definition: FMatrix.h:678
FMatrix< T, N, M > transpose(const FMatrix< T, M, N > &A)
Transpose.
Definition: FMatrix.h:564
double doubleRandom()
Uniform double.
Definition: Random.h:38
size_t size_tRandom(size_t a)
Uniform size_t.
Definition: Random.h:77
void waitKey(const char *message="Press <enter> to continue...")
Pause in program execution until key press.
Definition: IO.h:13
bool saveBinary(const T &obj, std::string filename)
Object saving.
Definition: IO.h:88
FMatrix< T, N, O > tmult(const FMatrix< T, M, N > &A, const FMatrix< T, M, O > &B)
Product.
Definition: FMatrix.h:615
double gaussianRandom()
Normal law.
Definition: Random.h:87
FMatrix< T, N, O > tmultt(const FMatrix< T, M, N > &A, const FMatrix< T, O, M > &B)
Product.
Definition: FMatrix.h:645
int intRandom(int a, int b)
Uniform int.
Definition: Random.h:55
const std::string VERSION
version of libraries.
Definition: Base.h:16
FVector< double, 3 > RGB2YUV(const RGB< T > &rgb)
RGB to YUV.
Definition: Color.h:411
const Color ORANGE
Predefined color.
Definition: Color.h:335
const AlphaColor AWHITE
Predefined color.
Definition: Color.h:360
const Color BLUE
Predefined color.
Definition: Color.h:299
bool loadText(T &obj, std::string filename)
Object loading.
Definition: IO.h:28
RGB< byte > Color
RGB<byte> alias.
Definition: Color.h:281
const Color MAGENTA
Predefined color.
Definition: Color.h:329
const Color RED
Predefined color.
Definition: Color.h:305
const Color GREEN
Predefined color.
Definition: Color.h:311
Image< byte, dim > grey(const Image< T, dim > &I, T m, T M)
Grey level representation.
Definition: IO.h:289