DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
exampleArrayImageAdapter.cpp File Reference

An example file for ArrayImageAdapter. More...

#include <iostream>
#include <DGtal/base/Common.h>
#include <DGtal/helpers/StdDefs.h>
#include <DGtal/io/boards/Board2D.h>
#include <new>
#include <cmath>
#include <algorithm>
#include <DGtal/io/colormaps/HueShadeColorMap.h>
#include <DGtal/images/ImageContainerBySTLVector.h>
#include <DGtal/images/ArrayImageAdapter.h>

Go to the source code of this file.

Functions

void ArrayImageAdapter_example ()
 
void moduleImages_example ()
 
int main ()
 

Detailed Description

An example file for ArrayImageAdapter.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Roland Denis (rolan.nosp@m.d.de.nosp@m.nis@u.nosp@m.niv-.nosp@m.smb.f.nosp@m.r ) LAboratory of MAthematics - LAMA (CNRS, UMR 5127), University of Savoie, France
Date
2015/10/14

This file is part of the DGtal library.

Definition in file exampleArrayImageAdapter.cpp.

Function Documentation

◆ ArrayImageAdapter_example()

void ArrayImageAdapter_example ( )

[ArrayImageAdapter_example]

[ArrayImageAdapter_example]

Definition at line 53 of file exampleArrayImageAdapter.cpp.

54{
56 using Space = SpaceND<2>;
58 using Point = Domain::Point;
59 using Value = double;
60
61 const Domain domain( Point(0, 1), Point(4, 3) );
62
63 Value* data = new Value[ domain.size() ];
64
65 // Convert this allocated memory to a CImage model.
66 ArrayImageAdapter< Value*, Domain > image( data, domain );
67 // Alternative syntax using the helpers:
68 // auto image = makeArrayImageAdapterFromIterator( data, domain );
69
70 // Fill the image with first coordinate of the point
71 for ( auto it = image.begin(); it != image.end(); ++it )
72 {
73 *it = it.getPoint()[0];
74 }
75
76 // Get a constant view on a sub-domain.
77 const Domain sub_domain( Point(1, 1), Point(3, 2) );
78 ArrayImageAdapter< Value const*, Domain > cst_image( data, domain, sub_domain );
79 // Alternative syntax using the helpers:
80 // auto const cst_image = makeArrayImageAdapterFromImage( image, sub_domain );
81
82 // Display it.
83 for ( auto value : cst_image )
84 {
85 std::cout << value << " ";
86 }
87 std::cout << std::endl;
89}
MyPointD Point
Definition: testClone2.cpp:383
Domain domain

References domain, and DGtal::HyperRectDomain< TSpace >::size().

Referenced by main().

◆ main()

int main ( void  )

Definition at line 209 of file exampleArrayImageAdapter.cpp.

210{
213 return 0;
214}
void moduleImages_example()
void ArrayImageAdapter_example()

References ArrayImageAdapter_example(), and moduleImages_example().

◆ moduleImages_example()

void moduleImages_example ( )

[def]

[def]

[raw_image_creation]

[raw_image_creation]

[image_filling]

[image_filling]

[ConstArrayImageAdapterForSubImage_creation]

[ConstArrayImageAdapterForSubImage_creation]

[ArrayImageAdapterForSubImage_creation]

[ArrayImageAdapterForSubImage_creation]

[ArrayImageAdapterForSubImage_alternateCreation]

[ArrayImageAdapterForSubImage_alternateCreation]

[ArrayImageAdapterForSubImage_modifByDomain]

[ArrayImageAdapterForSubImage_modifByDomain]

[ArrayImageAdapterForSubImage_modifByImage]

[ArrayImageAdapterForSubImage_modifByImage]

[ImageSTL_creation]

[ImageSTL_creation]

[ArrayImageAdapterFromImageSTL]

[ArrayImageAdapterFromImageSTL]

[ArrayImageAdapterFromImageSTL_alternate]

[ArrayImageAdapterFromImageSTL_alternate]

[ArrayImageAdapterFromImageSTL_copy]

[ArrayImageAdapterFromImageSTL_copy]

Definition at line 91 of file exampleArrayImageAdapter.cpp.

92{
93 using namespace Z2i;
94
95 Board2D aBoard;
96
98 using Value = double; // value type of the image
99 using HueShadeDouble = HueShadeColorMap<Value>; // a simple HueShadeColorMap varying on 'double' values
101
102 trace.beginBlock("image");
103
105 const Domain domain(Point(1,1), Point(16,16));
106 Value* data = new Value[ domain.size() ];
107 ArrayImageAdapter< Value*, Domain > image( data, domain );
109
111 Value i = 0;
112 for ( auto & value : image )
113 value = i++;
115
116 aBoard.clear();
117 Display2DFactory::drawImage<HueShadeDouble>(aBoard, image, 0, domain.size()-1);
118 aBoard.saveSVG("ArrayImageAdapter_image.svg");
119
120 trace.endBlock();
121
122 trace.beginBlock("subImage");
123
125 Domain subDomain(Point(1,1), Point(8,8));
126 ArrayImageAdapter< Value const*, Domain > constSubImage( data, domain, subDomain );
128
129 aBoard.clear();
130 Display2DFactory::drawImage<HueShadeDouble>(aBoard, constSubImage, 0, domain.size()-1);
131 aBoard.saveSVG("ArrayImageAdapter_subImage.svg");
132
133 trace.endBlock();
134
135 trace.beginBlock("modifying subImage through domain iterator");
136 {
138 ArrayImageAdapter< Value*, Domain > subImage( data, domain, subDomain );
140 }
141
143 auto subImage = makeArrayImageAdapterFromIterator( data, domain, subDomain );
145
146
148 for ( auto point : subImage.domain() )
149 {
150 Value coord = (point - Point(4,4)).norm();
151 subImage.setValue( point, 25*(cos(coord)+1) );
152 }
154
155 aBoard.clear();
156 Display2DFactory::drawImage<HueShadeDouble>(aBoard, image, 0, domain.size()-1);
157 aBoard.saveSVG("ArrayImageAdapter_subImage_modifByDomain.svg");
158
159 trace.endBlock();
160
161 trace.beginBlock("modifying subImage through image iterator");
163 for ( auto it = subImage.begin(), it_end = subImage.end(); it != it_end; ++it )
164 {
165 Value coord = (it.getPoint() - Point(4,4)).norm();
166 *it = 25*(sin(coord)+1);
167 }
169
170 aBoard.clear();
171 Display2DFactory::drawImage<HueShadeDouble>(aBoard, image, 0, domain.size()-1);
172 aBoard.saveSVG("ArrayImageAdapter_subImage_modifByImage.svg");
173
174 trace.endBlock();
175
176 trace.beginBlock("subImage from an ImageContainerBySTLVector");
179 for (auto& value : anIterableImage)
180 value = 0;
182
184 {
185 ArrayImageAdapter< ImageContainerBySTLVector<Domain,Value>::Iterator, Domain > subImageSTL( anIterableImage.begin(), domain, subDomain );
186 }
188
190 auto subImageSTL = makeArrayImageAdapterFromImage( anIterableImage, subDomain );
192
193 trace.endBlock();
194
195 trace.beginBlock("using std::copy on ArrayImageAdapter");
197 std::copy( subImage.cbegin(), subImage.cend(), subImageSTL.begin() );
199
200 aBoard.clear();
201 Display2DFactory::drawImage<HueShadeDouble>(aBoard, anIterableImage, 0, domain.size()-1);
202 aBoard.saveSVG("ArrayImageAdapter_subImage_copyToImageSTL.svg");
203
204 trace.endBlock();
205
206 delete[] data;
207}
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...
void beginBlock(const std::string &keyword="")
double endBlock()
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
ArrayImageAdapter< TArrayIterator, TDomain > makeArrayImageAdapterFromIterator(TArrayIterator anArrayIterator, TDomain const &aFullDomain, TDomain const &aViewDomain)
ArrayImageAdapter< decltype(((TImage *) nullptr) ->begin()), TDomain > makeArrayImageAdapterFromImage(TImage &anImage, TDomain const &aViewDomain)
Trace trace
Definition: Common.h:154

References DGtal::Trace::beginBlock(), LibBoard::Board::clear(), domain, DGtal::Trace::endBlock(), DGtal::makeArrayImageAdapterFromImage(), DGtal::makeArrayImageAdapterFromIterator(), LibBoard::Board::saveSVG(), DGtal::HyperRectDomain< TSpace >::size(), and DGtal::trace.

Referenced by main().