32#include "DGtal/base/Common.h"
33#include "DGtal/helpers/StdDefs.h"
34#include "DGtal/images/ImageContainerBySTLVector.h"
38#include "DGtal/images/ImageAdapter.h"
39#include "DGtal/images/ConstImageAdapter.h"
40#include "DGtal/io/colormaps/GrayscaleColorMap.h"
41#include "DGtal/io/readers/PGMReader.h"
42#include "DGtal/io/boards/Board2D.h"
44#include "ConfigTest.h"
55 unsigned int nbok = 0;
63 for (VImage::Iterator it = image.begin(); it != image.end(); ++it)
66 trace.
info() <<
"Original image: " << image << endl;
76 MyImageAdapter restimage(image,
domain, idD, idV, idVm1);
77 trace.
info() <<
"Restricted Image: " << restimage <<
" " << restimage.domain() << std::endl;
79 nbok += (restimage(
Z2i::Point(3,3)) == 10) ? 1 : 0;
81 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
82 <<
" read access on restricted Image" << endl;
85 nbok += (restimage(
Z2i::Point(3,3)) == 5) ? 1 : 0;
87 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
88 <<
" write on restricted Image" << endl;
92 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
93 <<
" written on original image" << endl;
109 template <
typename TValue>
110 class MyTransValueFunctor
113 typedef TValue
Value;
119 MyTransValueFunctor(
const Value& aValue = 0)
130 template <
typename TInput>
132 Value operator()(
const TInput& aInput)
const
134 return aInput+myValue;
147 unsigned int nbok = 0;
155 for (VImage::Iterator it = image.begin(); it != image.end(); ++it)
158 trace.
info() <<
"Original image: " << image << endl;
166 MyImageAdapter restimage(image,
domain, idD, idV);
167 trace.
info() <<
"Restricted Image: " << restimage <<
" " << restimage.domain() << std::endl;
168 nbok += (restimage(
Z2i::Point(3,3)) == 3) ? 1 : 0;
170 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
171 <<
" read access on restricted Image" << endl;
181 MyImageAdapter2 restimage2(image,
domain, idD_2, idV_2, idVm1_2);
185 nbok += (restimage2(
Z2i::Point(2,2)) ==
true) ? 1 : 0;
187 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
188 <<
" write on restricted Image 2" << endl;
195 trace.
warning()<<
"Restricted image with false at (2,2) = "<< (int)(restimage2)(
Z2i::Point(2,2)) << std::endl;
196 nbok += (restimage2(
Z2i::Point(2,2)) ==
true) ? 1 : 0;
198 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
199 <<
" write on restricted Image 2" << endl;
207 MyTransValueFunctor<Z2i::Point> idD_3(
Z2i::Point(2,2));
211 MyImageAdapter3 restimage3(image,
domain, idD_3, idV_3, idVm1_3);
214 nbok += (image(
Z2i::Point(4,4)) == 5) ? 1 : 0;
216 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
217 <<
" write on restricted Image 3" << endl;
230 unsigned int nbok = 0;
238 for (VImage::Iterator it = image.begin(); it != image.end(); ++it)
241 trace.
info() <<
"Original image: " << image << endl;
251 MyImageAdapter restimage(image,
domain, idD, idV, idVm1);
252 trace.
info() <<
"Restricted Image: " << restimage <<
" " << restimage.domain() << std::endl;
256 MyImageAdapter::Range::OutputIterator it = restimage.range().outputIterator();
257 for (
int i = 0; i < maximalValue; ++i)
261 MyImageAdapter::ConstRange r = restimage.constRange();
262 std::copy( r.begin(), r.end(), std::ostream_iterator<int>(cout,
", ") );
265 std::vector<int> to_vector(9);
266 std::copy(r.begin(), r.end(), to_vector.begin());
267 for (
int i = 0; i < 9; i++)
291 unsigned int nbok = 0;
299 string filename = testPath +
"samples/church-small.pgm";
301 trace.
info() <<
"Imported image: " << image << endl;
305 Display2DFactory::drawImage<Gray>(aBoard, image, (
unsigned char)0, (
unsigned char)255);
308 aBoard.
saveCairo(
"church.png", Board2D::CairoPNG);
321 MyImageAdapter bell_tower(image, domain_bell_tower, idbtD, idbtV, idbtVm1);
324 trace.
info() <<
"ImageAdapter: " << bell_tower <<
" " << bell_tower.domain() << std::endl;
326 nbok += bell_tower.isValid() ? 1 : 0;
330 Display2DFactory::drawImage<Gray>(aBoard, bell_tower, (
unsigned char)0, (
unsigned char)255);
331 aBoard.
saveSVG(
"bell_tower.svg");
333 aBoard.
saveCairo(
"bell_tower.png", Board2D::CairoPNG);
344 MyImageAdapter cars(image, domain_cars, idcD, idcV, idcVm1);
346 trace.
info() <<
"ImageAdapter: " << cars <<
" " << cars.domain() << std::endl;
348 nbok += cars.isValid() ? 1 : 0;
352 Display2DFactory::drawImage<Gray>(aBoard, cars, (
unsigned char)0, (
unsigned char)255);
355 aBoard.
saveCairo(
"cars.png", Board2D::CairoPNG);
359 MyImageAdapter::Domain::ConstIterator bt_it = bell_tower.domain().begin();
360 MyImageAdapter::Domain::ConstIterator bt_itEnd = bell_tower.domain().end();
361 for (; bt_it != bt_itEnd; ++bt_it)
363 bell_tower.setValue(*bt_it, 255);
367 Display2DFactory::drawImage<Gray>(aBoard, bell_tower, (
unsigned char)0, (
unsigned char)255);
368 aBoard.
saveSVG(
"bell_tower_after_filling.svg");
370 aBoard.
saveCairo(
"bell_tower_after_filling.png", Board2D::CairoPNG);
374 MyImageAdapter::Domain::ConstIterator c_it = cars.domain().begin();
375 MyImageAdapter::Domain::ConstIterator c_itEnd = cars.domain().end();
376 for (; c_it != c_itEnd; ++c_it)
378 cars.setValue(*c_it, 55);
382 Display2DFactory::drawImage<Gray>(aBoard, cars, (
unsigned char)0, (
unsigned char)255);
383 aBoard.
saveSVG(
"cars_after_filling.svg");
385 aBoard.
saveCairo(
"cars_after_filling.png", Board2D::CairoPNG);
399 it != domain_floor_lamp.
end();
414 MyImageAdapter2 floor_lamp(image, my_specific_domain_floor_lamp, idflD, idflV, idflVm1);
417 trace.
info() <<
"ImageAdapter: " << floor_lamp <<
" " << floor_lamp.domain() << std::endl;
419 nbok += floor_lamp.isValid() ? 1 : 0;
423 Display2DFactory::drawImage<Gray>(aBoard, floor_lamp, (
unsigned char)0, (
unsigned char)255);
424 aBoard.
saveSVG(
"floor_lamp.svg");
426 aBoard.
saveCairo(
"floor_lamp.png", Board2D::CairoPNG);
429 MyImageAdapter2::Domain::ConstIterator f_it = floor_lamp.domain().begin();
430 MyImageAdapter2::Domain::ConstIterator f_itEnd = floor_lamp.domain().end();
431 for (; f_it != f_itEnd; ++f_it)
433 floor_lamp.setValue(*f_it, 0);
437 Display2DFactory::drawImage<Gray>(aBoard, floor_lamp, (
unsigned char)0, (
unsigned char)255);
438 aBoard.
saveSVG(
"floor_lamp_after_filling.svg");
440 aBoard.
saveCairo(
"floor_lamp_after_filling.png", Board2D::CairoPNG);
444 Display2DFactory::drawImage<Gray>(aBoard, image, (
unsigned char)0, (
unsigned char)255);
445 aBoard.
saveSVG(
"church_after_filling.svg");
447 aBoard.
saveCairo(
"church_after_filling.png", Board2D::CairoPNG);
450 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
451 <<
"true == true" << endl;
461int main(
int argc,
char** argv )
465 for (
int i = 0; i < argc; ++i )
471 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
void insertNew(const Point &p)
Aim: Constructs a domain limited to the given digital set.
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Iterator for HyperRectDomain.
const ConstIterator & begin() const
const ConstIterator & end() const
Aim: implements an image adapter with a given domain (i.e. a subdomain) and 3 functors : g for domain...
void beginBlock(const std::string &keyword="")
Aim: Define a simple functor that returns a constant value (0 by default).
Aim: A small functor with an operator () that compares one value to a threshold value according to tw...
void clear(const DGtal::Color &color=DGtal::Color::None)
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
DGtal is the top-level namespace which contains all DGtal functions and types.
static ImageContainer importPGM(const std::string &aFilename, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
Aim: Defines the concept describing a read-only image, which is a refinement of CPointFunctor.
Aim: Defines the concept describing a read/write image, having an output iterator.
Aim: Define a simple functor using the static cast operator.
Aim: Define a simple default functor that just returns its argument.
bool test_range_constRange()