8 #ifndef IMPALGEBRA_GRID_INDEXES_H
9 #define IMPALGEBRA_GRID_INDEXES_H
11 #include <IMP/algebra/algebra_config.h>
13 #include "internal/grid_internal.h"
16 #include <IMP/internal/VectorData.h>
18 #include <cereal/access.hpp>
20 #include <IMP/internal/range.h>
22 IMPALGEBRA_BEGIN_NAMESPACE
32 IMP::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 IMP::internal::VectorData<int, D, true>& get_data()
const {
68 IMP::internal::VectorData<int, D, true>& access_data() {
return data_; }
73 IMP_DEPRECATED_ATTRIBUTE
76 data_.set_coordinates(vals.begin(), vals.end());
81 data_.set_coordinates(b, e);
84 ExtendedGridIndexD(
int x) {
87 data_.set_coordinates(v, v + 1);
89 ExtendedGridIndexD(
int x,
int y) {
92 data_.set_coordinates(v, v + 2);
94 ExtendedGridIndexD(
int x,
int y,
int z) {
97 data_.set_coordinates(v, v + 3);
99 ExtendedGridIndexD(
int i,
int j,
int k,
int l) {
101 int v[] = {i, j, k, l};
102 data_.set_coordinates(v, v + 4);
104 ExtendedGridIndexD(
int i,
int j,
int k,
int l,
int m) {
106 int v[] = {i, j, k, l, m};
107 data_.set_coordinates(v, v + 5);
109 ExtendedGridIndexD(
int i,
int j,
int k,
int l,
int m,
int n) {
111 int v[] = {i, j, k, l, m, n};
112 data_.set_coordinates(v, v + 6);
114 ExtendedGridIndexD() {}
115 unsigned int get_dimension()
const {
return data_.get_dimension(); }
118 IMP_BRACKET(
int,
unsigned int, i < get_dimension(),
120 "Using uninitialized grid index");
121 return data_.get_data()[i]);
124 for (
unsigned int i = 0; i < get_dimension(); ++i) {
125 out << operator[](i);
126 if (i != get_dimension() - 1) out <<
", ";
132 typedef const int* iterator;
133 iterator begin()
const {
return data_.get_data(); }
134 iterator end()
const {
return data_.get_data() + get_dimension(); }
137 unsigned int __len__()
const {
return get_dimension(); }
140 return boost::hash_range(begin(), end()));
141 ExtendedGridIndexD<D> get_uniform_offset(
int ii)
const {
142 ExtendedGridIndexD<D> ret(
typename ExtendedGridIndexD<D>::Filled(),
144 for (
unsigned int i = 0; i < get_dimension(); ++i) {
145 ret.access_data().get_data()[i] = operator[](i) + ii;
150 ExtendedGridIndexD<D> get_offset(
int i,
int j,
int k)
const {
152 int v[] = {operator[](0) + i, operator[](1) + j, operator[](2) + k};
153 ExtendedGridIndexD<D> ret(v, v + 3);
158 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
160 inline std::size_t hash_value(
const ExtendedGridIndexD<D>& ind) {
161 return ind.__hash__();
173 IMP::internal::VectorData<int, D, true> data_;
175 friend class cereal::access;
177 template<
class Archive>
void serialize(Archive &ar) {
183 if (data_.get_dimension() == 0 && o.data_.get_dimension() == 0) {
185 }
else if (data_.get_dimension() == 0) {
187 }
else if (o.data_.get_dimension() == 0) {
192 "Dimensions don't match");
194 return internal::lexicographical_compare(begin(), end(), o.begin(),
199 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
200 const IMP::internal::VectorData<int, D, true>& get_data()
const {
203 IMP::internal::VectorData<int, D, true>& access_data() {
return data_; }
204 struct Uninitialized {};
205 GridIndexD(Uninitialized,
int dim) : data_(dim) {}
207 GridIndexD(Filled,
int dim,
int value) : data_(dim) {
208 std::fill(data_.get_data(), data_.get_data() + dim, value);
215 data_.set_coordinates(v, v + 1);
220 data_.set_coordinates(v, v + 2);
225 data_.set_coordinates(v, v + 3);
229 int v[] = {i, j, k, l};
230 data_.set_coordinates(v, v + 4);
232 GridIndexD(
int i,
int j,
int k,
int l,
int m) {
234 int v[] = {i, j, k, l, m};
235 data_.set_coordinates(v, v + 5);
237 GridIndexD(
int i,
int j,
int k,
int l,
int m,
int n) {
239 int v[] = {i, j, k, l, m, n};
240 data_.set_coordinates(v, v + 6);
242 unsigned int get_dimension()
const {
return data_.get_dimension(); }
248 "Using uninitialized grid index");
249 return data_.get_data()[i]);
252 for (
unsigned int i = 0; i < get_dimension(); ++i) {
253 out << operator[](i);
254 if (i != get_dimension() - 1) out <<
", ";
259 typedef const int* iterator;
260 iterator begin()
const {
return data_.get_data(); }
261 iterator end()
const {
return data_.get_data() + get_dimension(); }
264 IMP_DEPRECATED_ATTRIBUTE
267 data_.set_coordinates(vals.begin(), vals.end());
271 data_.set_coordinates(b, e);
274 unsigned int __len__()
const {
return get_dimension(); }
280 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
283 return ind.__hash__();
287 #if !defined(IMP_DOXYGEN)
288 typedef GridIndexD<1> GridIndex1D;
289 typedef ExtendedGridIndexD<1> ExtendedGridIndex1D;
293 typedef GridIndexD<2> GridIndex2D;
294 typedef ExtendedGridIndexD<2> ExtendedGridIndex2D;
298 typedef GridIndexD<3> GridIndex3D;
299 typedef ExtendedGridIndexD<3> ExtendedGridIndex3D;
303 typedef GridIndexD<4> GridIndex4D;
304 typedef ExtendedGridIndexD<4> ExtendedGridIndex4D;
308 typedef GridIndexD<5> GridIndex5D;
309 typedef ExtendedGridIndexD<5> ExtendedGridIndex5D;
313 typedef GridIndexD<6> GridIndex6D;
314 typedef ExtendedGridIndexD<6> ExtendedGridIndex6D;
318 typedef GridIndexD<-1> GridIndexKD;
319 typedef ExtendedGridIndexD<-1> ExtendedGridIndexKD;
324 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.