OpenSim::Storage Class Reference

#include <Storage.h>

Inheritance diagram for OpenSim::Storage:
OpenSim::StorageInterface OpenSim::Object

List of all members.

Public Member Functions

 Storage (int aCapacity=Storage_DEFAULT_CAPACITY, const std::string &aName="UNKNOWN")
 Storage (const std::string &aFileName, bool readHeadersOnly=false) SWIG_DECLARE_EXCEPTION
 Storage (const Storage &aStorage, bool aCopyData=true)
 Copy constructor.
 Storage (const Storage &aStorage, int aStateIndex, int aN, const char *aDelimiter="\t")
 Construct a copy of a specified storage taking only a subset of the states.
virtual Objectcopy () const
 Copy this object.
virtual ~Storage ()
 Destructor.
Storageoperator= (const Storage &aStorage)
 Assignment operator to copy contents of an existing storage.
const std::string & getName () const
 Get the name of this object.
const std::string & getDescription () const
 Get the description of this object.
void setName (const std::string &aName)
void setDescription (const std::string &aDescription)
const int & getFileVersion () const
virtual int getSize () const
int getSmallestNumberOfStates () const
 Get the smallest number of states.
virtual StateVectorgetStateVector (int aTimeIndex) const
 Get the StateVector at a spcified time index.
virtual StateVectorgetLastStateVector () const
 Get the last states stored.
virtual double getFirstTime () const
 Get the time of the first stored states.
virtual double getLastTime () const
 Get the time of the last states.
double getMinTimeStep () const
 Get the smallest time step.
bool getTime (int aTimeIndex, double &rTime, int aStateIndex=-1) const
 Get the time at a specified time index for a specified state.
virtual int getTimeColumn (double *&rTimes, int aStateIndex=-1) const
 Get the times for a specified state.
virtual int getTimeColumn (Array< double > &rTimes, int aStateIndex=-1) const
virtual void getTimeColumnWithStartTime (Array< double > &rTimes, double startTime=0.0) const
 Get the time column starting at aTime.
void addKeyValuePair (const std::string &aKey, const std::string &aValue)
 Processing of special reserved words used by SIMM and corresponding values The keys and their corresponding values are maintained in _keyValueMap.
void getValueForKey (const std::string &aKey, std::string &rValue) const
bool hasKey (const std::string &aKey) const
const bool isInDegrees () const
void setInDegrees (const bool isInDegrees)
int getData (int aTimeIndex, int aStateIndex, double &rValue) const
 Get a data value of a specified state at a specified time index.
int getData (int aTimeIndex, int aStateIndex, int aN, double **rData) const
 Helper function for getData.
int getData (int aTimeIndex, int aStateIndex, int aN, double *rData) const
 At a specified time index, get a number of state values starting at a specified state.
int getData (int aTimeIndex, int aN, double **rData) const
 At a specified time index, get a number of state values starting at a specified state.
int getData (int aTimeIndex, int aN, double *rData) const
 Get the first aN states at a specified time index.
int getDataAtTime (double aTime, int aN, double **rData) const
 Get the first aN states at a specified time.
int getDataAtTime (double aTime, int aN, double *rData) const
 Get the first aN states at a specified time.
int getDataAtTime (double aTime, int aN, Array< double > &rData) const
int getDataColumn (int aStateIndex, double *&rData) const
 Get the data corresponding to a specified state.
int getDataColumn (int aStateIndex, Array< double > &rData) const
void setDataColumn (int aStateIndex, const Array< double > &aData)
 Set the data corresponding to a specified state.
int getDataColumn (const std::string &columnName, double *&rData) const
 Get the data corresponding to a state specified by name.
void getDataColumn (const std::string &columnName, Array< double > &data, double startTime=0.0)
 Get the data column starting at aTime.
void getDataForIdentifier (const std::string &identifier, Array< Array< double > > &rData, double startTime=0.0) const
 A data block, like a vector for a force, point, etc.
OpenSim::Array< int > getColumnIndicesForIdentifier (const std::string &identifier) const
 Get indices of columns corresponding to identifier, empty array if identifier is not found in labels.
void setStepInterval (int aStepInterval)
 Set the step interval.
int getStepInterval () const
 Get the step interval.
void setCapacityIncrement (int aIncrement)
 Set the capacity increment of this storage object.
int getCapacityIncrement () const
 Get the capacity increment of this storage object.
void setWriteSIMMHeader (bool aTrueFalse)
 Set the whether or not to write a header appropriate for a SIMM motion file.
bool getWriteSIMMHeader () const
 Get the whether or not to write a header appropriate for a SIMM motion file.
void setHeaderToken (const std::string &aToken)
 Set the header token.
const std::string & getHeaderToken () const
 Get the header token of this storage.
const int getStateIndex (const std::string &aColumnName, int startIndex=0) const
 Get the column index corresponding to specified column name.
void setColumnLabels (const Array< std::string > &aColumnLabels)
 Set column labels array.
const Array< std::string > & getColumnLabels () const
 Get column labels array.
int reset (int aIndex=0)
 Reset the storage to start storing at a specified index.
int reset (double aTime)
 Reset the storage to start storing after a specified time.
void purge ()
void crop (const double newStartTime, const double newFinalTime)
 Crop the storage object to the specified start and final time.
virtual int append (const StateVector &aVec, bool aCheckForDuplicateTime=true)
 Append an StateVector.
virtual int append (const Array< StateVector > &aArray)
 Append copies of all state vectors in an Storage object.
virtual int append (double aT, int aN, const double *aY, bool aCheckForDuplicateTime=true)
 Append an array of data that occured at a specified time.
virtual int append (double aT, const SimTK::Vector &aY, bool aCheckForDuplicateTime=true)
 Append an array of data that occured at a specified time.
virtual int append (double aT, const SimTK::Vec3 &aY, bool aCheckForDuplicateTime=true)
virtual int store (int aStep, double aT, int aN, const double *aY)
 Store a simulation vector.
void shiftTime (double aValue)
 Shift the times of all state vectors.
void scaleTime (double aValue)
 Scale the times of all state vectors.
void add (double aValue)
 Add a value to all state vectors in this storage instance.
void add (int aN, double aY[])
 Add an array to all state vectors in this storage instance.
void add (int aN, double aValue)
 Add a value to all entries in one column of the storage.
void add (StateVector *aStateVector)
 Add a state vector to the all state vectors in this storage instance.
void add (Storage *aStorage)
 Add a storage instance to this storage instance.
void subtract (double aValue)
 Subtract a value from all state vectors in this storage instance.
void subtract (int aN, double aY[])
 Subtract an array from all state vectors in this storage instance.
void subtract (StateVector *aStateVector)
 Subtract a state vector from all state vectors in this storage instance.
void subtract (Storage *aStorage)
 Subtract a storage instance to this storage instance.
void multiply (double aValue)
 Multiply all state vectors in this storage instance by a value.
void multiplyColumn (int aIndex, double aValue)
 Multiply entries at column aIndex by a value.
void multiply (int aN, double aY[])
 Multiply all state vectors in this storage instance by an array.
void multiply (StateVector *aStateVector)
 Multiply all state vectors in this storage instance by a state vector.
void multiply (Storage *aStorage)
 Multipy this storage instance by a storage instance.
void divide (double aValue)
 Divide all state vectors in this storage instance by a value.
void divide (int aN, double aY[])
 Divide all state vectors in this storage instance by an array.
void divide (StateVector *aStateVector)
 Divide all state vectors in this storage instance by a state vector.
void divide (Storage *aStorage)
 Divide this storage instance by a storage instance.
Storageintegrate (int aI1=-2, int aI2=-1) const
 Integrate the state vectors between aI1 and aI2.
Storageintegrate (double aT1, double aT2) const
 Integrate the state vectors between times aTI and aTF.
int computeArea (int aN, double *aArea) const
 Compute the area of the first aN states stored for all state vectors stored in this storage instance.
int computeArea (double aTI, double aTF, int aN, double *aArea) const
 Compute the area of the first aN states stored between the times aTI and aTF.
int computeAverage (int aN, double *aAve) const
 Compute the average value of the first aN states stored for all state vectors stored in this storage instance.
int computeAverage (double aTI, double aTF, int aN, double *aAve) const
 Compute the average value of the first aN states stored between the times aTI and aTF.
void pad (int aPadSize)
 Pad each of the columns in a statevector by a specified amount.
void smoothSpline (int aOrder, double aCutoffFrequency)
 Smooth spline each of the columns in the storage.
void lowpassIIR (double aCutoffFequency)
 Lowpass filter each of the columns in the storage.
void lowpassFIR (int aOrder, double aCutoffFequency)
 Lowpass filter each of the columns in the storage.
void addToRdStorage (Storage &rStorage, double aStartTime, double aEndTime)
virtual int findIndex (double aT) const
 Find the index of the storage element that occured immediately before or at a specified time ( getTime(index) <= aT ).
virtual int findIndex (int aI, double aT) const
 Find the index of the storage element that occured immediately before or at time aT ( aT <= getTime(index) ).
void findFrameRange (double aStartTime, double aEndTime, int &oStartFrame, int &oEndFrame) const
 Find the range of frames that is between start time and end time (inclusive).
double resample (double aDT, int aDegree)
 Resample Storage columns to specified rate.
double resampleLinear (double aDT)
 Resample using linear interpolation.
double compareColumn (Storage &aOtherStorage, const std::string &aColumnName, double startTime, double endTime=-1.0)
 Compare column named "aColumnName" in two storage objects If endTime is not specified the comparison goes to the end of the file.
double compareColumnRMS (Storage &aOtherStorage, const std::string &aColumnName, double startTime=SimTK::NaN, double endTime=SimTK::NaN)
 Compare column named "aColumnName" in two storage objects If endTime is not specified the comparison goes to the end of the file.
void compareWithStandard (Storage &standard, Array< std::string > &columnsUsed, Array< double > &comparisons)
bool makeStorageLabelsUnique ()
 Force column labels for a Storage object to become unique.
void print () const
 Print the contents of this storage instance to standard output.
bool print (const std::string &aFileName, const std::string &aMode="w", const std::string &aComment="") const
int print (const std::string &aFileName, double aDT, const std::string &aMode="w") const
void setOutputFileName (const std::string &aFileName)
 Set name of output file to be written into.
void interpolateAt (const Array< double > &targetTimes)
 interpolateAt passed in list of time values.

Static Public Member Functions

static const int & getLatestVersion ()
static void printResult (const Storage *aStorage, const std::string &aName, const std::string &aDir, double aDT, const std::string &aExtension)

Static Public Attributes

static const char * DEFAULT_HEADER_TOKEN = "endheader"
 Default token used to mark the end of the storage description in a file.
static const char * DEFAULT_HEADER_SEPARATOR = " \t\r\n"
static const int MAX_RESAMPLE_SIZE = 100000

Protected Attributes

Array< StateVector_storage
 Array of StateVectors.
std::string _headerToken
 Token used to mark the end of the description in a file.
Array< std::string > _columnLabels
 Column labels.
int _stepInterval
 Step interval at which states in a simulation are stored.
int _lastI
 Last index at which a search was started.
bool _writeSIMMHeader
 Flag for whether or not to insert a SIMM style header.
Units _units
 Units in which the data is represented.
bool _inDegrees
 Are angles, if any, specified in radians or degrees?
MapKeysToValues _keyValueMap
 Map between keys in file header and values.
std::string _fileName
 Cache for fileName and file pointer when the file is opened so we can flush and write intermediate files if needed.
FILE * _fp
std::string _name
 Name and Description.
std::string _description
 A description of the object.
int _fileVersion
 Storage file version as written to the file.

Static Protected Attributes

static std::string simmReservedKeys []
static const int LatestVersion = 1

Constructor & Destructor Documentation

OpenSim::Storage::Storage ( int  aCapacity = Storage_DEFAULT_CAPACITY,
const std::string &  aName = "UNKNOWN" 
) [explicit]
OpenSim::Storage::Storage ( const std::string &  aFileName,
bool  readHeadersOnly = false 
)
Storage::Storage ( const Storage aStorage,
bool  aCopyData = true 
)

Copy constructor.

Storage::Storage ( const Storage aStorage,
int  aStateIndex,
int  aN,
const char *  aDelimiter = "\t" 
)

Construct a copy of a specified storage taking only a subset of the states.

Parameters:
aStorage Storage to be copied.
aStateIndex Index of the state (column) at which to start the copy.
aN Number of states to copy.
aDelimiter Delimiter used to separate state labels (i.e., column labels). The delimiter is assumed to be a tab by default.
Storage::~Storage (  )  [virtual]

Destructor.

The stored StateVectors are deleted during destruction.


Member Function Documentation

void Storage::add ( Storage aStorage  ) 

Add a storage instance to this storage instance.

Linear interpolation or extrapolation is used to get the values of the states that correspond in time to the states held in this storage instance.

Parameters:
aStorage Storage to add to this storage. s
void Storage::add ( StateVector aStateVector  ) 

Add a state vector to the all state vectors in this storage instance.

Parameters:
aStateVector State vector to add to the state vectors.
See also:
StateVector::add(int,double[])
void Storage::add ( int  aN,
double  aValue 
)

Add a value to all entries in one column of the storage.

Parameters:
aN Index of the column that the value is to be added to.
aValue Value to add to the column.
See also:
StateVector::add(int,double)
void Storage::add ( int  aN,
double  aY[] 
)

Add an array to all state vectors in this storage instance.

Only the first aN states of each state vector are altered.

Parameters:
aN Length of aY
aY Array of values to add to the state vectors.
See also:
StateVector::add(int,double[])
void Storage::add ( double  aValue  ) 

Add a value to all state vectors in this storage instance.

Parameters:
aValue Value to add to the state vectors.
See also:
StateVector::add(double)
void Storage::addKeyValuePair ( const std::string &  aKey,
const std::string &  aValue 
)

Processing of special reserved words used by SIMM and corresponding values The keys and their corresponding values are maintained in _keyValueMap.

void Storage::addToRdStorage ( Storage rStorage,
double  aStartTime,
double  aEndTime 
)
virtual int OpenSim::Storage::append ( double  aT,
const SimTK::Vec3 &  aY,
bool  aCheckForDuplicateTime = true 
) [inline, virtual]

Reimplemented from OpenSim::StorageInterface.

int Storage::append ( double  aT,
const SimTK::Vector &  aY,
bool  aCheckForDuplicateTime = true 
) [virtual]

Append an array of data that occured at a specified time.

Parameters:
aT Time stamp of the data.
aY Vector.
Returns:
Index of the first empty storage element.

Implements OpenSim::StorageInterface.

int Storage::append ( double  aT,
int  aN,
const double *  aY,
bool  aCheckForDuplicateTime = true 
) [virtual]

Append an array of data that occured at a specified time.

Parameters:
aT Time stamp of the data.
aN Length of the array.
aY Array.
Returns:
Index of the first empty storage element.

Implements OpenSim::StorageInterface.

int Storage::append ( const Array< StateVector > &  aStorage  )  [virtual]

Append copies of all state vectors in an Storage object.

This method overrides Array::append(Array). Currently, there is no difference. The override is done for completeness.

Parameters:
aStorage Storage to be appended.
Returns:
The index of the first empty storage element.

Implements OpenSim::StorageInterface.

int Storage::append ( const StateVector aStateVector,
bool  aCheckForDuplicateTime = true 
) [virtual]

Append an StateVector.

Parameters:
aStateVector Statevector to be appended.
Returns:
Size of the storage after the append.

Implements OpenSim::StorageInterface.

double Storage::compareColumn ( Storage aOtherStorage,
const std::string &  aColumnName,
double  startTime,
double  endTime = -1.0 
)

Compare column named "aColumnName" in two storage objects If endTime is not specified the comparison goes to the end of the file.

Returns:
the difference or SimTK::Infinity if times do not match up.

NOTE: This assumes same time sampling between both Storages.

double Storage::compareColumnRMS ( Storage aOtherStorage,
const std::string &  aColumnName,
double  startTime = SimTK::NaN,
double  endTime = SimTK::NaN 
)

Compare column named "aColumnName" in two storage objects If endTime is not specified the comparison goes to the end of the file.

Returns:
the root mean square, using a spline to calculate values where the times do not match up.
void OpenSim::Storage::compareWithStandard ( Storage standard,
Array< std::string > &  columnsUsed,
Array< double > &  comparisons 
)
int Storage::computeArea ( double  aTI,
double  aTF,
int  aN,
double *  aArea 
) const

Compute the area of the first aN states stored between the times aTI and aTF.

It is assumed that there is enough memory at aArea to hold aN states. If aN exceeds the number of states held in storage, aN is disregarded.

The number of valid states in aArea is returned.

Note that if aTI and aTF do not fall exactly on the time stamp of a stored state, the states are linearly interpolated to provide an estimate of the state at aTI or at aTF.

int Storage::computeArea ( int  aN,
double *  aArea 
) const

Compute the area of the first aN states stored for all state vectors stored in this storage instance.

It is assumed that there is enough memory at aArea to hold aN states. If aN exceeds the number of states held in storage, aN is disregarded.

The number of valid states in aArea is returned.

int Storage::computeAverage ( double  aTI,
double  aTF,
int  aN,
double *  aAve 
) const

Compute the average value of the first aN states stored between the times aTI and aTF.

This method uses computeArea() to compute the area (integral) of each state on the interval [aTI,aTF] and then simply divides by the (aTF-aTI).

It is assumed that there is enough memory at aAve to hold aN states. If aN exceeds the number of states held in storage, aN is disregarded.

The number of valid states in aAve is returned.

Note that if aTI and aTF do not fall exactly on the time stamp of a stored state, the states are linearly interpolated to provide an estimate of the state at aTI or at aTF.

int Storage::computeAverage ( int  aN,
double *  aAve 
) const

Compute the average value of the first aN states stored for all state vectors stored in this storage instance.

This method uses computeArea() to compute the area (integral) and then simply divides by the the time interval (tf-ti).

It is assumed that there is enough memory at aAve to hold aN states. If aN exceeds the number of states held in storage, aN is disregarded.

The number of valid states in aAve is returned.

Object * Storage::copy (  )  const [virtual]

Copy this object.

Returns:
Pointer to a copy of this object.

Implements OpenSim::StorageInterface.

void Storage::crop ( const double  newStartTime,
const double  newFinalTime 
)

Crop the storage object to the specified start and final time.

void Storage::divide ( Storage aStorage  ) 

Divide this storage instance by a storage instance.

Linear interpolation or extrapolation is used to get the values of the states that correspond in time to the states held in this storage instance.

Parameters:
aStorage Storage instance by which to divide. s
void Storage::divide ( StateVector aStateVector  ) 

Divide all state vectors in this storage instance by a state vector.

Parameters:
aStateVector State vector by which to divide the state vectors.
void Storage::divide ( int  aN,
double  aY[] 
)

Divide all state vectors in this storage instance by an array.

Only the first aN states of each state vector are altered.

Parameters:
aN Length of aY
aY Array of values the states are to be divided by.
void Storage::divide ( double  aValue  ) 

Divide all state vectors in this storage instance by a value.

Parameters:
aValue Value by which to divide the state vectors.
void Storage::findFrameRange ( double  aStartTime,
double  aEndTime,
int &  oStartFrame,
int &  oEndFrame 
) const

Find the range of frames that is between start time and end time (inclusive).

Return the indices of the bounding frames.

int Storage::findIndex ( int  aI,
double  aT 
) const [virtual]

Find the index of the storage element that occured immediately before or at time aT ( aT <= getTime(index) ).

This method can be much more efficient than findIndex(aT) if a good guess is made for aI. If aI corresponds to a state which occured later than aT, an exhaustive search is performed by calling findIndex(aT).

Parameters:
aI Index at which to start searching.
aT Time.
Returns:
Index preceding or at time aT. If aT is less than the earliest time, 0 is returned.

Implements OpenSim::StorageInterface.

int Storage::findIndex ( double  aT  )  const [virtual]

Find the index of the storage element that occured immediately before or at a specified time ( getTime(index) <= aT ).

This method is not very efficient because it always starts its search with the first stored state.

Parameters:
aT Time.
Returns:
Index preceding or at time aT. If aT is less than the earliest time, 0 is returned.

Implements OpenSim::StorageInterface.

int Storage::getCapacityIncrement (  )  const

Get the capacity increment of this storage object.

Returns:
Capacity increment of this storage. For details on what the capacity increment does see Array::setCapacityIncrement().
OpenSim::Array< int > Storage::getColumnIndicesForIdentifier ( const std::string &  identifier  )  const

Get indices of columns corresponding to identifier, empty array if identifier is not found in labels.

Get the list of indices of columns corresponding to passed in identifier Normally you provide a prefix and all column numbers that share this suffix in their header are passed back.

const Array< string > & Storage::getColumnLabels (  )  const

Get column labels array.

Returns:
Character string of column labels.
int Storage::getData ( int  aTimeIndex,
int  aN,
double *  rData 
) const

Get the first aN states at a specified time index.

Parameters:
aTimeIndex Time index at which to get the states.
aN Number of states to get.
rData Array where the returned data will be set. The size of rData is assumed to be at least aN.
Returns:
Number of states that were set.
int Storage::getData ( int  aTimeIndex,
int  aN,
double **  rData 
) const

At a specified time index, get a number of state values starting at a specified state.

The method simply gets part of a row of data from adjacent columns in the storage object.

Parameters:
aTimeIndex Time index at which to get the states.
aStateIndex Index of the state (column) at which to start getting the data.
aN Number of states to get.
rData Pointer to an array where the returned data will be set. The size of *rData is assumed to be at least aN. If rData comes in as NULL, memory is allocated.
Returns:
Number of states.
int Storage::getData ( int  aTimeIndex,
int  aStateIndex,
int  aN,
double *  rData 
) const

At a specified time index, get a number of state values starting at a specified state.

The method simply gets part of a row of data from adjacent columns in the storage object.

Parameters:
aTimeIndex Index that identifies the time (row) at which to get the data value: 0 <= aTimeIndex < _storage.getSize().
aStateIndex Index of the state (column) at which to start getting the data.
aN Number of states (columns) to get.
rData Data values. rData should be able to hold at least N values.
Returns:
Number of states that were gotten.
int Storage::getData ( int  aTimeIndex,
int  aStateIndex,
int  aN,
double **  rData 
) const

Helper function for getData.

int Storage::getData ( int  aTimeIndex,
int  aStateIndex,
double &  rValue 
) const

Get a data value of a specified state at a specified time index.

Parameters:
aTimeIndex Index that identifies the time (row) at which to get the data value: 0 <= aTimeIndex < _storage.getSize().
aStateIndex Index of the state (column) for which to get the value.
rValue Value of the state.
Returns:
1 on success, 0 on failure.
int Storage::getDataAtTime ( double  aTime,
int  aN,
Array< double > &  rData 
) const [virtual]
int Storage::getDataAtTime ( double  aT,
int  aN,
double *  rData 
) const

Get the first aN states at a specified time.

The values of the states are determined by linear interpolation.

Parameters:
aT Time at which to get the states.
aN Number of states to get.
rData Array where the returned data will be set. The size of rData is assumed to be at least aN.
Returns:
Number of states that were set.
int Storage::getDataAtTime ( double  aT,
int  aN,
double **  rData 
) const

Get the first aN states at a specified time.

The values of the states are determined by linear interpolation.

Parameters:
aT Time at which to get the states.
aN Number of states to get.
rData Pointer to an array where the returned data will be set. The size of *rData is assumed to be at least aN. If rData comes in as NULL, memory is allocated.
Returns:
Number of states that were set.
void Storage::getDataColumn ( const std::string &  columnName,
Array< double > &  rData,
double  aStartTime = 0.0 
) [virtual]

Get the data column starting at aTime.

Return it in rData rData is preallocated by the caller.

Implements OpenSim::StorageInterface.

int Storage::getDataColumn ( const std::string &  aColumnName,
double *&  rData 
) const

Get the data corresponding to a state specified by name.

This call is equivalent to getting a column of data from the storage file.

Parameters:
aColumnName name in header of column for which to get the data.
rData Array containing the desired data. If rData is sent in as NULL, memory is allocated. However, if rData is sent in as a non-NULL, it is assumed that rData points to a memory block that is large enough to hold getSize() doubles.
Returns:
Number of values set in rData. The number of values set may be less than getSize() because not all stored state vectors are required to have the same number of states.
int Storage::getDataColumn ( int  aStateIndex,
Array< double > &  rData 
) const
int Storage::getDataColumn ( int  aStateIndex,
double *&  rData 
) const

Get the data corresponding to a specified state.

This call is equivalent to getting a column of data from the storage file.

Parameters:
aStateIndex Index of the state (column) for which to get the data.
rData Array containing the desired data. If rData is sent in as NULL, memory is allocated. However, if rData is sent in as a non-NULL, it is assumed that rData points to a memory block that is large enough to hold getSize() doubles.
Returns:
Number of values set in rData. The number of values set may be less than getSize() because not all stored state vectors are required to have the same number of states.
void Storage::getDataForIdentifier ( const std::string &  identifier,
Array< Array< double > > &  rData,
double  startTime = 0.0 
) const

A data block, like a vector for a force, point, etc.

It is desirable to access the block as a single entity provided an identifier that is common to all components (such as prefix in the column label).

.. will span multiple "columns" It is desirable to access the block as a single entity provided an identifier that is common to all components (such as prefix in the column label).

Parameters:
identifier string identifying a single block of data
rData Array<Array<double>> of data belonging to the identifier
identifier string identifying a single block of data
rData Array<Array<double>> of data belonging to the identifier
const std::string& OpenSim::Storage::getDescription (  )  const [inline]

Get the description of this object.

Reimplemented from OpenSim::Object.

const int& OpenSim::Storage::getFileVersion (  )  const [inline]
double Storage::getFirstTime (  )  const [virtual]

Get the time of the first stored states.

Returns:
Time of the first stored states. If there is no stored state, the constant SimTK::NaN (not a number) is returned.

Implements OpenSim::StorageInterface.

const string & Storage::getHeaderToken (  )  const

Get the header token of this storage.

Returns:
Header token.
See also:
setHeaderToken()
StateVector * Storage::getLastStateVector (  )  const [virtual]

Get the last states stored.

Returns:
Statevector. If no state vector is stored, NULL is returned.

Implements OpenSim::StorageInterface.

double Storage::getLastTime (  )  const [virtual]

Get the time of the last states.

Returns:
Time of the first stored states. If there is no stored state, the constant SimTK::NaN (not a number) is returned.

Implements OpenSim::StorageInterface.

static const int& OpenSim::Storage::getLatestVersion (  )  [inline, static]
double Storage::getMinTimeStep (  )  const

Get the smallest time step.

Returns:
Smallest time step. If there are less than 2 state vectors, SimTK::Infinity is returned.
const std::string& OpenSim::Storage::getName (  )  const [inline]

Get the name of this object.

Reimplemented from OpenSim::Object.

virtual int OpenSim::Storage::getSize (  )  const [inline, virtual]
int Storage::getSmallestNumberOfStates (  )  const

Get the smallest number of states.

Ordinarily, the number of states is the same in each state vector; however, this is not required.

Returns:
Smallest number of states.
const int Storage::getStateIndex ( const std::string &  aColumnName,
int  startIndex = 0 
) const

Get the column index corresponding to specified column name.

Returns:
State index of column or -1. Note that the returned index is equivalent to the state index. For example, for the first column in a storage (usually time) -1 would be returned. For the second colunn in a storage (the first state) 0 would be returned.

added a default Parameter for startIndex. -Ayman

StateVector * Storage::getStateVector ( int  aTimeIndex  )  const [virtual]

Get the StateVector at a spcified time index.

Parameters:
aTimeIndex Time index at which to get the state vector: 0 <= aTimeIndex < _storage.getSize().
Returns:
Statevector. If no valid statevector exists at aTimeIndex, NULL is returned.

Implements OpenSim::StorageInterface.

int Storage::getStepInterval (  )  const

Get the step interval.

bool Storage::getTime ( int  aTimeIndex,
double &  rTime,
int  aStateIndex = -1 
) const

Get the time at a specified time index for a specified state.

Parameters:
aTimeIndex Time index (row) for which to get the time.
rTime Time value.
aStateIndex Index of the state for which to get the time. By default, aStateIndex has a value of -1, which means disregard whether or not there is a valid state- just get the time at aTimeIndex. If aStateIndex is non-negative, the time is returned only if there is a valid state at aStateIndex.
Returns:
true when the time was set, false when there was no valid state.
int Storage::getTimeColumn ( Array< double > &  rTimes,
int  aStateIndex = -1 
) const [virtual]
int Storage::getTimeColumn ( double *&  rTimes,
int  aStateIndex = -1 
) const [virtual]

Get the times for a specified state.

Parameters:
rTime Array where times are set. If rTime is sent in as NULL, memory is allocated. If rTime is setn in as non-NULL, it is assumed that enough memory has been allocated at rTime to hold _storage.getSize() doubles.
aStateIndex Index of the state for which to get the times. By default, aStateIndex has a value of -1, which means disregard whether or not there is a valid state- just get the times. If aStateIndex is non-negative, the time is set only if there is a valid state at aStateIndex.
Returns:
Number of times set. This can be less than _storage.getSize() if a state does not exist for all or a subset of the stored statevectors.
void Storage::getTimeColumnWithStartTime ( Array< double > &  rTimes,
double  aStartTime = 0.0 
) const [virtual]

Get the time column starting at aTime.

Return it in rTimes rTimes is preallocated by the caller.

Implements OpenSim::StorageInterface.

void Storage::getValueForKey ( const std::string &  aKey,
std::string &  rValue 
) const
bool Storage::getWriteSIMMHeader (  )  const

Get the whether or not to write a header appropriate for a SIMM motion file.

Parameters:
aTrueFalse Whether (true) or not (false) to write a SIMM header.
bool Storage::hasKey ( const std::string &  aKey  )  const
Storage * Storage::integrate ( double  aTI,
double  aTF 
) const

Integrate the state vectors between times aTI and aTF.

The integration results are returned in an Storage instance that is a copy of this instance except the name has been appended with "_integrated" and, of course, the state vectors have been integrated. The caller is responsible for deleting the returned storage instance.

Note that if aTI and aTF do not fall exactly on the time stamp of a stored state, the states are linearly interpolated or extrapolated to provide an estimate of the state at aTI or at aTF.

Parameters:
aTI Time at which to start the integration.
aTF Time at which to stop the integration.
Returns:
Storage instance of integrated results. NULL is returned if an error is encountered.
Storage * Storage::integrate ( int  aI1 = -2,
int  aI2 = -1 
) const

Integrate the state vectors between aI1 and aI2.

The integration results are returned in an Storage instance that is a copy of this instance except the name has been appended with "_integrated" and, of course, the state vectors have been integrated. The caller is responsible for deleting the returned storage instance.

If aI1 is negative, integrations starts at the first StateVector held by this Storage instance. If aI2 is negative, integration starts at the last StateVector held by this Storage instance.

Note that aI1 and aI2 have negative default values, so that this method may be called without arguments to integrate all StateVectors held by this Storage instance.

Parameters:
aI1 Index of state vector at which to start integration.
aI2 Index of state vector at which to stop integration.
Returns:
Storage instance of integrated results. NULL is returned if an error is encountered.
void Storage::interpolateAt ( const Array< double > &  targetTimes  ) 

interpolateAt passed in list of time values.

Tries to check if there is a data row at the specified times to avoid introducing duplicates.

const bool OpenSim::Storage::isInDegrees (  )  const [inline]
void Storage::lowpassFIR ( int  aOrder,
double  aCutoffFrequency 
)

Lowpass filter each of the columns in the storage.

Note that as a part of this operation, the storage is resampled so that the statevectors are at equal spacing.

Parameters:
aOrder Order of the FIR filter.
aCutoffFrequency Cutoff frequency.
void Storage::lowpassIIR ( double  aCutoffFrequency  ) 

Lowpass filter each of the columns in the storage.

Note that as a part of this operation, the storage is resampled so that the statevectors are at equal spacing.

Parameters:
aOrder Order of the FIR filter.
aCutoffFrequency Cutoff frequency.
bool Storage::makeStorageLabelsUnique (  ) 

Force column labels for a Storage object to become unique.

This is done by prepending the string (n_) as needed where n=1, 2, ...

Returns:
true if labels were changed false otherwise.
void Storage::multiply ( Storage aStorage  ) 

Multipy this storage instance by a storage instance.

Linear interpolation or extrapolation is used to get the values of the states that correspond in time to the states held in this storage instance.

Parameters:
aStorage Storage instance by which to multiply. s
void Storage::multiply ( StateVector aStateVector  ) 

Multiply all state vectors in this storage instance by a state vector.

Parameters:
aStateVector State vector by which to multiply the state vectors.
See also:
StateVector::multiply(StateVector)
void Storage::multiply ( int  aN,
double  aY[] 
)

Multiply all state vectors in this storage instance by an array.

Only the first aN states of each state vector are altered.

Parameters:
aN Length of aY
aY Array of values the states are to be multiplied by.
See also:
StateVector::multiply(int,double[])
void Storage::multiply ( double  aValue  ) 

Multiply all state vectors in this storage instance by a value.

Parameters:
aValue Value by which to mutiply the state vectors.
See also:
StateVector::multiply(double)
void Storage::multiplyColumn ( int  aIndex,
double  aValue 
)

Multiply entries at column aIndex by a value.

Parameters:
aIndex is the index of the column to multiply
aValue Value by which to mutiply the column.
Storage & Storage::operator= ( const Storage aStorage  ) 

Assignment operator to copy contents of an existing storage.

Assignment operator.

Returns:
Reference to this object.

Reimplemented from OpenSim::StorageInterface.

void Storage::pad ( int  aPadSize  ) 

Pad each of the columns in a statevector by a specified amount.

Data is both prepended and appended by reflecting and negating.

Parameters:
aPadSize Number of data points to prepend and append.
int OpenSim::Storage::print ( const std::string &  aFileName,
double  aDT,
const std::string &  aMode = "w" 
) const
bool OpenSim::Storage::print ( const std::string &  aFileName,
const std::string &  aMode = "w",
const std::string &  aComment = "" 
) const
void Storage::print (  )  const

Print the contents of this storage instance to standard output.

void Storage::printResult ( const Storage aStorage,
const std::string &  aName,
const std::string &  aDir,
double  aDT,
const std::string &  aExtension 
) [static]
void OpenSim::Storage::purge (  )  [inline]
double Storage::resample ( double  aDT,
int  aDegree 
)

Resample Storage columns to specified rate.

This's done by fitting splines to Storage columns and resampling

Parameters:
aDT Time interval between adjacent statevectors.
Returns:
Actual sampling time step (may be clamped)
double Storage::resampleLinear ( double  aDT  ) 

Resample using linear interpolation.

int Storage::reset ( double  aTime  ) 

Reset the storage to start storing after a specified time.

If no valid statevector exists at that specified time, the storage is set to occur after the first valid statevector that immediately precedes the specified time.

Parameters:
aT Time after which to start storing states. If aT doesn't exist exactly in the storage, the time is rounded down to the first valid time.
Returns:
Index at which the next appended statevector will be stored.
int Storage::reset ( int  aIndex = 0  ) 

Reset the storage to start storing at a specified index.

All statevectors at and following the specified index are discarded.

If aIndex is less than or equal to zero, the storage object is emptied (i.e., its size is set to 0).

If aIndex is larger than the current size of the storage object, no action is taken.

Parameters:
aIndex Index at which to start storing new statevectors.
Returns:
Index at which the next appended statevector will be stored.
void Storage::scaleTime ( double  aValue  ) 

Scale the times of all state vectors.

Parameters:
aValue Value by which to scale the times.
void Storage::setCapacityIncrement ( int  aIncrement  ) 

Set the capacity increment of this storage object.

For details on what the capacity increment does see Array::setCapacityIncrement().

Parameters:
aIncrement Capacity increment.
See also:
Array
void Storage::setColumnLabels ( const Array< std::string > &  aColumnLabels  ) 

Set column labels array.

void Storage::setDataColumn ( int  aStateIndex,
const Array< double > &  aData 
)

Set the data corresponding to a specified state.

This call is equivalent to setting a column of data from the storage file.

Parameters:
aStateIndex Index of the state (column) for which to get the data.
aData Array containing the new data.
Returns:
Number of values set in rData. The number of values set may be less than getSize() because not all stored state vectors are required to have the same number of states.
void OpenSim::Storage::setDescription ( const std::string &  aDescription  )  [inline]

Reimplemented from OpenSim::Object.

void Storage::setHeaderToken ( const std::string &  aToken  ) 

Set the header token.

The header token is used to mark the end of the header portion of an Storage when an Storage is saved in a file.

If the header token is NULL, a default header token is used.

Parameters:
aToken Header token.
void OpenSim::Storage::setInDegrees ( const bool  isInDegrees  )  [inline]
void OpenSim::Storage::setName ( const std::string &  aName  )  [inline]

Reimplemented from OpenSim::Object.

void Storage::setOutputFileName ( const std::string &  aFileName  )  [virtual]

Set name of output file to be written into.

This has the side effect of openning the file for writing. The header will not have the correct number of rows but this may not be an issue for ersion 2 of the Storage class

Implements OpenSim::StorageInterface.

void Storage::setStepInterval ( int  aStepInterval  ) 

Set the step interval.

void Storage::setWriteSIMMHeader ( bool  aTrueFalse  ) 

Set the whether or not to write a header appropriate for a SIMM motion file.

Parameters:
aTrueFalse Whether (true) or not (false) to write a SIMM header.
void Storage::shiftTime ( double  aValue  ) 

Shift the times of all state vectors.

Parameters:
aValue Value by which to shift the times.
void Storage::smoothSpline ( int  aOrder,
double  aCutoffFrequency 
)

Smooth spline each of the columns in the storage.

Note that as a part of this operation, the storage is resampled so that the statevectors are at equal spacing.

Parameters:
aOrder Order of the spline.
aCutoffFrequency Cutoff frequency.
int Storage::store ( int  aStep,
double  aT,
int  aN,
const double *  aY 
) [virtual]

Store a simulation vector.

This method differs from append in that, if the integration step of a simulation is not a multiple of the step interval of this Storage class, the state is not appended. Note that if the step storage interval is 0, storage is turned off.

The first empty storage location is returned.

Implements OpenSim::StorageInterface.

void Storage::subtract ( Storage aStorage  ) 

Subtract a storage instance to this storage instance.

Linear interpolation or extrapolation is used to get the values of the states that correspond in time to the states held in this storage instance.

Parameters:
aStorage Storage to subtract from this storage. s
void Storage::subtract ( StateVector aStateVector  ) 

Subtract a state vector from all state vectors in this storage instance.

Parameters:
aStateVector State vector to subtract from the state vectors.
See also:
StateVector::subtract(int,double[])
void Storage::subtract ( int  aN,
double  aY[] 
)

Subtract an array from all state vectors in this storage instance.

Only the first aN states of each state vector are altered.

Parameters:
aN Length of aY
aY Array of values to subtract from the state vectors.
See also:
StateVector::subtract(int,double[])
void Storage::subtract ( double  aValue  ) 

Subtract a value from all state vectors in this storage instance.

Parameters:
aValue Value to subtract from the state vectors.
See also:
StateVector::subtract(double)

Member Data Documentation

Array<std::string> OpenSim::Storage::_columnLabels [protected]

Column labels.

std::string OpenSim::Storage::_description [protected]

A description of the object.

-> rdSerializable interface

Reimplemented from OpenSim::Object.

std::string OpenSim::Storage::_fileName [protected]

Cache for fileName and file pointer when the file is opened so we can flush and write intermediate files if needed.

Storage file version as written to the file.

FILE* OpenSim::Storage::_fp [protected]
std::string OpenSim::Storage::_headerToken [protected]

Token used to mark the end of the description in a file.

bool OpenSim::Storage::_inDegrees [protected]

Are angles, if any, specified in radians or degrees?

MapKeysToValues OpenSim::Storage::_keyValueMap [protected]

Map between keys in file header and values.

int OpenSim::Storage::_lastI [mutable, protected]

Last index at which a search was started.

std::string OpenSim::Storage::_name [protected]

Name and Description.

Reimplemented from OpenSim::Object.

Step interval at which states in a simulation are stored.

See store().

Array of StateVectors.

Units in which the data is represented.

Flag for whether or not to insert a SIMM style header.

const char * Storage::DEFAULT_HEADER_SEPARATOR = " \t\r\n" [static]
const char * Storage::DEFAULT_HEADER_TOKEN = "endheader" [static]

Default token used to mark the end of the storage description in a file.

const int Storage::LatestVersion = 1 [static, protected]
const int Storage::MAX_RESAMPLE_SIZE = 100000 [static]
string Storage::simmReservedKeys [static, protected]
Initial value:
 {
                                                                  "#",
                                                                  "range", "Range",
                                                                  "wrap", "Wrap", "WRAP",
                                                                  "event",
                                                                  "enforce_loops",
                                                                  "enforce_constraints",
                                                                  "calc_derivatives"}

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

Generated on Sun Sep 25 00:19:52 2011 for OpenSim by  doxygen 1.6.1