Xmipp  v3.23.11-Nereus
volume_to_web.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar Sorzano (coss@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #include "core/xmipp_program.h"
27 #include "core/xmipp_image.h"
28 
30 {
31 public:
34 
37 
40 
42  int Nslices;
43 
45  int maxWidth;
46 
48  int sep;
49 public:
51  void readParams()
52  {
53  fnVol=getParam("-i");
54  if (checkParam("--central_slices"))
55  {
56  fnCentralSlices=getParam("--central_slices");
57  Nslices=getIntParam("--central_slices",1);
58  }
59  if (checkParam("--projections"))
60  fnProjections=getParam("--projections");
61  maxWidth=getIntParam("--maxWidth");
62  sep=getIntParam("--separation");
63  }
64 
66  void defineParams()
67  {
68  addUsageLine("Creates a representation for the web of the input volume");
69  addParamsLine(" -i <volume> : Input volume");
70  addParamsLine(" [--central_slices <imgFile> <n=-1>] : Output central slices (normally jpg); n=-1 for all slices");
71  addParamsLine(" [--projections <imgFile>] : Output projections (normally jpg)");
72  addParamsLine(" [--maxWidth <w=800>] : Maximum image width");
73  addParamsLine(" [--separation <s=2>] : Separation in pixels between slices");
74  addExampleLine("xmipp_volume_to_web -i volume.vol --central_slices central_slices.jpg --projections projections.jpg");
75  }
76 
78  void run()
79  {
80  Image<double> V;
81  V.read(fnVol);
82  MultidimArray<double> &mV=V();
83 
84  Image<double> I;
85  if (!fnCentralSlices.empty())
86  {
87  // Choose the starting and finishing slice
88  if (Nslices==-1)
89  Nslices=ZSIZE(mV);
90  int kmiddle=ZSIZE(mV)/2;
91  int k0=kmiddle-Nslices/2;
92  int kF=k0+Nslices-1;
93 
94  // Resize the output image
95  int NslicesPerRow=maxWidth/XSIZE(mV);
96  if (NslicesPerRow==0)
97  NslicesPerRow=1;
98  else if (NslicesPerRow>Nslices)
99  NslicesPerRow=Nslices;
100  auto Nrows=(int)ceil(((float)Nslices)/NslicesPerRow);
101  if (Nrows==0)
102  Nrows=1;
103  I().resizeNoCopy(Nrows*YSIZE(mV)+(Nrows-1)*sep,NslicesPerRow*XSIZE(mV)+(NslicesPerRow-1)*sep);
104  I().initConstant(mV.computeMax());
105 
106  // Copy the slices into the output image
107  int outI=0, outJ=0;
108  for (int k=k0; k<=kF; ++k)
109  {
110  int outi=outI*(YSIZE(mV)+sep);
111  int outj=outJ*(XSIZE(mV)+sep);
112  for (size_t i=0; i<YSIZE(mV); ++i, ++outi)
113  memcpy(&IMGPIXEL(I,outi,outj),&A3D_ELEM(mV,k,i,0),XSIZE(mV)*sizeof(double));
114  outJ++;
115  if (outJ==NslicesPerRow)
116  {
117  outJ=0;
118  outI++;
119  }
120  }
121  I().rangeAdjust(0,255);
122  I.write(fnCentralSlices);
123  }
124  if (fnProjections!="")
125  {
126  // Take projections
127  MultidimArray<double> pXY, pYZ, pXZ;
128  pXY.initZeros(YSIZE(mV),XSIZE(mV));
129  pXZ.initZeros(ZSIZE(mV),XSIZE(mV));
130  pYZ.initZeros(ZSIZE(mV),YSIZE(mV));
131  double maxVal=-1e38;
133  {
134  double v=A3D_ELEM(mV,k,i,j);
135  A2D_ELEM(pXY,i,j)+=v;
136  A2D_ELEM(pXZ,k,j)+=v;
137  A2D_ELEM(pYZ,k,i)+=v;
138  maxVal=std::max(A2D_ELEM(pXY,i,j),maxVal);
139  maxVal=std::max(A2D_ELEM(pXZ,k,j),maxVal);
140  maxVal=std::max(A2D_ELEM(pYZ,k,i),maxVal);
141  }
142 
143  // Now produce output image
144  I().resizeNoCopy(XMIPP_MAX(YSIZE(mV),ZSIZE(mV)),2*(XSIZE(mV)+sep)+YSIZE(mV));
145  I().initConstant(maxVal);
146  int outi=0, outj=0;
147  for (size_t i=0; i<YSIZE(pXY); ++i, ++outi)
148  memcpy(&IMGPIXEL(I,outi,outj),&A2D_ELEM(pXY,i,0),XSIZE(pXY)*sizeof(double));
149 
150  outi=0;
151  outj=XSIZE(mV)+sep;
152  for (size_t i=0; i<YSIZE(pXZ); ++i, ++outi)
153  memcpy(&IMGPIXEL(I,outi,outj),&A2D_ELEM(pXZ,i,0),XSIZE(pXZ)*sizeof(double));
154 
155  outi=0;
156  outj=2*(XSIZE(mV)+sep);
157  for (size_t i=0; i<YSIZE(pYZ); ++i, ++outi)
158  memcpy(&IMGPIXEL(I,outi,outj),&A2D_ELEM(pYZ,i,0),XSIZE(pYZ)*sizeof(double));
159 
160  I().rangeAdjust(0,255);
161  I.write(fnProjections);
162  }
163  }
164 };
#define YSIZE(v)
#define A2D_ELEM(v, i, j)
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
int maxWidth
Maximum Width.
FileName fnVol
Volume to convert.
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
FileName fnCentralSlices
Output central slices.
FileName fnProjections
Output projections.
int sep
Separation.
#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)
const char * getParam(const char *param, int arg=0)
void run()
Run.
#define XSIZE(v)
int Nslices
Number of slices.
void max(Image< double > &op1, const Image< double > &op2)
#define ZSIZE(v)
void addExampleLine(const char *example, bool verbatim=true)
#define j
void readParams()
Read parameters from command line.
void defineParams()
define parameters
bool checkParam(const char *param)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void addUsageLine(const char *line, bool verbatim=false)
void initZeros(const MultidimArray< T1 > &op)
int getIntParam(const char *param, int arg=0)
void addParamsLine(const String &line)
#define IMGPIXEL(I, i, j)
T computeMax() const