IMP logo
IMP Reference Guide  2.15.0
The Integrative Modeling Platform
MRCReaderWriter.h
Go to the documentation of this file.
1 /**
2  * \file IMP/em/MRCReaderWriter.h
3  * \brief Classes to read or write MRC files.
4  *
5  * Copyright 2007-2021 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPEM_MRC_READER_WRITER_H
10 #define IMPEM_MRC_READER_WRITER_H
11 
12 #include <IMP/em/em_config.h>
13 #include "MapReaderWriter.h"
14 #include "internal/MRCHeader.h"
15 #include <string>
16 
17 IMPEM_BEGIN_NAMESPACE
18 
19 /** A class to read and write MRC files. */
20 class IMPEMEXPORT MRCReaderWriter : public MapReaderWriter {
21  public:
22  //! Empty constructor
24  //! Constructor
25  /**
26  * \param[in] fn name of the file to open or write
27  */
28  MRCReaderWriter(std::string fn) { filename = fn; }
29 #if !defined(DOXYGEN) && !defined(SWIG)
30  //! Reads an MRC file and translates the header to the general DensityHeader
31  void read(const char *fn_in, float **data, DensityHeader &head);
32  //! Writes an MRC file from the data and the general DensityHeader
33  void write(const char *fn_out, const float *data, const DensityHeader &head);
34 #endif
35 
36  private:
37  //! By default the data are read into the grid of the class, but an external
38  //! pointer to another grid can be specified
39  void read() { read(&grid); }
40 
41  void read(float **pt);
42  //! reads the header
43  void read_header();
44  //! reads the data
45  void read_data(float *pt);
46  //! Transpose data from section/row/col to z/y/x if needed
47  void transpose_data_to_zyx(float **pt);
48  //! reads data of size 8-bit
49  void read_8_data(float *pt);
50  //! reads data of size 32-bit
51  void read_32_data(float *pt);
52  void read_grid(void *pt, size_t size, size_t n);
53  void seek_to_data();
54  //! Write function
55  /**
56  * \param[in] fn name of the file to write
57  */
58  void write(const char *fn) { return write(fn, grid); }
59 
60  //! Write function
61  /**
62  * \param[in] fn name of the file to write
63  * \param[in] pt pointer to the data to write
64  */
65  void write(const char *fn, const float *pt);
66  //! Writes the header
67  /**
68  * \param[in] s stream to write the header
69  */
70  void write_header(std::ofstream &s);
71  //! Writes data
72  /**
73  * \param[in] s stream to write the data
74  * \param[in] pt pointer to the data
75  */
76  void write_data(std::ofstream &s, const float *pt);
77 
78  //! Name of the file
79  std::string filename;
80  //! file stream for the file read
81  std::fstream fs;
82  //! The header of the file
83  internal::MRCHeader header;
84  //! The grid of data. The data is stored in the grid with the convention
85  //! that the order of indexes is z,y,x
86  float *grid;
87 
89 };
90 
91 IMPEM_END_NAMESPACE
92 
93 #endif /* IMPEM_MRC_READER_WRITER_H */
The base class to handle reading and writing of density maps.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
MRCReaderWriter(std::string fn)
Constructor.
An abstract class for reading a map.
MRCReaderWriter()
Empty constructor.