DGtal 1.4.2
Loading...
Searching...
No Matches
testImage.cpp File Reference
#include <cstdio>
#include <cmath>
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/images/CImage.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ImageContainerBySTLMap.h"
#include "DGtal/images/ImageContainerByHashTree.h"
#include "DGtal/images/Image.h"
Include dependency graph for testImage.cpp:

Go to the source code of this file.

Functions

template<typename Image >
bool testImage (const Image &aImage)
 
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 )
Date
2010/05/25
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

This file is part of the DGtal library

Definition in file testImage.cpp.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

domain

image types

tests

Definition at line 145 of file testImage.cpp.

146{
147
148 trace.beginBlock ( "Testing image classes" );
149 trace.info() << "Args:";
150 for ( int i = 0; i < argc; ++i )
151 trace.info() << " " << argv[ i ];
152 trace.info() << endl;
153
155 typedef DGtal::int64_t Integer;
157 typedef Space::Point Point;
159
160 const Integer size = 5;
161 Point p = Point::diagonal(0);
162 Point q = Point::diagonal(size-1);
163 Domain d(p,q);
164
166 typedef short Value;
169 // TODO typedef experimental::ImageContainerByHashTree<Domain,Value> HImage;
170 // TODO typedef Image<VImage > LImage;
171
173 VImage vi(d);
174 bool res = testImage(vi);
175
176 MImage mi(d);
177 res = res && testImage(mi);
178
179 // TODO
180 // HImage hi(3, p, q, 0);
181 // res = res && testImage(hi);
182
183 // LImage li( new VImage(d) );
184 // res = res && testImage(li);
185
186 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
187 trace.endBlock();
188 return res ? 0 : 1;
189}
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
boost::int64_t int64_t
signed 94-bit integer.
Definition BasicTypes.h:74
Trace trace
Definition Common.h:153
MyPointD Point
bool testImage(const Image &aImage)
Definition testImage.cpp:57
HyperRectDomain< Space > Domain

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

◆ testImage()

template<typename Image >
bool testImage ( const Image & aImage)

Image tests.

Definition at line 57 of file testImage.cpp.

58{
59
60 BOOST_CONCEPT_ASSERT(( concepts::CImage<Image> ));
61
62 int nb = 0;
63 int nbok = 0;
64
66 trace.beginBlock ( "Main services, range" );
67
68 Image img(aImage);
69 Image img2 = img; //copy
70
71 //fill
72 typename Image::Domain::ConstIterator dit = img.domain().begin();
73 typename Image::Domain::ConstIterator ditEnd = img.domain().end();
74 for (int i = 0; ( (dit != ditEnd)&&(i < 5) ); ++dit, ++i)
75 {
76 img.setValue(*dit, i);
77 }
78 Image img3(img2);
79 img3 = img; //assignment
80
81 //ranges comparison
82 typename Image::ConstRange rimg = img.constRange();
83 typename Image::ConstRange rimg2 = img2.constRange();
84 typename Image::ConstRange rimg3 = img3.constRange();
85
86 bool flag2 = std::equal(rimg.begin(), rimg.end(), rimg2.begin());
87 bool flag3 = std::equal(rimg.begin(), rimg.end(), rimg3.begin());
88 bool flag23 = std::equal(rimg2.begin(), rimg2.end(), rimg3.begin());
89
90 nbok += ( (!flag2) && flag3 && (!flag23) )?1:0;
91 nb++;
92 trace.info() << "(" <<nbok << "/" << nb << ")" << std::endl;
94
96 trace.beginBlock ( "Output iterator" );
97 std::copy(rimg.begin(), rimg.end(), img2.range().outputIterator());
98
99 //rimg2 is invalid if Image is a proxy image
100 //because its iterators point to the data of aImage
101 //instead of pointing to the data of img2
102 rimg2 = img2.constRange();
103 flag2 = std::equal(rimg.begin(), rimg.end(), rimg2.begin());
104 nbok += (flag2)?1:0;
105 nb++;
106 trace.info() << "(" <<nbok << "/" << nb << ")" << std::endl;
107 trace.endBlock();
108
110 trace.beginBlock ( " Getters / setters " );
111 typename Image::Domain::Point p = img.domain().upperBound();
112
113 //local comparison
114 img.setValue( p, 128 );
115 bool flag4 = ( img(p) == 128 );
116
117 //range comparison
118 rimg = img.constRange();
119 rimg2 = img2.constRange();
120 rimg3 = img3.constRange();
121 std::copy( rimg.begin(), rimg.end(), std::ostream_iterator<int>(cout,", ") );
122 cout << endl;
123 flag2 = std::equal(rimg.begin(), rimg.end(), rimg2.begin());
124 std::copy( rimg2.begin(), rimg2.end(), std::ostream_iterator<int>(cout,", ") );
125 cout << endl;
126 flag3 = std::equal(rimg.begin(), rimg.end(), rimg3.begin());
127 std::copy( rimg3.begin(), rimg3.end(), std::ostream_iterator<int>(cout,", ") );
128 cout << endl;
129
130 nbok += ( flag4 && (!flag2) && (!flag3) )?1:0;
131 nb++;
132 trace.info() << "(" <<nbok << "/" << nb << ")" << std::endl;
133 trace.endBlock();
134
136 trace.beginBlock ( " Display " );
137 trace.info() << img << std::endl;
138 trace.info() << img2 << std::endl;
139 trace.info() << img3 << std::endl;
140 trace.endBlock();
141
142 return ( img.isValid() && img2.isValid() && img3.isValid() && (nbok == nb) );
143}
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
const Domain & domain() const
Definition Image.h:192
Range range()
Definition Image.h:214
ConstRange constRange() const
Definition Image.h:203
bool isValid() const
Definition Image.h:266
Aim: model of CConstBidirectionalRangeFromPoint that adapts any range of elements bounded by two iter...
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition CImage.h:103

References DGtal::SimpleRandomAccessConstRangeFromPoint< TConstIterator, DistanceFunctor >::begin(), DGtal::Trace::beginBlock(), DGtal::Image< TImageContainer >::constRange(), DGtal::Image< TImageContainer >::domain(), DGtal::SimpleRandomAccessConstRangeFromPoint< TConstIterator, DistanceFunctor >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::Image< TImageContainer >::isValid(), DGtal::SimpleRandomAccessRangeFromPoint< TConstIterator, TIterator, DistanceFunctor >::outputIterator(), DGtal::Image< TImageContainer >::range(), testImage(), and DGtal::trace.

Referenced by main(), and testImage().