Skip to content

Commit

Permalink
Merge pull request #47 from aymanhab/treatment_optimization
Browse files Browse the repository at this point in the history
Treatment optimization basic functionality works
  • Loading branch information
aymanhab authored Jan 3, 2025
2 parents d72cbd7 + 20d9e70 commit c65e35b
Show file tree
Hide file tree
Showing 17 changed files with 548 additions and 342 deletions.
391 changes: 218 additions & 173 deletions Gui/opensim/rice_cnl/src/org/opensim/rcnl/BaseToolPanel.java

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions Gui/opensim/rice_cnl/src/org/opensim/rcnl/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ TreatmentOptimizationJPanel.jRCNLTorqueControllerPanel.border.title=RCNL Torque
TreatmentOptimizationJPanel.jLabel2.text=Surrogate model data directory
TreatmentOptimizationJPanel.jCoordinatesListPanel3.border.title=Coordinate List
TreatmentOptimizationJPanel.jSynergyControllerDetailsPanel1.border.title=RCNL Synergy Controller
TreatmentOptimizationJPanel.jControllersPanel.TabConstraints.tabTitle=RCNL Controllers
TreatmentOptimizationJPanel.jControllersPanel.TabConstraints.tabTitle=RCNL Controllers
TreatmentOptimizationJPanel.jLabel6.text=Tracked Quantities Dir:
TreatmentOptimizationJPanel.jLabel8.text=Optimal Control Solver Settings File:
TreatmentOptimizationJPanel.jLabel5.text=Results Dir:
TreatmentOptimizationJPanel.outputPanel.border.title=Output
TreatmentOptimizationJPanel.inputOutputPanel.TabConstraints.tabTitle=Settings
TreatmentOptimizationJPanel.inputOutputPanel.TabConstraints.tabTitle=Settings
TreatmentOptimizationJPanel.jLabel4.text=Initial Guess Dir:
TreatmentOptimizationJPanel.jLabel3.text=Osimx File:
TreatmentOptimizationJPanel.currentModelFileTextField.toolTipText=Current Model in GUI
Expand Down Expand Up @@ -214,3 +214,5 @@ EditCostTermJPanel.jErrorCenterTextField.text=0.
EditCosnstraintTermJPanel.jComponentTypeTextField.text=\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \
EditCosnstraintTermJPanel.jMaxErrorTextField.text=0
EditCosnstraintTermJPanel.jMinErrorTextField.text=0
SelectQuantitiesFromListJPanel.jSelectAllCheckBox.toolTipText=select all shown quantities
SelectQuantitiesFromListJPanel.jSelectAllCheckBox.text=select all shown
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,12 @@ void restrictNamesBy(String pattern){
fireTableDataChanged();

}

void selectShown() {
for (int q=0; q<shownQuantities.size(); q++){
selected.set(shownQuantities.get(q), true);
}
fireTableDataChanged();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,12 @@ void restrictNamesBy(String pattern){
fireTableDataChanged();

}

void selectShown() {
for (int q=0; q<shownQuantities.size(); q++){
selected.set(shownQuantities.get(q), true);
}
fireTableDataChanged();
}

}
44 changes: 20 additions & 24 deletions Gui/opensim/rice_cnl/src/org/opensim/rcnl/EditCostTermJPanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,23 @@
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Component id="jComponentListPanel" alignment="0" pref="0" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jEnabledCheckBox" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel11" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jComponentTypeTextField" min="-2" pref="220" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jMaxErrorTextField" min="-2" pref="150" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="131" max="-2" attributes="0"/>
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jErrorCenterTextField" min="-2" pref="215" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="jComponentListPanel" alignment="0" pref="0" max="32767" attributes="0"/>
<Group type="103" alignment="1" groupAlignment="0" attributes="0">
<Component id="jEnabledCheckBox" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel11" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jComponentTypeTextField" min="-2" pref="220" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jMaxErrorTextField" min="-2" pref="150" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="131" max="-2" attributes="0"/>
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jErrorCenterTextField" min="-2" pref="215" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
Expand All @@ -55,9 +50,10 @@
<Component id="jCostTermNameTextField" min="-2" pref="460" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
Expand Down Expand Up @@ -130,9 +126,9 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jScrollPane2" min="-2" pref="780" max="-2" attributes="0"/>
<Component id="jScrollPane2" min="-2" pref="559" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="editComonentListButton" min="-2" max="-2" attributes="0"/>
<Component id="editComonentListButton" min="-2" pref="89" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
Expand Down
40 changes: 19 additions & 21 deletions Gui/opensim/rice_cnl/src/org/opensim/rcnl/EditCostTermJPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
jComponentListPanelLayout.setHorizontalGroup(
jComponentListPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jComponentListPanelLayout.createSequentialGroup()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 780, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 559, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(editComonentListButton)
.addComponent(editComonentListButton, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jComponentListPanelLayout.setVerticalGroup(
Expand Down Expand Up @@ -216,24 +216,21 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jComponentListPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jEnabledCheckBox)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComponentTypeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jMaxErrorTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(131, 131, 131)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jErrorCenterTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addContainerGap())
.addComponent(jComponentListPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jEnabledCheckBox)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel11)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComponentTypeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jMaxErrorTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(131, 131, 131)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jErrorCenterTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
Expand All @@ -244,7 +241,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jCostTermNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 460, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,9 @@ public void pressedCancel() {
super.pressedCancel(); //To change body of generated methods, choose Tools | Templates.
}

@Override
String getToolXML() {
return gcpPersonalizationToolModel.getToolAsObject().dump();
}

@Override
public void loadSettings(String nmsmFilename) {
String fileName = super.stripOuterTags(nmsmFilename);
String fileName = BaseToolPanel.stripOuterTags(nmsmFilename);
Model model = OpenSimDB.getInstance().getCurrentModel();
//if(model==null) throw new IOException("JointPersonalizationJPanel got null model");
gcpPersonalizationToolModel = new GCPPersonalizationToolModel(model, fileName);
Expand Down Expand Up @@ -453,9 +448,8 @@ public void setSettingsFileDescription(String description) {
}

@Override
public void saveSettings(String fileName, String contents) {
public void saveSettings(String fileName) {

String adjustedContents = contents;
// Before saving the settings, we need to make motion file and grf file relative to input_directory
String inputDir = gcpPersonalizationToolModel.getDataDir();
String saveInputMotion = gcpPersonalizationToolModel.getInputMotionFile();
Expand All @@ -469,10 +463,11 @@ public void saveSettings(String fileName, String contents) {
String relativeGRFFile = FileUtils.makePathRelative(saveGRFfile, inputDir);
if (relativeGRFFile != null)
gcpPersonalizationToolModel.setInputGRFFile(relativeGRFFile);
adjustedContents = getToolXML();
}
// Set proprties from relative path
super.saveSettings(fileName, adjustedContents); //To change body of generated methods, choose Tools | Templates.
String fullFilename = FileUtils.addExtensionIfNeeded(fileName, ".xml");
gcpPersonalizationToolModel.getToolAsObject().print(fullFilename);
replaceOpenSimDocumentTags(fullFilename);
// Restore from model
gcpPersonalizationToolModel.setInputMotionFile(saveInputMotion);
gcpPersonalizationToolModel.setInputGRFFile(saveGRFfile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,17 @@ public void pressedCancel() {
}

@Override
public String getToolXML() {
return jointPersonalizationToolModel.getToolAsObject().dump();
public void saveSettings(String fileName) {
String fullFilename = FileUtils.addExtensionIfNeeded(fileName, ".xml");
OpenSimObject obj = jointPersonalizationToolModel.getToolAsObject();
forceWritableProperties(obj);
obj.print(fullFilename);
replaceOpenSimDocumentTags(fullFilename);
}

@Override
public void loadSettings(String nmsmFilename) {
String fileName = super.stripOuterTags(nmsmFilename);
String fileName = BaseToolPanel.stripOuterTags(nmsmFilename);
Model model = OpenSimDB.getInstance().getCurrentModel();
//if(model==null) throw new IOException("JointPersonalizationJPanel got null model");
jointPersonalizationToolModel = new JointPersonalizationToolModel(model, fileName);
Expand All @@ -331,6 +335,24 @@ public void setSettingsFileDescription(String description) {
super.setSettingsFileDescription(description); //To change body of generated methods, choose Tools | Templates.
}

@Override
void forceWritableProperties(OpenSimObject dObject) {
super.forceWritableProperties(dObject); //To change body of generated methods, choose Tools | Templates.
// For each JMPTask in tasklist, force write of parent_frame_transformation, child_frame_transformation
// dObject is an instance of JointModelPersonalizationTool
AbstractProperty ap = dObject.getPropertyByName("JMPTaskList");
PropertyObjectList olist = PropertyObjectList.getAs(ap);
for (int i=0; i< olist.size(); i++){
OpenSimObject ithTask = olist.getValue(i);
AbstractProperty apJnts = ithTask.getPropertyByName("JMPJointSet");
PropertyObjectList poJointList = PropertyObjectList.updAs(apJnts);
for (int j=0; j<poJointList.size(); j++){
poJointList.getValue(j).updPropertyByName("parent_frame_transformation").setValueIsDefault(false);
poJointList.getValue(j).updPropertyByName("child_frame_transformation").setValueIsDefault(false);
}
}
}


// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton addJointTaskButton;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ public void setToolAsObject(OpenSimObject toolAsObject) {
public PropertyObjectList getJointTaskListAsObjectList() {
AbstractProperty ap = toolAsObject.getPropertyByName("JMPTaskList");
PropertyObjectList olist = PropertyObjectList.getAs(ap);
for (int i=0; i< olist.size(); i++){
OpenSimObject ithTask = olist.getValue(i);
}

return olist;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ public void pressedCancel() {

@Override
public void loadSettings(String nmsmFilename) {
String fileName = super.stripOuterTags(nmsmFilename);
String fileName = BaseToolPanel.stripOuterTags(nmsmFilename);
Model model = OpenSimDB.getInstance().getCurrentModel();
//if(model==null) throw new IOException("JointPersonalizationJPanel got null model");
mtpPersonalizationToolModel = new MTPPersonalizationToolModel(model, fileName);
Expand Down Expand Up @@ -701,8 +701,20 @@ public void setSettingsFileDescription(String description) {
// End of variables declaration//GEN-END:variables

@Override
String getToolXML() {
return mtpPersonalizationToolModel.getToolAsObject().dump();
public void saveSettings(String fileName) {
String fullFilename = FileUtils.addExtensionIfNeeded(fileName, ".xml");
OpenSimObject obj = mtpPersonalizationToolModel.getToolAsObject();
forceWritableProperties(obj);
obj.print(fullFilename);
replaceOpenSimDocumentTags(fullFilename);
}

@Override
void forceWritableProperties(OpenSimObject dObject) {
super.forceWritableProperties(dObject); //To change body of generated methods, choose Tools | Templates.
dObject.updPropertyByName("MuscleTendonLengthInitialization").setValueIsDefault(false);
dObject.updPropertyByName("MTPSynergyExtrapolation").setValueIsDefault(false);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,12 @@ void restrictNamesBy(String pattern){
fireTableDataChanged();

}
void selectShown() {
for (int q=0; q<shownQuantities.size(); q++){
selected.set(shownQuantities.get(q), true);
}
fireTableDataChanged();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ public void pressedCancel() {

@Override
public void loadSettings(String nmsmFilename) {
String fileName = super.stripOuterTags(nmsmFilename);
String fileName = BaseToolPanel.stripOuterTags(nmsmFilename);
Model model = OpenSimDB.getInstance().getCurrentModel();
//if(model==null) throw new IOException("JointPersonalizationJPanel got null model");
ncpPersonalizationToolModel = new NCPPersonalizationToolModel(model, fileName);
Expand Down Expand Up @@ -633,8 +633,18 @@ public void setSettingsFileDescription(String description) {
// End of variables declaration//GEN-END:variables

@Override
String getToolXML() {
return ncpPersonalizationToolModel.getToolAsObject().dump();
public void saveSettings(String fileName) {
String fullFilename = FileUtils.addExtensionIfNeeded(fileName, ".xml");
OpenSimObject obj = ncpPersonalizationToolModel.getToolAsObject();
forceWritableProperties(obj);
obj.print(fullFilename);
replaceOpenSimDocumentTags(fullFilename);
}

@Override
void forceWritableProperties(OpenSimObject dObject) {
super.forceWritableProperties(dObject); //To change body of generated methods, choose Tools | Templates.
dObject.updPropertyByName("MuscleTendonLengthInitialization").setValueIsDefault(false);
}

}
Loading

0 comments on commit c65e35b

Please sign in to comment.