Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TestImageAssign.cpp
1 #include <Base/Image/Image.hh>
2 
3 #include <string>
4 
5 using namespace BIAS;
6 using namespace std;
7 
8 int main(int argc, char *argv[])
9 {
10  const unsigned width=640, height=480, cc=1;
11  const bool interleaved = true;
12  ImageBase fib(width, height, cc, ImageBase::ST_float, interleaved);
13  ImageBase fib2(width, height, cc, ImageBase::ST_float, interleaved);
14  ImageBase ucib(width, height, cc, ImageBase::ST_unsignedchar, interleaved);
15  ImageBase ucib2(width, height, cc, ImageBase::ST_unsignedchar, interleaved);
16  Image<float> fi(width, height, cc, interleaved);
17  Image<float> fi2(width, height, cc, interleaved);
18  Image<unsigned char> uci(width, height, cc, interleaved);
19  Image<unsigned char> uci2(width, height, cc, interleaved);
20 
21  //////////////////////////////////////////
22  // assign compatible storage types
23  //////////////////////////////////////
24 
25  // assign ImageBase to ImageBase
26  try {
27  fib = fib2;
28  } catch (BaseException &ex) {
29  cerr << "Assigning ImageBase float to ImageBase float failed:"<<ex.What()<<endl;
30  BIASABORT;
31  }
32  try {
33  ucib = ucib2;
34  } catch (BaseException &ex) {
35  cerr << "Assigning ImageBase unsigned char to ImageBase unsigned char "
36  <<"failed:"<<ex.What()<<endl;
37  BIASABORT;
38  }
39  // assign Image<StorageType> to Image<StorageType>
40  try {
41  fi = fi2;
42  } catch (BaseException &ex) {
43  cerr << "Assigning Image<float> to Image<float> failed:"<<ex.What()<<endl;
44  BIASABORT;
45  }
46  try {
47  uci = uci2;
48  } catch (BaseException &ex) {
49  cerr << "Assigning Image<unsigned char> to Image<unsigned char> failed:"<<ex.What()<<endl;
50  BIASABORT;
51  }
52  // assign ImageBase to Image<StorageType>
53  try {
54  fi = fib;
55  } catch (BaseException &ex) {
56  cerr << "Assigning ImageBase float to Image<float> failed:"<<ex.What()<<endl;
57  BIASABORT;
58  }
59  try {
60  uci = ucib;
61  } catch (BaseException &ex) {
62  cerr << "Assigning ImageBase unsigned char to Image<unsigned char> failed:"<<ex.What()<<endl;
63  BIASABORT;
64  }
65  // assign Image<StorageType> to ImageBase
66  try {
67  fib = fi;
68  } catch (BaseException &ex) {
69  cerr << "Assigning Image<float> to ImageBase float failed:"<<ex.What()<<endl;
70  BIASABORT;
71  }
72  try {
73  ucib = uci;
74  } catch (BaseException &ex) {
75  cerr << "Assigning Image<unsigned char> to ImageBase unsigned char "
76  <<"failed:"<<ex.What()<<endl;
77  BIASABORT;
78  }
79 
80  //////////////////////////////////////////
81  // assign incompatible storage types
82  //////////////////////////////////////
83 
84  // assign ImageBase to ImageBase
85  bool caught_exception = false;
86  try { fib = ucib; }
87  catch (BaseException &ex) { caught_exception = true;cout<<"Expected error:"<<ex.What()<<endl; }
88  if (!caught_exception){
89  cerr << "Error: Assigning ImageBase unsigned char to ImageBase float "
90  <<"succeeded\n";
91  BIASABORT;
92  }
93  caught_exception = false;
94  try { ucib = fib; }
95  catch (BaseException &ex) { caught_exception = true;cout<<"Expected error:"<<ex.What()<<endl; }
96  if (!caught_exception){
97  cerr << "Error: Assigning ImageBase float to ImageBase unsigned char "
98  <<"succeeded\n";
99  BIASABORT;
100  }
101  // assign Image<StorageType> to Image<StorageType>
102  // actually I would rather have a compiler error here, but this is
103  // impossible as long as we acompiler error
104  caught_exception = false;
105  try { fi = uci; }
106  catch (BaseException &ex) { caught_exception = true;cout<<"Expected error:"<<ex.What()<<endl; }
107  if (!caught_exception){
108  cerr << "Error: Assigning Image<unsigned char> to Image<float> "
109  <<"succeeded\n";
110  BIASABORT;
111  }
112  caught_exception = false;
113  try { uci = fi; }
114  catch (BaseException &ex) { caught_exception = true;cout<<"Expected error:"<<ex.What()<<endl; }
115  if (!caught_exception){
116  cerr << "Error: Assigning Image<float> to Image<unsigned char> "
117  <<"succeeded\n";
118  BIASABORT;
119  }
120 
121  // assign ImageBase to Image<StorageType>
122  caught_exception = false;
123  try { uci = fib; }
124  catch (BaseException &ex) { caught_exception = true; cout<<"Expected error:"<<ex.What()<<endl;}
125  if (!caught_exception){
126  cerr << "Error: Assigning ImageBase float to Image<unsigned char> "
127  <<"succeeded\n";
128  BIASABORT;
129  }
130  caught_exception = false;
131  try { fi = ucib; }
132  catch (BaseException &ex) { caught_exception = true; cout<<"Expected error:"<<ex.What()<<endl;}
133  if (!caught_exception){
134  cerr << "Error: Assigning ImageBase unsigned char to Image<float> "
135  <<"succeeded\n";
136  BIASABORT;
137  }
138 
139  // assign Image<StorageType> to ImageBase
140  caught_exception = false;
141  try { ucib = fi; }
142  catch (BaseException &ex) { caught_exception = true;cout<<"Expected error:"<<ex.What()<<endl; }
143  if (!caught_exception){
144  cerr << "Error: Assigning Image<float> to ImageBase unsigned char "
145  <<"succeeded\n";
146  BIASABORT;
147  }
148  caught_exception = false;
149  try { fib = uci; }
150  catch (BaseException &ex) { caught_exception = true;cout<<"Expected error:"<<ex.What()<<endl; }
151  if (!caught_exception){
152  cerr << "Error: Assigning Image<unsigned char> to ImageBase float "
153  <<"succeeded\n";
154  BIASABORT;
155  }
156 
157  if (argc==1){ cout << "OK\n"; }
158  return 0;
159 }
float image storage type
Definition: ImageBase.hh:118
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
generic exception
Definition: Exception.hh:77
virtual const std::string & What() const
Definition: Exception.hh:95