IMP logo
IMP Reference Guide  2.15.0
The Integrative Modeling Platform
IMP::algebra::GridD< D, StorageT, Value, EmbeddingT > Class Template Reference

A voxel grid in d-dimensional space. More...

#include <IMP/algebra/GridD.h>

+ Inheritance diagram for IMP::algebra::GridD< D, StorageT, Value, EmbeddingT >:

Detailed Description

template<int D, class StorageT, class Value, class EmbeddingT = DefaultEmbeddingD<D>>
class IMP::algebra::GridD< D, StorageT, Value, EmbeddingT >

A voxel grid in d-dimensional space.

First some terminology:

  • a voxel is the data stored at a given location in space
  • an Index is a way of identifying a particular voxel. That is, given an index, it is easy to get the voxel, but not vice-versa.
  • an ExtendedIndex identifies a particular region in space, but it may not have a corresponding voxel (if it is outside of the region the grid is built on or if that voxel has not yet been added to the sparse grid).

IMP provides support for a variety of spatial grids. The grid support in C++ is implemented by combining several different layers to specify what capabilities are desired. These layers are:

  • Data: any type of data can be stored in a voxel of the grid.
  • Boundedness: By using UnboundedGridStorage3D or BoundedGridStorage3D, one can choose whether you want a grid over a finite region of space or over the whole space.
  • Storage: by choosing SparseGridStorage3D or DenseGridStorage3D, you can choose whether you want to store all voxels or only a subset of the voxels. The former is faster and more compact when most of the voxels are used, the latter when only a few are used (say <1/4).
  • Geometry: The Grid3D class itself provides a geometric layer, mapping Vector3D objects into voxels in the grid.

These are implemented as mix-ins, so each layer provides a set of accessible functionality as methods/types in the final class.

Basic operations
Creating a grid with a given cell size and upper and lower bounds
BoundingBox3D bb(Vector3D(10,10,10), Vector3D(100,100,100));
typedef Grid3D<Ints> Grid;
Grid grid(5, bb, 0.0);

Iterate over the set of voxels incident on a bounding box:

BoundingBoxD<3> bb(Vector3D(20.2,20.3,20.5), Vector3D(31.3,32.5,38.9));
for (Grid::IndexIterator it= grid.voxels_begin(bb);
it != grid.voxels_end(bb); ++it) {
it->push_back(1);
}
See Also
DenseGridStorage3D
SparseGridStorageD
Examples:
grid.cpp.

Definition at line 79 of file GridD.h.

Public Types

typedef EmbeddingT Embedding
 
typedef StorageT Storage
 
typedef VectorD< D > Vector
 

Public Member Functions

 GridD (const Ints counts, const BoundingBoxD< D > &bb, Value default_value=Value())
 
 GridD (double side, const BoundingBoxD< D > &bb, const Value &default_value=Value())
 
 GridD (const VectorD< D > &sides, const BoundingBoxD< D > &bb, const Value &default_value=Value())
 
 GridD (const Storage &storage, const Embedding &embed)
 
 GridD (double side, const VectorD< D > &origin, const Value &default_value=Value())
 
 GridD (const VectorD< D > &sides, const VectorD< D > &origin, const Value &default_value=Value())
 
 GridD ()
 An empty, undefined grid. More...
 
GridIndexD< D > add_voxel (const VectorD< D > &pt, const Value &vt)
 
const Value at (VectorD< D >) const
 
Valueat (VectorD< D >)
 
BoundingBoxD< D > get_bounding_box () const
 
ExtendedGridIndexD< D > get_extended_index (const GridIndexD< D > &index) const
 Convert an index back to an extended index. More...
 
Valueoperator[] (VectorD< D >)
 
const Value operator[] (VectorD< D >) const
 
void set_bounding_box (const BoundingBoxD< D > &bb3)
 Change the bounding box but not the grid or contents. More...
 
void show (std::ostream &out=std::cout) const
 

Get nearest

If the point is in the bounding box of the grid, this is the index of the voxel containing the point, otherwise it is the closest one in the bounding box. This can only be used with bounded grids, right now.

GridIndexD< D > get_nearest_index (const VectorD< D > &pt) const
 
ExtendedGridIndexD< D > get_nearest_extended_index (const VectorD< D > &pt) const
 

Voxel iterators

These iterators go through a range of voxels in the grid. These voxels include any that touch or are contained in the shape passed to the begin/end calls.

typedef
internal::GridIndexIterator
< ExtendedGridIndexD< D >
, internal::AllItHelp
< ExtendedGridIndexD< D >
, ExtendedGridIndexD< D > > > 
ExtendedIndexIterator
 
typedef boost::iterator_range
< typename
Storage::IndexIterator > 
Indexes
 
typedef boost::iterator_range
< typename
Storage::AllIndexIterator > 
AllIndexes
 
typedef boost::iterator_range
< ExtendedIndexIterator > 
ExtendedIndexes
 
VoxelIterator voxels_begin (const BoundingBoxD< D > &bb)
 
VoxelIterator voxels_end (const BoundingBoxD< D > &bb)
 
VoxelConstIterator voxels_begin (const BoundingBoxD< D > &bb) const
 
VoxelConstIterator voxels_end (const BoundingBoxD< D > &bb) const
 
Storage::IndexIterator indexes_begin (const BoundingBoxD< D > &bb) const
 
Storage::IndexIterator indexes_end (const BoundingBoxD< D > &) const
 
ExtendedIndexIterator extended_indexes_begin (const BoundingBoxD< D > &bb) const
 
ExtendedIndexIterator extended_indexes_end (const BoundingBoxD< D > &) const
 
Indexes get_indexes (const BoundingBoxD< D > &bb) const
 
AllIndexes get_all_indexes () const
 
ExtendedIndexes get_extended_indexes (const BoundingBoxD< D > &bb) const
 

Apply

In C++, iterating through all the voxels can be slow, and it can be faster to use functional programming to apply a function to each voxel. The passed apply function takes three arguments, the grid, the Grid::Index of the voxel and the Grid::Vector for the center of the voxel.

template<class Functor >
Functor apply (const Functor &f) const
 

Constructor & Destructor Documentation

template<int D, class StorageT, class Value, class EmbeddingT = DefaultEmbeddingD<D>>
IMP::algebra::GridD< D, StorageT, Value, EmbeddingT >::GridD ( const Ints  counts,
const BoundingBoxD< D > &  bb,
Value  default_value = Value() 
)

Create a grid from a bounding box and the counts in each direction.

This constructor works for all bounded grids.

Definition at line 138 of file GridD.h.

template<int D, class StorageT, class Value, class EmbeddingT = DefaultEmbeddingD<D>>
IMP::algebra::GridD< D, StorageT, Value, EmbeddingT >::GridD ( double  side,
const BoundingBoxD< D > &  bb,
const Value default_value = Value() 
)

Create a grid from a bounding box and the side of the cubical voxel.

This constructor works for all bounded grids.

Definition at line 150 of file GridD.h.

template<int D, class StorageT, class Value, class EmbeddingT = DefaultEmbeddingD<D>>
IMP::algebra::GridD< D, StorageT, Value, EmbeddingT >::GridD ( const VectorD< D > &  sides,
const BoundingBoxD< D > &  bb,
const Value default_value = Value() 
)

Create a grid from a bounding box and the sides of the variable size voxel.

This constructor works for all bounded grids.

Definition at line 165 of file GridD.h.

template<int D, class StorageT, class Value, class EmbeddingT = DefaultEmbeddingD<D>>
IMP::algebra::GridD< D, StorageT, Value, EmbeddingT >::GridD ( const Storage &  storage,
const Embedding &  embed 
)

Advanced constructor if you want to explicitly init storage and embedding.

Definition at line 176 of file GridD.h.

template<int D, class StorageT, class Value, class EmbeddingT = DefaultEmbeddingD<D>>
IMP::algebra::GridD< D, StorageT, Value, EmbeddingT >::GridD ( double  side,
const VectorD< D > &  origin,
const Value default_value = Value() 
)

Construct a grid from the cubical voxel side and the origin.

This constructor is only valid with unbounded (hence sparse) grids.

Definition at line 184 of file GridD.h.

template<int D, class StorageT, class Value, class EmbeddingT = DefaultEmbeddingD<D>>
IMP::algebra::GridD< D, StorageT, Value, EmbeddingT >::GridD ( const VectorD< D > &  sides,
const VectorD< D > &  origin,
const Value default_value = Value() 
)

Construct a grid from the variable voxel side and the origin.

This constructor is only valid with unbounded (hence sparse) grids.

Definition at line 194 of file GridD.h.

template<int D, class StorageT, class Value, class EmbeddingT = DefaultEmbeddingD<D>>
IMP::algebra::GridD< D, StorageT, Value, EmbeddingT >::GridD ( )

An empty, undefined grid.

Make sure you initialize it before you try to use it.

Definition at line 201 of file GridD.h.

Member Function Documentation

template<int D, class StorageT, class Value, class EmbeddingT = DefaultEmbeddingD<D>>
ExtendedGridIndexD<D> IMP::algebra::GridD< D, StorageT, Value, EmbeddingT >::get_extended_index ( const GridIndexD< D > &  index) const

Convert an index back to an extended index.

Definition at line 247 of file GridD.h.

template<int D, class StorageT, class Value, class EmbeddingT = DefaultEmbeddingD<D>>
void IMP::algebra::GridD< D, StorageT, Value, EmbeddingT >::set_bounding_box ( const BoundingBoxD< D > &  bb3)

Change the bounding box but not the grid or contents.

The origin is set to corner 0 of the new bounding box and the grid voxels are resized as needed.

Definition at line 270 of file GridD.h.


The documentation for this class was generated from the following file: