ImageT.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 IMAGETEMPLATE_H_
32 #define IMAGETEMPLATE_H_ "Image 1.3, 2010.05.05 Markus.Peura@fmi.fi"
33 
34 
35 // TODO: rename to WritableImage ?
36 
37 #include <drain/Log.h>
38 #include <stdlib.h> // for exit(-1) TODO: obsolete, use std::exceptions.
39 #include <stdexcept>
40 #include <vector>
41 #include <ostream>
42 
43 #include "Image.h"
44 #include "Intensity.h"
45 #include "../util/Point.h"
46 
47 namespace drain
48 {
49 
51 //static size_t Debug;
52 
54 namespace image
55 {
56 
57 
59 
65 template <class T=unsigned char>
66 class ImageT : public ModifiableImage
67 {
68 public:
69 
70  typedef T data_t;
71 
72 
73  ImageT(){
74  initialize(typeid(T), 0, 0, 0, 0);
75  //setStorageType(typeid(T));
76  }
77 
78  ImageT(size_t width, size_t height, size_t channelCount=1, size_t alphaChannelCount=0){
79  initialize(typeid(T), width,height,channelCount,alphaChannelCount);
80  }
81 
82  // Creates a new image having the geometry of \code image.
83  ImageT(const ImageT<T> &image){
84  initialize(typeid(T), image.getWidth(),image.getHeight(),image.getImageChannelCount(),image.getAlphaChannelCount());
85  setCoordinatePolicy(image.getCoordinatePolicy());
86  }
87 
88  inline
89  virtual ~ImageT(){};
90 
91  inline
92  const T & at(size_t i) const {
93  return *retrieve<const T>(address(i));
94  //return *(const T *)&buffer[ address(i)*encoding.byteSize ];
95  }
96 
97  inline
98  T & at(size_t i) {
99  return *retrieve<T>(address(i));
100  //return *(T *) retrieve(i);
101  //return *(T *)&buffer[ address(i)*encoding.byteSize ];
102  }
103 
104  inline
105  const T & at(size_t i, size_t j) const {
106  return *(const T *) retrieve<T>(address(i,j));
107  //return *(const T *)&buffer[ address(i)*encoding.byteSize ];
108  };
109 
110  inline
111  T & at(size_t i, size_t j){
112  return *(T *) retrieve<T>(address(i,j));
113  //return *(T *) retrieve<T>(i,j);
114  // return *(T *) & buffer[ address(i,j) * conf.byteSize ];
115  };
116 
117 
118 
119 };
120 
121 
122 
123 
124 
125 
126 
127 }
128 
129 }
130 
131 #endif
132 
133 // Drain
size_t address(size_t i) const
Computes the index location from image coordinates. Does not involve bit resolution.
Definition: ImageFrame.h:148
const CoordinatePolicy & getCoordinatePolicy() const
Coord policy.
Definition: ImageLike.h:167
A template class for images with static storage type.
Definition: ImageT.h:67
Image with modifiable geometry.
Definition: Image.h:63
virtual void initialize(const std::type_info &t, const Geometry &g)
Sets the type and allocates a data buffer.
Definition: Image.h:147
Definition: DataSelector.cpp:1277