Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members
ProgAngularDistributionShow Class Reference
Inheritance diagram for ProgAngularDistributionShow:
Inheritance graph
[legend]
Collaboration diagram for ProgAngularDistributionShow:
Collaboration graph
[legend]

Public Member Functions

void readParams ()
 
void defineParams ()
 
void run ()
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void show () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

FileName fnIn
 
FileName fnOut
 
String type
 
double R
 
double rmax
 
int shift_center
 
int solid_sphere
 
int steps
 
double rot_view
 
double tilt_view
 
bool up_down_correction
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

Definition at line 34 of file angular_distribution_show.cpp.

Member Function Documentation

◆ defineParams()

void ProgAngularDistributionShow::defineParams ( )
inlinevirtual

Function in which the param of each Program are defined.

Reimplemented from XmippProgram.

Definition at line 68 of file angular_distribution_show.cpp.

69  {
70  addUsageLine("Shows which is the angular distribution of a set of projections.");
71  addUsageLine("+There are three kinds of outputs: a bild file (chimera understands this format), a distance histogram and a postscript file. ");
72  addUsageLine("+In postcript, each projection is represented by a small isosceles triangles (the longest part is pointing to Y in the projection plane). ");
73  addUsageLine("+In chimera, each projection direction has a sphere whose radius is proportional to the number of images assigned to it");
74  addUsageLine("+The histogram output is the histogram of the minimum distance (in degrees) among projections. The distance is measured on the sphere surface. This gives an idea of how compact is the angular distribution.");
75  addParamsLine(" -i <metadata> : Metadata file with the angles");
76  addParamsLine(" -o <file> <type> : Output file");
77  addParamsLine(" where <type>");
78  addParamsLine(" chimera <R=60> <rmax=1.5> <shift_center=0> : R=sphere radius, rmax=maximum point radius, shift_center=shift in pixels applied to all coordinates");
79  addParamsLine(" : shift_center should be half the volume size and R should be 2/3 the volume size");
80  addParamsLine(" ps <R=60> <rmax=1.5> <rot=0> <tilt=30> <solid_sphere=0> : R=sphere radius, rmax=maximum point radius, rot and tilt defines the point of view, solid_sphere=0 (=no) or 1 (=yes)");
81  addParamsLine(" : If the sphere is solid, projections in the back plane are not shown");
82  addParamsLine(" histogram <stepno=100> : Number of divisions in the histogram");
83  addParamsLine("[--up_down_correction] : correct angles so that a semisphere is shown");
84  }
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ readParams()

void ProgAngularDistributionShow::readParams ( )
inlinevirtual

Function in which each program will read parameters that it need. If some error occurs the usage will be printed out.

Reimplemented from XmippProgram.

Definition at line 44 of file angular_distribution_show.cpp.

45  {
46  fnIn = getParam("-i");
47  fnOut = getParam("-o");
48  type = getParam("-o",1);
49  if (type=="chimera")
50  {
51  R=getDoubleParam("-o",2);
52  rmax=getDoubleParam("-o",3);
53  shift_center=getIntParam("-o",4);
54  }
55  else if (type=="ps")
56  {
57  R=getDoubleParam("-o",2);
58  rmax=getDoubleParam("-o",3);
59  rot_view=getDoubleParam("-o",4);
60  tilt_view=getDoubleParam("-o",5);
61  solid_sphere=getIntParam("-o",6);
62  }
63  else if (type=="histogram")
64  steps = getIntParam("-o",2);
65  up_down_correction = checkParam("--up_down_correction");
66  }
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
bool checkParam(const char *param)
int getIntParam(const char *param, int arg=0)

◆ run()

void ProgAngularDistributionShow::run ( )
inlinevirtual

This function will be start running the program. it also should be implemented by derived classes.

Reimplemented from XmippProgram.

Definition at line 86 of file angular_distribution_show.cpp.

87  {
88  // Get angles ==============================================================
89  MetaDataVec angles;
90  angles.read(fnIn);
91  size_t AngleNo = angles.size();
92  if (AngleNo == 0 || !angles.containsLabel(MDL_ANGLE_ROT))
93  REPORT_ERROR(ERR_MD_BADLABEL, "Input file doesn't contain angular information");
94 
95  double maxWeight = -99.e99;
96  MultidimArray<double> weight;
97  weight.initZeros(AngleNo);
98  if (angles.containsLabel(MDL_WEIGHT))
99  {
100  // Find maximum weight
101  int i=0;
102  for (size_t objId : angles.ids())
103  {
104  double w;
105  angles.getValue(MDL_WEIGHT,w,objId);
106  DIRECT_A1D_ELEM(weight,i++)=w;
107  maxWeight=XMIPP_MAX(w,maxWeight);
108  }
109  }
110  double imaxWeight=1.0/maxWeight;
111 
112  // Build vector tables ======================================================
113  std::vector< Matrix1D<double> > v, v_ang;
114  v.reserve(AngleNo);
115  v_ang.reserve(AngleNo);
116  Matrix1D<double> aux(3);
117  Matrix1D<double> aux_ang(3);
118  for (size_t objId : angles.ids())
119  {
120  double rot, tilt, psi;
121  angles.getValue(MDL_ANGLE_ROT,rot,objId);
122  angles.getValue(MDL_ANGLE_TILT,tilt,objId);
123  angles.getValue(MDL_ANGLE_PSI,psi,objId);
124  if (up_down_correction && fabs(tilt)>90)
125  \
126  Euler_up_down(rot,tilt,psi,rot,tilt,psi);
127  Euler_direction(rot, tilt, psi, aux);
128  v.push_back(aux);
129  VECTOR_R3(aux_ang, rot, tilt, psi);
130  v_ang.push_back(aux_ang);
131  }
132 
133  if (type=="histogram")
134  {
135  // Compute minimum distance table
137  dist.initZeros(AngleNo);
138  for (size_t i = 0; i < AngleNo; i++)
139  {
140  const Matrix1D<double> &vi=v[i];
141  for (size_t j = i + 1; j < AngleNo; j++)
142  {
143  const Matrix1D<double> &vj=v[j];
144  // Since the two vectors are in the unit sphere, the spherical distance
145  // is simply the arc cosine
146  double d = acos(XX(vi)*XX(vj) + YY(vi)*YY(vj) + ZZ(vi)*ZZ(vj));
147  d=RAD2DEG(d);
148  if (DIRECT_A1D_ELEM(dist,i) == 0 || d < DIRECT_A1D_ELEM(dist,i))
149  DIRECT_A1D_ELEM(dist,i) = d;
150  if (DIRECT_A1D_ELEM(dist,j) == 0 || d < DIRECT_A1D_ELEM(dist,j))
151  DIRECT_A1D_ELEM(dist,j) = d;
152  }
153  }
154 
155  Histogram1D dist_hist;
156  compute_hist(dist, dist_hist, steps);
157  dist_hist.write(fnOut);
158  }
159  else if (type=="chimera")
160  {
161  std::ofstream fh_bild;
162  fh_bild.open(fnOut.c_str(), std::ios::out);
163  if (!fh_bild)
165  fh_bild << ".color 1 0 0" << std::endl;
166 
167  int imax=v.size();
168  for (int i=0; i<imax; i++)
169  {
170  double r=rmax;
171  if (maxWeight>0)
172  r *= DIRECT_A1D_ELEM(weight,i)*imaxWeight;
173  fh_bild
174  << ".sphere "
175  << R*XX(v[i]) + shift_center << " "
176  << R*YY(v[i]) + shift_center << " "
177  << R*ZZ(v[i]) + shift_center << " "
178  << r
179  <<"\n";
180  }
181  fh_bild.close();
182  }
183  else if (type=="ps")
184  {
185  std::ofstream fh_ps;
186  fh_ps.open(fnOut.c_str(), std::ios::out);
187  if (!fh_ps)
189 
190  fh_ps << "%%!PS-Adobe-2.0\n";
191  fh_ps << "%% Creator: Angular Distribution\n";
192  fh_ps << "%% Title: Angular distribution of " << fnIn << "\n";
193  fh_ps << "%% Pages: 1\n";
194 
195 #define TO_PS(x,y) \
196  tmp=y; \
197  y=400.0f-x*250.0f/60; \
198  x=300.0f+tmp*250.0f/60;
199 
200  Matrix1D<double> p0(4), p1(4), p2(4), p3(4), view_direction, pp(3);
201  Matrix2D<double> A, euler_view;
202  Euler_angles2matrix(rot_view, tilt_view, 0., euler_view);
203  euler_view.getRow(2, view_direction);
204  double tmp;
205  int imax=v.size();
206  for (int i=0; i<imax; i++)
207  {
208  double r=rmax;
209  if (maxWeight>0)
210  r *= DIRECT_A1D_ELEM(weight,i)*imaxWeight;
211 
212  // Initially the triangle is on the floor of the projection plane
213  VECTOR_R3(p0, 0 , 0 , 0);
214  VECTOR_R3(p1, 0 , r*2 / 3*SIND(60), 0);
215  VECTOR_R3(p2, r / 2*0.6, -r*1 / 3*SIND(60), 0);
216  VECTOR_R3(p3, -r / 2*0.6, -r*1 / 3*SIND(60), 0);
217 
218  // Convert to homogeneous coordinates
219  p0(3) = 1;
220  p1(3) = 1;
221  p2(3) = 1;
222  p3(3) = 1;
223 
224  // Compute Transformation matrix
225  const Matrix1D<double> &v_angi=v_ang[i];
226  const Matrix1D<double> &vi=v[i];
227  Euler_angles2matrix(VEC_ELEM(v_angi,1), VEC_ELEM(v_angi,2),
228  VEC_ELEM(v_angi,3), A, true);
229  A = A.transpose(); // We go from the projection plane to the universal coordinates
230 
231  // Apply a translation to the sphere of radius R
232  MAT_ELEM(A, 0, 3) = R * XX(vi);
233  MAT_ELEM(A, 1, 3) = R * YY(vi);
234  MAT_ELEM(A, 2, 3) = R * ZZ(vi);
235 
236  // Convert triangle coordinates to universal ones
237  p0 = A * p0;
238  p1 = A * p1;
239  p2 = A * p2;
240  p3 = A * p3;
241 
242  // Check if this triangle must be drawn
243  if (solid_sphere)
244  {
245  // Point-plane distance
246  double d=XX(p0)*XX(view_direction)+
247  YY(p0)*YY(view_direction)+
248  ZZ(p0)*ZZ(view_direction);
249  if (d < 0)
250  continue;
251  }
252 
253  // Project this triangle onto the view plane and write in PS
254  Uproject_to_plane(p1, euler_view, pp);
255  TO_PS(XX(pp), YY(pp));
256  fh_ps << "newpath\n";
257  fh_ps << XX(pp) << " " << YY(pp) << " moveto\n";
258 
259  Uproject_to_plane(p2, euler_view, pp);
260  TO_PS(XX(pp), YY(pp));
261  fh_ps << XX(pp) << " " << YY(pp) << " lineto\n";
262 
263  Uproject_to_plane(p3, euler_view, pp);
264  TO_PS(XX(pp), YY(pp));
265  fh_ps << XX(pp) << " " << YY(pp) << " lineto\n";
266 
267  Uproject_to_plane(p1, euler_view, pp);
268  TO_PS(XX(pp), YY(pp));
269  fh_ps << XX(pp) << " " << YY(pp) << " lineto\n";
270 
271  fh_ps << "closepath\nstroke\n";
272  }
273  fh_ps << "showpage\n";
274  fh_ps.close();
275  }
276  }
Rotation angle of an image (double,degrees)
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
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 Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
Definition: geometry.cpp:624
void Euler_direction(double alpha, double beta, double gamma, Matrix1D< double > &v)
Definition: geometry.cpp:721
#define pp(s, x)
Definition: ml2d.cpp:473
Tilting angle of an image (double,degrees)
Couldn&#39;t write to file.
Definition: xmipp_error.h:140
Unexpected label.
Definition: xmipp_error.h:157
Special label to be used when gathering MDs in MpiMetadataPrograms.
doublereal * w
#define TO_PS(x, y)
Matrix2D< T > transpose() const
Definition: matrix2d.cpp:1314
#define SIND(x)
Definition: xmipp_macros.h:347
virtual IdIteratorProxy< false > ids()
size_t size() const override
#define i
doublereal * d
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
#define DIRECT_A1D_ELEM(v, i)
void compute_hist(const MultidimArrayGeneric &array, Histogram1D &hist, int no_steps)
Definition: histogram.cpp:572
#define XX(v)
Definition: matrix1d.h:85
#define j
#define YY(v)
Definition: matrix1d.h:93
bool getValue(MDObject &mdValueOut, size_t id) const override
#define RAD2DEG(r)
Definition: xmipp_macros.h:320
double psi(const double x)
void write(const FileName &fn, MDLabel=MDL_X, MDLabel=MDL_COUNT)
Definition: histogram.cpp:129
#define VECTOR_R3(v, x, y, z)
Definition: matrix1d.h:124
void initZeros(const MultidimArray< T1 > &op)
bool containsLabel(const MDLabel label) const override
void getRow(size_t i, Matrix1D< T > &v) const
Definition: matrix2d.cpp:871
void Uproject_to_plane(const Matrix1D< double > &point, const Matrix1D< double > &direction, double distance, Matrix1D< double > &result)
Definition: geometry.cpp:39
#define ZZ(v)
Definition: matrix1d.h:101
< Score 4 for volumes

Member Data Documentation

◆ fnIn

FileName ProgAngularDistributionShow::fnIn

Definition at line 37 of file angular_distribution_show.cpp.

◆ fnOut

FileName ProgAngularDistributionShow::fnOut

Definition at line 37 of file angular_distribution_show.cpp.

◆ R

double ProgAngularDistributionShow::R

Definition at line 39 of file angular_distribution_show.cpp.

◆ rmax

double ProgAngularDistributionShow::rmax

Definition at line 39 of file angular_distribution_show.cpp.

◆ rot_view

double ProgAngularDistributionShow::rot_view

Definition at line 41 of file angular_distribution_show.cpp.

◆ shift_center

int ProgAngularDistributionShow::shift_center

Definition at line 40 of file angular_distribution_show.cpp.

◆ solid_sphere

int ProgAngularDistributionShow::solid_sphere

Definition at line 40 of file angular_distribution_show.cpp.

◆ steps

int ProgAngularDistributionShow::steps

Definition at line 40 of file angular_distribution_show.cpp.

◆ tilt_view

double ProgAngularDistributionShow::tilt_view

Definition at line 41 of file angular_distribution_show.cpp.

◆ type

String ProgAngularDistributionShow::type

Definition at line 38 of file angular_distribution_show.cpp.

◆ up_down_correction

bool ProgAngularDistributionShow::up_down_correction

Definition at line 42 of file angular_distribution_show.cpp.


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