8 #ifndef IMPALGEBRA_GRID_RANGES_H
9 #define IMPALGEBRA_GRID_RANGES_H
11 #include <IMP/algebra/algebra_config.h>
18 #include <boost/iterator/transform_iterator.hpp>
23 IMPALGEBRA_BEGIN_NAMESPACE
37 <<
" with unbounded storage.");
39 void set_number_of_voxels(
Ints) {
41 <<
" with unbounded storage.");
43 unsigned int get_number_of_voxels(
int)
const {
44 return std::numeric_limits<int>::max();
46 static bool get_is_bounded() {
return false; }
52 typedef internal::GridIndexIterator<
55 ExtendedIndexIterator;
57 class ExtendedIndexIterator;
59 ExtendedIndexIterator extended_indexes_begin(
63 return ExtendedIndexIterator(lb, eub);
65 ExtendedIndexIterator extended_indexes_end(
67 return ExtendedIndexIterator();
73 extended_indexes_end(lb, ub));
101 void set_number_of_voxels(
Ints bds) {
103 "Wrong number of dimensions");
111 static bool get_is_bounded() {
return true; }
115 set_number_of_voxels(counts);
123 unsigned int get_number_of_voxels()
const {
125 for (
unsigned int i = 1; i < d_.get_dimension(); ++i) {
141 class AllIndexIterator;
143 typedef internal::GridIndexIterator<
148 AllIndexIterator all_indexes_begin()
const {
149 return indexes_begin(
151 d_.get_dimension(), 0),
154 AllIndexIterator all_indexes_end()
const {
return indexes_end(d_, d_); }
156 base::Vector<GridIndexD<D> > get_all_indexes()
const {
157 base::Vector<GridIndexD<D> > ret(all_indexes_begin(), all_indexes_end());
180 typedef internal::GridIndexIterator<
181 ExtendedGridIndexD<D>,
182 internal::AllItHelp<ExtendedGridIndexD<D>, GridIndexD<D> > >
184 typedef internal::GridIndexIterator<
185 ExtendedGridIndexD<D>,
186 internal::AllItHelp<ExtendedGridIndexD<D>, ExtendedGridIndexD<D> > >
187 ExtendedIndexIterator;
190 class ExtendedIndexIterator;
192 IndexIterator indexes_begin(
const ExtendedGridIndexD<D>& lb,
193 const ExtendedGridIndexD<D>& ub)
const {
194 ExtendedGridIndexD<D> eub = ub.get_uniform_offset(1);
195 std::pair<ExtendedGridIndexD<D>, ExtendedGridIndexD<D> > bp =
196 internal::intersect<ExtendedGridIndexD<D> >(lb, eub, d_);
197 if (bp.first == bp.second) {
198 return IndexIterator();
202 return IndexIterator(bp.first, bp.second);
205 IndexIterator indexes_end(
const ExtendedGridIndexD<D>&,
206 const ExtendedGridIndexD<D>&)
const {
208 return IndexIterator();
210 ExtendedIndexIterator extended_indexes_begin(
211 const ExtendedGridIndexD<D>& lb,
const ExtendedGridIndexD<D>& ub)
const {
212 ExtendedGridIndexD<D> eub = ub.get_uniform_offset(1);
213 return ExtendedIndexIterator(lb, eub);
215 ExtendedIndexIterator extended_indexes_end(
216 const ExtendedGridIndexD<D>&,
const ExtendedGridIndexD<D>&)
const {
218 return ExtendedIndexIterator();
223 const ExtendedGridIndexD<D>& lb,
const ExtendedGridIndexD<D>& ub)
const {
224 return base::Vector<GridIndexD<D> >(indexes_begin(lb, ub),
225 indexes_end(lb, ub));
227 base::Vector<ExtendedGridIndexD<D> > get_extended_indexes(
228 const ExtendedGridIndexD<D>& lb,
const ExtendedGridIndexD<D>& ub)
const {
229 return base::Vector<ExtendedGridIndexD<D> >(extended_indexes_begin(lb, ub),
230 extended_indexes_end(lb, ub));
243 for (
unsigned int i = 0; i < d_.get_dimension(); ++i) {
244 if (v[i] < 0 || v[i] >= static_cast<int>(get_number_of_voxels(i))) {
253 for (
unsigned int i = 0; i < ret.get_dimension(); ++i) {
254 ret.access_data().get_data()[i] = 0;
261 for (
unsigned int i = 0; i < ret.get_dimension(); ++i) {
262 --ret.access_data().get_data()[i];
269 typedef BoundedGridRangeD<1> BoundedGridRange1D;
270 typedef BoundedGridRangeD<2> BoundedGridRange2D;
271 typedef BoundedGridRangeD<3> BoundedGridRange3D;
272 typedef BoundedGridRangeD<4> BoundedGridRange4D;
273 typedef BoundedGridRangeD<5> BoundedGridRange5D;
274 typedef BoundedGridRangeD<6> BoundedGridRange6D;
275 typedef BoundedGridRangeD<-1> BoundedGridRangeKD;
285 IMPALGEBRA_END_NAMESPACE
GridIndexD< D > get_index(const ExtendedGridIndexD< D > &v) const
Convert a ExtendedIndex into a real Index if possible.
ParticleIndexes get_indexes(const ParticlesTemp &ps)
ExtendedGridIndexD< D > get_end_index() const
Get the past-end voxel.
ExtendedGridIndexD< D > get_maximum_extended_index() const
Return the index of the maximal cell.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
A class to represent a voxel grid.
Represent a real cell in a grid (one within the bounding box)
An index in an infinite grid on space.
unsigned int get_number_of_voxels(unsigned int i) const
Return the number of voxels in a certain direction.
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
Various general useful macros for IMP.
ExtendedGridIndexD< D > get_minimum_extended_index() const
Return the ExtendedGridIndexD of all zeros.
bool get_has_index(const ExtendedGridIndexD< D > &v) const
Return true if the ExtendedIndex is also a normal index value.
A bounding box in D dimensions.
A class for storing lists of IMP items.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.