1 #ifndef SimTK_SimTKCOMMON_MEASURE_H_
2 #define SimTK_SimTKCOMMON_MEASURE_H_
64 #define SimTK_MEASURE_HANDLE_PREAMBLE_BASE(MH,PH) \
65 class Implementation; \
66 explicit MH(Implementation* imp) : PH(imp) {} \
67 MH(SimTK::Subsystem& sub, Implementation* imp, \
68 const SimTK::AbstractMeasure::SetHandle& sh) \
70 MH& operator=(const MH& src) {PH::operator=(src); return *this;}\
71 MH& shallowAssign(const MH& src) {PH::shallowAssign(src); return *this;}\
72 MH& deepAssign(const MH& src) {PH::deepAssign(src); return *this;}
78 #define SimTK_MEASURE_HANDLE_PREAMBLE(MH,PH) \
79 SimTK_MEASURE_HANDLE_PREAMBLE_BASE(MH,PH) \
80 MH() : PH(new Implementation()) {} \
81 explicit MH(SimTK::Subsystem& sub) \
82 : PH(sub,new Implementation(), typename PH::SetHandle()) {}
88 #define SimTK_MEASURE_HANDLE_PREAMBLE_ABSTRACT(MH,PH) \
89 SimTK_MEASURE_HANDLE_PREAMBLE_BASE(MH,PH) \
111 #define SimTK_MEASURE_HANDLE_POSTSCRIPT(MH,PH) \
112 static bool isA(const SimTK::AbstractMeasure& m) \
113 { return dynamic_cast<const Implementation*>(&m.getImpl()) != 0; } \
114 static const MH& getAs(const SimTK::AbstractMeasure& m) \
115 { assert(isA(m)); return static_cast<const MH&>(m); } \
116 static MH& updAs(SimTK::AbstractMeasure& m) \
117 { assert(isA(m)); return static_cast<MH&>(m); } \
118 const Implementation& getImpl() const \
119 { return SimTK_DYNAMIC_CAST_DEBUG<const Implementation&> \
120 (SimTK::AbstractMeasure::getImpl());} \
121 Implementation& updImpl() \
122 { return SimTK_DYNAMIC_CAST_DEBUG<Implementation&> \
123 (SimTK::AbstractMeasure::updImpl());}
180 {
return shallowAssign(source); }
206 int getNumTimeDerivatives()
const;
216 Stage getDependsOnStage(
int derivOrder=0)
const;
221 {
return impl && impl==other.impl;}
226 bool isInSubsystem()
const;
234 MeasureIndex getSubsystemMeasureIndex()
const;
244 int getRefCount()
const;
249 Implementation* impl;
357 {
updImpl().setValue(value);
return *
this; }
378 explicit Zero(
int size);
398 explicit One(
int size);
433 {
getImpl().setValue(state, value); }
493 {
updImpl().setDependsOnStage(dependsOn);
return *
this; }
500 {
updImpl().setInvalidatedStage(invalidated);
return *
this; }
529 {
return getImpl().updValue(state); }
552 {
getImpl().markAsNotValid(state); }
558 { updValue(state) = value; markAsValid(state); }
605 "Measure_<T>::Plus::ctor()",
606 "Arguments must be in the same Subsystem as this Measure.");
630 "Measure_<T>::Minus::ctor()",
631 "Arguments must be in the same Subsystem as this Measure.");
654 "Measure_<T>::Scale::ctor()",
655 "Argument must be in the same Subsystem as this Measure.");
660 {
return getImpl().getOperandMeasure(); }
688 const T& initAlloc=T(0))
695 {
return getImpl().setValue(s, value); }
700 {
return getImpl().getDerivativeMeasure(); }
704 {
return getImpl().getInitialConditionMeasure(); }
707 {
updImpl().setDerivativeMeasure(d);
return *
this; }
709 {
updImpl().setInitialConditionMeasure(ic);
return *
this; }
759 {
return getImpl().isUsingApproximation(); }
764 {
return getImpl().getOperandMeasure(); }
770 {
updImpl().setOperandMeasure(operand);
return *
this; }
776 {
updImpl().setForceUseApproximation(mustApproximate); }
783 {
return getImpl().getForceUseApproximation(); }
855 {
updImpl().setOperation(op);
return *
this; }
866 {
return getImpl().getTimeOfExtremeValue(state); }
869 {
return getImpl().setValue(s, value); }
872 {
return getImpl().getOperandMeasure(); }
875 {
updImpl().setOperandMeasure(s);
return *
this; }
989 {
updImpl().setUseLinearInterpolationOnly(linearOnly);
return *
this; }
1005 {
updImpl().setCanUseCurrentValue(canUseCurrentValue);
return *
this; }
1009 {
updImpl().setSourceMeasure(source);
return *
this; }
1013 {
updImpl().setDelay(delay);
return *
this; }
1017 {
return getImpl().getUseLinearInterpolationOnly(); }
1021 {
return getImpl().getCanUseCurrentValue(); }
1025 {
return getImpl().getSourceMeasure(); }
1030 {
return getImpl().getDelay(); }
#define SimTK_ERRCHK_ALWAYS(cond, whereChecked, msg)
Definition: ExceptionMacros.h:281
#define SimTK_MEASURE_HANDLE_PREAMBLE(MH, PH)
Definition: Measure.h:78
Operation
Definition: Measure.h:839
#define SimTK_SimTKCOMMON_EXPORT
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:224
This is the header which should be included in user programs that would like to make use of all the S...
Includes internal headers providing declarations for the basic SimTK Core classes.
The abstract parent of all Measure Implementation classes.
Definition: MeasureImplementation.h:48
Stage getDependsOnStage(int derivOrder) const
Definition: MeasureImplementation.h:105
An object of this type is used as a dummy argument to make sure the automatically-generated handle co...
Definition: Measure.h:156
This is the base class for all Measure handle classes.
Definition: Measure.h:151
AbstractMeasure & operator=(const AbstractMeasure &source)
Shallow assignment operator results in this handle referencing the same Implementation object as does...
Definition: Measure.h:179
Implementation & updImpl()
Definition: Measure.h:241
const Implementation & getImpl() const
Definition: Measure.h:240
bool isSameMeasure(const AbstractMeasure &other) const
There can be multiple handles on the same Measure.
Definition: Measure.h:220
const Subsystem & getSubsystem() const
Return a reference to the Subsystem that owns this Measure.
Definition: MeasureImplementation.h:229
bool isEmptyHandle() const
Definition: Measure.h:223
bool hasImpl() const
Definition: Measure.h:242
This is a class to represent unique IDs for events in a type-safe way.
Definition: MeasureImplementation.h:608
This creates a Measure whose value is a Topology-stage constant of any type T.
Definition: Measure.h:339
SimTK_MEASURE_HANDLE_PREAMBLE(Constant, Measure_< T >)
Constant(const T &value)
Create a constant measure that is not part of any Subsystem, and provide the constant value.
Definition: Measure.h:345
SimTK_MEASURE_HANDLE_POSTSCRIPT(Constant, Measure_< T >)
Constant(Subsystem &sub, const T &value)
Create a constant measure with the given value and install it into the given Subsystem.
Definition: Measure.h:350
Constant & setValue(const T &value)
Change the value returned by this Measure.
Definition: Measure.h:356
Definition: MeasureImplementation.h:2024
(CAUTION: still under development) This is a Measure whose value at time t is the value that its sour...
Definition: Measure.h:971
Delay & setCanUseCurrentValue(bool canUseCurrentValue)
(Advanced) Allow the Delay measure to refer to the current value when estimating the delayed value.
Definition: Measure.h:1004
Delay(Subsystem &sub, const Measure_< T > &source, Real delay)
Create a Measure whose output is the same as the given source measure but delayed by a time delay.
Definition: Measure.h:979
const Measure_< T > & getSourceMeasure() const
Obtain a reference to the source Measure.
Definition: Measure.h:1024
bool getUseLinearInterpolationOnly() const
Return the value of the "use linear interpolation only" flag.
Definition: Measure.h:1016
Real getDelay() const
Get the amount of time by which this Measure is delaying its source Measure.
Definition: Measure.h:1029
Delay & setSourceMeasure(const Measure_< T > &source)
Replace the source measure.
Definition: Measure.h:1008
bool getCanUseCurrentValue() const
Return the value of the "can use current value" flag.
Definition: Measure.h:1020
Delay & setDelay(Real delay)
Change the delay time.
Definition: Measure.h:1012
Delay & setUseLinearInterpolationOnly(bool linearOnly)
(Advanced) Restrict the Delay measure to use only linear interpolation to estimate delayed values.
Definition: Measure.h:988
Definition: MeasureImplementation.h:1301
This Measure operator returns the time derivative of its operand measure, or a numerical approximatio...
Definition: Measure.h:742
bool getForceUseApproximation() const
Check the current value of the flag which forces this measure to use numerical approximation regardle...
Definition: Measure.h:782
SimTK_MEASURE_HANDLE_POSTSCRIPT(Differentiate, Measure_< T >)
const Measure_< T > & getOperandMeasure() const
Get a reference to the measure that is being differentiated by this measure.
Definition: Measure.h:763
Differentiate & setOperandMeasure(const Measure_< T > &operand)
Set the measure that is to be differentiated by this measure.
Definition: Measure.h:769
Differentiate(Subsystem &subsystem, const Measure_< T > &operand)
Create a measure whose value is the time derivative of the given operand measure.
Definition: Measure.h:750
void setForceUseApproximation(bool mustApproximate)
Force use of numerical approximation for the derivative, even if the operand measure can supply its o...
Definition: Measure.h:775
bool isUsingApproximation() const
Test whether the derivative returned as the value of this measure is being estimated numerically,...
Definition: Measure.h:758
SimTK_MEASURE_HANDLE_PREAMBLE(Differentiate, Measure_< T >)
Definition: MeasureImplementation.h:1440
This Measure tracks extreme values attained by the elements of its source operand since the last init...
Definition: Measure.h:835
void setValue(State &s, const T &value) const
Definition: Measure.h:868
Real getTimeOfExtremeValue(const State &state) const
Return the time at which the reported extreme value first occurred.
Definition: Measure.h:865
@ MaxAbs
Definition: Measure.h:840
Extreme & setOperandMeasure(const Measure_< T > &s)
Definition: Measure.h:874
@ Maximum
Definition: Measure.h:841
const Measure_< T > & getOperandMeasure() const
Definition: Measure.h:871
Operation getOperation() const
Return the operation currently being performed by this measure.
Definition: Measure.h:858
SimTK_MEASURE_HANDLE_POSTSCRIPT(Extreme, Measure_< T >)
Extreme & setOperation(Operation op)
Set the operation to be performed.
Definition: Measure.h:854
@ MinAbs
Definition: Measure.h:842
Extreme(Subsystem &sub, const Measure_< T > &operand, Operation op=MaxAbs)
Default behavior for the Extreme measure is to find the operand's value that is of maximum absolute v...
Definition: Measure.h:849
SimTK_MEASURE_HANDLE_PREAMBLE(Extreme, Measure_< T >)
void setDefaultValue(const T &defaultValue)
Set a new default value for this Measure.
Definition: MeasureImplementation.h:403
const T & getDefaultValue() const
Return a reference to the value that this Measure will use to initialize its value-level state resour...
Definition: MeasureImplementation.h:412
bool getIsPresumedValidAtDependsOnStage() const
Definition: MeasureImplementation.h:418
const T & getValue(const State &s, int derivOrder) const
Definition: MeasureImplementation.h:361
void setIsPresumedValidAtDependsOnStage(bool presume)
Definition: MeasureImplementation.h:414
The implementation for Integrate measures allocates a continuous state variable or variables from the...
Definition: MeasureImplementation.h:1142
This measure yields the time integral of a given derivative measure, initializing with an initial con...
Definition: Measure.h:675
SimTK_MEASURE_HANDLE_PREAMBLE(Integrate, Measure_< T >)
SimTK_MEASURE_HANDLE_POSTSCRIPT(Integrate, Measure_< T >)
const Measure_< T > & getInitialConditionMeasure() const
Get the measure whose value is used as an initial condition for the integral at the start of an integ...
Definition: Measure.h:703
Integrate(Subsystem &subsystem, const Measure_< T > &deriv, const Measure_< T > &ic, const T &initAlloc=T(0))
Create a new measure that will use Measure ic's value for initial conditions, and then integrate the ...
Definition: Measure.h:685
Integrate & setDerivativeMeasure(const Measure_< T > &d)
Definition: Measure.h:706
void setValue(State &s, const T &value) const
Set the current value of this measure by modifying the state variables that hold the integral.
Definition: Measure.h:694
const Measure_< T > & getDerivativeMeasure() const
Get the integrand (derivative) measure for this integral.
Definition: Measure.h:698
Integrate & setInitialConditionMeasure(const Measure_< T > &ic)
Definition: Measure.h:708
Track the value of the operand that is of maximum absolute value.
Definition: Measure.h:903
MaxAbs(Subsystem &sub, const Measure_< T > &operand)
Definition: Measure.h:906
Track the maximum value of the operand (signed).
Definition: Measure.h:893
Maximum(Subsystem &sub, const Measure_< T > &operand)
Definition: Measure.h:896
Track the value of the operand that is of minimum absolute value (not very useful).
Definition: Measure.h:914
MinAbs(Subsystem &sub, const Measure_< T > &operand)
Definition: Measure.h:917
Track the minimum value of the operand (signed).
Definition: Measure.h:883
Minimum(Subsystem &sub, const Measure_< T > &operand)
Definition: Measure.h:886
Definition: MeasureImplementation.h:1019
This Measure is the difference of two Measures of the same type T.
Definition: Measure.h:620
SimTK_MEASURE_HANDLE_POSTSCRIPT(Minus, Measure_< T >)
SimTK_MEASURE_HANDLE_PREAMBLE(Minus, Measure_< T >)
Minus(Subsystem &sub, const Measure_< T > &left, const Measure_< T > &right)
Definition: Measure.h:624
This creates a Measure::Constant whose value is always T(1) and can't be changed.
Definition: Measure.h:389
Definition: MeasureImplementation.h:966
This Measure is the sum of two Measures of the same type T.
Definition: Measure.h:595
SimTK_MEASURE_HANDLE_POSTSCRIPT(Plus, Measure_< T >)
Plus(Subsystem &sub, const Measure_< T > &left, const Measure_< T > &right)
Definition: Measure.h:599
SimTK_MEASURE_HANDLE_PREAMBLE(Plus, Measure_< T >)
Definition: MeasureImplementation.h:788
This Measure holds the result of some externally-determined computation, and helps to coordinate the ...
Definition: Measure.h:455
SimTK_MEASURE_HANDLE_POSTSCRIPT(Result, Measure_< T >)
bool isValid(const State &state) const
Check whether the value contained in this Measure is currently valid.
Definition: Measure.h:542
Result & setInvalidatedStage(Stage invalidated)
Change the invalidated stage for this measure's value, which must be strictly greater than the curren...
Definition: Measure.h:499
SimTK_MEASURE_HANDLE_PREAMBLE(Result, Measure_< T >)
void setValue(const State &state, const T &value) const
Set a new value and mark it as valid.
Definition: Measure.h:557
Result & setDependsOnStage(Stage dependsOn)
Change the dependsOn stage for this measure's value, which must be strictly less than the current set...
Definition: Measure.h:492
Stage getDependsOnStage() const
Get the dependsOn stage for this measure's value.
Definition: Measure.h:482
Stage getInvalidatedStage() const
Get the invalidated stage for this measure's value.
Definition: Measure.h:484
void markAsValid(const State &state) const
Mark the current value as valid.
Definition: Measure.h:537
Result & setIsPresumedValidAtDependsOnStage(bool presume)
Normally a Result measure's value is not considered valid unless we are notified explicitly that it i...
Definition: Measure.h:514
T & updValue(const State &state) const
Obtain write access to the Measure's value in order to modify it.
Definition: Measure.h:528
bool getIsPresumedValidAtDependsOnStage() const
Return the value of the "presumed valid at dependsOn stage" flag.
Definition: Measure.h:519
void markAsNotValid(const State &state) const
Manually mark the contained value as invalid.
Definition: Measure.h:551
Result(Subsystem &sub, Stage dependsOn, Stage invalidated)
Create a new Result measure and add it to the indicated subsystem.
Definition: Measure.h:477
NOT IMPLEMENTED YET – This is a Measure operator which, upon occurrence of a designated event,...
Definition: Measure.h:1055
const Measure_< T > & getSource() const
SampleAndHold & setEventId(EventId)
SimTK_MEASURE_HANDLE_POSTSCRIPT(SampleAndHold, Measure_< T >)
SampleAndHold(Subsystem &sub, const Measure_< T > &source, EventId e)
EventId getEventId() const
SampleAndHold & setSource(const Measure_< T > &s)
void setValue(State &s, const T &value) const
Set the held value to a particular value, unrelated to the source.
SimTK_MEASURE_HANDLE_PREAMBLE(SampleAndHold, Measure_< T >)
void sample(State &s) const
Force this Measure to sample its input at the current time.
Definition: MeasureImplementation.h:1074
This Measure multiplies some other Measure by a Real scale factor.
Definition: Measure.h:645
SimTK_MEASURE_HANDLE_POSTSCRIPT(Scale, Measure_< T >)
SimTK_MEASURE_HANDLE_PREAMBLE(Scale, Measure_< T >)
Scale(Subsystem &sub, Real factor, const Measure_< T > &operand)
Definition: Measure.h:649
const Measure_< T > & getOperandMeasure() const
Get the operand (thing being scaled) measure for this measure.
Definition: Measure.h:659
Definition: MeasureImplementation.h:904
This measure produces a sinusoidal function of time:
Definition: Measure.h:573
SimTK_MEASURE_HANDLE_PREAMBLE(Sinusoid, Measure_< T >)
Sinusoid(Subsystem &sub, const T &litude, const T &frequency, const T &phase=T(0))
Definition: Measure.h:577
SimTK_MEASURE_HANDLE_POSTSCRIPT(Sinusoid, Measure_< T >)
This creates a Measure::Time whose value is always T(time).
Definition: Measure.h:407
SimTK_MEASURE_HANDLE_POSTSCRIPT(Time, Measure_< T >)
SimTK_MEASURE_HANDLE_PREAMBLE(Time, Measure_< T >)
Definition: MeasureImplementation.h:708
This creates a Measure whose value is a discrete State variable of any type T.
Definition: Measure.h:420
SimTK_MEASURE_HANDLE_PREAMBLE(Variable, Measure_< T >)
void setValue(State &state, const T &value) const
Definition: Measure.h:432
SimTK_MEASURE_HANDLE_POSTSCRIPT(Variable, Measure_< T >)
Variable(Subsystem &sub, Stage invalidates, const T &defaultValue)
Definition: Measure.h:427
This creates a Measure::Constant whose value is always T(0) and can't be changed.
Definition: Measure.h:369
This is the base handle class for all Measures whose value type is known, including all the Simbody b...
Definition: Measure.h:261
SimTK_MEASURE_HANDLE_POSTSCRIPT(Measure_, AbstractMeasure)
const T & getValue(const State &s, int derivOrder=0) const
Retrieve the Value of this Measure or one of its time derivatives, assuming the supplied State has be...
Definition: Measure.h:274
Measure_ & setDefaultValue(const T &defaultValue)
Change the default value associated with this Measure.
Definition: Measure.h:283
const T & getDefaultValue() const
Obtain a reference to the default value associated with this Measure.
Definition: Measure.h:288
SimTK_MEASURE_HANDLE_PREAMBLE_ABSTRACT(Measure_, AbstractMeasure)
This class is still abstract so we don't want it to allocate an Implementation object in its default ...
This class is basically a glorified enumerated type, type-safe and range checked but permitting conve...
Definition: Stage.h:66
This object is intended to contain all state information for a SimTK::System, except topological info...
Definition: State.h:280
A Subsystem is expected to be part of a larger System and to have interdependencies with other subsys...
Definition: Subsystem.h:55
bool isSameSubsystem(const Subsystem &otherSubsystem) const
Determine if this Subsystem handle refers to the same Subsystem::Guts object as handle otherSubsystem...
Definition: Subsystem.h:322
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
SimTK_Real Real
This is the default compiled-in floating point type for SimTK, either float or double.
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:606
SimTK_DEFINE_UNIQUE_INDEX_TYPE(AssemblyConditionIndex)
Measure_< Real > Measure
This typedef is a convenient abbreviation for the most common kind of Measure – one that returns a si...
Definition: Measure.h:328