9 #ifndef IMPEM_DENSITY_MAP_H
10 #define IMPEM_DENSITY_MAP_H
12 #include <IMP/em/em_config.h>
20 #include <boost/scoped_array.hpp>
45 IMPEMEXPORT DensityMap*
read_map(std::string filename, MapReaderWriter *reader);
55 IMPEMEXPORT DensityMap*
read_map(std::string filename);
61 IMPEMEXPORT
void write_map(DensityMap* m, std::string filename,
62 MapReaderWriter *writer);
73 IMPEMEXPORT
void write_map(DensityMap* m, std::string filename);
82 IMPEMEXPORT algebra::BoundingBoxD<3>
104 std::string filename,
108 DensityMap(std::string name=
"DensityMap%1%");
125 void reset_data(
float value=0.0);
136 void std_normalize();
138 inline bool is_normalized()
const {
return normalized_;}
146 float get_location_in_dim_by_voxel(
long index,
int dim)
const;
156 return z * header_.get_nx() * header_.get_ny() +
157 y * header_.get_nx() + x;
168 long get_voxel_by_location(
float x,
float y,
float z)
const;
176 return get_voxel_by_location(v[0],v[1],v[2]);
190 "invalid map index");
192 "locations should be calculated prior to calling this function");
196 bool is_xyz_ind_part_of_volume(
int ix,
int iy,
int iz)
const;
204 bool is_part_of_volume(
float x,
float y,
float z)
const;
210 return is_part_of_volume(v[0],v[1],v[2]);
220 emreal get_value(
float x,
float y,
float z)
const;
222 return get_value(point[0],point[1],point[2]);
230 emreal get_value(
long index)
const;
238 void set_value(
long index,emreal value);
245 void set_value(
float x,
float y,
float z,emreal value);
253 void set_origin(
float x,
float y,
float z);
255 set_origin(v[0],v[1],v[2]);
260 header_.get_origin(1),
261 header_.get_origin(2));
271 const DensityHeader *get_header()
const {
return &header_;}
275 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
280 float* get_x_loc()
const {
282 "x location requested before being calculated");
289 float* get_y_loc()
const {
291 "y location requested before being calculated");
298 float* get_z_loc()
const {
300 "z location requested before being calculated");
304 emreal* get_data()
const {
return data_.get();}
311 bool same_origin(
const DensityMap *other)
const;
317 bool same_dimensions(
const DensityMap *other)
const;
323 bool same_voxel_size(
const DensityMap *other)
const;
330 emreal get_max_value()
const;
332 emreal get_min_value()
const;
340 void add(
const DensityMap *other);
347 void pick_max(
const DensityMap *other);
350 long get_number_of_voxels()
const;
359 void set_void_map(
int nx,
int ny,
int nz);
372 void pad(
int nx,
int ny,
int nz,
float val=0.0);
389 DensityMap* pad_margin(
int mrg_x,
int mrg_y,
int mrg_z,
float val=0.0);
397 DensityMap* get_cropped(
float threshold);
407 float get_maximum_value_in_xy_plane(
int z_ind);
409 float get_maximum_value_in_xz_plane(
int y_ind);
411 float get_maximum_value_in_yz_plane(
int x_ind);
421 std::string get_locations_string(
float t);
424 void update_voxel_size(
float new_apix);
431 void calc_all_voxel2loc();
435 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
444 double *kernel,
int dim_len);
451 void convolute_kernel(
452 double *kernel,
int dim_len) {
454 cmap->set_was_used(
true);
455 convolute_kernel(cmap,kernel,dim_len);
459 int lower_voxel_shift(emreal loc, emreal kdist, emreal orig,
int ndim)
const;
460 int upper_voxel_shift(emreal loc, emreal kdist, emreal orig,
int ndim)
const;
461 inline bool get_rms_calculated()
const {
return rms_calculated_;}
462 int get_dim_index_by_location(
float loc_val,
466 void update_header();
467 void reset_all_voxel2loc();
469 void allocated_data();
470 void float2real(
float *f_data, boost::scoped_array<emreal> &r_data);
471 void real2float(emreal *r_data, boost::scoped_array<float> &f_data);
473 DensityHeader header_;
474 boost::scoped_array<emreal> data_;
475 bool data_allocated_;
479 boost::scoped_array<float>
x_loc_, y_loc_, z_loc_;
484 bool rms_calculated_;
497 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
512 inline void calc_local_bounding_box(
514 double x,
double y,
double z,
516 int &iminx,
int &iminy,
int &iminz,
517 int &imaxx,
int &imaxy,
int &imaxz) {
518 const DensityHeader *h=d_map->get_header();
519 iminx = d_map->lower_voxel_shift(x, kdist,h->get_xorigin(),h->get_nx());
520 iminy = d_map->lower_voxel_shift(y, kdist,h->get_yorigin(),h->get_ny());
521 iminz = d_map->lower_voxel_shift(z, kdist,h->get_zorigin(),h->get_nz());
522 imaxx = d_map->upper_voxel_shift(x, kdist,h->get_xorigin(),h->get_nx());
523 imaxy = d_map->upper_voxel_shift(y, kdist,h->get_yorigin(),h->get_ny());
524 imaxz = d_map->upper_voxel_shift(z, kdist,h->get_zorigin(),h->get_nz());
583 IMPEMEXPORT
void get_transformed_into2(
const DensityMap *source,
610 IMPEMEXPORT DensityMap*
get_segment(DensityMap *map_to_segment,
611 int nx_start,
int nx_end,
612 int ny_start,
int ny_end,
613 int nz_start,
int nz_end);
616 IMPEMEXPORT DensityMap*
get_segment(DensityMap *map_to_segment,
621 float mas_threshold);
631 IMPEMEXPORT DensityMap*
binarize(DensityMap *orig_map,
632 float threshold,
bool reverse=
false);
646 IMPEMEXPORT DensityMap*
multiply(
const DensityMap *m1,
647 const DensityMap *m2);
650 IMPEMEXPORT
double convolute(
const DensityMap *m1,
const DensityMap *m2);
652 IMPEMEXPORT
double get_sum(
const DensityMap *m1);
678 algebra::DenseGridStorageD<3, float>,