IMP logo
IMP Reference Guide  develop.63b38c487d,2024/12/22
The Integrative Modeling Platform
grid.cpp
1 /**
2  * \example grid.cpp
3  * \brief Show some of the basics of using a grid from C++.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
11 #include <IMP/flags.h>
12 
13 #include <algorithm>
14 
15 int main(int argc, char *argv[]) {
16  IMP::setup_from_argv(argc, argv,
17  "Show some of the basics of using a grid from C++.");
18 
20  IMP::algebra::Vector3D(10, 10, 10));
21  // declare a grid covering the space 0 to 100 with a cell size of 1 and
22  // default value of 0
23  // unfortunately, due to swig GridD takes lots of redundant template
24  // parameters
26  double> Grid;
27  Grid grid(1, bb, 0);
28  // fill it with a gradient
29  for(Grid::Index i : grid.get_all_indexes()) {
30  IMP::algebra::Vector3D c = grid.get_center(i);
31  grid[i] = IMP::algebra::get_distance(c, IMP::algebra::Vector3D(10, 10, 10));
32  }
33  // we can get smooth values at off-grid points
34  // it is boring below .5
35  std::cout << "Smooth" << std::endl;
36  for (double x = .5; x < 4; x += .1) {
38  grid, IMP::algebra::Vector3D(x, x, x));
39  std::cout << vo << " ";
40  }
41  std::cout << std::endl;
42  // we can get chunky values at off-grid points instead
43  std::cout << "Chunky" << std::endl;
44  for (double x = .5; x < 4; x += .1) {
45  double vo = grid[IMP::algebra::Vector3D(x, x, x)];
46  std::cout << vo << " ";
47  }
48  std::cout << std::endl;
49  return EXIT_SUCCESS;
50 }
A voxel grid in d-dimensional space.
Definition: GridD.h:79
Functions to generate vectors.
Value get_linearly_interpolated(const GridD< D, Storage, Value, Embedding > &g, const VectorD< D > &pt)
Get the value from the grid with linear interpolation.
Definition: grid_utility.h:23
VectorD< 3 > Vector3D
Definition: VectorD.h:408
Support for shared command line flags.
All grids that are in the Python API should be defined here.
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.