ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkMRCHeaderObject.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkMRCHeaderObject_h
00019 #define __itkMRCHeaderObject_h
00020 
00021 #include "itkLightObject.h"
00022 #include "itkByteSwapper.h"
00023 #include "itkIntTypes.h"
00024 
00025 namespace itk
00026 {
00028 const char *const magicMAP = "MAP ";
00029 
00049 class ITK_EXPORT MRCHeaderObject:
00050   public itk::LightObject
00051 {
00052 public:
00054   typedef MRCHeaderObject            Self;
00055   typedef LightObject                Superclass;
00056   typedef SmartPointer< Self >       Pointer;
00057   typedef SmartPointer< const Self > ConstPointer;
00058 
00066   struct Header {
00067 
00083     int32_t mode;
00084 
00086     int32_t nxstart;
00087     int32_t nystart;
00088     int32_t nzstart;
00089 
00091     int32_t mx;
00092     int32_t my;
00093     int32_t mz;
00094 
00096     float xlen;
00097     float ylen;
00098     float zlen;
00099 
00101     float alpha;
00102     float beta;
00103     float gamma;
00104 
00111     // These need to be set for proper scaling of
00112     // non byte data.
00129     // These two values specify the structure of data in the
00130     // extended header; their meaning depend on whether the
00131     // extended header has the Agard format, a series of
00132     // 4-byte integers then real numbers, or has data
00133     // produced by SerialEM, a series of short integers.
00134     // SerialEM stores a float as two shorts, s1 and s2, by:
00135     // value = (sign of s1)*(|s1|*256 + (|s2| modulo 256))
00136     // * 2**((sign of s2) * (|s2|/256))
00137 
00138     int16_t nint;          // Number of integers per section (Agard format) or
00139                            // number of bytes per section (SerialEM format)
00140     int16_t nreal;         // Number of reals per section (Agard format) or
00141     // flags for which types of short data (SerialEM format):
00142     // 1 = tilt angle * 100  (2 bytes)
00143     // 2 = piece coordinates for montage  (6 bytes)
00144     // 4 = Stage position * 25    (4 bytes)
00145     // 8 = Magnification / 100 (2 bytes)
00146     // 16 = Intensity * 25000  (2 bytes)
00147     // 32 = Exposure dose in e-/A2, a float in 4 bytes
00148     // 128, 512: Reserved for 4-byte items
00149     // 64, 256, 1024: Reserved for 2-byte items
00150     // If the number of bytes implied by these flags does
00151     // not add up to the value in nint, then nint and nreal
00152     // are interpreted as ints and reals per section
00153 
00155     int8_t notused2[28];
00156 
00157     // Explanation of type of data.
00158     int16_t idtype;        // ( 0 = mono, 1 = tilt, 2 = tilts, 3 = lina, 4 =
00159                            // lins)
00160     int16_t lens;
00161     int16_t nd1;           // for idtype = 1, nd1 = axis (1, 2, or 3)
00162     int16_t nd2;
00163     int16_t vd1;           // vd1 = 100. * tilt increment
00164     int16_t vd2;           // vd2 = 100. * starting angle
00165 
00166     // Used to rotate model to match new rotated image.
00167     float tiltangles[6];     // 0,1,2 = original:  3,4,5 = current
00168 
00169     // NEW-STYLE MRC image2000 HEADER - IMOD 2.6.20 and above:
00170     float xorg;              // Origin of image.  Used to auto translate model
00171     float yorg;              // to match a new image that has been translated.
00172     float zorg;
00173 
00178     float rms;
00179 
00180     // ALL HEADERS:
00184   };
00185 
00187   struct FeiExtendedHeader {
00188 
00212     float magnification;
00213 
00215   };
00216 
00218   enum { MRCHEADER_MODE_UINT8 = 0,
00219          MRCHEADER_MODE_IN16 = 1,
00220          MRCHEADER_MODE_FLOAT = 2,
00221          MRCHEADER_MODE_COMPLEX_INT16 = 3,
00222          MRCHEADER_MODE_COMPLEX_FLOAT = 4,
00223          MRCHEADER_MODE_UINT16 = 6,
00224          MRCHEADER_MODE_RGB_BYTE = 16 };
00225 
00227   enum { MRCHEADER_MAP_X = 1,
00228          MRCHEADER_MAP_Y = 2,
00229          MRCHEADER_MAP_Z = 3 };
00230 public:
00231 
00233   itkNewMacro(Self);
00234 
00236   itkTypeMacro(MRCHeaderObject, LightObject);
00237 
00238   void DeepCopy(ConstPointer h);
00239 
00250   bool SetHeader(const Header *buffer);
00251 
00252   const Header & GetHeader() const;
00253 
00262   bool SetExtendedHeader(const void *buffer);
00263 
00267   SizeValueType GetExtendedHeaderSize(void) const;
00268 
00270   SizeValueType GetHeaderSize(void) const { return sizeof( Header ); }
00271 
00275   bool IsOriginalHeaderBigEndian(void) const;
00276 
00278   Header m_Header;                    // FIXME : This should be private and
00279                                       // should have Get/Set Methods.
00280 protected:
00281 
00282   MRCHeaderObject(void);
00283   ~MRCHeaderObject(void);
00284 
00286   void swapHeader(bool bigEndian);
00287 
00289   void PrintSelf(std::ostream & os, Indent indent) const;
00290 
00291 private:
00292   MRCHeaderObject(const Self &); //purposely not implemented
00293   void operator=(const Self &);  //purposely not implemented
00294 
00295   SizeValueType m_ExtendedHeaderSize;
00296   void        * m_ExtendedHeader;
00297 
00298   FeiExtendedHeader *m_ExtendedFeiHeader;
00299 
00300   bool m_BigEndianHeader;
00301 };
00302 } // namespace itk
00303 
00304 #endif
00305