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::PPMWriter< TImage, TFunctor > Struct Template Reference

#include <PPMWriter.h>

Public Types

typedef TImage Image
typedef TImage::Value Value
typedef TFunctor Functor

Public Member Functions

 BOOST_CONCEPT_ASSERT ((CUnaryFunctor< TFunctor, Value, DGtal::Color >))
 BOOST_STATIC_ASSERT ((TImage::Domain::dimension==2)||(TImage::Domain::dimension==3))

Static Public Member Functions

static bool exportPPM (const std::string &filename, const Image &aImage, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
static bool exportPPM3D (const std::string &filename, const Image &aImage, const Functor &aFunctor=Functor())

Detailed Description

template<typename TImage, typename TFunctor>
struct DGtal::PPMWriter< TImage, TFunctor >

Aim: Export a 2D and a 3D Image using the Netpbm PPM formats (ASCII mode).

Description of template struct 'PPMWriter'

A functor can be specified to convert image values to DGtal::Color values.

Template Parameters:
TImagethe Image type.
TFunctorthe type of functor used in the export.
See also:
testPNMRawWriter.cpp

Definition at line 72 of file PPMWriter.h.


Member Typedef Documentation

template<typename TImage , typename TFunctor >
typedef TFunctor DGtal::PPMWriter< TImage, TFunctor >::Functor

Definition at line 77 of file PPMWriter.h.

template<typename TImage , typename TFunctor >
typedef TImage DGtal::PPMWriter< TImage, TFunctor >::Image

Definition at line 75 of file PPMWriter.h.

template<typename TImage , typename TFunctor >
typedef TImage::Value DGtal::PPMWriter< TImage, TFunctor >::Value

Definition at line 76 of file PPMWriter.h.


Member Function Documentation

template<typename TImage , typename TFunctor >
DGtal::PPMWriter< TImage, TFunctor >::BOOST_CONCEPT_ASSERT ( (CUnaryFunctor< TFunctor, Value, DGtal::Color >)  )
template<typename TImage , typename TFunctor >
DGtal::PPMWriter< TImage, TFunctor >::BOOST_STATIC_ASSERT ( (TImage::Domain::dimension==2)||(TImage::Domain::dimension==3)  )
template<typename TImage , typename TFunctor >
bool DGtal::PPMWriter< I, C >::exportPPM ( const std::string &  filename,
const Image aImage,
const Functor aFunctor = Functor(),
bool  topbotomOrder = true 
)
static

Export an Image with PPM format.

Parameters:
filenamename of the output file
aImagethe image to export
aFunctorfunctor used to cast image values
saveASCIIused to save image with ASCII pixel value and with white space. (default= false since ASCII mode is not efficient).
Returns:
true if no errors occur.
Todo:
catch IOerror excpetion

Definition at line 45 of file PPMWriter.ih.

References DGtal::Color::blue(), DGtal::Color::green(), and DGtal::Color::red().

{
BOOST_STATIC_ASSERT(I::Domain::dimension == 2);
ofstream out;
typename I::Domain::Vector ext = aImage.extent();
typename I::Domain domain = aImage.domain();
typename I::Value val;
out.open(filename.c_str());
//PPM format
out << "P3"<<endl;
out << "#DGtal PNM Writer"<<endl<<endl;
out << ext[0]<<" "<< ext[1]<<endl;
out << "255" <<endl;
if(!topbotomOrder)
{
//We scan the domain instead of the image becaus we cannot
//trust the image container Iterator
for(typename I::Domain::ConstIterator it = domain.begin(), itend=domain.end();
it!=itend;
++it)
{
val = aImage( (*it) );
col = aFunctor( val );
out << (int)col.red()<<" "<<(int)col.green()<<" "<<(int)col.blue()<<" ";
}
}
else
{
typename I::Domain::Point ptUpper= domain.upperBound();
for(typename HyperRectDomain<typename I::Domain::Space>::ConstSubRange::ConstReverseIterator itY = domain.subRange(1, ptUpper).rbegin(),
itYend=domain.subRange(1, ptUpper).rend(); itY!=itYend; ++itY)
{
typename I::Domain::Point ptUpperY= *itY;
for(typename HyperRectDomain<typename I::Domain::Space>::ConstSubRange::ConstIterator it = domain.subRange(0, ptUpperY).begin(),
itend=domain.subRange(0, ptUpperY).end();
it!=itend;
++it)
{
val = aImage( (*it) );
col = aFunctor( val );
out << (int)col.red()<<" "<<(int)col.green()<<" "<<(int)col.blue()<<" ";
}
}
}
out.close();
return true;
}
template<typename TImage , typename TFunctor >
bool DGtal::PPMWriter< I, C >::exportPPM3D ( const std::string &  filename,
const Image aImage,
const Functor aFunctor = Functor() 
)
static

Export an Image with PPM3D format.

Parameters:
filenamename of the output file
aImagethe image to export
aFunctorfunctor used to cast image values
Returns:
true if no errors occur.
Todo:
catch IOerror excpetion

Definition at line 105 of file PPMWriter.ih.

References DGtal::Color::blue(), DGtal::Color::green(), and DGtal::Color::red().

{
BOOST_STATIC_ASSERT(I::Domain::dimension == 3);
ofstream out;
typename I::Domain::Vector ext = aImage.extent();
typename I::Domain domain(aImage.lowerBound(), aImage.upperBound());
typename I::Value val;
out.open(filename.c_str());
//PPM format
out << "P3-3D"<<endl;
out << "#DGtal PNM Writer"<<endl<<endl;
out << ext[0]<<" "<< ext[1]<<" "<< ext[2]<<endl;
out << "255" <<endl;
//We scan the domain instead of the image becaus we cannot
//trust the image container Iterator
for(typename I::Domain::ConstIterator it = domain.begin(), itend=domain.end();
it!=itend;
++it)
{
val = aImage( (*it) );
col = aFunctor( val );
out << (int)col.red()<<" "<<(int)col.green()<<" "<<(int)col.blue()<<" "; }
out.close();
return true;
}

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