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>
44 IMPEMEXPORT DensityMap *
read_map(std::string filename, MapReaderWriter *reader);
54 IMPEMEXPORT DensityMap *
read_map(std::string filename);
59 IMPEMEXPORT
void write_map(DensityMap *m, std::string filename,
60 MapReaderWriter *writer);
71 IMPEMEXPORT
void write_map(DensityMap *m, std::string filename);
103 DensityMap(std::string name =
"DensityMap%1%");
111 void reset_data(
float value = 0.0);
121 void std_normalize();
123 inline bool is_normalized()
const {
return normalized_; }
131 float get_location_in_dim_by_voxel(
long index,
int dim)
const;
140 return z * header_.get_nx() * header_.get_ny() + y * header_.get_nx() + x;
150 long get_voxel_by_location(
float x,
float y,
float z)
const;
158 return get_voxel_by_location(v[0], v[1], v[2]);
172 "invalid map index");
175 "locations should be calculated prior to calling this function");
179 bool is_xyz_ind_part_of_volume(
int ix,
int iy,
int iz)
const;
187 bool is_part_of_volume(
float x,
float y,
float z)
const;
193 return is_part_of_volume(v[0], v[1], v[2]);
203 emreal get_value(
float x,
float y,
float z)
const;
205 return get_value(point[0], point[1], point[2]);
212 emreal get_value(
long index)
const;
219 void set_value(
long index, emreal value);
225 void set_value(
float x,
float y,
float z, emreal value);
233 void set_origin(
float x,
float y,
float z);
235 set_origin(v[0], v[1], v[2]);
240 header_.get_origin(2));
249 const DensityHeader *get_header()
const {
return &header_; }
253 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
258 float *get_x_loc()
const {
260 "x location requested before being calculated");
267 float *get_y_loc()
const {
269 "y location requested before being calculated");
276 float *get_z_loc()
const {
278 "z location requested before being calculated");
282 emreal *get_data()
const {
return data_.get(); }
289 bool same_origin(
const DensityMap *other)
const;
295 bool same_dimensions(
const DensityMap *other)
const;
301 bool same_voxel_size(
const DensityMap *other)
const;
308 emreal get_max_value()
const;
310 emreal get_min_value()
const;
318 void add(
const DensityMap *other);
325 void pick_max(
const DensityMap *other);
328 long get_number_of_voxels()
const;
337 void set_void_map(
int nx,
int ny,
int nz);
349 void pad(
int nx,
int ny,
int nz,
float val = 0.0);
366 DensityMap *pad_margin(
int mrg_x,
int mrg_y,
int mrg_z,
float val = 0.0);
373 DensityMap *get_cropped(
float threshold);
383 float get_maximum_value_in_xy_plane(
int z_ind);
385 float get_maximum_value_in_xz_plane(
int y_ind);
387 float get_maximum_value_in_yz_plane(
int x_ind);
397 std::string get_locations_string(
float t);
400 void update_voxel_size(
float new_apix);
407 void calc_all_voxel2loc();
411 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
419 void convolute_kernel(
DensityMap *other,
double *kernel,
int dim_len);
426 void convolute_kernel(
double *kernel,
int dim_len) {
428 cmap->set_was_used(
true);
429 convolute_kernel(cmap, kernel, dim_len);
433 int lower_voxel_shift(emreal loc, emreal kdist, emreal orig,
int ndim)
const;
434 int upper_voxel_shift(emreal loc, emreal kdist, emreal orig,
int ndim)
const;
435 inline bool get_rms_calculated()
const {
return rms_calculated_; }
436 int get_dim_index_by_location(
float loc_val,
int ind)
const;
440 void update_header();
441 void reset_all_voxel2loc();
443 void allocated_data();
444 void float2real(
float *f_data, boost::scoped_array<emreal> &r_data);
445 void real2float(emreal *r_data, boost::scoped_array<float> &f_data);
447 DensityHeader header_;
448 boost::scoped_array<emreal> data_;
449 bool data_allocated_;
453 boost::scoped_array<float>
x_loc_, y_loc_, z_loc_;
458 bool rms_calculated_;
470 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
485 inline void calc_local_bounding_box(
const em::DensityMap *d_map,
double x,
486 double y,
double z,
float kdist,
int &iminx,
487 int &iminy,
int &iminz,
int &imaxx,
488 int &imaxy,
int &imaxz) {
489 const DensityHeader *h = d_map->get_header();
490 iminx = d_map->lower_voxel_shift(x, kdist, h->get_xorigin(), h->get_nx());
491 iminy = d_map->lower_voxel_shift(y, kdist, h->get_yorigin(), h->get_ny());
492 iminz = d_map->lower_voxel_shift(z, kdist, h->get_zorigin(), h->get_nz());
493 imaxx = d_map->upper_voxel_shift(x, kdist, h->get_xorigin(), h->get_nx());
494 imaxy = d_map->upper_voxel_shift(y, kdist, h->get_yorigin(), h->get_ny());
495 imaxz = d_map->upper_voxel_shift(z, kdist, h->get_zorigin(), h->get_nz());
550 IMPEMEXPORT
void get_transformed_into2(
const DensityMap *source,
554 inline bool get_interiors_intersect(
const DensityMap *d1,
556 return get_interiors_intersect(get_bounding_box(d1), get_bounding_box(d2));
576 IMPEMEXPORT DensityMap *
get_segment(DensityMap *map_to_segment,
int nx_start,
577 int nx_end,
int ny_start,
int ny_end,
578 int nz_start,
int nz_end);
581 IMPEMEXPORT DensityMap *
get_segment(DensityMap *map_to_segment,
586 float mas_threshold);
596 IMPEMEXPORT DensityMap *
binarize(DensityMap *orig_map,
float threshold,
597 bool reverse =
false);
610 IMPEMEXPORT DensityMap *
multiply(
const DensityMap *m1,
const DensityMap *m2);
613 IMPEMEXPORT
double convolute(
const DensityMap *m1,
const DensityMap *m2);
615 IMPEMEXPORT
double get_sum(
const DensityMap *m1);
636 template <
class S,
class V,
class E>
642 std::abs(arg.get_unit_cell()[0] - arg.get_unit_cell()[1]) < .01,
643 "The passed grid does not seem to have cubic voxels");
645 algebra::get_bounding_box(arg), arg.get_unit_cell()[0]);
647 static_cast<unsigned int>(ret->get_header()->get_nx()),
648 "X voxels don't match");
650 static_cast<unsigned int>(ret->get_header()->get_ny()),
651 "Y voxels don't match");
653 static_cast<unsigned int>(ret->get_header()->get_nz()),
654 "Z voxels don't match");
655 IMP_FOREACH(
typename Grid::Index i, arg.get_all_indexes()) {
656 long vi = ret->xyz_ind2voxel(i[0], i[1], i[2]);
657 ret->set_value(vi, arg[vi]);
void get_transformed_into(const DensityMap *source, const algebra::Transformation3D &tr, DensityMap *into, bool calc_rms=true)
Rotate a density map into another map.
The base class to handle reading and writing of density maps.
DensityMap * interpolate_map(DensityMap *in_map, double new_spacing)
IMP::base::Vector< IMP::base::Pointer< DensityMap > > DensityMaps
rotate a grid
DensityMap * create_density_map(const algebra::GridD< 3, algebra::DenseGridStorageD< 3, float >, float > &grid)
BoundingBoxD< 3 > BoundingBox3D
#define IMP_FUNCTION_LOG
Beginning logging for a non-member function.
A nullptr-initialized pointer to an IMP Object.
DensityMap * get_segment(DensityMap *map_to_segment, algebra::Vector3Ds vecs, float dist)
Get a segment of the map covered by the input points.
DensityMap * binarize(DensityMap *orig_map, float threshold, bool reverse=false)
double get_sum(const DensityMap *m1)
Return the sum of all voxels.
void add_to_map(DensityMap *dm, const kernel::Particles &pis)
A voxel grid in d-dimensional space space.
DensityMap * get_threshold_map(const DensityMap *orig_map, float threshold)
long get_voxel_by_location(const algebra::Vector3D &v) const
Calculate the voxel of a given location.
DensityMap * get_segment_by_masking(DensityMap *map_to_segment, DensityMap *mask, float mas_threshold)
Get a segment of the map covered by another map.
A smart pointer to a reference counted object.
bool loc_calculated_
true if the locations have already been computed
O * release()
Relinquish control of the raw pointer stored in the Pointer.
void write_map(DensityMap *m, std::string filename)
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
algebra::GridD< 3, algebra::DenseGridStorageD< 3, float >, float > get_grid(DensityMap *in_map)
Class for handling density maps.
double convolute(const DensityMap *m1, const DensityMap *m2)
DensityMap * multiply(const DensityMap *m1, const DensityMap *m2)
An abstract class for reading a map.
DensityMap * get_binarized_interior(DensityMap *dmap)
Return a binaries density map with 1 for voxels that are internal.
boost::scoped_array< float > x_loc_
A bounding box in D dimensions.
#define IMP_NO_SWIG(x)
Hide the line when SWIG is compiled or parses it.
algebra::Vector3D get_location_by_voxel(long index) const
Calculate the location of a given voxel.
double get_density(const DensityMap *m, const algebra::Vector3D &v)
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
DensityMap * read_map(std::string filename)
DensityMap * get_max_map(DensityMaps maps)
DensityMap * create_density_map(const DensityMap *other)
create a copy of another map
DensityHeader * get_header_writable()
Returns a pointer to the header of the map in a writable version.
Common base class for heavy weight IMP objects.
bool is_part_of_volume(const algebra::Vector3D &v) const
Checks whether a given point is in the grid the voxel of a given location.
Float approximate_molecular_mass(DensityMap *m, Float threshold)
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
Vector3D get_centroid(const Vector3Ds &ps)
Returns the centroid of a set of vectors.
Float get_spacing() const
Updated the voxel size of the map.
double Float
Basic floating-point value (could be float, double...)
long xyz_ind2voxel(int x, int y, int z) const
Calculate the voxel of a given xyz indexes.
All grids that are in the python API should be defined here.
A shared base class to help in debugging and things.
DensityMap * get_transformed(DensityMap *input, const algebra::Transformation3D &tr)
DensityMap * get_resampled(DensityMap *input, double scaling)
Get a resampled version of the map.
BoundingBoxD< D > get_bounding_box(const BoundingBoxD< D > &g)