31#include <DGtal/kernel/SpaceND.h>
32#include <DGtal/kernel/domains/HyperRectDomain.h>
33#include <DGtal/images/ImageContainerBySTLVector.h>
34#include <DGtal/images/CConstImage.h>
35#include <DGtal/images/CImage.h>
37#include <DGtal/images/ArrayImageAdapter.h>
39#include "DGtalCatch.h"
44template <
typename TImage,
typename TDomain >
45void fillImageWithCounter ( TImage& anImage, TDomain
const& aDomain )
48 for (
auto const& point : aDomain )
49 anImage.setValue( point,
cnt++ );
52template <
typename TImage >
53void fillImageWithCounter ( TImage& anImage )
55 fillImageWithCounter( anImage, anImage.domain() );
58template <
typename TImage,
typename TFunction,
typename TDomain >
59void fillImageWithPointFn ( TImage& anImage, TFunction
const& aFunction, TDomain
const&
domain )
63 for (
auto const& point :
domain )
66 for (
Dimension i = 0; i < Image::dimension; ++i )
67 value += aFunction( i, point[i] );
69 anImage.setValue(point, value);
73template <
typename TImage,
typename TFunction >
74void fillImageWithPointFn ( TImage& anImage, TFunction
const& aFunction )
76 fillImageWithPointFn ( anImage, aFunction, anImage.domain() );
79template <
typename TImage,
typename TFunction,
typename TDomain >
80void incrementImageWithPointFn ( TImage& anImage, TFunction
const& aFunction, TDomain
const&
domain )
84 for (
auto const& point :
domain )
86 Value value = anImage(point);
87 for (
Dimension i = 0; i < Image::dimension; ++i )
88 value += aFunction( i, point[i] );
90 anImage.setValue(point, value);
94template <
typename TImage,
typename TFunction >
95void incrementImageWithPointFn ( TImage& anImage, TFunction
const& aFunction )
97 incrementImageWithPointFn ( anImage, aFunction, anImage.domain() );
100template <
typename TDomain,
typename TValue,
typename TFunction >
105 auto imgit = anImage.begin();
106 for (
auto const& point : anImage.
domain() )
109 for (
Dimension i = 0; i < Image::dimension; ++i )
110 value += aFunction( i, point[i] );
116template <
typename TIterator,
typename TDomain,
typename TFunction >
117void fastFillImageWithPointFn ( ArrayImageAdapter<TIterator, TDomain>& anImage, TFunction
const& aFunction )
119 typedef ArrayImageAdapter<TIterator, TDomain>
Image;
121 for (
auto imgit = anImage.begin(); imgit != anImage.end(); ++imgit )
124 auto const point = imgit.getPoint();
126 for (
Dimension i = 0; i < Image::dimension; ++i )
127 value += aFunction( i, point[i] );
133template <
typename TImage >
134void checkImage( TImage& anImage )
136 using Image = TImage;
140 using Dimension =
typename Point::Dimension;
141 using Coordinate =
typename Point::Coordinate;
148 auto const domain = anImage.domain();
153 for (
Dimension i = 0; i < Domain::dimension; ++i )
155 lowerPt[i] = std::min( upperPt[i]-1, lowerPt[i] + 1 +
static_cast<Coordinate
>(i) );
156 upperPt[i] = std::max( lowerPt[i]+1, upperPt[i] -
static_cast<Coordinate
>(Domain::dimension - i) );
158 auto const sub_domain =
Domain( lowerPt, upperPt );
164 RefImage ref_image(
domain );
167 auto const fn = [] (
size_t i, Coordinate x) {
return cos(
static_cast<Value>(pow(100, i)*x ) ); };
170 SECTION(
"Filling with point dependant function" )
172 fillImageWithPointFn( ref_image, fn );
173 fillImageWithPointFn( anImage, fn );
174 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
178 SECTION(
"Filling with counter" )
180 fillImageWithCounter( ref_image );
181 fillImageWithCounter( anImage );
182 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
186 SECTION(
"Fast filling with point dependant function" )
188 fastFillImageWithPointFn( ref_image, fn );
189 fastFillImageWithPointFn( anImage, fn );
190 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
194 SECTION(
"Tests on initialized images" )
196 fastFillImageWithPointFn( ref_image, fn );
197 fastFillImageWithPointFn( anImage, fn );
198 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
201 SECTION(
"Incrementing with point dependant function" )
203 incrementImageWithPointFn( ref_image, fn );
204 incrementImageWithPointFn( anImage, fn );
205 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
209 SECTION(
"Partial filling with counter" )
212 fillImageWithCounter( ref_image, sub_domain );
213 fillImageWithCounter( sub_image );
214 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
218 SECTION(
"Partial increment with point dependant function" )
221 incrementImageWithPointFn( ref_image, fn, sub_domain );
222 incrementImageWithPointFn( sub_image, fn );
223 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
227 SECTION(
"Fast partial filling with point dependand function" )
230 fillImageWithPointFn( ref_image, fn, sub_domain );
231 fastFillImageWithPointFn( sub_image, fn );
232 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
238template < DGtal::Dimension N >
243 using Value = double;
245 template <
typename TImage >
247 void checkThat( TImage & anImage )
253 static const Domain subDomain;
257using TestImage3D = TestImage<3>;
258using Point3D = TestImage3D::Domain::Point;
259template <>
const TestImage3D::Domain TestImage3D::domain{ Point3D{0, 1, 2}, Point3D{12, 8, 11} };
260template <>
const TestImage3D::Domain TestImage3D::subDomain{ Point3D{0, 2, 4}, Point3D{8, 7, 10} };
263TEST_CASE_METHOD( TestImage3D,
"Checking ArrayImageAdapter with C-style array",
"[CArray][FullDomain]" )
271TEST_CASE_METHOD( TestImage3D,
"Checking ArrayImageAdapter with C-style array on sub-domain",
"[CArray][SubDomain]" )
279TEST_CASE_METHOD( TestImage3D,
"Checking ArrayImageAdapter with ImageContainerBySTLVector",
"[ImageSTL][FullDomain]" )
283 checkThat(image_view);
286TEST_CASE_METHOD( TestImage3D,
"Checking ArrayImageAdapter with ImageContainerBySTLVector on sub-domain",
"[ImageSTL][SubDomain]" )
290 checkThat(image_view);
const Point & lowerBound() const
const Point & upperBound() const
const Domain & domain() const
Aim: implements association bewteen points lying in a digital domain and values.
DGtal is the top-level namespace which contains all DGtal functions and types.
ArrayImageAdapter< TArrayIterator, TDomain > makeArrayImageAdapterFromIterator(TArrayIterator anArrayIterator, TDomain const &aFullDomain, TDomain const &aViewDomain)
ArrayImageAdapter< decltype(((TImage *) nullptr) ->begin()), TDomain > makeArrayImageAdapterFromImage(TImage &anImage, TDomain const &aViewDomain)
DGtal::uint32_t Dimension
Aim: Defines the concept describing a read/write image, having an output iterator.
TEST_CASE_METHOD(Fixture_object_diamond_with_hole, "Basic Graph functions", "[interface]")
SECTION("Testing constant forward iterators")
HyperRectDomain< Space > Domain
REQUIRE(domain.isInside(aPoint))