00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IMPEM_IMAGE_H
00009 #define IMPEM_IMAGE_H
00010
00011
00012
00013 #include "em_config.h"
00014 #include "ImageHeader.h"
00015 #include "ImageReaderWriter.h"
00016 #include "IMP/algebra/Matrix2D.h"
00017 #include "IMP/algebra/Rotation2D.h"
00018 #include <complex>
00019 #include <limits>
00020 #include <typeinfo>
00021
00022 IMPEM_BEGIN_NAMESPACE
00023
00024
00025
00026 template<typename T>
00027 class Image
00028 {
00029 public:
00030
00031 typedef Image<T> This;
00032
00033
00034 Image() {
00035 name_ = "";
00036 if (typeid(T) == typeid(double)) {
00037 header_.set_image_type(ImageHeader::IMG_IMPEM);
00038 }
00039 }
00040
00041
00042 Image(Int Ydim, Int Xdim) {
00043 data_.resize(Ydim, Xdim);
00044 header_.set_header();
00045 if (typeid(T) == typeid(double)) {
00046 header_.set_image_type(ImageHeader::IMG_IMPEM);
00047 }
00048 }
00049
00050
00051 algebra::Matrix2D<T>& get_data() {
00052 return data_;
00053 }
00054
00055
00056 void set_data(algebra::Matrix2D<T> &v) {
00057 data_.resize(v);
00058 for(unsigned long i=0;i<v.num_elements();i++) {
00059 data_.data()[i] = v.data()[i];
00060 }
00061 this->adjust_header();
00062 }
00063
00064
00065 ImageHeader& get_header() {
00066 return header_;
00067 }
00068
00069
00070
00071 void adjust_header() {
00072 if (typeid(T) == typeid(std::complex< double >)) {
00073 header_.set_image_type(ImageHeader::IMG_FOURIER);
00074 } else if (typeid(T) == typeid(double) ||
00075 typeid(T) == typeid(double)) {
00076 header_.set_image_type(ImageHeader::IMG_IMPEM);
00077 }
00078 header_.set_number_of_slices(1.0);
00079 header_.set_number_of_rows(data_.get_number_of_rows());
00080 header_.set_number_of_columns(data_.get_number_of_columns());
00081 header_.set_time();
00082 header_.set_date();
00083 header_.set_title(name_);
00084 header_.set_header();
00085 }
00086
00087
00088 void read(String filename,ImageReaderWriter<T>& reader) {
00089 IMP_LOG(VERBOSE, "reading EM image " << std::endl);
00090 reader.read(filename,header_,data_);
00091 }
00092
00093
00094 void write(String filename, ImageReaderWriter<T>& writer) {
00095 adjust_header();
00096 writer.write(filename,header_,data_);
00097 }
00098
00099 protected:
00100
00101 String name_;
00102
00103 algebra::Matrix2D<T> data_;
00104
00105 ImageHeader header_;
00106
00107 };
00108
00109
00110
00111 IMPEM_END_NAMESPACE
00112 #endif