IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
grid.cpp
1/**
2 * \example grid.cpp
3 * Show some of the basics of using a grid from C++.
4 *
5 * Copyright 2007-2026 IMP Inventors. All rights reserved.
6 *
7 */
11#include <IMP/flags.h>
12
13#include <algorithm>
14
15int 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:81
Support for shared command line flags.
BoundingBoxD< 3 > BoundingBox3D
Typedef for Python.
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.
Value get_linearly_interpolated(const GridD< D, Storage, Value, Embedding > &g, const VectorD< D > &pt)
Get the value from the grid with linear interpolation.
VectorD< 3 > Vector3D
Definition VectorD.h:407
void setup_from_argv(int argc, char **argv, std::string description)
Parse the command line flags and return the positional arguments.
All grids that are in the Python API should be defined here.
Functions to generate vectors.