Xmipp  v3.23.11-Nereus
vectorial.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar S. Sorzano (coss@cnb.csic.es)
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 #ifndef VECTORIAL_H
27 #define VECTORIAL_H
28 
29 #include <core/multidim_array.h>
30 
33 
34 
36 
41 #define FOR_ALL_ELEMENTS_IN_VECTORIAL_MATRIX3D(v) \
42  FOR_ALL_ELEMENTS_IN_ARRAY3D((v).__X)
43 
48 #define FOR_ALL_ELEMENTS_IN_MULTIDIM_VECTORIAL_MATRIX3D(v) \
49  FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY((v).__X)
50 
51 
66 {
67  // The 3 components
71 
72 public:
74 
75 
78  void resize(int Zdim, int Ydim, int Xdim)
79  {
80  __X.resize(Zdim, Ydim, Xdim);
81  __Y.resize(Zdim, Ydim, Xdim);
82  __Z.resize(Zdim, Ydim, Xdim);
83  }
84 
88  {
89  __X.resize(V);
90  __Y.resize(V);
91  __Z.resize(V);
92  }
93 
96  void clear()
97  {
98  __X.clear();
99  __Y.clear();
100  __Z.clear();
101  }
102 
105  void printShape() const
106  {
107  __X.printShape();
108  }
109 
112  void initZeros()
113  {
114  __X.initZeros();
115  __Y.initZeros();
116  __Z.initZeros();
117  }
118 
122  {
123  __X.setXmippOrigin();
124  __Y.setXmippOrigin();
125  __Z.setXmippOrigin();
126  }
128 
130 
131 
134  void vector_at(int k, int i, int j, Matrix1D< double >& result) const
135  {
136  if (VEC_XSIZE(result)!=3)
137  result.resize(3);
138  XX(result) = __X(k, i, j);
139  YY(result) = __Y(k, i, j);
140  ZZ(result) = __Z(k, i, j);
141  }
142 
147  const MultidimArray< double >& X() const
148  {
149  return __X;
150  }
151 
155  {
156  return __X;
157  }
158 
161  const MultidimArray< double >& Y() const
162  {
163  return __Y;
164  }
165 
169  {
170  return __Y;
171  }
172 
175  const MultidimArray< double >& Z() const
176  {
177  return __Z;
178  }
179 
183  {
184  return __Z;
185  }
186 
189  double X(int k, int i, int j) const
190  {
191  return A3D_ELEM(__X, k, i, j);
192  }
193 
196  double& X(int k, int i, int j)
197  {
198  return A3D_ELEM(__X, k, i, j);
199  }
200 
203  double Y(int k, int i, int j) const
204  {
205  return A3D_ELEM(__Y, k, i, j);
206  }
207 
210  double& Y(int k, int i, int j)
211  {
212  return A3D_ELEM(__Y, k, i, j);
213  }
214 
217  double Z(int k, int i, int j) const
218  {
219  return A3D_ELEM(__Z, k, i, j);
220  }
221 
224  double& Z(int k, int i, int j)
225  {
226  return A3D_ELEM(__Z, k, i, j);
227  }
229 
231 
232 
236  {
238  {
239  double mod = sqrt(
243  DIRECT_MULTIDIM_ELEM(__X,n) /= mod;
244  DIRECT_MULTIDIM_ELEM(__Y,n) /= mod;
245  DIRECT_MULTIDIM_ELEM(__Z,n) /= mod;
246  }
247  }
248 
253  void module(MultidimArray< double >& result) const
254  {
255  result.resize(__X);
256 
258  DIRECT_MULTIDIM_ELEM(result, n) = sqrt(
262  }
263 
269  void write(const FileName& fn) const
270  {
271  Image<double> V;
272 
273  V() = __X;
274  V.write(fn.insertBeforeExtension("_X"));
275  V() = __Y;
276  V.write(fn.insertBeforeExtension("_Y"));
277  V() = __Z;
278  V.write(fn.insertBeforeExtension("_Z"));
279  }
281 
283 
284 
285 #define OPERATION(func, arg1, arg2, result, op) \
286  func((arg1).__X, (arg2).__X, (result).__X, op); \
287  func((arg1).__Y, (arg2).__Y, (result).__Y, op); \
288  func((arg1).__Z, (arg2).__Z, (result).__Z, op);
289 
293  {
295  OPERATION(arrayByArray, *this, op1, temp, '+');
296  return temp;
297  }
298 
302  {
304  OPERATION(arrayByArray, *this, op1, temp, '-');
305  return temp;
306  }
307 
311  {
313  OPERATION(arrayByArray, *this, op1, temp, '*');
314  return temp;
315  }
316 
320  {
322  OPERATION(arrayByArray, *this, op1, temp, '/');
323  return temp;
324  }
325 
329  {
331  OPERATION(arrayByArray, *this, op1, temp, '^');
332  return temp;
333  }
334 
338  {
339  OPERATION(arrayByArray, *this, op1, *this, '+');
340  }
341 
345  {
346  OPERATION(arrayByArray, *this, op1, *this, '-');
347  }
348 
352  {
353  OPERATION(arrayByArray, *this, op1, *this, '*');
354  }
355 
359  {
360  OPERATION(arrayByArray, *this, op1, *this, '/');
361  }
362 
366  {
367  OPERATION(arrayByArray, *this, op1, *this, '^');
368  }
369 
370 #define OPERATION2(func, arg1, arg2, result, op) \
371  func((arg1).__X, (arg2), (result).__X, op); \
372  func((arg1).__Y, (arg2), (result).__Y, op); \
373  func((arg1).__Z, (arg2), (result).__Z, op);
374 
378  {
380  OPERATION2(arrayByScalar, *this, op1, temp, '+');
381  return temp;
382  }
383 
387  {
389  OPERATION2(arrayByScalar, *this, op1, temp, '-');
390  return temp;
391  }
392 
396  {
398  OPERATION2(arrayByScalar, *this, op1, temp, '*');
399  return temp;
400  }
401 
405  {
407  OPERATION2(arrayByScalar, *this, op1, temp, '/');
408  return temp;
409  }
410 
414  {
416  OPERATION2(arrayByScalar, *this, op1, temp, '^');
417  return temp;
418  }
419 
422  void operator+=(const double& op1)
423  {
424  OPERATION2(arrayByScalar, *this, op1, *this, '+');
425  }
426 
429  void operator-=(const double& op1)
430  {
431  OPERATION2(arrayByScalar, *this, op1, *this, '-');
432  }
433 
436  void operator*=(const double& op1)
437  {
438  OPERATION2(arrayByScalar, *this, op1, *this, '*');
439  }
440 
443  void operator/=(const double& op1)
444  {
445  OPERATION2(arrayByScalar, *this, op1, *this, '/');
446  }
447 
450  void operator^=(const double& op1)
451  {
452  OPERATION2(arrayByScalar, *this, op1, *this, '^');
453  }
454 };
456 #endif
double & Y(int k, int i, int j)
Definition: vectorial.h:210
#define OPERATION(func, arg1, arg2, result, op)
Definition: vectorial.h:285
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
Vectorial_MultidimArray operator/(const Vectorial_MultidimArray &op1) const
Definition: vectorial.h:319
void printShape(std::ostream &out=std::cout) const
void printShape() const
Definition: vectorial.h:105
void operator+=(const double &op1)
Definition: vectorial.h:422
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
void operator/=(const double &op1)
Definition: vectorial.h:443
void sqrt(Image< double > &op)
Vectorial_MultidimArray operator*(double op1) const
Definition: vectorial.h:395
FileName insertBeforeExtension(const String &str) const
const MultidimArray< double > & X() const
Definition: vectorial.h:147
void operator*=(const Vectorial_MultidimArray &op1)
Definition: vectorial.h:351
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
void operator-=(const Vectorial_MultidimArray &op1)
Definition: vectorial.h:344
const MultidimArray< double > & Y() const
Definition: vectorial.h:161
Vectorial_MultidimArray operator*(const Vectorial_MultidimArray &op1) const
Definition: vectorial.h:310
void operator/=(const Vectorial_MultidimArray &op1)
Definition: vectorial.h:358
#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
Vectorial_MultidimArray operator^(const Vectorial_MultidimArray &op1) const
Definition: vectorial.h:328
const MultidimArray< double > & Z() const
Definition: vectorial.h:175
#define A3D_ELEM(V, k, i, j)
void module(MultidimArray< double > &result) const
Definition: vectorial.h:253
double Y(int k, int i, int j) const
Definition: vectorial.h:203
MultidimArray< double > & Z()
Definition: vectorial.h:182
void vector_at(int k, int i, int j, Matrix1D< double > &result) const
Definition: vectorial.h:134
#define XX(v)
Definition: matrix1d.h:85
void operator^=(const Vectorial_MultidimArray &op1)
Definition: vectorial.h:365
Vectorial_MultidimArray operator+(const Vectorial_MultidimArray &op1) const
Definition: vectorial.h:292
Vectorial_MultidimArray operator^(double op1) const
Definition: vectorial.h:413
void resize(size_t Xdim, bool copy=true)
Definition: matrix1d.h:410
void resize(int Zdim, int Ydim, int Xdim)
Definition: vectorial.h:78
#define OPERATION2(func, arg1, arg2, result, op)
Definition: vectorial.h:370
#define DIRECT_MULTIDIM_ELEM(v, n)
void operator+=(const Vectorial_MultidimArray &op1)
Definition: vectorial.h:337
Vectorial_MultidimArray operator-(double op1) const
Definition: vectorial.h:386
void mod(const MultidimArray< T > &x, MultidimArray< T > &m, double y)
void resize(const MultidimArray< double > &V)
Definition: vectorial.h:87
#define j
#define YY(v)
Definition: matrix1d.h:93
Vectorial_MultidimArray operator+(double op1) const
Definition: vectorial.h:377
double X(int k, int i, int j) const
Definition: vectorial.h:189
double & X(int k, int i, int j)
Definition: vectorial.h:196
Vectorial_MultidimArray operator-(const Vectorial_MultidimArray &op1) const
Definition: vectorial.h:301
Vectorial_MultidimArray operator/(double op1) const
Definition: vectorial.h:404
#define FOR_ALL_ELEMENTS_IN_MULTIDIM_VECTORIAL_MATRIX3D(v)
Definition: vectorial.h:48
MultidimArray< double > & Y()
Definition: vectorial.h:168
void write(const FileName &fn) const
Definition: vectorial.h:269
void operator^=(const double &op1)
Definition: vectorial.h:450
void initZeros(const MultidimArray< T1 > &op)
void operator-=(const double &op1)
Definition: vectorial.h:429
void operator*=(const double &op1)
Definition: vectorial.h:436
double Z(int k, int i, int j) const
Definition: vectorial.h:217
int * n
#define ZZ(v)
Definition: matrix1d.h:101
double & Z(int k, int i, int j)
Definition: vectorial.h:224
MultidimArray< double > & X()
Definition: vectorial.h:154