Xmipp  v3.23.11-Nereus
xmipp_image_over.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Alberto Pascual Montano (pascual@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * Part of this module has been developed by Lorenzo Zampighi and Nelson Tang
8  * Dept. Physiology of the David Geffen School of Medicine
9  * Univ. of California, Los Angeles.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24  * 02111-1307 USA
25  *
26  * All comments concerning this program package may be sent to the
27  * e-mail address 'xmipp@cnb.csic.es'
28  ***************************************************************************/
29 
30 #ifndef CORE_IMAGEOVER_H
31 #define CORE_IMAGEOVER_H
32 
33 #include <core/xmipp_image.h>
109 class ImageOver : public Image<double>
110 {
111 public:
112  int uistep, vistep, wistep; // number of samples per
113  // one sample on normal image (50)
114  // in u,v,w directions
115 
116  int overumax, overvmax, overwmax; // table borders in normal units (-2,2)
117  int overumin, overvmin, overwmin; // table borders in normal units (-2,2)
118  // They should be an integer number
119 
120 public:
133  void init(int _umin, int _umax, int _uistep,
134  int _vmin, int _vmax, int _vistep,
135  int _wmin=0, int _wmax=0, int _wistep=1);
136 
142  void init(MultidimArray<double> &im, int _uistep=1, int _vistep=0, int _wistep=0);
143 
148  void window(int _v0, int _u0, int _vF, int _uF);
149 
159  void clear();
160 
175  void over2img(double v, double u, int& iv, int& iu) const
176  {
177  if (v < overvmin || v > overvmax)
178  REPORT_ERROR(ERR_VALUE_INCORRECT, "ImgeOver::over2img: v out of range");
179 
180  if (u < overumin || u > overumax)
181  REPORT_ERROR(ERR_VALUE_INCORRECT, "ImgeOver::over2img: u out of range");
182 
183  iu = (int) ROUND((((u) - overumin) * uistep));
184  iv = (int) ROUND((((v) - overvmin) * vistep));
185  }
186 
196 #define OVER2IMG(IO, v, u, iv, iu) \
197  iu = (int) round((((u)-(IO).overumin) * (IO).uistep)); \
198  iv = (int) round((((v)-(IO).overvmin) * (IO).vistep));
199 
200 #define OVER2IMG_Z(IO, w, iw) \
201  iw = (int) round((((w)-(IO).overwmin) * (IO).wistep));
202 
215  void img2over(size_t iv, size_t iu, double & v, double & u) const
216  {
217  if (iu < 0 || iu > XSIZE(data))
218  REPORT_ERROR(ERR_VALUE_INCORRECT, "ImageOver::img2over: iu out of range");
219  if (iv < 0 || iv > YSIZE(data))
220  REPORT_ERROR(ERR_VALUE_INCORRECT, "ImageOver::img2over: iv out of range");
221  u = (double)(overumin) + iu / (double)(uistep);
222  v = (double)(overvmin) + iv / (double)(vistep);
223  }
224 
234 #define IMG2OVER(IO, iv, iu, v, u) \
235  u = (double) (IO).overumin + (iu) / (double) ((IO).uistep); \
236  v = (double) (IO).overvmin + (iv) / (double) ((IO).vistep);
237 
249  double operator ()(double v, double u) const
250  {
251  if (v < overvmin || v > overvmax)
252  REPORT_ERROR(ERR_VALUE_INCORRECT, "ImgeOver::over2img: v out of range");
253  if (u < overumin || u > overumax)
254  REPORT_ERROR(ERR_VALUE_INCORRECT, "ImgeOver::over2img: u out of range");
255  int iu, iv;
256  OVER2IMG(*this, v, u, iv, iu);
257  return A2D_ELEM(data, iv, iu);
258  }
259 
270  double & operator ()(double v, double u)
271  {
272  int iu, iv;
273  OVER2IMG(*this, v, u, iv, iu);
274  return A2D_ELEM(data, iv, iu);
275  }
276 
286 #define OVERPIXEL(IO, y, x) IMGPIXEL((IO), \
287  (int) ROUND(((u) * (IO).uistep)), \
288  (int) ROUND(((v) * (IO).vistep)))
289 
290  // The following two functions have been redefined (they should be
291  // inherited from Image) because the compiler doesn't admit this
292  // inheritance and the redefinition of the fractional index pixel
293  // access.
294 
305  {
306  return data;
307  }
308 
310  {
311  return data;
312  }
313 
322  int umax() const
323  {
324  return overumax;
325  }
326 
335  int vmax() const
336  {
337  return overvmax;
338  }
339 
348  int wmax() const
349  {
350  return overwmax;
351  }
352 
361  int umin() const
362  {
363  return overumin;
364  }
365 
374  int vmin() const
375  {
376  return overvmin;
377  }
378 
387  int Ustep() const
388  {
389  return uistep;
390  }
391 
400  int Vstep() const
401  {
402  return vistep;
403  }
404 
413  int Wstep() const
414  {
415  return wistep;
416  }
417 
428  void downsample(Image< double >* I) const;
429 };
430 #endif
#define YSIZE(v)
#define A2D_ELEM(v, i, j)
int Wstep() const
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
MultidimArray< double > & operator()()
int umax() const
void over2img(double v, double u, int &iv, int &iu) const
int Vstep() const
int Ustep() const
MultidimArray< double > data
Definition: xmipp_image.h:55
int vmax() const
int vmin() const
#define XSIZE(v)
#define ROUND(x)
Definition: xmipp_macros.h:210
const MultidimArray< double > & operator()() const
int umin() const
#define OVER2IMG(IO, v, u, iv, iu)
void img2over(size_t iv, size_t iu, double &v, double &u) const
doublereal * u
void downsample(Image< double > *I) const
Incorrect value received.
Definition: xmipp_error.h:195
void window(int _v0, int _u0, int _vF, int _uF)
int wmax() const