|
| 1 | +/** |
| 2 | + * @file testRawReader.cpp |
| 3 | + * @ingroup Tests |
| 4 | + * @author David Coeurjolly (\c [email protected] ) |
| 5 | + * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France |
| 6 | + * |
| 7 | + * @date 2010/07/29 |
| 8 | + * |
| 9 | + * Functions for testing class RawReader. |
| 10 | + * |
| 11 | + * This file is part of the DGtal library. |
| 12 | + */ |
| 13 | + |
| 14 | +/////////////////////////////////////////////////////////////////////////////// |
| 15 | +#include <iostream> |
| 16 | +#include "DGtal/base/Common.h" |
| 17 | + |
| 18 | +#include "DGtal/kernel/SpaceND.h" |
| 19 | +#include "DGtal/kernel/domains/HyperRectDomain.h" |
| 20 | +#include "DGtal/kernel/images/ImageSelector.h" |
| 21 | +#include "DGtal/io/readers/RawReader.h" |
| 22 | +#include "DGtal/io/colormaps/HueShadeColorMap.h" |
| 23 | +#include "DGtal/io/colormaps/GrayscaleColorMap.h" |
| 24 | +#include "DGtal/io/colormaps/GradientColorMap.h" |
| 25 | +#include "DGtal/io/colormaps/ColorBrightnessColorMap.h" |
| 26 | + |
| 27 | +#include "DGtal/io/writers/PNMWriter.h" |
| 28 | + |
| 29 | +#include "ConfigTest.h" |
| 30 | + |
| 31 | + |
| 32 | +/////////////////////////////////////////////////////////////////////////////// |
| 33 | + |
| 34 | +using namespace std; |
| 35 | +using namespace DGtal; |
| 36 | + |
| 37 | +/////////////////////////////////////////////////////////////////////////////// |
| 38 | +// Functions for testing class RawReader. |
| 39 | +/////////////////////////////////////////////////////////////////////////////// |
| 40 | +/** |
| 41 | + * Example of a test. To be completed. |
| 42 | + * |
| 43 | + */ |
| 44 | +bool testRawReader() |
| 45 | +{ |
| 46 | + unsigned int nbok = 0; |
| 47 | + unsigned int nb = 0; |
| 48 | + |
| 49 | + trace.beginBlock ( "Testing Raw reader ..." ); |
| 50 | + |
| 51 | + typedef SpaceND<int,2> Space2Type; |
| 52 | + typedef HyperRectDomain<Space2Type> TDomain; |
| 53 | + typedef TDomain::Vector Vector; |
| 54 | + |
| 55 | + //Default image selector = STLVector |
| 56 | + typedef ImageSelector<TDomain, unsigned char>::Type Image; |
| 57 | + |
| 58 | + std::string filename = testPath + "samples/raw2D-64x64.raw"; |
| 59 | + |
| 60 | + Vector ext(16,16); |
| 61 | + |
| 62 | + Image image = RawReader<Image>::importRaw8( filename , ext); |
| 63 | + |
| 64 | + ///FIXME: check io errors |
| 65 | + trace.info() << image <<endl; |
| 66 | + |
| 67 | + //export |
| 68 | + typedef GrayscaleColorMap<unsigned char> Gray; |
| 69 | + PNMWriter<Image,Gray>::exportPGM("export-raw-reader.pgm",image,0,255); |
| 70 | + |
| 71 | + |
| 72 | + nbok += true ? 1 : 0; |
| 73 | + nb++; |
| 74 | + trace.info() << "(" << nbok << "/" << nb << ") " |
| 75 | + << "true == true" << std::endl; |
| 76 | + trace.endBlock(); |
| 77 | + |
| 78 | + return nbok == nb; |
| 79 | +} |
| 80 | + |
| 81 | +/////////////////////////////////////////////////////////////////////////////// |
| 82 | +// Standard services - public : |
| 83 | + |
| 84 | +int main( int argc, char** argv ) |
| 85 | +{ |
| 86 | + trace.beginBlock ( "Testing class RawReader" ); |
| 87 | + trace.info() << "Args:"; |
| 88 | + for ( int i = 0; i < argc; ++i ) |
| 89 | + trace.info() << " " << argv[ i ]; |
| 90 | + trace.info() << endl; |
| 91 | + |
| 92 | + bool res = testRawReader(); // && ... other tests |
| 93 | + trace.emphase() << ( res ? "Passed." : "Error." ) << endl; |
| 94 | + trace.endBlock(); |
| 95 | + return res ? 0 : 1; |
| 96 | +} |
| 97 | +// // |
| 98 | +/////////////////////////////////////////////////////////////////////////////// |
0 commit comments