DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Types | Public Member Functions | Static Public Member Functions
DGtal::RawReader< TImageContainer > Struct Template Reference

#include <RawReader.h>

Public Types

typedef TImageContainer ImageContainer
typedef
TImageContainer::Domain::Vector 
Vector

Public Member Functions

 BOOST_STATIC_ASSERT ((ImageContainer::Domain::dimension==2)||(ImageContainer::Domain::dimension==3))

Static Public Member Functions

static ImageContainer importRaw8 (const std::string &filename, const Vector &extent) throw (DGtal::IOException)

Detailed Description

template<typename TImageContainer>
struct DGtal::RawReader< TImageContainer >

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:
TImageContainerthe image container to use.
See also:
testRawReader.cpp

Definition at line 84 of file RawReader.h.


Member Typedef Documentation

template<typename TImageContainer >
typedef TImageContainer DGtal::RawReader< TImageContainer >::ImageContainer

Definition at line 89 of file RawReader.h.

template<typename TImageContainer >
typedef TImageContainer::Domain::Vector DGtal::RawReader< TImageContainer >::Vector

Definition at line 90 of file RawReader.h.


Member Function Documentation

template<typename TImageContainer >
DGtal::RawReader< TImageContainer >::BOOST_STATIC_ASSERT ( (ImageContainer::Domain::dimension==2)||(ImageContainer::Domain::dimension==3)  )
template<typename T >
T DGtal::RawReader< T >::importRaw8 ( const std::string &  filename,
const Vector extent 
) throw (DGtal::IOException)
inlinestatic

Main method to import a Raw (8bits) into an instance of the template parameter ImageContainer.

Parameters:
filenamethe file name to import.
extentthe size of the raw data set.
Returns:
an instance of the ImageContainer.

Definition at line 40 of file RawReader.ih.

References DGtal::Trace::error(), and DGtal::trace.

{
FILE * fin;
DGtal::IOException dgtalerror;
fin = fopen( filename.c_str() , "r" );
if (fin == NULL)
trace.error() << "RawReader : can't open "<< filename<<endl;
typename T::Point firstPoint;
typename T::Point lastPoint;
firstPoint = T::Point::zero;
lastPoint = extent;
unsigned int size=1;
for(unsigned int i=0; i < T::Domain::dimension; i++)
{
size *= lastPoint[i];
lastPoint[i]--;
}
typename T::Domain domain(firstPoint,lastPoint);
T image(domain);
typename T::Value val;
//We scan the Raw file
typename T::Domain::ConstIterator it = domain.begin(),itend=domain.end();
unsigned int count=0;
while ((fin) && (it != itend))
{
val = getc(fin);
image.setValue( (*it),val);
it++;
count++;
}
fclose( fin );
if (count != size )
{
trace.error() << "RawReader: error while opening file "<<filename<<endl;
throw dgtalerror;
}
else
return image;
}

The documentation for this struct was generated from the following files: