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>
19 #include <boost/serialization/access.hpp>
20 #include <boost/serialization/split_member.hpp>
27 IMPALGEBRA_BEGIN_NAMESPACE
38 friend class boost::serialization::access;
40 template<
class Archive>
void save(Archive &ar,
const unsigned int)
const {
41 ar << origin_ << unit_cell_;
44 template<
class Archive>
void load(Archive &ar,
const unsigned int) {
47 set_unit_cell(unit_cell_);
50 BOOST_SERIALIZATION_SPLIT_MEMBER()
55 for (
unsigned int i = 0; i < get_dimension(); ++i) {
61 VectorD<D> get_uniform_offset(
const O &v0,
double o)
const {
62 Floats ret(get_dimension());
63 for (
unsigned int i = 0; i < get_dimension(); ++i) {
69 Floats nuc(bb.get_dimension());
70 for (
unsigned int i = 0; i < bb.get_dimension(); ++i) {
73 nuc[i] = side / ns[i];
75 set_unit_cell(
VectorD<D>(nuc.begin(), nuc.end()));
85 void set_origin(
const VectorD<D> &o) { origin_ = o; }
86 const VectorD<D> get_origin()
const {
return origin_; }
87 unsigned int get_dimension()
const {
return get_origin().get_dimension(); }
90 Floats iuc(o.get_dimension());
91 for (
unsigned int i = 0; i < get_dimension(); ++i) {
92 iuc[i] = 1.0 / unit_cell_[i];
94 inverse_unit_cell_ =
VectorD<D>(iuc.begin(), iuc.end());
98 const VectorD<D> &get_inverse_unit_cell()
const {
return inverse_unit_cell_; }
114 origin_.get_dimension());
115 for (
unsigned int i = 0; i < get_dimension(); ++i) {
116 double d = o[i] - origin_[i];
117 double fi = d * inverse_unit_cell_[i];
118 ret.access_data().
get_data()[i] =
static_cast<int>(std::floor(fi));
124 origin_.get_dimension());
125 for (
unsigned int i = 0; i < get_dimension(); ++i) {
126 double d = o[i] - origin_[i];
127 double fi = d * inverse_unit_cell_[i];
128 ret.access_data().
get_data()[i] =
static_cast<int>(std::floor(fi));
136 VectorD<D> get_center(
const ExtendedGridIndexD<D> &ei)
const {
140 VectorD<D> get_center(
const GridIndexD<D> &ei)
const {
150 BoundingBoxD<D> get_bounding_box(
const ExtendedGridIndexD<D> &ei)
const {
151 return BoundingBoxD<D>(
156 BoundingBoxD<D> get_bounding_box(
const GridIndexD<D> &ei)
const {
157 return BoundingBoxD<D>(
164 <<
" unit cell: " << unit_cell_);
167 #if !defined(IMP_DOXYGEN)
168 typedef DefaultEmbeddingD<1> DefaultEmbedding1D;
169 typedef Vector<DefaultEmbedding1D> DefaultEmbedding1Ds;
171 typedef DefaultEmbeddingD<2> DefaultEmbedding2D;
172 typedef Vector<DefaultEmbedding2D> DefaultEmbedding2Ds;
174 typedef DefaultEmbeddingD<3> DefaultEmbedding3D;
175 typedef Vector<DefaultEmbedding3D> DefaultEmbedding3Ds;
177 typedef DefaultEmbeddingD<4> DefaultEmbedding4D;
178 typedef Vector<DefaultEmbedding4D> DefaultEmbedding4Ds;
180 typedef DefaultEmbeddingD<5> DefaultEmbedding5D;
181 typedef Vector<DefaultEmbedding5D> DefaultEmbedding5Ds;
183 typedef DefaultEmbeddingD<6> DefaultEmbedding6D;
184 typedef Vector<DefaultEmbedding6D> DefaultEmbedding6Ds;
186 typedef DefaultEmbeddingD<-1> DefaultEmbeddingKD;
187 typedef Vector<DefaultEmbeddingKD> DefaultEmbeddingKDs;
197 friend class boost::serialization::access;
199 template<
class Archive>
void serialize(Archive &ar,
const unsigned int) {
200 ar & origin_ & unit_cell_ & base_;
204 VectorD<D> get_coordinates(
const O &index)
const {
206 for (
unsigned int i = 0; i < unit_cell_.get_dimension(); ++i) {
210 "Log grid axis must have positive index.");
211 ret[i] += unit_cell_[i] * (1.0 - std::pow(base_[i], index[i])) /
214 ret[i] += unit_cell_[i] * index[i];
220 VectorD<D> get_uniform_offset(
const O &v0,
double o)
const {
221 Floats ret(get_dimension());
222 for (
unsigned int i = 0; i < get_dimension(); ++i) {
228 Floats nuc(bb.get_dimension());
229 for (
unsigned int i = 0; i < bb.get_dimension(); ++i) {
232 nuc[i] = side / ns[i];
234 set_unit_cell(
VectorD<D>(nuc.begin(), nuc.end()));
242 set_unit_cell(cell, base);
257 const Ints &counts,
bool bound_centers =
false) {
260 for (
unsigned int i = 0; i < bases.get_dimension(); ++i) {
262 "LogEmbedding base #" << i <<
" cannot be negative",
267 (std::pow(bases[i], counts[i]) - 1.0);
273 "Too large a cell side");
276 set_unit_cell(cell, bases);
281 get_uniform_offset(
GridIndexD<D>(counts.begin(), counts.end()), -.5));
282 VectorD<D> extents = upper_corner - lower_corner;
285 for (
unsigned int i = 0; i < uc.get_dimension(); ++i) {
294 uc[i] * (1.0 - std::pow(bases[i], .5)) / (1.0 - bases[i]);
298 set_unit_cell(uc, bases);
305 void set_origin(
const VectorD<D> &o) { origin_ = o; }
306 const VectorD<D> get_origin()
const {
return origin_; }
307 unsigned int get_dimension()
const {
return get_origin().get_dimension(); }
308 void set_unit_cell(
const VectorD<D> &o,
const VectorD<D> &base) {
312 void set_unit_cell(
const VectorD<D> &o) { unit_cell_ = o; }
327 origin_.get_dimension());
328 for (
unsigned int i = 0; i < get_dimension(); ++i) {
329 double d = o[i] - origin_[i];
331 double fi = d / unit_cell_[i];
332 double li = std::log(fi) / std::log(base_[i]);
333 ret.access_data().get_data()[i] =
static_cast<int>(std::floor(li));
345 VectorD<D> get_center(
const ExtendedGridIndexD<D> &ei)
const {
346 return get_coordinates(get_uniform_offset(ei, .5));
348 VectorD<D> get_center(
const GridIndexD<D> &ei)
const {
349 return get_coordinates(get_uniform_offset(ei, .5));
357 BoundingBoxD<D> get_bounding_box(
const ExtendedGridIndexD<D> &ei)
const {
358 return BoundingBoxD<D>(get_coordinates(ei),
359 get_coordinates(get_uniform_offset(ei, 1)));
361 BoundingBoxD<D> get_bounding_box(
const GridIndexD<D> &ei)
const {
362 return get_bounding_box(ExtendedGridIndexD<D>(ei.begin(), ei.end()));
366 <<
" base: " << base_);
369 #if !defined(IMP_DOXYGEN)
370 typedef LogEmbeddingD<1> LogEmbedding1D;
371 typedef Vector<LogEmbedding1D> LogEmbedding1Ds;
373 typedef LogEmbeddingD<2> LogEmbedding2D;
374 typedef Vector<LogEmbedding2D> LogEmbedding2Ds;
376 typedef LogEmbeddingD<3> LogEmbedding3D;
377 typedef Vector<LogEmbedding3D> LogEmbedding3Ds;
379 typedef LogEmbeddingD<4> LogEmbedding4D;
380 typedef Vector<LogEmbedding4D> LogEmbedding4Ds;
382 typedef LogEmbeddingD<5> LogEmbedding5D;
383 typedef Vector<LogEmbedding5D> LogEmbedding5Ds;
385 typedef LogEmbeddingD<6> LogEmbedding6D;
386 typedef Vector<LogEmbedding6D> LogEmbedding6Ds;
388 typedef LogEmbeddingD<-1> LogEmbeddingKD;
389 typedef Vector<LogEmbeddingKD> LogEmbeddingKDs;
392 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.
Helper macros for throwing and handling exceptions.
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)