DGtal 1.4.0
Loading...
Searching...
No Matches
testImage.cpp
Go to the documentation of this file.
1
34#include <cstdio>
35#include <cmath>
36#include <iostream>
37
38#include "DGtal/base/Common.h"
39#include "DGtal/kernel/SpaceND.h"
40#include "DGtal/kernel/domains/HyperRectDomain.h"
41#include "DGtal/images/CImage.h"
42#include "DGtal/images/ImageContainerBySTLVector.h"
43#include "DGtal/images/ImageContainerBySTLMap.h"
44#include "DGtal/images/ImageContainerByHashTree.h"
45#include "DGtal/images/Image.h"
46
47
48using namespace DGtal;
49using namespace std;
50
51
56template<typename Image>
57bool testImage(const Image& aImage)
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}
144
145int main( int argc, char** argv )
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}
190
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
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...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
boost::int64_t int64_t
signed 94-bit integer.
Definition BasicTypes.h:74
Trace trace
Definition Common.h:153
STL namespace.
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition CImage.h:103
int main()
Definition testBits.cpp:56
MyPointD Point
bool testImage(const Image &aImage)
Definition testImage.cpp:57
HyperRectDomain< Space > Domain