IMP logo
IMP Reference Guide  develop.f6c15b4169,2024/11/06
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-2022 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 <IMP/kinematics/kinematics_config.h>
12 #include "DOFValues.h"
13 
14 IMPKINEMATICS_BEGIN_NAMESPACE
15 
16 //! Base class for sampling certain combinations of degrees of freedom
17 class DOFsSampler : public IMP::Object {
19 
20  public:
21  //! Constructs the dofs sampler over specified dofs
23  : IMP::Object("IMP_KINEMATICS_DOFSSAMPLER"),
24  dofs_(dofs),
25  last_sample_(DOFValues(dofs)) {}
26 
27  //! @return a sample on the dofs over which this class samples
29  last_sample_ = do_get_sample();
30  return last_sample_;
31  }
32 
33  // TODO: should it be a class function? it is not strictly related to the
34  // class
35  /**
36  apply set of dof values in values over objects associated with
37  this DOFsSampler (e.g., joints)
38  */
39  virtual void apply(const DOFValues& values) = 0;
40 
41  /**
42  calls apply(), using values from the last sample returned by
43  get_sample() (or values of initial dofs provided to constructor,
44  if no sample was taken yet)
45  */
46  void apply_last_sample() { apply(last_sample_); }
47 
48  /**
49  make a new sample of the dofs over which this class samples,
50  and apply them to objects associated with this sampler (e.g.
51  joints)
52  */
53  void sample_and_apply() { apply(get_sample()); }
54 
55  //! Returns the dofs over which this sampler works
56  DOFs const& get_dofs() const { return dofs_; }
57 
58  //! Returns the i'th dof over which this sampler works
59  DOF const* get_dof(unsigned int i) const {
60  IMP_USAGE_CHECK(i < dofs_.size(),
61  "Accessing out-of-range dof in DOFsSampler");
62  return dofs_[i];
63  }
64 
65  unsigned int get_number_of_dofs() const { return dofs_.size(); }
66 
67  protected:
68  virtual DOFValues do_get_sample() const = 0;
69 
70  private:
71  //! DOFs over which to sample
72  DOFs dofs_;
73 
74  //! It is assumed that get_sample() implementations set this to its return
75  //! value
76  mutable DOFValues last_sample_;
77 };
78 
80 
81 IMPKINEMATICS_END_NAMESPACE
82 
83 #endif /* IMPKINEMATICS_DO_FS_SAMPLER_H */
a simple class for storage of DOF values.
IMP::Vector< IMP::Pointer< DOF > > DOFs
Definition: DOF.h:71
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
DOFsSampler(DOFs dofs)
Constructs the dofs sampler over specified dofs.
Definition: DOFsSampler.h:22
Base class for sampling certain combinations of degrees of freedom.
Definition: DOFsSampler.h:17
DOF const * get_dof(unsigned int i) const
Returns the i'th dof over which this sampler works.
Definition: DOFsSampler.h:59
Representation of one degree of freedom (DOF).
Definition: DOF.h:31
Common base class for heavy weight IMP objects.
Definition: Object.h:111
A class that holds DOF values for DOFs.
Definition: DOFValues.h:23
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
#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:28
DOFs const & get_dofs() const
Returns the dofs over which this sampler works.
Definition: DOFsSampler.h:56