IMP  2.1.1
The Integrative Modeling Platform
DensityHeader.h
Go to the documentation of this file.
1 /**
2  * \file IMP/em/DensityHeader.h
3  * \brief Metadata for a density file.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPEM_DENSITY_HEADER_H
10 #define IMPEM_DENSITY_HEADER_H
11 
12 #include <IMP/em/em_config.h>
13 #include "def.h"
14 #include <IMP/base/exception.h>
15 #include <iostream>
16 #include <fstream>
17 #include <cstring>
18 #include <limits>
20 #include <IMP/base/Object.h>
21 IMPEM_BEGIN_NAMESPACE
22 
23 /** \todo change so that the att will not be encoded but loaded from
24  a conf file (Keren) */
25 class IMPEMEXPORT DensityHeader
26 {
27 
28 public:
29  DensityHeader();
30  // If a copy constructor is not defined in a class, the compiler itself
31  // defines one. This will ensure a shallow copy.
32  // If the class does not have pointer variables with dynamically allocated
33  // memory, then one need not worry about defining a
34  // copy constructor. It can be left to the compiler's discretion.
35  // But if the class has pointer variables and has some dynamic memory
36  // allocations, then it is a must to have a copy constructor.
37 
38  //! gets the upper bound of the grid
39  /** \param[in] ind The dimension index x:=0,y:=1,z:=2
40  \return the coordinate value in angstroms
41  */
42  emreal get_top(int ind) const
43  {
44  IMP_USAGE_CHECK(top_calculated_,
45  " DensityHeader::get_top the top coordinates of the map "
46  << "have not been setup yet " << std::endl);
47  if (ind==0) return xtop_;
48  if (ind==1) return ytop_;
49  return ztop_;
50 
51  }
52  //! Compute the farthest point of the grid.
53  /**
54  /param[in] force if true then the top point is calculated
55  even if it has already been calcualted.
56  */
57  void compute_xyz_top(bool force=false);
58 
59 
60  //! Update the dimensions of the map to be (nnx,nny,nnz)
61  //!The origin of the map does not change
62  /**
63  /param[in] nnx the new number of voxels on the X axis
64  /param[in] nny the new number of voxels on the Y axis
65  /param[in] nnz the new number of voxels on the Z axis
66  */
67  void update_map_dimensions(int nnx,int nny,int nnz);
68 
69  //! Update the cell dimensions of the map multiplying the number of voxels
70  //! along each direction by the Objectpixelsize
71  void update_cell_dimensions();
72 
73  void show(std::ostream& out=std::cout) const;
74 
75  static const unsigned short MAP_FIELD_SIZE = 4;
76  static const unsigned short USER_FIELD_SIZE = 25;
77  static const unsigned short COMMENT_FIELD_NUM_OF = 10;
78  static const unsigned short COMMENT_FIELD_SINGLE_SIZE = 80;
79 
80 
81  //! number of first columns in map (x-dimension)
82  int nxstart;
83  //! number of first columns in map (y-dimension)
84  int nystart;
85  //! number of first columns in map (z-dimension)
86  int nzstart;
87 
88  int mx, my, mz; // Number of intervals along each dimension
89  float xlen,ylen,zlen; //Cell dimensions (angstroms)
90  float alpha, beta, gamma; //Cell angles (degrees)
91  //! Axes corresponding to columns (mapc), rows (mapr) and sections (maps)
92  //! (1,2,3 for x,y,z)
93  int mapc, mapr, maps;
94  float dmin,dmax,dmean; //Minimum, maximum and mean density value
95  int ispg; //space group number 0 or 1
96  int nsymbt; //Number of bytes used for symmetry data
97  int user[USER_FIELD_SIZE];//extra space used for anything
98  char map[MAP_FIELD_SIZE]; //character string 'MAP ' to identify file type
99  int machinestamp; //machine stamp (0x11110000 bigendian, 0x44440000 little)
100  float rms; //RMS deviation of map from mean density
101  int nlabl; //Number of labels being used
102  //! text comments \todo MRC: labels[10][80] - should it be a different field?
103  char comments[COMMENT_FIELD_NUM_OF][COMMENT_FIELD_SINGLE_SIZE];
104  //! magic byte for machine platform (~endian), OS-9=0, VAX=1, Convex=2,
105  //! SGI=3, Sun=4, Mac(Motorola)=5, PC,IntelMac=6
106  int magic;
107  float voltage; //Voltage of electron microscope
108  float Cs; //Cs of microscope
109  float Aperture; //Aperture used
110  float Magnification; //Magnification
111  float Postmagnification; //Postmagnification (of energy filter)
112  float Exposuretime; //Exposuretime
113  float Microscope; //Microscope
114  float Pixelsize; //Pixelsize - used for the microscope CCD camera
115  float CCDArea; //CCDArea
116  float Defocus; //Defocus
117  float Astigmatism;//Astigmatism
118  float AstigmatismAngle; //Astigmatism Angle
119  float FocusIncrement;//Focus-Increment
120  float CountsPerElectron;//Counts/Electron
121  float Intensity;//Intensity
122  float EnergySlitwidth;//Energy slitwidth of energy filter
123  float EnergyOffset; //Energy offset of Energy filter
124  float Tiltangle;//Tiltangle of stage
125  float Tiltaxis;//Tiltaxis
126  float MarkerX;//Marker_X coordinate
127  float MarkerY;//Marker_Y coordinate
128  int lswap;
129 
130  //! Returns the resolution of the map
131  inline float get_resolution() const {
132  IMP_INTERNAL_CHECK(is_resolution_set_,
133  "The resolution was not set"<<std::endl);
134  return resolution_;
135  }
136  //! Return if the resolution has been set
137  inline bool get_has_resolution() const {
138  return is_resolution_set_;
139  }
140  //! Sets the resolution of the map
141  inline void set_resolution(float resolution) {
142  is_resolution_set_=true;
143  resolution_=resolution;}
144  /** \note Use DensityMap::update_voxel_size() to set the spacing value.
145  */
146  inline float get_spacing() const {return Objectpixelsize_;}
147  //! Returns the origin on the map (x-coordinate)
148  inline float get_xorigin() const {return xorigin_;}
149  //! Returns the origin on the map (y-coordinate)
150  inline float get_yorigin() const {return yorigin_;}
151  //! Returns the origin on the map (z-coordinate)
152  inline float get_zorigin() const {return zorigin_;}
153  //! Returns the origin on the map
154  /**
155  \param[in] i the relevant coordinate (0:x, 1:y, 2:z)
156  \exception ValueException if the value of i is out of range.
157  */
158  inline float get_origin(int i) const {
159  IMP_USAGE_CHECK(i >= 0 && i <= 2,
160  "The origin coordinate should be between 0 and 2");
161  switch (i) {
162  case 0: return get_xorigin();
163  case 1: return get_yorigin();
164  default: return get_zorigin();
165  }
166  }
167  //! Sets the origin on the map (x-coordinate).
168  /**
169  \note This is an absolute position in space.
170  */
171  inline void set_xorigin(float x) {xorigin_=x; top_calculated_=false;}
172  //! Sets the origin on the map (y-coordinate)
173  /**
174  \note This is an absolute position in space.
175  */
176  inline void set_yorigin(float y) {yorigin_=y; top_calculated_=false;}
177  //! Sets the origin on the map (z-coordinate)
178  /**
179  \note This is an absolute position in space.
180  */
181  inline void set_zorigin(float z) {zorigin_=z; top_calculated_=false;}
182  //! True if the top coodinates (bounding-box) are calculated
183  inline bool is_top_calculated() const { return top_calculated_;}
184  float Objectpixelsize_; //this is the actual pixelsize
185 
186  // get/set functions
187  //! Get the number of voxels in the x dimension
188  inline int get_nx() const {return nx_;}
189  //! Get the number of voxels in the y dimension
190  inline int get_ny() const {return ny_;}
191  //! Get the number of voxels in the z dimension
192  inline int get_nz() const {return nz_;}
193  inline int get_number_of_voxels() const {return nx_*ny_*nz_;}
194  //! Get the number of bits that used to store the density of a single voxel
195  inline int get_data_type() const {return data_type_;}
196  inline void set_data_type(int data_type) {data_type_=data_type;}
197 
198 protected:
199  float xtop_, ytop_, ztop_; // The upper bound for the x,y and z grid.
200  float xorigin_, yorigin_, zorigin_; //Origin used for transforms
201  bool top_calculated_;
202  float resolution_;
203  bool is_resolution_set_;
204  int nx_,ny_,nz_; //map size (voxels) in x,y,z dimensions
205  //! How many bits are used to store the density of a single voxel
206  //! (used in MRC format)
208 };
209 
210 //! Create a header from a bounding box 3D
211 /**
212  See DensityHeader
213 */
215  const algebra::BoundingBoxD<3> &bb, float spacing);
216 
217 IMPEM_END_NAMESPACE
218 
219 #endif /* IMPEM_DENSITY_HEADER_H */
float get_resolution() const
Returns the resolution of the map.
int nxstart
number of first columns in map (x-dimension)
Definition: DensityHeader.h:82
bool is_top_calculated() const
True if the top coodinates (bounding-box) are calculated.
Definitions for EMBED.
float get_spacing() const
float get_yorigin() const
Returns the origin on the map (y-coordinate)
void set_zorigin(float z)
Sets the origin on the map (z-coordinate)
float get_zorigin() const
Returns the origin on the map (z-coordinate)
void set_resolution(float resolution)
Sets the resolution of the map.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
emreal get_top(int ind) const
gets the upper bound of the grid
Definition: DensityHeader.h:42
int nystart
number of first columns in map (y-dimension)
Definition: DensityHeader.h:84
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
DensityHeader create_density_header(const algebra::BoundingBoxD< 3 > &bb, float spacing)
Create a header from a bounding box 3D.
A bounding box in D dimensions.
bool get_has_resolution() const
Return if the resolution has been set.
int get_nx() const
Get the number of voxels in the x dimension.
void set_xorigin(float x)
Sets the origin on the map (x-coordinate).
Exception definitions and assertions.
int get_ny() const
Get the number of voxels in the y dimension.
float get_origin(int i) const
Returns the origin on the map.
void set_yorigin(float y)
Sets the origin on the map (y-coordinate)
void show(Hierarchy h, std::ostream &out=std::cout)
Print out a molecular hierarchy.
int nzstart
number of first columns in map (z-dimension)
Definition: DensityHeader.h:86
float get_xorigin() const
Returns the origin on the map (x-coordinate)
int get_nz() const
Get the number of voxels in the z dimension.
A shared base class to help in debugging and things.
int get_data_type() const
Get the number of bits that used to store the density of a single voxel.