Skip to content

Commit

Permalink
Merge branch 'main' into list_sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbianco committed Dec 20, 2023
2 parents e87c971 + 88da27e commit f2d93a0
Show file tree
Hide file tree
Showing 19 changed files with 59 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Bindings/Python/tests/test_DataTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_vector_rowvector(self):
assert (str(col[0]) == str(row[0]) and
str(col[1]) == str(row[1]) and
str(col[2]) == str(row[2]))
print('Test transpose VectorOVec3 to RowVectorVec3.')
print('Test transpose VectorVec3 to RowVectorVec3.')
row_copy = col.transpose()
assert (str(row_copy[0]) == str(row[0]) and
str(row_copy[1]) == str(row[1]) and
Expand Down
20 changes: 20 additions & 0 deletions Bindings/Python/tests/test_opensense.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def test_createObjects(self):
constraint_var = .0001
ikSolver = osim.InverseKinematicsSolver(model, mRefs, oRefs, coordinateReferences, constraint_var)
print("Created InverseKinematicsSolver object..")
oRefs = osim.BufferedOrientationsReference()
print("Created BufferedOrientationsReference object..")
ikSolver = osim.InverseKinematicsSolver(model, mRefs, oRefs, coordinateReferences, constraint_var)
print("Created InverseKinematicsSolver object with BufferedOrientationsReference..")

def test_vector_rowvector(self):
print()
Expand All @@ -43,3 +47,19 @@ def test_vector_rowvector(self):
col[1] == row[1] and
col[2] == row[2] and
col[3] == row[3])

def test_BufferedOrientationReferencePut(self):
# Make sure that we can append new data to the BufferedOrientationReference object
quatTable = osim.TimeSeriesTableQuaternion(os.path.join(test_dir,'orientation_quats.sto'))
print("Created TimeSeriesTableQuaternion object..")
orientationsData = osim.OpenSenseUtilities.convertQuaternionsToRotations(quatTable)
print("Convert Quaternions to orientationsData")
time = 0
rowVecView = orientationsData.getNearestRow(time)
print("Sliced orientationData")
rowVec = osim.RowVectorRotation(rowVecView)
print("Converted slice to row vector")
oRefs = osim.BufferedOrientationsReference()
print("Created BufferedOrienationReference object")
oRefs.putValues(time, rowVec)
print("Added row vector to BufferedOrientationReference object")
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ and `Blankevoort1991Ligament`, usages of `get_GeometryPath`, `upd_GeometryPath`,
- Exposed simbody methods to obtain GravityForces, MobilityForces and BodyForces (#3490)
- Simbody was updated such that the headers it transitively exposes to downstream projects are compatible with C++20 (#3619)
- Moved speed computation from `computeForce` in children of `ScalarActuator` to dedicated `getSpeed` function.
- Fix type problem with BufferedOrientationReference (Issue #3415, PR #3644)


v4.4.1
Expand Down
4 changes: 2 additions & 2 deletions OpenSim/Analyses/PointKinematics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ constructDescription()
strcat(descrip,"(position, velocity, or acceleration) of\n");

if(_relativeToBody){
sprintf(tmp,"point (%lf, %lf, %lf) on body %s relative to body %s of model %s.\n",
snprintf(tmp, BUFFER_LENGTH, "point (%lf, %lf, %lf) on body %s relative to body %s of model %s.\n",
_point[0],_point[1],_point[2],_body->getName().c_str(),
_relativeToBody->getName().c_str(), _model->getName().c_str());
}
else{
sprintf(tmp,"point (%lf, %lf, %lf) on the %s of model %s.\n",
snprintf(tmp, BUFFER_LENGTH, "point (%lf, %lf, %lf) on the %s of model %s.\n",
_point[0],_point[1],_point[2],_body->getName().c_str(),
_model->getName().c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Common/About.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static const char* OpenSimVersion = GET_OSIM_VERSION;

std::string GetVersionAndDate() {
char buffer[256];
sprintf(buffer,"version %s, build date %s %s",
snprintf(buffer, 256, "version %s, build date %s %s",
OpenSimVersion, __TIME__, __DATE__);
return std::string(buffer);
}
Expand Down
16 changes: 10 additions & 6 deletions OpenSim/Common/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ConstructDateAndTimeStamp()

// CONSTRUCT STAMP
char *stamp = new char[64];
sprintf(stamp,"%d%02d%02d_%02d%02d%02d",
snprintf(stamp, 64, "%d%02d%02d_%02d%02d%02d",
timeStruct->tm_year+1900,timeStruct->tm_mon+1,timeStruct->tm_mday,
timeStruct->tm_hour,timeStruct->tm_min,timeStruct->tm_sec);

Expand Down Expand Up @@ -282,18 +282,22 @@ void IO::
ConstructDoubleOutputFormat()
{
if(_GFormatForDoubleOutput) {
sprintf(_DoubleFormat,"%%g");
snprintf(_DoubleFormat, IO_DBLFMTLEN, "%%g");
} else if(_Scientific) {
if(_Pad<0) {
sprintf(_DoubleFormat,"%%.%dle",_Precision);
snprintf(_DoubleFormat, IO_DBLFMTLEN,
"%%.%dle", _Precision);
} else {
sprintf(_DoubleFormat,"%%%d.%dle",_Pad+_Precision,_Precision);
snprintf(_DoubleFormat, IO_DBLFMTLEN,
"%%%d.%dle", _Pad+_Precision, _Precision);
}
} else {
if(_Pad<0) {
sprintf(_DoubleFormat,"%%.%dlf",_Precision);
snprintf(_DoubleFormat, IO_DBLFMTLEN,
"%%.%dlf", _Precision);
} else {
sprintf(_DoubleFormat,"%%%d.%dlf",_Pad+_Precision,_Precision);
snprintf(_DoubleFormat, IO_DBLFMTLEN,
"%%%d.%dlf", _Pad+_Precision, _Precision);
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions OpenSim/Common/IO.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
#include <vector>

// DEFINES
const int IO_STRLEN = 2048;
constexpr int IO_STRLEN = 2048;
constexpr int IO_DBLFMTLEN = 256;


namespace OpenSim {
Expand Down Expand Up @@ -62,7 +63,7 @@ class OSIMCOMMON_API IO {
/** Specifies the precision of number output. */
static int _Precision;
/** The output format string. */
static char _DoubleFormat[256];
static char _DoubleFormat[IO_DBLFMTLEN];
/** Whether offline documents should also be printed when Object::print is called. */
static bool _PrintOfflineDocuments;

Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Common/PropertyDbl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ toString() const
{
if (SimTK::isFinite(_value)) {
char dbl[256];
sprintf(dbl, "%g", _value);
snprintf(dbl, 256, "%g", _value);
return dbl;
}

Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Common/PropertyDblArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ toString() const
string str = "(";
char dbl[256];
for(int i=0; i < _array.getSize(); i++){
sprintf(dbl, "%g", _array[i]);
snprintf(dbl, 256, "%g", _array[i]);
str += (i>0?" ":"") + string(dbl);
}
str += ")";
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Common/PropertyInt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ string PropertyInt::
toString() const
{
char intString[32];
sprintf(intString, "%d", _value);
snprintf(intString, 32, "%d", _value);
return intString;
}
2 changes: 1 addition & 1 deletion OpenSim/Common/PropertyIntArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ toString() const
string str = "(";
char intString[256];
for(int i=0; i < _array.getSize(); i++){
sprintf(intString, "%d", _array[i]);
snprintf(intString, 256, "%d", _array[i]);
str += (i>0?" ":"") + string(intString);
}
str += ")";
Expand Down
4 changes: 2 additions & 2 deletions OpenSim/Common/StateVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ print(FILE *fp) const

// TIME
char format[IO_STRLEN];
sprintf(format,"%s",IO::GetDoubleOutputFormat());
snprintf(format, IO_STRLEN, "%s", IO::GetDoubleOutputFormat());
int n=0,nTotal=0;
n = fprintf(fp,format,_t);
if(n<0) {
Expand All @@ -553,7 +553,7 @@ print(FILE *fp) const
nTotal += n;

// STATES
sprintf(format,"\t%s",IO::GetDoubleOutputFormat());
snprintf(format, IO_STRLEN, "\t%s", IO::GetDoubleOutputFormat());
for(int i=0;i<_data.getSize();i++) {
n = fprintf(fp,format,_data[i]);
if(n<0) {
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Common/Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,7 @@ bool Storage::makeStorageLabelsUnique() {
int c = 1;
while (exist) {
char cString[20];
sprintf(cString,"%d", c);
snprintf(cString, 20, "%d", c);
newName = std::string(cString) + "_" + offending;
exist = (lbls.findIndex(newName) != -1);
c++;
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Common/XMLDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ getVersionAsString(const int aVersion, std::string& aString)
for(int i=0; i<3; i++)
{
int digits = ver / div;
sprintf(pad, "%02d",digits);
snprintf(pad, 3, "%02d", digits);
ver -= div*(ver / div);
div /=100;
aString += string(pad);
Expand Down
8 changes: 4 additions & 4 deletions OpenSim/Simulation/BufferedOrientationsReference.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace OpenSim {
//=============================================================================
/**
* Subclass of OrientationsReference that handles live data by providing a DataQueue
* that allows clients to push data into and allows the InverseKinematicsSolver to
* that allows clients to push data into and allows the InverseKinematicsSolver to
* draw data from for solving.
* Ideally this would be templatized, allowing for all Reference classes to leverage it.
*
Expand Down Expand Up @@ -79,19 +79,19 @@ class OSIMSIMULATION_API BufferedOrientationsReference
SimTK::Array_<SimTK::Rotation_<double>>& values) const override;

/** add passed in values to data procesing Queue */
void putValues(double time, const SimTK::RowVector_<SimTK::Rotation>& dataRow);
void putValues(double time, const SimTK::RowVector_<SimTK::Rotation_<double>>& dataRow);

double getNextValuesAndTime(
SimTK::Array_<SimTK::Rotation_<double>>& values) override;

virtual bool hasNext() const override { return !_finished; };

void setFinished(bool finished) {
void setFinished(bool finished) {
_finished = finished;
};
private:
// Use a specialized data structure for holding the orientation data
mutable DataQueue_<SimTK::Rotation> _orientationDataQueue;
mutable DataQueue_<SimTK::Rotation_<double>> _orientationDataQueue;
bool _finished{false};
//=============================================================================
}; // END of class BufferedOrientationsReference
Expand Down
3 changes: 2 additions & 1 deletion OpenSim/Simulation/Model/AbstractTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,8 @@ std::string AbstractTool::createExternalLoadsFile(const std::string& oldFile,
ExternalForce* xf = new ExternalForce();
xf->setAppliedToBodyName((f==0)?body1:body2);
char pad[3];
sprintf(pad,"%d", f+1);
snprintf(pad, 3, "%d", f+1);

std::string suffix = "ExternalForce_"+string(pad);
xf->setName(suffix);
_externalLoads.adoptAndAppend(xf);
Expand Down
3 changes: 3 additions & 0 deletions OpenSim/Tools/IKMarkerTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ OpenSim_DECLARE_CONCRETE_OBJECT(IKMarkerTask, IKTask);
public:
IKMarkerTask() = default;
IKMarkerTask(const IKMarkerTask&) = default;
IKMarkerTask(IKMarkerTask&&) = default;
IKMarkerTask& operator=(const IKMarkerTask&) = default;
IKMarkerTask& operator=(IKMarkerTask&&) = default;
//=============================================================================
}; // END of class IKMarkerTask
//=============================================================================
Expand Down
3 changes: 3 additions & 0 deletions OpenSim/Tools/IMUInverseKinematicsTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class OSIMTOOLS_API OrientationWeightSet : public Set<OrientationWeight> {
// default copy, assignment operator, and destructor
OrientationWeightSet() = default;
OrientationWeightSet(const OrientationWeightSet&) = default;
OrientationWeightSet(OrientationWeightSet&&) = default;
OrientationWeightSet& operator=(const OrientationWeightSet&) = default;
OrientationWeightSet& operator=(OrientationWeightSet&&) = default;
//=============================================================================
};
//=============================================================================
Expand Down
2 changes: 1 addition & 1 deletion dependencies/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ AddDependency(NAME ezc3d
AddDependency(NAME simbody
DEFAULT ON
GIT_URL https://github.com/simbody/simbody.git
GIT_TAG 930ae0feff0adb5aec184af62d14f9d138cacd48
GIT_TAG 589e931f4a127830a5876ee4dd8f327b47361504
CMAKE_ARGS -DBUILD_EXAMPLES:BOOL=OFF
-DBUILD_TESTING:BOOL=OFF
${SIMBODY_EXTRA_CMAKE_ARGS})
Expand Down

0 comments on commit f2d93a0

Please sign in to comment.