DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
exampleTiledImage.cpp File Reference

An example file for tiledImage. More...

#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ImageFactoryFromImage.h"
#include "DGtal/images/TiledImage.h"

Go to the source code of this file.

Functions

int main ()
 

Detailed Description

An example file for tiledImage.

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
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
2013/01/23

This file is part of the DGtal library.

Definition in file exampleTiledImage.cpp.

Function Documentation

◆ main()

int main ( void  )

[def]

[def]

[image_creation]

[image_creation]

[image_filling]

[image_filling]

[TiledImage_creation]

[TiledImage_creation]

[TiledImage_read42]

[TiledImage_read42]

[TiledImage_read106]

[TiledImage_read106]

[TiledImage_write117]

[TiledImage_write117]

[TiledImage_read23]

[TiledImage_read23]

[TiledImage_read161]

[TiledImage_read161]

[TiledImage_write161]

[TiledImage_write161]

Definition at line 59 of file exampleTiledImage.cpp.

60{
61 trace.beginBlock("ORIGINAL image");
62
63 Board2D aBoard;
64
66 typedef HueShadeColorMap<int> HueShade; // a simple HueShadeColorMap varying on 'int' values
68
71 VImage image(Z2i::Domain(Z2i::Point(1,1), Z2i::Point(16,16)));
73
75 int i = 1;
76 for (VImage::Iterator it = image.begin(); it != image.end(); ++it)
77 *it = i++;
79
80 aBoard.clear();
81 Display2DFactory::drawImage<HueShade>(aBoard, image, (int)0, (int)255);
82 aBoard.saveSVG("tiledImage-image.svg");
83#ifdef WITH_CAIRO
84 aBoard.saveCairo("tiledImage-image.png", Board2D::CairoPNG);
85#endif
86
87 trace.info() << "ORIGINAL image: " << image << endl;
88
90
91 // ---
92
93 trace.beginBlock("tiledImage");
94
96 // here we create an image factory
97 typedef ImageFactoryFromImage<VImage> MyImageFactoryFromImage;
98 typedef MyImageFactoryFromImage::OutputImage OutputImage;
99 MyImageFactoryFromImage imageFactoryFromImage(image);
100
101 // here we create read and write policies
104 MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(imageFactoryFromImage, 2);
105 MyImageCacheWritePolicyWT imageCacheWritePolicyWT(imageFactoryFromImage);
106
107 // here we create the TiledImage
109 BOOST_CONCEPT_ASSERT(( concepts::CImage< MyTiledImage > ));
110 MyTiledImage tiledImage(imageFactoryFromImage, imageCacheReadPolicyFIFO, imageCacheWritePolicyWT, 4);
112
113 trace.info() << "tiledImage image: " << tiledImage << endl;
114
115 typedef MyTiledImage::OutputImage OutputImage;
116 /*VImage*/OutputImage::Value aValue;
117
118 trace.endBlock();
119
120 // ---
121
122 /*int cpt, sumcRp, sumcRrp, sumTp, sumTm, sumTrp, sumC;
123
124 cpt=sumcRp=0;
125 trace.beginBlock("test ConstRange");
126 for(MyTiledImage::ConstRange::ConstIterator tiled_it = tiledImage.constRange().begin(), tiled_itend = tiledImage.constRange().end();
127 tiled_it != tiled_itend; ++tiled_it)
128 {
129 trace.info() << (*tiled_it) << ",";
130 sumcRp += (*tiled_it);
131 cpt++;
132 }
133 trace.info() << "Cpt: " << cpt << " - sumcRp: " << sumcRp << " - cacheMissRead:" << tiledImage.getCacheMissRead() << endl;
134 trace.endBlock();
135
136 cpt=sumcRrp=0; tiledImage.clearCacheAndResetCacheMisses();
137 trace.beginBlock("test ConstRange (reverse)");
138 for(MyTiledImage::ConstRange::ConstReverseIterator rtiled_it = tiledImage.constRange().rbegin(), rtiled_itend = tiledImage.constRange().rend();
139 rtiled_it != rtiled_itend; ++rtiled_it)
140 {
141 trace.info() << (*rtiled_it) << ",";
142 sumcRrp += (*rtiled_it);
143 cpt++;
144 }
145 trace.info() << "Cpt: " << cpt << " - sumcRrp: " << sumcRrp << " - cacheMissRead:" << tiledImage.getCacheMissRead() << endl;
146 trace.endBlock();
147
148 // ---
149
150 cpt=sumTp=0; tiledImage.clearCacheAndResetCacheMisses();
151 trace.beginBlock("test TiledIterator (++)");
152 for(MyTiledImage::TiledIterator tiled_it = tiledImage.begin(), tiled_itend = tiledImage.end();
153 tiled_it != tiled_itend; ++tiled_it)
154 {
155 trace.info() << (*tiled_it) << ",";
156 sumTp += (*tiled_it);
157 cpt++;
158 }
159 trace.info() << "Cpt: " << cpt << " - sumTp: " << sumTp << " - cacheMissRead:" << tiledImage.getCacheMissRead() << endl;
160 trace.endBlock();
161
162 cpt=sumTm=0; tiledImage.clearCacheAndResetCacheMisses();
163 trace.beginBlock("test TiledIterator (--)");
164 {
165 MyTiledImage::TiledIterator tiled_it = tiledImage.end(), tiled_itend = tiledImage.begin();
166 do
167 {
168 --tiled_it;
169
170 trace.info() << (*tiled_it) << ",";
171 sumTm += (*tiled_it);
172 cpt++;
173 }
174 while (tiled_it != tiled_itend);
175 }
176 trace.info() << "Cpt: " << cpt << " - sumTm: " << sumTm << " - cacheMissRead:" << tiledImage.getCacheMissRead() << endl;
177 trace.endBlock();
178
179 // ---
180
181 cpt=sumTrp=0; tiledImage.clearCacheAndResetCacheMisses();
182 trace.beginBlock("test ReverseTiledIterator (++)");
183 for(MyTiledImage::ReverseTiledIterator rtiled_it = tiledImage.rbegin(), rtiled_itend = tiledImage.rend();
184 rtiled_it != rtiled_itend; ++rtiled_it)
185 {
186 trace.info() << (*rtiled_it) << ",";
187 sumTrp += (*rtiled_it);
188 cpt++;
189 }
190 trace.info() << "Cpt: " << cpt << " - sumTrp: " << sumTrp << " - cacheMissRead:" << tiledImage.getCacheMissRead() << endl;
191 trace.endBlock();
192
193 // ---
194
195 tiledImage.clearCacheAndResetCacheMisses();
196 trace.beginBlock("test Range (writing)");
197 {
198 const int maximalValue = tiledImage.domain().size();
199 MyTiledImage::Range::OutputIterator it = tiledImage.range().outputIterator();
200 for (int ii = 0; ii < maximalValue; ++ii)
201 {
202 *it++ = 10; // TODO : don't work with WT
203 //it.setValue(10); it++;
204 }
205 }
206 trace.endBlock();
207
208 // ---
209
210 cpt=sumC=0;
211 trace.beginBlock("test ConstIterator");
212 for(VImage::Domain::ConstIterator it = tiledImage.domain().begin(), itend = tiledImage.domain().end();
213 it != itend; ++it)
214 {
215 trace.info() << tiledImage(*it) << ",";
216 sumC += tiledImage(*it);
217 cpt++;
218 }
219 trace.info() << "Cpt: " << cpt << " - sumC: " << sumC << endl;
220 trace.endBlock();*/
221
222 // ---
223
224 trace.beginBlock("read and write on MyTiledImage");
225
227 trace.info() << "Read value for Point 4,2: " << tiledImage(Z2i::Point(4,2)) << endl;
229
231 trace.info() << "Read value for Point 10,6: " << tiledImage(Z2i::Point(10,6)) << endl;
233
235 aValue = 1; tiledImage.setValue(Z2i::Point(11,7), aValue);
236 trace.info() << "Write value for Point 11,7: " << aValue << endl;
238
240 trace.info() << "Read value for Point 2,3: " << tiledImage(Z2i::Point(2,3)) << endl;
242
244 trace.info() << "Read value for Point 16,1: " << tiledImage(Z2i::Point(16,1)) << endl;
246
248 aValue = 128; tiledImage.setValue(Z2i::Point(16,1), aValue);
249 trace.info() << "Write value for Point 16,1: " << aValue << endl;
251
252 trace.info() << " Point 16,1 on ORIGINAL image, value: " << image(Z2i::Point(16,1)) << endl;
253
254 aBoard.clear();
255 Display2DFactory::drawImage<HueShade>(aBoard, image, (int)0, (int)255);
256 aBoard.saveSVG("tiledImage-image2.svg");
257#ifdef WITH_CAIRO
258 aBoard.saveCairo("tiledImage-image2.png", Board2D::CairoPNG);
259#endif
260
261 trace.endBlock();
262
263 return 0;
264}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: implements a 'FIFO' read policy cache.
Aim: implements a 'WT (Write-through)' write policy cache.
Aim: implements a factory to produce images from a "bigger/original" one according to a given domain.
Aim: implements a tiled image from a "bigger/original" one from an ImageFactory.
Definition: TiledImage.h:77
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
Trace trace
Definition: Common.h:154
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:103

References DGtal::Trace::beginBlock(), LibBoard::Board::clear(), DGtal::Trace::endBlock(), DGtal::Trace::info(), LibBoard::Board::saveCairo(), LibBoard::Board::saveSVG(), and DGtal::trace.