DGtal  1.2.0
exampleConstImageFunctorHolder.cpp
Go to the documentation of this file.
1 
32 // Inclusions
33 #include "DGtal/base/Common.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/io/boards/Board2D.h"
36 
37 #include <cmath>
38 #include <DGtal/io/colormaps/HueShadeColorMap.h>
39 
41 #include "DGtal/images/ConstImageFunctorHolder.h"
43 
44 int main()
45 {
46  using namespace DGtal::Z2i;
47 
48  DGtal::Board2D aBoard;
49 
51  using Value = double; // value type of the image
52  using HueShadeDouble = DGtal::HueShadeColorMap<Value>; // a simple HueShadeColorMap varying on 'double' values
54 
55  // Image from a unary lambda
57  const Domain domain1(Point(1,1), Point(16,16));
58 
60  domain1,
61  [] (Point const& pt) { return 25 * ( std::cos( (pt - Point(4,4)).norm() ) + 1 ); }
62  );
64 
65  aBoard.clear();
66  DGtal::Display2DFactory::drawImage<HueShadeDouble>(aBoard, image1, 0, 225);
67  aBoard.saveSVG("ConstImageFunctorHolder_example1.svg");
68 
69  // Image from a binary lambda
71  const Domain domain2(Point(-1,1), Point(18,18));
72 
74  domain2,
75  [] (Point const& pt, Domain const& d) { // we could also capture the domain
76  return 2 * std::min( ( pt - d.lowerBound() ).norm(), ( pt - d.upperBound() ).norm() );
77  }
78  );
80 
81  aBoard.clear();
82  DGtal::Display2DFactory::drawImage<HueShadeDouble>(aBoard, image2, 0, 225);
83  aBoard.saveSVG("ConstImageFunctorHolder_example2.svg");
84 
85  // Image that depends on other images
88  domain1,
89  [&image1, &image2] (Point const& pt) { return image1(pt) + image2(pt); }
90  );
92 
93  aBoard.clear();
94  DGtal::Display2DFactory::drawImage<HueShadeDouble>(aBoard, image3, 0, 225);
95  aBoard.saveSVG("ConstImageFunctorHolder_example3.svg");
96  return 0;
97 }
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...
const Point & lowerBound() const
const Point & upperBound() const
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
int main()
[include]
Z2i this namespace gathers the standard of types for 2D imagery.
Space::Point Point
Definition: StdDefs.h:95
auto holdConstImageFunctor(TDomain const &aDomain, TFunctor &&aFunctor) -> ConstImageFunctorHolder< TDomain, TValue, decltype(holdFunctor(std::forward< TFunctor >(aFunctor)))>
ConstImageFunctorHolder construction helper with specification of the return type.