testRawReader.cpp

Aim: implements methods to read a "Vol" file format. Description of template class 'RawReader'

The main import method "importRaw8" returns an instance of the template parameter TImageContainer.

Example usage:

 ...
 typedef SpaceND<int,3> Space3;
 typedef HyperRectDomain<Space3> TDomain;
 typedef TDomain::Point Point;

 //Default image container = STLVector
 typedef ImageSelector<TDomain, int>::Type Image;
 
 RawReader<Image> reader;
 Image image = reader.importRaw8("data.raw");

 trace.info() << image <<endl;
 ...
Template Parameters:
TImageContainer the image container to use.

#include <iostream>
#include "DGtal/base/Common.h"

#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/kernel/images/ImageSelector.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/colormaps/ColorBrightnessColorMap.h"

#include "DGtal/io/writers/PNMWriter.h"
#include "DGtal/io/readers/RawReader.h"

#include "ConfigTest.h"



using namespace std;
using namespace DGtal;

// Functions for testing class RawReader.

bool testRawReader2D()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;
  
  trace.beginBlock ( "Testing Raw reader ..." );
  
  typedef SpaceND<int,2> Space2Type;
  typedef HyperRectDomain<Space2Type> TDomain;
  typedef TDomain::Vector Vector;
  
  //Default image selector = STLVector
  typedef ImageSelector<TDomain, unsigned char>::Type Image;
  
  std::string filename = testPath + "samples/raw2D-64x64.raw";
  
  Vector ext(16,16);
  
  Image image = RawReader<Image>::importRaw8( filename , ext);

  trace.info() << image <<endl;

  //export
  typedef GrayscaleColorMap<unsigned char> Gray;  
  PNMWriter<Image,Gray>::exportPGM("export-raw-reader.pgm",image,0,255);

  
  nbok += true ? 1 : 0; 
  nb++;
  trace.info() << "(" << nbok << "/" << nb << ") "
               << "true == true" << std::endl;
  trace.endBlock();
  
  return nbok == nb;
}

// Standard services - public :

int main( int argc, char** argv )
{
  trace.beginBlock ( "Testing class RawReader" );
  trace.info() << "Args:";
  for ( int i = 0; i < argc; ++i )
    trace.info() << " " << argv[ i ];
  trace.info() << endl;

  bool res = testRawReader2D(); // && ... other tests
  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
  trace.endBlock();
  return res ? 0 : 1;
}
//                                                                           //
Generated on Wed Sep 29 15:53:45 2010 for DGtal by  doxygen 1.6.3