DGtal  1.4.2
testImageSimple.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/images/CImage.h"
#include "DGtal/images/Image.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
Include dependency graph for testImageSimple.cpp:

Go to the source code of this file.

Functions

bool testSelfCheckConcept ()
 
bool testCreate ()
 
bool testAPI ()
 
bool testImageCopy ()
 
bool testImageCopyShort ()
 
bool testImageScan ()
 
int main (int argc, char **argv)
 

Detailed Description

This program 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 3 of the License, or (at your option) any later version.

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/02/07

Functions for testing class ImageSimple.

This file is part of the DGtal library.

Definition in file testImageSimple.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 311 of file testImageSimple.cpp.

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 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testCreate()
bool testSelfCheckConcept()
bool testAPI()
bool testImageScan()
bool testImageCopy()
bool testImageCopyShort()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testAPI(), testCreate(), testImageCopy(), testImageCopyShort(), testImageScan(), testSelfCheckConcept(), and DGtal::trace.

◆ testAPI()

bool testAPI ( )

Definition at line 118 of file testImageSimple.cpp.

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 }
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...
std::ostream & warning()
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:103
Domain domain
Image image(domain)

References DGtal::Trace::beginBlock(), domain, DGtal::Trace::endBlock(), image(), DGtal::Trace::info(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

◆ testCreate()

bool testCreate ( )

Definition at line 72 of file testImageSimple.cpp.

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 }
DGtal::int32_t Integer
Definition: StdDefs.h:74
MyPointD Point
Definition: testClone2.cpp:383

References DGtal::Trace::beginBlock(), domain, DGtal::Trace::endBlock(), image(), DGtal::Trace::info(), DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

◆ testImageCopy()

bool testImageCopy ( )

Definition at line 163 of file testImageSimple.cpp.

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 }

References DGtal::Trace::beginBlock(), domain, DGtal::Trace::endBlock(), image(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testImageCopyShort()

bool testImageCopyShort ( )

Definition at line 212 of file testImageSimple.cpp.

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 }

References DGtal::Trace::beginBlock(), domain, image(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testImageScan()

bool testImageScan ( )

Definition at line 272 of file testImageSimple.cpp.

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 }
Iterator for HyperRectDomain.

References DGtal::Trace::beginBlock(), domain, image(), and DGtal::trace.

Referenced by main().

◆ testSelfCheckConcept()

bool testSelfCheckConcept ( )

Example of a test. To be completed.

Definition at line 51 of file testImageSimple.cpp.

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 }

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().