IMP.bff
Loading...
Searching...
No Matches
PathMap.h
Go to the documentation of this file.
1
9#ifndef IMPBFF_PATHMAP_H
10#define IMPBFF_PATHMAP_H
11
12#include <IMP/bff/bff_config.h>
13
14#include <stdlib.h> /* malloc, free, rand */
15#include <limits>
16
17#include <cmath>
18#include <algorithm>
19#include <unordered_set>
20#include <queue>
21#include <vector>
22#include <utility> /* std::pair */
23#include <Eigen/Dense>
24
25#include <IMP/Object.h>
26#include <IMP/Particle.h>
27#include <IMP/core/XYZR.h>
28#include <IMP/em/SampledDensityMap.h>
29
30#include <IMP/em/MRCReaderWriter.h>
31#include <IMP/em/XplorReaderWriter.h>
32#include <IMP/em/EMReaderWriter.h>
33#include <IMP/em/SpiderReaderWriter.h>
34
35#include <IMP/bff/PathMapHeader.h>
36#include <IMP/bff/PathMapTile.h>
37#include <IMP/bff/PathMapTileEdge.h>
38
39IMPBFF_BEGIN_NAMESPACE
40
41class PathMapTile;
42
43
44class IMPBFFEXPORT PathMap : public IMP::em::SampledDensityMap {
45
46friend class PathMapTile;
47friend class AV;
48
49private:
50
51 // used in path search
52 std::vector<bool> visited;
53 std::vector<bool> edge_computed;
54 std::vector<float> cost;
55
56protected:
57
58 std::vector<PathMapTile> tiles;
60 std::vector<int> offsets_;
61 std::vector<PathMapTileEdge>& get_edges(int tile_idx);
62
63public:
64
65
78 float obstacle_threshold=-1.0,
79 bool binarize=true,
80 float obstacle_penalty=TILE_PENALTY_DEFAULT,
81 bool reset_tile_edges=true
82 );
83
91 void resize(unsigned int nvox);
92
109 void set_data(double *input, int n_input,
110 float obstacle_threshold=-1, bool binarize=true,
111 float obstacle_penalty=TILE_PENALTY_DEFAULT);
112
120 std::vector<int> get_neighbor_idx_offsets(double neighbor_radius = -1){
121 if(neighbor_radius < 0){
122 auto pmh = get_path_map_header();
123 neighbor_radius = pmh->get_neighbor_radius();
124 }
125 const int nn = ceil(neighbor_radius);
126 const double nr2 = neighbor_radius * neighbor_radius;
127
128 const IMP::em::DensityHeader* header = get_header();
129 int nx = header->get_nx();
130 int ny = header->get_ny();
131 int nx_ny = nx * ny;
132
133 std::vector<int> offsets;
134 for(int z = -nn; z < nn; z += 1) {
135 double dz2 = z * z;
136 int oz = z * nx_ny;
137 for(int y = -nn; y < nn; y++) {
138 int oy = y * nx;
139 double dz2_dy2 = dz2 + y * y;
140 for(int x = -nn; x < nn; x++) {
141 int ox = x;
142 int dz2_dy2_dx2 = dz2_dy2 + x * x;
143 if(dz2_dy2_dx2 <= nr2){
144 int d; // edge_cost is a float stored in an 32bit int
145 float *p = (float*) &d; // Make a float pointer point at the integer
146 *p = sqrt((float) dz2_dy2_dx2); // Pretend that the integer is a float and store the value
147 int tile_offset = oz + oy + ox;
148 offsets.emplace_back(z);
149 offsets.emplace_back(y);
150 offsets.emplace_back(x);
151 offsets.emplace_back(tile_offset);
152 offsets.emplace_back(d);
153 }
154 }
155 }
156 }
157 return offsets;
158 }
159
161
168 int get_dim_index_by_voxel(long index, int dim);
169
176 const PathMapHeader *get_path_map_header() const { return &pathMapHeader_; }
177
178
185 PathMapHeader *get_path_map_header_writable() { return &pathMapHeader_; }
186
187
197 void set_path_map_header(PathMapHeader &path_map_header, float resolution = -1.0);
198
199
217 std::vector<float> get_tile_values(
218 int value_type = PM_TILE_COST,
219 std::pair<float, float> bounds = std::pair<float, float>(
220 {std::numeric_limits<float>::min(),
221 std::numeric_limits<float>::max()}),
222 const std::string &feature_name=""
223 );
224
242 float **output, int *nx, int *ny, int *nz,
243 int value_type = PM_TILE_COST,
244 std::pair<float, float> bounds = std::pair<float, float>(
245 {std::numeric_limits<float>::min(),
246 std::numeric_limits<float>::max()}),
247 const std::string &feature_name=""
248 );
249
254 std::vector<PathMapTile>& get_tiles();
255
257
267 void fill_sphere(IMP::algebra::Vector3D r0, double radius, double value, bool inverse=true);
268
283 void find_path(long path_begin_idx, long path_end_idx = -1, int heuristic_mode = 0);
284
285
297 void find_path_dijkstra(long path_begin_idx, long path_end_idx = -1);
298
299
312 void find_path_astar(long path_begin_idx, long path_end_idx = -1);
313
321 std::vector<IMP::algebra::Vector4D> get_xyz_density();
322
331 void get_xyz_density(double** output, int* n_output1, int* n_output2);
332
341 void sample_obstacles(double extra_radius=0.0);
342
352 explicit PathMap(
353 PathMapHeader &header,
354 std::string name = "PathMap%1%",
355 IMP::em::KernelType kt = IMP::em::BINARIZED_SPHERE,
356 float resolution = -1.0
357 );
358
359};
360
361
377IMPEMEXPORT
379 PathMap *m,
380 std::string filename,
381 int value_type,
382 const std::pair<float, float> bounds = std::pair<float, float>(
383 std::numeric_limits<float>::min(),
384 std::numeric_limits<float>::max()
385 ),
386 const std::string &feature_name = ""
387);
388
389IMPBFF_END_NAMESPACE
390
391#endif //IMPBFF_PATHMAP_H
IMPEMEXPORT void write_path_map(PathMap *m, std::string filename, int value_type, const std::pair< float, float > bounds=std::pair< float, float >(std::numeric_limits< float >::min(), std::numeric_limits< float >::max()), const std::string &feature_name="")
Writes a path map to a file.
const float TILE_PENALTY_DEFAULT
Definition PathMapTile.h:25
@ PM_TILE_COST
Write path penalty.
Definition PathMapTile.h:37
A decorator for a particle with accessible volume (AV).
Definition AV.h:90
Definition PathMapHeader.h:33
Definition PathMap.h:44
void find_path_astar(long path_begin_idx, long path_end_idx=-1)
Finds the shortest path between two indices using the A* algorithm.
void update_tiles(float obstacle_threshold=-1.0, bool binarize=true, float obstacle_penalty=TILE_PENALTY_DEFAULT, bool reset_tile_edges=true)
Updates the tiles in the path map.
std::vector< PathMapTile > tiles
Definition PathMap.h:58
std::vector< float > get_tile_values(int value_type=PM_TILE_COST, std::pair< float, float > bounds=std::pair< float, float >({std::numeric_limits< float >::min(), std::numeric_limits< float >::max()}), const std::string &feature_name="")
Get the values of all tiles.
void get_xyz_density(double **output, int *n_output1, int *n_output2)
Get the XYZ density of the path map. This function returns the XYZ density of the path map as a 2D ar...
void fill_sphere(IMP::algebra::Vector3D r0, double radius, double value, bool inverse=true)
Change the value of a density inside or outside of a sphere.
std::vector< int > get_neighbor_idx_offsets(double neighbor_radius=-1)
Definition PathMap.h:120
std::vector< int > offsets_
Definition PathMap.h:60
int get_dim_index_by_voxel(long index, int dim)
Get index of voxel in an axis.
void set_data(double *input, int n_input, float obstacle_threshold=-1, bool binarize=true, float obstacle_penalty=TILE_PENALTY_DEFAULT)
Sets the data for the path map.
PathMapHeader * get_path_map_header_writable()
Returns a pointer to the header of the map in a writable version.
Definition PathMap.h:185
const PathMapHeader * get_path_map_header() const
Returns a read-only pointer to the header of the map.
Definition PathMap.h:176
std::vector< PathMapTile > & get_tiles()
void find_path_dijkstra(long path_begin_idx, long path_end_idx=-1)
Finds the shortest path between two nodes using Dijkstra's algorithm.
void find_path(long path_begin_idx, long path_end_idx=-1, int heuristic_mode=0)
Finds a path between two indices in the path map.
void sample_obstacles(double extra_radius=0.0)
Resamples the obstacles in the path map.
std::vector< PathMapTileEdge > & get_edges(int tile_idx)
void get_tile_values(float **output, int *nx, int *ny, int *nz, int value_type=PM_TILE_COST, std::pair< float, float > bounds=std::pair< float, float >({std::numeric_limits< float >::min(), std::numeric_limits< float >::max()}), const std::string &feature_name="")
Retrieves the values of the tiles in the path map.
PathMapHeader pathMapHeader_
Definition PathMap.h:59
std::vector< IMP::algebra::Vector4D > get_xyz_density()
Get the XYZ density of the path map. This function returns a vector of IMP::algebra::Vector4D objects...
void set_path_map_header(PathMapHeader &path_map_header, float resolution=-1.0)
Set the path map header.
void resize(unsigned int nvox)
Resizes the PathMap object.
PathMap(PathMapHeader &header, std::string name="PathMap%1%", IMP::em::KernelType kt=IMP::em::BINARIZED_SPHERE, float resolution=-1.0)
Constructs a PathMap object.
Definition PathMapTile.h:50