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>
19 #include <boost/serialization/access.hpp>
24 IMPALGEBRA_BEGIN_NAMESPACE
30 friend class boost::serialization::access;
32 template<
class Archive>
void serialize(Archive &ar,
const unsigned int) {}
42 <<
" with unbounded storage.");
44 void set_number_of_voxels(
Ints) {
46 <<
" with unbounded storage.");
48 unsigned int get_number_of_voxels(
int)
const {
49 return std::numeric_limits<int>::max();
51 static bool get_is_bounded() {
return false; }
57 typedef internal::GridIndexIterator<
60 ExtendedIndexIterator;
62 class ExtendedIndexIterator;
64 ExtendedIndexIterator extended_indexes_begin(
68 return ExtendedIndexIterator(lb, eub);
70 ExtendedIndexIterator extended_indexes_end(
72 return ExtendedIndexIterator();
78 extended_indexes_end(lb, ub));
106 friend class boost::serialization::access;
108 template<
class Archive>
void serialize(Archive &ar,
const unsigned int) {
112 void set_number_of_voxels(
Ints bds) {
114 "Wrong number of dimensions");
122 static bool get_is_bounded() {
return true; }
126 set_number_of_voxels(counts);
134 unsigned int get_number_of_voxels()
const {
136 for (
unsigned int i = 1; i < d_.get_dimension(); ++i) {
152 class AllIndexIterator;
154 typedef internal::GridIndexIterator<
159 AllIndexIterator all_indexes_begin()
const {
160 return indexes_begin(
162 d_.get_dimension(), 0),
165 AllIndexIterator all_indexes_end()
const {
return indexes_end(d_, d_); }
167 Vector<GridIndexD<D> > get_all_indexes()
const {
168 Vector<GridIndexD<D> > ret(all_indexes_begin(), all_indexes_end());
191 typedef internal::GridIndexIterator<
192 ExtendedGridIndexD<D>,
193 internal::AllItHelp<ExtendedGridIndexD<D>, GridIndexD<D> > >
195 typedef internal::GridIndexIterator<
196 ExtendedGridIndexD<D>,
197 internal::AllItHelp<ExtendedGridIndexD<D>, ExtendedGridIndexD<D> > >
198 ExtendedIndexIterator;
201 class ExtendedIndexIterator;
203 IndexIterator indexes_begin(
const ExtendedGridIndexD<D>& lb,
204 const ExtendedGridIndexD<D>& ub)
const {
205 ExtendedGridIndexD<D> eub = ub.get_uniform_offset(1);
206 std::pair<ExtendedGridIndexD<D>, ExtendedGridIndexD<D> > bp =
207 internal::intersect<ExtendedGridIndexD<D> >(lb, eub, d_);
208 if (bp.first == bp.second) {
209 return IndexIterator();
213 return IndexIterator(bp.first, bp.second);
216 IndexIterator indexes_end(
const ExtendedGridIndexD<D>&,
217 const ExtendedGridIndexD<D>&)
const {
219 return IndexIterator();
221 ExtendedIndexIterator extended_indexes_begin(
222 const ExtendedGridIndexD<D>& lb,
const ExtendedGridIndexD<D>& ub)
const {
223 ExtendedGridIndexD<D> eub = ub.get_uniform_offset(1);
224 return ExtendedIndexIterator(lb, eub);
226 ExtendedIndexIterator extended_indexes_end(
227 const ExtendedGridIndexD<D>&,
const ExtendedGridIndexD<D>&)
const {
229 return ExtendedIndexIterator();
234 const ExtendedGridIndexD<D>& lb,
const ExtendedGridIndexD<D>& ub)
const {
235 return Vector<GridIndexD<D> >(indexes_begin(lb, ub),
236 indexes_end(lb, ub));
238 Vector<ExtendedGridIndexD<D> > get_extended_indexes(
239 const ExtendedGridIndexD<D>& lb,
const ExtendedGridIndexD<D>& ub)
const {
240 return Vector<ExtendedGridIndexD<D> >(extended_indexes_begin(lb, ub),
241 extended_indexes_end(lb, ub));
254 for (
unsigned int i = 0; i < d_.get_dimension(); ++i) {
255 if (v[i] < 0 || v[i] >= static_cast<int>(get_number_of_voxels(i))) {
264 for (
unsigned int i = 0; i < ret.get_dimension(); ++i) {
265 ret.access_data().get_data()[i] = 0;
272 for (
unsigned int i = 0; i < ret.get_dimension(); ++i) {
273 --ret.access_data().get_data()[i];
280 typedef BoundedGridRangeD<1> BoundedGridRange1D;
281 typedef BoundedGridRangeD<2> BoundedGridRange2D;
282 typedef BoundedGridRangeD<3> BoundedGridRange3D;
283 typedef BoundedGridRangeD<4> BoundedGridRange4D;
284 typedef BoundedGridRangeD<5> BoundedGridRange5D;
285 typedef BoundedGridRangeD<6> BoundedGridRange6D;
286 typedef BoundedGridRangeD<-1> BoundedGridRangeKD;
296 IMPALGEBRA_END_NAMESPACE
GridIndexD< D > get_index(const ExtendedGridIndexD< D > &v) const
Convert a ExtendedIndex into a real Index if possible.
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.
Macros to handle array indexing.
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.
ParticleIndexes get_indexes(const ParticlesTemp &ps)
Get the indexes from a list of particles.