Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid tweaking tangent points of WrapCylinder when single object wrap… #3125

Merged
merged 50 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
3fef842
minor refactor to reduce num calls to get size of Array property
aymanhab Nov 30, 2021
3c4656a
Avoid duplicate transformation to Ground frame when computing path le…
aymanhab Dec 7, 2021
2953a68
remove_unused_variable
aymanhab Dec 7, 2021
9732b16
Remove macros that are replaceable by Vec3 operators
aymanhab Dec 7, 2021
f1e5db6
Merge branch 'wrap_performance' of https://github.com/opensim-org/ope…
aymanhab Dec 7, 2021
686f7eb
Inline usage of Macro in WrapEllipsoid
aymanhab Dec 8, 2021
3de0a01
More refactoring, use det for determinant, vec operators instead of l…
aymanhab Dec 10, 2021
eb93bf7
Update continuous_integration.yml
aymanhab Dec 10, 2021
051d80e
Remove rather than comment out function that was moved to header and …
aymanhab Dec 10, 2021
c958640
Merge branch 'wrap_performance' of https://github.com/opensim-org/ope…
aymanhab Dec 10, 2021
f2806d5
Update GeometryPath.cpp
aymanhab Dec 13, 2021
d6df20a
Update continuous_integration.yml
aymanhab Dec 13, 2021
72eaef6
Use normSqr for consistency
aymanhab Dec 13, 2021
d3d3fd1
Merge branch 'wrap_performance' of https://github.com/opensim-org/ope…
aymanhab Dec 13, 2021
3101d7c
Use UnitVec3 instead of Vec3 for plane normal
aymanhab Dec 16, 2021
17fd7d1
Avoid tweaking tangent points of WrapCylinder when single object wrap…
aymanhab Jan 17, 2022
40c48be
Add MocoAngularVelocityTrackingGoal to bindings; add option for quate…
nickbianco Nov 18, 2021
1b3d46e
Complete fixes for setRotationReference(); update changelog
nickbianco Nov 18, 2021
fe4a8c7
fix load issue with scale tool (#3110)
carmichaelong Nov 30, 2021
2a7ff61
Add extendPostScale() to DeGrooteFregly2016Muscle (#3108)
nickbianco Dec 6, 2021
949e0e4
Update continuous_integration.yml (#3115)
aymanhab Dec 17, 2021
041ace9
Fix inline assemble in catch.hpp dependency for ARM Macs (#3118)
keenon Dec 21, 2021
cfda915
Avoid tweaking tangent points of WrapCylinder when single object wrap…
aymanhab Jan 17, 2022
2e6a33f
Merge branch 'wrap_min_wrap_pts' of https://github.com/opensim-org/op…
aymanhab Jan 18, 2022
d4ccfff
disableVisualization when creating MocoProblem for Model
aymanhab Jan 18, 2022
348057a
Avoid messages about missing files if visualization is off.
aymanhab Jan 20, 2022
8963d69
fix comments per PR review
aymanhab Jan 20, 2022
4e1e06a
Disable visualization for all internal models used by MccoProblem
aymanhab Jan 20, 2022
51b8f37
Fix typo/mistake in variable name
aymanhab Jan 20, 2022
a8bd62a
Couple other places to disable visualization for models internal to M…
aymanhab Jan 20, 2022
620cc83
improve comments per feedback on PR
aymanhab Jan 24, 2022
a7a67b3
Use finer grain includes per PR review
aymanhab Jan 25, 2022
4979556
Retire Mtx::CrossProduct wrapper method for Vec3 operator
aymanhab Jan 25, 2022
75323a2
Remove now unused methods for CrossProduct, Interpolation, Translatio…
aymanhab Jan 25, 2022
2bb8e58
Fix case for pathname of UnitVec.h
aymanhab Jan 25, 2022
e8b18b1
Use norm for Mtx::Magnitude
aymanhab Jan 25, 2022
b215d1c
Remove redundant call to disableVisualization
aymanhab Jan 25, 2022
64d89c4
Remove Mtx::Angle and inline references to it.
aymanhab Jan 25, 2022
fa4daa8
Replace Mtx::Normalize with Vec3.normalize
aymanhab Jan 26, 2022
ba9bef3
Update standard input for testMocoInverse
aymanhab Jan 26, 2022
130c740
Minor rearrangement per feedback on PR
aymanhab Jan 26, 2022
d14c8d0
Eliminate Mtx class, move remaining 2 functions to WrapMath
aymanhab Jan 27, 2022
6c0a90c
Inline replace DotProduct with operator, and remove from WrapMath.h, …
aymanhab Jan 27, 2022
f0d1d80
Rename Normalize to NormalizeOrZero
aymanhab Jan 28, 2022
7202922
Update WrapMath.h
aymanhab Jan 31, 2022
5457816
Remove unused methods in WrapMath class, for consistency restore all …
aymanhab Feb 1, 2022
7ccdcae
Remove unused methods in WrapMath class, for consistency restore all …
aymanhab Feb 1, 2022
5a74771
Merge branch 'wrap_min_wrap_pts' of https://github.com/opensim-org/op…
aymanhab Feb 2, 2022
6bb9844
Update std again based on latest wrapping code update
aymanhab Feb 2, 2022
d424203
Update ModelProcessor.h
aymanhab Feb 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Applications/Forward/test/testForward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void testArm26() {
for (int j = 0; j < state->getSize(); ++j) {
stringstream message;
message << "t=" << time <<" state# "<< j << " " << standard->getColumnLabels()[j+1] << " std=" << data[j] <<" computed=" << state->getData()[j] << endl;
ASSERT_EQUAL(data[j], state->getData()[j], 1.0e-3,
ASSERT_EQUAL(data[j], state->getData()[j], 5.0e-3,
__FILE__, __LINE__, "ASSERT_EQUAL FAILED " + message.str());
cout << "ASSERT_EQUAL PASSED " << message.str();
}
Expand All @@ -173,7 +173,7 @@ void testArm26() {
for (int j = 0; j < state->getSize(); ++j) {
stringstream message;
message << "t=" << time <<" state# "<< j << " " << standard->getColumnLabels()[j+1] << " std=" << data[j] <<" computed=" << state->getData()[j] << endl;
ASSERT_EQUAL(data[j], state->getData()[j], 1.0e-3,
ASSERT_EQUAL(data[j], state->getData()[j], 5.0e-3,
__FILE__, __LINE__, "ASSERT_EQUAL FAILED " + message.str());
cout << "ASSERT_EQUAL PASSED " << message.str();
}
Expand Down
9 changes: 7 additions & 2 deletions OpenSim/Common/ModelDisplayHints.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,12 @@ class OSIMCOMMON_API ModelDisplayHints : public Object {
/** Default construction creates a valid display hints object with all
hints set to their default values. **/
ModelDisplayHints() { constructProperties(); }


/** Turn off visualization completely, only use API/modeling.
Meshes will not be loaded, pathwrappig intermediate points not computed.
Intentionally there's no reverse API to turn on visualization downstream.
**/
void disableVisualization() { _visualization = false; }
bool isVisualizationEnabled() const { return _visualization; }
private:
void constructProperties() {
constructProperty_show_wrap_geometry(true);
Expand All @@ -120,6 +124,7 @@ class OSIMCOMMON_API ModelDisplayHints : public Object {
constructProperty_show_forces(true);
constructProperty_show_debug_geometry(false);
}
bool _visualization{true};
};


Expand Down
1 change: 1 addition & 0 deletions OpenSim/Moco/MocoProblemRep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ void MocoProblemRep::initialize() {

// Grab a writable state from the copied model -- we'll use this to disable
// its constraints below.
m_model_disabled_constraints.updDisplayHints().disableVisualization();
m_state_disabled_constraints[0] = m_model_disabled_constraints.initSystem();
m_state_disabled_constraints[1] = m_state_disabled_constraints[0];

Expand Down
7 changes: 6 additions & 1 deletion OpenSim/Simulation/Model/GeometryPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,11 @@ void GeometryPath::computeLengtheningSpeed(const SimTK::State& s) const
}

setLengtheningSpeed(s, speed);
log_trace("length {}, speed {}",
calcLengthAfterPathComputation(s, currentPath), speed);
log_trace("Path:");
for (int i = 0; i < currentPath.getSize(); i++)
log_trace("{}", currentPath[i]->getLocation(s));
}

//_____________________________________________________________________________
Expand Down Expand Up @@ -974,7 +979,7 @@ applyWrapObjects(const SimTK::State& s, Array<AbstractPathPoint*>& path) const
WrapResult wr;
wr.startPoint = pt1;
wr.endPoint = pt2;

wr.singleWrap = (wrapSetSize==1);
result[i] = wo->wrapPathSegment(s, *path.get(pt1),
*path.get(pt2), ws, wr);
if (result[i] == WrapObject::mandatoryWrap) {
Expand Down
1 change: 1 addition & 0 deletions OpenSim/Simulation/Model/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,7 @@ void Model::generateDecorations
const SimTK::State& state,
SimTK::Array_<SimTK::DecorativeGeometry>& appendToThis) const
{
if (!hints.isVisualizationEnabled()) return;
ComponentList<const Component> allComps = getComponentList();
ComponentList<Component>::const_iterator iter = allComps.begin();
while (iter != allComps.end()){
Expand Down
29 changes: 21 additions & 8 deletions OpenSim/Simulation/Wrap/WrapCylinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
//=============================================================================
// INCLUDES
//=============================================================================
#include <SimTKcommon.h>
#include "WrapCylinder.h"
#include "PathWrap.h"
#include "WrapMath.h"
#include "WrapResult.h"
#include <OpenSim/Simulation/Model/Model.h>
#include <OpenSim/Common/ModelDisplayHints.h>
#include <OpenSim/Common/Mtx.h>
#include <OpenSim/Common/SimmMacros.h>
Expand All @@ -40,6 +42,7 @@
using namespace std;
using namespace OpenSim;
using SimTK::Vec3;
using SimTK::UnitVec3;

static const char* wrapTypeName = "cylinder";
static Vec3 p0(0.0, 0.0, -1.0);
Expand Down Expand Up @@ -181,10 +184,10 @@ int WrapCylinder::wrapLine(const SimTK::State& s, SimTK::Vec3& aPoint1, SimTK::V
double dist1, dist2;
double t12, t00;

Vec3 pp, vv, uu, r1a, r1b, r2a, r2b, apex, plane_normal, sum_musc,
Vec3 pp, vv, uu, r1a, r1b, r2a, r2b, apex, sum_musc,
r1am, r1bm, r2am, r2bm, p11, p22, r1p, r2p, axispt, near12,
vert1, vert2, mpt, apex1, apex2, l1, l2, near00;

UnitVec3 plane_normal;
int i, return_code = wrapped;
bool r1_inter, r2_inter;
bool constrained = (bool) (_wrapSign != 0);
Expand Down Expand Up @@ -537,11 +540,10 @@ int WrapCylinder::wrapLine(const SimTK::State& s, SimTK::Vec3& aPoint1, SimTK::V
uu = aPoint1 - apex;
vv = aPoint2 - apex;

Mtx::Normalize(3, uu, uu);
Mtx::Normalize(3, vv, vv);
uu.normalize();
vv.normalize();

Mtx::CrossProduct(uu, vv, plane_normal);
Mtx::Normalize(3, plane_normal, plane_normal);
SimTK::UnitVec3 plane_nomral(uu % vv);

d = - aPoint1[0] * plane_normal[0] - aPoint1[1] * plane_normal[1] - aPoint1[2] * plane_normal[2];

Expand Down Expand Up @@ -660,7 +662,18 @@ void WrapCylinder::_make_spiral_path(SimTK::Vec3& aPoint1,
m.set(0, 0, ax[0]); m.set(0, 1, ax[1]); m.set(0, 2, ax[2]);
m.set(1, 0, uu[0]); m.set(1, 1, uu[1]); m.set(1, 2, uu[2]);
m.set(2, 0, vv[0]); m.set(2, 1, vv[1]); m.set(2, 2, vv[2]);

// WrapTorus creates a WrapCyl with no connected model, avoid this hack
if (!_model.empty() && !getModel().getDisplayHints().isVisualizationEnabled() &&
aWrapResult.singleWrap) {
// Use one WrapSegment/cord instead of dense list of wrap_pt(s)
_calc_spiral_wrap_point(
r1a, axial_vec, m, ax, sense, 0, theta, wrap_pt);
aWrapResult.wrap_pts.append(wrap_pt);
_calc_spiral_wrap_point(
r1a, axial_vec, m, ax, sense, 1.0, theta, wrap_pt);
aWrapResult.wrap_pts.append(wrap_pt);
return;
}
// Each muscle segment on the surface of the cylinder should be
// 0.002 meters long. This assumes the model is in meters, of course.
int numWrapSegments = (int) (aWrapResult.wrap_path_length / 0.002);
Expand All @@ -675,7 +688,7 @@ void WrapCylinder::_make_spiral_path(SimTK::Vec3& aPoint1,

// adjust r1/r2 tangent points if necessary to achieve tangency with
// the spiral path:
if (i == 1 && iterations < MAX_ITERATIONS)
if (i == 1 && iterations < MAX_ITERATIONS && !aWrapResult.singleWrap)
{
bool did_adjust_r2 = false;
bool did_adjust_r1 = _adjust_tangent_point(aPoint1, dn, aWrapResult.r1, wrap_pt);
Expand Down
15 changes: 5 additions & 10 deletions OpenSim/Simulation/Wrap/WrapMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,15 @@ bool WrapMath::
IntersectLines(SimTK::Vec3& p1, SimTK::Vec3& p2, SimTK::Vec3& p3, SimTK::Vec3& p4,
SimTK::Vec3& pInt1, double& s, SimTK::Vec3& pInt2, double& t)
{
SimTK::Vec3 cross_prod, vec1, vec2;

vec1 = p2 - p1;
SimTK::Vec3 vec1 = p2 - p1;

double mag1 = Mtx::Normalize(3, vec1, vec1);

vec2 = p4 - p3;
SimTK::Vec3 vec2 = p4 - p3;

double mag2 = Mtx::Normalize(3, vec2, vec2);

Mtx::CrossProduct(vec1, vec2, cross_prod);
SimTK::Vec3 cross_prod = vec1 % vec2;

double denom = cross_prod.normSqr();

Expand Down Expand Up @@ -132,7 +130,7 @@ IntersectLines(SimTK::Vec3& p1, SimTK::Vec3& p2, SimTK::Vec3& p3, SimTK::Vec3& p
*/
bool WrapMath::
IntersectLineSegPlane(SimTK::Vec3& pt1, SimTK::Vec3& pt2,
SimTK::Vec3& plane, double d,
SimTK::UnitVec3& plane, double d,
SimTK::Vec3& inter)
{
SimTK::Vec3 vec = pt2 - pt1;
Expand All @@ -147,10 +145,7 @@ IntersectLineSegPlane(SimTK::Vec3& pt1, SimTK::Vec3& pt2,
if ((t < -LINE_EPSILON) || (t > 1.0 + LINE_EPSILON))
return false;

inter[0] = pt1[0] + (t * vec[0]);
inter[1] = pt1[1] + (t * vec[1]);
inter[2] = pt1[2] + (t * vec[2]);

inter = pt1 + (t * vec);
return true;
}

Expand Down
5 changes: 2 additions & 3 deletions OpenSim/Simulation/Wrap/WrapMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
*/

#include <OpenSim/Simulation/osimSimulationDLL.h>
#include <SimTKcommon/SmallMatrix.h>

#include <SimTKcommon.h>

namespace OpenSim {

Expand All @@ -54,7 +53,7 @@ class OSIMSIMULATION_API WrapMath
SimTK::Vec3& pInt2, double& t);
static bool
IntersectLineSegPlane(SimTK::Vec3& pt1, SimTK::Vec3& pt2,
SimTK::Vec3& plane, double d, SimTK::Vec3& inter);
SimTK::UnitVec3& plane, double d, SimTK::Vec3& inter);
static void
ConvertAxisAngleToQuaternion(const SimTK::Vec3& axis,
double angle, double quat[4]);
Expand Down
1 change: 1 addition & 0 deletions OpenSim/Simulation/Wrap/WrapResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void WrapResult::copyData(const WrapResult& aWrapResult) {
sv[i] = aWrapResult.sv[i];
}

singleWrap = aWrapResult.singleWrap;
// TODO: Should factor be omitted from the copy?
}

Expand Down
4 changes: 2 additions & 2 deletions OpenSim/Simulation/Wrap/WrapResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class OSIMSIMULATION_API WrapResult
// so we can more easily detect any bugs caused by not copying this
// variable.
double factor = SimTK::NaN; // scale factor used to normalize parameters

//=============================================================================
bool singleWrap = false; //Flag to indicate if a single wrap object to be considered so we can optimize
//=============================================================================
// METHODS
//=============================================================================
//--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion OpenSim/Tools/Test/testControllers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ void testPrescribedControllerFromFile(const std::string& modelFile,
"testPrescribedControllerFromFile '"+modelName+"'states failed");

CHECK_STORAGE_AGAINST_STANDARD(controls, std_controls,
std::vector<double>(nstates, 0.01), __FILE__, __LINE__,
std::vector<double>(nstates, 0.015), __FILE__, __LINE__,
"testPrescribedControllerFromFile '"+modelName+"'controls failed");

osimModel.disownAllComponents();
Expand Down