@@ -149,7 +149,7 @@ public double[] getGeometryPose(String name) {
149149 */
150150 public double [] getGeometrySize (String name ) {
151151 DoublePointer geomSize = model .geom_size ();
152- DoublePointer coords = geomSize .getPointer (getGeometryIndex (null ) * 3 );
152+ DoublePointer coords = geomSize .getPointer (getGeometryIndex (name ) * 3 );
153153 double x = coords .getPointer (0 ).get ();
154154 double y = coords .getPointer (1 ).get ();
155155 double z = coords .getPointer (2 ).get ();
@@ -183,20 +183,14 @@ public void setActualtorCtrl(HashMap<String, Double> control) {
183183 private HashMap <String , Integer > ActuatorNameIndexMap = null ;
184184
185185 public Set <String > getActuatorNames () {
186- getActuatorIndex ("" );
187- return ActuatorNameIndexMap .keySet ();
186+ return getActuatorNameIndexMap ().keySet ();
188187 }
189188
190189 public int getActuatorIndex (String name ) {
191190 check ();
192191
193- if (ActuatorNameIndexMap == null ) {
194- ActuatorNameIndexMap = new HashMap <>();
195- for (int i = 0 ; i < getNumberOfActuators (); i ++) {
196- ActuatorNameIndexMap .put (getActuatorName (i ), i );
197- }
198- }
199- Integer i = ActuatorNameIndexMap .get (name );
192+
193+ Integer i = getActuatorNameIndexMap ().get (name );
200194 if (i != null )
201195 return i ;
202196 throw new RuntimeException ("Actuator named " + name + " not found" );
@@ -219,20 +213,14 @@ public String getActuatorName(int i) {
219213 }
220214
221215 public Set <String > getJointNames () {
222- getJointIndex ("" );
223- return jointNameIndexMap .keySet ();
216+ return getJointNameIndexMap ().keySet ();
224217 }
225218
226219 public int getJointIndex (String name ) {
227220 check ();
228221
229- if (jointNameIndexMap == null ) {
230- jointNameIndexMap = new HashMap <>();
231- for (int i = 0 ; i < getNumberOfJoints (); i ++) {
232- jointNameIndexMap .put (getJointName (i ), i );
233- }
234- }
235- Integer i = jointNameIndexMap .get (name );
222+
223+ Integer i = getJointNameIndexMap ().get (name );
236224 if (i != null )
237225 return i ;
238226 throw new RuntimeException ("Joint named " + name + " not found" );
@@ -255,39 +243,28 @@ public String getJointName(int i) {
255243 }
256244
257245 public Set <String > getBodyNames () {
258- getBodyIndex ("" );
259- return bodyNameIndexMap .keySet ();
246+ return getBodyNameIndexMap ().keySet ();
260247 }
261248
262249 public int getBodyIndex (String name ) {
263250 check ();
264251
265- if (bodyNameIndexMap == null ) {
266- bodyNameIndexMap = new HashMap <>();
267- for (int i = 0 ; i < getNumberOfBodys (); i ++) {
268- bodyNameIndexMap .put (getBodyName (i ), i );
269- }
270- }
271- Integer i = bodyNameIndexMap .get (name );
252+
253+ Integer i = getBodyNameIndexMap ().get (name );
272254 if (i != null )
273255 return i ;
274256 throw new RuntimeException ("Body named " + name + " not found" );
275257 }
276258
277259 public Set <String > getGeometryNames () {
278- getGeometryIndex ( "" );
279- return geometryNameIndexMap .keySet ();
260+
261+ return getGeometryNameIndexMap () .keySet ();
280262 }
281263
282264 public int getGeometryIndex (String name ) {
283265 check ();
284- if (geometryNameIndexMap == null ) {
285- geometryNameIndexMap = new HashMap <>();
286- for (int i = 0 ; i < getNumberOfGeometrys (); i ++) {
287- geometryNameIndexMap .put (getGeometryName (i ), i );
288- }
289- }
290- Integer i = geometryNameIndexMap .get (name );
266+
267+ Integer i = getGeometryNameIndexMap ().get (name );
291268 if (i != null )
292269 return i ;
293270 throw new RuntimeException ("Geometry named " + name + " not found" );
@@ -298,13 +275,13 @@ public MuJoCoGeomType getMuJoCoGeomType(String geom) {
298275 return MuJoCoGeomType .get (type );
299276 }
300277
301- public int getBodyIndexOfGeometry (String geomName ) {
278+ public int getBodyIndexForGeometry (String geomName ) {
302279 int i = getGeometryIndex (geomName );
303280 return model .geom_bodyid ().getPointer (i ).get ();
304281 }
305282
306- public String getBodyNameOfGeometry (String geomName ) {
307- return getBodyName (getBodyIndexOfGeometry (geomName ));
283+ public String getBodyNameForGeometry (String geomName ) {
284+ return getBodyName (getBodyIndexForGeometry (geomName ));
308285 }
309286
310287 public double getTimestepSeconds () {
@@ -347,14 +324,14 @@ public mjData_ getData() {
347324 /**
348325 * @param daccessable the daccessable to set
349326 */
350- public void setData (mjData_ daccessable ) {
327+ private void setData (mjData_ daccessable ) {
351328 this .data = daccessable ;
352329 }
353330
354331 public void step () {
355332 stepOne ();
356333 if (controller != null )
357- controller .controlStep (data , model );
334+ controller .controlStep (this );
358335 stepTwo ();
359336 }
360337
@@ -409,4 +386,84 @@ public BytePointer getModelNames() {
409386 private void setModelNames (BytePointer modelNames ) {
410387 this .modelNames = modelNames ;
411388 }
389+
390+ /**
391+ * @return the bodyNameIndexMap
392+ */
393+ public HashMap <String , Integer > getBodyNameIndexMap () {
394+ if (bodyNameIndexMap == null ) {
395+ setBodyNameIndexMap (new HashMap <>());
396+ for (int i = 0 ; i < getNumberOfBodys (); i ++) {
397+ bodyNameIndexMap .put (getBodyName (i ), i );
398+ }
399+ }
400+ return bodyNameIndexMap ;
401+ }
402+
403+ /**
404+ * @param bodyNameIndexMap the bodyNameIndexMap to set
405+ */
406+ public void setBodyNameIndexMap (HashMap <String , Integer > bodyNameIndexMap ) {
407+ this .bodyNameIndexMap = bodyNameIndexMap ;
408+ }
409+
410+ /**
411+ * @return the geometryNameIndexMap
412+ */
413+ public HashMap <String , Integer > getGeometryNameIndexMap () {
414+ if (geometryNameIndexMap == null ) {
415+ setGeometryNameIndexMap (new HashMap <>());
416+ for (int i = 0 ; i < getNumberOfGeometrys (); i ++) {
417+ geometryNameIndexMap .put (getGeometryName (i ), i );
418+ }
419+ }
420+ return geometryNameIndexMap ;
421+ }
422+
423+ /**
424+ * @param geometryNameIndexMap the geometryNameIndexMap to set
425+ */
426+ public void setGeometryNameIndexMap (HashMap <String , Integer > geometryNameIndexMap ) {
427+ this .geometryNameIndexMap = geometryNameIndexMap ;
428+ }
429+
430+ /**
431+ * @return the jointNameIndexMap
432+ */
433+ public HashMap <String , Integer > getJointNameIndexMap () {
434+ if (jointNameIndexMap == null ) {
435+ setJointNameIndexMap (new HashMap <>());
436+ for (int i = 0 ; i < getNumberOfJoints (); i ++) {
437+ jointNameIndexMap .put (getJointName (i ), i );
438+ }
439+ }
440+ return jointNameIndexMap ;
441+ }
442+
443+ /**
444+ * @param jointNameIndexMap the jointNameIndexMap to set
445+ */
446+ public void setJointNameIndexMap (HashMap <String , Integer > jointNameIndexMap ) {
447+ this .jointNameIndexMap = jointNameIndexMap ;
448+ }
449+
450+ /**
451+ * @return the actuatorNameIndexMap
452+ */
453+ public HashMap <String , Integer > getActuatorNameIndexMap () {
454+ if (ActuatorNameIndexMap == null ) {
455+ setActuatorNameIndexMap (new HashMap <>());
456+ for (int i = 0 ; i < getNumberOfActuators (); i ++) {
457+ ActuatorNameIndexMap .put (getActuatorName (i ), i );
458+ }
459+ }
460+ return ActuatorNameIndexMap ;
461+ }
462+
463+ /**
464+ * @param actuatorNameIndexMap the actuatorNameIndexMap to set
465+ */
466+ public void setActuatorNameIndexMap (HashMap <String , Integer > actuatorNameIndexMap ) {
467+ ActuatorNameIndexMap = actuatorNameIndexMap ;
468+ }
412469}
0 commit comments