DGtal 1.4.0
Loading...
Searching...
No Matches
testRawReader.cpp File Reference
#include "DGtalCatch.h"
#include <DGtal/base/Common.h>
#include <DGtal/kernel/SpaceND.h>
#include <DGtal/kernel/domains/HyperRectDomain.h>
#include <DGtal/images/ImageSelector.h>
#include <DGtal/io/readers/RawReader.h>
#include <DGtal/io/writers/RawWriter.h>
#include <DGtal/kernel/domains/Linearizer.h>
#include <ConfigTest.h>
#include <string>
Include dependency graph for testRawReader.cpp:

Go to the source code of this file.

Functions

template<typename Image >
void testImageOnRef (Image const &anImage)
 
template<DGtal::Dimension N>
void testRawReaderOnRef ()
 
template<typename Image >
void generateRefImage (Image &anImage, typename Image::Value aSeed)
 
template<DGtal::Dimension N, typename T , template< typename > class RawIO>
void testWriteAndRead (T aSeed)
 
 TEST_CASE ("Checking RawReader with reference files in 2D", "[reader][2D][raw][raw32][uint32]")
 
 TEST_CASE ("Checking RawReader with reference files in 3D", "[reader][3D][raw][raw32][uint32]")
 
 TEST_CASE ("Checking writing & reading uint8 in 2D with generic IO", "[reader][writer][2D][raw][uint8]")
 
 TEST_CASE ("Checking writing & reading uint8 in 2D with 8bits IO", "[reader][writer][2D][raw8][uint8]")
 
 TEST_CASE ("Checking writing & reading int8 in 2D with generic IO", "[reader][writer][2D][raw][int8]")
 
 TEST_CASE ("Checking writing & reading uint16 in 2D with generic IO", "[reader][writer][2D][raw][uint16]")
 
 TEST_CASE ("Checking writing & reading uint16 in 2D with 16bits IO", "[reader][writer][2D][raw16][uint16]")
 
 TEST_CASE ("Checking writing & reading int16 in 2D with generic IO", "[reader][writer][2D][raw][int16]")
 
 TEST_CASE ("Checking writing & reading uint32 in 2D with generic IO", "[reader][writer][2D][raw][uint32]")
 
 TEST_CASE ("Checking writing & reading uint32 in 2D with 32bits IO", "[reader][writer][2D][raw32][uint32]")
 
 TEST_CASE ("Checking writing & reading int32 in 2D with generic IO", "[reader][writer][2D][raw][int32]")
 
 TEST_CASE ("Checking writing & reading uint64 in 2D with generic IO", "[reader][writer][2D][raw][uint64]")
 
 TEST_CASE ("Checking writing & reading int64 in 2D with generic IO", "[reader][writer][2D][raw][int64]")
 
 TEST_CASE ("Checking writing & reading double in 1D with generic IO", "[reader][writer][1D][raw][double]")
 
 TEST_CASE ("Checking writing & reading double in 2D with generic IO", "[reader][writer][2D][raw][double]")
 
 TEST_CASE ("Checking writing & reading double in 3D with generic IO", "[reader][writer][3D][raw][double]")
 

Detailed Description

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
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
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
10/12/2015

Functions for testing class RawReader.

This file is part of the DGtal library.

Definition in file testRawReader.cpp.

Function Documentation

◆ generateRefImage()

template<typename Image >
void generateRefImage ( Image & anImage,
typename Image::Value aSeed )

Compares an image to a generated data.

Template Parameters
ImageImage type.
Parameters
[out]anImageThe image.
aSeedSeed for the generator.

Definition at line 130 of file testRawReader.cpp.

131{
132 typedef typename Image::Domain Domain;
133 typedef typename Domain::Point Point;
134
135 const Domain domain = anImage.domain();
136
137 for ( typename Domain::ConstIterator it = domain.begin(), itEnd = domain.end(); it != itEnd; ++it )
138 {
139 const Point pt = *it;
140 const typename Image::Value refValue = aSeed * Linearizer<Domain, RowMajorStorage>::getIndex( pt, domain );
141 anImage.setValue( pt, refValue );
142 }
143}
const ConstIterator & begin() const
const ConstIterator & end() const
const Domain & domain() const
Definition Image.h:192
void setValue(const Point &aPoint, const Value &aValue)
Definition Image.h:247
Aim: Linearization and de-linearization interface for domains.
Definition Linearizer.h:78
MyPointD Point
Domain domain
HyperRectDomain< Space > Domain

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Image< TImageContainer >::domain(), domain, DGtal::HyperRectDomain< TSpace >::end(), and DGtal::Image< TImageContainer >::setValue().

Referenced by testWriteAndRead().

◆ TEST_CASE() [1/16]

TEST_CASE ( "Checking RawReader with reference files in 2D" ,
"" [reader][2D][raw][raw32][uint32] )

Definition at line 246 of file testRawReader.cpp.

247{
249}
void testRawReaderOnRef()

References testRawReaderOnRef().

◆ TEST_CASE() [2/16]

TEST_CASE ( "Checking RawReader with reference files in 3D" ,
"" [reader][3D][raw][raw32][uint32] )

Definition at line 251 of file testRawReader.cpp.

252{
254}

References testRawReaderOnRef().

◆ TEST_CASE() [3/16]

TEST_CASE ( "Checking writing & reading double in 1D with generic IO" ,
"" [reader][writer][1D][raw][double] )

Definition at line 316 of file testRawReader.cpp.

317{
319}
void testWriteAndRead(T aSeed)

References testWriteAndRead().

◆ TEST_CASE() [4/16]

TEST_CASE ( "Checking writing & reading double in 2D with generic IO" ,
"" [reader][writer][2D][raw][double] )

Definition at line 321 of file testRawReader.cpp.

322{
324}

References testWriteAndRead().

◆ TEST_CASE() [5/16]

TEST_CASE ( "Checking writing & reading double in 3D with generic IO" ,
"" [reader][writer][3D][raw][double] )

Definition at line 326 of file testRawReader.cpp.

327{
329}

References testWriteAndRead().

◆ TEST_CASE() [6/16]

TEST_CASE ( "Checking writing & reading int16 in 2D with generic IO" ,
"" [reader][writer][2D][raw][int16] )

Definition at line 283 of file testRawReader.cpp.

References testWriteAndRead().

◆ TEST_CASE() [7/16]

TEST_CASE ( "Checking writing & reading int32 in 2D with generic IO" ,
"" [reader][writer][2D][raw][int32] )

Definition at line 299 of file testRawReader.cpp.

References testWriteAndRead().

◆ TEST_CASE() [8/16]

TEST_CASE ( "Checking writing & reading int64 in 2D with generic IO" ,
"" [reader][writer][2D][raw][int64] )

Definition at line 310 of file testRawReader.cpp.

References testWriteAndRead().

◆ TEST_CASE() [9/16]

TEST_CASE ( "Checking writing & reading int8 in 2D with generic IO" ,
"" [reader][writer][2D][raw][int8] )

Definition at line 267 of file testRawReader.cpp.

References testWriteAndRead().

◆ TEST_CASE() [10/16]

TEST_CASE ( "Checking writing & reading uint16 in 2D with 16bits IO" ,
"" [reader][writer][2D][raw16][uint16] )

Definition at line 278 of file testRawReader.cpp.

References testWriteAndRead().

◆ TEST_CASE() [11/16]

TEST_CASE ( "Checking writing & reading uint16 in 2D with generic IO" ,
"" [reader][writer][2D][raw][uint16] )

Definition at line 273 of file testRawReader.cpp.

References testWriteAndRead().

◆ TEST_CASE() [12/16]

TEST_CASE ( "Checking writing & reading uint32 in 2D with 32bits IO" ,
"" [reader][writer][2D][raw32][uint32] )

Definition at line 294 of file testRawReader.cpp.

References testWriteAndRead().

◆ TEST_CASE() [13/16]

TEST_CASE ( "Checking writing & reading uint32 in 2D with generic IO" ,
"" [reader][writer][2D][raw][uint32] )

Definition at line 289 of file testRawReader.cpp.

References testWriteAndRead().

◆ TEST_CASE() [14/16]

TEST_CASE ( "Checking writing & reading uint64 in 2D with generic IO" ,
"" [reader][writer][2D][raw][uint64] )

Definition at line 305 of file testRawReader.cpp.

References testWriteAndRead().

◆ TEST_CASE() [15/16]

TEST_CASE ( "Checking writing & reading uint8 in 2D with 8bits IO" ,
"" [reader][writer][2D][raw8][uint8] )

Definition at line 262 of file testRawReader.cpp.

References testWriteAndRead().

◆ TEST_CASE() [16/16]

TEST_CASE ( "Checking writing & reading uint8 in 2D with generic IO" ,
"" [reader][writer][2D][raw][uint8] )

Definition at line 257 of file testRawReader.cpp.

References testWriteAndRead().

◆ testImageOnRef()

template<typename Image >
void testImageOnRef ( Image const & anImage)

Compares an image to the reference data.

Template Parameters
ImageImage type.
Parameters
anImageThe image to test.

Definition at line 62 of file testRawReader.cpp.

63{
64 typedef typename Image::Domain Domain;
65 typedef typename Domain::Point Point;
66
67 // Checking domain
68 INFO( "Checking domain" )
69 REQUIRE( anImage.domain().lowerBound() == Point::diagonal(0) );
70 REQUIRE( anImage.domain().upperBound() == Point::diagonal(4) );
71
72 // Checking values
73 INFO( "Checking values" )
74 const Domain domain = anImage.domain();
75 for ( typename Domain::ConstIterator it = domain.begin(), itEnd = domain.end(); it != itEnd; ++it )
76 {
77 const Point pt = *it;
78 const unsigned int refValue = anImage.dimension == 2 ?
79 1000000 * pt[0] * pt[1]
80 : 250000 * pt[0] * pt[1] * pt[2];
81
82 INFO( "At point " << pt );
83 REQUIRE( anImage( pt ) == refValue );
84 }
85}
MyDigitalSurface::ConstIterator ConstIterator
REQUIRE(domain.isInside(aPoint))
for(Domain::ConstIterator it=domain.begin(), it_end=domain.end();it !=it_end;++it,++cnt)

References DGtal::HyperRectDomain< TSpace >::begin(), DGtal::Image< TImageContainer >::domain(), domain, DGtal::HyperRectDomain< TSpace >::end(), and REQUIRE().

Referenced by testRawReaderOnRef().

◆ testRawReaderOnRef()

template<DGtal::Dimension N>
void testRawReaderOnRef ( )

Reads and compares a raw file to the reference data.

Template Parameters
NDimension of the image.

Definition at line 93 of file testRawReader.cpp.

94{
95 REQUIRE( N >= 2 );
96 REQUIRE( N <= 3 );
97
98 typedef SpaceND<N> Space;
101 typedef typename Domain::Vector Vector;
102
103 // Generating file name
104 std::string fileName = testPath + "samples/";
105 if ( N == 2)
106 fileName += "raw32bits5x5.raw";
107 else
108 fileName += "raw32bits5x5x5.raw";
109
110 // Reading file
111 const Vector extent = Vector::diagonal(5);
112
113 INFO( "Reading file with importRaw32" << fileName );
114 Image imageRaw32 = RawReader<Image>::importRaw32( fileName, extent );
115 testImageOnRef( imageRaw32 );
116
117 INFO( "Reading file with importRaw" << fileName );
118 Image imageRaw = RawReader<Image>::template importRaw< unsigned int >( fileName, extent );
119 testImageOnRef( imageRaw );
120}
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
DigitalPlane::Point Vector
Aim: Raw binary import of an Image.
Definition RawReader.h:94
static ImageContainer importRaw32(const std::string &filename, const Vector &extent, const Functor &aFunctor=Functor())
void testImageOnRef(Image const &anImage)
ImageContainerBySTLVector< Domain, Value > Image

References DGtal::RawReader< TImageContainer, TFunctor >::importRaw32(), REQUIRE(), and testImageOnRef().

Referenced by TEST_CASE(), and TEST_CASE().

◆ testWriteAndRead()

template<DGtal::Dimension N, typename T , template< typename > class RawIO>
void testWriteAndRead ( T aSeed)

Checks reading a previously writed file.

Template Parameters
NDimension of the image.
TValue type.
RawIOClass with writer and reader, templated by the image type.
Parameters
aSeedSeed to generate image values.

Definition at line 156 of file testRawReader.cpp.

157{
158 typedef SpaceND<N> Space;
160 typedef typename ImageSelector<Domain, T>::Type Image;
161 typedef typename Domain::Point Point;
162
163 Point upperPt;
164 upperPt[ 0 ] = 8;
165 for ( Dimension i = 1; i < N; ++i )
166 upperPt[ i ] = upperPt[ i-1 ] * ( i == 1 ? 4 : 2 );
167
168 const Domain domain( Point::diagonal(0), upperPt );
170 generateRefImage( refImage, aSeed );
171
172 INFO( "Writing image" );
173 RawIO<Image>::write( "export-raw-writer.raw", refImage );
174
175 INFO( "Reading image" );
176 Image image = RawIO<Image>::read( "export-raw-writer.raw", upperPt + Point::diagonal(1) );
177
178 INFO( "Comparing image values" );
179 for ( typename Domain::ConstIterator it = domain.begin(), itEnd = domain.end(); it != itEnd; ++it )
180 {
181 const Point pt = *it;
182 INFO( "At point " << pt );
183 REQUIRE( image( pt ) == refImage( pt ) );
184 }
185}
DGtal::uint32_t Dimension
Definition Common.h:136
void generateRefImage(Image &anImage, typename Image::Value aSeed)
Image refImage(domain)

References DGtal::HyperRectDomain< TSpace >::begin(), domain, DGtal::HyperRectDomain< TSpace >::end(), generateRefImage(), refImage(), and REQUIRE().

Referenced by TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), TEST_CASE(), and TEST_CASE().