Example #1
0
def class_load_test():
    (lib_path, jvm_path, switches) = jvm_util.start_jvm()
    jar_list = glob.glob(lib_path)
    ok_(len(jar_list) > 0, 'Can not find the jar file, please build it before testing')
    
    Node = JPackage('net').epsilony.tsmf.model.Node
    
    ok_(Node.__name__ == 'net.epsilony.tsmf.model.Node', 'Can\'t load class Node properly')
Example #2
0
def plot_jpolygon(pg, ax, *args, **kwds):
    vertes = pg.getVertes()
    xys = []
    codes = []
    for act_vs in vertes:
        atBegin = True
        for nd in act_vs:
            xys.append(nd.coord)
            if atBegin:
                codes.append(Path.MOVETO)
                atBegin = False
            else:
                codes.append(Path.LINETO)
        codes.append(Path.CLOSEPOLY)
        xys.append((0, 0))
    pp = PathPatch(Path(xys, codes), *args, **kwds)
    ax.add_patch(pp)
    
if __name__ == "__main__":
    from terse_demo.util.jvm_util import start_jvm
    from jpype import JClass
    start_jvm()
    JTestTool = JClass('net.epsilony.tsmf.util.TestTool')
    pg = JTestTool.samplePolygon(None)
    from matplotlib import pyplot as plt
    fig = plt.figure()
    ax = fig.add_subplot(111)
    plot_jpolygon(pg, ax)
    fig.show()
            
Example #3
0
'''
Created on 2012-12-22

@author: Man YUAN <*****@*****.**>
'''

import numpy as np
from terse_demo.util import jvm_util
from jpype import JPackage,JArray,JDouble
from terse_proto.tsmf.model import Polygon2D

jvm_util.start_jvm(8998)
JPolygon2D=JPackage('net').epsilony.tsmf.model.Polygon2D

            
def sample_vertes_xys():
    return np.array([[[0, 0], [1, 0], [1, 1],[0.5,0.5],[0,1]]],dtype=np.double)  

if __name__ == '__main__':

    pg_j = JPolygon2D.byCoordChains(sample_vertes_xys().tolist())
    dist_func_j=np.frompyfunc(lambda x,y:pg_j.distanceFunc(x,y),2,1)
    
    pg_py = Polygon2D(sample_vertes_xys())
    dist_func_py=np.frompyfunc(lambda x,y:pg_py.distance_function((x,y)),2,1)
    
    xs=np.linspace(-0.5,1.5,100)
    ys=np.linspace(-0.5,1.5,100)    
    (g_xs,g_ys)=np.meshgrid(xs, ys)
    
    g_zs_j=dist_func_j(g_xs,g_ys)
"""
Created on 2013-1-25

@author: Man YUAN <*****@*****.**>
"""

from terse_demo.util.jvm_util import start_jvm

start_jvm(8998)
from jpype import JClass
import numpy as np
from matplotlib import pyplot as plt


def plot_vs_by_y(pp, ax, y):
    xs = np.linspace(0.01, 48 - 0.01)
    ys = np.zeros_like(xs, dtype=np.double) + y
    plot_uvs(pp, ax, xs, ys)


def plot_uvs(pp, ax, xs, ys, axis=None, is_vs=True):
    if len(xs) != len(ys):
        raise ValueError("xs and ys should have same length")
    pp.setDiffOrder(0)
    act_uvs = []
    for i in xrange(len(xs)):
        xy = np.array((xs[i], ys[i]), dtype=np.double)
        uv = pp.value(xy, None)
        if is_vs:
            act_uvs.append(uv[1])
        else: