added functionality for supporting the GL front-end

This commit is contained in:
Stephen McQuay 2011-01-26 23:01:18 -07:00
parent ba848f6924
commit c323511b05

View File

@ -2,6 +2,8 @@ import sys
import re import re
from collections import defaultdict from collections import defaultdict
from xml.dom.minidom import Document
import numpy as np import numpy as np
from scipy.spatial import KDTree from scipy.spatial import KDTree
@ -23,7 +25,7 @@ class grid(object):
q = array (1D) of physical values q = array (1D) of physical values
""" """
if verts: if verts != None:
self.verts = np.array(verts) self.verts = np.array(verts)
self.tree = KDTree(self.verts) self.tree = KDTree(self.verts)
if q: if q:
@ -142,6 +144,33 @@ class grid(object):
r += "%s\n" % v r += "%s\n" % v
return r return r
def normalize_q(self, new_max = 0.1):
largest_number = np.max(np.abs(self.q))
self.q *= new_max/largest_number
def get_xml(self):
doc = Document()
ps = doc.createElement("points")
doc.appendChild(ps)
for i in zip(self.verts, self.q):
p = doc.createElement("point")
p.setAttribute("x", str(i[0][0]))
p.setAttribute('y', str(i[0][1]))
p.setAttribute('z', str(i[0][2]))
p.setAttribute('q', str(i[1] ))
ps.appendChild(p)
return doc
def toxml(self):
return self.get_xml().toxml()
def toprettyxml(self):
return self.get_xml().toprettyxml()
class delaunay_grid(grid): class delaunay_grid(grid):