コード例 #1
0
    def __init__(self, point_data):
        # data
        self.point_data = point_data
        self.timing_error = None
        self.ignored = False

        # geometry
        self.sphere_intersection = None
        self.coil_center = None
        self.coil_top = None

        coil_fun = read_and_transform.get_coil_transform_function(point_data.date)
        self.coil_center, self.coil_top = coil_fun(point_data)

        #recalculate coil_center, coil_top


        self.calculate_timing_error()
コード例 #2
0
ファイル: debugging_Jun.py プロジェクト: deherinu/TmsViewer
def main():
    os.chdir(os.path.dirname(__file__))
    os.chdir("../data")


    test_file = "TMS-597.csv"
    test_file = "TMS-640.csv"
    points = read_and_transform.read_csv_file(test_file)
    points = read_and_transform.normalize_to_ref(points,points[0])
    calib = read_and_transform.extract_calibration_samples(points)

    ren_win = vtk.vtkRenderWindow()
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
    iren.SetRenderWindow(ren_win)
    ren = vtk.vtkRenderer()
    ren_win.AddRenderer(ren)

    colors = [(1,0,0),(0,1,0),(0,1,1),(1,0,1)]
    ot_points = [p.point_pos for p in calib.itervalues()]
    d = calib[1].date
    point_f = read_and_transform.get_pointer_transform_function(d)
    calib_ps = [point_f(p) for p in calib.itervalues()]

    for p1,p2,c in izip(ot_points,calib_ps,colors):
        ac = __add_sphere_to_ren(p1,0.01,ren)
        ac.GetProperty().SetColor(c)
        ac.GetProperty().SetOpacity(0.2)
        ac = __add_sphere_to_ren(p2,0.01,ren)
        ac.GetProperty().SetColor(c)
        ac = __add_line_to_ren(p1,p2,ren)
        ac.GetProperty().SetColor(c)
        #ac.GetProperty().SetRepresentationToWireframe()

    calib_ps2 = [calib_ps[i] for i in [0,2,3]]
    r,ctr = tms_geom.adjust_sphere(calib_ps2)
    print r
    print ctr
    __add_sphere_to_ren(ctr,r,ren)

    coil_fun = read_and_transform.get_coil_transform_function(d)
    coils = read_and_transform.extract_coil_samples(points)
    oops = 0
    for p in coils:
        c,t = coil_fun(p)
        __add_sphere_to_ren(c,0.01,ren)
        l=__add_line_to_ren(c,t,ren)
        l.GetProperty().SetLineWidth(2)
        x = tms_geom.intersect_point_with_sphere(c,t-c,r,ctr)
        if x is None:
            x = tms_geom.intersect_point_with_sphere(c,c-t,r,ctr)
            oops += 1
        if x is not None:
            l2 = __add_line_to_ren(c,x,ren)


    print oops
    iren.Initialize()
    iren.Start()





    iren.Initialize()
    iren.Start()
コード例 #3
0
def __test_one():
    import os
    import vtk
    from itertools import izip

    test_dir = os.path.join(os.path.dirname(__file__), "data")
    test_file = os.path.join(test_dir, "TMS-441.csv")
    test_file = os.path.join(test_dir, "TMS-758.csv")
    #test_file = os.path.join(test_dir, "TMS-310.csv")

    points = tms_rt.read_csv_file(test_file)
    calibs = tms_rt.extract_calibration_samples(points)
    assert set(calibs.keys()) == {1, 2, 3, 4}
    ref = calibs[3]
    calibs_norm = dict(((k, tms_rt.normalize_point_to_ref(v, ref) ) for k, v in calibs.iteritems() ))

    ren_win = vtk.vtkRenderWindow()
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetInteractorStyle(vtk.vtkInteractorStyleTrackballCamera())
    iren.SetRenderWindow(ren_win)
    ren = vtk.vtkRenderer()
    ren_win.AddRenderer(ren)

    date = ref.date

    pointer_fun = tms_rt.get_pointer_transform_function(date)
    calib_points = [pointer_fun(p) for p in calibs_norm.itervalues()]

    r,ctr = tms_geom.adjust_sphere(calib_points)

    for p in calib_points:
        __add_sphere_to_ren(p,r/20,ren)

    ac = __add_sphere_to_ren(ctr,r,ren)
    ac.GetProperty().SetColor(1,0,0)
    #fit sphere to calibration

    coil_samples = tms_rt.extract_coil_samples(points)[:50]
    coil_samples_norm = tms_rt.normalize_to_ref(coil_samples, ref)
    coil_function = tms_rt.get_coil_transform_function(date)
    coil_pairs = [coil_function(p) for p in coil_samples_norm]
    cc = (0, 1, 0)
    cc2 = (0.2,0.7,0.2)
    for (c, t),p in izip(coil_pairs,coil_samples_norm):
        ac = __add_sphere_to_ren(c, 0.002, ren)
        ac.GetProperty().SetColor(cc)
        ac = __add_line_to_ren(c, np.subtract(t, c), ren)
        ac.GetProperty().SetColor(cc)

    #draw intersection with sphere
    intersects = [tms_geom.intersect_point_with_sphere(c,np.subtract(t,c),r,ctr) for c,t in coil_pairs]
    for p in intersects:
        ac = __add_sphere_to_ren(p, 0.001, ren)
        ac.GetProperty().SetColor(cc2)
        ac.GetProperty().SetOpacity(0.5)

    #find plane
    vec,  circle_radius = tms_geom.circle_from_points_in_sphere(intersects,r,ctr)
    __add_plane_to_ren(ctr+vec,vec,r,ren)

    iren.Initialize()
    iren.Start()