37 #ifndef AIMS_UTILITY_CONVERTER_VOLUME_H 
   38 #define AIMS_UTILITY_CONVERTER_VOLUME_H 
   47   template<
typename _Tp>
 
   54   template<
typename _Tp>
 
   65   template <
typename INP,
typename OUTP>
 
   74   template<
typename INP, 
typename OUTP>
 
   91   template <
typename INP>
 
   95     RawConverter( 
bool shallowcopy = 
false ) : _shallowcopy( shallowcopy ) {}
 
  103   template <
typename INP>
 
  105     : 
public Converter<carto::VolumeRef<INP>, carto::VolumeRef<INP> >
 
  116   template <
class INP,
class OUTP>
 
  132   template<
typename INP>
 
  134     : 
public RawConverter<carto::VolumeRef<INP>, carto::VolumeRef<INP> >
 
  146   template<
typename INP>
 
  148     : 
public Rescaler<carto::VolumeRef<INP>, carto::VolumeRef<INP> >
 
  158   template<
typename INP>
 
  161                              std::numeric_limits<INP>::is_specialized
 
  162   && std::numeric_limits<INP>::is_bounded >
 
  167           std::numeric_limits<INP>::is_specialized
 
  168           && std::numeric_limits<INP>::is_bounded >( shallowcopy ) {}
 
  171           std::numeric_limits<INP>::is_specialized
 
  172           && std::numeric_limits<INP>::is_bounded >( info, shallowcopy ) {}
 
  178   template <
class INP,
class OUTP>
 
  188   template <
class INP> 
inline 
  198   template <
typename INP, 
typename OUTP>
 
  205     std::vector<int> isz = in.
getSize();
 
  206     std::vector<int> osz = out.
getSize();
 
  209     int i, n = isz.size(), m = osz.size();
 
  210     for( i=0; i<std::min(n, m); ++i )
 
  211       if( isz[i] < osz[i] && !erased )
 
  213         out.
fill( OUTP( 0 ) );
 
  216       else if( isz[i] > osz[i] )
 
  217         throw std::runtime_error(
 
  218           "Converter output volume should be as large as input" );
 
  223           out.
fill( OUTP( 0 ) );
 
  228         throw std::runtime_error(
 
  229           "Converter output volume should be as large as input" );
 
  240     for( ; !it.
ended(); ++it, ++oit )
 
  255   template<
typename INP, 
typename OUTP>
 
  262   template<
typename INP, 
typename OUTP>
 
  271   template<
typename INP, 
typename OUTP>
 
  285     if( std::isnan( info.
vmin ) )
 
  293     if( std::isnan( info.
vmax ) )
 
  301     std::vector<int> isz = in.
getSize();
 
  302     std::vector<int> osz = out.
getSize();
 
  305     int i, n = isz.size(), m = osz.size();
 
  306     for( i=0; i<std::min(n, m); ++i )
 
  307       if( isz[i] < osz[i] && !erased )
 
  309         out.
fill( OUTP( 0 ) );
 
  312       else if( isz[i] > osz[i] )
 
  313         throw std::runtime_error(
 
  314           "Converter output volume should be as large as input" );
 
  319           out.
fill( OUTP( 0 ) );
 
  324         throw std::runtime_error(
 
  325           "Converter output volume should be as large as input" );
 
  336     for( ; !it.
ended(); ++it, ++oit )
 
  354   template<
class INP> 
inline 
  362       if( this->_shallowcopy )
 
  369         out->copyUuid( *in );
 
  377       std::vector<int> isz = in.
getSize();
 
  378       std::vector<int> osz = out.
getSize();
 
  381       int i, n = isz.size(), m = osz.size();
 
  382       for( i=0; i<std::min(n, m); ++i )
 
  383         if( isz[i] < osz[i] && !erased )
 
  385           out.
fill( INP( 0 ) );
 
  388         else if( isz[i] > osz[i] )
 
  389           throw std::runtime_error(
 
  390             "Converter output volume should be as large as input" );
 
  395             out.
fill( INP( 0 ) );
 
  400           throw std::runtime_error(
 
  401             "Converter output volume should be as large as input" );
 
  410       for( ; !it.
ended(); ++it, ++oit )
 
  429         sc( this->_info, 
true );
 
  430       sc.convert( in, out );
 
  448   template <
typename T, 
int D>
 
  461   template <
typename T, 
int D>
 
  467   template <
typename T, 
int D>
 
  474   template <
typename T, 
int D>
 
  486     std::vector<int> isz = in.getSize();
 
  487     std::vector<int> osz = out.
getSize();
 
  490     int i, n = isz.size(), m = osz.size();
 
  491     for( i=0; i<std::min(n, m); ++i )
 
  492       if( isz[i] < osz[i] && !erased )
 
  497       else if( isz[i] > osz[i] )
 
  498         throw std::runtime_error(
 
  499           "Converter output volume should be as large as input" );
 
  509         throw std::runtime_error(
 
  510           "Converter output volume should be as large as input" );
 
  513       it( &in.at( 0 ), in.getSize(), in.getStrides() );
 
  517     if( std::isnan( info.
vmin ) )
 
  522         for( ; !it.
ended(); ++it )
 
  527               for( 
int c = 0; c < D; ++c )
 
  528               if( (
double) (*p)[c] < info.
vmin )
 
  529                 info.
vmin = (double) (*p)[c];
 
  535     if( std::isnan( info.
vmax ) )
 
  545               for( 
int c = 0; c < D; ++c )
 
  546               if( (
double) (*p)[c] > info.
vmin )
 
  547                 info.
vmax = (double) (*p)[c];
 
  565         for( 
int c=0; c < D && c<3; ++c )
 
  578   template <
typename T, 
int D>
 
  591   template <
typename T, 
int D>
 
  597   template <
typename T, 
int D>
 
  604   template <
typename T, 
int D>
 
  609     if( out.getSizeX() == 0 )
 
  614     out.copyHeaderFrom( in.
header() );
 
  616     std::vector<int> isz = in.
getSize();
 
  617     std::vector<int> osz = out.getSize();
 
  620     int i, n = isz.size(), m = osz.size();
 
  621     for( i=0; i<std::min(n, m); ++i )
 
  622       if( isz[i] < osz[i] && !erased )
 
  627       else if( isz[i] > osz[i] )
 
  628         throw std::runtime_error(
 
  629           "Converter output volume should be as large as input" );
 
  639         throw std::runtime_error(
 
  640           "Converter output volume should be as large as input" );
 
  647     if( std::isnan( info.
vmin ) )
 
  652         for( ; !it.
ended(); ++it )
 
  657               for( 
int c = 0; c < 3; ++c )
 
  658               if( (
double) (*p)[c] < info.
vmin )
 
  659                 info.
vmin = (double) (*p)[c];
 
  665     if( std::isnan( info.
vmax ) )
 
  675               for( 
int c = 0; c < 3; ++c )
 
  676               if( (
double) (*p)[c] > info.
vmin )
 
  677                 info.
vmax = (double) (*p)[c];
 
  695         for( 
int c=0; c < D && c<3; ++c )
 
  700     out.header().getProperty( 
"scale_factor", scf );
 
  702     out.header().setProperty( 
"scale_factor", scf );
 
  703     out.header().setProperty( 
"data_type",
 
  705     if( out.header().hasProperty( 
"disk_data_type" ) )
 
  706       out.header().removeProperty( 
"disk_data_type" );
 
static OUTP * alloc(const INP &in)
ConverterSwitch(const RescalerInfo &, bool shallowcopy=false)
ConverterSwitch(bool shallowcopy=false)
ConverterSwitch(bool=false)
ConverterSwitch(const RescalerInfo &info, bool)
virtual void convert(const INP &in, OUTP &out) const
OUTP getScaledValue(INP value) const
const std::vector< int > & position() const
void setProperty(const std::string &, const T &)
virtual bool removeProperty(const std::string &key)
virtual bool hasProperty(const std::string &) const
bool getProperty(const std::string &, T &) const
RawConverter(bool shallowcopy=false)
void convert(const INP &in, OUTP &out) const
void convert(const INP &in, OUTP &out) const
ShallowConverter(bool rescale=false)
ShallowConverter(bool rescale, const RescalerInfo &info)
SmartConverter(bool shallowcopy=false)
SmartConverter(const RescalerInfo &info, bool shallowcopy=false)
std::vector< int > getBorders() const
void setVoxelSize(float vx, float vy=1., float vz=1., float vt=1.)
std::vector< float > getVoxelSize() const
VolumeRef< T > deepcopy() const
virtual void copyHeaderFrom(const PropertySet &other)
std::vector< int > getSize() const
const T & at(long x, long y=0, long z=0, long t=0) const
const PropertySet & header() const
void fill(const T &value)
std::vector< size_t > getStrides() const
const AllocatorContext & allocatorContext() const
void inc_line_ptr(const T *&p) const
void inc_line_ptr(T *&p) const