DGtal  1.5.beta
images/exampleTiledImage.cpp

Example of TiledImage.

See also
Images
#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"
using namespace std;
using namespace DGtal;
int main( /*int argc, char** argv*/ )
{
trace.beginBlock("ORIGINAL image");
Board2D aBoard;
typedef HueShadeColorMap<int> HueShade; // a simple HueShadeColorMap varying on 'int' values
typedef ImageContainerBySTLVector<Z2i::Domain, int> VImage;
VImage image(Z2i::Domain(Z2i::Point(1,1), Z2i::Point(16,16)));
int i = 1;
for (VImage::Iterator it = image.begin(); it != image.end(); ++it)
*it = i++;
aBoard.clear();
Display2DFactory::drawImage<HueShade>(aBoard, image, (int)0, (int)255);
aBoard.saveSVG("tiledImage-image.svg");
#ifdef WITH_CAIRO
aBoard.saveCairo("tiledImage-image.png", Board2D::CairoPNG);
#endif
trace.info() << "ORIGINAL image: " << image << endl;
// ---
trace.beginBlock("tiledImage");
// here we create an image factory
typedef ImageFactoryFromImage<VImage> MyImageFactoryFromImage;
typedef MyImageFactoryFromImage::OutputImage OutputImage;
MyImageFactoryFromImage imageFactoryFromImage(image);
// here we create read and write policies
typedef ImageCacheReadPolicyFIFO<OutputImage, MyImageFactoryFromImage> MyImageCacheReadPolicyFIFO;
typedef ImageCacheWritePolicyWT<OutputImage, MyImageFactoryFromImage> MyImageCacheWritePolicyWT;
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(imageFactoryFromImage, 2);
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(imageFactoryFromImage);
// here we create the TiledImage
typedef TiledImage<VImage, MyImageFactoryFromImage, MyImageCacheReadPolicyFIFO, MyImageCacheWritePolicyWT> MyTiledImage;
BOOST_CONCEPT_ASSERT(( concepts::CImage< MyTiledImage > ));
MyTiledImage tiledImage(imageFactoryFromImage, imageCacheReadPolicyFIFO, imageCacheWritePolicyWT, 4);
trace.info() << "tiledImage image: " << tiledImage << endl;
typedef MyTiledImage::OutputImage OutputImage;
/*VImage*/OutputImage::Value aValue;
// ---
/*int cpt, sumcRp, sumcRrp, sumTp, sumTm, sumTrp, sumC;
cpt=sumcRp=0;
trace.beginBlock("test ConstRange");
for(MyTiledImage::ConstRange::ConstIterator tiled_it = tiledImage.constRange().begin(), tiled_itend = tiledImage.constRange().end();
tiled_it != tiled_itend; ++tiled_it)
{
trace.info() << (*tiled_it) << ",";
sumcRp += (*tiled_it);
cpt++;
}
trace.info() << "Cpt: " << cpt << " - sumcRp: " << sumcRp << " - cacheMissRead:" << tiledImage.getCacheMissRead() << endl;
trace.endBlock();
cpt=sumcRrp=0; tiledImage.clearCacheAndResetCacheMisses();
trace.beginBlock("test ConstRange (reverse)");
for(MyTiledImage::ConstRange::ConstReverseIterator rtiled_it = tiledImage.constRange().rbegin(), rtiled_itend = tiledImage.constRange().rend();
rtiled_it != rtiled_itend; ++rtiled_it)
{
trace.info() << (*rtiled_it) << ",";
sumcRrp += (*rtiled_it);
cpt++;
}
trace.info() << "Cpt: " << cpt << " - sumcRrp: " << sumcRrp << " - cacheMissRead:" << tiledImage.getCacheMissRead() << endl;
trace.endBlock();
// ---
cpt=sumTp=0; tiledImage.clearCacheAndResetCacheMisses();
trace.beginBlock("test TiledIterator (++)");
for(MyTiledImage::TiledIterator tiled_it = tiledImage.begin(), tiled_itend = tiledImage.end();
tiled_it != tiled_itend; ++tiled_it)
{
trace.info() << (*tiled_it) << ",";
sumTp += (*tiled_it);
cpt++;
}
trace.info() << "Cpt: " << cpt << " - sumTp: " << sumTp << " - cacheMissRead:" << tiledImage.getCacheMissRead() << endl;
trace.endBlock();
cpt=sumTm=0; tiledImage.clearCacheAndResetCacheMisses();
trace.beginBlock("test TiledIterator (--)");
{
MyTiledImage::TiledIterator tiled_it = tiledImage.end(), tiled_itend = tiledImage.begin();
do
{
--tiled_it;
trace.info() << (*tiled_it) << ",";
sumTm += (*tiled_it);
cpt++;
}
while (tiled_it != tiled_itend);
}
trace.info() << "Cpt: " << cpt << " - sumTm: " << sumTm << " - cacheMissRead:" << tiledImage.getCacheMissRead() << endl;
trace.endBlock();
// ---
cpt=sumTrp=0; tiledImage.clearCacheAndResetCacheMisses();
trace.beginBlock("test ReverseTiledIterator (++)");
for(MyTiledImage::ReverseTiledIterator rtiled_it = tiledImage.rbegin(), rtiled_itend = tiledImage.rend();
rtiled_it != rtiled_itend; ++rtiled_it)
{
trace.info() << (*rtiled_it) << ",";
sumTrp += (*rtiled_it);
cpt++;
}
trace.info() << "Cpt: " << cpt << " - sumTrp: " << sumTrp << " - cacheMissRead:" << tiledImage.getCacheMissRead() << endl;
trace.endBlock();
// ---
tiledImage.clearCacheAndResetCacheMisses();
trace.beginBlock("test Range (writing)");
{
const int maximalValue = tiledImage.domain().size();
MyTiledImage::Range::OutputIterator it = tiledImage.range().outputIterator();
for (int ii = 0; ii < maximalValue; ++ii)
{
*it++ = 10; // TODO : don't work with WT
//it.setValue(10); it++;
}
}
trace.endBlock();
// ---
cpt=sumC=0;
trace.beginBlock("test ConstIterator");
for(VImage::Domain::ConstIterator it = tiledImage.domain().begin(), itend = tiledImage.domain().end();
it != itend; ++it)
{
trace.info() << tiledImage(*it) << ",";
sumC += tiledImage(*it);
cpt++;
}
trace.info() << "Cpt: " << cpt << " - sumC: " << sumC << endl;
trace.endBlock();*/
// ---
trace.beginBlock("read and write on MyTiledImage");
trace.info() << "Read value for Point 4,2: " << tiledImage(Z2i::Point(4,2)) << endl;
trace.info() << "Read value for Point 10,6: " << tiledImage(Z2i::Point(10,6)) << endl;
aValue = 1; tiledImage.setValue(Z2i::Point(11,7), aValue);
trace.info() << "Write value for Point 11,7: " << aValue << endl;
trace.info() << "Read value for Point 2,3: " << tiledImage(Z2i::Point(2,3)) << endl;
trace.info() << "Read value for Point 16,1: " << tiledImage(Z2i::Point(16,1)) << endl;
aValue = 128; tiledImage.setValue(Z2i::Point(16,1), aValue);
trace.info() << "Write value for Point 16,1: " << aValue << endl;
trace.info() << " Point 16,1 on ORIGINAL image, value: " << image(Z2i::Point(16,1)) << endl;
aBoard.clear();
Display2DFactory::drawImage<HueShade>(aBoard, image, (int)0, (int)255);
aBoard.saveSVG("tiledImage-image2.svg");
#ifdef WITH_CAIRO
aBoard.saveCairo("tiledImage-image2.png", Board2D::CairoPNG);
#endif
return 0;
}
// //
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
int main(int argc, char **argv)
MyPointD Point
Definition: testClone2.cpp:383
Image image(domain)
HyperRectDomain< Space > Domain