DGtal  1.2.0
Functions
testConstIteratorAdapter.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/PointVector.h"
#include "DGtal/kernel/BasicPointFunctors.h"
#include "DGtal/base/ConstIteratorAdapter.h"
#include "DGtal/base/Circulator.h"
#include <boost/concept_check.hpp>
Include dependency graph for testConstIteratorAdapter.cpp:

Go to the source code of this file.

Functions

bool testProjection ()
 
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
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
2011/09/01

Functions for testing class ConstIteratorAdapter.

This file is part of the DGtal library.

Definition in file testConstIteratorAdapter.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 177 of file testConstIteratorAdapter.cpp.

178 {
179  trace.beginBlock ( "Testing class ConstIteratorAdapter" );
180  trace.info() << "Args:";
181  for ( int i = 0; i < argc; ++i )
182  trace.info() << " " << argv[ i ];
183  trace.info() << endl;
184 
185  bool res = testProjection()
186  ; // && ... other tests
187  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
188  trace.endBlock();
189  return res ? 0 : 1;
190 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
bool testProjection()

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

◆ testProjection()

bool testProjection ( )

Example of a test. To be completed.

Definition at line 54 of file testConstIteratorAdapter.cpp.

55 {
56 
57  unsigned int nb = 0;
58  unsigned int nbok = 0;
59 
60  typedef PointVector<3,int> Point3;
61  typedef PointVector<2,int> Point2;
62  typedef std::vector<Point3>::iterator Iterator3;
63 
64  //projector
65  typedef DGtal::functors::Projector<SpaceND<2,int> > Projector2;
66 
68  BOOST_CONCEPT_ASSERT(( boost::RandomAccessIterator<Iterator3> ));
69 
70  BOOST_CONCEPT_ASSERT(( boost_concepts::ReadableIteratorConcept<Adapter> ));
72 
73  //range of 3d Points
74  std::vector<Point3> r;
75  r.push_back(Point3(0,0,0));
76  r.push_back(Point3(1,0,0));
77  r.push_back(Point3(2,0,0));
78  r.push_back(Point3(2,1,0));
79  r.push_back(Point3(2,1,1));
80  r.push_back(Point3(3,1,1));
81  r.push_back(Point3(4,1,1));
82  r.push_back(Point3(4,2,1));
83  r.push_back(Point3(4,2,2));
84  r.push_back(Point3(5,2,2));
85  r.push_back(Point3(6,2,2));
86  r.push_back(Point3(6,3,2));
87  r.push_back(Point3(6,3,3));
88  r.push_back(Point3(6,4,3));
89  r.push_back(Point3(6,4,4));
90  r.push_back(Point3(6,5,4));
91 
92  //true projection
93  std::vector<Point2> rtrue;
94  rtrue.push_back(Point2(0,0));
95  rtrue.push_back(Point2(1,0));
96  rtrue.push_back(Point2(2,0));
97  rtrue.push_back(Point2(2,1));
98  rtrue.push_back(Point2(2,1));
99  rtrue.push_back(Point2(3,1));
100  rtrue.push_back(Point2(4,1));
101  rtrue.push_back(Point2(4,2));
102  rtrue.push_back(Point2(4,2));
103  rtrue.push_back(Point2(5,2));
104  rtrue.push_back(Point2(6,2));
105  rtrue.push_back(Point2(6,3));
106  rtrue.push_back(Point2(6,3));
107  rtrue.push_back(Point2(6,4));
108  rtrue.push_back(Point2(6,4));
109  rtrue.push_back(Point2(6,5));
110 
111  trace.beginBlock ( "Testing block ..." );
112 
113  trace.info() << "2d points after projection (XY)" << endl;
114 
115  Projector2 proj;
116 
117  Adapter aitBegin(r.begin(),proj);
118  Adapter ait = aitBegin;
119  Adapter aitEnd(r.end(),proj);
120 
121  for ( ; ait != aitEnd; ++ait)
122  {
123  trace.info() << *(ait.base());
124  trace.info() << *ait;
125  trace.info() << "(" << ait->operator[](0) << ", " << ait->operator[](1) << ")" << endl;
126  }
127 
128  //comparison
129  if ( std::equal( rtrue.begin(), rtrue.end(), aitBegin ) == true )
130  nbok++;
131  nb++;
132  trace.info() << nbok << "/" << nb << std::endl;
133 
134  //basic operators
135  trace.info() << "basic operators (operator==)" << endl;
136  if ( ( ait != aitBegin ) && ( ait == aitEnd ) )
137  nbok++;
138  nb++;
139  trace.info() << nbok << "/" << nb << std::endl;
140 
141  //random access
142  ait = (aitBegin + 3);
143  ait += 1;
144  ait = 1 + ait;
145  trace.info() << "random access operators (operator+)" << endl;
146  trace.info() << *(aitBegin.base()) << *aitBegin << endl;
147  trace.info() << "+5" << std::endl;
148  trace.info() << *(ait.base()) << *ait << endl;
149  if ( ( *ait == Point2(3,1) ) == true )
150  nbok++;
151  nb++;
152  trace.info() << nbok << "/" << nb << std::endl;
153 
154  trace.info() << "backward scanning" << endl;
155  std::reverse_iterator<Adapter> raitBegin( aitEnd );
156  if ( std::equal( rtrue.rbegin(), rtrue.rend(), raitBegin ) == true )
157  nbok++;
158  nb++;
159  trace.info() << nbok << "/" << nb << std::endl;
160 
161  trace.info() << "circular scanning" << endl;
162  Circulator<Adapter> caitBegin( aitBegin, aitBegin, aitEnd );
163  if ( std::equal( rtrue.begin(), rtrue.end(), caitBegin ) == true )
164  nbok++;
165  nb++;
166  trace.info() << nbok << "/" << nb << std::endl;
167 
168 
169  trace.endBlock();
170 
171  return (nb == nbok);
172 }
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:86
This class adapts any iterator so that operator* returns another element than the one pointed to by t...
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
Aim: Functor that maps a point P of dimension i to a point Q of dimension j. The member myDims is an ...
Go to http://www.sgi.com/tech/stl/RandomAccessIterator.html.
Definition: Boost.dox:44
Go to http://www.boost.org/doc/libs/1_52_0/libs/iterator/doc/RandomAccessTraversal....
Go to http://www.boost.org/doc/libs/1_52_0/libs/iterator/doc/ReadableIterator.html.

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

Referenced by main().