32#ifndef DRAIN_IMAGE_TRAY
33#define DRAIN_IMAGE_TRAY
51class Tray :
public std::map<size_t, T &> {
56 typedef std::map<size_t, image_t &> map_t;
80 const image_t &
get(
size_t i = 0)
const {
81 typename map_t::const_iterator it = this->find(i);
82 if (it == this->end()){
83 throw std::runtime_error(
"Tray::get(i): find failed");
90 image_t &
get(
size_t i = 0){
91 typename map_t::iterator it = this->find(i);
92 if (it == this->end()){
93 throw std::runtime_error(
"Tray::get(i): find failed");
102 void set(image_t & img,
size_t i=0){
103 this->insert(
typename map_t::value_type(i, img));
109 this->insert(
typename map_t::value_type(this->size(), img));
127 for (
typename std::vector<T2>::iterator it = v.begin(); it != v.end(); ++it) {
137 geometry.channels.set(this->size());
148 if (g != it->second.getGeometry())
170 typename map_t::iterator it=this->begin();
171 typename std::vector<T2>::const_iterator vit = v.begin();
172 while (it!=this->end()){
173 it->second.put(p, *vit);
184 typename std::vector<T2>::iterator vit = v.begin();
185 typename map_t::const_iterator it=this->begin();
186 while (it!=this->end()){
187 *vit = it->second.template get<T2>(p);
217 bool hasOverlap(
const Tray<T2> & tray)
const {
218 for (
typename map_t::const_iterator it=this->begin(); it!=this->end(); ++it){
220 if (it->second.hasOverlap(it2->second)){
230 void toOStr(std::ostream & ostr)
const {
231 for (
typename map_t::const_iterator it=this->begin(); it!=this->end(); ++it){
232 ostr << it->first <<
':' << it->second <<
'\n';
236 void createVector(std::vector<Image> & v)
const {
237 for (
typename map_t::const_iterator it=this->begin(); it!=this->end(); ++it){
239 v.insert(v.end(), Image(it->second.getType()));
245 mutable Geometry geometry;
253std::ostream & operator<<(std::ostream &ostr,
const Tray<T> & tray){
254 ostr <<
"Tray " << tray.getGeometry() <<
":\n";
271 typedef typename Tray<T>::image_t image_t;
272 typedef typename Tray<T>::map_t map_t;
316 this->geometry.channels.set(this->size(), this->alpha.size());
317 return this->geometry;
321 bool hasAlpha()
const {
322 return !alpha.empty();
329 typename map_t::const_iterator it = alpha.find(i);
330 if (it == alpha.end()){
331 throw std::runtime_error(
"ChannelTray::getAlpha(i): find failed");
339 this->alpha.Tray<T>::clear();
360 this->alpha.Tray<T>::copy(t.alpha);
367 alpha.Tray<T>::copy(t.alpha);
374 this->alpha.insert(
typename map_t::value_type(i, img));
380 typename map_t::iterator it = alpha.find(i);
381 if (it == alpha.end()){
382 throw std::runtime_error(
"ChannelTray::getAlpha(i): find failed");
403 takeAlphaChannels(alpha, img);
410 takeAlphaChannels(alpha, img);
422 void setChannels(
const T2 & img,
const T2 & alphaImg){
450 void toOStr(std::ostream & ostr = std::cout)
const {
453 if (this->hasAlpha()){
454 ostr <<
"alphas: " << std::endl;
455 alpha.Tray<T>::toOStr(ostr);
469 for (
size_t i = 0; i < img.getImageChannelCount(); ++i) {
476 void takeAlphaChannels(
Tray<T> & tray, T2 & img){
478 for (
size_t i = 0; i < img.getAlphaChannelCount(); ++i) {
491 for (
size_t i = 0; i < img.getImageChannelCount(); ++i) {
498 void takeAlphaChannels(
Tray<const T> & tray,
const T2 & img){
500 for (
size_t i = 0; i < img.getAlphaChannelCount(); ++i) {
511std::ostream & operator<<(std::ostream &ostr,
const ImageTray<T> & tray){
512 ostr <<
"ChannelTray " << tray.getGeometry() <<
":\n";
544 * \param image - image object to be referenced
545 * Notice: if image contains alpha channels, they will \e not be separated.
547 Clip(image_t & image){
553 \param image - image object, the image channels of which will referenced.
554 \param alpha - image object, the image channels of which will referenced as alpha channels.
555 Notice: if first argument contains alpha channels, they will \e not be separated.
557 TODO: consider if empty alpha?
559 Clip(image_t & image, image_t & alpha){
568 const Geometry & getGeometry() const {
569 geometry.setGeometry(this->get().getGeometry());
570 geometry.setChannelCount(this->size(), this->alpha.size());
573 // TODO consider setGeometry
579 void appendAlpha(image_t & image){
580 alpha.insert(typename map_t::value_type(alpha.size(), image));
585 bool hasAlpha() const {
586 return !alpha.empty();
591 // TODO: if no explicit alpha, return images alpha?
594 const image_t & getAlpha(size_t i = 0) const {
595 typename map_t::const_iterator it = alpha.find(i);
596 if (it == alpha.end()){
597 std::runtime_error("ImageTray::getAlpha(i): find failed");
605 image_t & getAlpha(size_t i = 0){
606 typename map_t::iterator it = alpha.find(i);
607 if (it == alpha.end()){
608 std::runtime_error("ImageTray::getAlpha(i): find failed");
615 void toOStr(std::ostream & ostr) const {
616 Tray<T>::toOStr(ostr);
618 for (typename Tray<T>::map_t::const_iterator it=alpha.begin(); it!=alpha.end(); ++it){
619 ostr << '\t' << it->first << ':' << it->second << '\n';
627 void setAlpha(size_t i, image_t & image){
628 alpha.insert(typename map_t::value_type(i, image));
634 void append(image_t & image){
635 throw std::runtime_error("Clip::append defunct");
636 //this->insert(typename map_t::value_type(this->size(), image));
639 mutable Geometry geometry;
Definition Geometry.h:143
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:266
void setAlphaChannels(const T2 &img)
Splits.
Definition ImageTray.h:443
void setChannels(T2 &img)
Splits.
Definition ImageTray.h:401
const Geometry & getGeometry() const
Appends the whole single image.
Definition ImageTray.h:314
void setAlphaChannels(T2 &img)
Splits.
Definition ImageTray.h:433
void setAlpha(image_t &img, size_t i=0)
Replace image in position i.
Definition ImageTray.h:373
static void takeImageChannels(Tray< T > &tray, T2 &img)
Splits.
Definition ImageTray.h:467
image_t & getAlpha(size_t i=0)
Returns the i'th alpha image.
Definition ImageTray.h:379
void copy(const Tray< T2 > &t)
Add image sequence.
Definition ImageTray.h:345
const image_t & getAlpha(size_t i=0) const
Returns the i'th alpha image.
Definition ImageTray.h:328
void copy(Tray< T2 > &t)
Add image sequence.
Definition ImageTray.h:352
void appendAlpha(image_t &img)
Add image to the end of the container.
Definition ImageTray.h:390
static void takeImageChannels(Tray< const T > &tray, const T2 &img)
Splits.
Definition ImageTray.h:489
Set of images, usable for general calls of type traverseFrame(src, dst) .
Definition ImageTray.h:51
virtual void appendImage(image_t &img)
Add image to the end.
Definition ImageTray.h:108
void putPixel(const Point2D< int > &p, const std::vector< T2 > &v)
Put intensity vector.
Definition ImageTray.h:169
image_t & get(size_t i=0)
Returns the i'th image.
Definition ImageTray.h:90
virtual const Geometry & getGeometry() const
Returns the geometry of the first frame.
Definition ImageTray.h:134
virtual bool checkGeometry(const Geometry &g) const
Returns true, if all the frames have the same width and height.
Definition ImageTray.h:143
void copy(const Tray< T2 > &t)
Add image sequence. Replaces old values.
Definition ImageTray.h:115
const image_t & get(size_t i=0) const
Returns the i'th image.
Definition ImageTray.h:80
void copyVector(std::vector< T2 > &v)
Add image sequence.
Definition ImageTray.h:125
void set(image_t &img, size_t i=0)
Replace image in position i.
Definition ImageTray.h:102
void getPixel(const Point2D< int > &p, std::vector< T2 > &v) const
Get intensity vector.
Definition ImageTray.h:183
bool checkGeometry() const
Returns true, if all the frames have the same width and height.
Definition ImageTray.h:155
Definition DataSelector.cpp:1277