32#define IMAGE_FRAME_H_ "ImageFrame 0.9, 2011.09.25 Markus.Peura@fmi.fi"
36#include "drain/TypeUtils.h"
37#include "drain/Sprinter.h"
38#include "drain/util/ValueScaling.h"
39#include "drain/util/VariableMap.h"
41#include "CoordinatePolicy.h"
156 return ( + j * conf.area.getWidth() + i);
164 size_t address(
size_t i,
size_t j,
size_t k)
const {
165 return ( + k*conf.area.getArea() + j*conf.area.getWidth() + i);
201 void put(
size_t i,
size_t j, T x){
216 void put(
size_t i,
size_t j,
size_t k, T x){
225 template <
class T,
class P>
239 conf.
caster.
put( & bufferPtr[
address(i,j) * conf.byteSize], getScaling().inv(x));
262 T
get(
size_t i,
size_t j)
const {
274 T
get(
size_t i,
size_t j,
size_t k)
const {
285 return getScaling().
fwd(conf.
caster.
get<
double>( & bufferPtr[
address(i,j) * conf.byteSize ] ));
292 template <
class T,
class P>
295 return conf.
caster.
get<T>( & bufferPtr[
address(p.x,p.y) * conf.byteSize ] );
299 template <
class T,
class P>
301 void putPixel(
const Point2D<P> &p,
const std::vector<T> & pixel)
const {
302 for (
typename std::vector<T>::size_type i = 0; i < pixel.size(); ++i) {
308 template <
class T,
class P>
310 void getPixel(
const Point2D<P> &p, std::vector<T> & pixel)
const {
311 for (
typename std::vector<T>::size_type i = 0; i < pixel.size(); ++i) {
312 pixel[i] = conf.
caster.
get<T>( & bufferPtr[
address(p.x,p.y,i)*conf.byteSize]);
328 for (
iterator it = segmentBegin; it != segmentEnd; ++it)
370 return *propertiesPtr;
382 void setName(
const std::string & s){ name = s; };
385 const std::string & getName()
const {
return name; };
388 void toStream(std::ostream &ostr = std::cout)
const;
391 Channel & getChannel(
size_t i) = 0;
394 const Channel & getChannel(
size_t i)
const = 0;
397 Channel & getAlphaChannel(
size_t i=0) = 0;
400 const Channel & getAlphaChannel(
size_t i=0)
const = 0;
420 Logger(getImgLog(), __FILE__, __FUNCTION__).
error(
"tried to change type [", conf.
getType(),
"] to [", t,
"]");
423 else if (conf.getGeometry() != geometry){
424 Logger(getImgLog(), __FILE__, __FUNCTION__).
error(
"tried to change geometry ", conf.getGeometry(),
" to ", geometry);
438 void initialize(
const std::type_info &t,
size_t width,
size_t height,
size_t imageChannels=1,
size_t alphaChannels=0){
452 unsigned char * bufferPtr;
454 iterator segmentBegin;
470 throw std::runtime_error(
"ImageFrame infinite loop: -> unsetType() ?");
478 void setView(
const ImageFrame & src,
size_t channelStart,
size_t channelCount,
bool catenate=
false);
483 return (bufferPtr != &buffer[0]);
504 T * retrieve(
size_t a){
505 return (T*) & buffer[ a*conf.byteSize ];
511 const T * retrieve(
size_t a)
const {
512 return (
const T*) & buffer[ a*conf.byteSize ];
531 std::vector<unsigned char> buffer;
542std::ostream & operator<<(std::ostream &ostr,
const ImageFrame & src){
552std::ostream & drain::Sprinter::toStream<drain::image::ImageFrame>(std::ostream & ostr,
const drain::image::ImageFrame & src,
const SprinterLayout & layout);
Definition CastableIterator.h:57
T get(const void *p) const
Default implementation throws an error. See specialized implementation below.
Definition Caster.h:194
void put(void *p, const T &x) const
Default conversion (for unconventional types). Uses std::stringstream for conversion.
Definition Caster.h:157
A map of FlexVariable:s.
Definition VariableMap.h:138
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & error(const TT &... args)
Echoes.
Definition Log.h:416
double fwd(double x) const
Forward scaling: given encoded value x, returns corresponding value (possibly physically meaningful).
Definition ValueScaling.h:295
const std::type_info & getType() const
Linear scaling.
Definition ImageConf.h:110
Caster caster
In base class(es), mainly for storing storage type. In derived classes, also for value conversions.
Definition ImageConf.h:97
void setPhysicalRange(const Range< double > &range, bool rescale=false)
Sets channel specific scaling instead of shared (image-level) scaling.
Definition ImageConf.h:229
Definition Geometry.h:145
Struct for image (excluding data)
Definition ImageConf.h:333
Image with static geometry.
Definition ImageFrame.h:64
const iterator & begin()
Returns iterator pointing to the first image element.
Definition ImageFrame.h:116
T get(size_t i, size_t j) const
Gets the intensity at location i,j .
Definition ImageFrame.h:262
const iterator & end()
Returns the iterator pointing to the element after the last element of the image buffer.
Definition ImageFrame.h:122
size_t address(size_t i, size_t j, size_t k) const
Computes the index location from image coordinates. Does not involve bit resolution.
Definition ImageFrame.h:164
void toStream(std::ostream &ostr=std::cout) const
Prints images geometry, buffer size and type information.
Definition ImageFrame.cpp:256
const const_iterator & end() const
Returns the iterator pointing to the element after the last element of the image buffer.
Definition ImageFrame.h:135
T get(const Point2D< P > &p) const
Gets the intensity at location p=(i,j) .
Definition ImageFrame.h:294
void adjustBuffer()
Resize data buffer to match the geometry.
Definition ImageFrame.cpp:99
void put(size_t i, size_t j, T x)
Sets the intensity at location i,j to x. See address().
Definition ImageFrame.h:201
T get(size_t i, size_t j, size_t k) const
Gets the intensity at location i,j,k .
Definition ImageFrame.h:274
virtual void initialize(const std::type_info &t, size_t width, size_t height, size_t imageChannels=1, size_t alphaChannels=0)
Sets the type and allocates a data buffer.
Definition ImageFrame.h:438
void setStorageType(const std::type_info &type)
Sets the storage type of the image - typically unsigned char, unsigned int or float....
Definition ImageFrame.cpp:62
void put(size_t i, size_t j, size_t k, T x)
Sets the intensity at location i,j,k to x.
Definition ImageFrame.h:216
void * getBuffer()
Returns the pointer to the start of the image array.
Definition ImageFrame.h:176
virtual bool suggestType(const std::type_info &t)
Definition ImageFrame.cpp:73
const void * getBuffer() const
Returns the pointer to the start of the image array.
Definition ImageFrame.h:170
bool hasSameSegment(const ImageFrame &image) const
Return true, if both frames have same type and are using the same data segment.
Definition ImageFrame.h:358
void copyData(const ImageFrame &src)
Copies data. Does not change encoding, geometry, or coordinate policy.
Definition ImageFrame.cpp:236
void put(size_t i, T x)
Sets the intensity in location i to x. See \address.
Definition ImageFrame.h:189
void put(const Point2D< P > &p, T x)
Gets the intensity at location p=(i,j) .
Definition ImageFrame.h:227
void setView(const ImageFrame &src, size_t channelStart, size_t channelCount, bool catenate=false)
Sets the image to view the data and scaling of another image.
Definition ImageFrame.cpp:142
size_t address(size_t i, size_t j) const
Computes the index location from image coordinates. Does not involve bit resolution.
Definition ImageFrame.h:155
size_t address(size_t i) const
Computes the index location from image coordinates. Does not involve bit resolution.
Definition ImageFrame.h:145
bool isView() const
Returns true, if the image "points to" another image. For example, channels are views.
Definition ImageFrame.h:482
FlexVariableMap properties
Container for user-defined KEY=VALUE metadata.
Definition ImageFrame.h:366
void setPhysicalRange(double min, double max, bool rescale=false)
Sets the supported range for physical values and optionally adjusts the scaling for maximal resolutio...
Definition ImageFrame.h:109
void clear()
Sets the intensities to zero. Does not change image geometry. See resetGeometry().
Definition ImageFrame.h:320
const const_iterator & begin() const
Returns iterator pointing to the first image element.
Definition ImageFrame.h:129
double getScaled(size_t i, size_t j) const
Get intensity in original physical scale.
Definition ImageFrame.h:284
T get(size_t i) const
Gets the intensity at location i. See address().
Definition ImageFrame.h:251
bool hasOverlap(const ImageFrame &image) const
Checks if images have a common memory segment.
Definition ImageFrame.h:338
void putScaled(size_t i, size_t j, double x)
Put intensity using original physical value.
Definition ImageFrame.h:238
virtual bool requireGeometry(const Geometry &geometry)
Definition ImageFrame.cpp:87
void setPhysicalRange(const Range< double > &range, bool rescale=false)
Sets the supported range for physical values and optionally adjusts the scaling for maximal resolutio...
Definition ImageFrame.h:103
void fill(T x)
Sets the intensities to given value. Does not change image geometry.
Definition ImageFrame.h:327
virtual void updateChannelVector() const
Updates channel vector. Copies scaling of the host image.
Definition ImageFrame.h:497
virtual void initialize(const std::type_info &t, const Geometry &geometry)
Sets the type and allocates a data buffer.
Definition ImageFrame.h:417
A base class for images.
Definition ImageLike.h:61
Definition DataSelector.cpp:1277
DRAIN_TYPENAME(void)
Add a specialization for each type of those you want to support.