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 IMPALGEBRA_BEGIN_NAMESPACE
29 internal::VectorData<int, D, true> data_;
32 if (data_.get_dimension() == 0 && o.data_.get_dimension() == 0) {
34 }
else if (data_.get_dimension() == 0) {
36 }
else if (o.data_.get_dimension() == 0) {
41 "Dimensions don't match");
43 return internal::lexicographical_compare(begin(), end(), o.begin(),
48 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
49 struct Uninitialized {};
53 std::fill(data_.get_data(), data_.get_data() + dim, value);
55 const internal::VectorData<int, D, true>& get_data()
const {
return data_; }
56 internal::VectorData<int, D, true>& access_data() {
return data_; }
61 IMP_DEPRECATED_ATTRIBUTE
64 data_.set_coordinates(vals.begin(), vals.end());
69 data_.set_coordinates(b, e);
72 ExtendedGridIndexD(
int x,
int y,
int z) {
75 data_.set_coordinates(v, v + 3);
77 ExtendedGridIndexD() {}
78 unsigned int get_dimension()
const {
return data_.get_dimension(); }
82 int,
unsigned int, i < get_dimension(),
83 IMP_USAGE_CHECK(!data_.get_is_null(),
"Using uninitialized grid index");
84 return data_.get_data()[i]);
87 for (
unsigned int i = 0; i < get_dimension(); ++i) {
89 if (i != get_dimension() - 1)
96 typedef const int* iterator;
97 iterator begin()
const {
return data_.get_data(); }
98 iterator end()
const {
return data_.get_data() + get_dimension(); }
101 unsigned int __len__()
const {
return get_dimension(); }
104 return boost::hash_range(begin(), end()));
105 ExtendedGridIndexD<D> get_uniform_offset(
int ii)
const {
106 ExtendedGridIndexD<D> ret(
typename ExtendedGridIndexD<D>::Filled(),
108 for (
unsigned int i = 0; i < get_dimension(); ++i) {
109 ret.access_data().get_data()[i] = operator[](i) + ii;
114 ExtendedGridIndexD<D> get_offset(
int i,
int j,
int k)
const {
116 int v[] = {operator[](0) + i, operator[](1) + j, operator[](2) + k};
117 ExtendedGridIndexD<D> ret(v, v + 3);
122 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
124 inline std::size_t hash_value(
const ExtendedGridIndexD<D>& ind) {
125 return ind.__hash__();
137 internal::VectorData<int, D, true> data_;
140 if (data_.get_dimension() == 0 && o.data_.get_dimension() == 0) {
142 }
else if (data_.get_dimension() == 0) {
144 }
else if (o.data_.get_dimension() == 0) {
149 "Dimensions don't match");
151 return internal::lexicographical_compare(begin(), end(), o.begin(),
156 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
157 const internal::VectorData<int, D, true>& get_data()
const {
return data_; }
158 internal::VectorData<int, D, true>& access_data() {
return data_; }
159 struct Uninitialized {};
160 GridIndexD(Uninitialized,
int dim) : data_(dim) {}
162 GridIndexD(Filled,
int dim,
int value) : data_(dim) {
163 std::fill(data_.get_data(), data_.get_data() + dim, value);
168 unsigned int get_dimension()
const {
return data_.get_dimension(); }
173 int,
unsigned int, i < get_dimension(),
174 IMP_USAGE_CHECK(!data_.get_is_null(),
"Using uninitialized grid index");
175 return data_.get_data()[i]);
178 for (
unsigned int i = 0; i < get_dimension(); ++i) {
179 out << operator[](i);
180 if (i != get_dimension() - 1)
186 typedef const int* iterator;
187 iterator begin()
const {
return data_.get_data(); }
188 iterator end()
const {
return data_.get_data() + get_dimension(); }
191 IMP_DEPRECATED_ATTRIBUTE
194 data_.set_coordinates(vals.begin(), vals.end());
198 data_.set_coordinates(b, e);
201 unsigned int __len__()
const {
return get_dimension(); }
207 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
210 return ind.__hash__();
214 #if !defined(IMP_DOXYGEN)
215 typedef GridIndexD<1> GridIndex1D;
216 typedef ExtendedGridIndexD<1> ExtendedGridIndex1D;
220 typedef GridIndexD<2> GridIndex2D;
221 typedef ExtendedGridIndexD<2> ExtendedGridIndex2D;
225 typedef GridIndexD<3> GridIndex3D;
226 typedef ExtendedGridIndexD<3> ExtendedGridIndex3D;
230 typedef GridIndexD<4> GridIndex4D;
231 typedef ExtendedGridIndexD<4> ExtendedGridIndex4D;
235 typedef GridIndexD<5> GridIndex5D;
236 typedef ExtendedGridIndexD<5> ExtendedGridIndex5D;
240 typedef GridIndexD<6> GridIndex6D;
241 typedef ExtendedGridIndexD<6> ExtendedGridIndex6D;
245 typedef GridIndexD<-1> GridIndexKD;
246 typedef ExtendedGridIndexD<-1> ExtendedGridIndexKD;
251 IMPALGEBRA_END_NAMESPACE
ExtendedGridIndexD(Ints vals)
Create a grid cell from three arbitrary indexes.
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.
#define IMP_HASHABLE_INLINE(name, hashret)
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
#define IMP_COMPARISONS(Name)
Implement comparison in a class using a compare function.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
#define IMP_CONST_BRACKET(Value, Index, bounds_check_expr, expr)
Exception definitions and assertions.
#define IMP_BRACKET(Value, Index, bounds_check_expr, expr)