Skip to content

Instantly share code, notes, and snippets.

@adrienkaiser
Created March 18, 2014 15:42
Show Gist options
  • Save adrienkaiser/9622682 to your computer and use it in GitHub Desktop.
Save adrienkaiser/9622682 to your computer and use it in GitHub Desktop.
A small python script to retrieve specific data from a XML file given as argument, and write it out to be used in C++ code.
#!/usr/bin/python
# Usage:
# $ readMapXML.py map.xml > mapcpp.txt
import sys # For argv and exit
if len(sys.argv) < 2:
sys.exit(1)
mapFile = sys.argv[1]
# Find nb of keyframes in map
for line in open(mapFile, 'r'):
indexKF = line.find("<KeyFrames size=")
if indexKF > 0: # if nb KF found
indexEnd = line.find(">")
nbKF = int( line[ indexKF+17 : indexEnd-1 ] )
break
print "double poseVectors[" + str(nbKF) + "][6] ="
print "{"
nbKFfound = 0
for line in open(mapFile, 'r'):
indexPose = line.find("pose=")
if indexPose > 0: # if pose found
indexFixed = line.find("fixed=")
poseXML = line[ indexPose+6 : indexFixed-2 ]
poseCut = poseXML.split(' ')
poseC = " {"
for p in poseCut :
poseC = poseC + p + ", "
poseC = poseC[ : -2 ] + "},"
print poseC
nbKFfound = nbKFfound + 1
if nbKFfound >= nbKF :
break
print "};"
print "!!!! WARNING : Remove \',\' on last line !!"
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment