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