DGtal  1.5.beta
testConstImageAdapter.cpp File Reference

A test file for ConstImageAdapter. More...

#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigTest.h"
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/ConstImageAdapter.h"
Include dependency graph for testConstImageAdapter.cpp:

Go to the source code of this file.

Functions

template<typename R >
void displayRange (const R &r)
 
int main (int argc, char **argv)
 

Detailed Description

A test file for ConstImageAdapter.

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
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/02/13
Author
Martial Tola (marti.nosp@m.al.t.nosp@m.ola@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/10/12

This file is part of the DGtal library.

Definition in file testConstImageAdapter.cpp.

Function Documentation

◆ displayRange()

template<typename R >
void displayRange ( const R &  r)
Examples
io/viewers/viewer3D-7-stdplane.cpp, and io/viewers/viewer3D-7bis-stdplane.cpp.

Definition at line 52 of file testConstImageAdapter.cpp.

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 }
std::ostream & info()
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:153

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

◆ main()

int main ( int  argc,
char **  argv 
)

[ConstImageAdapterConstruction]

[ConstImageAdapterConstruction]

[ConstImageAdapterRange]

[ConstImageAdapterRange]

Definition at line 64 of file testConstImageAdapter.cpp.

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 }
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()
double endBlock()
Aim: A small functor with an operator () that compares one value to a threshold value according to tw...
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
ImageContainerBySTLVector< Domain, Value > Image

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