DGtal  1.2.0
testConstImageAdapter.cpp
Go to the documentation of this file.
1 
36 #include <iostream>
37 
38 #include "DGtal/base/Common.h"
39 #include "DGtal/helpers/StdDefs.h"
40 #include "ConfigTest.h"
41 
42 #include "DGtal/base/BasicFunctors.h"
43 #include "DGtal/images/ImageSelector.h"
44 #include "DGtal/images/ConstImageAdapter.h"
45 
47 
48 using namespace std;
49 using namespace DGtal;
50 
51 template <typename R>
52 void displayRange(const R& r)
53 {
54  typedef typename R::ConstIterator I;
55  for (I it = r.begin(), itEnd = r.end();
56  it != itEnd; ++it)
57  {
58  trace.info() << *it << " ";
59  }
60  trace.info() << std::endl;
61 }
62 
64 int main( int argc, char** argv )
65 {
66  unsigned int nbok = 0;
67  unsigned int nb = 0;
68 
69  trace.beginBlock ( "Test for ConstImageAdapter" );
70  trace.info() << "Args:";
71  for ( int i = 0; i < argc; ++i )
72  trace.info() << " " << argv[ i ];
73  trace.info() << endl;
74 
75  using namespace Z2i;
76 
77  trace.beginBlock("Image creation");
78 
79  //domain
80  const Integer size = 5;
81  Point p = Point::diagonal(0);
82  Point q = Point::diagonal(size-1);
83  Domain d(p,q);
84 
85  //image
87  Image img(d);
88 
89  //fill
90  const int maximalValue = size*size;
91  Image::Range::OutputIterator it = img.range().outputIterator();
92  for (int i = 0; i < maximalValue; ++i)
93  *it++ = i;
94 
95  //display values
96  Image::ConstRange r = img.constRange();
97  std::copy( r.begin(), r.end(), std::ostream_iterator<int>(cout,", ") );
98  cout << endl;
99  trace.endBlock();
100 
101 
102  const int thresholdValue = maximalValue/2;
103  trace.beginBlock("Implicit thresholding");
104 
107  DGtal::functors::Thresholder<Image::Value> t( thresholdValue );
109  BOOST_CONCEPT_ASSERT(( concepts::CConstImage< MyConstImageAdapter > ));
110  MyConstImageAdapter a(img, d, g, t);
112 
113  //display values
116  ra = a.constRange();
117  std::copy( ra.begin(), ra.end(), std::ostream_iterator<int>(cout,", ") );
118  cout << endl;
119 
120  std::vector<int> to_vector(25);
121  std::copy(ra.begin(), ra.end(), to_vector.begin());
122  for (int i = 0; i < 25; i++)
123  {
124  if (i<=12)
125  {
126  if (to_vector[i]==1)
127  {
128  cout << "ok, ";
129  nbok += 1 ; nb++;
130  }
131  else
132  {
133  cout << "!ok, ";
134  nb++;
135  }
136  }
137  else
138  {
139  if (to_vector[i]==0)
140  {
141  cout << "ok, ";
142  nbok += 1 ; nb++;
143  }
144  else
145  {
146  cout << "!ok, ";
147  nb++;
148  }
149  }
150  }
152 
153  cout << endl;
154 
155  trace.endBlock();
156 
157  bool res = (nbok == nb);
158 
159  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
160  trace.endBlock();
161  return res ? 0 : 1;
162 }
163 // //
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
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()
double endBlock()
Aim: A small functor with an operator () that compares one value to a threshold value according to tw...
MyDigitalSurface::ConstIterator ConstIterator
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-only image, which is a refinement of CPointFunctor.
Definition: CConstImage.h:95
Aim: Define a simple default functor that just returns its argument.
MyPointD Point
Definition: testClone2.cpp:383
int main(int argc, char **argv)
void displayRange(const R &r)
ImageContainerBySTLVector< Domain, Value > Image