Xmipp  v3.23.11-Nereus
multidim_array_base.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: David Strelak (davidstrelak@gmail.com)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #include "multidim_array_base.h"
27 #include "xmipp_error.h"
28 #include "xmipp_macros.h"
29 #include "matrix1d.h"
30 
32 {
33  ndim = Ndim;
35 }
36 
43 {
44  zdim = Zdim;
47 }
48 
55 {
56  ydim = Ydim;
57  yxdim=(size_t)ydim*xdim;
60 }
61 
68 {
69  xdim = Xdim;
70  yxdim=(size_t)ydim*xdim;
73 }
74 
78 void MultidimArrayBase::setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)
79 {
80  if (((size_t)Xdim)*Ydim*Zdim*Ndim < 1)
81  REPORT_ERROR(ERR_MULTIDIM_SIZE, "Dimensions' size cannot be zero nor negative.");
82  ndim=Ndim;
83  zdim=Zdim;
84  ydim=Ydim;
85  xdim=Xdim;
86  yxdim=ydim*xdim;
89 }
90 
95 {
96  if (newDim.ndim*newDim.zdim*newDim.ydim*newDim.xdim < 1)
97  REPORT_ERROR(ERR_MULTIDIM_SIZE, "Dimensions' size cannot be zero nor negative.");
98  ndim = newDim.ndim;
99  zdim = newDim.zdim;
100  ydim = newDim.ydim;
101  xdim = newDim.xdim;
102 
103  newDim.yxdim = yxdim = ydim*xdim;
104  newDim.zyxdim = zyxdim = zdim*yxdim;
105  newDim.nzyxdim = nzyxdim = ndim*zyxdim;
106 }
107 
114 void MultidimArrayBase::getDimensions(size_t& Xdim, size_t& Ydim, size_t& Zdim, size_t &Ndim) const
115 {
116  Xdim = xdim;
117  Ydim = ydim;
118  Zdim = zdim;
119  Ndim = ndim;
120 }
121 
123 {
124  adim.xdim = xdim;
125  adim.ydim = ydim;
126  adim.zdim = zdim;
127  adim.ndim = ndim;
128  adim.yxdim = yxdim;
129  adim.zyxdim = zyxdim;
130  adim.nzyxdim = nzyxdim;
131 }
132 
134 {
135  ArrayDim adim;
136  adim.xdim = xdim;
137  adim.ydim = ydim;
138  adim.zdim = zdim;
139  adim.ndim = ndim;
140  adim.yxdim = yxdim;
141  adim.zyxdim = zyxdim;
142  adim.nzyxdim = nzyxdim;
143 
144  return adim;
145 }
146 
155 void MultidimArrayBase::getDimensions(int* size) const
156 {
157  size[0] = xdim;
158  size[1] = ydim;
159  size[2] = zdim;
160  size[3] = ndim;
161 }
162 
170 {
171  return nzyxdim;
172 }
173 
177 void MultidimArrayBase::resize(ArrayDim &adim, bool copy)
178 {
179  setDimensions(adim);
180  resize(adim.ndim, adim.zdim, adim.ydim, adim.xdim, copy);
181 }
182 
187 {
188  ndim=m.ndim;
189  zdim=m.zdim;
190  ydim=m.ydim;
191  xdim=m.xdim;
192  yxdim=m.yxdim;
193  zyxdim=m.zyxdim;
194  nzyxdim=m.nzyxdim;
195  zinit=m.zinit;
196  yinit=m.yinit;
197  xinit=m.xinit;
198 }
199 
201 {
205 }
206 
208 {
209  zinit = yinit = xinit = 0;
210 }
211 
213 {
217 }
218 
220 {
223 }
224 
231 {
232 
233  if (v.size() < 2)
234  REPORT_ERROR(ERR_MATRIX_SIZE, "isCorner: index vector has got not enough components");
235 
236  else if (ZSIZE(*this)==1)
237  return ((XX(v) == STARTINGX(*this) && YY(v) == STARTINGY(*this)) ||
238  (XX(v) == STARTINGX(*this) && YY(v) == FINISHINGY(*this)) ||
239  (XX(v) == FINISHINGX(*this) && YY(v) == STARTINGY(*this)) ||
240  (XX(v) == FINISHINGX(*this) && YY(v) == FINISHINGY(*this)));
241  else if (ZSIZE(*this)>1)
242  return ((XX(v) == STARTINGX(*this) && YY(v) == STARTINGY(*this) && ZZ(v) == STARTINGZ(*this)) ||
243  (XX(v) == STARTINGX(*this) && YY(v) == FINISHINGY(*this) && ZZ(v) == STARTINGZ(*this)) ||
244  (XX(v) == FINISHINGX(*this) && YY(v) == STARTINGY(*this) && ZZ(v) == STARTINGZ(*this)) ||
245  (XX(v) == FINISHINGX(*this) && YY(v) == FINISHINGY(*this) && ZZ(v) == STARTINGZ(*this)) ||
246  (XX(v) == STARTINGX(*this) && YY(v) == STARTINGY(*this) && ZZ(v) == FINISHINGZ(*this)) ||
247  (XX(v) == STARTINGX(*this) && YY(v) == FINISHINGY(*this) && ZZ(v) == FINISHINGZ(*this)) ||
248  (XX(v) == FINISHINGX(*this) && YY(v) == STARTINGY(*this) && ZZ(v) == FINISHINGZ(*this)) ||
249  (XX(v) == FINISHINGX(*this) && YY(v) == FINISHINGY(*this) && ZZ(v) == FINISHINGZ(*this)));
250  else
251  REPORT_ERROR(ERR_MATRIX_SIZE, formatString("isCorner: index vector has too many components. dimV= %lu matrix dim = %i", v.size(), XSIZE(*this)));
252 }
253 
260 {
261  if (r.size() < 1)
262  {
263  REPORT_ERROR(ERR_MATRIX_SIZE, "Outside: index vector has not got enough components");
264  }
265  else if (r.size()==1)
266  {
267  return (XX(r) < STARTINGX(*this) || XX(r) > FINISHINGX(*this));
268  }
269  else if (r.size()==2)
270  {
271  return (XX(r) < STARTINGX(*this) || XX(r) > FINISHINGX(*this) ||
272  YY(r) < STARTINGY(*this) || YY(r) > FINISHINGY(*this));
273  }
274  else if (r.size()==3)
275  {
276  return (XX(r) < STARTINGX(*this) || XX(r) > FINISHINGX(*this) ||
277  YY(r) < STARTINGY(*this) || YY(r) > FINISHINGY(*this) ||
278  ZZ(r) < STARTINGZ(*this) || ZZ(r) > FINISHINGZ(*this));
279  }
280  else
281  REPORT_ERROR(ERR_MATRIX_SIZE,"Outside: index vector has too many components");
282 }
283 
284 void MultidimArrayBase::printShape(std::ostream& out) const
285 {
286  if (NSIZE(*this) > 1)
287  out << " Number of images = "<<NSIZE(*this);
288 
289  if (ZSIZE(*this)>1)
290  out<< " Size(Z,Y,X): " << ZSIZE(*this) << "x" << YSIZE(*this) << "x" << XSIZE(*this)
291  << " k=[" << STARTINGZ(*this) << ".." << FINISHINGZ(*this) << "]"
292  << " i=[" << STARTINGY(*this) << ".." << FINISHINGY(*this) << "]"
293  << " j=[" << STARTINGX(*this) << ".." << FINISHINGX(*this) << "]";
294  else if (YSIZE(*this)>1)
295  out<< " Size(Y,X): " << YSIZE(*this) << "x" << XSIZE(*this)
296  << " i=[" << STARTINGY(*this) << ".." << FINISHINGY(*this) << "]"
297  << " j=[" << STARTINGX(*this) << ".." << FINISHINGX(*this) << "]";
298  else if (XSIZE(*this)>1)
299  out<< " Size(X): " << XSIZE(*this)
300  << " j=[" << STARTINGX(*this) << ".." << FINISHINGX(*this) << "]";
301  else
302  out << " Empty MultidimArray!";
303  out<<"\n";
304 }
void moveOriginTo(int k, int i, int j)
#define NSIZE(v)
#define YSIZE(v)
size_t xdim
#define FINISHINGX(v)
void printShape(std::ostream &out=std::cout) const
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
size_t size() const
Definition: matrix1d.h:508
Problem with matrix size.
Definition: xmipp_error.h:152
ArrayDim getDimensions() const
bool isCorner(const Matrix1D< double > &v) const
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
#define FINISHINGZ(v)
#define STARTINGX(v)
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
#define STARTINGY(v)
#define XX(v)
Definition: matrix1d.h:85
size_t nzyxdim
size_t zdim
size_t zyxdim
size_t yxdim
#define XSIZE(v)
#define ZSIZE(v)
void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)
#define j
virtual void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)=0
#define YY(v)
Definition: matrix1d.h:93
int m
void copyShape(const MultidimArrayBase &m)
size_t ndim
#define FINISHINGY(v)
bool outside(int k, int i, int j) const
#define FIRST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:439
String formatString(const char *format,...)
size_t ydim
#define STARTINGZ(v)
#define ZZ(v)
Definition: matrix1d.h:101