Skip to content

Commit

Permalink
Merge pull request #3890 from opensim-org/feature_PointForceDirection…
Browse files Browse the repository at this point in the history
…-cleanup

Clean up OpenSim::PointForceDirection
  • Loading branch information
adamkewley authored Aug 27, 2024
2 parents 4cc61ad + 0cfc3ef commit 05b334d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 47 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ v4.6
allow extrapolation using the `extrapolate` flag. Combined with the `ignoreNaNs` flag, this prevents NaNs from
occurring in the output. (#3867)
- Added `Output`s to `ExpressionBasedCoordinateForce`, `ExpressionBasedPointToPointForce`, and `ExpressionBasedBushingForce` for accessing force values. (#3872)
- `PointForceDirection` no longer has a virtual destructor, is `final`, and its `scale` functionality
has been marked as `[[deprecated]]` (#3890)

v4.5.1
======
Expand Down
98 changes: 51 additions & 47 deletions OpenSim/Simulation/Model/PointForceDirection.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
* National Institutes of Health (U54 GM072970, R24 HD065690) and by DARPA *
* through the Warrior Web program. *
* *
* Copyright (c) 2005-2017 Stanford University and the Authors *
* Author(s): Ajay Seth *
* Copyright (c) 2005-2024 Stanford University and the Authors *
* Author(s): Ajay Seth, Adam Kewley *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); you may *
* not use this file except in compliance with the License. You may obtain a *
Expand All @@ -23,70 +23,74 @@
* limitations under the License. *
* -------------------------------------------------------------------------- */

// INCLUDES
#include <OpenSim/Simulation/Model/PhysicalFrame.h>
#include <OpenSim/Simulation/osimSimulationDLL.h>

namespace OpenSim {

class Body;
class PhysicalFrame;
//=============================================================================
//=============================================================================
/** Convenience class for a generic representation of geometry of a complex
Force (or any other object) with multiple points of contact through
which forces are applied to bodies. This represents one such point and an
array of these objects defines a complete Force distribution (ie. path).

/**
* Convenience class for a generic representation of geometry of a complex
* Force (or any other object) with multiple points of contact through
* which forces are applied to bodies. This represents one such point and an
* array of these objects defines a complete Force distribution (i.e., path).
*
* @author Ajay Seth
* @version 1.0
*/
class OSIMSIMULATION_API PointForceDirection final {
public:
PointForceDirection(
SimTK::Vec3 point,
const PhysicalFrame& frame,
SimTK::Vec3 direction) :

_point(point), _frame(&frame), _direction(direction)
{}

[[deprecated("the 'scale' functionality should not be used in new code: OpenSim already assumes 'direction' is non-unit-length")]]
PointForceDirection(
SimTK::Vec3 point,
const PhysicalFrame& frame,
SimTK::Vec3 direction,
double scale) :

_point(point), _frame(&frame), _direction(direction), _scale(scale)
{}

/** Returns the point of "contact", defined in `frame()` */
SimTK::Vec3 point() { return _point; }

class OSIMSIMULATION_API PointForceDirection
{
/** Returns the frame in which `point()` is defined */
const PhysicalFrame& frame() { return *_frame; }

/** Returns the (potentially, non-unit-length) direction, defined in ground, of the force at `point()` */
SimTK::Vec3 direction() { return _direction; }

/** Returns the scale factor of the force */
[[deprecated("this functionality should not be used in new code: OpenSim already assumes 'direction' is non-unit-length")]]
double scale() { return _scale; }

/** Replaces the current direction with `direction + newDirection` */
void addToDirection(SimTK::Vec3 newDirection) { _direction += newDirection; }

//=============================================================================
// MEMBER VARIABLES
//=============================================================================
private:
/** Point of "contact" with a body, defined in the body frame */
SimTK::Vec3 _point;

/** The frame in which the point is defined */
const PhysicalFrame &_frame;
const PhysicalFrame* _frame;

/** Direction of the force at the point, defined in ground */
SimTK::Vec3 _direction;
/** Optional parameter to scale the force that results from a scalar
(tension) multiplies the direction */
double _scale;
//=============================================================================
// METHODS
//=============================================================================
//--------------------------------------------------------------------------
// CONSTRUCTION
//--------------------------------------------------------------------------
public:
virtual ~PointForceDirection() {};
/** Default constructor takes the point, body, direction and scale
as arguments */
PointForceDirection(SimTK::Vec3 point, const PhysicalFrame &frame,
SimTK::Vec3 direction, double scale=1):
_point(point), _frame(frame), _direction(direction), _scale(scale)
{}

/** get point of "contact" with on a body defined in the body frame */
SimTK::Vec3 point() {return _point; }
/** get the body in which the point is defined */
const PhysicalFrame& frame() {return _frame; }
/** get direction of the force at the point defined in ground */
SimTK::Vec3 direction() {return _direction; }
/** get the scale factor on the force */
double scale() {return _scale; }

/** replace the current direction with the resultant with a new direction */
void addToDirection(SimTK::Vec3 newDirection) {_direction+=newDirection;}

//=============================================================================
}; // END of class PointForceDirection
//=============================================================================
/** Deprecated parameter to scale the force that results from a scalar
(tension) multiplies the direction */
double _scale = 1.0;
};

} // namespace

#endif // __PointForceDirection_h__

0 comments on commit 05b334d

Please sign in to comment.