ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkMRCHeaderObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkMRCHeaderObject_h
19 #define __itkMRCHeaderObject_h
20 
21 #include "itkLightObject.h"
22 #include "itkByteSwapper.h"
23 #include "itkIntTypes.h"
24 
25 namespace itk
26 {
28 const char *const magicMAP = "MAP ";
29 
49 class ITK_EXPORT MRCHeaderObject:
50  public itk::LightObject
51 {
52 public:
58 
66  struct Header {
67 
84 
89 
94 
96  float xlen;
97  float ylen;
98  float zlen;
99 
101  float alpha;
102  float beta;
103  float gamma;
104 
111  // These need to be set for proper scaling of
112  // non byte data.
129  // These two values specify the structure of data in the
130  // extended header; their meaning depend on whether the
131  // extended header has the Agard format, a series of
132  // 4-byte integers then real numbers, or has data
133  // produced by SerialEM, a series of short integers.
134  // SerialEM stores a float as two shorts, s1 and s2, by:
135  // value = (sign of s1)*(|s1|*256 + (|s2| modulo 256))
136  // * 2**((sign of s2) * (|s2|/256))
137 
138  int16_t nint; // Number of integers per section (Agard format) or
139  // number of bytes per section (SerialEM format)
140  int16_t nreal; // Number of reals per section (Agard format) or
141  // flags for which types of short data (SerialEM format):
142  // 1 = tilt angle * 100 (2 bytes)
143  // 2 = piece coordinates for montage (6 bytes)
144  // 4 = Stage position * 25 (4 bytes)
145  // 8 = Magnification / 100 (2 bytes)
146  // 16 = Intensity * 25000 (2 bytes)
147  // 32 = Exposure dose in e-/A2, a float in 4 bytes
148  // 128, 512: Reserved for 4-byte items
149  // 64, 256, 1024: Reserved for 2-byte items
150  // If the number of bytes implied by these flags does
151  // not add up to the value in nint, then nint and nreal
152  // are interpreted as ints and reals per section
153 
155  int8_t notused2[28];
156 
157  // Explanation of type of data.
158  int16_t idtype; // ( 0 = mono, 1 = tilt, 2 = tilts, 3 = lina, 4 =
159  // lins)
161  int16_t nd1; // for idtype = 1, nd1 = axis (1, 2, or 3)
163  int16_t vd1; // vd1 = 100. * tilt increment
164  int16_t vd2; // vd2 = 100. * starting angle
165 
166  // Used to rotate model to match new rotated image.
167  float tiltangles[6]; // 0,1,2 = original: 3,4,5 = current
168 
169  // NEW-STYLE MRC image2000 HEADER - IMOD 2.6.20 and above:
170  float xorg; // Origin of image. Used to auto translate model
171  float yorg; // to match a new image that has been translated.
172  float zorg;
173 
178  float rms;
179 
180  // ALL HEADERS:
184  };
185 
188 
212  float magnification;
213 
215  };
216 
218  enum { MRCHEADER_MODE_UINT8 = 0,
219  MRCHEADER_MODE_IN16 = 1,
220  MRCHEADER_MODE_FLOAT = 2,
221  MRCHEADER_MODE_COMPLEX_INT16 = 3,
222  MRCHEADER_MODE_COMPLEX_FLOAT = 4,
223  MRCHEADER_MODE_UINT16 = 6,
224  MRCHEADER_MODE_RGB_BYTE = 16 };
225 
227  enum { MRCHEADER_MAP_X = 1,
228  MRCHEADER_MAP_Y = 2,
229  MRCHEADER_MAP_Z = 3 };
230 public:
231 
233  itkNewMacro(Self);
234 
236  itkTypeMacro(MRCHeaderObject, LightObject);
237 
238  void DeepCopy(ConstPointer h);
239 
250  bool SetHeader(const Header *buffer);
251 
252  const Header & GetHeader() const;
253 
262  bool SetExtendedHeader(const void *buffer);
263 
267  SizeValueType GetExtendedHeaderSize(void) const;
268 
270  SizeValueType GetHeaderSize(void) const { return sizeof( Header ); }
271 
275  bool IsOriginalHeaderBigEndian(void) const;
276 
278  Header m_Header; // FIXME : This should be private and
279  // should have Get/Set Methods.
280 protected:
281 
282  MRCHeaderObject(void);
283  ~MRCHeaderObject(void);
284 
286  void swapHeader(bool bigEndian);
287 
289  void PrintSelf(std::ostream & os, Indent indent) const;
290 
291 private:
292  MRCHeaderObject(const Self &); //purposely not implemented
293  void operator=(const Self &); //purposely not implemented
294 
297 
299 
301 };
302 } // namespace itk
303 
304 #endif
305