DGtal 1.4.0
Loading...
Searching...
No Matches
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
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.endBlock();
// ---
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
MyImageCacheReadPolicyFIFO imageCacheReadPolicyFIFO(imageFactoryFromImage, 2);
MyImageCacheWritePolicyWT imageCacheWritePolicyWT(imageFactoryFromImage);
// here we create the TiledImage
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;
trace.endBlock();
// ---
/*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
trace.endBlock();
return 0;
}
// //
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
DGtal is the top-level namespace which contains all DGtal functions and types.
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