DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testHDF5Reader.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/writers/PPMWriter.h"
#include "DGtal/io/readers/HDF5Reader.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
#include "ConfigTest.h"

Go to the source code of this file.

Functions

bool testHDF5Reader ()
 
bool testHDF5_3DReader ()
 
int main (int argc, char **argv)
 

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
Martial Tola (marti.nosp@m.al.t.nosp@m.ola@l.nosp@m.iris.nosp@m..cnrs.nosp@m..fr )
Date
2013/04/16

Functions for testing class HDF5Reader.

This file is part of the DGtal library.

Definition in file testHDF5Reader.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 119 of file testHDF5Reader.cpp.

120{
121 trace.beginBlock ( "Testing class HDF5Reader" );
122 trace.info() << "Args:";
123 for ( int i = 0; i < argc; ++i )
124 trace.info() << " " << argv[ i ];
125 trace.info() << endl;
126
127 bool res = testHDF5Reader() && testHDF5_3DReader(); // && ... other tests
128 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
129 trace.endBlock();
130 return res ? 0 : 1;
131}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
bool testHDF5_3DReader()
bool testHDF5Reader()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testHDF5_3DReader(), testHDF5Reader(), and DGtal::trace.

◆ testHDF5_3DReader()

bool testHDF5_3DReader ( )

Definition at line 76 of file testHDF5Reader.cpp.

77{
78 unsigned int nbok = 0;
79 unsigned int nb = 0;
80
81 trace.beginBlock ( "Testing hdf5 3D reader ..." );
82
83 typedef SpaceND<3> Space4Type;
84 typedef HyperRectDomain<Space4Type> TDomain;
85
86 //Default image selector = STLVector
88
89
90 std::string filename = testPath + "samples/cat10.h5";
91 Image image = HDF5Reader<Image>::importHDF5_3D( filename, "/UInt8Array3D" );
92
93 trace.info() << image <<endl;
94
95 nbok += true ? 1 : 0;
96 nb++;
97
98 unsigned int nbval=0;
99 for(Image::ConstIterator it=image.begin(), itend=image.end();
100 it != itend; ++it)
101 if ( (*it) != 0)
102 nbval++;
103
104 trace.info() << "Number of points with (val!=0) = "<<nbval<<endl;
105
106 nbok += ( nbval == 8043) ? 1 : 0;
107 nb++;
108
109 trace.info() << "(" << nbok << "/" << nb << ") "
110 << "true == true" << std::endl;
111 trace.endBlock();
112
113 return nbok == nb;
114}
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
static ImageContainer importHDF5_3D(const std::string &aFilename, const std::string &aDataset, const Functor &aFunctor=Functor())

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::HDF5Reader< TImageContainer, TFunctor >::importHDF5_3D(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testHDF5Reader()

bool testHDF5Reader ( )

Definition at line 47 of file testHDF5Reader.cpp.

48{
49 unsigned int nbok = 0;
50 unsigned int nb = 0;
51
52 trace.beginBlock ( "Testing hdf5 reader ..." );
53 nbok += true ? 1 : 0;
54 nb++;
55 std::string filename = testPath + "samples/ex_image2.h5";
56
57 trace.info() << "Loading filename: " << filename << std::endl;
58
59 typedef GrayscaleColorMap<unsigned char> Gray; // a simple GrayscaleColorMap varying on 'unsigned char' values
61
62 Image image = HDF5Reader<Image>::importHDF5( filename, "/image8bit" );
63 trace.info() << "image8bitFromHDF5image image: " << image << endl;
64 PPMWriter<Image,Gray>::exportPPM("image8bitFromHDF5image.ppm", image, Gray(0,255));
65
66 image = HDF5Reader<Image>::importHDF5( filename, "/image24bitpixel" );
67 trace.info() << "image24bitFromHDF5image image: " << image << endl;
68 PPMWriter<Image,Gray>::exportPPM("image24bitFromHDF5image.ppm", image, Gray(0,255));
69
70 trace.info() << "(" << nbok << "/" << nb << ") " << "true == true" << std::endl;
71 trace.endBlock();
72
73 return nbok == nb;
74}
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
static ImageContainer importHDF5(const std::string &aFilename, const std::string &aDataset, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
ImageContainerBySTLVector< Domain, Value > Type
Definition: ImageSelector.h:78
static bool exportPPM(const std::string &filename, const Image &aImage, const Functor &aFunctor=Functor(), bool topbottomOrder=true)

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::PPMWriter< TImage, TFunctor >::exportPPM(), DGtal::HDF5Reader< TImageContainer, TFunctor >::importHDF5(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().