ImageChannel.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31 #ifndef IMAGE_CHANNEL_H_
32 #define IMAGE_CHANNEL_H_ "ImageFrame 0.9, 2011.09.25 Markus.Peura@fmi.fi"
33 
34 #include <drain/TypeUtils.h>
35 #include <stddef.h> // size_t
36 
37 
38 #include <drain/CastableIterator.h>
39 
40 #include "drain/util/VariableMap.h"
41 #include "ImageFrame.h"
42 
43 
44 namespace drain
45 {
46 
48 namespace image
49 {
50 
51 
53 
60 class Channel : public ImageFrame {
61 
62 public:
63 
64  inline
65  Channel(){
66  };
67 
68  inline
69  Channel(const Channel & channel){
70  //conf.setConf() TOO GENERAL, discards scalingPtr
71  setStorageType(channel.getType());
72  conf.setScaling(channel.getScaling()); // NOTE: pointer-selected
73  conf.setGeometry(channel.getGeometry());
74  setCoordinatePolicy(channel.getCoordinatePolicy());
75  //conf.setConf(channel.getConf());
76 
77  // conf.setEncoding(channel.getEncoding());
78  };
79 
80  virtual inline
81  Channel & getChannel(size_t i){
82  if (i != 0)
83  throw std::runtime_error("Channel: getChannel(i) with i>0");
84  return *this;
85  };
86 
87 
88  virtual inline
89  const Channel & getChannel(size_t i) const {
90  if (i != 0)
91  throw std::runtime_error("Channel: getChannel(i) with i>0");
92  return *this;
93  }
94 
95  virtual inline
96  Channel & getAlphaChannel(size_t i=0){
97  throw std::runtime_error("Channel: getAlphaChannel() impossible");
98  return *this;
99  };
100 
101  virtual inline
102  const Channel & getAlphaChannel(size_t i=0) const {
103  throw std::runtime_error("Channel: getAlphaChannel() impossible");
104  return *this;
105  };
106 
107 
108 };
109 
111 
114 class ChannelView : public Channel {
115 
116 public:
117 
118  inline
119  ChannelView(){
120  };
121 
122  inline
123  ChannelView(const ChannelView & channel) : Channel(channel) {
124  //std::cerr << "ChannelView copy constr\n";
125  };
126 
127  inline
128  ChannelView(const ImageFrame & src, size_t channel = 0) {
129  setView(src, channel);
130  };
131 
132  inline
133  void setView(const ImageFrame & src, size_t channel){
134  ImageFrame::setView(src, channel, 1);
135  conf.channels.set(1,0);
136  }
137 
138  inline
139  void setView(const Channel & src){
140  ImageFrame::setView(src, 0, 1);
141  conf.channels.set(1,0);
142  }
143 
144 
145 
146 };
147 
148 
150 class MultiChannel : public ImageFrame {
151 
152 public:
153 
154  inline
155  MultiChannel(){};
156 
157  inline
158  MultiChannel(const MultiChannel & img){
159  this->conf.setScaling(img.getScaling());
160  };
161 
162 
163  Channel & getChannel(size_t i);
164 
165  const Channel & getChannel(size_t i) const;
166 
167  Channel & getAlphaChannel(size_t i=0);
168 
169  const Channel & getAlphaChannel(size_t i=0) const;
170 
171 
172  // hide?
173  inline
174  const std::vector<ChannelView> & getChannelVector() const {
176  return channelVector;
177  };
178 
179 protected:
180 
181  void updateChannelVector() const;
182 
183  mutable std::vector<ChannelView> channelVector;
184 
185 
186 };
187 
188 
189 
190 } // image::
191 } // drain::
192 
193 #endif /* IMAGE_FRAME_H_*/
194 
195 // Drain
virtual void setScaling(double scale, double offset)
Set linear scaling.
Definition: ValueScaling.h:136
View to a single channel.
Definition: ImageChannel.h:114
Image with static geometry.
Definition: ImageChannel.h:60
Image with static geometry.
Definition: ImageFrame.h:67
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 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 std::type_info & getType() const
Get the storage type.
Definition: ImageLike.h:100
const CoordinatePolicy & getCoordinatePolicy() const
Coord policy.
Definition: ImageLike.h:167
Multi-channel ImageFrame.
Definition: ImageChannel.h:150
void updateChannelVector() const
Updates channel vector. Copies scaling of the host image.
Definition: ImageChannel.cpp:94
Definition: DataSelector.cpp:1277