Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | Friends | List of all members
Phantom Class Reference

#include <phantom.h>

Collaboration diagram for Phantom:
Collaboration graph
[legend]

Public Member Functions

 Phantom ()
 
 Phantom (const FileName &fn_phantom)
 
 Phantom (const Phantom &other)
 
 ~Phantom ()
 
Phantomoperator= (const Phantom &P)
 Assignment. More...
 
void clear ()
 
int FeatNo ()
 
Featureoperator() (int i)
 
const Featureoperator() (int i) const
 
void add (Feature *f)
 
void assign (const Phantom &P)
 
void prepare ()
 Prepare for work. More...
 
double max_distance () const
 Return the maximum distance of any feature to the volume center. More...
 
double volume () const
 Return the volume of all the features. More...
 
void read (const FileName &fn_phantom, bool apply_scale=true)
 
void write (const FileName &fn_phantom="")
 
int voxel_inside_any_feat (const Matrix1D< double > &r, Matrix1D< double > &aux1, Matrix1D< double > &aux2) const
 
int voxel_inside_any_feat (const Matrix1D< double > &r) const
 
int any_feature_intersects_sphere (const Matrix1D< double > &r, double radius, Matrix1D< double > &aux1, Matrix1D< double > &aux2, Matrix1D< double > &aux3) const
 
int any_feature_intersects_sphere (const Matrix1D< double > &r, double radius) const
 
void draw_in (MultidimArray< double > &V)
 
void label (MultidimArray< double > &V)
 
void sketch_in (MultidimArray< double > &V, int clean=DONT_CLEAN, double colour=2)
 
void shift (double shiftX, double shiftY, double shiftZ)
 
void rotate (const Matrix2D< double > &E)
 
void selfApplyGeometry (const Matrix2D< double > &A, int inv)
 
void project_to (Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const Matrix2D< double > *A=nullptr) const
 
void project_to (Projection &P, double rot, double tilt, double psi, const Matrix2D< double > *A=nullptr) const
 
void project_to (Projection &P, const Matrix2D< double > &VP, double disappearing_th=1.0) const
 
void surface (double z0, double radius, int direction, Image< double > *P) const
 

Public Attributes

FileName fn
 Filename. More...
 
int xdim
 Final volume X dimension. More...
 
int ydim
 Final volume Y dimension. More...
 
int zdim
 Final volume Z dimension. More...
 
double Background_Density
 Final volume background density. More...
 
double current_scale
 Has been the scale applied? More...
 
double param_file_scale
 Param file scale. More...
 
double phantom_scale
 Param file scale. More...
 
std::vector< Feature * > VF
 List with the features. More...
 

Friends

std::ostream & operator<< (std::ostream &o, const Phantom &f)
 

Detailed Description

Phantom class. The phantom class is simply a list (STL vector) of features plus some information about the size of the final volume to generate and its background density. This is the class that will interact with the reconstruction programs as the features classes themselves haven't got enough information to generate the final volume. The file format to generate the phantom is described in the previous page (Phantoms).

This class is thought to be filled from a file, and doesn't give many facilities to update it from program. This is something to do.

Here goes an example of how to manage loops in the phantom class,

// Show all features
for (int i=1; i<=P.FeatNo(); i++) std::cout << P(i);

Definition at line 1352 of file phantom.h.

Constructor & Destructor Documentation

◆ Phantom() [1/3]

Phantom::Phantom ( )

Empty constructor. The empty phantom is 0x0x0, background density=0, no feature is inside and no name.

Definition at line 1967 of file phantom.cpp.

1968 {
1969  xdim = ydim = zdim = 0;
1970  Background_Density = 0;
1971  fn = "";
1972  current_scale = 1;
1973  phantom_scale = 1.;
1974 }
double phantom_scale
Param file scale.
Definition: phantom.h:1377
int ydim
Final volume Y dimension.
Definition: phantom.h:1362
FileName fn
Filename.
Definition: phantom.h:1356
double Background_Density
Final volume background density.
Definition: phantom.h:1368
int zdim
Final volume Z dimension.
Definition: phantom.h:1365
int xdim
Final volume X dimension.
Definition: phantom.h:1359
double current_scale
Has been the scale applied?
Definition: phantom.h:1371

◆ Phantom() [2/3]

Phantom::Phantom ( const FileName fn_phantom)
inline

Construct from a phantom file. Construct the phantom according to the specifications of the given file. The file must accomplish the structure given in Phantoms.

Definition at line 1390 of file phantom.h.

1391  {
1392  read(fn_phantom);
1393  }
void read(const FileName &fn_phantom, bool apply_scale=true)
Definition: phantom.cpp:2088

◆ Phantom() [3/3]

Phantom::Phantom ( const Phantom other)

Copy constructor. The empty phantom is 0x0x0, background density=0, no feature is inside and no name.

Definition at line 1976 of file phantom.cpp.

1977 {
1978  *this = other;
1979 }

◆ ~Phantom()

Phantom::~Phantom ( )
inline

Destructor. All features are freed.

Definition at line 1402 of file phantom.h.

1403  {
1404  clear();
1405  }
void clear()
Definition: phantom.cpp:1981

Member Function Documentation

◆ add()

void Phantom::add ( Feature f)
inline

Add a feature to the phantom. This function allows you to add new features at the end of the phantom. \ Ex: Sphere S; S.radius(); S.prepare(); Phantom.add(&S);

Definition at line 1438 of file phantom.h.

1439  {
1440  VF.push_back(f);
1441  }
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ any_feature_intersects_sphere() [1/2]

int Phantom::any_feature_intersects_sphere ( const Matrix1D< double > &  r,
double  radius,
Matrix1D< double > &  aux1,
Matrix1D< double > &  aux2,
Matrix1D< double > &  aux3 
) const

Speeded up sphere intersecting any feature. This function returns the first feature in the list intersecting a sphere with center r in R3 and the given radius. In none, 0 is returned. This speeded up function needs two vectors with dimension 3 externally resized.

Definition at line 2416 of file phantom.cpp.

2419 {
2420  bool intersects;
2421  for (size_t i = 0; i < VF.size(); i++)
2422  {
2423  intersects = VF[i]->intersects_sphere(r, radius, aux1, aux2, aux3);
2424  if (intersects)
2425  return i + 1;
2426  }
2427  return 0;
2428 }
#define i
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ any_feature_intersects_sphere() [2/2]

int Phantom::any_feature_intersects_sphere ( const Matrix1D< double > &  r,
double  radius 
) const
inline

Sphere intersecting feature. This function is based in the previous one. It makes the same but you needn't supply the auxiliar vectors.

Definition at line 1515 of file phantom.h.

1517  {
1518  Matrix1D<double> aux1(3);
1519  Matrix1D<double> aux2(3);
1520  Matrix1D<double> aux3(3);
1521  return any_feature_intersects_sphere(r, radius, aux1, aux2, aux3);
1522  }
int any_feature_intersects_sphere(const Matrix1D< double > &r, double radius, Matrix1D< double > &aux1, Matrix1D< double > &aux2, Matrix1D< double > &aux3) const
Definition: phantom.cpp:2416

◆ assign()

void Phantom::assign ( const Phantom P)

Another function for assignment.

◆ clear()

void Phantom::clear ( )

Clear the phantom. Force the phantom to be empty. All features are freed.

Definition at line 1981 of file phantom.cpp.

1982 {
1983  xdim = ydim = zdim = 0;
1984  Background_Density = 0;
1985  fn = "";
1986  for (size_t i = 0; i < VF.size(); i++)
1987  delete VF[i];
1988  VF.clear();
1989 }
int ydim
Final volume Y dimension.
Definition: phantom.h:1362
FileName fn
Filename.
Definition: phantom.h:1356
#define i
double Background_Density
Final volume background density.
Definition: phantom.h:1368
int zdim
Final volume Z dimension.
Definition: phantom.h:1365
int xdim
Final volume X dimension.
Definition: phantom.h:1359
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ draw_in()

void Phantom::draw_in ( MultidimArray< double > &  V)

Draw the phantom in the volume. The volume is cleaned, resized to the phantom size and its origin is set at the center of the volume. Then every feature is drawn into the volume

Definition at line 2432 of file phantom.cpp.

2433 {
2434  V.resize(zdim, ydim, xdim);
2435  V.setXmippOrigin();
2437  for (size_t i = 0; i < VF.size(); i++)
2438  VF[i]->draw_in(V);
2439 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
int ydim
Final volume Y dimension.
Definition: phantom.h:1362
void initConstant(T val)
#define i
void draw_in(MultidimArray< double > &V)
Definition: phantom.cpp:2432
double Background_Density
Final volume background density.
Definition: phantom.h:1368
int zdim
Final volume Z dimension.
Definition: phantom.h:1365
int xdim
Final volume X dimension.
Definition: phantom.h:1359
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ FeatNo()

int Phantom::FeatNo ( )
inline

Returns the number of features in the list.

Definition at line 1415 of file phantom.h.

1416  {
1417  return VF.size();
1418  }
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ label()

void Phantom::label ( MultidimArray< double > &  V)

Label a volume after the phantom. The volume is cleaned, resized to the phantom size and its origin is set at the center of the volume. Then every feature is drawn into the volume using different densities. Background has got density 0, the border for first feature density -1, the first feature has got density 1, the second 2 and its border -2, ...

Definition at line 2443 of file phantom.cpp.

2444 {
2445  Matrix1D<double> r(3);
2446  Matrix1D<double> aux1(3);
2447  Matrix1D<double> aux2(3);
2448  V.resize(zdim, ydim, xdim);
2449  V.setXmippOrigin();
2451  {
2452  ZZ(r) = k;
2453  YY(r) = i;
2454  XX(r) = j;
2455  int sel_feat = voxel_inside_any_feat(r, aux1, aux2);
2456  // If it is not in the background, check that it is completely
2457  // inside the feature, if not set it to border.
2458  if (sel_feat != 0)
2459  if (VF[sel_feat-1]->voxel_inside(r, aux1, aux2) != 8)
2460  sel_feat = -sel_feat;
2461  A3D_ELEM(V, k, i, j) = sel_feat;
2462  }
2463 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
int ydim
Final volume Y dimension.
Definition: phantom.h:1362
int voxel_inside_any_feat(const Matrix1D< double > &r, Matrix1D< double > &aux1, Matrix1D< double > &aux2) const
Definition: phantom.cpp:2395
#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
#define j
#define YY(v)
Definition: matrix1d.h:93
int zdim
Final volume Z dimension.
Definition: phantom.h:1365
int xdim
Final volume X dimension.
Definition: phantom.h:1359
#define ZZ(v)
Definition: matrix1d.h:101
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ max_distance()

double Phantom::max_distance ( ) const

Return the maximum distance of any feature to the volume center.

Definition at line 2070 of file phantom.cpp.

2071 {
2072  double retval = 0;
2073  for (size_t i = 0; i < VF.size(); i++)
2074  retval = XMIPP_MAX(retval, VF[i]->max_distance + VF[i]->center.module());
2075  return retval;
2076 }
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
#define i
double max_distance() const
Return the maximum distance of any feature to the volume center.
Definition: phantom.cpp:2070
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ operator()() [1/2]

Feature* Phantom::operator() ( int  i)
inline

Access to a feature pointer. You can address each one of the features using this operator, remember that features are numbered as 1, 2, ... FeatNo()

Definition at line 1423 of file phantom.h.

1424  {
1425  return VF[i-1];
1426  }
#define i
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ operator()() [2/2]

const Feature* Phantom::operator() ( int  i) const
inline

Constant Access to a feature pointer. Same as the previous one but with constant access.

Definition at line 1430 of file phantom.h.

1431  {
1432  return VF[i-1];
1433  }
#define i
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ operator=()

Phantom & Phantom::operator= ( const Phantom P)

Assignment.

Definition at line 1991 of file phantom.cpp.

1992 {
1993  if (&P == this)
1994  return *this;
1995  clear();
1996  fn = P.fn;
1997  xdim = P.xdim;
1998  ydim = P.ydim;
1999  zdim = P.zdim;
2002  Sphere *sph;
2003  Blob *blo;
2004  Gaussian *gau;
2005  Cylinder *cyl;
2006  DCylinder *dcy;
2007  Cube *cub;
2008  Ellipsoid *ell;
2009  Cone *con;
2010  for (size_t i = 0; i < P.VF.size(); i++)
2011  if (P.VF[i]->type == "sph")
2012  {
2013  sph = new Sphere;
2014  *sph = *((Sphere *) P.VF[i]);
2015  add(sph);
2016  }
2017  else if (P.VF[i]->type == "blo")
2018  {
2019  blo = new Blob;
2020  *blo = *((Blob *) P.VF[i]);
2021  add(blo);
2022  }
2023  else if (P.VF[i]->type == "gau")
2024  {
2025  gau = new Gaussian;
2026  *gau = *((Gaussian *) P.VF[i]);
2027  add(gau);
2028  }
2029  else if (P.VF[i]->type == "cyl")
2030  {
2031  cyl = new Cylinder;
2032  *cyl = *((Cylinder *) P.VF[i]);
2033  add(cyl);
2034  }
2035  else if (P.VF[i]->type == "dcy")
2036  {
2037  dcy = new DCylinder;
2038  *dcy = *((DCylinder *) P.VF[i]);
2039  add(dcy);
2040  }
2041  else if (P.VF[i]->type == "cub")
2042  {
2043  cub = new Cube;
2044  *cub = *((Cube *) P.VF[i]);
2045  add(cub);
2046  }
2047  else if (P.VF[i]->type == "ell")
2048  {
2049  ell = new Ellipsoid;
2050  *ell = *((Ellipsoid *) P.VF[i]);
2051  add(ell);
2052  }
2053  else if (P.VF[i]->type == "con")
2054  {
2055  con = new Cone;
2056  *con = *((Cone *) P.VF[i]);
2057  add(con);
2058  }
2059  return *this;
2060 }
Definition: phantom.h:1244
Definition: phantom.h:563
double phantom_scale
Param file scale.
Definition: phantom.h:1377
int ydim
Final volume Y dimension.
Definition: phantom.h:1362
FileName fn
Filename.
Definition: phantom.h:1356
#define i
Definition: phantom.h:1010
double Background_Density
Final volume background density.
Definition: phantom.h:1368
void add(Feature *f)
Definition: phantom.h:1438
int zdim
Final volume Z dimension.
Definition: phantom.h:1365
int xdim
Final volume X dimension.
Definition: phantom.h:1359
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380
void clear()
Definition: phantom.cpp:1981

◆ prepare()

void Phantom::prepare ( )

Prepare for work.

Definition at line 2063 of file phantom.cpp.

2064 {
2065  for (size_t i = 0; i < VF.size(); i++)
2066  VF[i]->prepare();
2067 }
#define i
void prepare()
Prepare for work.
Definition: phantom.cpp:2063
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ project_to() [1/3]

void Phantom::project_to ( Projection P,
int  Ydim,
int  Xdim,
double  rot,
double  tilt,
double  psi,
const Matrix2D< double > *  A = nullptr 
) const

Project phantom from a direction. The direction is specified by the 3 Euler angles (as usual, rot=1st, tilt=2nd, psi=3rd), the projection size is (Ydim x Xdim) given in the function call, the projection logical origin is set at the physical center of the image. The projection is cleaned and then the projection of the phantom is computed. A matrix A (3x3) can be supplied in order to apply a deformation in the projection plane. A must be such that

deformed position=A*undeformed position

Definition at line 2511 of file phantom.cpp.

2513 {
2514 #ifdef DEBUG
2515  std::cout << "Ydim=" << Ydim << " Xdim=" << Xdim << std::endl
2516  << "rot=" << rot << " tilt=" << tilt << " psi=" << psi << std::endl
2517  << "A\n" << A;
2518 #endif
2519  // Initialise projection
2520  P().initZeros(Ydim, Xdim);
2521  P().setXmippOrigin();
2522  P.setAngles(rot, tilt, psi);
2523 
2524  // Compute volume to Projection matrix
2525  Matrix2D<double> VP = P.euler;
2526  if (A != nullptr)
2527  VP = (*A) * VP;
2528  Matrix2D<double> PV = VP.inv();
2529  // Project all features
2530  for (size_t i = 0; i < VF.size(); i++)
2531  VF[i]->project_to(P, VP, PV);
2532 }
Matrix2D< double > euler
void inv(Matrix2D< T > &result) const
Definition: matrix2d.cpp:663
#define i
double psi(const double x)
void setAngles(double _rot, double _tilt, double _psi)
void project_to(Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const Matrix2D< double > *A=nullptr) const
Definition: phantom.cpp:2511
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ project_to() [2/3]

void Phantom::project_to ( Projection P,
double  rot,
double  tilt,
double  psi,
const Matrix2D< double > *  A = nullptr 
) const

Project phantom from a direction. The same as before but this time the projection is supposed to be already resized and with the right center. The phantom projection is added to the already drawn projection.

Definition at line 2535 of file phantom.cpp.

2537 {
2538  P.setAngles(rot, tilt, psi);
2539 
2540  // Compute volume to Projection matrix
2541  Matrix2D<double> VP = P.euler;
2542  if (A != nullptr)
2543  VP = (*A) * VP;
2544  Matrix2D<double> PV = VP.inv();
2545 
2546  // Project all features
2547  for (size_t i = 0; i < VF.size(); i++)
2548  VF[i]->project_to(P, VP, PV);
2549 }
Matrix2D< double > euler
void inv(Matrix2D< T > &result) const
Definition: matrix2d.cpp:663
#define i
double psi(const double x)
void setAngles(double _rot, double _tilt, double _psi)
void project_to(Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const Matrix2D< double > *A=nullptr) const
Definition: phantom.cpp:2511
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ project_to() [3/3]

void Phantom::project_to ( Projection P,
const Matrix2D< double > &  VP,
double  disappearing_th = 1.0 
) const

Project phantom using a conversion matrix. The same as before but this time the projection is supposed to be already resized and with the right center. The phantom projection is added to the already drawn projeciton. Euler angles of the projection are not set and the phantom volume is projected to the projection plane making use of the matrix provided (3x3) which is the needed transformation from the volume to the projection plane. Inside the projection plane only the first two coordinates are valid. If disappearing_th < 1 then the ith phantom feature is skiped with a provability = 1-disappearing_th

Definition at line 2551 of file phantom.cpp.

2552 {
2553  Matrix2D<double> PV = VP.inv();
2554 
2555  // Project all features
2556  for (size_t i = 0; i < VF.size(); i++)
2557  {
2558  if (rnd_unif(0, 1) < disappearing_th)
2559  VF[i]->project_to(P, VP, PV);
2560  }
2561 }
void inv(Matrix2D< T > &result) const
Definition: matrix2d.cpp:663
#define i
double rnd_unif()
void project_to(Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const Matrix2D< double > *A=nullptr) const
Definition: phantom.cpp:2511
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ read()

void Phantom::read ( const FileName fn_phantom,
bool  apply_scale = true 
)

Read a phantom file. The file must accomplish the structure given in Phantoms .

If you don't apply the scale then all spatial coordinates are expressed in the given scale units. I.e., if the scale is 0.25 that means that every voxel in the voxel phantom represent 4 length units (usually Angstroms). If the scale is applied, then coordinates are expressed in voxel edge units. Otherwise, coordinates are expressed in length units (usually Angstroms).

We recommend apply_scale=false only if you plan to modify the description file without produstd::cing projections, voxel phantoms, ...

Definition at line 2088 of file phantom.cpp.

2089 {
2090 
2091  FILE *fh_phantom;
2092  char line[256];
2093  int Global_Feature_Read = 0; // Indicates if the line with volume dimensions
2094  // has been already read
2095  int stat;
2096  Sphere *sph;
2097  Blob *blo;
2098  Gaussian *gau;
2099  Cylinder *cyl;
2100  DCylinder *dcy;
2101  Cube *cub;
2102  Ellipsoid *ell;
2103  Cone *con;
2104  Feature *feat;
2105  Feature *scaled_feat;
2106  std::string feat_type;
2107  double scale = 1.; // The scale factor is not stored
2108  char straux[6];
2109 
2110  // Clear actual phantom
2111  clear();
2112 
2113  if (fn_phantom.isMetaData())
2114  {
2115  MetaDataVec MD1; //MetaData for the first block (phantom parameters)
2116  MetaDataVec MD2; //MetaData for the second block (phantom parameters)
2117  std::vector <double> TempVec; // A temporary vector for reading vector data
2118  size_t objId;
2119 
2120  // Assign different blocks to different MetaDatas
2121  MD1.read((std::string)"block1@"+fn_phantom.c_str());
2122  MD2.read((std::string)"block2@"+fn_phantom.c_str());
2123 
2124  // Read the first block containing parameters of phantom
2125  objId = MD1.firstRowId();
2126  MD1.getValue(MDL_DIMENSIONS_3D, TempVec, objId);
2127  if (TempVec.size()<3)
2128  REPORT_ERROR(ERR_ARG_MISSING, MDL::label2Str(MDL_DIMENSIONS_3D) + " problems with project dimensions");
2129  xdim = (int)TempVec[0];
2130  ydim = (int)TempVec[1];
2131  zdim = (int)TempVec[2];
2133  Background_Density = 0;
2134  if (!MD1.getValue(MDL_SCALE, scale, objId))
2135  scale = 1;
2136  if (apply_scale)
2137  {
2138  xdim = (int) CEIL(scale * xdim);
2139  ydim = (int) CEIL(scale * ydim);
2140  zdim = (int) CEIL(scale * zdim);
2141  current_scale = 1;
2142  }
2143  else
2144  current_scale = scale;
2145 
2146  // Read the second block
2147  for (auto& FeatureRow: MD2)
2148  {
2149  if(!FeatureRow.getValue(MDL_PHANTOM_FEATURE_TYPE, feat_type))
2150  REPORT_ERROR(ERR_ARG_MISSING, MDL::label2Str(MDL_PHANTOM_FEATURE_TYPE) + " feature type not present");
2151  if (feat_type == "sph")
2152  {
2153  sph = new Sphere;
2154  feat = sph;
2155  sph->read(FeatureRow);
2156  }
2157  else if (feat_type == "blo")
2158  {
2159  blo = new Blob;
2160  feat = blo;
2161  blo->read(FeatureRow);
2162  }
2163  else if (feat_type == "gau")
2164  {
2165  gau = new Gaussian;
2166  feat = gau;
2167  gau->read(FeatureRow);
2168  }
2169  else if (feat_type == "cyl")
2170  {
2171  cyl = new Cylinder;
2172  feat = cyl;
2173  cyl->read(FeatureRow);
2174  }
2175  else if (feat_type == "dcy")
2176  {
2177  dcy = new DCylinder;
2178  feat = dcy;
2179  dcy->read(FeatureRow);
2180  }
2181  else if (feat_type == "cub")
2182  {
2183  cub = new Cube;
2184  feat = cub;
2185  cub->read(FeatureRow);
2186  }
2187  else if (feat_type == "ell")
2188  {
2189  ell = new Ellipsoid;
2190  feat = ell;
2191  ell->read(FeatureRow);
2192  }
2193  else if (feat_type == "con")
2194  {
2195  con = new Cone;
2196  feat = con;
2197  con->read(FeatureRow);
2198  }
2199  else
2201  if (apply_scale)
2202  {
2203  scaled_feat = feat->scale(scale);
2204  scaled_feat->center = scaled_feat->center * scale;
2205  delete feat;
2206 
2207  // Store feature
2208  VF.push_back(scaled_feat);
2209  }
2210  else
2211  VF.push_back(feat);
2212  }
2213  }
2214  else
2215  {
2216  // Open Volume Description File
2217  if ((fh_phantom = fopen(fn_phantom.c_str(), "r")) == nullptr)
2218  REPORT_ERROR(ERR_IO_NOTOPEN, (std::string)"Phantom::read: Cannot open the phantom file: "
2219  + fn_phantom);
2220  fn = fn_phantom;
2221 
2222  size_t lineNumber = 0;
2223  // Read the file
2224  while (fgets(line, 256, fh_phantom) != nullptr)
2225  {
2226  ++lineNumber;
2227  if (line[0] == 0)
2228  continue;
2229  if (line[0] == '#')
2230  continue;
2231  if (line[0] == '\n')
2232  continue;
2233 
2234  // Read volume dimensions and global density .........................
2235  if (Global_Feature_Read == 0)
2236  {
2237  Global_Feature_Read = 1;
2238  stat = sscanf(line, "%d %d %d %lf %lf", &xdim, &ydim, &zdim,
2239  &Background_Density, &scale);
2240  if (stat < 3)
2241  REPORT_ERROR(ERR_IO_NOREAD, "Phantom::read: check the volume"
2242  " dimensions and global density in volume description file");
2243  if (stat <= 3)
2244  Background_Density = 0;
2245  if (stat <= 4)
2246  scale = 1;
2247  if (apply_scale)
2248  {
2249  xdim = (int) CEIL(scale * xdim);
2250  ydim = (int) CEIL(scale * ydim);
2251  zdim = (int) CEIL(scale * zdim);
2252  current_scale = 1;
2253  }
2254  else
2255  current_scale = scale;
2256  continue;
2257  }
2258 
2259  // Read feature description ..........................................
2260  stat = sscanf(line, "%s", straux);
2261  feat_type = straux;
2262  if (stat != 1)
2263  REPORT_ERROR(ERR_IO_NOREAD, formatString("Phantom::read: Not correct feature type in line number %ld : \n%s",lineNumber, line));
2264 
2265  if (feat_type == "sph")
2266  {
2267  sph = new Sphere;
2268  feat = sph;
2269  sph->readCommon(line);
2270  sph->read_specific(line);
2271  }
2272  else if (feat_type == "blo")
2273  {
2274  blo = new Blob;
2275  feat = blo;
2276  blo->readCommon(line);
2277  blo->read_specific(line);
2278  }
2279  else if (feat_type == "gau")
2280  {
2281  gau = new Gaussian;
2282  feat = gau;
2283  gau->readCommon(line);
2284  gau->read_specific(line);
2285  }
2286  else if (feat_type == "cyl")
2287  {
2288  cyl = new Cylinder;
2289  feat = cyl;
2290  cyl->readCommon(line);
2291  cyl->read_specific(line);
2292  }
2293  else if (feat_type == "dcy")
2294  {
2295  dcy = new DCylinder;
2296  feat = dcy;
2297  dcy->readCommon(line);
2298  dcy->read_specific(line);
2299  }
2300  else if (feat_type == "cub")
2301  {
2302  cub = new Cube;
2303  feat = cub;
2304  cub->readCommon(line);
2305  cub->read_specific(line);
2306  }
2307  else if (feat_type == "ell")
2308  {
2309  ell = new Ellipsoid;
2310  feat = ell;
2311  ell->readCommon(line);
2312  ell->read_specific(line);
2313  }
2314  else if (feat_type == "con")
2315  {
2316  con = new Cone;
2317  feat = con;
2318  con->readCommon(line);
2319  con->read_specific(line);
2320  }
2321  else
2322  REPORT_ERROR(ERR_IO_NOREAD, (std::string)"Phantom::read: Unknown feature type: " + line);
2323 
2324  // Scale and Store feature
2325  if (apply_scale)
2326  {
2327  scaled_feat = feat->scale(scale);
2328  scaled_feat->center = scaled_feat->center * scale;
2329  delete feat;
2330 
2331  // Store feature
2332  VF.push_back(scaled_feat);
2333  }
2334  else
2335  VF.push_back(feat);
2336  }
2337  fclose(fh_phantom);
2338  phantom_scale = scale;
2339  }
2340 }
Argument missing.
Definition: xmipp_error.h:114
Definition: phantom.h:1244
Definition: phantom.h:563
double phantom_scale
Param file scale.
Definition: phantom.h:1377
int ydim
Final volume Y dimension.
Definition: phantom.h:1362
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void readCommon(char *line)
Definition: phantom.cpp:177
void read_specific(char *line)
Definition: phantom.cpp:264
void read(MDRow &row)
Definition: phantom.cpp:213
void read_specific(char *line)
Definition: phantom.cpp:222
Matrix1D< double > center
Definition: phantom.h:119
void read_specific(char *line)
Definition: phantom.cpp:332
FileName fn
Filename.
Definition: phantom.h:1356
void read_specific(char *line)
Definition: phantom.cpp:382
#define CEIL(x)
Definition: xmipp_macros.h:225
Incorrect argument received.
Definition: xmipp_error.h:113
size_t firstRowId() const override
Definition: phantom.h:1010
virtual Feature * scale(double factor) const =0
double Background_Density
Final volume background density.
Definition: phantom.h:1368
void read_specific(char *line)
Definition: phantom.cpp:308
Couldn&#39;t read from file.
Definition: xmipp_error.h:139
scaling factor for an image or volume (double)
Phantom background density (double)
void read_specific(char *line)
Definition: phantom.cpp:239
Type of the feature (Sphere, Blob, ...) (std::string)
void read_specific(char *line)
Definition: phantom.cpp:283
bool getValue(MDObject &mdValueOut, size_t id) const override
File cannot be open.
Definition: xmipp_error.h:137
int zdim
Final volume Z dimension.
Definition: phantom.h:1365
bool isMetaData(bool failIfNotExists=true) const
int xdim
Final volume X dimension.
Definition: phantom.h:1359
String formatString(const char *format,...)
double current_scale
Has been the scale applied?
Definition: phantom.h:1371
static String label2Str(const MDLabel &label)
void read_specific(char *line)
Definition: phantom.cpp:357
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380
void clear()
Definition: phantom.cpp:1981

◆ rotate()

void Phantom::rotate ( const Matrix2D< double > &  E)

Rotate. Rotate a phantom after a given 3D rotation.

Definition at line 2486 of file phantom.cpp.

2487 {
2488  for (size_t i = 0; i < VF.size(); i++)
2489  VF[i]->rotate(E);
2490 }
void rotate(const Matrix2D< double > &E)
Definition: phantom.cpp:2486
#define i
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ selfApplyGeometry()

void Phantom::selfApplyGeometry ( const Matrix2D< double > &  A,
int  inv 
)

Apply a general geometric transformation. The transformation must be defined by a 4x4 matrix that can be generated using the geometric functions in xmippGeometry or xmippMatrix2D. The inv argument is either IS_INV or IS_NOT_INV. Matrices coming out from xmippGeometry for rotations, shifts, ... are not INV.

An exception is thrown if the matrix A is not valid.

Definition at line 2493 of file phantom.cpp.

2494 {
2495  if ((MAT_XSIZE(A) != 4) || (MAT_YSIZE(A) != 4))
2496  REPORT_ERROR(ERR_MATRIX_SIZE, "Apply_geom3D: geometrical transformation is not 4x4");
2497  if (A.isIdentity())
2498  return;
2499  Matrix2D<double> T;
2500  if (inv == xmipp_transformation::IS_INV)
2501  T = A.inv();
2502  else
2503  T = A;
2504 
2505  for (size_t i = 0; i < VF.size(); i++)
2506  VF[i]->selfApplyGeometry(T);
2507 }
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
bool isIdentity() const
Definition: matrix2d.cpp:1323
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Problem with matrix size.
Definition: xmipp_error.h:152
void inv(Matrix2D< T > &result) const
Definition: matrix2d.cpp:663
#define i
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
void selfApplyGeometry(const Matrix2D< double > &A, int inv)
Definition: phantom.cpp:2493
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ shift()

void Phantom::shift ( double  shiftX,
double  shiftY,
double  shiftZ 
)

Shift. Shift all features in the phantom a given amount of voxels. See Feature::shift.

Definition at line 2479 of file phantom.cpp.

2480 {
2481  for (size_t i = 0; i < VF.size(); i++)
2482  VF[i]->shift(shiftX, shiftY, shiftZ);
2483 }
void shift(double shiftX, double shiftY, double shiftZ)
Definition: phantom.cpp:2479
#define i
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ sketch_in()

void Phantom::sketch_in ( MultidimArray< double > &  V,
int  clean = DONT_CLEAN,
double  colour = 2 
)

Sketch the surface of the phantom in the volume. This function allows you to draw only the surface of every feature (see Feature::sketch_in to see when a voxel is said to belong to the feature surface). The input volume might be cleaned (resized and the logical origin set at the physical center) or not according to the labels CLEAN or DONT_CLEAN (by default). The grey level for those voxels can be defined (by default, 2) and the colour is assigned

Definition at line 2467 of file phantom.cpp.

2468 {
2469  if (clean)
2470  {
2471  V.resize(zdim, ydim, xdim);
2472  V.setXmippOrigin();
2473  }
2474  for (size_t i = 0; i < VF.size(); i++)
2475  VF[i]->sketch_in(V, colour);
2476 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
int ydim
Final volume Y dimension.
Definition: phantom.h:1362
void sketch_in(MultidimArray< double > &V, int clean=DONT_CLEAN, double colour=2)
Definition: phantom.cpp:2467
#define i
int zdim
Final volume Z dimension.
Definition: phantom.h:1365
int xdim
Final volume X dimension.
Definition: phantom.h:1359
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ surface()

void Phantom::surface ( double  z0,
double  radius,
int  direction,
Image< double > *  P 
) const

Surface of the phantom as in AFM. This function produces the surface of a phantom in a given image when measuring rays go POS_NEG or NEG_POS (from Z positive to Z negative, and viceversa). If rays reach point z0 and the phantom is not reached the surface for that point is z0, otherwise it is the z of the last voxel which is still outside the phantom.

This function throws an exception if z0 is outside the volume definition. If z0 is equal to zdim then it is not used.

The radius is the probe radius for the surface generation.

If the output image is not resized, it is resized to the Y and X dimensions of the phantom.

Definition at line 2565 of file phantom.cpp.

2567 {
2568  if (z0 != zdim)
2570  REPORT_ERROR(ERR_INDEX_OUTOFBOUNDS, "Phantom::surface: z0 outside phantom");
2571 #ifdef DEBUG
2572 
2573  std::cout << "Direction: " << direction << std::endl;
2574  std::cout << "z0: " << z0 << std::endl;
2575  std::cout << "zdim: " << zdim << std::endl;
2576 #endif
2577 
2578  Matrix1D<double> aux1(3);
2579  Matrix1D<double> aux2(3);
2580  Matrix1D<double> aux3(3);
2581  Matrix1D<double> r(3);
2582  if (XSIZE((*P)()) == 0)
2583  {
2584  (*P)().resize(ydim, xdim);
2585  (*P)().setXmippOrigin();
2586  }
2588  {
2589 #ifdef DEBUG
2590  std::cout << "Processing (" << i << "," << j << ")" << std::endl;
2591 #endif
2592  // Init ray
2593  int k;
2594  if (direction == POS_NEG)
2595  k = LAST_XMIPP_INDEX(zdim) + 1;
2596  else
2597  k = FIRST_XMIPP_INDEX(zdim) - 1;
2598  bool finished;
2599  finished = false;
2600 
2601 #ifdef DEBUG
2602 
2603  std::cout << "Initial k=" << k << std::endl;
2604 #endif
2605  // Check that it is not inside and move ray
2606  // at the end k takes the right value for the image
2607  while (!finished)
2608  {
2609  VECTOR_R3(r, j, i, k);
2610 #ifdef DEBUG
2611 
2612  std::cout << "Checking " << r.transpose() << std::endl;
2613 #endif
2614  // If it is inside move a step backward and finish
2615  if (any_feature_intersects_sphere(r, radius, aux1, aux2, aux3))
2616  {
2617  finished = true;
2618  if (direction == POS_NEG)
2619  k++;
2620  else
2621  k--;
2622  }
2623  else
2624  {
2625  // Else, move until you find z0
2626  if (z0 != zdim)
2627  if (direction == POS_NEG)
2628  {
2629  k--;
2630  if (k < z0)
2631  {
2632  finished = true;
2633  k = CEIL(z0);
2634  }
2635  }
2636  else
2637  {
2638  k++;
2639  if (k > z0)
2640  {
2641  finished = true;
2642  k = FLOOR(z0);
2643  }
2644  }
2645  // or you reach the end of the volume
2646  else
2647  if (direction == POS_NEG)
2648  {
2649  k--;
2650  if (k < FIRST_XMIPP_INDEX(zdim))
2651  {
2652  finished = true;
2653  }
2654  }
2655  else
2656  {
2657  k++;
2658  if (k > LAST_XMIPP_INDEX(zdim))
2659  {
2660  finished = true;
2661  }
2662  }
2663  }
2664  }
2665 
2666  IMGPIXEL(*P, i, j) = k;
2667  }
2668 }
Index out of bounds.
Definition: xmipp_error.h:132
int ydim
Final volume Y dimension.
Definition: phantom.h:1362
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define z0
#define IMGMATRIX(I)
#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 FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
int any_feature_intersects_sphere(const Matrix1D< double > &r, double radius, Matrix1D< double > &aux1, Matrix1D< double > &aux2, Matrix1D< double > &aux3) const
Definition: phantom.cpp:2416
#define FLOOR(x)
Definition: xmipp_macros.h:240
#define CEIL(x)
Definition: xmipp_macros.h:225
#define XSIZE(v)
void direction(const MultidimArray< double > &orMap, MultidimArray< double > &qualityMap, double lambda, int size, MultidimArray< double > &dirMap, int x, int y)
#define j
#define POS_NEG
Definition: phantom.h:1604
int zdim
Final volume Z dimension.
Definition: phantom.h:1365
#define FIRST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:439
int xdim
Final volume X dimension.
Definition: phantom.h:1359
#define VECTOR_R3(v, x, y, z)
Definition: matrix1d.h:124
#define LAST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:448
#define IMGPIXEL(I, i, j)

◆ volume()

double Phantom::volume ( ) const

Return the volume of all the features.

Definition at line 2079 of file phantom.cpp.

2080 {
2081  double retval = 0;
2082  for (size_t i = 0; i < VF.size(); i++)
2083  retval += VF[i]->volume();
2084  return retval;
2085 }
double volume() const
Return the volume of all the features.
Definition: phantom.cpp:2079
#define i
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ voxel_inside_any_feat() [1/2]

int Phantom::voxel_inside_any_feat ( const Matrix1D< double > &  r,
Matrix1D< double > &  aux1,
Matrix1D< double > &  aux2 
) const

Speeded up voxel inside any feature. This function tells you if the voxel of size 1x1x1 whose center is at position r is inside any of the features. A voxel is said to be inside a feature if it shares at least 1 corner with the feature. This function returns the first feature of the list containing the voxel. Features are numbered as 1, 2, ... If the voxel is not in any feature the function returns 0.

aux1 and aux2, are two vectors of dimension 3. They must be supplied in order to gain speed in the calculations. This is very useful when checking if many voxels are inside any feature. See also Feature::voxel_inside to know more.

Definition at line 2395 of file phantom.cpp.

2397 {
2398  int inside;
2399  int current_i;
2400  double current_density;
2401  current_i = 0;
2402  current_density = Background_Density;
2403  for (size_t i = 0; i < VF.size(); i++)
2404  {
2405  inside = VF[i]->voxel_inside(r, aux1, aux2);
2406  if (inside != 0 && VF[i]->density > current_density)
2407  {
2408  current_i = i + 1;
2409  current_density = VF[i]->density;
2410  }
2411  }
2412  return current_i;
2413 }
#define i
double Background_Density
Final volume background density.
Definition: phantom.h:1368
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

◆ voxel_inside_any_feat() [2/2]

int Phantom::voxel_inside_any_feat ( const Matrix1D< double > &  r) const
inline

Voxel inside any feature. The same as the previous one but you needn't supply the extra auxiliar vectors.

Definition at line 1495 of file phantom.h.

1496  {
1497  Matrix1D<double> aux1(3);
1498  Matrix1D<double> aux2(3);
1499  return voxel_inside_any_feat(r, aux1, aux2);
1500  }
int voxel_inside_any_feat(const Matrix1D< double > &r, Matrix1D< double > &aux1, Matrix1D< double > &aux2) const
Definition: phantom.cpp:2395

◆ write()

void Phantom::write ( const FileName fn_phantom = "")

Write a phantom file in the standard feature format. You may rename the file or not giving a different name in the write call.

Definition at line 2355 of file phantom.cpp.

2356 {
2357  MetaDataVec MD1; //MetaData for phanto global parameters
2358  MetaDataVec MD2; //MetaData for Feature parameters
2359  std::vector<double> FCVect(3); //For the center of feature
2360  size_t id;
2361  // Write global parameters to the first block
2362  std::vector<double> PCVector; //For the center of Phantom
2363  MD1.setColumnFormat(false);
2364  id = MD1.addObject();
2365  PCVector.push_back(xdim);
2366  PCVector.push_back(ydim);
2367  PCVector.push_back(zdim);
2368  MD1.setValue(MDL_DIMENSIONS_3D, PCVector, id);
2370  if (current_scale != 1)
2371  MD1.setValue(MDL_SCALE, current_scale, id);
2372  else
2373  MD1.setValue(MDL_SCALE, 1.0, id);
2374  MD1.write((std::string)"block1@"+fn_phantom.c_str(), MD_OVERWRITE);
2375 
2376  // Write specific parameters
2377  std::string SAddAssign; // string variab for feature operation (+/=)
2378  for (size_t i = 0; i < VF.size(); i++)
2379  {
2380  id = MD2.addObject();
2381  SAddAssign = VF[i]->add_assign;
2383  MD2.setValue(MDL_PHANTOM_FEATURE_OPERATION, SAddAssign, id);
2384  MD2.setValue(MDL_PHANTOM_FEATURE_DENSITY, VF[i]->density, id);
2385  FCVect[0] = XX(VF[i]->center);
2386  FCVect[1] = YY(VF[i]->center);
2387  FCVect[2] = ZZ(VF[i]->center);
2388  MD2.setValue(MDL_PHANTOM_FEATURE_CENTER, FCVect, id);
2389  VF[i]->feat_printm(MD2, id);
2390  }
2391  MD2.write((std::string)"block2@"+fn_phantom.c_str(), MD_APPEND);
2392 }
int ydim
Final volume Y dimension.
Definition: phantom.h:1362
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
#define i
The density of the feature (double)
#define XX(v)
Definition: matrix1d.h:85
viol type
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
double Background_Density
Final volume background density.
Definition: phantom.h:1368
scaling factor for an image or volume (double)
Phantom background density (double)
Type of the feature (Sphere, Blob, ...) (std::string)
#define YY(v)
Definition: matrix1d.h:93
Operation in case of overlapping features (+,-)
Center of the feature (vector double)
int zdim
Final volume Z dimension.
Definition: phantom.h:1365
virtual void setColumnFormat(bool column)
int xdim
Final volume X dimension.
Definition: phantom.h:1359
double current_scale
Has been the scale applied?
Definition: phantom.h:1371
#define ZZ(v)
Definition: matrix1d.h:101
std::vector< Feature * > VF
List with the features.
Definition: phantom.h:1380

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  o,
const Phantom f 
)
friend

Show a phantom file. The more descriptive format is used instead of the standard Feature format

Definition at line 2343 of file phantom.cpp.

2344 {
2345  std::cout << "Phantom ---------------------------------------\n";
2346  std::cout << "Dimensions: " << P.xdim << " x " << P.ydim << " x " << P.zdim << std::endl;
2347  std::cout << "Background density: " << P.Background_Density << std::endl;
2348  std::cout << "phantom_scale : " << P.phantom_scale << std::endl;
2349  for (size_t i = 0; i < P.VF.size(); i++)
2350  o << P.VF[i];
2351  return o;
2352 }
#define i

Member Data Documentation

◆ Background_Density

double Phantom::Background_Density

Final volume background density.

Definition at line 1368 of file phantom.h.

◆ current_scale

double Phantom::current_scale

Has been the scale applied?

Definition at line 1371 of file phantom.h.

◆ fn

FileName Phantom::fn

Filename.

Definition at line 1356 of file phantom.h.

◆ param_file_scale

double Phantom::param_file_scale

Param file scale.

Definition at line 1374 of file phantom.h.

◆ phantom_scale

double Phantom::phantom_scale

Param file scale.

Definition at line 1377 of file phantom.h.

◆ VF

std::vector<Feature*> Phantom::VF

List with the features.

Definition at line 1380 of file phantom.h.

◆ xdim

int Phantom::xdim

Final volume X dimension.

Definition at line 1359 of file phantom.h.

◆ ydim

int Phantom::ydim

Final volume Y dimension.

Definition at line 1362 of file phantom.h.

◆ zdim

int Phantom::zdim

Final volume Z dimension.

Definition at line 1365 of file phantom.h.


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