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>
25 IMPALGEBRA_BEGIN_NAMESPACE
36 for (
unsigned int i = 0; i < get_dimension(); ++i) {
42 VectorD<D> get_uniform_offset(
const O &v0,
double o)
const {
43 Floats ret(get_dimension());
44 for (
unsigned int i = 0; i < get_dimension(); ++i) {
50 Floats nuc(bb.get_dimension());
51 for (
unsigned int i = 0; i < bb.get_dimension(); ++i) {
54 nuc[i] = side / ns[i];
56 set_unit_cell(
VectorD<D>(nuc.begin(), nuc.end()));
66 void set_origin(
const VectorD<D> &o) { origin_ = o; }
67 const VectorD<D> get_origin()
const {
return origin_; }
68 unsigned int get_dimension()
const {
return get_origin().get_dimension(); }
71 Floats iuc(o.get_dimension());
72 for (
unsigned int i = 0; i < get_dimension(); ++i) {
73 iuc[i] = 1.0 / unit_cell_[i];
75 inverse_unit_cell_ =
VectorD<D>(iuc.begin(), iuc.end());
79 const VectorD<D> &get_inverse_unit_cell()
const {
return inverse_unit_cell_; }
95 origin_.get_dimension());
96 for (
unsigned int i = 0; i < get_dimension(); ++i) {
97 double d = o[i] - origin_[i];
98 double fi = d * inverse_unit_cell_[i];
99 ret.access_data().
get_data()[i] =
static_cast<int>(std::floor(fi));
105 origin_.get_dimension());
106 for (
unsigned int i = 0; i < get_dimension(); ++i) {
107 double d = o[i] - origin_[i];
108 double fi = d * inverse_unit_cell_[i];
109 ret.access_data().
get_data()[i] =
static_cast<int>(std::floor(fi));
117 VectorD<D> get_center(
const ExtendedGridIndexD<D> &ei)
const {
121 VectorD<D> get_center(
const GridIndexD<D> &ei)
const {
132 return BoundingBoxD<D>(
138 return BoundingBoxD<D>(
145 <<
" unit cell: " << unit_cell_);
148 #if !defined(IMP_DOXYGEN)
149 typedef DefaultEmbeddingD<1> DefaultEmbedding1D;
150 typedef base::Vector<DefaultEmbedding1D> DefaultEmbedding1Ds;
152 typedef DefaultEmbeddingD<2> DefaultEmbedding2D;
153 typedef base::Vector<DefaultEmbedding2D> DefaultEmbedding2Ds;
155 typedef DefaultEmbeddingD<3> DefaultEmbedding3D;
156 typedef base::Vector<DefaultEmbedding3D> DefaultEmbedding3Ds;
158 typedef DefaultEmbeddingD<4> DefaultEmbedding4D;
159 typedef base::Vector<DefaultEmbedding4D> DefaultEmbedding4Ds;
161 typedef DefaultEmbeddingD<5> DefaultEmbedding5D;
162 typedef base::Vector<DefaultEmbedding5D> DefaultEmbedding5Ds;
164 typedef DefaultEmbeddingD<6> DefaultEmbedding6D;
165 typedef base::Vector<DefaultEmbedding6D> DefaultEmbedding6Ds;
167 typedef DefaultEmbeddingD<-1> DefaultEmbeddingKD;
168 typedef base::Vector<DefaultEmbeddingKD> DefaultEmbeddingKDs;
178 VectorD<D> get_coordinates(
const O &index)
const {
180 for (
unsigned int i = 0; i < unit_cell_.get_dimension(); ++i) {
184 "Log grid axis must have positive index.");
185 ret[i] += unit_cell_[i] * (1.0 - std::pow(base_[i], index[i])) /
188 ret[i] += unit_cell_[i] * index[i];
194 VectorD<D> get_uniform_offset(
const O &v0,
double o)
const {
195 Floats ret(get_dimension());
196 for (
unsigned int i = 0; i < get_dimension(); ++i) {
202 Floats nuc(bb.get_dimension());
203 for (
unsigned int i = 0; i < bb.get_dimension(); ++i) {
206 nuc[i] = side / ns[i];
208 set_unit_cell(
VectorD<D>(nuc.begin(), nuc.end()));
216 set_unit_cell(cell, base);
231 const Ints &counts,
bool bound_centers =
false) {
234 for (
unsigned int i = 0; i < bases.get_dimension(); ++i) {
236 "LogEmbedding base #" << i <<
" cannot be negative",
241 (std::pow(bases[i], counts[i]) - 1.0);
247 "Too large a cell side");
250 set_unit_cell(cell, bases);
255 get_uniform_offset(
GridIndexD<D>(counts.begin(), counts.end()), -.5));
256 VectorD<D> extents = upper_corner - lower_corner;
259 for (
unsigned int i = 0; i < uc.get_dimension(); ++i) {
268 uc[i] * (1.0 - std::pow(bases[i], .5)) / (1.0 - bases[i]);
272 set_unit_cell(uc, bases);
279 void set_origin(
const VectorD<D> &o) { origin_ = o; }
280 const VectorD<D> get_origin()
const {
return origin_; }
281 unsigned int get_dimension()
const {
return get_origin().get_dimension(); }
282 void set_unit_cell(
const VectorD<D> &o,
const VectorD<D> &base) {
286 void set_unit_cell(
const VectorD<D> &o) { unit_cell_ = o; }
301 origin_.get_dimension());
302 for (
unsigned int i = 0; i < get_dimension(); ++i) {
303 double d = o[i] - origin_[i];
305 double fi = d / unit_cell_[i];
306 double li = std::log(fi) / std::log(base_[i]);
307 ret.access_data().get_data()[i] =
static_cast<int>(std::floor(li));
319 VectorD<D> get_center(
const ExtendedGridIndexD<D> &ei)
const {
320 return get_coordinates(get_uniform_offset(ei, .5));
322 VectorD<D> get_center(
const GridIndexD<D> &ei)
const {
323 return get_coordinates(get_uniform_offset(ei, .5));
332 return BoundingBoxD<D>(get_coordinates(ei),
333 get_coordinates(get_uniform_offset(ei, 1)));
340 <<
" base: " << base_);
343 #if !defined(IMP_DOXYGEN)
344 typedef LogEmbeddingD<1> LogEmbedding1D;
345 typedef base::Vector<LogEmbedding1D> LogEmbedding1Ds;
347 typedef LogEmbeddingD<2> LogEmbedding2D;
348 typedef base::Vector<LogEmbedding2D> LogEmbedding2Ds;
350 typedef LogEmbeddingD<3> LogEmbedding3D;
351 typedef base::Vector<LogEmbedding3D> LogEmbedding3Ds;
353 typedef LogEmbeddingD<4> LogEmbedding4D;
354 typedef base::Vector<LogEmbedding4D> LogEmbedding4Ds;
356 typedef LogEmbeddingD<5> LogEmbedding5D;
357 typedef base::Vector<LogEmbedding5D> LogEmbedding5Ds;
359 typedef LogEmbeddingD<6> LogEmbedding6D;
360 typedef base::Vector<LogEmbedding6D> LogEmbedding6Ds;
362 typedef LogEmbeddingD<-1> LogEmbeddingKD;
363 typedef base::Vector<LogEmbeddingKD> LogEmbeddingKDs;
366 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.
const double * get_data() const
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.
An exception for an invalid value being passed to IMP.
BoundingBoxD< D > get_bounding_box(const BoundingBoxD< D > &g)