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>
24 IMPALGEBRA_BEGIN_NAMESPACE
38 <<
" with unbounded storage.");
40 void set_number_of_voxels(
Ints) {
42 <<
" with unbounded storage.");
44 unsigned int get_number_of_voxels(
int)
const {
45 return std::numeric_limits<int>::max();
47 static bool get_is_bounded() {
return false; }
53 typedef internal::GridIndexIterator<
56 ExtendedIndexIterator;
58 class ExtendedIndexIterator;
60 ExtendedIndexIterator extended_indexes_begin(
64 return ExtendedIndexIterator(lb, eub);
66 ExtendedIndexIterator extended_indexes_end(
68 return ExtendedIndexIterator();
74 extended_indexes_end(lb, ub));
102 void set_number_of_voxels(
Ints bds) {
104 "Wrong number of dimensions");
112 static bool get_is_bounded() {
return true; }
116 set_number_of_voxels(counts);
124 unsigned int get_number_of_voxels()
const {
126 for (
unsigned int i = 1; i < d_.get_dimension(); ++i) {
142 class AllIndexIterator;
144 typedef internal::GridIndexIterator<
149 AllIndexIterator all_indexes_begin()
const {
150 return indexes_begin(
152 d_.get_dimension(), 0),
155 AllIndexIterator all_indexes_end()
const {
return indexes_end(d_, d_); }
157 base::Vector<GridIndexD<D> > get_all_indexes()
const {
158 base::Vector<GridIndexD<D> > ret(all_indexes_begin(), all_indexes_end());
181 typedef internal::GridIndexIterator<
182 ExtendedGridIndexD<D>,
183 internal::AllItHelp<ExtendedGridIndexD<D>, GridIndexD<D> > >
185 typedef internal::GridIndexIterator<
186 ExtendedGridIndexD<D>,
187 internal::AllItHelp<ExtendedGridIndexD<D>, ExtendedGridIndexD<D> > >
188 ExtendedIndexIterator;
191 class ExtendedIndexIterator;
193 IndexIterator indexes_begin(
const ExtendedGridIndexD<D>& lb,
194 const ExtendedGridIndexD<D>& ub)
const {
195 ExtendedGridIndexD<D> eub = ub.get_uniform_offset(1);
196 std::pair<ExtendedGridIndexD<D>, ExtendedGridIndexD<D> > bp =
197 internal::intersect<ExtendedGridIndexD<D> >(lb, eub, d_);
198 if (bp.first == bp.second) {
199 return IndexIterator();
203 return IndexIterator(bp.first, bp.second);
206 IndexIterator indexes_end(
const ExtendedGridIndexD<D>&,
207 const ExtendedGridIndexD<D>&)
const {
209 return IndexIterator();
211 ExtendedIndexIterator extended_indexes_begin(
212 const ExtendedGridIndexD<D>& lb,
const ExtendedGridIndexD<D>& ub)
const {
213 ExtendedGridIndexD<D> eub = ub.get_uniform_offset(1);
214 return ExtendedIndexIterator(lb, eub);
216 ExtendedIndexIterator extended_indexes_end(
217 const ExtendedGridIndexD<D>&,
const ExtendedGridIndexD<D>&)
const {
219 return ExtendedIndexIterator();
224 const ExtendedGridIndexD<D>& lb,
const ExtendedGridIndexD<D>& ub)
const {
225 return base::Vector<GridIndexD<D> >(indexes_begin(lb, ub),
226 indexes_end(lb, ub));
228 base::Vector<ExtendedGridIndexD<D> > get_extended_indexes(
229 const ExtendedGridIndexD<D>& lb,
const ExtendedGridIndexD<D>& ub)
const {
230 return base::Vector<ExtendedGridIndexD<D> >(extended_indexes_begin(lb, ub),
231 extended_indexes_end(lb, ub));
244 for (
unsigned int i = 0; i < d_.get_dimension(); ++i) {
245 if (v[i] < 0 || v[i] >= static_cast<int>(get_number_of_voxels(i))) {
254 for (
unsigned int i = 0; i < ret.get_dimension(); ++i) {
255 ret.access_data().get_data()[i] = 0;
262 for (
unsigned int i = 0; i < ret.get_dimension(); ++i) {
263 --ret.access_data().get_data()[i];
270 typedef BoundedGridRangeD<1> BoundedGridRange1D;
271 typedef BoundedGridRangeD<2> BoundedGridRange2D;
272 typedef BoundedGridRangeD<3> BoundedGridRange3D;
273 typedef BoundedGridRangeD<4> BoundedGridRange4D;
274 typedef BoundedGridRangeD<5> BoundedGridRange5D;
275 typedef BoundedGridRangeD<6> BoundedGridRange6D;
276 typedef BoundedGridRangeD<-1> BoundedGridRangeKD;
286 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 maximumal cell.
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.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Various general useful macros for IMP.
unsigned int get_number_of_voxels(unsigned int i) const
Return the number of voxels in a certain direction.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
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.
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
A bounding box in D dimensions.
A class for storing lists of IMP items.
Declare an efficient stl-compatible map.