7 #ifndef IMPEM2D_SPIDER_IMAGE_READER_WRITER_H
8 #define IMPEM2D_SPIDER_IMAGE_READER_WRITER_H
10 #include <IMP/em2d/em2d_config.h>
28 IMPEM2D_BEGIN_NAMESPACE
35 bool skip_type_check_;
37 bool skip_extra_checkings_;
45 skip_type_check_ =
false;
46 force_reversed_ =
false;
47 skip_extra_checkings_ =
false;
60 bool force_reversed,
bool skip_extra_checkings) {
62 skip_type_check_ = skip_type_check;
63 force_reversed_ = force_reversed;
64 skip_extra_checkings_ = skip_extra_checkings;
69 this->read_from_floats(filename, header, data);
74 this->write_to_floats(filename, header, data);
77 void read_from_ints(
const String &, em::ImageHeader &,
80 void write_to_ints(
const String &, em::ImageHeader &,
94 in.open(filename.c_str(), std::ios::in | std::ios::binary);
95 if (in.fail() || in.bad()) {
99 bool success = header.
read(in, skip_type_check_, force_reversed_,
100 skip_extra_checkings_);
102 IMP_THROW(
"Error reading header from Spider Image " << filename,
108 unsigned int rows = (int)header.get_number_of_rows();
109 unsigned int cols = (int)header.get_number_of_columns();
111 Eigen::Array<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
112 floats = Eigen::Array<float, Eigen::Dynamic, Eigen::Dynamic,
113 Eigen::RowMajor>::Zero(rows, cols);
116 data = floats.cast<
double>();
129 out.open(filename.c_str(), std::ios::out | std::ios::binary);
134 Eigen::Array<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
135 floats = data.cast<
float>();
144 IMPEM2D_END_NAMESPACE
bool get_is_big_endian()
Returns 1 if machine is big endian else 0.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Virtual class for reader/writers of images.
SpiderImageReaderWriter(const String &filename, bool skip_type_check, bool force_reversed, bool skip_extra_checkings)
Full constructor.
Virtual class for reader/writers of images Copyright 2007-2026 IMP Inventors. All rights reserved...
#define IMP_LOG_VERBOSE(expr)
Exception definitions and assertions.
An input/output exception.
Functions to deal with byte order.
Functions to deal with very common math operations.
void read_from_floats(const String &filename, em::ImageHeader &header, DoubleMatrix &data) const override
Logging and error reporting support.
Matrices used to store image data Copyright 2007-2026 IMP Inventors. All rights reserved.
SpiderImageReaderWriter()
void reversed_read(void *dest, size_t size, size_t nitems, std::ifstream &f, bool reverse)
Reads from file in normal or reverse order.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
void reversed_write(const void *src, size_t size, size_t nitems, std::ofstream &f, bool reverse=false)
Writes to a file in normal or reversed order.
Logging and error reporting support.
Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > DoubleMatrix
Matrix of doubles, used to store the data of an image.
std::string String
Basic string value.
void write_to_floats(const String &filename, em::ImageHeader &header, const DoubleMatrix &data) const override
Writes an EM image in Spider format.