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"
18 #include <cereal/access.hpp>
20 #include <IMP/internal/range.h>
22 IMPALGEBRA_BEGIN_NAMESPACE
32 internal::VectorData<int, D, true> data_;
34 friend class cereal::access;
36 template<
class Archive>
void serialize(Archive &ar) {
42 if (data_.get_dimension() == 0 && o.data_.get_dimension() == 0) {
44 }
else if (data_.get_dimension() == 0) {
46 }
else if (o.data_.get_dimension() == 0) {
51 "Dimensions don't match");
53 return internal::lexicographical_compare(begin(), end(), o.begin(),
58 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
59 struct Uninitialized {};
63 std::fill(data_.get_data(), data_.get_data() + dim, value);
65 const internal::VectorData<int, D, true>& get_data()
const {
return data_; }
66 internal::VectorData<int, D, true>& access_data() {
return data_; }
71 IMP_DEPRECATED_ATTRIBUTE
74 data_.set_coordinates(vals.begin(), vals.end());
79 data_.set_coordinates(b, e);
82 ExtendedGridIndexD(
int x) {
85 data_.set_coordinates(v, v + 1);
87 ExtendedGridIndexD(
int x,
int y) {
90 data_.set_coordinates(v, v + 2);
92 ExtendedGridIndexD(
int x,
int y,
int z) {
95 data_.set_coordinates(v, v + 3);
97 ExtendedGridIndexD(
int i,
int j,
int k,
int l) {
99 int v[] = {i, j, k, l};
100 data_.set_coordinates(v, v + 4);
102 ExtendedGridIndexD(
int i,
int j,
int k,
int l,
int m) {
104 int v[] = {i, j, k, l, m};
105 data_.set_coordinates(v, v + 5);
107 ExtendedGridIndexD(
int i,
int j,
int k,
int l,
int m,
int n) {
109 int v[] = {i, j, k, l, m, n};
110 data_.set_coordinates(v, v + 6);
112 ExtendedGridIndexD() {}
113 unsigned int get_dimension()
const {
return data_.get_dimension(); }
116 IMP_BRACKET(
int,
unsigned int, i < get_dimension(),
118 "Using uninitialized grid index");
119 return data_.get_data()[i]);
122 for (
unsigned int i = 0; i < get_dimension(); ++i) {
123 out << operator[](i);
124 if (i != get_dimension() - 1) out <<
", ";
130 typedef const int* iterator;
131 iterator begin()
const {
return data_.get_data(); }
132 iterator end()
const {
return data_.get_data() + get_dimension(); }
135 unsigned int __len__()
const {
return get_dimension(); }
138 return boost::hash_range(begin(), end()));
139 ExtendedGridIndexD<D> get_uniform_offset(
int ii)
const {
140 ExtendedGridIndexD<D> ret(
typename ExtendedGridIndexD<D>::Filled(),
142 for (
unsigned int i = 0; i < get_dimension(); ++i) {
143 ret.access_data().get_data()[i] = operator[](i) + ii;
148 ExtendedGridIndexD<D> get_offset(
int i,
int j,
int k)
const {
150 int v[] = {operator[](0) + i, operator[](1) + j, operator[](2) + k};
151 ExtendedGridIndexD<D> ret(v, v + 3);
156 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
158 inline std::size_t hash_value(
const ExtendedGridIndexD<D>& ind) {
159 return ind.__hash__();
171 internal::VectorData<int, D, true> data_;
173 friend class cereal::access;
175 template<
class Archive>
void serialize(Archive &ar) {
181 if (data_.get_dimension() == 0 && o.data_.get_dimension() == 0) {
183 }
else if (data_.get_dimension() == 0) {
185 }
else if (o.data_.get_dimension() == 0) {
190 "Dimensions don't match");
192 return internal::lexicographical_compare(begin(), end(), o.begin(),
197 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
198 const internal::VectorData<int, D, true>& get_data()
const {
return data_; }
199 internal::VectorData<int, D, true>& access_data() {
return data_; }
200 struct Uninitialized {};
201 GridIndexD(Uninitialized,
int dim) : data_(dim) {}
203 GridIndexD(Filled,
int dim,
int value) : data_(dim) {
204 std::fill(data_.get_data(), data_.get_data() + dim, value);
211 data_.set_coordinates(v, v + 1);
216 data_.set_coordinates(v, v + 2);
221 data_.set_coordinates(v, v + 3);
225 int v[] = {i, j, k, l};
226 data_.set_coordinates(v, v + 4);
228 GridIndexD(
int i,
int j,
int k,
int l,
int m) {
230 int v[] = {i, j, k, l, m};
231 data_.set_coordinates(v, v + 5);
233 GridIndexD(
int i,
int j,
int k,
int l,
int m,
int n) {
235 int v[] = {i, j, k, l, m, n};
236 data_.set_coordinates(v, v + 6);
238 unsigned int get_dimension()
const {
return data_.get_dimension(); }
244 "Using uninitialized grid index");
245 return data_.get_data()[i]);
248 for (
unsigned int i = 0; i < get_dimension(); ++i) {
249 out << operator[](i);
250 if (i != get_dimension() - 1) out <<
", ";
255 typedef const int* iterator;
256 iterator begin()
const {
return data_.get_data(); }
257 iterator end()
const {
return data_.get_data() + get_dimension(); }
260 IMP_DEPRECATED_ATTRIBUTE
263 data_.set_coordinates(vals.begin(), vals.end());
267 data_.set_coordinates(b, e);
270 unsigned int __len__()
const {
return get_dimension(); }
276 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
279 return ind.__hash__();
283 #if !defined(IMP_DOXYGEN)
284 typedef GridIndexD<1> GridIndex1D;
285 typedef ExtendedGridIndexD<1> ExtendedGridIndex1D;
289 typedef GridIndexD<2> GridIndex2D;
290 typedef ExtendedGridIndexD<2> ExtendedGridIndex2D;
294 typedef GridIndexD<3> GridIndex3D;
295 typedef ExtendedGridIndexD<3> ExtendedGridIndex3D;
299 typedef GridIndexD<4> GridIndex4D;
300 typedef ExtendedGridIndexD<4> ExtendedGridIndex4D;
304 typedef GridIndexD<5> GridIndex5D;
305 typedef ExtendedGridIndexD<5> ExtendedGridIndex5D;
309 typedef GridIndexD<6> GridIndex6D;
310 typedef ExtendedGridIndexD<6> ExtendedGridIndex6D;
314 typedef GridIndexD<-1> GridIndexKD;
315 typedef ExtendedGridIndexD<-1> ExtendedGridIndexKD;
320 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)
Implement operator[] and at() for C++, and getitem for Python.
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)
Implement operator[] and at() for C++, and getitem for Python.
#define IMP_COMPARISONS(Name)
Implement comparison in a class using a compare function.
Exception definitions and assertions.
Macros to handle array indexing.
Base class for a simple primitive-like type.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
Base class for a simple primitive-like type.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.