API  4.5
For C++ developers
OpenSim::Output< T > Class Template Reference
+ Inheritance diagram for OpenSim::Output< T >:

Public Member Functions

 Output ()
 
 Output (const std::string &name, const std::function< void(const Component *comp, const SimTK::State &, const std::string &channel, T &)> &outputFunction, const SimTK::Stage &dependsOnStage, bool isList)
 Convenience constructor Create a Component::Output bound to a specific method of the Component and valid at a given realization Stage. More...
 
 Output (const Output &source)
 Custom copy constructor is for setting the Channel's pointer back to this Output. More...
 
Outputoperator= (const Output &source)
 Custom copy assignment operator is for setting the Channel's pointer back to this Output. More...
 
virtual ~Output ()
 
 Output (Output &&)=delete
 
Outputoperator= (Output &&)=delete
 
bool isCompatible (const AbstractOutput &o) const override
 
void compatibleAssign (const AbstractOutput &o) override
 
void clearChannels () override
 Output Interface. More...
 
void addChannel (const std::string &channelName) override
 Add a channel to this Output. More...
 
const AbstractChannelgetChannel (const std::string &name) const override
 For a single-value output, name must be empty or must be the output's name. More...
 
const ChannelMapgetChannels () const
 Use this to iterate through this Output's channels (even for single-value Channels). More...
 
const T & getValue (const SimTK::State &state) const
 Return the Value of this output if the state is appropriately realized
to a stage at or beyond the dependsOnStage, otherwise expect an Exception. More...
 
std::string getTypeName () const override
 The name of the value type (e.g., double) produced by this output. More...
 
std::string getValueAsString (const SimTK::State &state) const override
 
Output< T > * clone () const override
 
 SimTK_DOWNCAST (Output, AbstractOutput)
 
- Public Member Functions inherited from OpenSim::AbstractOutput
 AbstractOutput ()
 
 AbstractOutput (const std::string &name, SimTK::Stage dependsOnStage, bool isList)
 
 AbstractOutput (const AbstractOutput &other)=default
 
virtual ~AbstractOutput ()=default
 
const std::string & getName () const
 Output's name. More...
 
const SimTK::Stage & getDependsOnStage () const
 Output's dependence on System being realized to at least this System::Stage. More...
 
bool isListOutput () const
 Can this Output have more than one channel? More...
 
const ComponentgetOwner () const
 Output's owning Component. More...
 
std::string getPathName () const
 This returns <absolute-path-to-component>|<output-name>. More...
 
AbstractOutputoperator= (const AbstractOutput &o)
 
unsigned int getNumberOfSignificantDigits () const
 Specification for number of significant figures in string value. More...
 
void setNumberOfSignificantDigits (unsigned int numSigFigs)
 

Public Types

typedef std::map< std::string, ChannelChannelMap
 The container type that holds onto all of Channels in an Output. More...
 

Static Public Member Functions

static Output< T > * safeDownCast (AbstractOutput *parent)
 For use in python/java/MATLAB bindings. More...
 

Related Functions

(Note that these are not member functions.)

Creating Outputs for your Component

Use these macros at the top of your component class declaration, near where you declare Property properties.

#define OpenSim_DECLARE_OUTPUT(oname, T, func, ostage)
 Create an output for a member function of this component. More...
 
#define OpenSim_DECLARE_LIST_OUTPUT(oname, T, func, ostage)
 Create a list output for a member function of this component. More...
 
#define OpenSim_DECLARE_OUTPUT_FOR_STATE_VARIABLE(oname)
 Create an Output for a StateVariable in this component. More...
 

Nested Classes

class  Channel
 

Additional Inherited Members

- Protected Member Functions inherited from OpenSim::AbstractOutput
void setOwner (const Component &owner)
 
- Protected Attributes inherited from OpenSim::AbstractOutput
SimTK::ReferencePtr< const Component_owner
 

Member Typedef Documentation

◆ ChannelMap

template<class T>
typedef std::map<std::string, Channel> OpenSim::Output< T >::ChannelMap

The container type that holds onto all of Channels in an Output.

Constructor & Destructor Documentation

◆ Output() [1/4]

template<class T>
OpenSim::Output< T >::Output ( )
inline

◆ Output() [2/4]

template<class T>
OpenSim::Output< T >::Output ( const std::string &  name,
const std::function< void(const Component *comp, const SimTK::State &, const std::string &channel, T &)> &  outputFunction,
const SimTK::Stage &  dependsOnStage,
bool  isList 
)
inlineexplicit

Convenience constructor Create a Component::Output bound to a specific method of the Component and valid at a given realization Stage.

Parameters
nameThe name of the output.
outputFunctionThe output function to be invoked (returns Output T)
dependsOnStageStage at which Output can be evaluated.
isListCan this Output have more than one channel?

◆ Output() [3/4]

template<class T>
OpenSim::Output< T >::Output ( const Output< T > &  source)
inline

Custom copy constructor is for setting the Channel's pointer back to this Output.

◆ ~Output()

template<class T>
virtual OpenSim::Output< T >::~Output ( )
inlinevirtual

◆ Output() [4/4]

template<class T>
OpenSim::Output< T >::Output ( Output< T > &&  )
delete

Member Function Documentation

◆ addChannel()

template<class T>
void OpenSim::Output< T >::addChannel ( const std::string &  channelName)
inlineoverridevirtual

Add a channel to this Output.

This should be called within the component's extendFinalizeFromProperties() .

Implements OpenSim::AbstractOutput.

References OpenSim::AbstractOutput::isListOutput().

◆ clearChannels()

template<class T>
void OpenSim::Output< T >::clearChannels ( )
inlineoverridevirtual

Output Interface.

Remove all channels from this Output (for list Outputs).

Implements OpenSim::AbstractOutput.

References OpenSim::AbstractOutput::isListOutput().

◆ clone()

template<class T>
Output<T>* OpenSim::Output< T >::clone ( ) const
inlineoverridevirtual

◆ compatibleAssign()

template<class T>
void OpenSim::Output< T >::compatibleAssign ( const AbstractOutput< T > &  o)
inlineoverridevirtual

◆ getChannel()

template<class T>
const AbstractChannel& OpenSim::Output< T >::getChannel ( const std::string &  name) const
inlineoverridevirtual

For a single-value output, name must be empty or must be the output's name.

Implements OpenSim::AbstractOutput.

References OpenSim::AbstractOutput::getName(), and OpenSim::AbstractOutput::isListOutput().

Referenced by OpenSim::Input< T >::finalizeConnection().

◆ getChannels()

template<class T>
const ChannelMap& OpenSim::Output< T >::getChannels ( ) const
inline

Use this to iterate through this Output's channels (even for single-value Channels).

for (const auto& chan : getChannels()) {
std::cout << chan.second->getName() << std::endl;
}

◆ getTypeName()

template<class T>
std::string OpenSim::Output< T >::getTypeName ( ) const
inlineoverridevirtual

The name of the value type (e.g., double) produced by this output.

Implements OpenSim::AbstractOutput.

References OpenSim::Object_GetClassName< T >::name().

Referenced by OpenSim::Output< T >::compatibleAssign().

◆ getValue()

template<class T>
const T& OpenSim::Output< T >::getValue ( const SimTK::State &  state) const
inline

Return the Value of this output if the state is appropriately realized
to a stage at or beyond the dependsOnStage, otherwise expect an Exception.

References OpenSim::AbstractOutput::_owner, OpenSim::AbstractOutput::getDependsOnStage(), and OpenSim::AbstractOutput::isListOutput().

Referenced by OpenSim::Output< T >::getValueAsString().

◆ getValueAsString()

template<class T>
std::string OpenSim::Output< T >::getValueAsString ( const SimTK::State &  state) const
inlineoverridevirtual

◆ isCompatible()

template<class T>
bool OpenSim::Output< T >::isCompatible ( const AbstractOutput< T > &  o) const
inlineoverridevirtual

◆ operator=() [1/2]

template<class T>
Output& OpenSim::Output< T >::operator= ( const Output< T > &  source)
inline

Custom copy assignment operator is for setting the Channel's pointer back to this Output.

References OpenSim::AbstractOutput::operator=().

◆ operator=() [2/2]

template<class T>
Output& OpenSim::Output< T >::operator= ( Output< T > &&  )
delete

◆ safeDownCast()

template<class T>
static Output<T>* OpenSim::Output< T >::safeDownCast ( AbstractOutput< T > *  parent)
inlinestatic

For use in python/java/MATLAB bindings.

◆ SimTK_DOWNCAST()

template<class T>
OpenSim::Output< T >::SimTK_DOWNCAST ( Output< T >  ,
AbstractOutput< T >   
)

Friends And Related Function Documentation

◆ OpenSim_DECLARE_LIST_OUTPUT

template<class T>
#define OpenSim_DECLARE_LIST_OUTPUT (   oname,
  T,
  func,
  ostage 
)
related

Create a list output for a member function of this component.

A list output can have multiple values, or channels. The component must publish what channels its outputs have by calling AbstractOutput::addChannel() within
Component::extendFinalizeFromProperties(). The provided member function must take the name of the channel whose value is requested.

class MyComponent : public Component {
public:
double getData(const SimTK::State& s, const std::string& requestedChannel) const;
OpenSim_DECLARE_LIST_OUTPUT(data, double, getData, SimTK::Stage::Dynamics);
...
protected:
void extendFinalizeFromProperties() {
Super::extendFinalizeFromProperties();
for (const auto& name : getChannelsToAdd()) {
updOutput("data").addChannel(name);
}
}
};

In this example, getChannelsToAdd() is a placeholder for whatever way you determine your class' available channels. For example, TableSource_ uses the columns of its DataTable_.

◆ OpenSim_DECLARE_OUTPUT

template<class T>
#define OpenSim_DECLARE_OUTPUT (   oname,
  T,
  func,
  ostage 
)
related

Create an output for a member function of this component.

The following must be true about componentMemberFunction, the function that returns the output:

  1. It is a member function of your component.
  2. The member function is const.
  3. It takes only one argument, which is const SimTK::State&.
  4. The function returns the computed quantity by value (e.g., double computeQuantity(const SimTK::State&) const).

You must also provide the stage on which the output depends.

Here's an example for using this macro:

class MyComponent : public Component {
public:
OpenSim_DECLARE_OUTPUT(force, double, getForce, SimTK::Stage::Dynamics);
...
};
Warning
The fourth requirement above can be lifted if the function returns a quantity that is stored in the provided SimTK::State (as a state variable, cache variable, etc.); in this case, your function's return type should be const T& (e.g, const double&). If your function returns a const T& but the quantity is NOT stored in the provided SimTK::State, the output value will be invalid!
See also
Component::constructOutput()

◆ OpenSim_DECLARE_OUTPUT_FOR_STATE_VARIABLE

template<class T>
#define OpenSim_DECLARE_OUTPUT_FOR_STATE_VARIABLE (   oname)
related

Create an Output for a StateVariable in this component.

The provided name is both the name of the output and of the state variable.

While this macro is a convenient way to construct an Output for a StateVariable, it is inefficient because it uses a string lookup at runtime. To create a more efficient Output, create a member variable that returns the state variable directly (see Coordinate::getValue() or Muscle::getActivation()) and then use the OpenSim_DECLARE_OUTPUT macro.

class MyComponent : public Component {
public:
...
};
See also
Component::constructOutputForStateVariable()

The documentation for this class was generated from the following file: