31 #ifndef IMAGE_FRAME_H_
32 #define IMAGE_FRAME_H_ "ImageFrame 0.9, 2011.09.25 Markus.Peura@fmi.fi"
37 #include <drain/TypeUtils.h>
38 #include <drain/Sprinter.h>
40 #include <drain/image/CoordinatePolicy.h>
42 #include "drain/util/ValueScaling.h"
43 #include "drain/util/VariableMap.h"
46 #include "ImageLike.h"
159 return ( + j * conf.area.getWidth() + i);
167 size_t address(
size_t i,
size_t j,
size_t k)
const {
168 return ( + k*conf.area.getArea() + j*conf.area.getWidth() + i);
204 void put(
size_t i,
size_t j, T x){
219 void put(
size_t i,
size_t j,
size_t k, T x){
228 template <
class T,
class P>
242 conf.
caster.
put( & bufferPtr[
address(i,j) * conf.byteSize], getScaling().inv(x));
265 T
get(
size_t i,
size_t j)
const {
277 T
get(
size_t i,
size_t j,
size_t k)
const {
288 return getScaling().
fwd(conf.
caster.
get<
double>( & bufferPtr[
address(i,j) * conf.byteSize ] ));
295 template <
class T,
class P>
298 return conf.
caster.
get<T>( & bufferPtr[
address(p.x,p.y) * conf.byteSize ] );
302 template <
class T,
class P>
304 void putPixel(
const Point2D<P> &p,
const std::vector<T> & pixel)
const {
305 for (
typename std::vector<T>::size_type i = 0; i < pixel.size(); ++i) {
311 template <
class T,
class P>
313 void getPixel(
const Point2D<P> &p, std::vector<T> & pixel)
const {
314 for (
typename std::vector<T>::size_type i = 0; i < pixel.size(); ++i) {
315 pixel[i] = conf.
caster.
get<T>( & bufferPtr[
address(p.x,p.y,i)*conf.byteSize]);
331 for (
iterator it = segmentBegin; it != segmentEnd; ++it)
373 return *propertiesPtr;
385 void setName(
const std::string & s){ name = s; };
388 const std::string & getName()
const {
return name; };
391 void toStream(std::ostream &ostr = std::cout)
const;
394 Channel & getChannel(
size_t i) = 0;
397 const Channel & getChannel(
size_t i)
const = 0;
400 Channel & getAlphaChannel(
size_t i=0) = 0;
403 const Channel & getAlphaChannel(
size_t i=0)
const = 0;
416 if ((conf.
getType() == t) && (conf.getGeometry() == geometry))
419 throw std::runtime_error(std::string(
"ImageFrame::")+__FUNCTION__+
": tried to change ImageFrame geometry");
426 void initialize(
const std::type_info &t,
size_t width,
size_t height,
size_t imageChannels=1,
size_t alphaChannels=0){
440 unsigned char * bufferPtr;
442 iterator segmentBegin;
458 throw std::runtime_error(
"ImageFrame infinite loop: -> unsetType() ?");
466 void setView(
const ImageFrame & src,
size_t channelStart,
size_t channelCount,
bool catenate=
false);
471 return (bufferPtr != &buffer[0]);
492 T * retrieve(
size_t a){
493 return (T*) & buffer[ a*conf.byteSize ];
499 const T * retrieve(
size_t a)
const {
500 return (
const T*) & buffer[ a*conf.byteSize ];
519 std::vector<unsigned char> buffer;
530 std::ostream & operator<<(std::ostream &ostr,
const ImageFrame & src){
540 std::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
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:67
const void * getBuffer() const
Returns the pointer to the start of the image array.
Definition: ImageFrame.h:173
T get(size_t i, size_t j) const
Gets the intensity at location i,j .
Definition: ImageFrame.h:265
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:167
void toStream(std::ostream &ostr=std::cout) const
Prints images geometry, buffer size and type information.
Definition: ImageFrame.cpp:229
void * getBuffer()
Returns the pointer to the start of the image array.
Definition: ImageFrame.h:179
const iterator & begin()
Returns iterator pointing to the first image element.
Definition: ImageFrame.h:119
T get(const Point2D< P > &p) const
Gets the intensity at location p=(i,j) .
Definition: ImageFrame.h:297
void adjustBuffer()
Resize data buffer to match the geometry.
Definition: ImageFrame.cpp:72
void put(size_t i, size_t j, T x)
Sets the intensity at location i,j to x. See address().
Definition: ImageFrame.h:204
T get(size_t i, size_t j, size_t k) const
Gets the intensity at location i,j,k .
Definition: ImageFrame.h:277
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:426
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:219
bool hasSameSegment(const ImageFrame &image) const
Return true, if both frames have same type and are using the same data segment.
Definition: ImageFrame.h:361
void copyData(const ImageFrame &src)
Copies data. Does not change encoding, geometry, or coordinate policy.
Definition: ImageFrame.cpp:209
void put(size_t i, T x)
Sets the intensity in location i to x. See \address.
Definition: ImageFrame.h:192
void put(const Point2D< P > &p, T x)
Gets the intensity at location p=(i,j) .
Definition: ImageFrame.h:230
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:115
const iterator & end()
Returns the iterator pointing to the element after the last element of the image buffer.
Definition: ImageFrame.h:125
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:158
size_t address(size_t i) const
Computes the index location from image coordinates. Does not involve bit resolution.
Definition: ImageFrame.h:148
bool isView() const
Returns true, if the image "points to" another image. For example, channels are views.
Definition: ImageFrame.h:470
FlexVariableMap properties
Container for user-defined KEY=VALUE metadata.
Definition: ImageFrame.h:369
const const_iterator & begin() const
Returns iterator pointing to the first image element.
Definition: ImageFrame.h:132
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:112
void clear()
Sets the intensities to zero. Does not change image geometry. See resetGeometry().
Definition: ImageFrame.h:323
double getScaled(size_t i, size_t j) const
Get intensity in original physical scale.
Definition: ImageFrame.h:287
const const_iterator & end() const
Returns the iterator pointing to the element after the last element of the image buffer.
Definition: ImageFrame.h:138
T get(size_t i) const
Gets the intensity at location i. See address().
Definition: ImageFrame.h:254
bool hasOverlap(const ImageFrame &image) const
Checks if images have a common memory segment.
Definition: ImageFrame.h:341
void putScaled(size_t i, size_t j, double x)
Put intensity using original physical value.
Definition: ImageFrame.h:241
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:106
void fill(T x)
Sets the intensities to given value. Does not change image geometry.
Definition: ImageFrame.h:330
virtual void updateChannelVector() const
Updates channel vector. Copies scaling of the host image.
Definition: ImageFrame.h:485
virtual void initialize(const std::type_info &t, const Geometry &geometry)
Returns numeric channel index from "r", "g", "b", or "a" or a non-negative number in string format.
Definition: ImageFrame.h:415
A base class for images.
Definition: ImageLike.h:61
Definition: DataSelector.cpp:1277