DGtal  1.4.2
exampleTiledImage.cpp
Go to the documentation of this file.
1 
38 #include <iostream>
39 
40 #include "DGtal/base/Common.h"
41 #include "DGtal/helpers/StdDefs.h"
42 #include "ConfigExamples.h"
43 
44 #include "DGtal/io/boards/Board2D.h"
45 
47 #include "DGtal/io/colormaps/HueShadeColorMap.h"
48 
49 #include "DGtal/images/ImageContainerBySTLVector.h"
50 #include "DGtal/images/ImageFactoryFromImage.h"
51 #include "DGtal/images/TiledImage.h"
53 
55 
56 using namespace std;
57 using namespace DGtal;
58 
59 int main( /*int argc, char** argv*/ )
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 
89  trace.endBlock();
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
102  typedef ImageCacheReadPolicyFIFO<OutputImage, MyImageFactoryFromImage> MyImageCacheReadPolicyFIFO;
103  typedef ImageCacheWritePolicyWT<OutputImage, MyImageFactoryFromImage> MyImageCacheWritePolicyWT;
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 }
265 // //
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:151
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1011
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1138
int main()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:103
Image image(domain)