9 #ifndef IMPALGEBRA_GRID_EMBEDDINGS_H
10 #define IMPALGEBRA_GRID_EMBEDDINGS_H
12 #include <IMP/algebra/algebra_config.h>
18 #include <boost/iterator/transform_iterator.hpp>
26 IMPALGEBRA_BEGIN_NAMESPACE
37 for (
unsigned int i = 0; i < get_dimension(); ++i) {
43 VectorD<D> get_uniform_offset(
const O &v0,
double o)
const {
44 Floats ret(get_dimension());
45 for (
unsigned int i = 0; i < get_dimension(); ++i) {
51 Floats nuc(bb.get_dimension());
52 for (
unsigned int i = 0; i < bb.get_dimension(); ++i) {
55 nuc[i] = side / ns[i];
57 set_unit_cell(
VectorD<D>(nuc.begin(), nuc.end()));
67 void set_origin(
const VectorD<D> &o) { origin_ = o; }
68 const VectorD<D> get_origin()
const {
return origin_; }
69 unsigned int get_dimension()
const {
return get_origin().get_dimension(); }
72 Floats iuc(o.get_dimension());
73 for (
unsigned int i = 0; i < get_dimension(); ++i) {
74 iuc[i] = 1.0 / unit_cell_[i];
76 inverse_unit_cell_ =
VectorD<D>(iuc.begin(), iuc.end());
80 const VectorD<D> &get_inverse_unit_cell()
const {
return inverse_unit_cell_; }
96 origin_.get_dimension());
97 for (
unsigned int i = 0; i < get_dimension(); ++i) {
98 double d = o[i] - origin_[i];
99 double fi = d * inverse_unit_cell_[i];
100 ret.access_data().get_data()[i] =
static_cast<int>(std::floor(fi));
106 origin_.get_dimension());
107 for (
unsigned int i = 0; i < get_dimension(); ++i) {
108 double d = o[i] - origin_[i];
109 double fi = d * inverse_unit_cell_[i];
110 ret.access_data().get_data()[i] =
static_cast<int>(std::floor(fi));
118 VectorD<D> get_center(
const ExtendedGridIndexD<D> &ei)
const {
122 VectorD<D> get_center(
const GridIndexD<D> &ei)
const {
133 return BoundingBoxD<D>(
139 return BoundingBoxD<D>(
146 <<
" unit cell: " << unit_cell_);
149 #if !defined(IMP_DOXYGEN)
150 typedef DefaultEmbeddingD<1> DefaultEmbedding1D;
151 typedef base::Vector<DefaultEmbedding1D> DefaultEmbedding1Ds;
153 typedef DefaultEmbeddingD<2> DefaultEmbedding2D;
154 typedef base::Vector<DefaultEmbedding2D> DefaultEmbedding2Ds;
156 typedef DefaultEmbeddingD<3> DefaultEmbedding3D;
157 typedef base::Vector<DefaultEmbedding3D> DefaultEmbedding3Ds;
159 typedef DefaultEmbeddingD<4> DefaultEmbedding4D;
160 typedef base::Vector<DefaultEmbedding4D> DefaultEmbedding4Ds;
162 typedef DefaultEmbeddingD<5> DefaultEmbedding5D;
163 typedef base::Vector<DefaultEmbedding5D> DefaultEmbedding5Ds;
165 typedef DefaultEmbeddingD<6> DefaultEmbedding6D;
166 typedef base::Vector<DefaultEmbedding6D> DefaultEmbedding6Ds;
168 typedef DefaultEmbeddingD<-1> DefaultEmbeddingKD;
169 typedef base::Vector<DefaultEmbeddingKD> DefaultEmbeddingKDs;
179 VectorD<D> get_coordinates(
const O &index)
const {
181 for (
unsigned int i = 0; i < unit_cell_.get_dimension(); ++i) {
185 "Log grid axis must have positive index.");
186 ret[i] += unit_cell_[i] * (1.0 - std::pow(base_[i], index[i])) /
189 ret[i] += unit_cell_[i] * index[i];
195 VectorD<D> get_uniform_offset(
const O &v0,
double o)
const {
196 Floats ret(get_dimension());
197 for (
unsigned int i = 0; i < get_dimension(); ++i) {
203 Floats nuc(bb.get_dimension());
204 for (
unsigned int i = 0; i < bb.get_dimension(); ++i) {
207 nuc[i] = side / ns[i];
209 set_unit_cell(
VectorD<D>(nuc.begin(), nuc.end()));
217 set_unit_cell(cell, base);
232 const Ints &counts,
bool bound_centers =
false) {
235 for (
unsigned int i = 0; i < bases.get_dimension(); ++i) {
237 "LogEmbedding base #" << i <<
" cannot be negative",
242 (std::pow(bases[i], counts[i]) - 1.0);
248 "Too large a cell side");
251 set_unit_cell(cell, bases);
256 get_uniform_offset(
GridIndexD<D>(counts.begin(), counts.end()), -.5));
257 VectorD<D> extents = upper_corner - lower_corner;
260 for (
unsigned int i = 0; i < uc.get_dimension(); ++i) {
269 uc[i] * (1.0 - std::pow(bases[i], .5)) / (1.0 - bases[i]);
273 set_unit_cell(uc, bases);
280 void set_origin(
const VectorD<D> &o) { origin_ = o; }
281 const VectorD<D> get_origin()
const {
return origin_; }
282 unsigned int get_dimension()
const {
return get_origin().get_dimension(); }
283 void set_unit_cell(
const VectorD<D> &o,
const VectorD<D> &base) {
287 void set_unit_cell(
const VectorD<D> &o) { unit_cell_ = o; }
302 origin_.get_dimension());
303 for (
unsigned int i = 0; i < get_dimension(); ++i) {
304 double d = o[i] - origin_[i];
306 double fi = d / unit_cell_[i];
307 double li = std::log(fi) / std::log(base_[i]);
308 ret.access_data().get_data()[i] =
static_cast<int>(std::floor(li));
320 VectorD<D> get_center(
const ExtendedGridIndexD<D> &ei)
const {
321 return get_coordinates(get_uniform_offset(ei, .5));
323 VectorD<D> get_center(
const GridIndexD<D> &ei)
const {
324 return get_coordinates(get_uniform_offset(ei, .5));
333 return BoundingBoxD<D>(get_coordinates(ei),
334 get_coordinates(get_uniform_offset(ei, 1)));
341 <<
" base: " << base_);
344 #if !defined(IMP_DOXYGEN)
345 typedef LogEmbeddingD<1> LogEmbedding1D;
346 typedef base::Vector<LogEmbedding1D> LogEmbedding1Ds;
348 typedef LogEmbeddingD<2> LogEmbedding2D;
349 typedef base::Vector<LogEmbedding2D> LogEmbedding2Ds;
351 typedef LogEmbeddingD<3> LogEmbedding3D;
352 typedef base::Vector<LogEmbedding3D> LogEmbedding3Ds;
354 typedef LogEmbeddingD<4> LogEmbedding4D;
355 typedef base::Vector<LogEmbedding4D> LogEmbedding4Ds;
357 typedef LogEmbeddingD<5> LogEmbedding5D;
358 typedef base::Vector<LogEmbedding5D> LogEmbedding5Ds;
360 typedef LogEmbeddingD<6> LogEmbedding6D;
361 typedef base::Vector<LogEmbedding6D> LogEmbedding6Ds;
363 typedef LogEmbeddingD<-1> LogEmbeddingKD;
364 typedef base::Vector<LogEmbeddingKD> LogEmbeddingKDs;
367 IMPALGEBRA_END_NAMESPACE
VectorD< D > get_elementwise_product(const algebra::VectorD< D > &a, const algebra::VectorD< D > &b)
const VectorD< D > & get_corner(unsigned int i) const
For 0 return lower corner and 1 upper corner.
Ints get_index(const kernel::ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
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.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
ExtendedGridIndexD< D > get_extended_index(const VectorD< D > &o) const
Return the index that would contain the voxel if the grid extended there.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
A Cartesian vector in D-dimensions.
ExtendedGridIndexD< D > get_extended_index(const VectorD< D > &o) const
Return the index that would contain the voxel if the grid extended there.
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
const VectorD< D > & get_unit_cell() const
Return the unit cell, relative to the origin.
A bounding box in D dimensions.
A class for storing lists of IMP items.
An axis-aligned bounding box.
Exception definitions and assertions.
const VectorD< D > & get_unit_cell() const
Return the unit cell, relative to the origin.
Exception definitions and assertions.
#define IMP_FAILURE(message)
A runtime failure for IMP.
LogEmbeddingD(const BoundingBoxD< D > &bb, const VectorD< D > &bases, const Ints &counts, bool bound_centers=false)
#define IMP_ALWAYS_CHECK(condition, message, exception_name)
Throw an exception if a check fails.
Declare an efficient stl-compatible map.
An exception for an invalid value being passed to IMP.
BoundingBoxD< D > get_bounding_box(const BoundingBoxD< D > &g)