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() {
57 typedef internal::GridIndexIterator<ExtendedGridIndexD<D>,
58 internal::AllItHelp<ExtendedGridIndexD<D>,
61 ExtendedIndexIterator;
63 class ExtendedIndexIterator;
71 return ExtendedIndexIterator(lb, eub);
76 return ExtendedIndexIterator();
83 (extended_indexes_begin(lb, ub),
84 extended_indexes_end(lb, ub));
121 void set_number_of_voxels(
Ints bds) {
123 || static_cast<int>(bds.size()) ==D,
124 "Wrong number of dimensions");
131 static bool get_is_bounded() {
138 set_number_of_voxels(counts);
146 unsigned int get_number_of_voxels()
const {
148 for (
unsigned int i=1; i< d_.get_dimension(); ++i) {
166 class AllIndexIterator;
168 typedef internal::GridIndexIterator<ExtendedGridIndexD<D>,
169 internal::AllItHelp<ExtendedGridIndexD<D>,
173 AllIndexIterator all_indexes_begin()
const {
177 AllIndexIterator all_indexes_end()
const {
178 return indexes_end(ExtendedGridIndexD<D>(
Ints(d_.get_dimension(), 0)),
182 base::Vector<GridIndexD<D> > get_all_indexes()
const {
183 base::Vector<GridIndexD<D> > ret(all_indexes_begin(),
209 typedef internal::GridIndexIterator<ExtendedGridIndexD<D>,
210 internal::AllItHelp<ExtendedGridIndexD<D>,
213 typedef internal::GridIndexIterator<ExtendedGridIndexD<D>,
214 internal::AllItHelp<ExtendedGridIndexD<D>,
215 ExtendedGridIndexD<D>
217 ExtendedIndexIterator;
220 class ExtendedIndexIterator;
222 IndexIterator indexes_begin(
const ExtendedGridIndexD<D>& lb,
223 const ExtendedGridIndexD<D>& ub)
const {
224 ExtendedGridIndexD<D> eub=ub.get_uniform_offset(1);
225 std::pair<ExtendedGridIndexD<D>, ExtendedGridIndexD<D> > bp
226 = internal::intersect<ExtendedGridIndexD<D> >(lb,eub, d_);
227 if (bp.first== bp.second) {
228 return IndexIterator();
233 return IndexIterator(bp.first, bp.second);
236 IndexIterator indexes_end(
const ExtendedGridIndexD<D>&,
237 const ExtendedGridIndexD<D>&)
const {
239 return IndexIterator();
241 ExtendedIndexIterator
242 extended_indexes_begin(
const ExtendedGridIndexD<D>& lb,
243 const ExtendedGridIndexD<D>& ub)
const {
244 ExtendedGridIndexD<D> eub=ub.get_uniform_offset(1);
245 return ExtendedIndexIterator(lb, eub);
247 ExtendedIndexIterator
248 extended_indexes_end(
const ExtendedGridIndexD<D>&,
249 const ExtendedGridIndexD<D>&)
const {
251 return ExtendedIndexIterator();
255 base::Vector<GridIndexD<D> >
257 const ExtendedGridIndexD<D>& ub)
const {
258 return base::Vector<GridIndexD<D> >(indexes_begin(lb, ub),
259 indexes_end(lb, ub));
261 base::Vector<ExtendedGridIndexD<D> >
262 get_extended_indexes(
const ExtendedGridIndexD<D>& lb,
263 const ExtendedGridIndexD<D>& ub)
const {
264 return base::Vector<ExtendedGridIndexD<D> >
265 (extended_indexes_begin(lb, ub),
266 extended_indexes_end(lb, ub));
280 for (
unsigned int i=0; i< d_.get_dimension(); ++i) {
282 || v[i] >= static_cast<int>(get_number_of_voxels(i))) {
295 for (
unsigned int i=0; i< ret.get_dimension(); ++i) {
296 --ret.access_data().get_data()[i];
305 typedef BoundedGridRangeD<1> BoundedGridRange1D;
306 typedef BoundedGridRangeD<2> BoundedGridRange2D;
307 typedef BoundedGridRangeD<3> BoundedGridRange3D;
308 typedef BoundedGridRangeD<4> BoundedGridRange4D;
309 typedef BoundedGridRangeD<5> BoundedGridRange5D;
310 typedef BoundedGridRangeD<6> BoundedGridRange6D;
311 typedef BoundedGridRangeD<-1> BoundedGridRangeKD;
321 IMPALGEBRA_END_NAMESPACE