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 {
131 BoundingBoxD<D> get_bounding_box(
const ExtendedGridIndexD<D> &ei)
const {
132 return BoundingBoxD<D>(
137 BoundingBoxD<D> get_bounding_box(
const GridIndexD<D> &ei)
const {
138 return BoundingBoxD<D>(
145 <<
" unit cell: " << unit_cell_);
148 #if !defined(IMP_DOXYGEN)
149 typedef DefaultEmbeddingD<1> DefaultEmbedding1D;
150 typedef Vector<DefaultEmbedding1D> DefaultEmbedding1Ds;
152 typedef DefaultEmbeddingD<2> DefaultEmbedding2D;
153 typedef Vector<DefaultEmbedding2D> DefaultEmbedding2Ds;
155 typedef DefaultEmbeddingD<3> DefaultEmbedding3D;
156 typedef Vector<DefaultEmbedding3D> DefaultEmbedding3Ds;
158 typedef DefaultEmbeddingD<4> DefaultEmbedding4D;
159 typedef Vector<DefaultEmbedding4D> DefaultEmbedding4Ds;
161 typedef DefaultEmbeddingD<5> DefaultEmbedding5D;
162 typedef Vector<DefaultEmbedding5D> DefaultEmbedding5Ds;
164 typedef DefaultEmbeddingD<6> DefaultEmbedding6D;
165 typedef Vector<DefaultEmbedding6D> DefaultEmbedding6Ds;
167 typedef DefaultEmbeddingD<-1> DefaultEmbeddingKD;
168 typedef 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));
331 BoundingBoxD<D> get_bounding_box(
const ExtendedGridIndexD<D> &ei)
const {
332 return BoundingBoxD<D>(get_coordinates(ei),
333 get_coordinates(get_uniform_offset(ei, 1)));
335 BoundingBoxD<D> get_bounding_box(
const GridIndexD<D> &ei)
const {
336 return get_bounding_box(ExtendedGridIndexD<D>(ei.begin(), ei.end()));
340 <<
" base: " << base_);
343 #if !defined(IMP_DOXYGEN)
344 typedef LogEmbeddingD<1> LogEmbedding1D;
345 typedef Vector<LogEmbedding1D> LogEmbedding1Ds;
347 typedef LogEmbeddingD<2> LogEmbedding2D;
348 typedef Vector<LogEmbedding2D> LogEmbedding2Ds;
350 typedef LogEmbeddingD<3> LogEmbedding3D;
351 typedef Vector<LogEmbedding3D> LogEmbedding3Ds;
353 typedef LogEmbeddingD<4> LogEmbedding4D;
354 typedef Vector<LogEmbedding4D> LogEmbedding4Ds;
356 typedef LogEmbeddingD<5> LogEmbedding5D;
357 typedef Vector<LogEmbedding5D> LogEmbedding5Ds;
359 typedef LogEmbeddingD<6> LogEmbedding6D;
360 typedef Vector<LogEmbedding6D> LogEmbedding6Ds;
362 typedef LogEmbeddingD<-1> LogEmbeddingKD;
363 typedef Vector<LogEmbeddingKD> LogEmbeddingKDs;
366 IMPALGEBRA_END_NAMESPACE
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
VectorD< D > get_elementwise_product(const algebra::VectorD< D > &a, const algebra::VectorD< D > &b)
Return the vector that is the elementwise product of the two.
const VectorD< D > & get_corner(unsigned int i) const
For 0 return lower corner and for 1, the upper corner.
#define IMP_FAILURE(message)
A runtime failure for IMP.
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.
ExtendedGridIndexD< D > get_extended_index(const VectorD< D > &o) const
Return the index that would contain the voxel if the grid extended there.
Exception definitions and assertions.
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
A Cartesian vector in D-dimensions.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
ExtendedGridIndexD< D > get_extended_index(const VectorD< D > &o) const
Return the index that would contain the voxel if the grid extended there.
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.
Embed a grid as an evenly spaced axis aligned grid.
const VectorD< D > & get_unit_cell() const
Return the unit cell, relative to the origin.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
const double * get_data() const
Return a pointer to the data stored.
#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.
LogEmbeddingD(const BoundingBoxD< D > &bb, const VectorD< D > &bases, const Ints &counts, bool bound_centers=false)