8 #ifndef IMPALGEBRA_GRID_INDEXES_H
9 #define IMPALGEBRA_GRID_INDEXES_H
11 #include <IMP/algebra/algebra_config.h>
13 #include "internal/vector.h"
14 #include "internal/grid_internal.h"
19 #include <IMP/internal/range.h>
21 IMPALGEBRA_BEGIN_NAMESPACE
31 internal::VectorData<int, D, true> data_;
34 if (data_.get_dimension() == 0 && o.data_.get_dimension() == 0) {
36 }
else if (data_.get_dimension() == 0) {
38 }
else if (o.data_.get_dimension() == 0) {
43 "Dimensions don't match");
45 return internal::lexicographical_compare(begin(), end(), o.begin(),
50 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
51 struct Uninitialized {};
55 std::fill(data_.get_data(), data_.get_data() + dim, value);
57 const internal::VectorData<int, D, true>& get_data()
const {
return data_; }
58 internal::VectorData<int, D, true>& access_data() {
return data_; }
63 IMP_DEPRECATED_ATTRIBUTE
66 data_.set_coordinates(vals.begin(), vals.end());
71 data_.set_coordinates(b, e);
74 ExtendedGridIndexD(
int x) {
77 data_.set_coordinates(v, v + 1);
79 ExtendedGridIndexD(
int x,
int y) {
82 data_.set_coordinates(v, v + 2);
84 ExtendedGridIndexD(
int x,
int y,
int z) {
87 data_.set_coordinates(v, v + 3);
89 ExtendedGridIndexD(
int i,
int j,
int k,
int l) {
91 int v[] = {i, j, k, l};
92 data_.set_coordinates(v, v + 4);
94 ExtendedGridIndexD(
int i,
int j,
int k,
int l,
int m) {
96 int v[] = {i, j, k, l, m};
97 data_.set_coordinates(v, v + 5);
99 ExtendedGridIndexD(
int i,
int j,
int k,
int l,
int m,
int n) {
101 int v[] = {i, j, k, l, m, n};
102 data_.set_coordinates(v, v + 6);
104 ExtendedGridIndexD() {}
105 unsigned int get_dimension()
const {
return data_.get_dimension(); }
108 IMP_BRACKET(
int,
unsigned int, i < get_dimension(),
110 "Using uninitialized grid index");
111 return data_.get_data()[i]);
114 for (
unsigned int i = 0; i < get_dimension(); ++i) {
115 out << operator[](i);
116 if (i != get_dimension() - 1) out <<
", ";
122 typedef const int* iterator;
123 iterator begin()
const {
return data_.get_data(); }
124 iterator end()
const {
return data_.get_data() + get_dimension(); }
127 unsigned int __len__()
const {
return get_dimension(); }
130 return boost::hash_range(begin(), end()));
131 ExtendedGridIndexD<D> get_uniform_offset(
int ii)
const {
132 ExtendedGridIndexD<D> ret(
typename ExtendedGridIndexD<D>::Filled(),
134 for (
unsigned int i = 0; i < get_dimension(); ++i) {
135 ret.access_data().get_data()[i] = operator[](i) + ii;
140 ExtendedGridIndexD<D> get_offset(
int i,
int j,
int k)
const {
142 int v[] = {operator[](0) + i, operator[](1) + j, operator[](2) + k};
143 ExtendedGridIndexD<D> ret(v, v + 3);
148 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
150 inline std::size_t hash_value(
const ExtendedGridIndexD<D>& ind) {
151 return ind.__hash__();
163 internal::VectorData<int, D, true> data_;
166 if (data_.get_dimension() == 0 && o.data_.get_dimension() == 0) {
168 }
else if (data_.get_dimension() == 0) {
170 }
else if (o.data_.get_dimension() == 0) {
175 "Dimensions don't match");
177 return internal::lexicographical_compare(begin(), end(), o.begin(),
182 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
183 const internal::VectorData<int, D, true>& get_data()
const {
return data_; }
184 internal::VectorData<int, D, true>& access_data() {
return data_; }
185 struct Uninitialized {};
186 GridIndexD(Uninitialized,
int dim) : data_(dim) {}
188 GridIndexD(Filled,
int dim,
int value) : data_(dim) {
189 std::fill(data_.get_data(), data_.get_data() + dim, value);
196 data_.set_coordinates(v, v + 1);
201 data_.set_coordinates(v, v + 2);
206 data_.set_coordinates(v, v + 3);
210 int v[] = {i, j, k, l};
211 data_.set_coordinates(v, v + 4);
213 GridIndexD(
int i,
int j,
int k,
int l,
int m) {
215 int v[] = {i, j, k, l, m};
216 data_.set_coordinates(v, v + 5);
218 GridIndexD(
int i,
int j,
int k,
int l,
int m,
int n) {
220 int v[] = {i, j, k, l, m, n};
221 data_.set_coordinates(v, v + 6);
223 unsigned int get_dimension()
const {
return data_.get_dimension(); }
229 "Using uninitialized grid index");
230 return data_.get_data()[i]);
233 for (
unsigned int i = 0; i < get_dimension(); ++i) {
234 out << operator[](i);
235 if (i != get_dimension() - 1) out <<
", ";
240 typedef const int* iterator;
241 iterator begin()
const {
return data_.get_data(); }
242 iterator end()
const {
return data_.get_data() + get_dimension(); }
245 IMP_DEPRECATED_ATTRIBUTE
248 data_.set_coordinates(vals.begin(), vals.end());
252 data_.set_coordinates(b, e);
255 unsigned int __len__()
const {
return get_dimension(); }
261 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
264 return ind.__hash__();
268 #if !defined(IMP_DOXYGEN)
269 typedef GridIndexD<1> GridIndex1D;
270 typedef ExtendedGridIndexD<1> ExtendedGridIndex1D;
274 typedef GridIndexD<2> GridIndex2D;
275 typedef ExtendedGridIndexD<2> ExtendedGridIndex2D;
279 typedef GridIndexD<3> GridIndex3D;
280 typedef ExtendedGridIndexD<3> ExtendedGridIndex3D;
284 typedef GridIndexD<4> GridIndex4D;
285 typedef ExtendedGridIndexD<4> ExtendedGridIndex4D;
289 typedef GridIndexD<5> GridIndex5D;
290 typedef ExtendedGridIndexD<5> ExtendedGridIndex5D;
294 typedef GridIndexD<6> GridIndex6D;
295 typedef ExtendedGridIndexD<6> ExtendedGridIndex6D;
299 typedef GridIndexD<-1> GridIndexKD;
300 typedef ExtendedGridIndexD<-1> ExtendedGridIndexKD;
305 IMPALGEBRA_END_NAMESPACE
ExtendedGridIndexD(Ints vals)
Create a grid cell from three arbitrary indexes.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
#define IMP_CONST_BRACKET(Value, Index, bounds_check_expr, expr)
Represent a real cell in a grid (one within the bounding box)
#define IMP_HASHABLE_INLINE(name, hashret)
An index in an infinite grid on space.
#define IMP_BRACKET(Value, Index, bounds_check_expr, expr)
#define IMP_COMPARISONS(Name)
Implement comparison in a class using a compare function.
Exception definitions and assertions.
Various general useful macros for IMP.
Base for a simple primitive-like type.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.