DGtal  1.2.0
testImageSimple.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/kernel/domains/HyperRectDomain.h"
34 #include "DGtal/kernel/SpaceND.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/images/CImage.h"
37 #include "DGtal/images/Image.h"
38 #include "DGtal/images/ImageContainerBySTLVector.h"
40 
41 using namespace std;
42 using namespace DGtal;
43 
45 // Functions for testing class ImageSimple.
47 
52 {
53  unsigned int nbok = 0;
54  unsigned int nb = 0;
55 
56  trace.beginBlock ( "Testing Boost concept ..." );
58  BOOST_CONCEPT_ASSERT(( concepts::CImage< MyImage > ));
59 
60  nbok ++;
61 
62 
63  nb++;
64  trace.info() << "(" << nbok << "/" << nb << ") "
65  << "true == true" << std::endl;
66  trace.endBlock();
67 
68  return nbok == nb;
69 }
70 
71 
72 bool testCreate()
73 {
74  unsigned int nbok = 0;
75  unsigned int nb = 0;
76 
77  trace.beginBlock ( "Testing Image Create ..." );
79  typedef Image<VImage > MyImage;
80  BOOST_CONCEPT_ASSERT(( concepts::CImage< MyImage > ));
81 
82  Z2i::Point a(0,0);
83  Z2i::Point b(128,128);
84  Z2i::Domain domain(a,b);
85  MyImage image( new VImage(domain) );
86 
87  trace.info()<<image<<std::endl;
88  trace.info()<<*image.getPointer()<<std::endl;
89 
90  nbok += image.isValid() ? 1 : 0;
91  nb++;
92 
93  typedef HyperRectDomain<SpaceND <6> > Domain6;
95  typedef Image<VImage6 > MyImage6;
96  BOOST_CONCEPT_ASSERT(( concepts::CImage< MyImage6 > ));
97 
98  Z2i::Integer aa[] = {0,0,0,0,0,0};
99  Z2i::Integer bb[] = {2,2,2,2,2,2};
100  Domain6::Point A(aa);
101  Domain6::Point B(bb);
102 
103  MyImage6 imageBis( new VImage6( Domain6(A,B) ) );
104  trace.warning() << "Dimension 6 image"<<std::endl;
105  trace.info()<< imageBis <<std::endl;
106 
107  nbok += imageBis.isValid() ? 1 : 0;
108  nb++;
109 
110 
111  trace.info() << "(" << nbok << "/" << nb << ") "
112  << "true == true" << std::endl;
113  trace.endBlock();
114 
115  return nbok == nb;
116 }
117 
118 bool testAPI()
119 {
120  unsigned int nbok = 0;
121  unsigned int nb = 0;
122 
123  trace.beginBlock ( "Testing Image API ..." );
125  typedef Image<VImage > MyImage;
126  BOOST_CONCEPT_ASSERT(( concepts::CImage< MyImage > ));
127 
128  Z2i::Point a(0,0);
129  Z2i::Point b(32,32);
130  Z2i::Point c(12, 14);
131 
132  Z2i::Domain domain(a,b);
133  MyImage image( new VImage(domain) );
134 
135  trace.info()<<image<<std::endl;
136 
137 
138  nbok += image.isValid() ? 1 : 0;
139  nb++;
140 
141  image.setValue(c, 42);
142  trace.info()<< "Value at "<<c<<" = "<< image(c)<<std::endl;
143 
144  trace.warning() << "Image Iterate"<<std::endl;
145  trace.info()<<std::endl;
146  MyImage::ConstRange r = image.constRange();
147  for(MyImage::ConstRange::ConstIterator it =r.begin(), ite=r.end();
148  it != ite; ++it)
149  std::cerr << (*it)<<" ";
150 
151  trace.info()<<std::endl;
152 
153  nbok += (image(c) == 42) ? 1 : 0;
154  nb++;
155 
156  trace.info() << "(" << nbok << "/" << nb << ") "
157  << "true == true" << std::endl;
158  trace.endBlock();
159 
160  return nbok == nb;
161 }
162 
164 {
165  unsigned int nbok = 0;
166  unsigned int nb = 0;
167 
168  trace.beginBlock ( "Testing copy of Image..." );
170  typedef Image<VImage > MyImage;
171  BOOST_CONCEPT_ASSERT(( concepts::CImage< MyImage > ));
172 
173  Z2i::Point a(0,0);
174  Z2i::Point b(32,32);
175  Z2i::Point c(12, 14);
176 
177  Z2i::Domain domain(a,b);
178  MyImage image( new VImage(domain) );
179 
180  trace.info()<<image<<std::endl;
181 
182  nbok += image.isValid() ? 1 : 0;
183  nb++;
184 
185  //Image pointer
186  VImage * imContainer =
187  new VImage(domain);
188 
189  //Image through smart pointer
190  //(that takes ownership and must free the memory)
191  MyImage image2(imContainer);
192 
193  const MyImage::ImagePointer p = image2.getPointer();
194  trace.info() << p << std::endl;
195  trace.info() << *p << std::endl;
196 
197  nbok += (image2.isValid()) ? 1 : 0;
198  nb++;
199 
200  trace.info() << p.get() << std::endl;
201  trace.info() << imContainer << std::endl;
202  nbok += (p.get() == imContainer) ? 1 : 0;
203  nb++;
204 
205  trace.info() << "(" << nbok << "/" << nb << ") "
206  << "true == true" << std::endl;
207 
208  trace.endBlock();
209 
210  return nbok == nb;
211 }
213 {
214  unsigned int nbok = 0;
215  unsigned int nb = 0;
216 
217  trace.beginBlock ( "Testing smart copy of Image..." );
219  typedef Image<VImage > MyImage;
220  BOOST_CONCEPT_ASSERT(( concepts::CImage< MyImage > ));
221 
222  Z2i::Point a(0,0);
223  Z2i::Point b(32,32);
224  Z2i::Point c(12, 14);
225 
226  Z2i::Domain domain(a,b);
227 
228  MyImage image( new VImage(domain) );
229  trace.info() << "Image constructed: "<< image <<std::endl;
230 
231  VImage myImageC( domain );
232  MyImage imageFromConstRef ( myImageC );
233  trace.info() << "Image constructed (from constRef): "<< imageFromConstRef <<std::endl;
234  nbok += (imageFromConstRef.getPointer().count()== 2) ? 1 : 0;
235  nb++;
236  trace.info() << "(" << nbok << "/" << nb << ") "
237  << "unique" << std::endl;
238 
239  MyImage image3;
240  trace.info() << "Image constructed (degulat): "<< image3 <<std::endl;
241 
242 
243  trace.info() << "default: "<< image3 <<std::endl;
244  image3 = image;
245  nbok += (image3.getPointer().count()== 3) ? 1 : 0;
246  nb++;
247  trace.info() << "(" << nbok << "/" << nb << ") "
248  << "true == true" << std::endl;
249  trace.info() << "assignment: "<< image3 <<std::endl;
250  nbok += (image3.getPointer().count()== 3) ? 1 : 0;
251  nb++;
252  trace.info() << "(" << nbok << "/" << nb << ") "
253  << "true == true" << std::endl;
254 
255  image3.setValue(Z2i::Point(1,1), 4);
256  trace.info() << "setValue on assigned: "<< image3 <<std::endl;
257  nbok += (image3.getPointer().count()== 2) ? 1 : 0;
258  nb++;
259 
260  MyImage image4(image3);
261  trace.info() << "Image constructed (copy): "<< image4 <<std::endl;
262  nbok += (image4.getPointer().count()== 3) ? 1 : 0;
263  nb++;
264 
265 
266  trace.info() << "(" << nbok << "/" << nb << ") "
267  << "true == true" << std::endl;
268 
269  return nbok == nb;
270 }
271 
273 {
274  unsigned int nbok = 0;
275  unsigned int nb = 0;
276 
277  trace.beginBlock ( "Testing Image scan ..." );
279  typedef Image<VImage > MyImage;
280  BOOST_CONCEPT_ASSERT(( concepts::CImage< MyImage > ));
281 
282  Z2i::Point a(0,0);
283  Z2i::Point b(32,32);
284  Z2i::Point c(12, 14);
285 
286  Z2i::Domain domain(a,b);
287  MyImage image( new VImage(domain) );
288 
289  typedef MyImage::Range::Iterator Iterator;
290  typedef MyImage::Domain::ConstIterator DomainConstIterator;
291 
292  //Setting values iterating on the domain points
293  for(Iterator it = image.range().begin(), itend = image.range().end();
294  it != itend; ++it)
295  *it = 42 ; // (*it) is a container cell
296 
297 
298  //Fast init of the image using container built-in iterator
299  for(DomainConstIterator it = image.domain().begin(), itend = image.domain().end();
300  it != itend; ++it)
301  image.setValue( *it , 42 ); // (*it) is a Point
302 
303 
304  return nbok == nb;
305 }
306 
307 
309 // Standard services - public :
310 
311 int main( int argc, char** argv )
312 {
313  trace.beginBlock ( "Testing class ImageSimple" );
314  trace.info() << "Args:";
315  for ( int i = 0; i < argc; ++i )
316  trace.info() << " " << argv[ i ];
317  trace.info() << endl;
318 
319  bool res = testSelfCheckConcept()
320  && testCreate()
321  && testAPI()
322  && testImageCopy() && testImageScan()
323  && testImageCopyShort();// && ... other tests
324 
325  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
326  trace.endBlock();
327  return res ? 0 : 1;
328 }
329 // //
Iterator for HyperRectDomain.
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
Aim: model of CConstBidirectionalRangeFromPoint that adapts any range of elements bounded by two iter...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
std::ostream & warning()
double endBlock()
DGtal::int32_t Integer
Definition: StdDefs.h:74
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:103
MyPointD Point
Definition: testClone2.cpp:383
int main(int argc, char **argv)
bool testCreate()
bool testSelfCheckConcept()
bool testAPI()
bool testImageScan()
bool testImageCopy()
bool testImageCopyShort()
Domain domain
Image image(domain)