36 #ifndef VIGRA_IMPEXBASE_HXX 
   37 #define VIGRA_IMPEXBASE_HXX 
   41 #include "inspectimage.hxx" 
   42 #include "sized_int.hxx" 
   63         pixel_t_of_string(
const std::string& pixel_type)
 
   65             if (pixel_type == 
"BILEVEL")
 
   67                 return UNSIGNED_INT_8;
 
   69             else if (pixel_type == 
"UINT8")
 
   71                 return UNSIGNED_INT_8;
 
   73             else if (pixel_type == 
"UINT16")
 
   75                 return UNSIGNED_INT_16;
 
   77             else if (pixel_type == 
"UINT32")
 
   79                 return UNSIGNED_INT_32;
 
   81             else if (pixel_type == 
"INT16")
 
   85             else if (pixel_type == 
"INT32")
 
   89             else if (pixel_type == 
"FLOAT")
 
   93             else if (pixel_type == 
"DOUBLE")
 
   99                 vigra_fail(
"vigra_ext::detail::pixel_t_of_string: unknown pixel type");
 
  100                 return UNSIGNED_INT_8; 
 
  107             template <
typename T>
 
  108             T operator()(T x)
 const 
  115         typedef pair<double, double> range_t;
 
  118         class linear_transform
 
  121             linear_transform(
const range_t& 
source, 
const range_t& destination) :
 
  122                 scale_((destination.second - destination.first) / (source.second - source.first)),
 
  123                 offset_(destination.first / scale_ - source.first)
 
  126             template <
typename T>
 
  127             double operator()(T x)
 const 
  129                 return scale_ * (
static_cast<double>(x) + offset_);
 
  134             const double offset_;
 
  138         template <
class Iterator, 
class Accessor>
 
  139         inline static range_t
 
  140         find_value_range(Iterator upper_left, Iterator lower_right, Accessor accessor,
 
  143             typedef typename Accessor::value_type value_type;
 
  145             FindMinMax<value_type> extrema;
 
  147             inspectImage(upper_left, lower_right, accessor, extrema);
 
  149             return range_t(static_cast<double>(extrema.min), static_cast<double>(extrema.max));
 
  153         template <
class Iterator, 
class Accessor>
 
  154         inline static range_t
 
  155         find_value_range(Iterator upper_left, Iterator lower_right, Accessor accessor,
 
  158             typedef typename Accessor::ElementAccessor element_accessor;
 
  159             typedef typename element_accessor::value_type value_type;
 
  161             const int number_of_bands(static_cast<int>(accessor.size(upper_left)));
 
  162             FindMinMax<value_type> extrema;
 
  164             for (
int i = 0; i != number_of_bands; ++i)
 
  166                 element_accessor band(i, accessor);
 
  171             return range_t(static_cast<double>(extrema.min), static_cast<double>(extrema.max));
 
  175         template <
class SourceIterator, 
class SourceAccessor>
 
  176         inline static range_t
 
  177         find_source_value_range(
const ImageExportInfo& export_info,
 
  178                                 SourceIterator upper_left, SourceIterator lower_right, SourceAccessor accessor)
 
  180             if (export_info.getFromMin() < export_info.getFromMax())
 
  182                 return range_t(export_info.getFromMin(), export_info.getFromMax());
 
  186                 typedef typename SourceAccessor::value_type SourceValueType;
 
  187                 typedef typename NumericTraits<SourceValueType>::isScalar is_scalar;
 
  189                 const range_t range(find_value_range(upper_left, lower_right, accessor, is_scalar()));
 
  191                 if (range.first < range.second)
 
  193                     return range_t(range.first, range.second);
 
  197                     return range_t(range.first, range.first + 1.0);
 
  203         template <
typename T>
 
  204         inline static range_t
 
  205         find_destination_value_range(
const ImageExportInfo& export_info)
 
  207             if (export_info.getToMin() < export_info.getToMax())
 
  209                 return range_t(export_info.getToMin(), export_info.getToMax());
 
  213                 return range_t(static_cast<double>(NumericTraits<T>::min()),
 
  214                                static_cast<double>(NumericTraits<T>::max()));
 
  219         inline static range_t
 
  220         find_destination_value_range(
const ImageExportInfo& export_info, pixel_t pixel_type)
 
  224             case UNSIGNED_INT_8: 
return find_destination_value_range<UInt8>(export_info);
 
  225             case UNSIGNED_INT_16: 
return find_destination_value_range<UInt16>(export_info);
 
  226             case UNSIGNED_INT_32: 
return find_destination_value_range<UInt32>(export_info);
 
  227             case SIGNED_INT_16: 
return find_destination_value_range<Int16>(export_info);
 
  228             case SIGNED_INT_32: 
return find_destination_value_range<Int32>(export_info);
 
  229             case IEEE_FLOAT_32: 
return find_destination_value_range<float>(export_info);
 
  230             case IEEE_FLOAT_64: 
return find_destination_value_range<double>(export_info);
 
  232                 vigra_fail(
"vigra_ext::detail::find_destination_value_range: not reached");
 
  233                 return range_t(0.0, 0.0); 
 
  240 #endif // VIGRA_IMPEXBASE_HXX 
vigra::GridGraph< N, DirectedTag >::vertex_descriptor source(typename vigra::GridGraph< N, DirectedTag >::edge_descriptor const &e, vigra::GridGraph< N, DirectedTag > const &g)
Get a vertex descriptor for the start vertex of edge e in graph g (API: boost). 
Definition: multi_gridgraph.hxx:2943
void inspectImage(...)
Apply read-only functor to every pixel in the image.