42 int actual_start_line;
45 int actual_start_pixel;
48 int extern_start_line;
49 int extern_start_pixel;
59 virtual type operator() (
int x,
int y);
61 virtual type operator[] (
int k);
62 virtual const type operator[] (
int k)
const;
67 void set_actual_lines (
int act_start_line,
int act_nr_lines);
69 void set_actual_pixels (
int act_start_pixel,
int act_nr_pixels);
71 void set_extern_start_line (
int start_line);
73 void set_extern_start_pixel (
int start_pixel);
75 int get_nr_lines () {
return nr_lines;}
76 int get_nr_pixels () {
return nr_pixels;}
77 int get_actual_start_line () {
return actual_start_line;}
78 int get_actual_nr_lines () {
return actual_nr_lines;}
79 int get_actual_start_pixel () {
return actual_start_pixel;}
80 int get_actual_nr_pixels () {
return actual_nr_pixels;}
81 int get_extern_start_line () {
return extern_start_line;}
82 int get_extern_start_pixel () {
return extern_start_pixel;}
84 type *get_data_ptr () {
return data;}
85 type **get_data_lines_ptr () {
return data_lines;}
89 void dump (
char *filename);
90 void dumpall(
char *filename);
91 void write (
char *filename,
int append=0);
100 if(y<0 || y>=nr_lines)
101 cerr <<
"DataPatch::operator()(int x,int y), Invalid par y: " << y << endl;
102 if(x<0 || x>=nr_pixels)
103 cerr <<
"DataPatch::operator()(int x,int y), Invalid par x: " << x << endl;
104 return data_lines[y][x];
109 if(k < 0 || k >=nr_lines*nr_pixels)
110 cerr <<
"DataPatch::operator[](int k), Invalid par k: " << k << endl;
116 if(k < 0 || k >=nr_lines*nr_pixels)
117 cerr <<
"DataPatch::operator[](int k), Invalid par k: " << k << endl;
143 template <
class type>
150 actual_start_line = 0;
151 actual_nr_lines = nr_lines;
153 actual_start_pixel = 0;
154 actual_nr_pixels = nr_pixels;
156 extern_start_line = 0;
157 extern_start_pixel = 0;
163 cerr <<
"DataPatch:invalid nr_lines: " << nr_lines << endl;
165 cerr <<
"DataPatch:invalid nr_pixels: " << nr_lines << endl;
167 data =
new type[nr_lines*nr_pixels];
168 data_lines =
new type *[nr_lines];
171 cerr <<
"DataPatch: unable to allocate memory: " <<
sizeof(type)*nr_lines*nr_pixels << endl;
173 if (data_lines == NULL)
174 cerr <<
"DataPatch: unable to allocate memory: " <<
sizeof(type)*nr_lines << endl;
176 for(
int ii = 0; ii < nr_lines; ii++)
177 data_lines[ii] = data+ii*nr_pixels;
182 template <
class type>
186 if(data != NULL)
delete [] data;
187 if(data_lines != NULL)
delete [] data_lines;
192 template <
class type>
inline
195 if (act_start_line < 0)
196 cerr <<
"DataPatch:invalid actual_start_line: " << act_start_line << endl;
197 if (act_nr_lines <= 0)
198 cerr <<
"DataPatch:invalid actual_nr_lines: " << act_nr_lines << endl;
199 if (act_start_line + act_nr_lines > nr_lines)
200 cerr <<
"DataPatch:invalid actual_lines: " << act_start_line+act_nr_lines << endl;
201 actual_start_line = act_start_line;
202 actual_nr_lines = act_nr_lines;
207 template <
class type>
inline
210 if (act_start_pixel < 0)
211 cerr <<
"DataPatch:invalid actual_start_pixel: " << act_start_pixel << endl;
212 if (act_nr_pixels <= 0)
213 cerr <<
"DataPatch:invalid actual_nr_pixels: " << act_nr_pixels << endl;
214 if (act_start_pixel + act_nr_pixels > nr_pixels)
215 cerr <<
"DataPatch:invalid actual_pixels: " << act_start_pixel+act_nr_pixels << endl;
216 actual_start_pixel = act_start_pixel;
217 actual_nr_pixels = act_nr_pixels;
222 template <
class type>
inline
226 cerr <<
"DataPatch:invalid extern_start_line: " << start_line << endl;
227 extern_start_line = start_line;
232 template <
class type>
inline
236 cerr <<
"DataPatch:invalid extern_start_pixel: "<< start_pixel << endl;
237 extern_start_pixel = start_pixel;
259 if (!(fp = fopen(filename,
"w"))) {
260 cerr <<
"DataPatch::dump: error on opening: " << filename << endl;
265 for (
int line = actual_start_line; line < actual_nr_lines; line++) {
266 for (
int pixel = actual_start_pixel; pixel < actual_nr_pixels; pixel++)
267 if (fwrite ((
void*)&data_lines [line][pixel],
sizeof(type), 1, fp) != 1) {
268 cerr <<
"DataPatch::dump: error on writing: " << filename << endl;
272 cerr <<
"DataPatch::dump: number of pixels: " << actual_nr_pixels << endl;
280 if (!(fp = fopen(filename,
"a"))) {
281 cerr <<
"DataPatch::write: error on opening: " << filename << endl;
285 if (!(fp = fopen(filename,
"w"))) {
286 cerr <<
"DataPatch::write: error on opening: " << filename << endl;
292 for (
int line = actual_start_line; line < actual_nr_lines; line++) {
293 for (
int pixel = actual_start_pixel; pixel < actual_nr_pixels; pixel++)
294 if (fwrite ((
void*)&data_lines [line][pixel],
sizeof(type), 1, fp) != 1) {
295 cerr <<
"DataPatch::write: error on writing: " << filename << endl;
308 if (!(fp = fopen(filename,
"w"))) {
309 cerr <<
"DataPatch::dump: error on opening: " << filename << endl;
314 for (
int line = 0; line < nr_lines; line++) {
315 for (
int pixel = 0; pixel < nr_pixels; pixel++)
316 if (fwrite ((
void*)&data_lines [line][pixel],
sizeof(type), 1, fp) != 1) {
317 cerr <<
"DataPatch::dump: error on writing: " << filename << endl;
321 cerr <<
"DataPatch::dumpall: number of pixels: " << nr_pixels << endl;
331 for (
int line = actual_start_line; line < actual_start_line + actual_nr_lines; line++) {
332 for (
int pixel = actual_start_pixel; pixel < actual_start_pixel+actual_nr_pixels; pixel++) {
333 sum += data_lines [line][pixel];
337 if (cnt != 0) sum /= cnt;
Definition: DataPatch.h:28