Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
10 changes: 10 additions & 0 deletions Bindings/Java/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ macro(OpenSimAddJavaTest TESTNAME)
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/TestVisualization")
file(COPY "${OPENSIM_SHARED_TEST_FILES_DIR}/gait10dof18musc_subject01.osim"
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/TestEditProperties")
file(COPY "${OPENSIM_SHARED_TEST_FILES_DIR}/gait2354_simbody.osim"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use model/setup files that are already in the repo (e.g., the files used by testScale.cpp), particularly since this isn't a correctness/regression test? There are already 4 files named "gait2354_simbody.osim" in the repo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the note @tkuchida I'm actually using the recommended method of having these files added to the shared testing folder, we should make sure other tests are using it from there. This may or maynot be part of this PR but good point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is the recommended method, but ideally, one of the pre-existing gait2354 models would have been moved to the shared folder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment to this effect in Issue #206.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @tkuchida 👏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we want to move to shared resources to avoid duplication, I think copying essentially the same files in testScale violates that spirit. I would prefer we use the testScale files that already exist instead of making yet another copy.

DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/TestModelScaling")
file(COPY "${OPENSIM_SHARED_TEST_FILES_DIR}/gait2354_Scale_MarkerSet.xml"
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/TestModelScaling")
file(COPY "${OPENSIM_SHARED_TEST_FILES_DIR}/subject01_Setup_Scale.xml"
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/TestModelScaling")
file(COPY "${OPENSIM_SHARED_TEST_FILES_DIR}/subject01_static.trc"
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/TestModelScaling")
if(WIN32)
# On Windows, CMake cannot use RPATH to hard code the location of libraries
# in the binary directory (DLL's don't have RPATH), so we must set PATH to
Expand Down Expand Up @@ -132,6 +140,8 @@ OpenSimAddJavaTest(TestVisualization)
OpenSimAddJavaTest(TestEditProperties)
OpenSimAddJavaTest(TestTables)
OpenSimAddJavaTest(TestModelBuilding)
OpenSimAddJavaTest(TestModelScaling)

if(WITH_BTK)
OpenSimAddJavaTest(TestC3DFileAdapter)
endif()
Expand Down
46 changes: 46 additions & 0 deletions Bindings/Java/tests/TestModelScaling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import org.opensim.modeling.*;
import java.io.IOException;

class TestModelScaling {
public static void main(String[] args) {

try {
ScaleTool scaleTool = null;
// Live current model in GUI would be used for unscaledModel
Model unscaledModel = new Model("gait2354_simbody.osim");
// Exercise "loadsettings" from file"
try {
scaleTool = new ScaleTool("subject01_Setup_Scale.xml");
} catch (IOException ex) {
System.exit(-1);
}
System.out.println("ScaleTool created!");
// Populate the tabs of Scale factors and measurements
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment does not describe what is happening below.

MarkerSet extraMarkerSet = new MarkerSet(unscaledModel, "gait2354_Scale_MarkerSet.xml");
System.out.println("Extra MarkerSet created!");
unscaledModel.updateMarkerSet(extraMarkerSet);
System.out.println("Extra MarkerSet added to model!");
OpenSimContext context = new OpenSimContext(unscaledModel.initSystem(), unscaledModel);
MeasurementSet measurementSet = scaleTool.getModelScaler().getMeasurementSet();
System.out.println("MeasurementSet created!");
MarkerData measurementTrial = new MarkerData("subject01_static.trc");
System.out.println("MarkerData for static trial loaded!");
double scaleFactor = context.computeMeasurementScaleFactor(scaleTool.getModelScaler(), unscaledModel,
measurementTrial, measurementSet.get(0));
System.out.println("Measurement computed !");
// When we run the tool we create a copy of the unscaled model and scale in place using the
// calls below which exercise the "run" button
Model processedModel = new Model(unscaledModel);
processedModel.setName(scaleTool.getName());
OpenSimContext processedContext = new OpenSimContext(processedModel.initSystem(), processedModel);
processedContext.processModelScale(scaleTool.getModelScaler(),
processedModel, "", scaleTool.getSubjectMass());
processedContext.processModelMarkerPlacer(scaleTool.getMarkerPlacer(), processedModel, "");
System.out.println("Test finished!");
}
catch (IOException ex){
System.exit(-1);
}
System.gc();
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove Model::replaceMarkerSet() (see #1780) and deleteUnusedMarkers() since they appear to be unused by the GUI?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MarkerPlacer::processModel uses deleteUnusedMarkers(), it's not used by the GUI directly. replaceMarkerSet is not called by the GUI anymore and can be removed.

Loading