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" 48 using namespace DGtal;
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));
208 functors::Identity idV_3;
209 functors::Identity idVm1_3;
211 MyImageAdapter3 restimage3(image, domain, idD_3, idV_3, idVm1_3);
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;
255 const int maximalValue = domain.
size();
256 MyImageAdapter::Range::OutputIterator it = restimage.range().outputIterator();
257 for (
int i = 0; i < maximalValue; ++i)
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++)
272 nbok +=
true ? 1 : 0; nb++;
277 nbok +=
false ? 1 : 0; nb++;
290 unsigned int nbok = 0;
298 string filename = testPath +
"samples/church-small.pgm";
300 trace.
info() <<
"Imported image: " << image << endl;
304 Display2DFactory::drawImage<Gray>(aBoard,
image, (
unsigned char)0, (
unsigned char)255);
307 aBoard.saveCairo(
"church.png", Board2D::CairoPNG);
313 nbok +=
true ? 1 : 0;
323 MyImageAdapter bell_tower(image, domain_bell_tower, idbtD, idbtV, idbtVm1);
326 trace.
info() <<
"ImageAdapter: " << bell_tower <<
" " << bell_tower.domain() << std::endl;
328 nbok += bell_tower.isValid() ? 1 : 0;
332 Display2DFactory::drawImage<Gray>(aBoard, bell_tower, (
unsigned char)0, (
unsigned char)255);
333 aBoard.saveSVG(
"bell_tower.svg");
335 aBoard.saveCairo(
"bell_tower.png", Board2D::CairoPNG);
346 MyImageAdapter cars(image, domain_cars, idcD, idcV, idcVm1);
348 trace.
info() <<
"ImageAdapter: " << cars <<
" " << cars.domain() << std::endl;
350 nbok += cars.isValid() ? 1 : 0;
354 Display2DFactory::drawImage<Gray>(aBoard, cars, (
unsigned char)0, (
unsigned char)255);
355 aBoard.saveSVG(
"cars.svg");
357 aBoard.saveCairo(
"cars.png", Board2D::CairoPNG);
363 for (; bt_it != bt_itEnd; ++bt_it)
365 bell_tower.setValue(*bt_it, 255);
369 Display2DFactory::drawImage<Gray>(aBoard, bell_tower, (
unsigned char)0, (
unsigned char)255);
370 aBoard.saveSVG(
"bell_tower_after_filling.svg");
372 aBoard.saveCairo(
"bell_tower_after_filling.png", Board2D::CairoPNG);
378 for (; c_it != c_itEnd; ++c_it)
380 cars.setValue(*c_it, 55);
384 Display2DFactory::drawImage<Gray>(aBoard, cars, (
unsigned char)0, (
unsigned char)255);
385 aBoard.saveSVG(
"cars_after_filling.svg");
387 aBoard.saveCairo(
"cars_after_filling.png", Board2D::CairoPNG);
401 it != domain_floor_lamp.
end();
415 functors::Identity idflD, idflV, idflVm1;
416 MyImageAdapter2 floor_lamp(image, my_specific_domain_floor_lamp, idflD, idflV, idflVm1);
419 trace.
info() <<
"ImageAdapter: " << floor_lamp <<
" " << floor_lamp.domain() << std::endl;
421 nbok += floor_lamp.isValid() ? 1 : 0;
425 Display2DFactory::drawImage<Gray>(aBoard, floor_lamp, (
unsigned char)0, (
unsigned char)255);
426 aBoard.saveSVG(
"floor_lamp.svg");
428 aBoard.saveCairo(
"floor_lamp.png", Board2D::CairoPNG);
433 for (; f_it != f_itEnd; ++f_it)
435 floor_lamp.setValue(*f_it, 0);
439 Display2DFactory::drawImage<Gray>(aBoard, floor_lamp, (
unsigned char)0, (
unsigned char)255);
440 aBoard.saveSVG(
"floor_lamp_after_filling.svg");
442 aBoard.saveCairo(
"floor_lamp_after_filling.png", Board2D::CairoPNG);
446 Display2DFactory::drawImage<Gray>(aBoard,
image, (
unsigned char)0, (
unsigned char)255);
447 aBoard.saveSVG(
"church_after_filling.svg");
449 aBoard.saveCairo(
"church_after_filling.png", Board2D::CairoPNG);
452 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " 453 <<
"true == true" << endl;
463 int main(
int argc,
char** argv )
467 for (
int i = 0; i < argc; ++i )
473 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
void beginBlock(const std::string &keyword="")
const ConstIterator & end() const
Aim: Define a simple functor that returns a constant value (0 by default).
const Domain domain(Point(1, 2), Point(6, 5))
MyDigitalSurface::ConstIterator ConstIterator
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Aim: Define a simple functor using the static cast operator.
Image::ConstRange ConstRange
void insertNew(const Point &p)
bool test_range_constRange()
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Aim: Define a simple default functor that just returns its argument.
Aim: A small functor with an operator () that compares one value to a threshold value according to tw...
int main(int argc, char **argv)
Aim: implements an image adapter with a given domain (i.e. a subdomain) and 3 functors : g for domain...
const ConstIterator & begin() const
Aim: Constructs a domain limited to the given digital set.
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
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: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...