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"
41 using namespace DGtal;
44 template <
typename TImage,
typename TDomain >
45 void fillImageWithCounter ( TImage& anImage, TDomain
const& aDomain )
48 for (
auto const& point : aDomain )
49 anImage.setValue( point,
cnt++ );
52 template <
typename TImage >
53 void fillImageWithCounter ( TImage& anImage )
55 fillImageWithCounter( anImage, anImage.domain() );
58 template <
typename TImage,
typename TFunction,
typename TDomain >
59 void 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);
73 template <
typename TImage,
typename TFunction >
74 void fillImageWithPointFn ( TImage& anImage, TFunction
const& aFunction )
76 fillImageWithPointFn ( anImage, aFunction, anImage.domain() );
79 template <
typename TImage,
typename TFunction,
typename TDomain >
80 void 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);
94 template <
typename TImage,
typename TFunction >
95 void incrementImageWithPointFn ( TImage& anImage, TFunction
const& aFunction )
97 incrementImageWithPointFn ( anImage, aFunction, anImage.domain() );
100 template <
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] );
116 template <
typename TIterator,
typename TDomain,
typename TFunction >
117 void 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] );
133 template <
typename TImage >
136 using Image = TImage;
140 using Coordinate =
typename Point::Coordinate;
147 auto const domain = anImage.domain();
152 for (
Dimension i = 0; i < Domain::dimension; ++i )
154 lowerPt[i] = std::min( upperPt[i]-1, lowerPt[i] + 1 +
static_cast<Coordinate
>(i) );
155 upperPt[i] =
std::max( lowerPt[i]+1, upperPt[i] -
static_cast<Coordinate
>(Domain::dimension - i) );
157 auto const sub_domain =
Domain( lowerPt, upperPt );
163 RefImage ref_image(
domain );
166 auto const fn = [] (
size_t i, Coordinate x) {
return cos(
static_cast<Value>(pow(100, i)*x ) ); };
169 SECTION(
"Filling with point dependant function" )
171 fillImageWithPointFn( ref_image, fn );
172 fillImageWithPointFn( anImage, fn );
173 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
177 SECTION(
"Filling with counter" )
179 fillImageWithCounter( ref_image );
180 fillImageWithCounter( anImage );
181 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
185 SECTION(
"Fast filling with point dependant function" )
187 fastFillImageWithPointFn( ref_image, fn );
188 fastFillImageWithPointFn( anImage, fn );
189 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
193 SECTION(
"Tests on initialized images" )
195 fastFillImageWithPointFn( ref_image, fn );
196 fastFillImageWithPointFn( anImage, fn );
197 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
200 SECTION(
"Incrementing with point dependant function" )
202 incrementImageWithPointFn( ref_image, fn );
203 incrementImageWithPointFn( anImage, fn );
204 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
208 SECTION(
"Partial filling with counter" )
211 fillImageWithCounter( ref_image, sub_domain );
212 fillImageWithCounter( sub_image );
213 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
217 SECTION(
"Partial increment with point dependant function" )
220 incrementImageWithPointFn( ref_image, fn, sub_domain );
221 incrementImageWithPointFn( sub_image, fn );
222 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
226 SECTION(
"Fast partial filling with point dependand function" )
229 fillImageWithPointFn( ref_image, fn, sub_domain );
230 fastFillImageWithPointFn( sub_image, fn );
231 REQUIRE( std::equal( ref_image.begin(), ref_image.end(), anImage.begin() ) );
237 template < DGtal::Dimension N >
242 using Value = double;
244 template <
typename TImage >
246 void checkThat( TImage & anImage )
252 static const Domain subDomain;
256 using TestImage3D = TestImage<3>;
259 template <>
const TestImage3D::Domain TestImage3D::subDomain{ Point3D{0, 2, 4}, Point3D{8, 7, 10} };
262 TEST_CASE_METHOD( TestImage3D,
"Checking ArrayImageAdapter with C-style array",
"[CArray][FullDomain]" )
270 TEST_CASE_METHOD( TestImage3D,
"Checking ArrayImageAdapter with C-style array on sub-domain",
"[CArray][SubDomain]" )
278 TEST_CASE_METHOD( TestImage3D,
"Checking ArrayImageAdapter with ImageContainerBySTLVector",
"[ImageSTL][FullDomain]" )
282 checkThat(image_view);
285 TEST_CASE_METHOD( TestImage3D,
"Checking ArrayImageAdapter with ImageContainerBySTLVector on sub-domain",
"[ImageSTL][SubDomain]" )
289 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.
TImageContainer::Point Point
TImageContainer::Domain Domain
TImageContainer::Value Value
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.
bool checkImage(const Image &a, const Image &b)
TEST_CASE_METHOD(Fixture_object_diamond_with_hole, "Basic Graph functions", "[interface]")
ImageContainerBySTLVector< Domain, Value > Image
SECTION("Testing constant forward iterators")
HyperRectDomain< Space > Domain
REQUIRE(domain.isInside(aPoint))