ImageLike.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 IMAGELIKE_H_
32 #define IMAGELIKE_H_ "ImageLike 1.1, 2020/02 Markus.Peura@fmi.fi"
33 
34 /*
35 #include <stddef.h> // size_t
36 
37 ##include "../util/Caster.h"
38 #include "../util/ValueScaling.h"
39 
40 #include "Geometry.h"
41 #include "Coordinates.h"
42 */
43 #include "ImageConf.h"
44 
45 namespace drain
46 {
47 
49 namespace image
50 {
51 
52 
54 
58 // Consider: in future, may be merged to ImageConf ?
59 // Consider : ImageLike<CONF> : protected CONF {
60 
61 class ImageLike { // public ImageConf { // or rename ImageBase
62 
63 public:
64 
65  inline
66  ImageLike() {};
67 
68  inline
69  ImageLike(const ImageLike &image){
70  std::cerr << __FILE__ << __FUNCTION__ << " setConf/Geom has no effect\n";
71  conf.setConf(image.conf);
72  //conf.setEncoding(image.getEncoding());
73  //conf.setCoordinatePolicy(image.getCoordinatePolicy());
74  };
75 
76  /*
77  inline
78  ImageLike(const ImageConf &conf){
79  std::cerr << __FILE__ << __FUNCTION__ << " setConf has no effect\n";
80  //setConf(conf);
81  }
82  */
83 
84  virtual inline
85  ~ImageLike(){};
86 
87  /*
88  inline
89  const ImageConf & getConf() const {
90  return conf; // *this;
91  }
92 
93  virtual inline
94  const Encoding & getEncoding() const {
95  return conf; // *this;
96  }
97  */
99  inline
100  const std::type_info & getType() const {
101  return conf.caster.getType();
102  }
103 
104  inline
105  bool typeIsSet() const {
106  return conf.caster.typeIsSet();
107  };
108 
109 
110  virtual inline // CHECK if virtual needed
111  const Geometry & getGeometry() const {
112  return conf;
113  }
114 
115 
116  inline
117  size_t getWidth() const {
118  return conf.getWidth();
119  };
120 
121  inline
122  size_t getHeight() const {
123  return conf.getHeight();
124  };
125 
126  inline
127  size_t getArea() const {
128  return conf.getArea();
129  };
130 
131  inline
132  size_t getChannelCount() const {
133  return conf.getChannelCount(); // getGeometry unneeded?
134  };
135 
136 
137  inline
138  const size_t getImageChannelCount() const {
139  return conf.getImageChannelCount();
140  };
141 
142 
143  inline
144  const size_t getAlphaChannelCount() const {
145  return conf.getAlphaChannelCount();
146  };
147 
148 
149  inline
150  bool hasAlphaChannel() const {
151  return conf.hasAlphaChannel();
152  };
153 
154 
155  inline
156  size_t getVolume() const {
157  return conf.getVolume();
158  };
159 
160  inline
161  bool isEmpty() const {
162  return conf.isEmpty();
163  };
164 
166  inline
168  return conf.coordinatePolicy;
169  }
170 
172  inline
174  return conf.coordinatePolicy;
175  }
176 
177  // TODO: lower?
178  template <class T>
179  inline
180  void setCoordinatePolicy(const T & policy){
181  conf.coordinatePolicy.set(policy);
182  }
183 
184  // TODO: lower?
185  inline
186  void setCoordinatePolicy(EdgePolicy::index_t xUnderFlowPolicy, EdgePolicy::index_t yUnderFlowPolicy, EdgePolicy::index_t xOverFlowPolicy, EdgePolicy::index_t yOverFlowPolicy){
187  conf.coordinatePolicy.set(xUnderFlowPolicy, yUnderFlowPolicy, xOverFlowPolicy, yOverFlowPolicy);
188  }
189 
190  virtual inline
191  const drain::ValueScaling & getScaling() const {
192  return conf.getScaling();
193  }
194 
195 
196  // Notice: scaling is modifiable.
197  virtual inline
198  drain::ValueScaling & getScaling() {
199  return conf.getScaling();
200  }
201 
202  // Notice: scaling is modifiable.
203  virtual inline
204  void setScaling(const drain::ValueScaling & scaling){
205  conf.setScaling(scaling);
206  }
207 
208  // Notice: scaling is modifiable.
209  virtual inline
210  void setScaling(double scale, double offset){
211  conf.setScaling(scale, offset);
212  }
213 
214 
215 
216  template <class T>
217  inline
218  typename drain::typeLimiter<T>::value_t getLimiter() const {
219  return drain::Type::call<drain::typeLimiter<T> >(conf.caster.getType());
220  }
221 
222 
223 
224 
225 
226 protected:
227 
228  ImageConf conf;
229 
230 };
231 
232 
233 } // image::
234 } // drain::
235 
236 #endif /* IMAGELIKE_H_*/
const std::type_info & getType() const
Returns type_info of the current type.
Definition: Caster.h:144
Linear scaling and physical range for image intensities.
Definition: ValueScaling.h:64
virtual const ValueScaling & getScaling() const
Get linear scaling.
Definition: ValueScaling.h:147
virtual void setScaling(double scale, double offset)
Set linear scaling.
Definition: ValueScaling.h:136
Policies for coordinate underflows and overflows.
Definition: CoordinatePolicy.h:106
Caster caster
In base class(es), mainly for storing storage type. In derived classes, also for value conversions.
Definition: ImageConf.h:97
Definition: Geometry.h:145
size_t getChannelCount() const
Set...
Definition: Geometry.h:257
CoordinatePolicy coordinatePolicy
Rules to handle under- and overflows of horizontal and vertical coordinates.
Definition: ImageConf.h:383
A base class for images.
Definition: ImageLike.h:61
const std::type_info & getType() const
Get the storage type.
Definition: ImageLike.h:100
CoordinatePolicy & getCoordinatePolicy()
Coord policy.
Definition: ImageLike.h:173
const CoordinatePolicy & getCoordinatePolicy() const
Coord policy.
Definition: ImageLike.h:167
Class for ensuring that variable of type D remains within limits of type S.
Definition: TypeUtils.h:653
Definition: DataSelector.cpp:1277