IMP  2.1.1
The Integrative Modeling Platform
DOFsSampler.h
Go to the documentation of this file.
1 /**
2  * \file kinematics/DOFsSampler.h \brief
3  *
4  * Copyright 2007-2010 Sali Lab. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPKINEMATICS_DO_FS_SAMPLER_H
9 #define IMPKINEMATICS_DO_FS_SAMPLER_H
10 
11 #include "kinematics_config.h"
12 #include "DOFValues.h"
13 
14 IMPKINEMATICS_BEGIN_NAMESPACE
15 
16 /**
17  a base class for sampling certain combinations of degrees of freedom
18  */
20 {
22 
23 public:
24  /** Constructs the dofs sampler over specified dofs
25  */
26  DOFsSampler(DOFs dofs) :
27  IMP::base::Object("IMP_KINEMATICS_DOFSSAMPLER"),
28  dofs_(dofs),
29  last_sample_( DOFValues( dofs ) )
30  {
31  }
32 
33  /**
34  @return a sample on the dofs over which this class samples
35  */
36  DOFValues get_sample() const
37  {
38  last_sample_ = do_get_sample();
39  return last_sample_;
40  }
41 
42  // TODO: should it be a class function? it is not strictly related to the
43  // class
44  /**
45  apply set of dof values in values over objects associated with
46  this DOFsSampler (e.g., joints)
47  */
48  virtual void apply(const DOFValues& values) = 0;
49 
50  /**
51  calls apply(), using values from the last sample returned by
52  get_sample() (or values of initial dofs provided to constructor,
53  if no sample was taken yet)
54  */
55  void apply_last_sample() { apply(last_sample_); }
56 
57  /**
58  make a new sample of the dofs over which this class samples,
59  and apply them to objects associated with this sampler (e.g.
60  joints)
61  */
62  void sample_and_apply() { apply(get_sample()); }
63 
64  /** Returns the dofs over which this sampler works
65  */
66  DOFs const& get_dofs() const
67  { return dofs_; }
68 
69  /** Returns the i'th dof over which this sampler works
70  */
71  DOF const* get_dof(unsigned int i) const
72  {
73  IMP_USAGE_CHECK( i < dofs_.size(),
74  "Accessing out-of-range dof in DOFsSampler");
75  return dofs_[i];
76  }
77 
78  unsigned int get_number_of_dofs() const
79  { return dofs_.size(); }
80 
81 
82  protected:
83  virtual DOFValues do_get_sample() const = 0;
84 
85  private:
86  //! DOFs over which to sample
87  DOFs dofs_;
88 
89  //! It is assumed that get_sample() implementations set this to its return
90  //! value
91  mutable DOFValues last_sample_;
92 };
93 
95 
96 IMPKINEMATICS_END_NAMESPACE
97 
98 #endif /* IMPKINEMATICS_DO_FS_SAMPLER_H */
a simple class for storage of DOF values.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
DOF const * get_dof(unsigned int i) const
Definition: DOFsSampler.h:71
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Common base class for heavy weight IMP objects.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
DOFValues get_sample() const
Definition: DOFsSampler.h:36
DOFs const & get_dofs() const
Definition: DOFsSampler.h:66
IMP::base::Vector< IMP::base::Pointer< DOF > > DOFs
Definition: DOF.h:73