Xmipp  v3.23.11-Nereus
Public Attributes | List of all members

#include <common_lines.h>

Inheritance diagram for MultidimArray< T >:
Inheritance graph
[legend]
Collaboration diagram for MultidimArray< T >:
Collaboration graph
[legend]

Public Member Functions

Constructors
 MultidimArray ()
 
 MultidimArray (size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, T *data)
 
 MultidimArray (size_t Ndim, int Zdim, int Ydim, int Xdim)
 
 MultidimArray (int Zdim, int Ydim, int Xdim)
 
 MultidimArray (int Ydim, int Xdim)
 
 MultidimArray (int Xdim)
 
 MultidimArray (const MultidimArray< T > &V)
 
 MultidimArray (MultidimArray< T > &&V) noexcept
 
 MultidimArray (const Matrix1D< T > &V)
 
 MultidimArray (const std::vector< T > &vector)
 
virtual ~MultidimArray ()
 
void clear ()
 
Core memory operations
void coreInit () noexcept
 
void swap (MultidimArray< T > &other) noexcept
 
void coreAllocate (size_t _ndim, int _zdim, int _ydim, int _xdim)
 
void coreAllocate ()
 
void coreAllocateReuse ()
 
FILE * mmapFile (T *&_data, size_t nzyxDim) const
 
void coreDeallocate () noexcept
 
void alias (const MultidimArray< T > &m)
 
void aliasRow (const MultidimArray< T > &m, size_t select_row)
 
void aliasSlice (const MultidimArray< T > &m, size_t select_slice)
 
void aliasImageInStack (const MultidimArray< T > &m, size_t select_image)
 
Size
void resize (size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
 
template<typename T1 >
void resize (const MultidimArray< T1 > &v, bool copy=true)
 
template<typename T1 >
void resizeNoCopy (const MultidimArray< T1 > &v)
 
void checkDimensionWithDebug (int dim, const char *file, int line) const
 
void selfWindow (int n0, int z0, int y0, int x0, int nF, int zF, int yF, int xF, T init_value=0)
 
template<class T1 >
void window (MultidimArray< T1 > &result, int n0, int z0, int y0, int x0, int nF, int zF, int yF, int xF, T1 init_value=0) const
 
template<class T1 >
void window (MultidimArray< T1 > &result, int z0, int y0, int x0, int zF, int yF, int xF, T1 init_value=0) const
 
void selfWindow (int z0, int y0, int x0, int zF, int yF, int xF, T init_value=0)
 
template<class T1 >
void window (MultidimArray< T1 > &result, int y0, int x0, int yF, int xF, T1 init_value=0) const
 
void selfWindow (int y0, int x0, int yF, int xF, T init_value=0)
 
template<class T1 >
void window (MultidimArray< T1 > &result, int x0, int xF, T1 init_value=0) const
 
void selfWindow (int x0, int xF, T init_value=0)
 
void patch (MultidimArray< T > patchArray, int x, int y)
 
Access to the pixel values
T & operator() (const Matrix1D< double > &v) const
 
T & operator() (const Matrix1D< int > &v) const
 
T & operator() (size_t n, int k, int i, int j) const
 
T & operator() (int k, int i, int j) const
 
T & operator() (int i, int j) const
 
T & operator() (int i) const
 
T & operator[] (size_t i) const
 
void * getArrayPointer () const
 
void getImage (size_t n, MultidimArray< T > &M, size_t n2=0) const
 
template<typename T1 >
void getSlice (int k, MultidimArray< T1 > &M, char axis='Z', bool reverse=false, size_t n=0) const
 
void getSliceAsMatrix (size_t k, Matrix2D< T > &m) const
 
void getAliasAsRowVector (Matrix1D< T > &m) const
 
template<typename T1 >
void setSlice (int k, const MultidimArray< T1 > &v, size_t n=0)
 
template<typename T1 >
void reslice (MultidimArray< T1 > &out, AxisView face, bool flip=false, size_t n=0) const
 
void reslice (AxisView face, bool flip=false, size_t n=0)
 
void getCol (size_t j, MultidimArray< T > &v) const
 
void setCol (size_t j, const MultidimArray< T > &v)
 
void getRow (size_t i, MultidimArray< T > &v) const
 
void setRow (int i, const MultidimArray< T > &v)
 
void getReal (MultidimArray< double > &realImg) const
 
void getImag (MultidimArray< double > &imagImg) const
 
void toPhysical (int k_log, int i_log, int j_log, int &k_phys, int &i_phys, int &j_phys) const
 
void toLogical (int k_phys, int i_phys, int j_phys, int &k_log, int &i_log, int &j_log) const
 
void toPhysical (int i_log, int j_log, int &i_phys, int &j_phys) const
 
void toLogical (int i_phys, int j_phys, int &i_log, int &j_log) const
 
void toPhysical (int i_log, int &i_phys) const
 
void toLogical (int i_phys, int &i_log) const
 
interpolatedElement3D (double x, double y, double z, T outside_value=(T) 0) const
 
interpolatedElement2D (double x, double y, T outside_value=(T) 0) const
 
interpolatedElement2DOutsideZero (double x, double y) const
 
interpolatedElement1D (double x, T outside_value=(T) 0) const
 
interpolatedElementBSpline3D (double x, double y, double z, int SplineDegree=3) const
 
interpolatedElementBSpline2D (double x, double y, int SplineDegree=3) const
 
interpolatedElementBSpline2D_Degree3 (double x, double y) const
 
interpolatedElementBSpline1D (double x, int SplineDegree=3) const
 
Statistics functions
void printStats (std::ostream &out=std::cout) const
 
computeMax () const
 
void maxIndex (int &jmax) const
 
computeMin () const
 
void minIndex (int &lmin, int &kmin, int &imin, int &jmin) const
 
void minIndex (int &kmin, int &imin, int &jmin) const
 
void minIndex (int &imin, int &jmin) const
 
void minIndex (int &jmin) const
 
void maxIndex (size_t &lmax, int &kmax, int &imax, int &jmax) const
 
void computeDoubleMinMax (double &minval, double &maxval) const
 
void computeDoubleMinMaxRange (double &minval, double &maxval, size_t offset, size_t size) const
 
double computeAvg () const
 
double computeStddev () const
 
void computeStats (double &avg, double &stddev, T &minval, T &maxval) const
 
template<typename U >
void computeAvgStdev (U &avg, U &stddev) const
 
void computeAvgStdev_within_binary_mask (const MultidimArray< int > &mask, double &avg, double &stddev) const
 
void computeMedian_within_binary_mask (const MultidimArray< int > &mask, double &median) const
 
void computeStats (double &avg, double &stddev, T &min_val, T &max_val, Matrix1D< int > &corner1, Matrix1D< int > &corner2, size_t n=0)
 
double computeMedian () const
 
void rangeAdjust (T minF, T maxF)
 
void rangeAdjust (T minF, T maxF, MultidimArray< int > &mask)
 
void rangeAdjust (const MultidimArray< T > &example, const MultidimArray< int > *mask=NULL)
 
template<typename U >
void statisticsAdjust (U avgF, U stddevF)
 
Initialization
void initConstant (T val)
 
template<typename T1 >
void initZeros (const MultidimArray< T1 > &op)
 
void initZeros ()
 
void initZeros (size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim)
 
void initZeros (int Xdim)
 
void initZeros (int Ydim, int Xdim)
 
void initZeros (int Zdim, int Ydim, int Xdim)
 
void initLinear (T minF, T maxF, int n=1, const String &mode="incr")
 
void initRandom (double op1, double op2, RandomMode mode=RND_UNIFORM)
 
void addNoise (double op1, double op2, const String &mode="uniform", double df=3.) const
 
- Public Member Functions inherited from MultidimArrayBase
virtual ~MultidimArrayBase ()
 
int getDim () const
 
void setMmap (bool mmap)
 
void maxIndex (ArrayCoord &pos) const
 
void maxIndex (int &kmax, int &imax, int &jmax) const
 
void maxIndex (int &imax, int &jmax) const
 
void maxIndex (int &jmax) const
 
void printShape (std::ostream &out=std::cout) const
 
void setNdim (int Ndim)
 
void setZdim (int Zdim)
 
void setYdim (int Ydim)
 
void setXdim (int Xdim)
 
void setDimensions (int Xdim, int Ydim, int Zdim, size_t Ndim)
 
void setDimensions (ArrayDim &newDim)
 
void getDimensions (size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const
 
void getDimensions (ArrayDim &idim) const
 
ArrayDim getDimensions () const
 
void getDimensions (int *size) const
 
size_t getSize () const
 
void resize (size_t Zdim, size_t Ydim, size_t Xdim)
 
void resize (size_t Ydim, size_t Xdim)
 
void resize (size_t Xdim)
 
void resize (ArrayDim &adim, bool copy=true)
 
void resizeNoCopy (size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim)
 
void resizeNoCopy (size_t Zdim, size_t Ydim, size_t Xdim)
 
void resizeNoCopy (size_t Ydim, size_t Xdim)
 
void resizeNoCopy (size_t Xdim)
 
size_t rowNumber () const
 
size_t colNumber () const
 
void copyShape (const MultidimArrayBase &m)
 
bool sameShape (const MultidimArrayBase &op) const
 
void setXmippOrigin ()
 
void resetOrigin ()
 
void moveOriginTo (int k, int i, int j)
 
void moveOriginTo (int i, int j)
 
int startingZ () const
 
int finishingZ () const
 
int startingY () const
 
int finishingY () const
 
int startingX () const
 
int finishingX () const
 
bool isCorner (const Matrix1D< double > &v) const
 
bool outside (int k, int i, int j) const
 
bool outside (int i, int j) const
 
bool outside (int i) const
 
bool outside (const Matrix1D< double > &r) const
 

Public Attributes

T * data
 
- Public Attributes inherited from MultidimArrayBase
bool destroyData
 
size_t ndim
 
size_t zdim
 
size_t ydim
 
size_t xdim
 
size_t yxdim
 
size_t zyxdim
 
size_t nzyxdim
 
int zinit
 
int yinit
 
int xinit
 
bool mmapOn
 
FILE * mFd
 
size_t nzyxdimAlloc
 

Friends

Scalar "by" array operations

These operations are between a scalar (of the same type as the array) and an array. The result must have been defined to be of the same type as the operand. The former content of the result array is lost after the operation.

In this kind of operations the constant is operated with each element of array 2. The result has also got the same shape as the input array and its former content is lost

void coreScalarByArray (const T &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)
 
void scalarByArray (T op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)
 
MultidimArray< T > operator+ (T op1, const MultidimArray< T > &op2)
 
MultidimArray< T > operator- (T op1, const MultidimArray< T > &op2)
 
MultidimArray< T > operator* (T op1, const MultidimArray< T > &op2)
 
MultidimArray< T > operator/ (T op1, const MultidimArray< T > &op2)
 

Array "by" array operations.

These are operations that are performed between 2 arrays of the SAME type (two integer vectors, two double matrices, ...). If they are not of the same type you can convert one of the arrays to the desired type using the function typeCast. The result must have been defined to be of the same type as the operands.

In this kind of operations each element of array 1 is operated with its homologous in array 2, it is very important that both have got the same size and starting origins. The result has also got the same shape as the two operated arrays and its former content is lost.

MultidimArray< T > operator+ (const MultidimArray< T > &op1) const
 
MultidimArray< T > operator- (const MultidimArray< T > &op1) const
 
MultidimArray< T > operator* (const MultidimArray< T > &op1) const
 
MultidimArray< T > operator/ (const MultidimArray< T > &op1) const
 
void operator+= (const MultidimArray< T > &op1)
 
void operator-= (const MultidimArray< T > &op1)
 
void operator*= (const MultidimArray< T > &op1)
 
void operator/= (const MultidimArray< T > &op1)
 
double dotProduct (const MultidimArray< T > &op1)
 
void coreArrayByArray (const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)
 
void selfCoreArrayByArrayMask (const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation, const MultidimArray< T > *mask)
 
void arrayByArray (const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)
 
void selfArrayByArrayMask (const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation, const MultidimArray< T > *mask=NULL)
 

Array "by" scalar operations

These operations are between an array and a scalar (of the same type as the array). The result must have been defined to be of the same type as the operands.

In this kind of operations each element of array 1 is operated with the given constant. The result has also got the same shape as the input array and its former content is lost

MultidimArray< T > operator+ (T op1) const
 
MultidimArray< T > operator- (T op1) const
 
MultidimArray< T > operator* (T op1) const
 
MultidimArray< T > operator/ (T op1) const
 
void equal (T op1, MultidimArray< char > &result) const
 
void operator+= (const T &op1)
 
void operator-= (const T &op1)
 
void operator*= (const T &op1)
 
void operator/= (const T &op1)
 
void coreArrayByScalar (const MultidimArray< T > &op1, const T &op2, MultidimArray< T > &result, char operation)
 
void arrayByScalar (const MultidimArray< T > &op1, T op2, MultidimArray< T > &result, char operation)
 

Utilities

Here you have several easy functions to manage the values of the array.

T *** adaptForNumericalRecipes3D (size_t n=0) const
 
void killAdaptationForNumericalRecipes3D (T ***m) const
 
T ** adaptForNumericalRecipes2D (size_t n=0) const
 
T * adaptForNumericalRecipes22D () const
 
void loadFromNumericalRecipes2D (T **m, int Ydim, int Xdim)
 
void killAdaptationForNumericalRecipes2D (T **m) const
 
void killAdaptationForNumericalRecipes22D (T **m) const
 
T * adaptForNumericalRecipes1D () const
 
void killAdaptationForNumericalRecipes1D (T *m) const
 
void centerOfMass (Matrix1D< double > &center, void *mask=NULL, size_t n=0)
 
void sort (MultidimArray< T > &result) const
 
void indexSort (MultidimArray< int > &indx) const
 
void cumlativeDensityFunction (MultidimArray< double > &cdf)
 
void threshold (const String &type, T a, T b=0, MultidimArray< int > *mask=NULL)
 
size_t countThreshold (const String &type, T a, T b, MultidimArray< int > *mask=NULL)
 
void substitute (T oldv, T newv, double accuracy=XMIPP_EQUAL_ACCURACY, MultidimArray< int > *mask=NULL)
 
void randomSubstitute (T oldv, T avgv, T sigv, double accuracy=XMIPP_EQUAL_ACCURACY, MultidimArray< int > *mask=NULL)
 
void binarize (double val=0, double accuracy=XMIPP_EQUAL_ACCURACY, MultidimArray< int > *mask=NULL)
 
void binarizeRange (double valMin=0, double valMax=255, MultidimArray< int > *mask=NULL)
 
void selfROUND ()
 
void selfCEIL ()
 
void selfFLOOR ()
 
void selfABS ()
 
void selfNormalizeInterval (double minPerc=0.25, double maxPerc=0.75, int Npix=1000)
 
void selfSQRT ()
 
double sum () const
 
double sum2 () const
 
void selfLog10 ()
 
void selfLog ()
 
void selfReverseX ()
 
void selfReverseY ()
 
void selfReverseZ ()
 
void profile (int x0, int y0, int xF, int yF, int N, MultidimArray< double > &profile) const
 
void showWithGnuPlot (const String &xlabel, const String &title)
 
void edit ()
 
void write (const FileName &fn) const
 
void MultidimArrayMax (const MultidimArray< T > &v1, const MultidimArray< T > &v2, MultidimArray< T > &result)
 
void MultidimArrayMIN (const MultidimArray< T > &v1, const MultidimArray< T > &v2, MultidimArray< T > &result)
 

Operators

MultidimArray< T > & operator= (const MultidimArray< T > &op1)
 
MultidimArray< T > & operator= (MultidimArray< T > &&other) noexcept
 
MultidimArray< T > & operator= (const Matrix2D< T > &op1)
 
MultidimArray< T > operator- () const
 
void copy (Matrix2D< T > &op1) const
 
bool equal (const MultidimArray< T > &op, double accuracy=XMIPP_EQUAL_ACCURACY) const
 
std::istream & operator>> (std::istream &in, MultidimArray< T > &v)
 

Detailed Description

template<typename T>
class MultidimArray< T >

Definition at line 35 of file common_lines.h.

Constructor & Destructor Documentation

◆ MultidimArray() [1/10]

template<typename T>
MultidimArray< T >::MultidimArray ( )
inline

Empty constructor. The empty constructor creates an array with no memory associated, size=0.

Definition at line 94 of file multidim_array.h.

95  {
96  coreInit();
97  }
void coreInit() noexcept

◆ MultidimArray() [2/10]

template<typename T>
MultidimArray< T >::MultidimArray ( size_t  Ndim,
size_t  Zdim,
size_t  Ydim,
size_t  Xdim,
T *  data 
)
inline

Size constructor with 4D size and already allocated data.

Definition at line 102 of file multidim_array.h.

102  {
103  this->coreInit();
104  this->setDimensions(Xdim, Ydim, Zdim, Ndim);
105  this->data = data;
106  this->nzyxdimAlloc = this->nzyxdim;
107  this->destroyData = false;
108  }
void coreInit() noexcept
void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)

◆ MultidimArray() [3/10]

template<typename T>
MultidimArray< T >::MultidimArray ( size_t  Ndim,
int  Zdim,
int  Ydim,
int  Xdim 
)
inline

Size constructor with 4D size. The Size constructor creates an array with memory associated, and fills it with zeros.

Definition at line 115 of file multidim_array.h.

116  {
117  coreInit();
118  coreAllocate(Ndim, Zdim, Ydim, Xdim);
119  }
void coreInit() noexcept

◆ MultidimArray() [4/10]

template<typename T>
MultidimArray< T >::MultidimArray ( int  Zdim,
int  Ydim,
int  Xdim 
)
inline

Size constructor with 3D size. The Size constructor creates an array with memory associated, and fills it with zeros.

Definition at line 125 of file multidim_array.h.

126  {
127  coreInit();
128  coreAllocate(1UL, Zdim, Ydim, Xdim);
129  }
void coreInit() noexcept

◆ MultidimArray() [5/10]

template<typename T>
MultidimArray< T >::MultidimArray ( int  Ydim,
int  Xdim 
)
inline

Size constructor with 2D size. The Size constructor creates an array with memory associated, and fills it with zeros.

Definition at line 135 of file multidim_array.h.

136  {
137  coreInit();
138  coreAllocate(1UL, 1, Ydim, Xdim);
139  }
void coreInit() noexcept

◆ MultidimArray() [6/10]

template<typename T>
MultidimArray< T >::MultidimArray ( int  Xdim)
inline

Size constructor with 1D size. The Size constructor creates an array with memory associated, and fills it with zeros.

Definition at line 145 of file multidim_array.h.

146  {
147  coreInit();
148  coreAllocate(1UL, 1, 1, Xdim);
149  }
void coreInit() noexcept

◆ MultidimArray() [7/10]

template<typename T>
MultidimArray< T >::MultidimArray ( const MultidimArray< T > &  V)
inline

Copy constructor

The created volume is a perfect copy of the input array but with a different memory assignment.

Definition at line 160 of file multidim_array.h.

161  {
162  coreInit();
163  *this = V;
164  }
void coreInit() noexcept

◆ MultidimArray() [8/10]

template<typename T>
MultidimArray< T >::MultidimArray ( MultidimArray< T > &&  V)
inlinenoexcept

Move constructor

The created volume is a perfect copy of the input array but with a different memory assignment.

Definition at line 175 of file multidim_array.h.

176  {
177  coreInit();
178  swap(V);
179  }
void swap(MultidimArray< T > &other) noexcept
void coreInit() noexcept

◆ MultidimArray() [9/10]

template<typename T>
MultidimArray< T >::MultidimArray ( const Matrix1D< T > &  V)
inline

Copy constructor from a Matrix1D. The Size constructor creates an array with memory associated, and fills it with zeros.

Definition at line 185 of file multidim_array.h.

186  {
187  coreInit();
188  coreAllocate(1, 1, 1, V.size());
189  for (size_t i = 0; i < V.size(); i++)
190  DIRECT_A1D_ELEM(*this,i) = VEC_ELEM(V,i);
191  }
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
size_t size() const
Definition: matrix1d.h:508
void coreInit() noexcept
#define i
#define DIRECT_A1D_ELEM(v, i)

◆ MultidimArray() [10/10]

template<typename T>
MultidimArray< T >::MultidimArray ( const std::vector< T > &  vector)
inline

Constructor from vector 1D This will create a MultidimArray 1D the size and elements will be copied from the std::vector

Definition at line 198 of file multidim_array.h.

199  {
200  coreInit();
201  coreAllocate(1, 1, 1, vector.size());
202  for (size_t i = 0; i < vector.size(); i++)
203  DIRECT_A1D_ELEM(*this,i) = vector[i];
204  }
void coreInit() noexcept
#define i
#define DIRECT_A1D_ELEM(v, i)

◆ ~MultidimArray()

template<typename T>
virtual MultidimArray< T >::~MultidimArray ( )
inlinevirtual

Destructor.

Definition at line 209 of file multidim_array.h.

210  {
211  coreDeallocate();
212  }
void coreDeallocate() noexcept

Member Function Documentation

◆ adaptForNumericalRecipes1D()

template<typename T>
T* MultidimArray< T >::adaptForNumericalRecipes1D ( ) const
inline

Produce a 1D array suitable for working with Numerical Recipes

This function must be used only as a preparation for routines which need that the first physical index is 1 and not 0 as it usually is in C. In fact the vector provided for Numerical recipes is exactly this same one but with the indexes changed.

This function is not ported to Python.

Definition at line 2976 of file multidim_array.h.

2977  {
2978  return MULTIDIM_ARRAY(*this) - 1;
2979  }
#define MULTIDIM_ARRAY(v)

◆ adaptForNumericalRecipes22D()

template<typename T>
T* MultidimArray< T >::adaptForNumericalRecipes22D ( ) const
inline

Produce a 1D pointer suitable for working with Numerical Recipes (2)

This function meets the same goal as the one before, however this one work with 2D arrays as a single pointer. The first element of the array is pointed by result[1*Xdim+1], and in general result[i*Xdim+j]

Definition at line 2935 of file multidim_array.h.

2936  {
2937  return MULTIDIM_ARRAY(*this) - 1 - XSIZE(*this);
2938  }
#define MULTIDIM_ARRAY(v)
#define XSIZE(v)

◆ adaptForNumericalRecipes2D()

template<typename T>
T** MultidimArray< T >::adaptForNumericalRecipes2D ( size_t  n = 0) const
inline

Produce a 2D array suitable for working with Numerical Recipes

This function must be used only as a preparation for routines which need that the first physical index is 1 and not 0 as it usually is in C. New memory is needed to hold the new double pointer array.

Definition at line 2918 of file multidim_array.h.

2919  {
2920  T** m = NULL;
2921  ask_Tmatrix(m, 1, YSIZE(*this), 1, XSIZE(*this));
2922 
2924  m[i+1][j+1] = DIRECT_NZYX_ELEM(*this, n, 0, i, j);
2925 
2926  return m;
2927  }
#define YSIZE(v)
#define DIRECT_NZYX_ELEM(v, l, k, i, j)
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY2D(m)
#define i
#define XSIZE(v)
#define j
int m
void ask_Tmatrix(T **&m, int nrl, int nrh, int ncl, int nch)
Definition: xmipp_memory.h:40
int * n

◆ adaptForNumericalRecipes3D()

template<typename T>
T*** MultidimArray< T >::adaptForNumericalRecipes3D ( size_t  n = 0) const
inline

Produce a 3D array suitable for working with Numerical Recipes.

This function must be used only as a preparation for routines which need that the first physical index is 1 and not 0 as it usually is in C. New memory is needed to hold the new double pointer array.

Definition at line 2894 of file multidim_array.h.

2895  {
2896  T*** m = NULL;
2897  ask_Tvolume(m, 1, ZSIZE(*this), 1, YSIZE(*this), 1, XSIZE(*this));
2898 
2900  m[k+1][i+1][j+1] = DIRECT_NZYX_ELEM(*this, n, k, i, j);
2901 
2902  return m;
2903  }
#define YSIZE(v)
#define DIRECT_NZYX_ELEM(v, l, k, i, j)
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY3D(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 XSIZE(v)
#define ZSIZE(v)
#define j
int m
void ask_Tvolume(T ***&m, int nsl, int nsh, int nrl, int nrh, int ncl, int nch)
Definition: xmipp_memory.h:78
int * n

◆ addNoise()

template<typename T >
void MultidimArray< T >::addNoise ( double  op1,
double  op2,
const String mode = "uniform",
double  df = 3. 
) const

Add noise to actual values.

This function add some noise to the actual values of the array according to a certain random distribution. You must choose two parameters for each, for the uniform distribution they mean the range where to generate the random numbers, while in the gaussian case they are the mean and the standard deviation. By default the uniform distribution is selected. The size and origin of the array are not modified. The array itself is modified.

v1.addNoise(0, 1);
// uniform distribution between 0 and 1
v1.addNoise(0, 1, "uniform");
// the same
v1.addNoise(0, 1, "gaussian");
// gaussian distribution with 0 mean and stddev=1
v1.addNoise(0, 1, "student", 3);
// t-student distribution with 0 mean and stddev=1, and 3 degrees of freedom

Definition at line 837 of file multidim_array.cpp.

841 {
842  T* ptr=NULL;
843  size_t n;
844  if (mode == "uniform")
846  *ptr += static_cast< T >(rnd_unif(op1, op2));
847  else if (mode == "gaussian")
849  *ptr += static_cast< T >(rnd_gaus(op1, op2));
850  else if (mode == "student")
852  *ptr += static_cast< T >(rnd_student_t(df, op1, op2));
853  else
855  formatString("AddNoise: Mode not supported (%s)", mode.c_str()));
856 }
double rnd_student_t(double nu)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
double rnd_unif()
void mode
double rnd_gaus()
String formatString(const char *format,...)
Incorrect value received.
Definition: xmipp_error.h:195
int * n

◆ alias()

template<typename T>
void MultidimArray< T >::alias ( const MultidimArray< T > &  m)
inline

Alias a multidimarray.

Treat the multidimarray as if it were a volume. The data is not copied into new memory, but a pointer to the multidimarray is copied. You should not make any operation on this volume such that the memory locations are changed

Definition at line 379 of file multidim_array.h.

380  {
381  coreDeallocate();
382  copyShape(m);
383  this->data=m.data;
384  this->nzyxdimAlloc = this->nzyxdim;
385  this->destroyData = false;
386  }
void coreDeallocate() noexcept
void copyShape(const MultidimArrayBase &m)

◆ aliasImageInStack()

template<typename T>
void MultidimArray< T >::aliasImageInStack ( const MultidimArray< T > &  m,
size_t  select_image 
)
inline

Alias an image in a stack.

Treat the multidimarray as if it were a single slice. The data is not copied into new memory, but a pointer to the selected image in the multidimarray is copied. You should not make any operation on this volume such that the memory locations are changed. Select_slice starts at 0 towards Nsize.

Definition at line 436 of file multidim_array.h.

437  {
438  if (select_image >= NSIZE(m))
439  REPORT_ERROR(ERR_MULTIDIM_SIZE, "aliasImageInStack: Selected image cannot be higher than N size.");
440  if (ZSIZE(m)!=1)
441  REPORT_ERROR(ERR_MULTIDIM_SIZE, "aliasImageInStack: This function is not meant for volumes");
442 
443  coreDeallocate();
444  setDimensions(XSIZE(m), YSIZE(m), 1, 1);
445  this->data = m.data + XSIZE(m)*YSIZE(m)*(select_image);
446  this->nzyxdimAlloc = this->nzyxdim;
447  this->destroyData = false;
448  }
#define NSIZE(v)
#define YSIZE(v)
void coreDeallocate() noexcept
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
#define XSIZE(v)
#define ZSIZE(v)
void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)

◆ aliasRow()

template<typename T>
void MultidimArray< T >::aliasRow ( const MultidimArray< T > &  m,
size_t  select_row 
)
inline

Alias a row in an image.

Treat the multidimarray as if it were a single slice. The data is not copied into new memory, but a pointer to the selected slice in the multidimarray is copied. You should not make any operation on this volume such that the memory locations are changed. Select_slice starts at 0 towards Zsize.

Definition at line 396 of file multidim_array.h.

397  {
398  if (select_row >= YSIZE(m))
399  REPORT_ERROR(ERR_MULTIDIM_SIZE, "aliasRow: Selected row cannot be higher than Y size.");
400 
401  coreDeallocate();
402  setDimensions(XSIZE(m),1, 1, 1);
403  this->data = m.data + XSIZE(m)*select_row;
404  this->nzyxdimAlloc = this->nzyxdim;
405  this->destroyData = false;
406  }
#define YSIZE(v)
void coreDeallocate() noexcept
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
#define XSIZE(v)
void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)

◆ aliasSlice()

template<typename T>
void MultidimArray< T >::aliasSlice ( const MultidimArray< T > &  m,
size_t  select_slice 
)
inline

Alias a slice in a multidimarray.

Treat the multidimarray as if it were a single slice. The data is not copied into new memory, but a pointer to the selected slice in the multidimarray is copied. You should not make any operation on this volume such that the memory locations are changed. Select_slice starts at 0 towards Zsize.

Definition at line 416 of file multidim_array.h.

417  {
418  if (select_slice >= ZSIZE(m))
419  REPORT_ERROR(ERR_MULTIDIM_SIZE, "aliasSlice: Selected slice cannot be higher than Z size.");
420 
421  coreDeallocate();
422  setDimensions(XSIZE(m), YSIZE(m), 1, 1);
423  this->data = m.data + XSIZE(m)*YSIZE(m)*(select_slice);
424  this->nzyxdimAlloc = this->nzyxdim;
425  this->destroyData = false;
426  }
#define YSIZE(v)
void coreDeallocate() noexcept
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
#define XSIZE(v)
#define ZSIZE(v)
void setDimensions(int Xdim, int Ydim, int Zdim, size_t Ndim)

◆ binarize()

template<typename T>
void MultidimArray< T >::binarize ( double  val = 0,
double  accuracy = XMIPP_EQUAL_ACCURACY,
MultidimArray< int > *  mask = NULL 
)
inline

Binarize.

This functions substitutes all values in a volume which are greater than val+accuracy by 1 and the rest are set to 0. Use threshold to get a very powerful binarization.

Definition at line 3252 of file multidim_array.h.

3255  {
3256  T* ptr=NULL;
3257  size_t n;
3259  if (mask == NULL || DIRECT_MULTIDIM_ELEM(*mask,n) > 0 )
3260  {
3261  if (*ptr <= val + accuracy)
3262  *ptr = 0;
3263  else
3264  *ptr = 1;
3265  }
3266  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define DIRECT_MULTIDIM_ELEM(v, n)
int * n

◆ binarizeRange()

template<typename T>
void MultidimArray< T >::binarizeRange ( double  valMin = 0,
double  valMax = 255,
MultidimArray< int > *  mask = NULL 
)
inline

Binarize using a range

This functions substitutes all values in a volume which are in the range between valMin and valMax by 1 and the rest are set to 0.

Definition at line 3273 of file multidim_array.h.

3275  {
3276  T* ptr=NULL;
3277  size_t n;
3279  if (mask == NULL || DIRECT_MULTIDIM_ELEM(*mask,n) > 0 )
3280  {
3281  if ( (*ptr < valMax) && (*ptr > valMin) )
3282  *ptr = 1;
3283  else
3284  *ptr = 0;
3285  }
3286  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define DIRECT_MULTIDIM_ELEM(v, n)
int * n

◆ centerOfMass()

template<typename T>
void MultidimArray< T >::centerOfMass ( Matrix1D< double > &  center,
void *  mask = NULL,
size_t  n = 0 
)
inline

Computes the center of mass of the nth array

Definition at line 2992 of file multidim_array.h.

2993  {
2994  center.initZeros(3);
2995  double mass = 0;
2996  MultidimArray< int >* imask = (MultidimArray< int >*) mask;
2997 
2999  {
3000  if ((imask == NULL || NZYX_ELEM(*imask, n, k, i, j)) &&
3001  A3D_ELEM(*this, k, i, j) > 0)
3002  {
3003  XX(center) += j * NZYX_ELEM(*this, n, k, i, j);
3004  YY(center) += i * NZYX_ELEM(*this, n, k, i, j);
3005  ZZ(center) += k * NZYX_ELEM(*this, n, k, i, j);
3006 
3007  mass += NZYX_ELEM(*this, n, k, i, j);
3008  }
3009  }
3010 
3011  if (mass != 0)
3012  center /= mass;
3013  }
#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 A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define XX(v)
Definition: matrix1d.h:85
void initZeros()
Definition: matrix1d.h:592
#define NZYX_ELEM(v, l, k, i, j)
#define j
#define YY(v)
Definition: matrix1d.h:93
int * n
#define ZZ(v)
Definition: matrix1d.h:101

◆ checkDimensionWithDebug()

template<typename T>
void MultidimArray< T >::checkDimensionWithDebug ( int  dim,
const char *  file,
int  line 
) const
inline

Definition at line 521 of file multidim_array.h.

522  {
523  if (getDim() != dim)
524  {
525  std::cerr<<" Check for dimension: " << dim <<std::endl;
526  std::cerr << "MultidimArray shape: ";
527  printShape(std::cerr);
528  std::cerr << std::endl;
529  std::cerr << "Check called from file "<<file<<" line "<<line<<std::endl;
530  exit(1);
531  }
532  }
void printShape(std::ostream &out=std::cout) const

◆ clear()

template<typename T>
void MultidimArray< T >::clear ( )
inlinevirtual

Clear.

Implements MultidimArrayBase.

Definition at line 216 of file multidim_array.h.

217  {
218  coreDeallocate();
219  coreInit();
220  }
void coreDeallocate() noexcept
void coreInit() noexcept

◆ computeAvg()

template<typename T>
double MultidimArray< T >::computeAvg ( ) const
inlinevirtual

Average of the values in the array.

The returned value is always double, independently of the type of the array.

Implements MultidimArrayBase.

Definition at line 1739 of file multidim_array.h.

1740  {
1741  if (NZYXSIZE(*this) <= 0)
1742  return 0;
1743 
1744  double sum = 0;
1745 
1746  T* ptr=NULL;
1747  size_t n;
1749  sum += static_cast< double >(*ptr);
1750 
1751  return sum / NZYXSIZE(*this);
1752  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define NZYXSIZE(v)
int * n
double sum() const

◆ computeAvgStdev()

template<typename T>
template<typename U >
void MultidimArray< T >::computeAvgStdev ( U &  avg,
U &  stddev 
) const
inline

Compute statistics.

The average, standard deviation, minimum and maximum value are returned.

Definition at line 1836 of file multidim_array.h.

1837  {
1838  static_assert(
1839  std::is_same<double, U>::value || std::is_same<float, U>::value,
1840  "U must be a floating presiont type");
1841  if (NZYXSIZE(*this) <= 0)
1842  return;
1843 
1844  avg = 0;
1845  stddev = 0;
1846  const size_t nMax = nzyxdim;
1847  for (size_t n = 0; n < nMax; ++n)
1848  {
1849  U v = (U)data[n];
1850  avg += v;
1851  stddev += v * v;
1852  }
1853 
1854  avg /= NZYXSIZE(*this);
1855 
1856  if (NZYXSIZE(*this) > 1)
1857  {
1858  stddev = stddev / NZYXSIZE(*this) - avg * avg;
1859  stddev *= NZYXSIZE(*this) / (NZYXSIZE(*this) - 1);
1860 
1861  // Foreseeing numerical instabilities
1862  stddev = sqrt(fabs(stddev));
1863  }
1864  else
1865  stddev = 0;
1866  }
void sqrt(Image< double > &op)
#define NZYXSIZE(v)
int * n

◆ computeAvgStdev_within_binary_mask()

template<typename T>
void MultidimArray< T >::computeAvgStdev_within_binary_mask ( const MultidimArray< int > &  mask,
double &  avg,
double &  stddev 
) const
inline

Compute statistics in the active area

Only the statistics for values in the overlapping between the mask and the volume for those the mask is not 0 are computed.

Definition at line 1873 of file multidim_array.h.

1875  {
1876  double sum1 = 0;
1877  double sum2 = 0;
1878  double N = 0;
1879 
1881  {
1882  if (DIRECT_MULTIDIM_ELEM(mask, n) != 0)
1883  {
1884  ++N;
1885  double aux=DIRECT_MULTIDIM_ELEM(*this, n);
1886  sum1 += aux;
1887  sum2 += aux*aux;
1888  }
1889  }
1890 
1891  // average and standard deviation
1892  avg = sum1 / N;
1893  if (N > 1)
1894  stddev = sqrt(fabs(sum2 / N - avg * avg) * N / (N - 1));
1895  else
1896  stddev = 0;
1897  }
void sqrt(Image< double > &op)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
double sum2() const
int * n

◆ computeDoubleMinMax()

template<typename T>
void MultidimArray< T >::computeDoubleMinMax ( double &  minval,
double &  maxval 
) const
inline

Minimum and maximum of the values in the array.

As doubles.

Definition at line 1688 of file multidim_array.h.

1689  {
1690  if (NZYXSIZE(*this) <= 0)
1691  return;
1692 
1693  T* ptr=NULL;
1694  size_t n;
1695  T Tmin=DIRECT_MULTIDIM_ELEM(*this,0);
1696  T Tmax=Tmin;
1698  {
1699  T val=*ptr;
1700  if (val < Tmin)
1701  Tmin = val;
1702  else if (val > Tmax)
1703  Tmax = val;
1704  }
1705  minval = static_cast< double >(Tmin);
1706  maxval = static_cast< double >(Tmax);
1707  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define DIRECT_MULTIDIM_ELEM(v, n)
#define NZYXSIZE(v)
int * n

◆ computeDoubleMinMaxRange()

template<typename T>
void MultidimArray< T >::computeDoubleMinMaxRange ( double &  minval,
double &  maxval,
size_t  offset,
size_t  size 
) const
inlinevirtual

Minimum and maximum of the values in the array.

As doubles.

Implements MultidimArrayBase.

Definition at line 1713 of file multidim_array.h.

1714  {
1715  if (NZYXSIZE(*this) <= 0)
1716  return;
1717 
1718  minval = maxval = static_cast< double >(data[offset]);
1719 
1720  T* ptr=NULL;
1721  T val;
1722  size_t n;
1723 
1724  for (n=offset,ptr=data+offset; n<size; ++n, ++ptr)
1725  {
1726  val = *ptr;
1727  if (val < minval)
1728  minval = static_cast< double >(val);
1729  else if (val > maxval)
1730  maxval = static_cast< double >(val);
1731  }
1732  }
#define NZYXSIZE(v)
int * n

◆ computeMax()

template<typename T>
T MultidimArray< T >::computeMax ( ) const
inline

Maximum of the values in the array.

The returned value is of the same type as the type of the array.

Definition at line 1537 of file multidim_array.h.

1538  {
1539  if (NZYXSIZE(*this) <= 0)
1540  return static_cast< T >(0);
1541 
1542  T maxval = data[0];
1543 
1544  T* ptr=NULL;
1545  size_t n;
1547  if (*ptr > maxval)
1548  maxval = *ptr;
1549 
1550  return maxval;
1551  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define NZYXSIZE(v)
int * n

◆ computeMedian()

template<typename T>
double MultidimArray< T >::computeMedian ( ) const
inline

Median

Calculate the median element.

med = v1.computeMedian();

Definition at line 1951 of file multidim_array.h.

1952  {
1953  if (XSIZE(*this) == 0)
1954  return 0;
1955 
1956  if (XSIZE(*this) == 1)
1957  return DIRECT_MULTIDIM_ELEM(*this,0);
1958 
1959  // Initialise data
1960  MultidimArray<T> temp;
1961  this->sort(temp);
1962 
1963  // Get median
1964  if (NZYXSIZE(*this)%2==0)
1965  return 0.5*(DIRECT_MULTIDIM_ELEM(temp,NZYXSIZE(*this)/2-1)+
1966  DIRECT_MULTIDIM_ELEM(temp,NZYXSIZE(*this)/2 ));
1967  else
1968  return DIRECT_MULTIDIM_ELEM(temp,NZYXSIZE(*this)/2);
1969  }
void sort(MultidimArray< T > &result) const
#define XSIZE(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
#define NZYXSIZE(v)

◆ computeMedian_within_binary_mask()

template<typename T >
void MultidimArray< T >::computeMedian_within_binary_mask ( const MultidimArray< int > &  mask,
double &  median 
) const

Definition at line 1099 of file multidim_array.cpp.

1100 {
1101  std::vector<double> bgI;
1102 
1104  {
1105  if (DIRECT_MULTIDIM_ELEM(mask, n) != 0)
1106  {
1107  double aux = DIRECT_MULTIDIM_ELEM(*this, n);
1108  bgI.push_back(aux);
1109  }
1110  }
1111 
1112  std::sort(bgI.begin(), bgI.end());
1113  if (bgI.size() % 2 != 0)
1114  median = bgI[bgI.size() / 2];
1115  else
1116  median = (bgI[(bgI.size() - 1) / 2] + bgI[bgI.size() / 2]) / 2.0;
1117 }
void median(MultidimArray< T > &x, MultidimArray< T > &y, T &m)
Definition: filters.h:1055
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
int * n

◆ computeMin()

template<typename T>
T MultidimArray< T >::computeMin ( ) const
inline

Minimum of the values in the array.

The returned value is of the same type as the type of the array.

Definition at line 1568 of file multidim_array.h.

1569  {
1570  if (NZYXSIZE(*this) <= 0)
1571  return static_cast< T >(0);
1572 
1573  T minval = data[0];
1574 
1575  T* ptr=NULL;
1576  size_t n;
1578  if (*ptr < minval)
1579  minval = *ptr;
1580 
1581  return minval;
1582  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define NZYXSIZE(v)
int * n

◆ computeStats() [1/2]

template<typename T>
void MultidimArray< T >::computeStats ( double &  avg,
double &  stddev,
T &  minval,
T &  maxval 
) const
inline

Compute statistics.

The average, standard deviation, minimum and maximum value are returned.

Definition at line 1791 of file multidim_array.h.

1792  {
1793  if (NZYXSIZE(*this) <= 0)
1794  return;
1795 
1796  avg = 0;
1797  stddev = 0;
1798 
1799  minval = maxval = data[0];
1800 
1801  T* ptr=NULL;
1802  size_t n;
1804  {
1805  T Tval=*ptr;
1806  double val=Tval;
1807  avg += val;
1808  stddev += val * val;
1809 
1810  if (Tval > maxval)
1811  maxval = Tval;
1812  else if (Tval < minval)
1813  minval = Tval;
1814  }
1815 
1816  avg /= NZYXSIZE(*this);
1817 
1818  if (NZYXSIZE(*this) > 1)
1819  {
1820  stddev = stddev / NZYXSIZE(*this) - avg * avg;
1821  stddev *= NZYXSIZE(*this) / (NZYXSIZE(*this) - 1);
1822 
1823  // Foreseeing numerical instabilities
1824  stddev = sqrt(static_cast< double >(ABS(stddev)));
1825  }
1826  else
1827  stddev = 0;
1828  }
void sqrt(Image< double > &op)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define ABS(x)
Definition: xmipp_macros.h:142
#define NZYXSIZE(v)
int * n

◆ computeStats() [2/2]

template<typename T>
void MultidimArray< T >::computeStats ( double &  avg,
double &  stddev,
T &  min_val,
T &  max_val,
Matrix1D< int > &  corner1,
Matrix1D< int > &  corner2,
size_t  n = 0 
)
inline

Compute statistics within 2D region of 2D image.

The 2D region is specified by two corners. Note that this function only works for the 0th image in a multi-image array...

Definition at line 1906 of file multidim_array.h.

1913  {
1914  (*this).checkDimension(2);
1915  min_val = max_val = NZYX_ELEM((*this), n, 0, YY(corner1), XX(corner1));
1916 
1917  Matrix1D< double > r(3);
1918  double N = 0, sum = 0, sum2 = 0;
1919 
1920  FOR_ALL_ELEMENTS_IN_ARRAY2D_BETWEEN(corner1, corner2)
1921  {
1922  sum += (*this)(r);
1923  sum2 += (*this)(r) * (*this)(r);
1924  N++;
1925 
1926  if ((*this)(r) < min_val)
1927  min_val = (*this)(r);
1928  else if ((*this)(r) > max_val)
1929  max_val = (*this)(r);
1930  }
1931 
1932  if (N != 0)
1933  {
1934  avg = sum / N;
1935  stddev = sqrt(sum2 / N - avg * avg);
1936  }
1937  else
1938  {
1939  avg = stddev = 0;
1940  }
1941  }
void sqrt(Image< double > &op)
#define XX(v)
Definition: matrix1d.h:85
#define NZYX_ELEM(v, l, k, i, j)
#define YY(v)
Definition: matrix1d.h:93
double sum2() const
#define FOR_ALL_ELEMENTS_IN_ARRAY2D_BETWEEN(corner1, corner2)
int * n
double sum() const

◆ computeStddev()

template<typename T>
double MultidimArray< T >::computeStddev ( ) const
inline

Standard deviation of the values in the array.

Be careful that the standard deviation and NOT the variance is returned. The returned value is always double, independently of the type of the array.

Definition at line 1760 of file multidim_array.h.

1761  {
1762  if (NZYXSIZE(*this) <= 1)
1763  return 0;
1764 
1765  double avg = 0, stddev = 0;
1766 
1767  T* ptr=NULL;
1768  size_t n;
1770  {
1771  double val=static_cast< double >(*ptr);
1772  avg += val;
1773  stddev += val * val;
1774  }
1775 
1776  avg /= NZYXSIZE(*this);
1777  stddev = stddev / NZYXSIZE(*this) - avg * avg;
1778  stddev *= NZYXSIZE(*this) / (NZYXSIZE(*this) - 1);
1779 
1780  // Foreseeing numerical instabilities
1781  stddev = sqrt(static_cast<double>((ABS(stddev))));
1782 
1783  return stddev;
1784  }
void sqrt(Image< double > &op)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define ABS(x)
Definition: xmipp_macros.h:142
#define NZYXSIZE(v)
int * n

◆ copy()

template<typename T>
void MultidimArray< T >::copy ( Matrix2D< T > &  op1) const

Definition at line 56 of file multidim_array.cpp.

57 {
58  op1.resizeNoCopy(YSIZE(*this), XSIZE(*this));
59  memcpy(MATRIX2D_ARRAY(op1), MULTIDIM_ARRAY(*this), MULTIDIM_SIZE(*this)*sizeof(T));
60 }
#define YSIZE(v)
#define MULTIDIM_SIZE(v)
#define MULTIDIM_ARRAY(v)
void resizeNoCopy(int Ydim, int Xdim)
Definition: matrix2d.h:534
#define XSIZE(v)
#define MATRIX2D_ARRAY(m)
Definition: matrix2d.h:89

◆ coreAllocate() [1/2]

template<typename T>
void MultidimArray< T >::coreAllocate ( size_t  _ndim,
int  _zdim,
int  _ydim,
int  _xdim 
)
inline

Core allocate with dimensions.

Definition at line 262 of file multidim_array.h.

263  {
264  if (_ndim <= 0 || _zdim <= 0 || _ydim<=0 || _xdim<=0)
265  {
266  clear();
267  return;
268  }
269  if(data!=NULL)
270  REPORT_ERROR(ERR_MEM_NOTDEALLOC, "do not allocate space for an image if you have not deallocate it first");
271 
272  ndim=_ndim;
273  zdim=_zdim;
274  ydim=_ydim;
275  xdim=_xdim;
276  yxdim=(size_t)ydim*xdim;
277  zyxdim=yxdim*zdim;
279 
280  coreAllocate();
281  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Memory has not been deallocated.
Definition: xmipp_error.h:167

◆ coreAllocate() [2/2]

template<typename T>
void MultidimArray< T >::coreAllocate ( )
inline

Core allocate without dimensions.

It is supposed the dimensions are set previously with setXdim(x), setYdim(y) setZdim(z), setNdim(n) or with setDimensions(Xdim, Ydim, Zdim, Ndim);

Definition at line 289 of file multidim_array.h.

290  {
291  if(data!=NULL)
292  REPORT_ERROR(ERR_MEM_NOTDEALLOC, "do not allocate space for an image if you have not deallocate it first");
293 
294  if (mmapOn)
295  mFd = mmapFile(data, nzyxdim);
296  else
297  {
298  try
299  {
300  data = new T [nzyxdim];
301  if (data == NULL)
302  {
303  setMmap(true);
304  mFd = mmapFile(data, nzyxdim);
305  }
306  }
307  catch (std::bad_alloc &)
308  {
309  setMmap(true);
310  mFd = mmapFile(data, nzyxdim);
311  }
312  }
313  memset(data,0,nzyxdim*sizeof(T));
315  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
FILE * mmapFile(T *&_data, size_t nzyxDim) const
Memory has not been deallocated.
Definition: xmipp_error.h:167
void setMmap(bool mmap)

◆ coreAllocateReuse()

template<typename T>
void MultidimArray< T >::coreAllocateReuse ( )
inlinevirtual

Core allocate without dimensions.

It is supposed the dimensions are set previously with setXdim(x), setYdim(y) setZdim(z), setNdim(n) or with setDimensions(Xdim, Ydim, Zdim, Ndim);

Implements MultidimArrayBase.

Definition at line 323 of file multidim_array.h.

324  {
325  if(data != NULL && nzyxdim <= nzyxdimAlloc)
326  return;
327  else if (nzyxdim > nzyxdimAlloc)
328  coreDeallocate();
329 
330  if (mmapOn)
331  mFd = mmapFile(data, nzyxdim);
332  else
333  {
334  data = new T [nzyxdim];
335  if (data == NULL)
336  REPORT_ERROR(ERR_MEM_NOTENOUGH, "Allocate: No space left");
337  }
338  memset(data,0,nzyxdim*sizeof(T));
340  }
void coreDeallocate() noexcept
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
FILE * mmapFile(T *&_data, size_t nzyxDim) const
There is not enough memory for allocation.
Definition: xmipp_error.h:166

◆ coreDeallocate()

template<typename T>
void MultidimArray< T >::coreDeallocate ( )
inlinevirtualnoexcept

Core deallocate. Free all data.

Implements MultidimArrayBase.

Definition at line 349 of file multidim_array.h.

350  {
351  if (data != NULL && destroyData)
352  {
353  if (mmapOn)
354  {
355 #ifdef XMIPP_MMAP
356  munmap(data,nzyxdimAlloc*sizeof(T));
357  fclose(mFd);
358 #else
359 
360  REPORT_ERROR(ERR_MMAP,"Mapping not supported in Windows");
361 #endif
362 
363  }
364  else
365  delete[] data;
366  }
367  data = NULL;
368  destroyData = true;
369  nzyxdimAlloc = 0;
370  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Global mmap error.
Definition: xmipp_error.h:170

◆ coreInit()

template<typename T>
void MultidimArray< T >::coreInit ( )
inlinenoexcept

Core init. Initialize everything to 0

Definition at line 229 of file multidim_array.h.

◆ countThreshold()

template<typename T>
size_t MultidimArray< T >::countThreshold ( const String type,
a,
b,
MultidimArray< int > *  mask = NULL 
)
inline

Count with threshold.

This function returns the number of elements meeting the threshold condition.

Definition at line 3160 of file multidim_array.h.

3164  {
3165  int mode;
3166 
3167  if (type == "abs_above")
3168  mode = 1;
3169  else if (type == "abs_below")
3170  mode = 2;
3171  else if (type == "above")
3172  mode = 3;
3173  else if (type == "below")
3174  mode = 4;
3175  else if (type == "range")
3176  mode = 5;
3177  else
3179  formatString("CountThreshold: mode not supported (%s)", type.c_str()));
3180 
3181  size_t ret = 0;
3182 
3183  T* ptr=NULL;
3184  size_t n;
3186  if (mask == NULL || DIRECT_MULTIDIM_ELEM(*mask,n) > 0 )
3187  {
3188  switch (mode)
3189  {
3190  case 1:
3191  if (ABS(*ptr) > a)
3192  ret++;
3193  break;
3194  case 2:
3195  if (ABS(*ptr) < a)
3196  ret++;
3197  break;
3198  case 3:
3199  if (*ptr > a)
3200  ret++;
3201  break;
3202  case 4:
3203  if (*ptr < a)
3204  ret++;
3205  break;
3206  case 5:
3207  if (*ptr >= a && *ptr <= b)
3208  ret++;
3209  break;
3210  }
3211  }
3212  return ret;
3213  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
doublereal * b
viol type
#define ABS(x)
Definition: xmipp_macros.h:142
#define DIRECT_MULTIDIM_ELEM(v, n)
void mode
String formatString(const char *format,...)
Incorrect value received.
Definition: xmipp_error.h:195
int * n
doublereal * a

◆ cumlativeDensityFunction()

template<typename T>
void MultidimArray< T >::cumlativeDensityFunction ( MultidimArray< double > &  cdf)
inline

Cumulative Density Function. For each entry in the array, give what is the probability of having a value smaller or equal than this entry.

Definition at line 3042 of file multidim_array.h.

3043  {
3044  MultidimArray<int> indx;
3045  indexSort(indx);
3046  cdf.resizeNoCopy(*this);
3047  double iSize=1.0/XSIZE(indx);
3049  {
3050  int ii=A1D_ELEM(indx,i)-1;
3051  A1D_ELEM(cdf,ii)=(i+1)*iSize;
3052  }
3053  }
void resizeNoCopy(const MultidimArray< T1 > &v)
#define A1D_ELEM(v, i)
#define i
#define XSIZE(v)
#define FOR_ALL_ELEMENTS_IN_ARRAY1D(v)
void indexSort(MultidimArray< int > &indx) const

◆ dotProduct()

template<typename T>
double MultidimArray< T >::dotProduct ( const MultidimArray< T > &  op1)
inline

Dot product

Definition at line 2405 of file multidim_array.h.

2406  {
2407  if (!sameShape(op1))
2408  REPORT_ERROR(ERR_MULTIDIM_SIZE,"The two arrays for dot product are not of the same shape");
2409  double dot=0;
2410  size_t n;
2411  T* ptrOp1=NULL;
2412  T* ptrOp2=NULL;
2413  const size_t unroll=4;
2414  size_t nmax=unroll*(MULTIDIM_SIZE(*this)/unroll);
2415  for (n=0, ptrOp1=data,ptrOp2=op1.data;
2416  n<nmax; n+=unroll, ptrOp1+=unroll, ptrOp2+=unroll)
2417  {
2418  dot += *ptrOp1 * *ptrOp2;
2419  dot += *(ptrOp1+1) * *(ptrOp2+1);
2420  dot += *(ptrOp1+2) * *(ptrOp2+2);
2421  dot += *(ptrOp1+3) * *(ptrOp2+3);
2422  }
2423  for (n=nmax, ptrOp1=data+nmax, ptrOp2=op1.data+nmax;
2424  n<MULTIDIM_SIZE(*this); ++n, ++ptrOp1, ++ptrOp2)
2425  dot += *ptrOp1 * *ptrOp2;
2426  return dot;
2427  }
int * nmax
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define MULTIDIM_SIZE(v)
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
bool sameShape(const MultidimArrayBase &op) const
int * n
__host__ __device__ float dot(float2 a, float2 b)

◆ edit()

template<typename T >
void MultidimArray< T >::edit ( )

Edit with xmipp_editor.

This function generates a random filename starting with PPP and edits it with xmipp_editor. After closing the editor the file is removed.

Definition at line 956 of file multidim_array.cpp.

957 {
958  FileName nam;
959  nam.initRandom(15);
960 
961  nam = formatString("PPP%s.txt", nam.c_str());
962  write(nam);
963 
964  if (0 != system(formatString("xmipp_edit -i %s -remove &", nam.c_str()).c_str())) {
965  REPORT_ERROR(ERR_IO, "Cannot open xmipp_edit");
966  }
967 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Input/Output general error.
Definition: xmipp_error.h:134
void write(const FileName &fn) const
String formatString(const char *format,...)
void initRandom(int length)

◆ equal() [1/2]

template<typename T>
void MultidimArray< T >::equal ( op1,
MultidimArray< char > &  result 
) const
inline

v3 = (v1 == k).

Definition at line 2545 of file multidim_array.h.

2546  {
2547  result.resizeNoCopy(*this);
2549  DIRECT_MULTIDIM_ELEM(result,n) = DIRECT_MULTIDIM_ELEM(*this,n) == op1;
2550  }
void resizeNoCopy(const MultidimArray< T1 > &v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
int * n

◆ equal() [2/2]

template<typename T>
bool MultidimArray< T >::equal ( const MultidimArray< T > &  op,
double  accuracy = XMIPP_EQUAL_ACCURACY 
) const
inline

Equality.

Returns true if this object has got the same shape (origin and size) than the argument and the same values (within accuracy).

Definition at line 3721 of file multidim_array.h.

3723  {
3724  if (!sameShape(op) || data==NULL || op.data == NULL)
3725  return false;
3727  {
3728  if (fabs(DIRECT_MULTIDIM_ELEM(*this,n) -
3729  DIRECT_MULTIDIM_ELEM(op,n)) > accuracy)
3730  return false;
3731  }
3732  return true;
3733  }
bool sameShape(const MultidimArrayBase &op) const
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
int * n

◆ getAliasAsRowVector()

template<typename T>
void MultidimArray< T >::getAliasAsRowVector ( Matrix1D< T > &  m) const
inline

Return the data aliased as a row vector in a Matrix1D

Definition at line 1014 of file multidim_array.h.

1015  {
1016  m.vdim = NZYXSIZE(*this);
1017  m.destroyData = false;
1018  m.row = true;
1019  m.vdata = data;
1020  }
bool row
<0=column vector (default), 1=row vector
Definition: matrix1d.h:267
#define NZYXSIZE(v)
T * vdata
The array itself.
Definition: matrix1d.h:258
bool destroyData
Destroy data.
Definition: matrix1d.h:261
size_t vdim
Number of elements.
Definition: matrix1d.h:264

◆ getArrayPointer()

template<typename T>
void* MultidimArray< T >::getArrayPointer ( ) const
inlinevirtual

Return the void pointer to the internal data array

Implements MultidimArrayBase.

Definition at line 864 of file multidim_array.h.

865  {
866  return (void*) data;
867 
868  }

◆ getCol()

template<typename T>
void MultidimArray< T >::getCol ( size_t  j,
MultidimArray< T > &  v 
) const
inline

Get Column

This function returns a column vector corresponding to the chosen column.

std::vector< double > v;
m.getCol(-1, v);

Definition at line 1126 of file multidim_array.h.

1127  {
1128  if (xdim == 0 || ydim == 0)
1129  {
1130  v.clear();
1131  return;
1132  }
1133 
1134  if (j >= xdim)
1135  REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS,"getCol: Matrix subscript (j) greater than matrix dimension");
1136 
1137  v.resizeNoCopy(ydim);
1138  for (size_t i = 0; i < ydim; i++)
1139  DIRECT_A1D_ELEM(v,i) = DIRECT_A2D_ELEM(*this,i, j);
1140  }
Index out of bounds.
Definition: xmipp_error.h:132
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void resizeNoCopy(const MultidimArray< T1 > &v)
#define DIRECT_A2D_ELEM(v, i, j)
#define i
#define DIRECT_A1D_ELEM(v, i)
#define j

◆ getImag()

template<typename T>
void MultidimArray< T >::getImag ( MultidimArray< double > &  imagImg) const
inline

Definition at line 1221 of file multidim_array.h.

1222  {
1223  REPORT_ERROR(ERR_TYPE_INCORRECT, "MultidimArray: Non complex datatype.");
1224  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Incorrect type received.
Definition: xmipp_error.h:190

◆ getImage()

template<typename T>
void MultidimArray< T >::getImage ( size_t  n,
MultidimArray< T > &  M,
size_t  n2 = 0 
) const
inline

Copy an image from a stack to another

Copy image image n from this MDA to image n2 in MDA M.

V.getImage(0, m, 3);

Definition at line 877 of file multidim_array.h.

878  {
879  if (XSIZE(*this) == 0)
880  {
881  M.clear();
882  return;
883  }
884 
885  if (n > NSIZE(*this))
886  REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS," Multidimarray getImage: n larger than NSIZE");
887 
888  if (ZSIZE(*this) != ZSIZE(M) || YSIZE(*this) != YSIZE(M) || XSIZE(*this) != XSIZE(M))
889  {
890  if (n2 == 0)
891  M.resizeNoCopy(*this);
892  else
893  REPORT_ERROR(ERR_MULTIDIM_SIZE, "MultidimArray::getImage: Target dimensions do not match source dimensions.");
894  }
895 
896  if (n2 > NSIZE(M))
897  REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS," Multidimarray getImage: n larger than MultidimArray target NSIZE");
898 
899 
901  DIRECT_NZYX_ELEM(M, n2, k, i, j) = DIRECT_NZYX_ELEM(*this, n, k, i, j);
902 
903  STARTINGX(M) = STARTINGX(*this);
904  STARTINGY(M) = STARTINGY(*this);
905  STARTINGZ(M) = STARTINGZ(*this);
906  }
Index out of bounds.
Definition: xmipp_error.h:132
#define NSIZE(v)
#define YSIZE(v)
#define DIRECT_NZYX_ELEM(v, l, k, i, j)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void resizeNoCopy(const MultidimArray< T1 > &v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY3D(V)
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
#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 XSIZE(v)
#define ZSIZE(v)
#define j
#define STARTINGZ(v)
int * n

◆ getReal()

template<typename T>
void MultidimArray< T >::getReal ( MultidimArray< double > &  realImg) const
inline

Definition at line 1216 of file multidim_array.h.

1217  {
1218  REPORT_ERROR(ERR_TYPE_INCORRECT, "MultidimArray: Non complex datatype.");
1219  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Incorrect type received.
Definition: xmipp_error.h:190

◆ getRow()

template<typename T>
void MultidimArray< T >::getRow ( size_t  i,
MultidimArray< T > &  v 
) const
inline

Get row

This function returns a row vector corresponding to the chosen row inside the nth 2D matrix, the numbering of the rows is also logical not physical.

std::vector< double > v;
m.getRow(-2, v);

Definition at line 1178 of file multidim_array.h.

1179  {
1180  if (xdim == 0 || ydim == 0)
1181  {
1182  v.clear();
1183  return;
1184  }
1185 
1186  if (i >= ydim)
1187  REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS, "getRow: Matrix subscript (i) greater than matrix dimension");
1188 
1189  v.resizeNoCopy(xdim);
1190  memcpy(&A1D_ELEM(v,0),&A2D_ELEM(*this,i,0),xdim*sizeof(T));
1191  }
Index out of bounds.
Definition: xmipp_error.h:132
#define A2D_ELEM(v, i, j)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void resizeNoCopy(const MultidimArray< T1 > &v)
#define A1D_ELEM(v, i)
#define i

◆ getSlice()

template<typename T>
template<typename T1 >
void MultidimArray< T >::getSlice ( int  k,
MultidimArray< T1 > &  M,
char  axis = 'Z',
bool  reverse = false,
size_t  n = 0 
) const
inline

2D Slice access for reading.

This function returns a slice (a 2D matrix) corresponding to the chosen slice inside the nth 3D matrix, the numbering of the slices is also logical not physical. This function differs from the previous one in that this one cuts and assign in a single step instead of in two steps, as in the previous example.

V.slice(0, m);

Definition at line 921 of file multidim_array.h.

922  {
923  if (XSIZE(*this) == 0)
924  {
925  M.clear();
926  return;
927  }
928 
929  T* ptr=NULL;
930  switch (axis)
931  {
932  case 'Z':
933  if (k < STARTINGZ(*this) || k > FINISHINGZ(*this))
935  "Slice: Multidim subscript (k) out of range");
936 
937  M.resize(1, 1, YSIZE(*this), XSIZE(*this),false);
938  k = k - STARTINGZ(*this);
939 
940  if (reverse)
941  {
942  int zEnd = ZSIZE(*this) - 1;
944  DIRECT_A2D_ELEM(M, i, j) = (T1) DIRECT_NZYX_ELEM(*this, n, k, zEnd-i, j);
945  }
946  else
947  {
948  ptr=&(DIRECT_NZYX_ELEM(*this, n, k, 0, 0));
950  DIRECT_MULTIDIM_ELEM(M, n) = (T1) *(ptr++);
951  }
952 
953  STARTINGX(M) = STARTINGX(*this);
954  STARTINGY(M) = STARTINGY(*this);
955  break;
956  case 'Y':
957  if (k < STARTINGY(*this) || k > FINISHINGY(*this))
959  "Slice: Multidim subscript (i) out of range");
960 
961  k = k - STARTINGY(*this);
962  M.resizeNoCopy(ZSIZE(*this), XSIZE(*this));
963 
964  if (reverse)
965  {
966  int zEnd = ZSIZE(*this) - 1;
968  DIRECT_A2D_ELEM(M, i, j) = (T1) DIRECT_NZYX_ELEM(*this, n, zEnd-i, k, j);
969  }
970  else
971  {
973  DIRECT_A2D_ELEM(M, i, j) = (T1) DIRECT_NZYX_ELEM(*this, n, i, k, j);
974  }
975 
976  STARTINGX(M) = STARTINGX(*this);
977  STARTINGY(M) = STARTINGZ(*this);
978  break;
979  case 'X':
980  if (k < STARTINGX(*this) || k > FINISHINGX(*this))
982  "Slice: Multidim subscript (j) out of range");
983 
984  k = k - STARTINGX(*this);
985  M.resizeNoCopy(YSIZE(*this), ZSIZE(*this));
986 
987  if (reverse)
988  {
989  int zEnd = ZSIZE(*this) - 1;
991  DIRECT_A2D_ELEM(M, i, j) = (T1) DIRECT_NZYX_ELEM(*this, n, zEnd-j, i, k);
992  }
993  else
994  {
996  DIRECT_A2D_ELEM(M, i, j) = (T1) DIRECT_NZYX_ELEM(*this, n, j, i, k);
997  }
998 
999  STARTINGX(M) = STARTINGY(*this);
1000  STARTINGY(M) = STARTINGZ(*this);
1001  break;
1002  default:
1004  formatString("Slice: not supported axis %c", axis));
1005  }
1006  }
Index out of bounds.
Definition: xmipp_error.h:132
#define YSIZE(v)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
#define DIRECT_NZYX_ELEM(v, l, k, i, j)
#define FINISHINGX(v)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY2D(m)
void resizeNoCopy(const MultidimArray< T1 > &v)
#define DIRECT_A2D_ELEM(v, i, j)
#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)
char axis
#define XSIZE(v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define ZSIZE(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
#define j
#define FINISHINGY(v)
String formatString(const char *format,...)
Incorrect value received.
Definition: xmipp_error.h:195
#define STARTINGZ(v)
int * n

◆ getSliceAsMatrix()

template<typename T>
void MultidimArray< T >::getSliceAsMatrix ( size_t  k,
Matrix2D< T > &  m 
) const

Get Z slice as matrix

Definition at line 38 of file multidim_array.cpp.

39 {
40 // there's wrong bracket somewhere, and I don't want to think about it now
41 // m.resizeNoCopy(YSIZE(*this),XSIZE(*this));
42 // memcpy(&MAT_ELEM(m,0,0),&A3D_ELEM(*this,k,0,0),YSIZE(*this),XSIZE(*this)*sizeof(double));
43  REPORT_ERROR(ERR_NOT_IMPLEMENTED,"Please contact developers");
44 }
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211

◆ indexSort()

template<typename T >
void MultidimArray< T >::indexSort ( MultidimArray< int > &  indx) const

Gives a vector with the indexes for a sorted vector

This function returns the indexes of a sorted vector. The input vector is not modified at all. For instance, if the input vector is [3 2 -1 0] the result of this function would be [3 4 2 1] meaning that the lowest value is at index 3, then comes the element at index 4, ... Note that indexes start at 1.

v2 = v1.indexSort();

Definition at line 882 of file multidim_array.cpp.

883 {
884  checkDimension(1);
885 
887  indx.clear();
888 
889  if (xdim == 0)
890  return;
891 
892  if (xdim == 1)
893  {
894  indx.resizeNoCopy(1);
895  DIRECT_A1D_ELEM(indx,0) = 1;
896  return;
897  }
898 
899  // Initialise data
900  indx.resizeNoCopy(xdim);
901  typeCast(*this, temp);
902 
903  // Sort indexes
904  double* temp_array = temp.adaptForNumericalRecipes1D();
905  int* indx_array = indx.adaptForNumericalRecipes1D();
906  indexx(XSIZE(*this), temp_array, indx_array);
907 }
void resizeNoCopy(const MultidimArray< T1 > &v)
#define DIRECT_A1D_ELEM(v, i)
#define checkDimension(dim)
void indexx(int n, double arrin[], int indx[])
#define XSIZE(v)
T * adaptForNumericalRecipes1D() const
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
Definition: matrix1d.h:1227

◆ initConstant()

template<typename T>
void MultidimArray< T >::initConstant ( val)
inline

Same value in all components.

The constant must be of a type compatible with the array type, ie, you cannot assign a double to an integer array without a casting. It is not an error if the array is empty, then nothing is done.

v.initConstant(3.14);

Definition at line 2705 of file multidim_array.h.

2706  {
2707  T* ptr=NULL;
2708  size_t n;
2710  *ptr = val;
2711  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
int * n

◆ initLinear()

template<typename T>
void MultidimArray< T >::initLinear ( minF,
maxF,
int  n = 1,
const String mode = "incr" 
)
inline

Linear initialization (only for 1D)

The 1D vector is filled with values increasing/decreasing linearly within a range or at given steps.

Increment functionality: The default increment is 1, the initial point is incremented by this value until the upper limit is reached. This is the default working mode for the function.

v1.initLinear(1, 3); // v1=[1 2 3]
v1.initLinear(1.5, 3.1); // v1=[1.5 2.5]
v1.initLinear(0, 10, 3); // v1=[0 3 6 9]
v1.initLinear(0, 10, 3, "incr"); // v1=[0 3 6 9]

Step functionality: The given range is divided in as many points as indicated (in the example 6 points).

v1.initLinear(0, 10, 6, "steps"); // v1=[0 2 4 6 8 10]

Definition at line 2797 of file multidim_array.h.

2798  {
2799  double slope;
2800  int steps;
2801 
2802  if (mode == "incr")
2803  {
2804  steps = 1 + (int) FLOOR((double) ABS((maxF - minF)) / ((double) n));
2805  slope = n * SGN(maxF - minF);
2806  }
2807  else if (mode == "steps")
2808  {
2809  steps = n;
2810  slope = (maxF - minF) / (steps - 1);
2811  }
2812  else
2813  REPORT_ERROR(ERR_VALUE_INCORRECT, "Init_linear: Mode not supported (" + mode +
2814  ")");
2815 
2816  if (steps == 0)
2817  clear();
2818  else
2819  {
2820  resizeNoCopy(steps);
2821  for (int i = 0; i < steps; i++)
2822  A1D_ELEM(*this, i) = (T)((double) minF + slope * i);
2823  }
2824  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void resizeNoCopy(const MultidimArray< T1 > &v)
#define A1D_ELEM(v, i)
#define i
#define FLOOR(x)
Definition: xmipp_macros.h:240
#define ABS(x)
Definition: xmipp_macros.h:142
void mode
double steps
Incorrect value received.
Definition: xmipp_error.h:195
#define SGN(x)
Definition: xmipp_macros.h:155
int * n

◆ initRandom()

template<typename T >
template void MultidimArray< T >::initRandom ( double  op1,
double  op2,
RandomMode  mode = RND_UNIFORM 
)

Initialize with random values.

This function allows you to initialize the array with a set of random values picked from a uniform random distribution or a gaussian one. You must choose two parameters for each, for the uniform distribution they mean the range where to generate the random numbers, while in the gaussian case they are the mean and the standard deviation. By default the uniform distribution is selected. The size and origin of the array are not modified.

v.initRandom(0, 1);
// uniform distribution between 0 and 1
v.initRandom(0, 1, "uniform");
// the same
v.initRandom(0, 1, "gaussian");
// gaussian distribution with 0 m ean and stddev=1

Definition at line 821 of file multidim_array.cpp.

822 {
823  T* ptr=NULL;
824  size_t n;
825  if (mode == RND_UNIFORM)
827  *ptr = static_cast< T >(rnd_unif(op1, op2));
828  else if (mode == RND_GAUSSIAN)
830  *ptr = static_cast< T >(rnd_gaus(op1, op2));
831  else
833  formatString("InitRandom: Mode not supported"));
834 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
double rnd_unif()
void mode
double rnd_gaus()
String formatString(const char *format,...)
Incorrect value received.
Definition: xmipp_error.h:195
int * n

◆ initZeros() [1/6]

template<typename T>
template<typename T1 >
void MultidimArray< T >::initZeros ( const MultidimArray< T1 > &  op)
inline

Initialize to zeros following a pattern.

All values are set to 0, and the origin and size of the pattern are adopted.

v2.initZeros(v1);

Definition at line 2723 of file multidim_array.h.

2724  {
2725  if (data == NULL || !sameShape(op))
2726  resizeNoCopy(op);
2727  memset(data,0,nzyxdim*sizeof(T));
2728  }
void resizeNoCopy(const MultidimArray< T1 > &v)
bool sameShape(const MultidimArrayBase &op) const

◆ initZeros() [2/6]

template<typename T>
void MultidimArray< T >::initZeros ( )
inline

Initialize to zeros with current size.

All values are set to 0. The current size and origin are kept. It is not an error if the array is empty, then nothing is done.

v.initZeros();

Definition at line 2739 of file multidim_array.h.

2740  {
2741  memset(data,0,nzyxdim*sizeof(T));
2742  }

◆ initZeros() [3/6]

template<typename T>
void MultidimArray< T >::initZeros ( size_t  Ndim,
size_t  Zdim,
size_t  Ydim,
size_t  Xdim 
)
inline

Initialize to zeros with a given size.

Definition at line 2746 of file multidim_array.h.

2747  {
2748  if (xdim!=Xdim || ydim!=Ydim || zdim!=Zdim || ndim!=Ndim)
2749  resize(Ndim, Zdim,Ydim,Xdim,false);
2750  memset(data,0,nzyxdim*sizeof(T));
2751  }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)

◆ initZeros() [4/6]

template<typename T>
void MultidimArray< T >::initZeros ( int  Xdim)
inline

Initialize to zeros with a given size.

Definition at line 2755 of file multidim_array.h.

2756  {
2757  initZeros(1, 1, 1, Xdim);
2758  }

◆ initZeros() [5/6]

template<typename T>
void MultidimArray< T >::initZeros ( int  Ydim,
int  Xdim 
)
inline

Initialize to zeros with a given size.

Definition at line 2762 of file multidim_array.h.

2763  {
2764  initZeros(1, 1, Ydim, Xdim);
2765  }

◆ initZeros() [6/6]

template<typename T>
void MultidimArray< T >::initZeros ( int  Zdim,
int  Ydim,
int  Xdim 
)
inline

Initialize to zeros with a given size.

Definition at line 2769 of file multidim_array.h.

2770  {
2771  initZeros(1, Zdim, Ydim, Xdim);
2772  }

◆ interpolatedElement1D()

template<typename T>
T MultidimArray< T >::interpolatedElement1D ( double  x,
outside_value = (T) 0 
) const
inline

Interpolates the value of the nth 1D matrix M at the point (x)

Bilinear interpolation. (x) is in logical coordinates.

Definition at line 1425 of file multidim_array.h.

1426  {
1427  int x0 = floor(x);
1428  double fx = x - x0;
1429  int x1 = x0 + 1;
1430 
1431  int j0=STARTINGX(*this);
1432  int jF=FINISHINGX(*this);
1433 
1434 #define ASSIGNVAL1D(d,j) \
1435  if ((j) < j0 || (j) > jF) \
1436  d=outside_value;\
1437  else \
1438  d=A1D_ELEM(*this, j);
1439 
1440  double d0, d1;
1441  ASSIGNVAL1D(d0,x0);
1442  ASSIGNVAL1D(d1,x1);
1443 
1444  return (T) LIN_INTERP(fx, d0, d1);
1445  }
#define ASSIGNVAL1D(d, j)
__host__ __device__ float2 floor(const float2 v)
#define FINISHINGX(v)
#define STARTINGX(v)
doublereal * x
#define x0
double * d0
#define LIN_INTERP(a, l, h)
Definition: xmipp_macros.h:381

◆ interpolatedElement2D()

template<typename T>
T MultidimArray< T >::interpolatedElement2D ( double  x,
double  y,
outside_value = (T) 0 
) const
inline

Interpolates the value of the nth 2D matrix M at the point (x,y)

Bilinear interpolation. (x,y) are in logical coordinates.

Definition at line 1355 of file multidim_array.h.

1356  {
1357  int x0 = floor(x);
1358  double fx = x - x0;
1359  int x1 = x0 + 1;
1360  int y0 = floor(y);
1361  double fy = y - y0;
1362  int y1 = y0 + 1;
1363 
1364  int i0=STARTINGY(*this);
1365  int j0=STARTINGX(*this);
1366  int iF=FINISHINGY(*this);
1367  int jF=FINISHINGX(*this);
1368 
1369 #define ASSIGNVAL2D(d,i,j) \
1370  if ((j) < j0 || (j) > jF || (i) < i0 || (i) > iF) \
1371  d=outside_value;\
1372  else \
1373  d=A2D_ELEM(*this, i, j);
1374 
1375  double d00, d10, d11, d01;
1376  ASSIGNVAL2D(d00,y0,x0);
1377  ASSIGNVAL2D(d01,y0,x1);
1378  ASSIGNVAL2D(d10,y1,x0);
1379  ASSIGNVAL2D(d11,y1,x1);
1380 
1381  double d0 = LIN_INTERP(fx, d00, d01);
1382  double d1 = LIN_INTERP(fx, d10, d11);
1383  return (T) LIN_INTERP(fy, d0, d1);
1384  }
__host__ __device__ float2 floor(const float2 v)
#define FINISHINGX(v)
static double * y
#define STARTINGX(v)
doublereal * x
#define STARTINGY(v)
#define y0
#define x0
#define ASSIGNVAL2D(d, i, j)
double * d0
#define FINISHINGY(v)
#define LIN_INTERP(a, l, h)
Definition: xmipp_macros.h:381

◆ interpolatedElement2DOutsideZero()

template<typename T>
T MultidimArray< T >::interpolatedElement2DOutsideZero ( double  x,
double  y 
) const
inline

Non-divergent version of interpolatedElement2D

works only for outside_value = 0 does not break vectorization

Definition at line 1391 of file multidim_array.h.

1392  {
1393  int x0 = floor(x);
1394  double fx = x - x0;
1395  int x1 = x0 + 1;
1396  int y0 = floor(y);
1397  double fy = y - y0;
1398  int y1 = y0 + 1;
1399 
1400  int i0=STARTINGY(*this);
1401  int j0=STARTINGX(*this);
1402  int iF=FINISHINGY(*this);
1403  int jF=FINISHINGX(*this);
1404 
1405  int b;
1406 #define ASSIGNVAL2DNODIV(d,i,j) \
1407  b = ((j) < j0 || (j) > jF || (i) < i0 || (i) > iF); \
1408  b ? d=0 : d=A2D_ELEM(*this, i, j);
1409 
1410  double d00, d10, d11, d01;
1411  ASSIGNVAL2DNODIV(d00,y0,x0);
1412  ASSIGNVAL2DNODIV(d01,y0,x1);
1413  ASSIGNVAL2DNODIV(d10,y1,x0);
1414  ASSIGNVAL2DNODIV(d11,y1,x1);
1415 
1416  double d0 = LIN_INTERP(fx, d00, d01);
1417  double d1 = LIN_INTERP(fx, d10, d11);
1418  return (T) LIN_INTERP(fy, d0, d1);
1419  }
__host__ __device__ float2 floor(const float2 v)
#define FINISHINGX(v)
static double * y
#define STARTINGX(v)
doublereal * x
#define STARTINGY(v)
doublereal * b
#define y0
#define x0
double * d0
#define FINISHINGY(v)
#define ASSIGNVAL2DNODIV(d, i, j)
#define LIN_INTERP(a, l, h)
Definition: xmipp_macros.h:381

◆ interpolatedElement3D()

template<typename T>
T MultidimArray< T >::interpolatedElement3D ( double  x,
double  y,
double  z,
outside_value = (T) 0 
) const
inline

Interpolates the value of the nth 3D matrix M at the point (x,y,z).

(x,y,z) are in logical coordinates.

Definition at line 1317 of file multidim_array.h.

1318  {
1319  int x0 = FLOOR(x);
1320  double fx = x - x0;
1321  int x1 = x0 + 1;
1322 
1323  int y0 = FLOOR(y);
1324  double fy = y - y0;
1325  int y1 = y0 + 1;
1326 
1327  int z0 = FLOOR(z);
1328  double fz = z - z0;
1329  int z1 = z0 + 1;
1330 
1331  double doutside_value=outside_value;
1332  double d000 = (OUTSIDE3D(z0, y0, x0)) ? doutside_value : A3D_ELEM(*this, z0, y0, x0);
1333  double d001 = (OUTSIDE3D(z0, y0, x1)) ? doutside_value : A3D_ELEM(*this, z0, y0, x1);
1334  double d010 = (OUTSIDE3D(z0, y1, x0)) ? doutside_value : A3D_ELEM(*this, z0, y1, x0);
1335  double d011 = (OUTSIDE3D(z0, y1, x1)) ? doutside_value : A3D_ELEM(*this, z0, y1, x1);
1336  double d100 = (OUTSIDE3D(z1, y0, x0)) ? doutside_value : A3D_ELEM(*this, z1, y0, x0);
1337  double d101 = (OUTSIDE3D(z1, y0, x1)) ? doutside_value : A3D_ELEM(*this, z1, y0, x1);
1338  double d110 = (OUTSIDE3D(z1, y1, x0)) ? doutside_value : A3D_ELEM(*this, z1, y1, x0);
1339  double d111 = (OUTSIDE3D(z1, y1, x1)) ? doutside_value : A3D_ELEM(*this, z1, y1, x1);
1340 
1341  double dx00 = LIN_INTERP(fx, d000, d001);
1342  double dx01 = LIN_INTERP(fx, d100, d101);
1343  double dx10 = LIN_INTERP(fx, d010, d011);
1344  double dx11 = LIN_INTERP(fx, d110, d111);
1345  double dxy0 = LIN_INTERP(fy, dx00, dx10);
1346  double dxy1 = LIN_INTERP(fy, dx01, dx11);
1347 
1348  return (T) LIN_INTERP(fz, dxy0, dxy1);
1349  }
#define OUTSIDE3D(k, i, j)
static double * y
#define z0
doublereal * x
#define A3D_ELEM(V, k, i, j)
#define FLOOR(x)
Definition: xmipp_macros.h:240
#define y0
#define x0
double z
#define LIN_INTERP(a, l, h)
Definition: xmipp_macros.h:381

◆ interpolatedElementBSpline1D()

template<typename T >
T MultidimArray< T >::interpolatedElementBSpline1D ( double  x,
int  SplineDegree = 3 
) const

Interpolates the value of the nth 1D vector M at the point (x) knowing that this vector is a set of B-spline coefficients

(x) is in logical coordinates

To interpolate using splines you must first produce the Bspline coefficients. An example to interpolate a vector at (0.5) using splines would be:

MultidimArray< double > Bspline_coeffs;
myVector.produceSplineCoefficients(Bspline_coeffs, 3);
interpolated_value = Bspline_coeffs.interpolatedElementBSpline(0.5,3);

Definition at line 760 of file multidim_array.cpp.

761 {
762  int SplineDegree_1 = SplineDegree - 1;
763 
764  // Logical to physical
765  x -= STARTINGX(*this);
766 
767  int l1 = (int)ceil(x - SplineDegree_1);
768  int l2 = l1 + SplineDegree;
769  int Xdim=(int)XSIZE(*this);
770  double sum = 0.0;
771  for (int l = l1; l <= l2; l++)
772  {
773  double xminusl = x - (double) l;
774  int equivalent_l=l;
775  if (l<0)
776  equivalent_l=-l-1;
777  else if (l>=Xdim)
778  equivalent_l=2*Xdim-l-1;
779  double Coeff = (double) DIRECT_A1D_ELEM(*this, equivalent_l);
780  double aux;
781  switch (SplineDegree)
782  {
783  case 2:
784  sum += Coeff * Bspline02(xminusl);
785  break;
786 
787  case 3:
788  BSPLINE03(aux,xminusl);
789  sum += Coeff * aux;
790  break;
791 
792  case 4:
793  sum += Coeff * Bspline04(xminusl);
794  break;
795 
796  case 5:
797  sum += Coeff * Bspline05(xminusl);
798  break;
799 
800  case 6:
801  sum += Coeff * Bspline06(xminusl);
802  break;
803 
804  case 7:
805  sum += Coeff * Bspline07(xminusl);
806  break;
807 
808  case 8:
809  sum += Coeff * Bspline08(xminusl);
810  break;
811 
812  case 9:
813  sum += Coeff * Bspline09(xminusl);
814  break;
815  }
816  }
817  return (T) sum;
818 }
double Bspline05(double Argument)
#define STARTINGX(v)
doublereal * x
double Bspline04(double Argument)
#define DIRECT_A1D_ELEM(v, i)
#define XSIZE(v)
double Bspline07(double Argument)
double Bspline08(double Argument)
double Bspline02(double Argument)
double Bspline09(double Argument)
double Bspline06(double Argument)
double sum() const
#define BSPLINE03(y, x)
Definition: kernel.h:83

◆ interpolatedElementBSpline2D()

template<typename T >
T MultidimArray< T >::interpolatedElementBSpline2D ( double  x,
double  y,
int  SplineDegree = 3 
) const

Interpolates the value of the nth 2D matrix M at the point (x,y) knowing that this image is a set of B-spline coefficients

(x,y) are in logical coordinates

To interpolate using splines you must first produce the Bspline coefficients. An example to interpolate an image at (0.5,0.5) using splines would be:

MultidimArray< double > Bspline_coeffs;
myImage.produceSplineCoefficients(Bspline_coeffs, 3);
interpolated_value = Bspline_coeffs.interpolatedElementBSpline(0.5,
0.5,3);

Definition at line 570 of file multidim_array.cpp.

571 {
572  int SplineDegree_1 = SplineDegree - 1;
573 
574  // Logical to physical
575  y -= STARTINGY(*this);
576  x -= STARTINGX(*this);
577 
578  int l1 = (int)ceil(x - SplineDegree_1);
579  int l2 = l1 + SplineDegree;
580  int m1 = (int)ceil(y - SplineDegree_1);
581  int m2 = m1 + SplineDegree;
582 
583  double columns = 0.0;
584  double aux;
585  int Ydim=(int)YSIZE(*this);
586  int Xdim=(int)XSIZE(*this);
587  for (int m = m1; m <= m2; m++)
588  {
589  int equivalent_m=m;
590  if (m<0)
591  equivalent_m=-m-1;
592  else if (m>=Ydim)
593  equivalent_m=2*Ydim-m-1;
594  double rows = 0.0;
595  for (int l = l1; l <= l2; l++)
596  {
597  double xminusl = x - (double) l;
598  int equivalent_l=l;
599  if (l<0)
600  equivalent_l=-l-1;
601  else if (l>=Xdim)
602  equivalent_l=2*Xdim-l-1;
603  double Coeff = DIRECT_A2D_ELEM(*this, equivalent_m,equivalent_l);
604  switch (SplineDegree)
605  {
606  case 2:
607  rows += Coeff * Bspline02(xminusl);
608  break;
609 
610  case 3:
611  BSPLINE03(aux,xminusl);
612  rows += Coeff * aux;
613  break;
614 
615  case 4:
616  rows += Coeff * Bspline04(xminusl);
617  break;
618 
619  case 5:
620  rows += Coeff * Bspline05(xminusl);
621  break;
622 
623  case 6:
624  rows += Coeff * Bspline06(xminusl);
625  break;
626 
627  case 7:
628  rows += Coeff * Bspline07(xminusl);
629  break;
630 
631  case 8:
632  rows += Coeff * Bspline08(xminusl);
633  break;
634 
635  case 9:
636  rows += Coeff * Bspline09(xminusl);
637  break;
638  }
639  }
640 
641  double yminusm = y - (double) m;
642  switch (SplineDegree)
643  {
644  case 2:
645  columns += rows * Bspline02(yminusm);
646  break;
647 
648  case 3:
649  BSPLINE03(aux,yminusm);
650  columns += rows * aux;
651  break;
652 
653  case 4:
654  columns += rows * Bspline04(yminusm);
655  break;
656 
657  case 5:
658  columns += rows * Bspline05(yminusm);
659  break;
660 
661  case 6:
662  columns += rows * Bspline06(yminusm);
663  break;
664 
665  case 7:
666  columns += rows * Bspline07(yminusm);
667  break;
668 
669  case 8:
670  columns += rows * Bspline08(yminusm);
671  break;
672 
673  case 9:
674  columns += rows * Bspline09(yminusm);
675  break;
676  }
677  }
678  return (T) columns;
679 }
#define YSIZE(v)
double Bspline05(double Argument)
static double * y
#define DIRECT_A2D_ELEM(v, i, j)
#define STARTINGX(v)
doublereal * x
double Bspline04(double Argument)
#define STARTINGY(v)
#define XSIZE(v)
double Bspline07(double Argument)
double Bspline08(double Argument)
int m
double Bspline02(double Argument)
double Bspline09(double Argument)
double Bspline06(double Argument)
#define BSPLINE03(y, x)
Definition: kernel.h:83

◆ interpolatedElementBSpline2D_Degree3()

template<typename T >
T MultidimArray< T >::interpolatedElementBSpline2D_Degree3 ( double  x,
double  y 
) const

Definition at line 682 of file multidim_array.cpp.

683 {
684  bool firstTime=true; // Inner loop first time execution flag.
685  double *ref;
686 
687  // Logical to physical
688  y -= STARTINGY(*this);
689  x -= STARTINGX(*this);
690 
691  int l1 = (int)ceil(x - 2);
692  int l2 = l1 + 3;
693  int m1 = (int)ceil(y - 2);
694  int m2 = m1 + 3;
695 
696  double columns = 0.0;
697  double aux;
698  int Ydim=(int)YSIZE(*this);
699  int Xdim=(int)XSIZE(*this);
700 
701  int equivalent_l_Array[LOOKUP_TABLE_LEN]; // = new int [l2 - l1 + 1];
702  double aux_Array[LOOKUP_TABLE_LEN];// = new double [l2 - l1 + 1];
703 
704  for (int m = m1; m <= m2; m++)
705  {
706  int equivalent_m=m;
707  if (m<0)
708  equivalent_m=-m-1;
709  else if (m>=Ydim)
710  equivalent_m=2*Ydim-m-1;
711  double rows = 0.0;
712  int index=0;
713  ref = &DIRECT_A2D_ELEM(*this, equivalent_m,0);
714  for (int l = l1; l <= l2; l++)
715  {
716  int equivalent_l;
717  // Check if it is first time executing inner loop.
718  if (firstTime)
719  {
720  double xminusl = x - (double) l;
721  equivalent_l=l;
722  if (l<0)
723  {
724  equivalent_l=-l-1;
725  }
726  else if (l>=Xdim)
727  {
728  equivalent_l=2*Xdim-l-1;
729  }
730 
731  equivalent_l_Array[index] = equivalent_l;
732  BSPLINE03(aux,xminusl);
733  aux_Array[index] = aux;
734  index++;
735  }
736  else
737  {
738  equivalent_l = equivalent_l_Array[index];
739  aux = aux_Array[index];
740  index++;
741  }
742 
743  //double Coeff = DIRECT_A2D_ELEM(*this, equivalent_m,equivalent_l);
744  double Coeff = ref[equivalent_l];
745  rows += Coeff * aux;
746  }
747 
748  // Set first time inner flag is executed to false.
749  firstTime = false;
750 
751  double yminusm = y - (double) m;
752  BSPLINE03(aux,yminusm);
753  columns += rows * aux;
754  }
755 
756  return (T) columns;
757 }
#define YSIZE(v)
#define LOOKUP_TABLE_LEN
static double * y
#define DIRECT_A2D_ELEM(v, i, j)
#define STARTINGX(v)
doublereal * x
#define STARTINGY(v)
viol index
#define XSIZE(v)
int m
#define BSPLINE03(y, x)
Definition: kernel.h:83

◆ interpolatedElementBSpline3D()

template<typename T >
T MultidimArray< T >::interpolatedElementBSpline3D ( double  x,
double  y,
double  z,
int  SplineDegree = 3 
) const

Interpolates the value of the nth 3D matrix M at the point (x,y,z) knowing that this image is a set of B-spline coefficients.

(x,y,z) are in logical coordinates.

Definition at line 424 of file multidim_array.cpp.

426 {
427  int SplineDegree_1 = SplineDegree - 1;
428 
429  // Logical to physical
430  z -= STARTINGZ(*this);
431  y -= STARTINGY(*this);
432  x -= STARTINGX(*this);
433 
434  int l1 = (int)ceil(x - SplineDegree_1);
435  int l2 = l1 + SplineDegree;
436 
437  int m1 = (int)ceil(y - SplineDegree_1);
438  int m2 = m1 + SplineDegree;
439 
440  int n1 = (int)ceil(z - SplineDegree_1);
441  int n2 = n1 + SplineDegree;
442 
443  double zyxsum = 0.0;
444  double aux;
445  int Xdim=(int)XSIZE(*this);
446  int Ydim=(int)YSIZE(*this);
447  int Zdim=(int)ZSIZE(*this);
448  for (int nn = n1; nn <= n2; nn++)
449  {
450  int equivalent_nn=nn;
451  if (nn<0)
452  equivalent_nn=-nn-1;
453  else if (nn>=Zdim)
454  equivalent_nn=2*Zdim-nn-1;
455  double yxsum = 0.0;
456  for (int m = m1; m <= m2; m++)
457  {
458  int equivalent_m=m;
459  if (m<0)
460  equivalent_m=-m-1;
461  else if (m>=Ydim)
462  equivalent_m=2*Ydim-m-1;
463  double xsum = 0.0;
464  for (int l = l1; l <= l2; l++)
465  {
466  double xminusl = x - (double) l;
467  int equivalent_l=l;
468  if (l<0)
469  equivalent_l=-l-1;
470  else if (l>=Xdim)
471  equivalent_l=2*Xdim-l-1;
472  double Coeff = (double) DIRECT_A3D_ELEM(*this,
473  equivalent_nn,equivalent_m,equivalent_l);
474  switch (SplineDegree)
475  {
476  case 2:
477  xsum += Coeff * Bspline02(xminusl);
478  break;
479  case 3:
480  BSPLINE03(aux,xminusl);
481  xsum += Coeff * aux;
482  break;
483  case 4:
484  xsum += Coeff * Bspline04(xminusl);
485  break;
486  case 5:
487  xsum += Coeff * Bspline05(xminusl);
488  break;
489  case 6:
490  xsum += Coeff * Bspline06(xminusl);
491  break;
492  case 7:
493  xsum += Coeff * Bspline07(xminusl);
494  break;
495  case 8:
496  xsum += Coeff * Bspline08(xminusl);
497  break;
498  case 9:
499  xsum += Coeff * Bspline09(xminusl);
500  break;
501  }
502  }
503 
504  double yminusm = y - (double) m;
505  switch (SplineDegree)
506  {
507  case 2:
508  yxsum += xsum * Bspline02(yminusm);
509  break;
510  case 3:
511  BSPLINE03(aux,yminusm);
512  yxsum += xsum * aux;
513  break;
514  case 4:
515  yxsum += xsum * Bspline04(yminusm);
516  break;
517  case 5:
518  yxsum += xsum * Bspline05(yminusm);
519  break;
520  case 6:
521  yxsum += xsum * Bspline06(yminusm);
522  break;
523  case 7:
524  yxsum += xsum * Bspline07(yminusm);
525  break;
526  case 8:
527  yxsum += xsum * Bspline08(yminusm);
528  break;
529  case 9:
530  yxsum += xsum * Bspline09(yminusm);
531  break;
532  }
533  }
534 
535  double zminusn = z - (double) nn;
536  switch (SplineDegree)
537  {
538  case 2:
539  zyxsum += yxsum * Bspline02(zminusn);
540  break;
541  case 3:
542  BSPLINE03(aux,zminusn);
543  zyxsum += yxsum * aux;
544  break;
545  case 4:
546  zyxsum += yxsum * Bspline04(zminusn);
547  break;
548  case 5:
549  zyxsum += yxsum * Bspline05(zminusn);
550  break;
551  case 6:
552  zyxsum += yxsum * Bspline06(zminusn);
553  break;
554  case 7:
555  zyxsum += yxsum * Bspline07(zminusn);
556  break;
557  case 8:
558  zyxsum += yxsum * Bspline08(zminusn);
559  break;
560  case 9:
561  zyxsum += yxsum * Bspline09(zminusn);
562  break;
563  }
564  }
565 
566  return (T) zyxsum;
567 }
#define YSIZE(v)
double Bspline05(double Argument)
static double * y
#define STARTINGX(v)
doublereal * x
double Bspline04(double Argument)
#define STARTINGY(v)
#define XSIZE(v)
double Bspline07(double Argument)
#define ZSIZE(v)
double z
double Bspline08(double Argument)
#define DIRECT_A3D_ELEM(v, k, i, j)
int m
double Bspline02(double Argument)
double Bspline09(double Argument)
double Bspline06(double Argument)
#define STARTINGZ(v)
#define BSPLINE03(y, x)
Definition: kernel.h:83

◆ killAdaptationForNumericalRecipes1D()

template<typename T>
void MultidimArray< T >::killAdaptationForNumericalRecipes1D ( T *  m) const
inline

Kill a 1D array produced for Numerical Recipes.

Nothing needs to be done in fact.

This function is not ported to Python.

Definition at line 2987 of file multidim_array.h.

2988  {}

◆ killAdaptationForNumericalRecipes22D()

template<typename T>
void MultidimArray< T >::killAdaptationForNumericalRecipes22D ( T **  m) const
inline

Kill a 2D array produced for numerical recipes, 2.

Nothing needs to be done.

Definition at line 2964 of file multidim_array.h.

2965  {}

◆ killAdaptationForNumericalRecipes2D()

template<typename T>
void MultidimArray< T >::killAdaptationForNumericalRecipes2D ( T **  m) const
inline

Kill a 2D array produced for numerical recipes

The allocated memory is freed.

Definition at line 2955 of file multidim_array.h.

2956  {
2957  free_Tmatrix(m, 1, YSIZE(*this), 1, XSIZE(*this));
2958  }
#define YSIZE(v)
void free_Tmatrix(T **&m, int nrl, int nrh, int ncl, int nch)
Definition: xmipp_memory.h:61
#define XSIZE(v)
int m

◆ killAdaptationForNumericalRecipes3D()

template<typename T>
void MultidimArray< T >::killAdaptationForNumericalRecipes3D ( T ***  m) const
inline

Kill a 3D array produced for numerical recipes.

Definition at line 2907 of file multidim_array.h.

2908  {
2909  free_Tvolume(m, 1, ZSIZE(*this), 1, YSIZE(*this), 1, XSIZE(*this));
2910  }
#define YSIZE(v)
void free_Tvolume(T ***&m, int nsl, int nsh, int nrl, int nrh, int ncl, int nch)
Definition: xmipp_memory.h:106
#define XSIZE(v)
#define ZSIZE(v)
int m

◆ loadFromNumericalRecipes2D()

template<typename T>
void MultidimArray< T >::loadFromNumericalRecipes2D ( T **  m,
int  Ydim,
int  Xdim 
)
inline

Load 2D array from numerical recipes result.

Definition at line 2942 of file multidim_array.h.

2943  {
2944  resizeNoCopy(Ydim, Xdim);
2945 
2946  for (int i = 1; i <= Ydim; i++)
2947  for (int j = 1; j <= Xdim; j++)
2948  DIRECT_A2D_ELEM(*this,i - 1, j - 1) = m[i][j];
2949  }
void resizeNoCopy(const MultidimArray< T1 > &v)
#define DIRECT_A2D_ELEM(v, i, j)
#define i
#define j
int m

◆ maxIndex() [1/2]

template<typename T>
void MultidimArray< T >::maxIndex ( int &  jmax) const
inline

1D Indices for the maximum element.

This function just calls to the 4D function

Definition at line 1557 of file multidim_array.h.

1558  {
1559  size_t zeroLong=0;
1560  int zeroInt=0;
1561  maxIndex(zeroLong,zeroInt,zeroInt,jmax);
1562  }
void maxIndex(int &jmax) const

◆ maxIndex() [2/2]

template<typename T>
void MultidimArray< T >::maxIndex ( size_t &  lmax,
int &  kmax,
int &  imax,
int &  jmax 
) const
inlinevirtual

4D Indices for the maximum element.

This function returns the index of the maximum element of an array. array(l,k,i,j). Returns -1 if the array is empty

Implements MultidimArrayBase.

Definition at line 1654 of file multidim_array.h.

1655  {
1656  if (XSIZE(*this) == 0)
1657  {
1658  lmax = kmax = imax = jmax = -1;
1659  return;
1660  }
1661 
1662  kmax = STARTINGZ(*this);
1663  imax = STARTINGY(*this);
1664  jmax = STARTINGX(*this);
1665  lmax = 0;
1666  size_t n=0;
1667  T maxval = DIRECT_MULTIDIM_ELEM(*this, n);
1668 
1670  {
1671  T val=DIRECT_MULTIDIM_ELEM(*this, n);
1672  if (val > maxval)
1673  {
1674  maxval = val;
1675  lmax = l;
1676  kmax = k;
1677  imax = i;
1678  jmax = j;
1679  }
1680  ++n;
1681  }
1682  }
#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 XSIZE(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
#define j
#define STARTINGZ(v)
int * n
#define FOR_ALL_NZYX_ELEMENTS_IN_MULTIDIMARRAY(V)

◆ minIndex() [1/4]

template<typename T>
void MultidimArray< T >::minIndex ( int &  lmin,
int &  kmin,
int &  imin,
int &  jmin 
) const
inline

4D Indices for the minimum element.

This function returns the index of the minimum element of an array. array(l,k,i,j). Returns -1 if the array is empty

Definition at line 1589 of file multidim_array.h.

1590  {
1591  if (XSIZE(*this) == 0)
1592  {
1593  lmin = kmin = imin = jmin = -1;
1594  return;
1595  }
1596 
1597  kmin = STARTINGZ(*this);
1598  imin = STARTINGY(*this);
1599  jmin = STARTINGX(*this);
1600  lmin = 0;
1601  size_t n=0;
1602  T minval = DIRECT_MULTIDIM_ELEM(*this, n);
1603 
1605  {
1606  T val=DIRECT_MULTIDIM_ELEM(*this,n);
1607  if (val > minval)
1608  {
1609  minval = val;
1610  lmin = l;
1611  kmin = k;
1612  imin = i;
1613  jmin = j;
1614  }
1615  ++n;
1616  }
1617  }
#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 XSIZE(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
#define j
#define STARTINGZ(v)
int * n
#define FOR_ALL_NZYX_ELEMENTS_IN_MULTIDIMARRAY(V)

◆ minIndex() [2/4]

template<typename T>
void MultidimArray< T >::minIndex ( int &  kmin,
int &  imin,
int &  jmin 
) const
inline

3D Indices for the minimum element.

This function just calls to the 4D function

Definition at line 1623 of file multidim_array.h.

1624  {
1625  int zeroInt=0;
1626  minIndex(zeroInt,kmin,imin,jmin);
1627  }
void minIndex(int &lmin, int &kmin, int &imin, int &jmin) const

◆ minIndex() [3/4]

template<typename T>
void MultidimArray< T >::minIndex ( int &  imin,
int &  jmin 
) const
inline

2D Indices for the minimum element.

This function just calls to the 4D function

Definition at line 1633 of file multidim_array.h.

1634  {
1635  int zeroInt=0;
1636  minIndex(zeroInt,zeroInt,imin,jmin);
1637  }
void minIndex(int &lmin, int &kmin, int &imin, int &jmin) const

◆ minIndex() [4/4]

template<typename T>
void MultidimArray< T >::minIndex ( int &  jmin) const
inline

1D Indices for the minimum element.

This function just calls to the 4D function

Definition at line 1643 of file multidim_array.h.

1644  {
1645  int zeroInt=0;
1646  minIndex(zeroInt,zeroInt,zeroInt,jmin);
1647  }
void minIndex(int &lmin, int &kmin, int &imin, int &jmin) const

◆ mmapFile()

template<typename T>
template FILE * MultidimArray< T >::mmapFile ( T *&  _data,
size_t  nzyxDim 
) const

Definition at line 859 of file multidim_array.cpp.

860 {
861 #ifdef XMIPP_MMAP
862  FILE* fMap = tmpfile();
863  int Fd = fileno(fMap);
864 
865  if ((lseek(Fd, nzyxDim*sizeof(T)-1, SEEK_SET) == -1) || (::write(Fd,"",1) == -1))
866  {
867  fclose(fMap);
868  REPORT_ERROR(ERR_IO_NOWRITE,"MultidimArray::resize: Error 'stretching' the map file.");
869  }
870  if ( (_data = (T*) mmap(0,nzyxDim*sizeof(T), PROT_READ | PROT_WRITE, MAP_SHARED, Fd, 0)) == (void*) MAP_FAILED )
871  REPORT_ERROR(ERR_MMAP_NOTADDR,formatString("MultidimArray::resize: mmap failed. Error %s", strerror(errno)));
872 
873  return fMap;
874 #else
875 
876  REPORT_ERROR(ERR_MMAP,"Mapping not supported in Windows");
877 #endif
878 
879 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Global mmap error.
Definition: xmipp_error.h:170
Couldn&#39;t write to file.
Definition: xmipp_error.h:140
Map addressing of file has failed.
Definition: xmipp_error.h:171
void write(const FileName &fn) const
String formatString(const char *format,...)

◆ operator()() [1/6]

template<typename T>
T& MultidimArray< T >::operator() ( const Matrix1D< double > &  v) const
inline

Volume element access via double vector.

Returns the value of a matrix logical position, but this time the element position is determined by a R3 vector. The elements can be used either by value or by reference. An exception is thrown if the index is outside the logical range. Pay attention in the following example that we are accessing the same element as in the previous function but, now we have to give first the X position because we are building first a vector of the form (x,y,z).

V(vectorR3(1, -2, 0)) = 1;
val = V(vectorR3(1, -2, 0));

Definition at line 755 of file multidim_array.h.

756  {
757  switch (VEC_XSIZE(v))
758  {
759  case 1:
760  return A1D_ELEM((*this), ROUND(XX(v)));
761  case 2:
762  return A2D_ELEM((*this), ROUND(YY(v)), ROUND(XX(v)));
763  case 3:
764  return A3D_ELEM((*this), ROUND(ZZ(v)), ROUND(YY(v)), ROUND(XX(v)));
765  default:
766  REPORT_ERROR(ERR_ARG_INCORRECT,"Cannot handle indexes with dimension larger than 3");
767  }
768  }
#define A2D_ELEM(v, i, j)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
#define A1D_ELEM(v, i)
#define A3D_ELEM(V, k, i, j)
#define XX(v)
Definition: matrix1d.h:85
Incorrect argument received.
Definition: xmipp_error.h:113
#define ROUND(x)
Definition: xmipp_macros.h:210
#define YY(v)
Definition: matrix1d.h:93
#define ZZ(v)
Definition: matrix1d.h:101

◆ operator()() [2/6]

template<typename T>
T& MultidimArray< T >::operator() ( const Matrix1D< int > &  v) const
inline

Volume element access via integer vector.

Definition at line 772 of file multidim_array.h.

773  {
774  switch (VEC_XSIZE(v))
775  {
776  case 1:
777  return A1D_ELEM((*this), XX(v));
778  case 2:
779  return A2D_ELEM((*this), YY(v), XX(v));
780  case 3:
781  return A3D_ELEM((*this), ZZ(v), YY(v), XX(v));
782  default:
783  REPORT_ERROR(ERR_ARG_INCORRECT,"Cannot handle indexes with dimension larger than 3");
784  }
785  }
#define A2D_ELEM(v, i, j)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
#define A1D_ELEM(v, i)
#define A3D_ELEM(V, k, i, j)
#define XX(v)
Definition: matrix1d.h:85
Incorrect argument received.
Definition: xmipp_error.h:113
#define YY(v)
Definition: matrix1d.h:93
#define ZZ(v)
Definition: matrix1d.h:101

◆ operator()() [3/6]

template<typename T>
T& MultidimArray< T >::operator() ( size_t  n,
int  k,
int  i,
int  j 
) const
inline

4D element access via index.

Returns the value of a matrix logical position. In our example we could access from v(0, 0,-2,-1) to v(0, 1,2,1). The elements can be used either by value or by reference. An exception is thrown if the index is outside the logical range. Be careful that the argument order is (Z,Y,X).

V(0, 0, -2, 1) = 1;
val = V(0, 0, -2, 1);

Definition at line 799 of file multidim_array.h.

800  {
801  return NZYX_ELEM(*this, n, k, i, j);
802  }
#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 NZYX_ELEM(v, l, k, i, j)
#define j
int * n

◆ operator()() [4/6]

template<typename T>
T& MultidimArray< T >::operator() ( int  k,
int  i,
int  j 
) const
inline

3D element access via index.

Returns the value of a matrix logical position. In our example we could access from v(0,-2,-1) to v(1,2,1). The elements can be used either by value or by reference. An exception is thrown if the index is outside the logical range. Be careful that the argument order is (Z,Y,X).

V(0, -2, 1) = 1;
val = V(0, -2, 1);

Definition at line 816 of file multidim_array.h.

817  {
818  return A3D_ELEM(*this, k, i, j);
819  }
#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 A3D_ELEM(V, k, i, j)
#define j

◆ operator()() [5/6]

template<typename T>
T& MultidimArray< T >::operator() ( int  i,
int  j 
) const
inline

Matrix element access via index

Returns the value of a matrix logical position. In our example we could access from v(-2,-1) to v(2,1). The elements can be used either by value or by reference. An exception is thrown if the index is outside the logical range. The first argument is the Y position and the second the X position.

m(-2, 1) = 1;
val = m(-2, 1);

Definition at line 834 of file multidim_array.h.

835  {
836  return A2D_ELEM(*this, i, j);
837  }
#define A2D_ELEM(v, i, j)
#define i
#define j

◆ operator()() [6/6]

template<typename T>
T& MultidimArray< T >::operator() ( int  i) const
inline

Vector element access

Returns the value of a vector logical position. In our example we could access from v(-2) to v(2). The elements can be used either by value or by reference. An exception is thrown if the index is outside the logical range.

v(-2) = 1;
val = v(-2);

Definition at line 851 of file multidim_array.h.

852  {
853  return A1D_ELEM(*this, i);
854  }
#define A1D_ELEM(v, i)
#define i

◆ operator*() [1/2]

template<typename T>
MultidimArray<T> MultidimArray< T >::operator* ( const MultidimArray< T > &  op1) const
inline

v3 = v1 * v2.

Definition at line 2360 of file multidim_array.h.

2361  {
2362  MultidimArray<T> tmp;
2363  arrayByArray(*this, op1, tmp, '*');
2364  return tmp;
2365  }
friend void arrayByArray(const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)

◆ operator*() [2/2]

template<typename T>
MultidimArray<T> MultidimArray< T >::operator* ( op1) const
inline

v3 = v1 * k.

Definition at line 2526 of file multidim_array.h.

2527  {
2528  MultidimArray<T> tmp;
2529  arrayByScalar(*this, op1, tmp, '*');
2530  return tmp;
2531  }
friend void arrayByScalar(const MultidimArray< T > &op1, T op2, MultidimArray< T > &result, char operation)

◆ operator*=() [1/2]

template<typename T>
void MultidimArray< T >::operator*= ( const MultidimArray< T > &  op1)
inline

v3 *= v2.

Definition at line 2392 of file multidim_array.h.

2393  {
2394  arrayByArray(*this, op1, *this, '*');
2395  }
friend void arrayByArray(const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)

◆ operator*=() [2/2]

template<typename T>
void MultidimArray< T >::operator*= ( const T &  op1)
inline

v3 *= k.

This function is not ported to Python.

Definition at line 2574 of file multidim_array.h.

2575  {
2576  arrayByScalar(*this, op1, *this, '*');
2577  }
friend void arrayByScalar(const MultidimArray< T > &op1, T op2, MultidimArray< T > &result, char operation)

◆ operator+() [1/2]

template<typename T>
MultidimArray<T> MultidimArray< T >::operator+ ( const MultidimArray< T > &  op1) const
inline

v3 = v1 + v2.

Definition at line 2342 of file multidim_array.h.

2343  {
2344  MultidimArray<T> tmp;
2345  arrayByArray(*this, op1, tmp, '+');
2346  return tmp;
2347  }
friend void arrayByArray(const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)

◆ operator+() [2/2]

template<typename T>
MultidimArray<T> MultidimArray< T >::operator+ ( op1) const
inline

v3 = v1 + k.

Definition at line 2508 of file multidim_array.h.

2509  {
2510  MultidimArray<T> tmp;
2511  arrayByScalar(*this, op1, tmp, '+');
2512  return tmp;
2513  }
friend void arrayByScalar(const MultidimArray< T > &op1, T op2, MultidimArray< T > &result, char operation)

◆ operator+=() [1/2]

template<typename T>
void MultidimArray< T >::operator+= ( const MultidimArray< T > &  op1)
inline

v3 += v2.

Definition at line 2378 of file multidim_array.h.

2379  {
2380  arrayByArray(*this, op1, *this, '+');
2381  }
friend void arrayByArray(const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)

◆ operator+=() [2/2]

template<typename T>
void MultidimArray< T >::operator+= ( const T &  op1)
inline

v3 += k.

This function is not ported to Python.

Definition at line 2556 of file multidim_array.h.

2557  {
2558  arrayByScalar(*this, op1, *this, '+');
2559  }
friend void arrayByScalar(const MultidimArray< T > &op1, T op2, MultidimArray< T > &result, char operation)

◆ operator-() [1/3]

template<typename T>
MultidimArray<T> MultidimArray< T >::operator- ( const MultidimArray< T > &  op1) const
inline

v3 = v1 - v2.

Definition at line 2351 of file multidim_array.h.

2352  {
2353  MultidimArray<T> tmp;
2354  arrayByArray(*this, op1, tmp, '-');
2355  return tmp;
2356  }
friend void arrayByArray(const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)

◆ operator-() [2/3]

template<typename T>
MultidimArray<T> MultidimArray< T >::operator- ( op1) const
inline

v3 = v1 - k.

Definition at line 2517 of file multidim_array.h.

2518  {
2519  MultidimArray<T> tmp;
2520  arrayByScalar(*this, op1, tmp, '-');
2521  return tmp;
2522  }
friend void arrayByScalar(const MultidimArray< T > &op1, T op2, MultidimArray< T > &result, char operation)

◆ operator-() [3/3]

template<typename T>
MultidimArray<T> MultidimArray< T >::operator- ( void  ) const
inline

Unary minus.

It is used to build arithmetic expressions. You can make a minus of anything as long as it is correct semantically.

v1 = -v2;
v1 = -v2.transpose();

Definition at line 3684 of file multidim_array.h.

3685  {
3686  MultidimArray<T> tmp(*this);
3687  T* ptr;
3688  size_t n;
3690  *ptr = -(*ptr);
3691  return tmp;
3692  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
int * n

◆ operator-=() [1/2]

template<typename T>
void MultidimArray< T >::operator-= ( const MultidimArray< T > &  op1)
inline

v3 -= v2.

Definition at line 2385 of file multidim_array.h.

2386  {
2387  arrayByArray(*this, op1, *this, '-');
2388  }
friend void arrayByArray(const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)

◆ operator-=() [2/2]

template<typename T>
void MultidimArray< T >::operator-= ( const T &  op1)
inline

v3 -= k.

This function is not ported to Python.

Definition at line 2565 of file multidim_array.h.

2566  {
2567  arrayByScalar(*this, op1, *this, '-');
2568  }
friend void arrayByScalar(const MultidimArray< T > &op1, T op2, MultidimArray< T > &result, char operation)

◆ operator/() [1/2]

template<typename T>
MultidimArray<T> MultidimArray< T >::operator/ ( const MultidimArray< T > &  op1) const
inline

v3 = v1 / v2.

Definition at line 2369 of file multidim_array.h.

2370  {
2371  MultidimArray<T> tmp;
2372  arrayByArray(*this, op1, tmp, '/');
2373  return tmp;
2374  }
friend void arrayByArray(const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)

◆ operator/() [2/2]

template<typename T>
MultidimArray<T> MultidimArray< T >::operator/ ( op1) const
inline

v3 = v1 / k.

Definition at line 2535 of file multidim_array.h.

2536  {
2537  MultidimArray<T> tmp;
2538  arrayByScalar(*this, op1, tmp, '/');
2539  return tmp;
2540  }
friend void arrayByScalar(const MultidimArray< T > &op1, T op2, MultidimArray< T > &result, char operation)

◆ operator/=() [1/2]

template<typename T>
void MultidimArray< T >::operator/= ( const MultidimArray< T > &  op1)
inline

v3 /= v2.

Definition at line 2399 of file multidim_array.h.

2400  {
2401  arrayByArray(*this, op1, *this, '/');
2402  }
friend void arrayByArray(const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)

◆ operator/=() [2/2]

template<typename T>
void MultidimArray< T >::operator/= ( const T &  op1)
inline

v3 /= k.

This function is not ported to Python.

Definition at line 2583 of file multidim_array.h.

2584  {
2585  arrayByScalar(*this, op1, *this, '/');
2586  }
friend void arrayByScalar(const MultidimArray< T > &op1, T op2, MultidimArray< T > &result, char operation)

◆ operator=() [1/3]

template<typename T>
MultidimArray<T>& MultidimArray< T >::operator= ( const MultidimArray< T > &  op1)
inline

Assignment.

You can build as complex assignment expressions as you like. Multiple assignment is allowed.

v1 = v2 + v3;
v1 = v2 = v3;

This function is ported to Python as assign.

Definition at line 3628 of file multidim_array.h.

3629  {
3630  if (&op1 != this)
3631  {
3632  if (data == NULL || !sameShape(op1))
3633  resizeNoCopy(op1);
3634  memcpy(data,op1.data,MULTIDIM_SIZE(op1)*sizeof(T));
3635  }
3636  return *this;
3637  }
#define MULTIDIM_SIZE(v)
void resizeNoCopy(const MultidimArray< T1 > &v)
bool sameShape(const MultidimArrayBase &op) const

◆ operator=() [2/3]

template<typename T>
MultidimArray<T>& MultidimArray< T >::operator= ( MultidimArray< T > &&  other)
inlinenoexcept

Move assignment.

You can build as complex assignment expressions as you like. Multiple assignment is allowed.

v1 = v2 + v3;
v1 = v2 = v3;

Definition at line 3649 of file multidim_array.h.

3650  {
3651  if (&other != this)
3652  {
3653  coreDeallocate();
3654  coreInit();
3655  swap(other);
3656  }
3657  return *this;
3658  }
void coreDeallocate() noexcept
void swap(MultidimArray< T > &other) noexcept
void coreInit() noexcept

◆ operator=() [3/3]

template<typename T>
MultidimArray< T > & MultidimArray< T >::operator= ( const Matrix2D< T > &  op1)

Assignment.

You can build as complex assignment expressions as you like. Multiple assignment is allowed.

v1 = v2 + v3;
v1 = v2 = v3;

This function is ported to Python as assign.

Definition at line 47 of file multidim_array.cpp.

48 {
49  resizeNoCopy(MAT_YSIZE(op1), MAT_XSIZE(op1));
50  memcpy(data,MATRIX2D_ARRAY(op1), MAT_SIZE(op1)*sizeof(T));
51 
52  return *this;
53 }
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
#define MAT_SIZE(m)
Definition: matrix2d.h:128
void resizeNoCopy(const MultidimArray< T1 > &v)
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
#define MATRIX2D_ARRAY(m)
Definition: matrix2d.h:89

◆ operator[]()

template<typename T>
T& MultidimArray< T >::operator[] ( size_t  i) const
inline

Definition at line 856 of file multidim_array.h.

857  {
858  return data[i];
859  }
#define i

◆ patch()

template<typename T>
void MultidimArray< T >::patch ( MultidimArray< T >  patchArray,
int  x,
int  y 
)
inline

Make a patch with the input array in the given positions

Definition at line 727 of file multidim_array.h.

728  {
729  int n = XSIZE(patchArray)*sizeof(T);
730 
731  for (size_t i=0; i < YSIZE(patchArray); ++i)
732  memcpy(&dAij(*this, y+i, x), &dAij(patchArray, i, 0), n);
733  }
#define YSIZE(v)
#define dAij(M, i, j)
static double * y
doublereal * x
#define i
#define XSIZE(v)
int * n

◆ printStats()

template<typename T>
void MultidimArray< T >::printStats ( std::ostream &  out = std::cout) const
inline

Print statistics in current line.

No end of line character is written after this print out.

a.computeStats();
std::cout << "Statistics of variable a ";
a.printStats();
std::cout << std::endl;

Definition at line 1507 of file multidim_array.h.

1508  {
1509  T minval, maxval;
1510  double avgval, devval;
1511 
1512  computeStats(avgval, devval, minval, maxval);
1513 
1514  out.setf(std::ios::showpoint);
1515  int old_prec = out.precision(7);
1516 
1517  out << " min= ";
1518  out.width(9);
1519  out << minval;
1520  out << " max= ";
1521  out.width(9);
1522  out << maxval;
1523  out << " avg= ";
1524  out.width(9);
1525  out << avgval;
1526  out << " dev= ";
1527  out.width(9);
1528  out << devval;
1529 
1530  out.precision(old_prec);
1531  }
void computeStats(double &avg, double &stddev, T &minval, T &maxval) const

◆ profile()

template<typename T>
void MultidimArray< T >::profile ( int  x0,
int  y0,
int  xF,
int  yF,
int  N,
MultidimArray< double > &  profile 
) const
inline

Extracts the 1D profile between two points in a 2D array

Given two logical indexes, this function returns samples of the line that joins them. This is done by bilinear interpolation. The number of samples in the line is N.

Definition at line 3576 of file multidim_array.h.

3578  {
3579  checkDimension(2);
3580  profile.initZeros(N);
3581  double tx_step = (double)(xF - x0) / (N - 1);
3582  double ty_step = (double)(yF - y0) / (N - 1);
3583  double tx = x0, ty = y0;
3584 
3585  for (int i = 0; i < N; i++)
3586  {
3587  profile(i) = interpolatedElement2D(tx, ty);
3588  tx += tx_step;
3589  ty += ty_step;
3590  }
3591  }
#define i
T interpolatedElement2D(double x, double y, T outside_value=(T) 0) const
#define checkDimension(dim)
#define y0
#define x0
void profile(int x0, int y0, int xF, int yF, int N, MultidimArray< double > &profile) const
#define xF
void initZeros(const MultidimArray< T1 > &op)
#define yF

◆ randomSubstitute()

template<typename T>
void MultidimArray< T >::randomSubstitute ( oldv,
avgv,
sigv,
double  accuracy = XMIPP_EQUAL_ACCURACY,
MultidimArray< int > *  mask = NULL 
)

Substitute a given value by a sample from a Gaussian distribution.

Substitute a given value by a sample from a Gaussian distribution. The accuracy is used to say if the value in the array is equal to the old value. Set it to 0 for perfect accuracy.

Definition at line 1120 of file multidim_array.cpp.

1125 {
1126  T* ptr=NULL;
1127  size_t n;
1129  if (mask == NULL || DIRECT_MULTIDIM_ELEM(*mask,n) > 0 )
1130  if (ABS(*ptr - oldv) <= accuracy)
1131  *ptr = rnd_gaus(avgv, sigv);
1132 }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define ABS(x)
Definition: xmipp_macros.h:142
#define DIRECT_MULTIDIM_ELEM(v, n)
double rnd_gaus()
int * n

◆ rangeAdjust() [1/3]

template<typename T>
void MultidimArray< T >::rangeAdjust ( minF,
maxF 
)
inline

Adjust the range of the array to a given one.

A linear operation is performed on the values of the array such that after it, the values of the array are comprissed between the two values set. The actual array is modified itself

v.rangeAdjust(0, 1);
// The array is now ranging from 0 to 1

Definition at line 1982 of file multidim_array.h.

1983  {
1984  if (NZYXSIZE(*this) <= 0)
1985  return;
1986 
1987  double min0=0., max0=0.;
1988  computeDoubleMinMax(min0, max0);
1989 
1990  // If max0==min0, it means that the vector is a constant one, so the
1991  // only possible transformation is to a fixed minF
1992  double slope;
1993  if (max0 != min0)
1994  slope = static_cast< double >(maxF - minF) /
1995  static_cast< double >(max0 - min0);
1996  else
1997  slope = 0;
1998 
1999  T* ptr=NULL;
2000  size_t n;
2002  *ptr = minF + static_cast< T >(slope *
2003  static_cast< double >(*ptr - min0));
2004  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
void computeDoubleMinMax(double &minval, double &maxval) const
#define NZYXSIZE(v)
int * n

◆ rangeAdjust() [2/3]

template<typename T>
void MultidimArray< T >::rangeAdjust ( minF,
maxF,
MultidimArray< int > &  mask 
)
inline

Adjust the range of the array to a given one within a mask.

A linear operation is performed on the values of the array such that after it, the values of the array are comprissed between the two values set. The actual array is modified itself. The linear transformation is computed within the mask, but it is applied everywhere.

v.rangeAdjust(0, 1, mask);
// The array is now ranging from 0 to 1

Definition at line 2019 of file multidim_array.h.

2020  {
2021  if (MULTIDIM_SIZE(*this) <= 0)
2022  return;
2023 
2024  double min0=0., max0=0.;
2025  bool first=true;
2026  T* ptr=NULL;
2027  size_t n;
2028  int * ptrMask=MULTIDIM_ARRAY(mask);
2030  {
2031  if (*ptrMask)
2032  {
2033  T val= *ptr;
2034  if (first)
2035  {
2036  min0=max0=(double)val;
2037  first=false;
2038  }
2039  else
2040  {
2041  min0=XMIPP_MIN(min0,val);
2042  max0=XMIPP_MAX(max0,val);
2043  }
2044  }
2045  ptrMask++;
2046  }
2047 
2048  // If max0==min0, it means that the vector is a constant one, so the
2049  // only possible transformation is to a fixed minF
2050  double slope;
2051  if (max0 != min0)
2052  slope = static_cast< double >(maxF - minF) /
2053  static_cast< double >(max0 - min0);
2054  else
2055  slope = 0;
2056 
2058  *ptr = minF + static_cast< T >(slope *
2059  static_cast< double >(*ptr - min0));
2060  }
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
#define MULTIDIM_SIZE(v)
#define MULTIDIM_ARRAY(v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
glob_log first
#define XMIPP_MIN(x, y)
Definition: xmipp_macros.h:181
int * n

◆ rangeAdjust() [3/3]

template<typename T>
void MultidimArray< T >::rangeAdjust ( const MultidimArray< T > &  example,
const MultidimArray< int > *  mask = NULL 
)
inline

Adjust the range of the array to the range of another array in a least squares sense.

A linear operation is performed on the values of the array such that after it, the values of the self array are as similar as possible (L2 sense) to the values of the array shown as sample

Definition at line 2073 of file multidim_array.h.

2075  {
2076  if (NZYXSIZE(*this) <= 0)
2077  return;
2078 
2079  double avgExample=0., stddevExample=0., avgThis, stddevThis;
2080  if (mask!=NULL)
2081  {
2082  example.computeAvgStdev_within_binary_mask(*mask,avgExample,stddevExample);
2083  computeAvgStdev_within_binary_mask(*mask,avgThis,stddevThis);
2084  }
2085  else
2086  {
2087  computeAvgStdev(avgThis,stddevThis);
2088  example.computeAvgStdev(avgExample,stddevExample);
2089  }
2090 
2091  // y=a+bx
2092  double b=stddevThis>0? stddevExample/stddevThis:0;
2093  double a=avgExample-avgThis*b;
2094 
2095  size_t n;
2096  T *ptr=NULL;
2098  *ptr = static_cast< T >(a+b * static_cast< double > (*ptr));
2099  }
void computeAvgStdev(U &avg, U &stddev) const
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
void computeAvgStdev_within_binary_mask(const MultidimArray< int > &mask, double &avg, double &stddev) const
doublereal * b
#define NZYXSIZE(v)
int * n
doublereal * a

◆ resize() [1/2]

template<typename T >
void MultidimArray< T >::resize ( size_t  Ndim,
size_t  Zdim,
size_t  Ydim,
size_t  Xdim,
bool  copy = true 
)
virtual

Resize to a given size

This function resize the actual array to the given size. The origin is not modified. If the actual array is larger than the pattern then the values outside the new size are lost, if it is smaller then 0's are added. An exception is thrown if there is no memory.

V1.resize(3, 3, 2);

Implements MultidimArrayBase.

Definition at line 983 of file multidim_array.cpp.

984 {
985  if (Ndim*Zdim*Ydim*Xdim == nzyxdimAlloc && data != NULL)
986  {
987  ndim = Ndim;
988  xdim = Xdim;
989  ydim = Ydim;
990  zdim = Zdim;
991  yxdim = Ydim * Xdim;
992  zyxdim = Zdim * yxdim;
993  nzyxdim = Ndim * zyxdim;
994  return;
995  }
996  else if (!destroyData)
997  REPORT_ERROR(ERR_MULTIDIM_SIZE, "Cannot resize array when accessing through alias.");
998 
999  if (Xdim <= 0 || Ydim <= 0 || Zdim <= 0 || Ndim <= 0)
1000  {
1001  clear();
1002  return;
1003  }
1004 
1005  // data can be NULL while xdim etc are set to non-zero values
1006  // (This can happen for reading of images...)
1007  // In that case, initialize data to zeros.
1008  if (NZYXSIZE(*this) > 0 && data == NULL)
1009  {
1010  ndim = Ndim;
1011  xdim = Xdim;
1012  ydim = Ydim;
1013  zdim = Zdim;
1014  yxdim = Ydim * Xdim;
1015  zyxdim = Zdim * yxdim;
1016  nzyxdim = Ndim * zyxdim;
1017 
1018  coreAllocate();
1019  return;
1020  }
1021 
1022  // Ask for memory
1023  size_t YXdim=(size_t)Ydim*Xdim;
1024  size_t ZYXdim=YXdim*Zdim;
1025  size_t NZYXdim=ZYXdim*Ndim;
1026  FILE* new_mFd=NULL;
1027 
1028  T * new_data=NULL;
1029 
1030  try
1031  {
1032  if (mmapOn)
1033  new_mFd = mmapFile(new_data, NZYXdim);
1034  else
1035  new_data = new T [NZYXdim];
1036 
1037  memset(new_data,0,NZYXdim*sizeof(T));
1038  }
1039  catch (std::bad_alloc &)
1040  {
1041  if (!mmapOn)
1042  {
1043  setMmap(true);
1044  resize(Ndim, Zdim, Ydim, Xdim, copy);
1045  return;
1046  }
1047  else
1048  {
1049  std::ostringstream sstream;
1050  sstream << "Allocate: No space left to allocate ";
1051  sstream << (NZYXdim * sizeof(T)/1024/1024/1024) ;
1052  sstream << "Gb." ;
1053  REPORT_ERROR(ERR_MEM_NOTENOUGH, sstream.str());
1054  }
1055  }
1056  // Copy needed elements, fill with 0 if necessary
1057  if (copy)
1058  {
1059  const auto nCopy = std::min(Ndim, NSIZE(*this));
1060  const auto zCopy = std::min(Zdim, ZSIZE(*this));
1061  const auto yCopy = std::min(Ydim, YSIZE(*this));
1062  const auto xCopy = std::min(Xdim, XSIZE(*this));
1063  const auto xCopyBytes = xCopy*sizeof(T);
1064 
1065  for (size_t l = 0; l < nCopy; ++l)
1066  for (size_t k = 0; k < zCopy; ++k)
1067  for (size_t i = 0; i < yCopy; ++i)
1068  memcpy(
1069  new_data + l*ZYXdim + k*YXdim + i*Xdim,
1070  data + l*zyxdim + k*yxdim + i*xdim,
1071  xCopyBytes
1072  );
1073  }
1074 
1075  // deallocate old array
1076  coreDeallocate();
1077 
1078  // assign *this vector to the newly created
1079  data = new_data;
1080  ndim = Ndim;
1081  xdim = Xdim;
1082  ydim = Ydim;
1083  zdim = Zdim;
1084  yxdim = Ydim * Xdim;
1085  zyxdim = Zdim * yxdim;
1086  nzyxdim = Ndim * zyxdim;
1087  mFd = new_mFd;
1089 }
#define NSIZE(v)
#define YSIZE(v)
void min(Image< double > &op1, const Image< double > &op2)
void coreDeallocate() noexcept
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
FILE * mmapFile(T *&_data, size_t nzyxDim) const
There is not enough memory for allocation.
Definition: xmipp_error.h:166
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
#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
void setMmap(bool mmap)
#define XSIZE(v)
#define ZSIZE(v)
#define NZYXSIZE(v)
void copy(Matrix2D< T > &op1) const

◆ resize() [2/2]

template<typename T>
template<typename T1 >
void MultidimArray< T >::resize ( const MultidimArray< T1 > &  v,
bool  copy = true 
)
inline

Resize according to a pattern.

This function resize the actual array to the same size and origin as the input pattern. If the actual array is larger than the pattern then the trailing values are lost, if it is smaller then 0's are added at the end

v2.resize(v1);
// v2 has got now the same structure as v1

Definition at line 490 of file multidim_array.h.

491  {
492  if (NSIZE(*this) != NSIZE(v) || XSIZE(*this) != XSIZE(v) ||
493  YSIZE(*this) != YSIZE(v) || ZSIZE(*this) != ZSIZE(v) || data==NULL)
494  resize(NSIZE(v), ZSIZE(v), YSIZE(v), XSIZE(v), copy);
495 
496  STARTINGX(*this) = STARTINGX(v);
497  STARTINGY(*this) = STARTINGY(v);
498  STARTINGZ(*this) = STARTINGZ(v);
499  }
#define NSIZE(v)
#define YSIZE(v)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
#define STARTINGX(v)
#define STARTINGY(v)
#define XSIZE(v)
#define ZSIZE(v)
void copy(Matrix2D< T > &op1) const
#define STARTINGZ(v)

◆ resizeNoCopy()

template<typename T>
template<typename T1 >
void MultidimArray< T >::resizeNoCopy ( const MultidimArray< T1 > &  v)
inline

Resize according to a pattern with no copy.

Definition at line 504 of file multidim_array.h.

505  {
506  if (NSIZE(*this) != NSIZE(v) || XSIZE(*this) != XSIZE(v) ||
507  YSIZE(*this) != YSIZE(v) || ZSIZE(*this) != ZSIZE(v) || data==NULL)
508  resize(NSIZE(v), ZSIZE(v), YSIZE(v), XSIZE(v), false);
509 
510  STARTINGX(*this) = STARTINGX(v);
511  STARTINGY(*this) = STARTINGY(v);
512  STARTINGZ(*this) = STARTINGZ(v);
513  }
#define NSIZE(v)
#define YSIZE(v)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
#define STARTINGX(v)
#define STARTINGY(v)
#define XSIZE(v)
#define ZSIZE(v)
#define STARTINGZ(v)

◆ reslice() [1/2]

template<typename T>
template<typename T1 >
void MultidimArray< T >::reslice ( MultidimArray< T1 > &  out,
AxisView  face,
bool  flip = false,
size_t  n = 0 
) const
inline

Reslice the volume aliging any X or Y direction with Z axis

Parameters
faceSelect the face to become the new Z direction
outThe resliced volume is returned
flipInvert the positions of Z planes, keeping the X-Y orientation
nSelect the number of image in case of stacks

Definition at line 1062 of file multidim_array.h.

1063  {
1064  ArrayDim aDim, aDimOut;
1065  getDimensions(aDim);
1066 
1067  char axis='Z';
1068  bool reverse=false;
1069 
1070  aDimOut = aDim;
1071 
1072  if (face == VIEW_Y_NEG || face == VIEW_Y_POS)
1073  {
1074  axis = 'Y';
1075  aDimOut.ydim = aDim.zdim;
1076  aDimOut.zdim = aDim.ydim;
1077  reverse = (face == VIEW_Y_NEG);
1078  }
1079  else if (face == VIEW_X_NEG || face == VIEW_X_POS)
1080  {
1081  axis = 'X';
1082  aDimOut.xdim = aDim.zdim;
1083  aDimOut.zdim = aDim.xdim;
1084  reverse = (face == VIEW_X_NEG);
1085  }
1086 
1087  flip = flip^reverse;
1088 
1089  out.resize(aDimOut, false);
1090 
1091  MultidimArray<T1> imTemp;
1092 
1093  int index;
1094 
1095  for (size_t k = 0; k < aDimOut.zdim; k++)
1096  {
1097  imTemp.aliasSlice(out, k);
1098  index = k + (aDimOut.zdim - 1 - 2*k) * (int)flip;
1099  this->getSlice(index, imTemp, axis, !reverse);
1100  }
1101  }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
size_t xdim
void getSlice(int k, MultidimArray< T1 > &M, char axis='Z', bool reverse=false, size_t n=0) const
ArrayDim getDimensions() const
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
void aliasSlice(const MultidimArray< T > &m, size_t select_slice)
char axis
size_t zdim
viol index
size_t ydim

◆ reslice() [2/2]

template<typename T>
void MultidimArray< T >::reslice ( AxisView  face,
bool  flip = false,
size_t  n = 0 
)
inline

Reslice the current volume

Parameters
faceSelect the face to become the new Z direction
flipInvert the positions of Z planes, keeping the X-Y orientation
nSelect the number of image in case of stacks

Definition at line 1109 of file multidim_array.h.

1110  {
1111  MultidimArray<T> mTemp;
1112  reslice(mTemp, face, flip, n);
1113  *this = mTemp;
1114  }
void reslice(MultidimArray< T1 > &out, AxisView face, bool flip=false, size_t n=0) const
int * n

◆ selfABS()

template<typename T>
void MultidimArray< T >::selfABS ( )
inline

ABS

Applies an ABS (absolute value) to each array element.

Definition at line 3330 of file multidim_array.h.

3331  {
3332  T* ptr=NULL;
3333  size_t n;
3335  *ptr = ABS(*ptr);
3336  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define ABS(x)
Definition: xmipp_macros.h:142
int * n

◆ selfCEIL()

template<typename T>
void MultidimArray< T >::selfCEIL ( )
inline

CEILING

Applies a CEILING (look for the nearest larger integer) to each array element.

Definition at line 3305 of file multidim_array.h.

3306  {
3307  T* ptr=NULL;
3308  size_t n;
3310  *ptr = CEIL(*ptr);
3311  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define CEIL(x)
Definition: xmipp_macros.h:225
int * n

◆ selfFLOOR()

template<typename T>
void MultidimArray< T >::selfFLOOR ( )
inline

FLOOR

Applies a FLOOR (look for the nearest larger integer) to each array element.

Definition at line 3318 of file multidim_array.h.

3319  {
3320  T* ptr=NULL;
3321  size_t n;
3323  *ptr = FLOOR(*ptr);
3324  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define FLOOR(x)
Definition: xmipp_macros.h:240
int * n

◆ selfLog()

template<typename T>
void MultidimArray< T >::selfLog ( )
inline

Log.

Each component of the result is the log of the original components.

Definition at line 3464 of file multidim_array.h.

3465  {
3466  T* ptr=NULL;
3467  size_t n;
3469  *ptr = static_cast< T >(log(static_cast< double >(*ptr)));
3470  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
void log(Image< double > &op)
int * n

◆ selfLog10()

template<typename T>
void MultidimArray< T >::selfLog10 ( )
inline

Log10.

Each component of the result is the log10 of the original components.

Definition at line 3452 of file multidim_array.h.

3453  {
3454  T* ptr=NULL;
3455  size_t n;
3457  *ptr = static_cast< T >(log10(static_cast< double >(*ptr)));
3458  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
void log10(Image< double > &op)
int * n

◆ selfNormalizeInterval()

template<typename T >
void MultidimArray< T >::selfNormalizeInterval ( double  minPerc = 0.25,
double  maxPerc = 0.75,
int  Npix = 1000 
)

Normalize the percentil interval values between -1 to 1 the normalization is done over a Npix number of pixels chosen at random

v_sorted(minPerc) = -1 v_sorted(maxPerc) = 1

Definition at line 910 of file multidim_array.cpp.

911 {
912  std::vector<double> randValues; // Vector with random chosen values
913 
914  for(int i=0; i<Npix; i++)
915  {
916  size_t indx = (size_t)rnd_unif(0, MULTIDIM_SIZE(*this));
917  randValues.push_back(DIRECT_MULTIDIM_ELEM(*this,indx));
918  }
919  std::sort(randValues.begin(),randValues.end());
920 
921  double m = randValues[(size_t)(minPerc*Npix)];
922  double M = randValues[(size_t)(maxPerc*Npix)];
923 
924  T* ptr=NULL;
925  size_t n;
927  *ptr = 2/(M-m)*(*ptr-m)-1;
928 }
#define MULTIDIM_SIZE(v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define i
double rnd_unif()
#define DIRECT_MULTIDIM_ELEM(v, n)
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
int m
int * n

◆ selfReverseX()

template<typename T>
void MultidimArray< T >::selfReverseX ( )
inlinevirtual

Reverse matrix values over X axis, keep in this object.

Maybe better with an example:

Odd case

slice 0
[01 02 03 [07 08 09
04 05 06 04 05 06
07 08 09] 01 02 03]
----->
slice 1
[11 12 13 [17 18 19
14 15 16 14 15 16
17 18 19] 11 12 13]

Even case

slice 0
[01 02 03 04 [01 04 03 02
05 06 06 07 05 07 06 06
08 09 10 11 08 11 10 09
12 13 14 15] 12 15 14 13]

Implements MultidimArrayBase.

Definition at line 3501 of file multidim_array.h.

3502  {
3503  size_t xsize=XSIZE(*this);
3504  size_t halfSizeX = (xsize-2)/2;
3505  size_t xsize_1=xsize-1;
3506  for (size_t k = 0; k < ZSIZE(*this); k++)
3507  for (size_t i = 0; i < YSIZE(*this); i++)
3508  for (size_t j = 0; j <=halfSizeX; j++)
3509  {
3510  T aux;
3511  T& d1=DIRECT_ZYX_ELEM(*this, k, i, j);
3512  T& d2=DIRECT_ZYX_ELEM(*this, k, i, xsize_1 - j);
3513  SWAP(d1,d2,aux);
3514  }
3515  STARTINGX(*this) = -FINISHINGX(*this);
3516  }
#define YSIZE(v)
#define FINISHINGX(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 XSIZE(v)
#define ZSIZE(v)
#define j
#define DIRECT_ZYX_ELEM(v, k, i, j)
#define SWAP(a, b, tmp)
Definition: xmipp_macros.h:428

◆ selfReverseY()

template<typename T>
void MultidimArray< T >::selfReverseY ( )
inlinevirtual

Reverse matrix values over Y axis, keep in this object.

Maybe better with an example:

slice 0
[01 02 03 [07 08 09
04 05 06 04 05 06
07 08 09] 01 02 03]

Implements MultidimArrayBase.

Definition at line 3531 of file multidim_array.h.

3532  {
3533  size_t ysize=YSIZE(*this);
3534  size_t halfSizeY = (ysize-2)/2;
3535  size_t ysize_1=ysize-1;
3536  for (size_t k = 0; k < ZSIZE(*this); k++)
3537  for (size_t i = 0; i <= halfSizeY; i++)
3538  for (size_t j = 0; j < XSIZE(*this); j++)
3539  {
3540  T aux;
3541  T& d1=DIRECT_ZYX_ELEM(*this, k, i, j);
3542  T& d2=DIRECT_ZYX_ELEM(*this, k, ysize_1 - i, j);
3543  SWAP(d1,d2,aux);
3544  }
3545  STARTINGY(*this) = -FINISHINGY(*this);
3546  }
#define YSIZE(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 XSIZE(v)
#define ZSIZE(v)
#define j
#define FINISHINGY(v)
#define DIRECT_ZYX_ELEM(v, k, i, j)
#define SWAP(a, b, tmp)
Definition: xmipp_macros.h:428

◆ selfReverseZ()

template<typename T>
void MultidimArray< T >::selfReverseZ ( )
inlinevirtual

Reverse matrix values over Z axis, keep result in this object.

Implements MultidimArrayBase.

Definition at line 3553 of file multidim_array.h.

3554  {
3555  size_t zsize=ZSIZE(*this);
3556  size_t halfSizeZ = (zsize-2)/2;
3557  size_t zsize_1=zsize-1;
3558  for (size_t k = 0; k <= halfSizeZ; k++)
3559  for (size_t i = 0; i <YSIZE(*this); i++)
3560  for (size_t j = 0; j < XSIZE(*this); j++)
3561  {
3562  T aux;
3563  T& d1=DIRECT_ZYX_ELEM(*this, k, i, j);
3564  T& d2=DIRECT_ZYX_ELEM(*this, zsize_1- k, i, j);
3565  SWAP(d1,d2,aux);
3566  }
3567  STARTINGZ(*this) = -FINISHINGZ(*this);
3568  }
#define YSIZE(v)
#define FINISHINGZ(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 XSIZE(v)
#define ZSIZE(v)
#define j
#define DIRECT_ZYX_ELEM(v, k, i, j)
#define SWAP(a, b, tmp)
Definition: xmipp_macros.h:428
#define STARTINGZ(v)

◆ selfROUND()

template<typename T>
void MultidimArray< T >::selfROUND ( )
inline

ROUND

Applies a ROUND (look for the nearest integer) to each array element.

Definition at line 3292 of file multidim_array.h.

3293  {
3294  T* ptr=NULL;
3295  size_t n;
3297  *ptr = ROUND(*ptr);
3298  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define ROUND(x)
Definition: xmipp_macros.h:210
int * n

◆ selfSQRT()

template<typename T>
void MultidimArray< T >::selfSQRT ( )
inline

Sqrt.

Each component of the result is the square root of the original component.

Definition at line 3389 of file multidim_array.h.

3390  {
3391  T* ptr=NULL;
3392  size_t n;
3394  *ptr = static_cast< T >(sqrt(static_cast< double >(*ptr)));
3395  }
void sqrt(Image< double > &op)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
int * n

◆ selfWindow() [1/4]

template<typename T>
void MultidimArray< T >::selfWindow ( int  n0,
int  z0,
int  y0,
int  x0,
int  nF,
int  zF,
int  yF,
int  xF,
init_value = 0 
)
inline

Generic selfWindow routine (dim independent)

This function will call to 3D,2D or 1D specific selfWindow routines

Definition at line 538 of file multidim_array.h.

541  {
542  if (this->ndim >1)
543  REPORT_ERROR(ERR_MULTIDIM_DIM,"stack windowing not implemented");
544  if (this->zdim >1)
545  {//call 3Dwindow
546  selfWindow( z0, y0, x0,
547  zF, yF, xF,
548  init_value);
549  }
550  else if (this->ydim >1)
551  {//call 2Dwindow
552  selfWindow( y0, x0,
553  yF, xF,
554  init_value);
555 
556  }
557  else if (this->xdim >1)
558  {//call 1Dwindow
559  selfWindow( x0, xF, init_value);
560  }
561  }
void selfWindow(int n0, int z0, int y0, int x0, int nF, int zF, int yF, int xF, T init_value=0)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define zF
#define z0
#define y0
#define x0
#define xF
Incorrect MultidimArray dimensions.
Definition: xmipp_error.h:173
#define yF

◆ selfWindow() [2/4]

template<typename T>
void MultidimArray< T >::selfWindow ( int  z0,
int  y0,
int  x0,
int  zF,
int  yF,
int  xF,
init_value = 0 
)
inline

3D Self window

Definition at line 633 of file multidim_array.h.

635  {
636  if (z0 == STARTINGZ(*this) && zF == FINISHINGZ(*this) &&
637  y0 == STARTINGY(*this) && yF == FINISHINGY(*this) &&
638  x0 == STARTINGX(*this) && xF == FINISHINGX(*this))
639  return;
640 
641  MultidimArray<T> result;
642  window(result,z0,y0,x0,zF,yF,xF,init_value);
643  *this=result;
644  }
#define FINISHINGX(v)
#define zF
#define z0
#define FINISHINGZ(v)
#define STARTINGX(v)
#define STARTINGY(v)
void window(MultidimArray< T1 > &result, int n0, int z0, int y0, int x0, int nF, int zF, int yF, int xF, T1 init_value=0) const
#define y0
#define x0
#define xF
#define FINISHINGY(v)
#define yF
#define STARTINGZ(v)

◆ selfWindow() [3/4]

template<typename T>
void MultidimArray< T >::selfWindow ( int  y0,
int  x0,
int  yF,
int  xF,
init_value = 0 
)
inline

2D Self window

Definition at line 682 of file multidim_array.h.

684  {
685  MultidimArray<T> result;
686  window(result,y0,x0,yF,xF,init_value);
687  *this=result;
688  }
void window(MultidimArray< T1 > &result, int n0, int z0, int y0, int x0, int nF, int zF, int yF, int xF, T1 init_value=0) const
#define y0
#define x0
#define xF
#define yF

◆ selfWindow() [4/4]

template<typename T>
void MultidimArray< T >::selfWindow ( int  x0,
int  xF,
init_value = 0 
)
inline

1D Self window

Definition at line 718 of file multidim_array.h.

720  {
721  MultidimArray<T> result;
722  window(result,x0,xF,init_value);
723  *this=result;
724  }
void window(MultidimArray< T1 > &result, int n0, int z0, int y0, int x0, int nF, int zF, int yF, int xF, T1 init_value=0) const
#define x0
#define xF

◆ setCol()

template<typename T>
void MultidimArray< T >::setCol ( size_t  j,
const MultidimArray< T > &  v 
)
inline

Set Column

This function sets a column vector corresponding to the chosen column inside matrix.

m.setCol(0, (m.row(1)).transpose()); // Copies row 1 in column 0

Definition at line 1151 of file multidim_array.h.

1152  {
1153  if (xdim == 0 || ydim == 0)
1154  REPORT_ERROR(ERR_MULTIDIM_EMPTY, "setCol: Target matrix is empty");
1155 
1156  if (j>= xdim)
1157  REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS, "setCol: Matrix subscript (j) out of range");
1158 
1159  if (v.xdim != ydim)
1161  "setCol: Vector dimension different from matrix one");
1162 
1163  for (size_t i = 0; i < ydim; i++)
1164  DIRECT_A2D_ELEM(*this,i, j) = DIRECT_A1D_ELEM(v,i);
1165  }
Index out of bounds.
Definition: xmipp_error.h:132
MultidimArray is empty.
Definition: xmipp_error.h:175
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define DIRECT_A2D_ELEM(v, i, j)
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
#define i
#define DIRECT_A1D_ELEM(v, i)
#define j

◆ setRow()

template<typename T>
void MultidimArray< T >::setRow ( int  i,
const MultidimArray< T > &  v 
)
inline

Set Row

This function sets a row vector corresponding to the chosen row in the 2D Matrix

m.setRow(-2, m.row(1)); // Copies row 1 in row -2

Definition at line 1201 of file multidim_array.h.

1202  {
1203  if (xdim == 0 || ydim == 0)
1204  REPORT_ERROR(ERR_MULTIDIM_EMPTY, "setRow: Target matrix is empty");
1205 
1206  if (i < 0 || i >= ydim)
1207  REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS, "setRow: Matrix subscript (i) out of range");
1208 
1209  if (v.xdim != xdim)
1211  "setRow: Vector dimension different from matrix one");
1212 
1213  memcpy(&A2D_ELEM(*this,i,0),&A1D_ELEM(v,0),xdim*sizeof(T));
1214  }
Index out of bounds.
Definition: xmipp_error.h:132
#define A2D_ELEM(v, i, j)
MultidimArray is empty.
Definition: xmipp_error.h:175
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define A1D_ELEM(v, i)
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
#define i

◆ setSlice()

template<typename T>
template<typename T1 >
void MultidimArray< T >::setSlice ( int  k,
const MultidimArray< T1 > &  v,
size_t  n = 0 
)
inline

Slice access for writing.

This function sets a 2D matrix corresponding to the chosen slice inside the nth volume, the numbering of the slices is also logical not physical.

// Copies slice 0 in slice 1
V.setSlice(1, (V.slice(0)));

Definition at line 1033 of file multidim_array.h.

1034  {
1035  if (xdim == 0)
1036  return;
1037 
1038  if (k < STARTINGZ(*this) || k > FINISHINGZ(*this))
1040  "setSlice: MultidimArray subscript (k=%d) out of range [%d, %d]",
1041  k,STARTINGZ(*this),FINISHINGZ(*this)));
1042 
1043  if (v.rowNumber() != YSIZE(*this) || v.colNumber() != XSIZE(*this))
1045  "setSlice: MultidimArray dimensions different from the matrix ones");
1046 
1047  k-=STARTINGZ(*this);
1048  T *ptr=&(DIRECT_NZYX_ELEM(*this, n, k, 0, 0));
1050  *(ptr++) = (T) DIRECT_MULTIDIM_ELEM(v, n);
1051  }
Index out of bounds.
Definition: xmipp_error.h:132
#define YSIZE(v)
#define DIRECT_NZYX_ELEM(v, l, k, i, j)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define FINISHINGZ(v)
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 XSIZE(v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
size_t colNumber() const
String formatString(const char *format,...)
Incorrect MultidimArray dimensions.
Definition: xmipp_error.h:173
#define STARTINGZ(v)
int * n
size_t rowNumber() const

◆ showWithGnuPlot()

template<typename T >
void MultidimArray< T >::showWithGnuPlot ( const String xlabel,
const String title 
)

Show using gnuplot

This function uses gnuplot to plot this vector. You must supply the xlabel, ylabel, and title.

Definition at line 931 of file multidim_array.cpp.

932 {
933  checkDimension(1);
934 
935  FileName fn_tmp;
936  fn_tmp.initRandom(10);
937  const char * fnStr = fn_tmp.c_str();
938  MultidimArray<T>::write(formatString("PPP%s.txt", fnStr));
939 
940  std::ofstream fh_gplot;
941  fh_gplot.open(formatString("PPP%s.gpl", fnStr).c_str());
942  if (!fh_gplot)
944  formatString("vector::showWithGnuPlot: Cannot open PPP%s.gpl for output", fnStr));
945  fh_gplot << "set xlabel \"" + xlabel + "\"\n";
946  fh_gplot << "plot \"PPP" + fn_tmp + ".txt\" title \"" + title +
947  "\" w l\n";
948  fh_gplot << "pause 300 \"\"\n";
949  fh_gplot.close();
950  if (0 != system(formatString("(gnuplot PPP%s.gpl; rm PPP%s.txt PPP%s.gpl) &", fnStr, fnStr, fnStr).c_str()) ) {
951  REPORT_ERROR(ERR_IO, "Cannot open gnuplot");
952  }
953 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Input/Output general error.
Definition: xmipp_error.h:134
#define checkDimension(dim)
void write(const FileName &fn) const
File cannot be open.
Definition: xmipp_error.h:137
String formatString(const char *format,...)
void initRandom(int length)

◆ sort()

template<typename T>
void MultidimArray< T >::sort ( MultidimArray< T > &  result) const

Sort vector elements

Sort in ascending order the vector elements. You can use the "reverse" function to sort in descending order.

v2 = v1.sort();

Definition at line 1092 of file multidim_array.cpp.

1093 {
1094  result = *this;
1095  std::sort(result.data, result.data + result.nzyxdim);
1096 }
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18

◆ statisticsAdjust()

template<typename T>
template<typename U >
void MultidimArray< T >::statisticsAdjust ( avgF,
stddevF 
)
inline

Adjust the average and stddev of the array to given values.

A linear operation is performed on the values of the array such that after it, the average and standard deviation of the array are the two values set. The actual array is modified itself

v.statisticsAdjust(0,1);
// The array has got now 0 mean and stddev=1

Definition at line 2114 of file multidim_array.h.

2115  {
2116  static_assert(
2117  std::is_same<double, U>::value || std::is_same<float, U>::value,
2118  "U must be a floating presiont type");
2119  U avg0 = 0;
2120  U stddev0 = 0;
2121 
2122  if (NZYXSIZE(*this) == 0)
2123  return;
2124 
2125  computeAvgStdev(avg0, stddev0);
2126 
2127  U a = (stddev0 != 0) ? (stddevF / stddev0) : 0;
2128  U b = avgF - a * avg0;
2129 
2130  T* ptr=&DIRECT_MULTIDIM_ELEM(*this,0);
2131  size_t nmax=(nzyxdim/4)*4;
2132  for (size_t n=0; n<nmax; n+=4, ptr+=4)
2133  {
2134  *(ptr )= static_cast< T >(a * (*(ptr )) + b);
2135  *(ptr+1)= static_cast< T >(a * (*(ptr+1)) + b);
2136  *(ptr+2)= static_cast< T >(a * (*(ptr+2)) + b);
2137  *(ptr+3)= static_cast< T >(a * (*(ptr+3)) + b);
2138  }
2139  for (size_t n=nmax; n<nzyxdim; ++n, ptr+=1)
2140  *(ptr )= static_cast< T >(a * (*(ptr )) + b);
2141  }
int * nmax
void computeAvgStdev(U &avg, U &stddev) const
doublereal * b
#define DIRECT_MULTIDIM_ELEM(v, n)
#define NZYXSIZE(v)
int * n
doublereal * a

◆ substitute()

template<typename T>
void MultidimArray< T >::substitute ( oldv,
newv,
double  accuracy = XMIPP_EQUAL_ACCURACY,
MultidimArray< int > *  mask = NULL 
)
inline

Substitute a value by another.

Substitute an old value by a new one. The accuracy is used to say if the value in the array is equal to the old value. Set it to 0 for perfect accuracy.

Definition at line 3221 of file multidim_array.h.

3225  {
3226  T* ptr=NULL;
3227  size_t n;
3229  if (mask == NULL || DIRECT_MULTIDIM_ELEM(*mask,n) > 0 )
3230  if (ABS(*ptr - oldv) <= accuracy)
3231  *ptr = newv;
3232  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
#define ABS(x)
Definition: xmipp_macros.h:142
#define DIRECT_MULTIDIM_ELEM(v, n)
int * n

◆ sum()

template<typename T>
double MultidimArray< T >::sum ( ) const
inline

Sum of matrix values.

This function returns the sum of all internal values.

double sum = m.sum();

Definition at line 3405 of file multidim_array.h.

3406  {
3407  double sum = 0;
3408  T* ptr=NULL;
3409  size_t n;
3411  sum += *ptr;
3412  return sum;
3413  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
int * n
double sum() const

◆ sum2()

template<typename T>
double MultidimArray< T >::sum2 ( ) const
inline

Sum of squared vector values.

This function returns the sum of all internal values to the second power.

double sum2 = m.sum2();

Definition at line 3424 of file multidim_array.h.

3425  {
3426  double sum = 0;
3427 
3428  // Unroll the loop
3429  const size_t unroll=4;
3430  size_t nmax=(NZYXSIZE(*this)/unroll)*unroll;
3431  T* ptr = MULTIDIM_ARRAY(*this);
3432  for (size_t n=0; n<nmax; n+=unroll, ptr+=unroll)
3433  {
3434  sum+= (*ptr)*(*ptr);
3435  T* ptr1=ptr+1;
3436  sum+= (*ptr1)*(*ptr1);
3437  T* ptr2=ptr+2;
3438  sum+= (*ptr2)*(*ptr2);
3439  T* ptr3=ptr+3;
3440  sum+= (*ptr3)*(*ptr3);
3441  }
3442  // Do the remaining elements
3443  for (size_t n=nmax; n<NZYXSIZE(*this); ++n, ++ptr)
3444  sum+=(*ptr)*(*ptr);
3445  return sum;
3446  }
int * nmax
#define MULTIDIM_ARRAY(v)
#define NZYXSIZE(v)
int * n
double sum() const

◆ swap()

template<typename T>
void MultidimArray< T >::swap ( MultidimArray< T > &  other)
inlinenoexcept

Definition at line 241 of file multidim_array.h.

242  {
243  std::swap(xdim, other.xdim);
244  std::swap(ydim, other.ydim);
245  std::swap(zdim, other.zdim);
246  std::swap(ndim, other.ndim);
247  std::swap(yxdim, other.yxdim);
248  std::swap(zyxdim, other.zyxdim);
249  std::swap(nzyxdim, other.nzyxdim);
250  std::swap(xinit, other.xinit);
251  std::swap(yinit, other.yinit);
252  std::swap(zinit, other.zinit);
253  std::swap(data, other.data);
254  std::swap(nzyxdimAlloc, other.nzyxdimAlloc);
255  std::swap(destroyData, other.destroyData);
256  std::swap(mmapOn, other.mmapOn);
257  std::swap(mFd, other.mFd);
258  }

◆ threshold()

template<typename T>
void MultidimArray< T >::threshold ( const String type,
a,
b = 0,
MultidimArray< int > *  mask = NULL 
)
inline

Several thresholding.

Apply a threshold to the array, the object is modified itself. There are several kinds of thresholding and you must specify it, the values given in the fuction have different meanings according to the threshold applied.

abs_above: if |x|>a => x=b abs_below: if |x|<a => x=b above: if x >a => x=b below: if x <a => x=b range: if x <a => x=a and if x>b => x=b soft: if abs(x)<a => x=0 else x=sgn(x)*(abs(x)-a)

v.threshold("abs_above", 10, 10);
// any value whose absolute value is above 10 will be substituted by
// -10 (if it is negative) or 10 (if it is positive)
v.threshold("abs_below", 0.1, 0);
// any value whose absolute value is below 0.1 will be substituted by
// -0 (if it is negative) or 0 (if it is positive)
v.threshold("above", 10, 10);
// any value above 10 will be substituted by 10
v.threshold("below", -10, -10);
// any value below -10 will be substituted by -10
v.threshold("range", 0, 1);
// v is "saturated" by values 0 and 1, any value outside this range
// will be substituted by its nearest border

Definition at line 3089 of file multidim_array.h.

3093  {
3094  int mode;
3095 
3096  if (type == "abs_above")
3097  mode = 1;
3098  else if (type == "abs_below")
3099  mode = 2;
3100  else if (type == "above")
3101  mode = 3;
3102  else if (type == "below")
3103  mode = 4;
3104  else if (type == "range")
3105  mode = 5;
3106  else if (type == "soft")
3107  mode = 6;
3108  else
3110  formatString("Threshold: mode not supported (%s)", type.c_str() ));
3111 
3112  T* ptr=NULL;
3113  size_t n;
3114  T ma=-a;
3116  {
3117  if (mask == NULL || DIRECT_MULTIDIM_ELEM(*mask,n) > 0 )
3118  {
3119  switch (mode)
3120  {
3121  case 1:
3122  if (ABS(*ptr) > a)
3123  *ptr = SGN(*ptr) * b;
3124  break;
3125  case 2:
3126  if (ABS(*ptr) < a)
3127  *ptr = SGN(*ptr) * b;
3128  break;
3129  case 3:
3130  if (*ptr > a)
3131  *ptr = b;
3132  break;
3133  case 4:
3134  if (*ptr < a)
3135  *ptr = b;
3136  break;
3137  case 5:
3138  if (*ptr < a)
3139  *ptr = a;
3140  else if (*ptr > b)
3141  *ptr = b;
3142  break;
3143  case 6:
3144  if (*ptr<ma)
3145  *ptr+=a;
3146  else if (*ptr>a)
3147  *ptr-=a;
3148  else
3149  *ptr=0;
3150  }
3151  }
3152  }
3153  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
doublereal * b
viol type
#define ABS(x)
Definition: xmipp_macros.h:142
#define DIRECT_MULTIDIM_ELEM(v, n)
void mode
String formatString(const char *format,...)
Incorrect value received.
Definition: xmipp_error.h:195
#define SGN(x)
Definition: xmipp_macros.h:155
int * n
doublereal * a

◆ toLogical() [1/3]

template<typename T>
void MultidimArray< T >::toLogical ( int  k_phys,
int  i_phys,
int  j_phys,
int &  k_log,
int &  i_log,
int &  j_log 
) const
inline

3D Physical to logical index translation.

This function returns the logical position of a physical one.

m.toLogical(i_phys, j_phys, i_log, j_log);

Definition at line 1251 of file multidim_array.h.

1253  {
1254  k_log = k_phys + STARTINGZ(*this);
1255  i_log = i_phys + STARTINGY(*this);
1256  j_log = j_phys + STARTINGX(*this);
1257  }
#define STARTINGX(v)
#define STARTINGY(v)
#define STARTINGZ(v)

◆ toLogical() [2/3]

template<typename T>
void MultidimArray< T >::toLogical ( int  i_phys,
int  j_phys,
int &  i_log,
int &  j_log 
) const
inline

2D Physical to logical index translation

This function returns the logical position of a physical one.

m.toLogical(i_phys, j_phys, i_log, j_log);

Definition at line 1281 of file multidim_array.h.

1282  {
1283  i_log = i_phys + STARTINGY(*this);
1284  j_log = j_phys + STARTINGX(*this);
1285  }
#define STARTINGX(v)
#define STARTINGY(v)

◆ toLogical() [3/3]

template<typename T>
void MultidimArray< T >::toLogical ( int  i_phys,
int &  i_log 
) const
inline

1D Physical to logical index translation.

This function returns the logical position of a physical one.

v.toLogical(i_phys, i_log);

Definition at line 1308 of file multidim_array.h.

1309  {
1310  i_log = i_phys + STARTINGX(*this);
1311  }
#define STARTINGX(v)

◆ toPhysical() [1/3]

template<typename T>
void MultidimArray< T >::toPhysical ( int  k_log,
int  i_log,
int  j_log,
int &  k_phys,
int &  i_phys,
int &  j_phys 
) const
inline

3D Logical to physical index translation.

This function returns the physical position of a logical one.

m.toPhysical(k_log, i_log, j_log, k_phys, i_phys, j_phys);

Definition at line 1235 of file multidim_array.h.

1237  {
1238  k_phys = k_log - STARTINGZ(*this);
1239  i_phys = i_log - STARTINGY(*this);
1240  j_phys = j_log - STARTINGX(*this);
1241  }
#define STARTINGX(v)
#define STARTINGY(v)
#define STARTINGZ(v)

◆ toPhysical() [2/3]

template<typename T>
void MultidimArray< T >::toPhysical ( int  i_log,
int  j_log,
int &  i_phys,
int &  j_phys 
) const
inline

2D Logical to physical index translation

This function returns the physical position of a logical one.

m.toPhysical(i_log, j_log, i_phys, j_phys);

Definition at line 1267 of file multidim_array.h.

1268  {
1269  i_phys = i_log - STARTINGY(*this);
1270  j_phys = j_log - STARTINGX(*this);
1271  }
#define STARTINGX(v)
#define STARTINGY(v)

◆ toPhysical() [3/3]

template<typename T>
void MultidimArray< T >::toPhysical ( int  i_log,
int &  i_phys 
) const
inline

1D Logical to physical index translation

This function returns the physical position of a logical one.

v.toPhysical(i_log, i_phys);

Definition at line 1295 of file multidim_array.h.

1296  {
1297  i_phys = i_log - STARTINGX(*this);
1298  }
#define STARTINGX(v)

◆ window() [1/4]

template<typename T>
template<class T1 >
void MultidimArray< T >::window ( MultidimArray< T1 > &  result,
int  n0,
int  z0,
int  y0,
int  x0,
int  nF,
int  zF,
int  yF,
int  xF,
T1  init_value = 0 
) const
inline

Definition at line 564 of file multidim_array.h.

567  {
568  if (this->ndim >1)
569  REPORT_ERROR(ERR_MULTIDIM_DIM,"stack windowing not implemented");
570  if (this->zdim >1)
571  {//call 3Dwindow
572  window(result, z0, y0, x0,
573  zF, yF, xF,
574  init_value);
575  }
576  else if (this->ydim >1)
577  {//call 2Dwindow
578  window(result, y0, x0,
579  yF, xF,
580  init_value);
581  }
582  else if (this->xdim >1)
583  {//call 1Dwindow
584  window(result, x0, xF, init_value);
585  }
586  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define zF
#define z0
void window(MultidimArray< T1 > &result, int n0, int z0, int y0, int x0, int nF, int zF, int yF, int xF, T1 init_value=0) const
#define y0
#define x0
#define xF
Incorrect MultidimArray dimensions.
Definition: xmipp_error.h:173
#define yF

◆ window() [2/4]

template<typename T>
template<class T1 >
void MultidimArray< T >::window ( MultidimArray< T1 > &  result,
int  z0,
int  y0,
int  x0,
int  zF,
int  yF,
int  xF,
T1  init_value = 0 
) const
inline

Put a 3D selfWindow to the nth volume

The volume is windowed within the two positions given to this function. Indexes always refer to logical indexes. If a position is outside the actual matrix range then the matrix is padded init_value until the new position is reached. In the following example suppose that m1 is the following and that the origin is (-1,-1,-1).

slice 0
[01 02 03 [
04 05 06 04 05 06 0
07 08 09] 07 08 09 0]
----->
slice 1
[11 12 13 [
14 15 16 14 15 16 0
17 18 19] 17 18 19 0]
V1.selfWindow(0, 0, -1, 1, 1, 2);

Definition at line 615 of file multidim_array.h.

617  {
618  result.resizeNoCopy(zF - z0 + 1, yF - y0 + 1, xF - x0 + 1);
619  STARTINGZ(result) = z0;
620  STARTINGY(result) = y0;
621  STARTINGX(result) = x0;
622 
624  if ((k >= STARTINGZ(*this) && k <= FINISHINGZ(*this)) &&
625  (i >= STARTINGY(*this) && i <= FINISHINGY(*this)) &&
626  (j >= STARTINGX(*this) && j <= FINISHINGX(*this)))
627  A3D_ELEM(result, k, i, j) = (T1) A3D_ELEM(*this, k, i, j);
628  else
629  A3D_ELEM(result, k, i, j) = init_value;
630  }
#define FINISHINGX(v)
void resizeNoCopy(const MultidimArray< T1 > &v)
#define zF
#define z0
#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 A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define y0
#define x0
#define xF
#define j
#define FINISHINGY(v)
#define yF
#define STARTINGZ(v)

◆ window() [3/4]

template<typename T>
template<class T1 >
void MultidimArray< T >::window ( MultidimArray< T1 > &  result,
int  y0,
int  x0,
int  yF,
int  xF,
T1  init_value = 0 
) const
inline

Put a 2D selfWindow to the nth matrix

The matrix is windowed within the two positions given to this function. Indexes always refer to logical indexes. If a position is outside the actual matrix range then the matrix is padded with init_value until the new position is reached. In the following examples suppose that m1 is the following and that the origin is (-1,-1).

[1 2 3 [1 2 3 0
m1 = 4 5 6 ---> m1 = 4 5 6 0
7 8 9] 7 8 9 0]
m1.selfWindow(-1, -1, 1, 2);

Definition at line 666 of file multidim_array.h.

668  {
669  result.resizeNoCopy(yF - y0 + 1, xF - x0 + 1);
670  STARTINGY(result) = y0;
671  STARTINGX(result) = x0;
672 
674  if (j >= STARTINGX(*this) && j <= FINISHINGX(*this) &&
675  i >= STARTINGY(*this) && i <= FINISHINGY(*this))
676  A2D_ELEM(result, i, j) = A2D_ELEM(*this, i, j);
677  else
678  A2D_ELEM(result, i, j) = init_value;
679  }
#define A2D_ELEM(v, i, j)
#define FINISHINGX(v)
void resizeNoCopy(const MultidimArray< T1 > &v)
#define STARTINGX(v)
#define i
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
#define STARTINGY(v)
#define y0
#define x0
#define xF
#define j
#define FINISHINGY(v)
#define yF

◆ window() [4/4]

template<typename T>
template<class T1 >
void MultidimArray< T >::window ( MultidimArray< T1 > &  result,
int  x0,
int  xF,
T1  init_value = 0 
) const
inline

Put a 1D selfWindow to the nth vector

The vector is windowed within the two indexes given to this function. Indexes always refer to logical indexes. If an index is outside the actual vector range then the vector is padded winit_value. In the following examples suppose that v1=[-2 -1 0 1 2] and that the origin is -2.

v1.selfWindow(-1, 2); // v1=[-1 0 1 2]; v1.startingX() == -1
v1.selfWindow(-3, 1); // v1=[0 -2 -1 0 1]; v1.startingX() == -3

Definition at line 705 of file multidim_array.h.

706  {
707  result.resizeNoCopy(xF - x0 + 1);
708  STARTINGX(result) = x0;
709 
711  if (i >= STARTINGX(*this) && i <= FINISHINGX(*this))
712  A1D_ELEM(result, i) = A1D_ELEM(*this, i);
713  else
714  A1D_ELEM(result, i) = init_value;
715  }
#define FINISHINGX(v)
void resizeNoCopy(const MultidimArray< T1 > &v)
#define A1D_ELEM(v, i)
#define STARTINGX(v)
#define i
#define x0
#define xF
#define FOR_ALL_ELEMENTS_IN_ARRAY1D(v)

◆ write()

template<typename T >
void MultidimArray< T >::write ( const FileName fn) const

Write to an ASCII file.

Definition at line 970 of file multidim_array.cpp.

971 {
972  std::ofstream out;
973  out.open(fn.c_str(), std::ios::out);
974  if (!out)
976  formatString("MultidimArray::write: File %s cannot be opened for output", fn.c_str()));
977 
978  out << *this;
979  out.close();
980 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
File cannot be open.
Definition: xmipp_error.h:137
String formatString(const char *format,...)

Friends And Related Function Documentation

◆ arrayByArray

template<typename T>
void arrayByArray ( const MultidimArray< T > &  op1,
const MultidimArray< T > &  op2,
MultidimArray< T > &  result,
char  operation 
)
friend

Array by array

This function must take two vectors of the same size, and operate element by element according to the operation required. This is the function which really implements the operations. Simple calls to it perform much faster than calls to the corresponding operators. Although it is supposed to be a hidden function not useable by normal programmers.

Definition at line 2310 of file multidim_array.h.

2314  {
2315  if (!op1.sameShape(op2))
2317  formatString("Array_by_array: different shapes (%c)", operation));
2318  if (result.data == NULL || !result.sameShape(op1))
2319  result.resizeNoCopy(op1);
2320  coreArrayByArray(op1, op2, result, operation);
2321  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void resizeNoCopy(const MultidimArray< T1 > &v)
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
friend void coreArrayByArray(const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)
bool sameShape(const MultidimArrayBase &op) const
String formatString(const char *format,...)

◆ arrayByScalar

template<typename T>
void arrayByScalar ( const MultidimArray< T > &  op1,
op2,
MultidimArray< T > &  result,
char  operation 
)
friend

Array by scalar.

This function must take one vector and a constant, and operate element by element according to the operation required. This is the function which really implements the operations. Simple calls to it perform much faster than calls to the corresponding operators. Although it is supposed to be a hidden function not useable by normal programmers.

This function is not ported to Python.

Definition at line 2496 of file multidim_array.h.

2500  {
2501  if (result.data == NULL || !result.sameShape(op1))
2502  result.resizeNoCopy(op1);
2503  coreArrayByScalar(op1, op2, result, operation);
2504  }
void resizeNoCopy(const MultidimArray< T1 > &v)
bool sameShape(const MultidimArrayBase &op) const
friend void coreArrayByScalar(const MultidimArray< T > &op1, const T &op2, MultidimArray< T > &result, char operation)

◆ coreArrayByArray

template<typename T>
void coreArrayByArray ( const MultidimArray< T > &  op1,
const MultidimArray< T > &  op2,
MultidimArray< T > &  result,
char  operation 
)
friend

Core array by array operation.

It assumes that the result is already resized.

Definition at line 2163 of file multidim_array.h.

2166  {
2167  T* ptrResult=NULL;
2168  T* ptrOp1=NULL;
2169  T* ptrOp2=NULL;
2170  size_t n;
2171  // Loop unrolling
2172  const size_t unroll=4;
2173  size_t nmax=unroll*(op1.nzyxdim/unroll);
2174  switch (operation)
2175  {
2176  case '+':
2177  for (n=0, ptrResult=result.data, ptrOp1=op1.data,ptrOp2=op2.data;
2178  n<nmax; n+=unroll, ptrResult+=unroll, ptrOp1+=unroll, ptrOp2+=unroll)
2179  {
2180  *ptrResult = *ptrOp1 + *ptrOp2;
2181  *(ptrResult+1) = *(ptrOp1+1) + *(ptrOp2+1);
2182  *(ptrResult+2) = *(ptrOp1+2) + *(ptrOp2+2);
2183  *(ptrResult+3) = *(ptrOp1+3) + *(ptrOp2+3);
2184  }
2185  for (n=nmax, ptrResult=result.data+nmax, ptrOp1=op1.data+nmax, ptrOp2=op2.data+nmax;
2186  n<op1.zyxdim; ++n, ++ptrResult, ++ptrOp1, ++ptrOp2)
2187  *ptrResult = *ptrOp1 + *ptrOp2;
2188  break;
2189  case '-':
2190  for (n=0, ptrResult=result.data, ptrOp1=op1.data,ptrOp2=op2.data;
2191  n<nmax; n+=unroll, ptrResult+=unroll, ptrOp1+=unroll, ptrOp2+=unroll)
2192  {
2193  *ptrResult = *ptrOp1 - *ptrOp2;
2194  *(ptrResult+1) = *(ptrOp1+1) - *(ptrOp2+1);
2195  *(ptrResult+2) = *(ptrOp1+2) - *(ptrOp2+2);
2196  *(ptrResult+3) = *(ptrOp1+3) - *(ptrOp2+3);
2197  }
2198  for (n=nmax, ptrResult=result.data+nmax, ptrOp1=op1.data+nmax, ptrOp2=op2.data+nmax;
2199  n<op1.zyxdim; ++n, ++ptrResult, ++ptrOp1, ++ptrOp2)
2200  *ptrResult = *ptrOp1 - *ptrOp2;
2201  break;
2202  case '*':
2203  for (n=0, ptrResult=result.data, ptrOp1=op1.data,ptrOp2=op2.data;
2204  n<nmax; n+=unroll, ptrResult+=unroll, ptrOp1+=unroll, ptrOp2+=unroll)
2205  {
2206  *ptrResult = *ptrOp1 * *ptrOp2;
2207  *(ptrResult+1) = *(ptrOp1+1) * *(ptrOp2+1);
2208  *(ptrResult+2) = *(ptrOp1+2) * *(ptrOp2+2);
2209  *(ptrResult+3) = *(ptrOp1+3) * *(ptrOp2+3);
2210  }
2211  for (n=nmax, ptrResult=result.data+nmax, ptrOp1=op1.data+nmax, ptrOp2=op2.data+nmax;
2212  n<op1.zyxdim; ++n, ++ptrResult, ++ptrOp1, ++ptrOp2)
2213  *ptrResult = *ptrOp1 * *ptrOp2;
2214  break;
2215  case '/':
2216  for (n=0, ptrResult=result.data, ptrOp1=op1.data,ptrOp2=op2.data;
2217  n<nmax; n+=unroll, ptrResult+=unroll, ptrOp1+=unroll, ptrOp2+=unroll)
2218  {
2219  *ptrResult = *ptrOp1 / *ptrOp2;
2220  *(ptrResult+1) = *(ptrOp1+1) / *(ptrOp2+1);
2221  *(ptrResult+2) = *(ptrOp1+2) / *(ptrOp2+2);
2222  *(ptrResult+3) = *(ptrOp1+3) / *(ptrOp2+3);
2223  }
2224  for (n=nmax, ptrResult=result.data+nmax, ptrOp1=op1.data+nmax, ptrOp2=op2.data+nmax;
2225  n<op1.zyxdim; ++n, ++ptrResult, ++ptrOp1, ++ptrOp2)
2226  *ptrResult = *ptrOp1 / *ptrOp2;
2227  break;
2228  }
2229  }
int * nmax
int * n

◆ coreArrayByScalar

template<typename T>
void coreArrayByScalar ( const MultidimArray< T > &  op1,
const T &  op2,
MultidimArray< T > &  result,
char  operation 
)
friend

Core array by scalar operation.

It assumes that the result is already resized.

This function is not ported to Python.

Definition at line 2448 of file multidim_array.h.

2452  {
2453  T* ptrResult=NULL;
2454  T* ptrOp1=NULL;
2455  size_t n;
2456  switch (operation)
2457  {
2458  case '+':
2459  for (n=0, ptrResult=result.data, ptrOp1=op1.data;
2460  n<op1.zyxdim; ++n, ++ptrResult, ++ptrOp1)
2461  *ptrResult = *ptrOp1 + op2;
2462  break;
2463  case '-':
2464  for (n=0, ptrResult=result.data, ptrOp1=op1.data;
2465  n<op1.zyxdim; ++n, ++ptrResult, ++ptrOp1)
2466  *ptrResult = *ptrOp1 - op2;
2467  break;
2468  case '*':
2469  for (n=0, ptrResult=result.data, ptrOp1=op1.data;
2470  n<op1.zyxdim; ++n, ++ptrResult, ++ptrOp1)
2471  *ptrResult = *ptrOp1 * op2;
2472  break;
2473  case '/':
2474  for (n=0, ptrResult=result.data, ptrOp1=op1.data;
2475  n<op1.zyxdim; ++n, ++ptrResult, ++ptrOp1)
2476  *ptrResult = *ptrOp1 / op2;
2477  break;
2478  case '=':
2479  for (n=0, ptrResult=result.data, ptrOp1=op1.data;
2480  n<op1.zyxdim; ++n, ++ptrResult, ++ptrOp1)
2481  *ptrResult = *ptrOp1 == op2;
2482  break;
2483  }
2484  }
int * n

◆ coreScalarByArray

template<typename T>
void coreScalarByArray ( const T &  op1,
const MultidimArray< T > &  op2,
MultidimArray< T > &  result,
char  operation 
)
friend

Core array by scalar operation.

It assumes that the result is already resized.

This function is not ported to Python.

Definition at line 2608 of file multidim_array.h.

2612  {
2613  T* ptrResult=NULL;
2614  T* ptrOp2=NULL;
2615  size_t n;
2616  for (n=0, ptrResult=result.data, ptrOp2=op2.data;
2617  n<op2.zyxdim; ++n, ++ptrResult, ++ptrOp2)
2618  switch (operation)
2619  {
2620  case '+':
2621  *ptrResult = op1 + *ptrOp2;
2622  break;
2623  case '-':
2624  *ptrResult = op1 - *ptrOp2;
2625  break;
2626  case '*':
2627  *ptrResult = op1 * *ptrOp2;
2628  break;
2629  case '/':
2630  *ptrResult = op1 / *ptrOp2;
2631  break;
2632  }
2633  }
int * n

◆ MultidimArrayMax

template<typename T>
void MultidimArrayMax ( const MultidimArray< T > &  v1,
const MultidimArray< T > &  v2,
MultidimArray< T > &  result 
)
friend

MAX

Each component of the result is the maximum of the correspoing components of the two input arrays. They must have the same shape, if not an exception is thrown

Definition at line 3352 of file multidim_array.h.

3354  {
3355  if (!v1.sameShape(v2))
3356  REPORT_ERROR(ERR_MULTIDIM_SIZE, "MAX: arrays of different shape");
3357 
3358  result.resizeNoCopy(v1);
3360  DIRECT_MULTIDIM_ELEM(result,n) = XMIPP_MAX(
3361  DIRECT_MULTIDIM_ELEM(v1,n),
3362  DIRECT_MULTIDIM_ELEM(v2,n));
3363  }
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void resizeNoCopy(const MultidimArray< T1 > &v)
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
bool sameShape(const MultidimArrayBase &op) const
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
int * n

◆ MultidimArrayMIN

template<typename T>
void MultidimArrayMIN ( const MultidimArray< T > &  v1,
const MultidimArray< T > &  v2,
MultidimArray< T > &  result 
)
friend

MIN

Each component of the result is the minimum of the correspoing components of the two input arrays. They must have the same shape, if not an exception is thrown

Definition at line 3371 of file multidim_array.h.

3373  {
3374  if (!v1.sameShape(v2))
3375  REPORT_ERROR(ERR_MULTIDIM_SIZE, "MIN: arrays of different shape");
3376 
3377  result.resizeNoCopy(v1);
3379  DIRECT_MULTIDIM_ELEM(result,n) = XMIPP_MIN(
3380  DIRECT_MULTIDIM_ELEM(v1,n),
3381  DIRECT_MULTIDIM_ELEM(v2,n));
3382  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void resizeNoCopy(const MultidimArray< T1 > &v)
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
bool sameShape(const MultidimArrayBase &op) const
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
#define XMIPP_MIN(x, y)
Definition: xmipp_macros.h:181
int * n

◆ operator*

template<typename T>
MultidimArray<T> operator* ( op1,
const MultidimArray< T > &  op2 
)
friend

v3 = k * v2.

Definition at line 2675 of file multidim_array.h.

2676  {
2677  MultidimArray<T> tmp;
2678  scalarByArray(op1, op2, tmp, '*');
2679  return tmp;
2680  }
friend void scalarByArray(T op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)

◆ operator+

template<typename T>
MultidimArray<T> operator+ ( op1,
const MultidimArray< T > &  op2 
)
friend

v3 = k + v2.

Definition at line 2657 of file multidim_array.h.

2658  {
2659  MultidimArray<T> tmp;
2660  scalarByArray(op1, op2, tmp, '+');
2661  return tmp;
2662  }
friend void scalarByArray(T op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)

◆ operator-

template<typename T>
MultidimArray<T> operator- ( op1,
const MultidimArray< T > &  op2 
)
friend

v3 = k - v2.

Definition at line 2666 of file multidim_array.h.

2667  {
2668  MultidimArray<T> tmp;
2669  scalarByArray(op1, op2, tmp, '-');
2670  return tmp;
2671  }
friend void scalarByArray(T op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)

◆ operator/

template<typename T>
MultidimArray<T> operator/ ( op1,
const MultidimArray< T > &  op2 
)
friend

v3 = k / v2

Definition at line 2684 of file multidim_array.h.

2685  {
2686  MultidimArray<T> tmp;
2687  scalarByArray(op1, op2, tmp, '/');
2688  return tmp;
2689  }
friend void scalarByArray(T op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)

◆ operator>>

template<typename T>
std::istream& operator>> ( std::istream &  in,
MultidimArray< T > &  v 
)
friend

Input from input stream.

Actual size of the array is used to know how many values must be read.

v.<3);
std::cin >> v;

This function is not ported to Python.

Definition at line 3705 of file multidim_array.h.

3706  {
3707  T* ptr;
3708  size_t n;
3710  in >> *ptr;
3711  return in;
3712  }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
int in
int * n

◆ scalarByArray

template<typename T>
void scalarByArray ( op1,
const MultidimArray< T > &  op2,
MultidimArray< T > &  result,
char  operation 
)
friend

Scalar by array.

This function must take one scalar and a vector, and operate element by element according to the operation required. This is the function which really implements the operations. Simple calls to it perform much faster than calls to the corresponding operators. Although it is supposed to be a hidden function not useable by normal programmers.

This function is not ported to Python.

Definition at line 2645 of file multidim_array.h.

2649  {
2650  if (result.data == NULL || !result.sameShape(op2))
2651  result.resizeNoCopy(op2);
2652  coreScalarByArray(op1, op2, result, operation);
2653  }
void resizeNoCopy(const MultidimArray< T1 > &v)
friend void coreScalarByArray(const T &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation)
bool sameShape(const MultidimArrayBase &op) const

◆ selfArrayByArrayMask

template<typename T>
void selfArrayByArrayMask ( const MultidimArray< T > &  op1,
const MultidimArray< T > &  op2,
MultidimArray< T > &  result,
char  operation,
const MultidimArray< T > *  mask = NULL 
)
friend

Self Array by array

Similar to array by array. requires 4 vectors the pixel result(i) is calculated as result(i) += op1(i), if the mask is different from zero result(i) += op2(i) * mask(i)

Definition at line 2329 of file multidim_array.h.

2333  {
2334  if (!op1.sameShape(op2) || !result.sameShape(op1))
2336  formatString("Array_by_array: different shapes (%c)", operation));
2337  selfCoreArrayByArrayMask(op1, op2, result, operation, mask);
2338  }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
bool sameShape(const MultidimArrayBase &op) const
String formatString(const char *format,...)
friend void selfCoreArrayByArrayMask(const MultidimArray< T > &op1, const MultidimArray< T > &op2, MultidimArray< T > &result, char operation, const MultidimArray< T > *mask)

◆ selfCoreArrayByArrayMask

template<typename T>
void selfCoreArrayByArrayMask ( const MultidimArray< T > &  op1,
const MultidimArray< T > &  op2,
MultidimArray< T > &  result,
char  operation,
const MultidimArray< T > *  mask 
)
friend

Core array by array operation.

It assumes that the result is already resized.

Definition at line 2235 of file multidim_array.h.

2238  {
2239  T* ptrResult=NULL;
2240  T* ptrOp1=NULL;
2241  T* ptrOp2=NULL;
2242  T* ptrMask=NULL;
2243  T zero;
2244  zero = T(0);
2245  size_t n;
2246  switch (operation)
2247  {
2248  case '+':
2249  for (n=0, ptrResult=result.data, ptrOp1=op1.data,ptrOp2=op2.data,
2250  ptrMask=mask->data;
2251  n<op1.nzyxdim; n++, ptrResult++,
2252  ptrOp1++, ptrOp2++, ptrMask++)
2253  {
2254  if ((*ptrMask)==zero)
2255  *ptrResult += (*ptrOp1);
2256  else
2257  *ptrResult += (*ptrOp2);//(*ptrOp2) * (*ptrMask);
2258  }
2259  break;
2260  case '-':
2261  for (n=0, ptrResult=result.data, ptrOp1=op1.data,ptrOp2=op2.data,
2262  ptrMask=mask->data;
2263  n<op1.nzyxdim; n++, ptrResult++,
2264  ptrOp1++, ptrOp2++, ptrMask++)
2265  {
2266  if ((*ptrMask)==zero)
2267  *ptrResult -= (*ptrOp1);
2268  else
2269  *ptrResult -= (*ptrOp2) * (*ptrMask);
2270  }
2271  break;
2272  //NOTE: not clear if this should be the default case for * and / operators
2273  case '*':
2274  for (n=0, ptrResult=result.data, ptrOp1=op1.data,ptrOp2=op2.data,
2275  ptrMask=mask->data;
2276  n<op1.nzyxdim; n++, ptrResult++,
2277  ptrOp1++, ptrOp2++, ptrMask++)
2278  {
2279  if ((*ptrMask)==zero)
2280  *ptrResult *= (*ptrOp1);
2281  else
2282  *ptrResult *= (*ptrOp2) * (*ptrMask);
2283  }
2284  break;
2285  case '/':
2286  for (n=0, ptrResult=result.data, ptrOp1=op1.data,ptrOp2=op2.data,
2287  ptrMask=mask->data;
2288  n<op1.nzyxdim; n++, ptrResult++,
2289  ptrOp1++, ptrOp2++, ptrMask++)
2290  {
2291  if ((*ptrMask)==zero)
2292  *ptrResult /= (*ptrOp1);
2293  else
2294  *ptrResult /= (*ptrOp2) * (*ptrMask);
2295  }
2296  break;
2297  }
2298  }
int * n
ql0001_ & zero(ctemp+1),(cvec+1),(a+1),(b+1),(bl+1),(bu+1),(x+1),(w+1), &iout, ifail, &zero,(w+3), &lwar2,(iw+1), &leniw, &glob_grd.epsmac

Member Data Documentation

◆ data

template<typename T>
T* MultidimArray< T >::data

Definition at line 84 of file multidim_array.h.


The documentation for this class was generated from the following files: