testVolReader.cpp

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

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

The private methods have been backported from the SimpleVol project (see http://liris.cnrs.fr/david.coeurjolly).

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;

 Image image = VolReader<Image>::importVol("data.vol");

 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/readers/VolReader.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/VolWriter.h"

#include "ConfigTest.h"


using namespace std;
using namespace DGtal;

// Functions for testing class VolReader.

bool testVolReader()
{
  unsigned int nbok = 0;
  unsigned int nb = 0;
  
  trace.beginBlock ( "Testing VolReader ..." );

  typedef SpaceND<int,3> Space4Type;
  typedef HyperRectDomain<Space4Type> TDomain;
  typedef TDomain::Point Point;
  
  //Default image selector = STLVector
  typedef ImageSelector<TDomain, unsigned char>::Type Image;
  
  
  std::string filename = testPath + "samples/cat10.vol";
  Image image = VolReader<Image>::importVol( filename );
  
  trace.info() << image <<endl;
  
  nbok += true ? 1 : 0; 
  nb++;

  unsigned int nbval=0;
  for(Image::ConstIterator it=image.begin(), itend=image.end();
      it != itend;   ++it)
    if ( image(it) != 0)
      nbval++;
  
  trace.info() << "Number of points with (val!=0)  = "<<nbval<<endl;

  nbok += ( nbval == 8043)  ? 1 : 0; 
  nb++;

  typedef HueShadeColorMap<unsigned char> Hue;
  typedef GrayscaleColorMap<unsigned char> Gray;

  VolWriter<Image,Gray>::exportVol("catenoid-export.vol",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 VolReader" );
  trace.info() << "Args:";
  for ( int i = 0; i < argc; ++i )
    trace.info() << " " << argv[ i ];
  trace.info() << endl;

  bool res = testVolReader(); // && ... 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